Skip to content

Commit

Permalink
Update docs on Mon Dec 16 11:34:58 UTC 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 16, 2024
1 parent 1162831 commit 8dfe876
Show file tree
Hide file tree
Showing 241 changed files with 3,898 additions and 3,898 deletions.
12 changes: 6 additions & 6 deletions 2015/1/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,17 @@ <h2 id="problem-name">Not Quite Lisp</h2>

namespace AdventOfCode.Y2015.Day01;

[ProblemName("Not Quite Lisp")]
[ProblemName(&quot;Not Quite Lisp&quot;)]
class Solution : Solver {

public object PartOne(string input) => Levels(input).Last().level;
public object PartOne(string input) =&gt; Levels(input).Last().level;

public object PartTwo(string input) => Levels(input).First(p => p.level == -1).idx;
public object PartTwo(string input) =&gt; Levels(input).First(p =&gt; p.level == -1).idx;

IEnumerable<(int idx, int level)> Levels(string input){
IEnumerable&lt;(int idx, int level)&gt; Levels(string input){
var level = 0;
for (var i = 0; i < input.Length; i++) {
level += input[i] == '(' ? 1 : -1;
for (var i = 0; i &lt; input.Length; i++) {
level += input[i] == &#039;(&#039; ? 1 : -1;
yield return (i+1, level);
}
}
Expand Down
20 changes: 10 additions & 10 deletions 2015/10/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,27 +285,27 @@ <h2 id="problem-name">Elves Look, Elves Say</h2>

namespace AdventOfCode.Y2015.Day10;

[ProblemName("Elves Look, Elves Say")]
[ProblemName(&quot;Elves Look, Elves Say&quot;)]
class Solution : Solver {

public object PartOne(string input) => LookAndSay(input).Skip(39).First().Length;
public object PartTwo(string input) => LookAndSay(input).Skip(49).First().Length;
public object PartOne(string input) =&gt; LookAndSay(input).Skip(39).First().Length;
public object PartTwo(string input) =&gt; LookAndSay(input).Skip(49).First().Length;

IEnumerable<string> LookAndSay(string input) {
IEnumerable&lt;string&gt; LookAndSay(string input) {
while (true) {
var sb = new StringBuilder();
var ich = 0;
while (ich < input.Length) {
if (ich < input.Length - 2 && input[ich] == input[ich + 1] && input[ich] == input[ich + 2]) {
sb.Append("3");
while (ich &lt; input.Length) {
if (ich &lt; input.Length - 2 &amp;&amp; input[ich] == input[ich + 1] &amp;&amp; input[ich] == input[ich + 2]) {
sb.Append(&quot;3&quot;);
sb.Append(input[ich]);
ich += 3;
} else if (ich < input.Length - 1 && input[ich] == input[ich + 1]) {
sb.Append("2");
} else if (ich &lt; input.Length - 1 &amp;&amp; input[ich] == input[ich + 1]) {
sb.Append(&quot;2&quot;);
sb.Append(input[ich]);
ich += 2;
} else {
sb.Append("1");
sb.Append(&quot;1&quot;);
sb.Append(input[ich]);
ich += 1;
}
Expand Down
24 changes: 12 additions & 12 deletions 2015/11/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,27 +285,27 @@ <h2 id="problem-name">Corporate Policy</h2>

namespace AdventOfCode.Y2015.Day11;

[ProblemName("Corporate Policy")]
[ProblemName(&quot;Corporate Policy&quot;)]
class Solution : Solver {

public object PartOne(string input) => Passwords(input).First();
public object PartTwo(string input) => Passwords(input).Skip(1).First();
public object PartOne(string input) =&gt; Passwords(input).First();
public object PartTwo(string input) =&gt; Passwords(input).Skip(1).First();

IEnumerable<string> Passwords(string pwd) =>
IEnumerable&lt;string&gt; Passwords(string pwd) =&gt;
from word in Words(pwd)
let straigth = Enumerable.Range(0, word.Length - 2).Any(i => word[i] == word[i + 1] - 1 && word[i] == word[i + 2] - 2)
let reserved = "iol".Any(ch => word.Contains(ch))
let pairs = Enumerable.Range(0, word.Length - 1).Select(i => word.Substring(i, 2)).Where(sword => sword[0] == sword[1]).Distinct()
where straigth && !reserved && pairs.Count() > 1
let straigth = Enumerable.Range(0, word.Length - 2).Any(i =&gt; word[i] == word[i + 1] - 1 &amp;&amp; word[i] == word[i + 2] - 2)
let reserved = &quot;iol&quot;.Any(ch =&gt; word.Contains(ch))
let pairs = Enumerable.Range(0, word.Length - 1).Select(i =&gt; word.Substring(i, 2)).Where(sword =&gt; sword[0] == sword[1]).Distinct()
where straigth &amp;&amp; !reserved &amp;&amp; pairs.Count() &gt; 1
select word;

IEnumerable<string> Words(string word) {
IEnumerable&lt;string&gt; Words(string word) {
while (true) {
var sb = new StringBuilder();
for (var i = word.Length - 1; i >= 0; i--) {
for (var i = word.Length - 1; i &gt;= 0; i--) {
var ch = word[i] + 1;
if (ch > 'z') {
ch = 'a';
if (ch &gt; &#039;z&#039;) {
ch = &#039;a&#039;;
sb.Insert(0, (char)ch);
} else {
sb.Insert(0, (char)ch);
Expand Down
18 changes: 9 additions & 9 deletions 2015/12/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,22 +284,22 @@ <h2 id="problem-name">JSAbacusFramework.io</h2>

namespace AdventOfCode.Y2015.Day12;

[ProblemName("JSAbacusFramework.io")]
[ProblemName(&quot;JSAbacusFramework.io&quot;)]
class Solution : Solver {

public object PartOne(string input) => Solve(input, false);
public object PartTwo(string input) => Solve(input, true);
public object PartOne(string input) =&gt; Solve(input, false);
public object PartTwo(string input) =&gt; Solve(input, true);

int Solve(string input, bool skipRed) {
int Traverse(JsonElement t) {
return t.ValueKind switch
{
JsonValueKind.Object when skipRed && t.EnumerateObject().Any(
p => p.Value.ValueKind == JsonValueKind.String && p.Value.GetString() == "red") => 0,
JsonValueKind.Object => t.EnumerateObject().Select(p => Traverse(p.Value)).Sum(),
JsonValueKind.Array => t.EnumerateArray().Select(Traverse).Sum(),
JsonValueKind.Number => t.GetInt32(),
_ => 0
JsonValueKind.Object when skipRed &amp;&amp; t.EnumerateObject().Any(
p =&gt; p.Value.ValueKind == JsonValueKind.String &amp;&amp; p.Value.GetString() == &quot;red&quot;) =&gt; 0,
JsonValueKind.Object =&gt; t.EnumerateObject().Select(p =&gt; Traverse(p.Value)).Sum(),
JsonValueKind.Array =&gt; t.EnumerateArray().Select(Traverse).Sum(),
JsonValueKind.Number =&gt; t.GetInt32(),
_ =&gt; 0
};
}

Expand Down
30 changes: 15 additions & 15 deletions 2015/13/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,19 @@ <h2 id="problem-name">Knights of the Dinner Table</h2>

namespace AdventOfCode.Y2015.Day13;

[ProblemName("Knights of the Dinner Table")]
[ProblemName(&quot;Knights of the Dinner Table&quot;)]
class Solution : Solver {

public object PartOne(string input) => Happiness(input, false).Max();
public object PartTwo(string input) => Happiness(input, true).Max();
public object PartOne(string input) =&gt; Happiness(input, false).Max();
public object PartTwo(string input) =&gt; Happiness(input, true).Max();

IEnumerable<int> Happiness(string input, bool includeMe) {
var dh = new Dictionary<(string, string), int>();
foreach (var line in input.Split('\n')) {
var m = Regex.Match(line, @"(.*) would (.*) (.*) happiness units by sitting next to (.*).");
IEnumerable&lt;int&gt; Happiness(string input, bool includeMe) {
var dh = new Dictionary&lt;(string, string), int&gt;();
foreach (var line in input.Split(&#039;\n&#039;)) {
var m = Regex.Match(line, @&quot;(.*) would (.*) (.*) happiness units by sitting next to (.*).&quot;);
var a = m.Groups[1].Value;
var b = m.Groups[4].Value;
var happiness = int.Parse(m.Groups[3].Value) * (m.Groups[2].Value == "gain" ? 1 : -1);
var happiness = int.Parse(m.Groups[3].Value) * (m.Groups[2].Value == &quot;gain&quot; ? 1 : -1);
if (!dh.ContainsKey((a, b))) {
dh[(a, b)] = 0;
dh[(b, a)] = 0;
Expand All @@ -306,23 +306,23 @@ <h2 id="problem-name">Knights of the Dinner Table</h2>
dh[(b, a)] += happiness;
}

var people = dh.Keys.Select(k => k.Item1).Distinct().ToList();
var people = dh.Keys.Select(k =&gt; k.Item1).Distinct().ToList();
if (includeMe) {
people.Add("me");
people.Add(&quot;me&quot;);
}
return Permutations(people.ToArray()).Select(order =>
order.Zip(order.Skip(1).Append(order[0]), (a, b) => dh.TryGetValue((a, b), out var v) ? v : 0).Sum()
return Permutations(people.ToArray()).Select(order =&gt;
order.Zip(order.Skip(1).Append(order[0]), (a, b) =&gt; dh.TryGetValue((a, b), out var v) ? v : 0).Sum()
);
}

IEnumerable<T[]> Permutations<T>(T[] rgt) {
IEnumerable&lt;T[]&gt; Permutations&lt;T&gt;(T[] rgt) {

IEnumerable<T[]> PermutationsRec(int i) {
IEnumerable&lt;T[]&gt; PermutationsRec(int i) {
if (i == rgt.Length) {
yield return rgt.ToArray();
}

for (var j = i; j < rgt.Length; j++) {
for (var j = i; j &lt; rgt.Length; j++) {
(rgt[i], rgt[j]) = (rgt[j], rgt[i]);
foreach (var perm in PermutationsRec(i + 1)) {
yield return perm;
Expand Down
22 changes: 11 additions & 11 deletions 2015/14/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,29 +285,29 @@ <h2 id="problem-name">Reindeer Olympics</h2>

namespace AdventOfCode.Y2015.Day14;

[ProblemName("Reindeer Olympics")]
[ProblemName(&quot;Reindeer Olympics&quot;)]
class Solution : Solver {

public object PartOne(string input) => Race(Parse(input)).Skip(2502).First().Max();
public object PartTwo(string input) => Race2(Parse(input)).Skip(2502).First().Max();
public object PartOne(string input) =&gt; Race(Parse(input)).Skip(2502).First().Max();
public object PartTwo(string input) =&gt; Race2(Parse(input)).Skip(2502).First().Max();

IEnumerable<int>[] Parse(string input) => input.Split('\n').Select(Reindeer).ToArray();
IEnumerable&lt;int&gt;[] Parse(string input) =&gt; input.Split(&#039;\n&#039;).Select(Reindeer).ToArray();

IEnumerable<int[]> Race(IEnumerable<int>[] reindeers) {
IEnumerable&lt;int[]&gt; Race(IEnumerable&lt;int&gt;[] reindeers) {
var res = new int[reindeers.Length];
var enumarators = reindeers.Select(r => r.GetEnumerator()).ToArray();
var enumarators = reindeers.Select(r =&gt; r.GetEnumerator()).ToArray();
while (true) {
yield return (from en in enumarators
let _ = en.MoveNext()
select en.Current).ToArray();
}
}

IEnumerable<int[]> Race2(IEnumerable<int>[] reindeers) {
IEnumerable&lt;int[]&gt; Race2(IEnumerable&lt;int&gt;[] reindeers) {
var points = new int[reindeers.Length];
foreach (var step in Race(reindeers)) {
var m = step.Max();
for (var i = 0; i < step.Length; i++) {
for (var i = 0; i &lt; step.Length; i++) {
if (step[i] == m) {
points[i]++;
}
Expand All @@ -316,8 +316,8 @@ <h2 id="problem-name">Reindeer Olympics</h2>
}
}

IEnumerable<int> Reindeer(string line) {
var m = Regex.Match(line, @"(.*) can fly (.*) km/s for (.*) seconds, but then must rest for (.*) seconds.");
IEnumerable&lt;int&gt; Reindeer(string line) {
var m = Regex.Match(line, @&quot;(.*) can fly (.*) km/s for (.*) seconds, but then must rest for (.*) seconds.&quot;);
var speed = int.Parse(m.Groups[2].Value);
var flightTime = int.Parse(m.Groups[3].Value);
var restTime = int.Parse(m.Groups[4].Value);
Expand All @@ -329,7 +329,7 @@ <h2 id="problem-name">Reindeer Olympics</h2>
dist += speed;
}
t++;
if ((flying && t == flightTime) || (!flying && t == restTime)) {
if ((flying &amp;&amp; t == flightTime) || (!flying &amp;&amp; t == restTime)) {
t = 0;
flying = !flying;
}
Expand Down
26 changes: 13 additions & 13 deletions 2015/15/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ <h2 id="problem-name">Science for Hungry People</h2>

namespace AdventOfCode.Y2015.Day15;

[ProblemName("Science for Hungry People")]
[ProblemName(&quot;Science for Hungry People&quot;)]
class Solution : Solver {

public object PartOne(string input) => Solve(input, null);
public object PartTwo(string input) => Solve(input, 500);
public object PartOne(string input) =&gt; Solve(input, null);
public object PartTwo(string input) =&gt; Solve(input, 500);

long Solve(string input, int? calories) {
var ingredients = Parse(input);
Expand All @@ -299,32 +299,32 @@ <h2 id="problem-name">Science for Hungry People</h2>
var maxValue = 0L;
foreach (var amounts in Partition(100, ingredients.Length)) {
var props = new int[propsCount];
for (int ingredient = 0; ingredient < ingredients.Length; ingredient++) {
for (int prop = 0; prop < 5; prop++) {
for (int ingredient = 0; ingredient &lt; ingredients.Length; ingredient++) {
for (int prop = 0; prop &lt; 5; prop++) {
props[prop] += ingredients[ingredient][prop] * amounts[ingredient];
}
}
if (!calories.HasValue || calories.Value == props.Last()) {
var value = props.Take(propsCount - 1).Aggregate(1L, (acc, p) => acc * Math.Max(0, p));
var value = props.Take(propsCount - 1).Aggregate(1L, (acc, p) =&gt; acc * Math.Max(0, p));
maxValue = Math.Max(maxValue, value);
}
}
return maxValue;
}

int[][] Parse(string input) =>
(from line in input.Split('\n')
let m = Regex.Match(line, @".*: capacity (.*), durability (.*), flavor (.*), texture (.*), calories (.*)")
let nums = m.Groups.Cast<Group>().Skip(1).Select(g => int.Parse(g.Value)).ToArray()
int[][] Parse(string input) =&gt;
(from line in input.Split(&#039;\n&#039;)
let m = Regex.Match(line, @&quot;.*: capacity (.*), durability (.*), flavor (.*), texture (.*), calories (.*)&quot;)
let nums = m.Groups.Cast&lt;Group&gt;().Skip(1).Select(g =&gt; int.Parse(g.Value)).ToArray()
select nums).ToArray();

IEnumerable<int[]> Partition(int n, int k) {
IEnumerable&lt;int[]&gt; Partition(int n, int k) {
if (k == 1) {
yield return new int[] { n };
} else {
for (var i = 0; i <= n; i++) {
for (var i = 0; i &lt;= n; i++) {
foreach (var rest in Partition(n - i, k - 1)) {
yield return rest.Select(x => x).Append(i).ToArray();
yield return rest.Select(x =&gt; x).Append(i).ToArray();
}
}
}
Expand Down
50 changes: 25 additions & 25 deletions 2015/16/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,42 +285,42 @@ <h2 id="problem-name">Aunt Sue</h2>

namespace AdventOfCode.Y2015.Day16;

[ProblemName("Aunt Sue")]
[ProblemName(&quot;Aunt Sue&quot;)]
class Solution : Solver {

private Dictionary<string, int> target = new Dictionary<string, int> {
["children"] = 3,
["cats"] = 7,
["samoyeds"] = 2,
["pomeranians"] = 3,
["akitas"] = 0,
["vizslas"] = 0,
["goldfish"] = 5,
["trees"] = 3,
["cars"] = 2,
["perfumes"] = 1,
private Dictionary&lt;string, int&gt; target = new Dictionary&lt;string, int&gt; {
[&quot;children&quot;] = 3,
[&quot;cats&quot;] = 7,
[&quot;samoyeds&quot;] = 2,
[&quot;pomeranians&quot;] = 3,
[&quot;akitas&quot;] = 0,
[&quot;vizslas&quot;] = 0,
[&quot;goldfish&quot;] = 5,
[&quot;trees&quot;] = 3,
[&quot;cars&quot;] = 2,
[&quot;perfumes&quot;] = 1,
};

public object PartOne(string input) =>
Parse(input).FindIndex(p => p.Keys.All(k => p[k] == target[k])) + 1;
public object PartOne(string input) =&gt;
Parse(input).FindIndex(p =&gt; p.Keys.All(k =&gt; p[k] == target[k])) + 1;

public object PartTwo(string input) =>
Parse(input).FindIndex(p => p.Keys.All(k => {
if (k == "cats" || k == "trees") {
return p[k] > target[k];
} else if (k == "pomeranians" || k == "goldfish") {
return p[k] < target[k];
public object PartTwo(string input) =&gt;
Parse(input).FindIndex(p =&gt; p.Keys.All(k =&gt; {
if (k == &quot;cats&quot; || k == &quot;trees&quot;) {
return p[k] &gt; target[k];
} else if (k == &quot;pomeranians&quot; || k == &quot;goldfish&quot;) {
return p[k] &lt; target[k];
} else {
return p[k] == target[k];
}
})) + 1;

List<Dictionary<string, int>> Parse(string input) => (
from line in input.Split('\n')
let parts = Regex.Matches(line, @"(\w+): (\d+)")
List&lt;Dictionary&lt;string, int&gt;&gt; Parse(string input) =&gt; (
from line in input.Split(&#039;\n&#039;)
let parts = Regex.Matches(line, @&quot;(\w+): (\d+)&quot;)
select parts.ToDictionary(
part => part.Groups[1].Value,
part => int.Parse(part.Groups[2].Value))
part =&gt; part.Groups[1].Value,
part =&gt; int.Parse(part.Groups[2].Value))
).ToList();
}
</code></pre></div>
Expand Down
Loading

0 comments on commit 8dfe876

Please sign in to comment.