diff --git a/src/01.cs b/src/01.cs index 13a248a..cc2ebb4 100644 --- a/src/01.cs +++ b/src/01.cs @@ -27,6 +27,7 @@ internal class Day01 : Day lastDepth = depth; } + t.Stop(); Logger.Log($"<+black>> part1: <+white>{numIncreased}"); } @@ -61,6 +62,7 @@ internal class Day01 : Day lastTotal = total; } + t.Stop(); Logger.Log($"<+black>> part2: <+white>{numIncreased}"); } } diff --git a/src/02.cs b/src/02.cs index fdbcabe..be5dc56 100644 --- a/src/02.cs +++ b/src/02.cs @@ -54,6 +54,7 @@ internal class Day02 : Day } } + t.Stop(); Logger.Log($"<+black>> part1: h: {pos.h}, d: {pos.d}, result: <+white>{pos.h * pos.d}"); } @@ -81,6 +82,7 @@ internal class Day02 : Day } } + t.Stop(); Logger.Log($"<+black>> part2: h: {pos.h}, d: {pos.d}, result: <+white>{pos.h * pos.d}"); } } diff --git a/src/03.cs b/src/03.cs index 81b75b3..4db5ad7 100644 --- a/src/03.cs +++ b/src/03.cs @@ -41,6 +41,7 @@ internal class Day03 : Day } } + t.Stop(); Logger.Log($"<+black>> part1: gamma rate: {gammaRate}, epsilon rate: {epsilonRate}, mult: <+white>{gammaRate * epsilonRate}"); } @@ -123,6 +124,7 @@ internal class Day03 : Day } } + t.Stop(); Logger.Log($"<+black>> part2: o2*co2 = {o2} * {co2} = <+white>{o2 * co2}"); } } diff --git a/src/05.cs b/src/05.cs index 4141e5f..6f61cc7 100644 --- a/src/05.cs +++ b/src/05.cs @@ -72,6 +72,7 @@ internal class Day05 : Day { using var t = new Timer(); int numPointsGreater = Solve(lines, (line) => !(line.Start.X == line.End.X || line.Start.Y == line.End.Y)); + t.Stop(); Logger.Log($"<+black>> part1: <+white>{numPointsGreater}"); } @@ -79,6 +80,7 @@ internal class Day05 : Day { using var t = new Timer(); int numPointsGreater = Solve(lines, (line) => false); + t.Stop(); Logger.Log($"<+black>> part2: <+white>{numPointsGreater}"); } diff --git a/src/06.cs b/src/06.cs index 02b4a36..3c00bb2 100644 --- a/src/06.cs +++ b/src/06.cs @@ -44,6 +44,7 @@ internal class Day06 : Day } } + t.Stop(); #pragma warning disable CA1829 // Use Length/Count property instead of Count() when available - Count is of type int, list might be longer than that Logger.Log($"<+black>> part1: #fish=<+white>{list.LongCount()}"); #pragma warning restore CA1829 // Use Length/Count property instead of Count() when available @@ -72,6 +73,7 @@ internal class Day06 : Day fishAtState[8] = adders; } + t.Stop(); Logger.Log($"<+black>> part2: #fish=<+white>{fishAtState.Values.Sum()}"); } } diff --git a/src/07.cs b/src/07.cs index dd2e4b9..f8d499f 100644 --- a/src/07.cs +++ b/src/07.cs @@ -39,6 +39,7 @@ internal class Day07 : Day var (minDist, minNum) = Solve(nums, (d) => d); + t.Stop(); Logger.Log($"<+black>> part1: position: {minNum}, fuel cost: <+white>{minDist}"); } @@ -50,6 +51,7 @@ internal class Day07 : Day // found by searching "factorial but with addition" because i'm smart like that. var (minDist, minNum) = Solve(nums, (d) => ((d * d) + d) / 2); + t.Stop(); Logger.Log($"<+black>> part2: position: {minNum}, fuel cost: <+white>{minDist}"); } } diff --git a/src/08.cs b/src/08.cs index db6c79e..afbcbff 100644 --- a/src/08.cs +++ b/src/08.cs @@ -36,6 +36,7 @@ internal class Day08 : Day } } + t.Stop(); Logger.Log($"<+black>> part1: <+white>{count}"); } @@ -100,6 +101,7 @@ internal class Day08 : Day sum += num; } + t.Stop(); Logger.Log($"<+black>> part2: <+white>{sum}"); } diff --git a/src/09.cs b/src/09.cs index 53fb46f..62e9de3 100644 --- a/src/09.cs +++ b/src/09.cs @@ -24,6 +24,7 @@ internal class Day09 : Day var lowPoints = GetLowPoints(grid); var totalRisk = lowPoints.Sum(x => grid[x.Item1, x.Item2] + 1); + t.Stop(); Logger.Log($"<+black>> part1: <+white>{totalRisk}"); } @@ -72,6 +73,7 @@ internal class Day09 : Day } var top3Mult = basins.OrderByDescending(x => x).Take(3).Aggregate(1, (x, y) => x * y); + t.Stop(); Logger.Log($"<+black>> part2: <+white>{top3Mult}"); } diff --git a/src/10.cs b/src/10.cs index 0df8580..7899d55 100644 --- a/src/10.cs +++ b/src/10.cs @@ -49,6 +49,7 @@ internal class Day10 : Day } } + t.Stop(); Logger.Log($"<+black>> part1: <+white>{score}"); } @@ -133,6 +134,7 @@ internal class Day10 : Day var final = scores.OrderBy(x => x).Skip(scores.Count / 2).First(); + t.Stop(); Logger.Log($"<+black>> part2: <+white>{final}"); } } diff --git a/src/11.cs b/src/11.cs index 8d74607..9b46133 100644 --- a/src/11.cs +++ b/src/11.cs @@ -99,6 +99,7 @@ internal class Day11 : Day } } + t.Stop(); Logger.Log($"<+black>> part1: <+white>{numFlashes}"); } @@ -132,6 +133,7 @@ internal class Day11 : Day } } + t.Stop(); Logger.Log($"<+black>> part2: <+white>{step}"); } } diff --git a/src/12.cs b/src/12.cs index 2206c9e..54f1b77 100644 --- a/src/12.cs +++ b/src/12.cs @@ -47,6 +47,7 @@ internal class Day12 : Day var validPaths = new List>(); FindPaths(paths, validPaths, new List(){ "START" }, false); + t.Stop(); Logger.Log($"<+black>> part1: <+white>{validPaths.Count}"); //validPaths.Select(x => string.Join(',', x)).OrderBy(x => x).ForEach(x => Logger.Log(x)); } @@ -102,6 +103,7 @@ internal class Day12 : Day var validPaths = new List>(); FindPaths(paths, validPaths, new List() { "START" }, true); + t.Stop(); Logger.Log($"<+black>> part2: <+white>{validPaths.Count}"); //validPaths.Select(x => string.Join(',', x)).OrderBy(x => x).ForEach(x => Logger.Log(x)); } diff --git a/src/13.cs b/src/13.cs index 71140b3..6c32194 100644 --- a/src/13.cs +++ b/src/13.cs @@ -57,6 +57,7 @@ internal class Day13 : Day Fold(grid, folds[0].axis, folds[0].line); + t.Stop(); Logger.Log($"<+black>> part1: <+white>{grid.Count}"); } @@ -87,6 +88,8 @@ internal class Day13 : Day sb.Append('\n'); } } + + t.Stop(); Logger.Log($"<+white>{sb}"); Logger.Log($"<+black>> part2: {grid.Count}"); } diff --git a/src/14.cs b/src/14.cs index ddb8886..4b33cb5 100644 --- a/src/14.cs +++ b/src/14.cs @@ -59,6 +59,7 @@ internal class Day14 : Day var least = frequencies.Min(x => x.Value); var most = frequencies.Max(x => x.Value); + t.Stop(); Logger.Log($"<+black>> part1: <+white>{most - least}"); } @@ -110,6 +111,7 @@ internal class Day14 : Day } } + t.Stop(); Logger.Log($"<+black>> part2: <+white>{most - least}"); } } diff --git a/src/15.cs b/src/15.cs index fba91f6..548a799 100644 --- a/src/15.cs +++ b/src/15.cs @@ -75,6 +75,7 @@ internal class Day15 : Day var risk = Solve(grid); + t.Stop(); Logger.Log($"<+black>> part1: <+white>{risk}"); } @@ -107,6 +108,7 @@ internal class Day15 : Day var risk = Solve(ScaleUp(grid)); + t.Stop(); Logger.Log($"<+black>> part2: <+white>{risk}"); } } diff --git a/src/17.cs b/src/17.cs index 1cae221..b03cc00 100644 --- a/src/17.cs +++ b/src/17.cs @@ -35,8 +35,12 @@ internal class Day17 : Day bounds.minY = Convert.ToInt32(ys[0][(ys[0].IndexOf('=') + 1)..]); bounds.maxY = Convert.ToInt32(ys[1]); - Part1(bounds); - Part2(bounds); + using var t = new Timer(); + var successes = GetSuccessfulVelocities(bounds); + t.Stop(); + + Part1(successes); + Part2(successes); } private static (int x, int y) Step((int x, int y) pt, ref (int x, int y) velocity) @@ -56,23 +60,16 @@ internal class Day17 : Day return (pt.x, pt.y); } - private static void Part1(Rectangle bounds) + private static void Part1(Dictionary<(int x, int y), int> successes) { - using var t = new Timer(); - - var successes = GetSuccessfulVelocities(bounds); var max = successes.MaxBy(vel => vel.Value); var numOthers = successes.Count(vel => vel.Value == max.Value); Logger.Log($"<+black>> part1: highest Y was at velocity {max.Key} (and {numOthers} other{(numOthers == 1 ? "" : "s")}): <+white>{max.Value}"); } - private static void Part2(Rectangle bounds) + private static void Part2(Dictionary<(int x, int y), int> successes) { - using var t = new Timer(); - - var successes = GetSuccessfulVelocities(bounds); - Logger.Log($"<+black>> part2: #successful velocities: <+white>{successes.Count}"); } @@ -141,21 +138,16 @@ internal class Day17 : Day private static (int min, int max) GetYVelocityRange(Rectangle bounds) { int maxSuccessYVel = int.MinValue; + int maxVelY = Math.Abs(bounds.minY) - 1; int guess = bounds.minY; - bool foundYVals = false; - while (!foundYVals) + while (guess <= maxVelY) { var guesspt = (0, 0); var testVel = (0, guess); - bool lastWasAbove = false; while (true) { guesspt = Step(guesspt, ref testVel); - if (bounds.IsHigh(guesspt)) - { - lastWasAbove = true; - } - else if (!bounds.IsLow(guesspt)) + if (!bounds.IsHigh(guesspt) && !bounds.IsLow(guesspt)) { if (guess > maxSuccessYVel) { @@ -163,14 +155,8 @@ internal class Day17 : Day } break; } - else + else if (bounds.IsLow(guesspt)) { - // need to find a better way to choose a reasonable guess max... - if (lastWasAbove && guess > bounds.minY * -4) - { - foundYVals = true; - } - break; } } diff --git a/src/Template.cs b/src/Template.cs index 246f0df..cf1e21e 100644 --- a/src/Template.cs +++ b/src/Template.cs @@ -13,6 +13,9 @@ internal class DayTemplate : Day { using var t = new Timer(); + + + t.Stop(); Logger.Log($"<+black>> part1: <+white>"); } @@ -20,6 +23,9 @@ internal class DayTemplate : Day { using var t = new Timer(); + + + t.Stop(); Logger.Log($"<+black>> part2: <+white>"); } }