Skip to content

Commit 8dfe876

Browse files
Update docs on Mon Dec 16 11:34:58 UTC 2024
1 parent 1162831 commit 8dfe876

File tree

241 files changed

+3898
-3898
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+3898
-3898
lines changed

2015/1/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,17 @@ <h2 id="problem-name">Not Quite Lisp</h2>
284284

285285
namespace AdventOfCode.Y2015.Day01;
286286

287-
[ProblemName("Not Quite Lisp")]
287+
[ProblemName(&quot;Not Quite Lisp&quot;)]
288288
class Solution : Solver {
289289

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

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

294-
IEnumerable<(int idx, int level)> Levels(string input){
294+
IEnumerable&lt;(int idx, int level)&gt; Levels(string input){
295295
var level = 0;
296-
for (var i = 0; i < input.Length; i++) {
297-
level += input[i] == '(' ? 1 : -1;
296+
for (var i = 0; i &lt; input.Length; i++) {
297+
level += input[i] == &#039;(&#039; ? 1 : -1;
298298
yield return (i+1, level);
299299
}
300300
}

2015/10/index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,27 +285,27 @@ <h2 id="problem-name">Elves Look, Elves Say</h2>
285285

286286
namespace AdventOfCode.Y2015.Day10;
287287

288-
[ProblemName("Elves Look, Elves Say")]
288+
[ProblemName(&quot;Elves Look, Elves Say&quot;)]
289289
class Solution : Solver {
290290

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

294-
IEnumerable<string> LookAndSay(string input) {
294+
IEnumerable&lt;string&gt; LookAndSay(string input) {
295295
while (true) {
296296
var sb = new StringBuilder();
297297
var ich = 0;
298-
while (ich < input.Length) {
299-
if (ich < input.Length - 2 && input[ich] == input[ich + 1] && input[ich] == input[ich + 2]) {
300-
sb.Append("3");
298+
while (ich &lt; input.Length) {
299+
if (ich &lt; input.Length - 2 &amp;&amp; input[ich] == input[ich + 1] &amp;&amp; input[ich] == input[ich + 2]) {
300+
sb.Append(&quot;3&quot;);
301301
sb.Append(input[ich]);
302302
ich += 3;
303-
} else if (ich < input.Length - 1 && input[ich] == input[ich + 1]) {
304-
sb.Append("2");
303+
} else if (ich &lt; input.Length - 1 &amp;&amp; input[ich] == input[ich + 1]) {
304+
sb.Append(&quot;2&quot;);
305305
sb.Append(input[ich]);
306306
ich += 2;
307307
} else {
308-
sb.Append("1");
308+
sb.Append(&quot;1&quot;);
309309
sb.Append(input[ich]);
310310
ich += 1;
311311
}

2015/11/index.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -285,27 +285,27 @@ <h2 id="problem-name">Corporate Policy</h2>
285285

286286
namespace AdventOfCode.Y2015.Day11;
287287

288-
[ProblemName("Corporate Policy")]
288+
[ProblemName(&quot;Corporate Policy&quot;)]
289289
class Solution : Solver {
290290

291-
public object PartOne(string input) => Passwords(input).First();
292-
public object PartTwo(string input) => Passwords(input).Skip(1).First();
291+
public object PartOne(string input) =&gt; Passwords(input).First();
292+
public object PartTwo(string input) =&gt; Passwords(input).Skip(1).First();
293293

294-
IEnumerable<string> Passwords(string pwd) =>
294+
IEnumerable&lt;string&gt; Passwords(string pwd) =&gt;
295295
from word in Words(pwd)
296-
let straigth = Enumerable.Range(0, word.Length - 2).Any(i => word[i] == word[i + 1] - 1 && word[i] == word[i + 2] - 2)
297-
let reserved = "iol".Any(ch => word.Contains(ch))
298-
let pairs = Enumerable.Range(0, word.Length - 1).Select(i => word.Substring(i, 2)).Where(sword => sword[0] == sword[1]).Distinct()
299-
where straigth && !reserved && pairs.Count() > 1
296+
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)
297+
let reserved = &quot;iol&quot;.Any(ch =&gt; word.Contains(ch))
298+
let pairs = Enumerable.Range(0, word.Length - 1).Select(i =&gt; word.Substring(i, 2)).Where(sword =&gt; sword[0] == sword[1]).Distinct()
299+
where straigth &amp;&amp; !reserved &amp;&amp; pairs.Count() &gt; 1
300300
select word;
301301

302-
IEnumerable<string> Words(string word) {
302+
IEnumerable&lt;string&gt; Words(string word) {
303303
while (true) {
304304
var sb = new StringBuilder();
305-
for (var i = word.Length - 1; i >= 0; i--) {
305+
for (var i = word.Length - 1; i &gt;= 0; i--) {
306306
var ch = word[i] + 1;
307-
if (ch > 'z') {
308-
ch = 'a';
307+
if (ch &gt; &#039;z&#039;) {
308+
ch = &#039;a&#039;;
309309
sb.Insert(0, (char)ch);
310310
} else {
311311
sb.Insert(0, (char)ch);

2015/12/index.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,22 +284,22 @@ <h2 id="problem-name">JSAbacusFramework.io</h2>
284284

285285
namespace AdventOfCode.Y2015.Day12;
286286

287-
[ProblemName("JSAbacusFramework.io")]
287+
[ProblemName(&quot;JSAbacusFramework.io&quot;)]
288288
class Solution : Solver {
289289

290-
public object PartOne(string input) => Solve(input, false);
291-
public object PartTwo(string input) => Solve(input, true);
290+
public object PartOne(string input) =&gt; Solve(input, false);
291+
public object PartTwo(string input) =&gt; Solve(input, true);
292292

293293
int Solve(string input, bool skipRed) {
294294
int Traverse(JsonElement t) {
295295
return t.ValueKind switch
296296
{
297-
JsonValueKind.Object when skipRed && t.EnumerateObject().Any(
298-
p => p.Value.ValueKind == JsonValueKind.String && p.Value.GetString() == "red") => 0,
299-
JsonValueKind.Object => t.EnumerateObject().Select(p => Traverse(p.Value)).Sum(),
300-
JsonValueKind.Array => t.EnumerateArray().Select(Traverse).Sum(),
301-
JsonValueKind.Number => t.GetInt32(),
302-
_ => 0
297+
JsonValueKind.Object when skipRed &amp;&amp; t.EnumerateObject().Any(
298+
p =&gt; p.Value.ValueKind == JsonValueKind.String &amp;&amp; p.Value.GetString() == &quot;red&quot;) =&gt; 0,
299+
JsonValueKind.Object =&gt; t.EnumerateObject().Select(p =&gt; Traverse(p.Value)).Sum(),
300+
JsonValueKind.Array =&gt; t.EnumerateArray().Select(Traverse).Sum(),
301+
JsonValueKind.Number =&gt; t.GetInt32(),
302+
_ =&gt; 0
303303
};
304304
}
305305

2015/13/index.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,19 @@ <h2 id="problem-name">Knights of the Dinner Table</h2>
285285

286286
namespace AdventOfCode.Y2015.Day13;
287287

288-
[ProblemName("Knights of the Dinner Table")]
288+
[ProblemName(&quot;Knights of the Dinner Table&quot;)]
289289
class Solution : Solver {
290290

291-
public object PartOne(string input) => Happiness(input, false).Max();
292-
public object PartTwo(string input) => Happiness(input, true).Max();
291+
public object PartOne(string input) =&gt; Happiness(input, false).Max();
292+
public object PartTwo(string input) =&gt; Happiness(input, true).Max();
293293

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

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

318-
IEnumerable<T[]> Permutations<T>(T[] rgt) {
318+
IEnumerable&lt;T[]&gt; Permutations&lt;T&gt;(T[] rgt) {
319319

320-
IEnumerable<T[]> PermutationsRec(int i) {
320+
IEnumerable&lt;T[]&gt; PermutationsRec(int i) {
321321
if (i == rgt.Length) {
322322
yield return rgt.ToArray();
323323
}
324324

325-
for (var j = i; j < rgt.Length; j++) {
325+
for (var j = i; j &lt; rgt.Length; j++) {
326326
(rgt[i], rgt[j]) = (rgt[j], rgt[i]);
327327
foreach (var perm in PermutationsRec(i + 1)) {
328328
yield return perm;

2015/14/index.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,29 +285,29 @@ <h2 id="problem-name">Reindeer Olympics</h2>
285285

286286
namespace AdventOfCode.Y2015.Day14;
287287

288-
[ProblemName("Reindeer Olympics")]
288+
[ProblemName(&quot;Reindeer Olympics&quot;)]
289289
class Solution : Solver {
290290

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

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

296-
IEnumerable<int[]> Race(IEnumerable<int>[] reindeers) {
296+
IEnumerable&lt;int[]&gt; Race(IEnumerable&lt;int&gt;[] reindeers) {
297297
var res = new int[reindeers.Length];
298-
var enumarators = reindeers.Select(r => r.GetEnumerator()).ToArray();
298+
var enumarators = reindeers.Select(r =&gt; r.GetEnumerator()).ToArray();
299299
while (true) {
300300
yield return (from en in enumarators
301301
let _ = en.MoveNext()
302302
select en.Current).ToArray();
303303
}
304304
}
305305

306-
IEnumerable<int[]> Race2(IEnumerable<int>[] reindeers) {
306+
IEnumerable&lt;int[]&gt; Race2(IEnumerable&lt;int&gt;[] reindeers) {
307307
var points = new int[reindeers.Length];
308308
foreach (var step in Race(reindeers)) {
309309
var m = step.Max();
310-
for (var i = 0; i < step.Length; i++) {
310+
for (var i = 0; i &lt; step.Length; i++) {
311311
if (step[i] == m) {
312312
points[i]++;
313313
}
@@ -316,8 +316,8 @@ <h2 id="problem-name">Reindeer Olympics</h2>
316316
}
317317
}
318318

319-
IEnumerable<int> Reindeer(string line) {
320-
var m = Regex.Match(line, @"(.*) can fly (.*) km/s for (.*) seconds, but then must rest for (.*) seconds.");
319+
IEnumerable&lt;int&gt; Reindeer(string line) {
320+
var m = Regex.Match(line, @&quot;(.*) can fly (.*) km/s for (.*) seconds, but then must rest for (.*) seconds.&quot;);
321321
var speed = int.Parse(m.Groups[2].Value);
322322
var flightTime = int.Parse(m.Groups[3].Value);
323323
var restTime = int.Parse(m.Groups[4].Value);
@@ -329,7 +329,7 @@ <h2 id="problem-name">Reindeer Olympics</h2>
329329
dist += speed;
330330
}
331331
t++;
332-
if ((flying && t == flightTime) || (!flying && t == restTime)) {
332+
if ((flying &amp;&amp; t == flightTime) || (!flying &amp;&amp; t == restTime)) {
333333
t = 0;
334334
flying = !flying;
335335
}

2015/15/index.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ <h2 id="problem-name">Science for Hungry People</h2>
286286

287287
namespace AdventOfCode.Y2015.Day15;
288288

289-
[ProblemName("Science for Hungry People")]
289+
[ProblemName(&quot;Science for Hungry People&quot;)]
290290
class Solution : Solver {
291291

292-
public object PartOne(string input) => Solve(input, null);
293-
public object PartTwo(string input) => Solve(input, 500);
292+
public object PartOne(string input) =&gt; Solve(input, null);
293+
public object PartTwo(string input) =&gt; Solve(input, 500);
294294

295295
long Solve(string input, int? calories) {
296296
var ingredients = Parse(input);
@@ -299,32 +299,32 @@ <h2 id="problem-name">Science for Hungry People</h2>
299299
var maxValue = 0L;
300300
foreach (var amounts in Partition(100, ingredients.Length)) {
301301
var props = new int[propsCount];
302-
for (int ingredient = 0; ingredient < ingredients.Length; ingredient++) {
303-
for (int prop = 0; prop < 5; prop++) {
302+
for (int ingredient = 0; ingredient &lt; ingredients.Length; ingredient++) {
303+
for (int prop = 0; prop &lt; 5; prop++) {
304304
props[prop] += ingredients[ingredient][prop] * amounts[ingredient];
305305
}
306306
}
307307
if (!calories.HasValue || calories.Value == props.Last()) {
308-
var value = props.Take(propsCount - 1).Aggregate(1L, (acc, p) => acc * Math.Max(0, p));
308+
var value = props.Take(propsCount - 1).Aggregate(1L, (acc, p) =&gt; acc * Math.Max(0, p));
309309
maxValue = Math.Max(maxValue, value);
310310
}
311311
}
312312
return maxValue;
313313
}
314314

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

321-
IEnumerable<int[]> Partition(int n, int k) {
321+
IEnumerable&lt;int[]&gt; Partition(int n, int k) {
322322
if (k == 1) {
323323
yield return new int[] { n };
324324
} else {
325-
for (var i = 0; i <= n; i++) {
325+
for (var i = 0; i &lt;= n; i++) {
326326
foreach (var rest in Partition(n - i, k - 1)) {
327-
yield return rest.Select(x => x).Append(i).ToArray();
327+
yield return rest.Select(x =&gt; x).Append(i).ToArray();
328328
}
329329
}
330330
}

2015/16/index.html

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -285,42 +285,42 @@ <h2 id="problem-name">Aunt Sue</h2>
285285

286286
namespace AdventOfCode.Y2015.Day16;
287287

288-
[ProblemName("Aunt Sue")]
288+
[ProblemName(&quot;Aunt Sue&quot;)]
289289
class Solution : Solver {
290290

291-
private Dictionary<string, int> target = new Dictionary<string, int> {
292-
["children"] = 3,
293-
["cats"] = 7,
294-
["samoyeds"] = 2,
295-
["pomeranians"] = 3,
296-
["akitas"] = 0,
297-
["vizslas"] = 0,
298-
["goldfish"] = 5,
299-
["trees"] = 3,
300-
["cars"] = 2,
301-
["perfumes"] = 1,
291+
private Dictionary&lt;string, int&gt; target = new Dictionary&lt;string, int&gt; {
292+
[&quot;children&quot;] = 3,
293+
[&quot;cats&quot;] = 7,
294+
[&quot;samoyeds&quot;] = 2,
295+
[&quot;pomeranians&quot;] = 3,
296+
[&quot;akitas&quot;] = 0,
297+
[&quot;vizslas&quot;] = 0,
298+
[&quot;goldfish&quot;] = 5,
299+
[&quot;trees&quot;] = 3,
300+
[&quot;cars&quot;] = 2,
301+
[&quot;perfumes&quot;] = 1,
302302
};
303303

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

307-
public object PartTwo(string input) =>
308-
Parse(input).FindIndex(p => p.Keys.All(k => {
309-
if (k == "cats" || k == "trees") {
310-
return p[k] > target[k];
311-
} else if (k == "pomeranians" || k == "goldfish") {
312-
return p[k] < target[k];
307+
public object PartTwo(string input) =&gt;
308+
Parse(input).FindIndex(p =&gt; p.Keys.All(k =&gt; {
309+
if (k == &quot;cats&quot; || k == &quot;trees&quot;) {
310+
return p[k] &gt; target[k];
311+
} else if (k == &quot;pomeranians&quot; || k == &quot;goldfish&quot;) {
312+
return p[k] &lt; target[k];
313313
} else {
314314
return p[k] == target[k];
315315
}
316316
})) + 1;
317317

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

0 commit comments

Comments
 (0)