diff --git a/AoC_2026/Day05.cs b/AoC_2026/Day05.cs index 6202a3a..4e10ac1 100644 --- a/AoC_2026/Day05.cs +++ b/AoC_2026/Day05.cs @@ -5,7 +5,7 @@ namespace AoC_2026; public class Day05 : IPuzzleSolver { - private static Func[] ParsePuzzleInput(string path) + private static Func[] ParsePuzzleInput(string path) { var puzzleInput = File.ReadAllText(path) .Split(" ", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) @@ -14,35 +14,17 @@ public class Day05 : IPuzzleSolver return puzzleInput; } - private static Func ParseButton(string button) + private static Func ParseButton(string button) { - button = button[1..^1]; - if(button == "bksp") - return Subtract; - if (button == "oct") - return ToOctal; - if (button.StartsWith('*')) + return button[1..^1] switch { - var a = int.Parse(button[1..]); - return display => Multiply(display, a); - } - if (button.StartsWith('/')) - { - var a = int.Parse(button[1..]); - return display => Divide(display, a); - } - if (button.IndexOf("->", StringComparison.Ordinal) > 0) - { - var parts = button.Split("->"); - var a = parts[0]; - var b = parts[1]; - return display => Replace(display, a, b); - } - else - { - var a = int.Parse(button); - return display => Add(display, a); - } + "bksp" => Subtract, + "oct" => ToOctal, + var btn when btn.StartsWith('*') => display => Multiply(display, long.Parse(btn[1..])), + var btn when btn.StartsWith('/') => display => Divide(display, long.Parse(btn[1..])), + var btn when btn.Split("->") is [var a, var b] => display => Replace(display, a, b), + var btn => display => Add(display, long.Parse(btn)) + }; } public long SolvePart1(string pathToPuzzleInput) @@ -68,8 +50,8 @@ public class Day05 : IPuzzleSolver return result; } - private static HashSet<(int number, int depth)> GetUniqulyAchievableNumbers(int display, Func[] buttons, - HashSet<(int number, int depth)> seenDisplayValues, int maxPresses = -1) + private static HashSet<(long number, int depth)> GetUniqulyAchievableNumbers(long display, Func[] buttons, + HashSet<(long number, int depth)> seenDisplayValues, int maxPresses = -1) { if (!seenDisplayValues.Add((display, maxPresses)) || maxPresses == 0) return seenDisplayValues; @@ -82,34 +64,34 @@ public class Day05 : IPuzzleSolver return seenDisplayValues; } - private static int ApplyDisplaySafety(int display, int displayOld) + private static long ApplyDisplaySafety(long display, long displayOld) { return display > 9999 ? displayOld : display; } - private static int Add(int display, int buttonValue) + private static long Add(long display, long buttonValue) { return display * 10 + buttonValue; } - private static int Multiply(int display, int buttonValue) + private static long Multiply(long display, long buttonValue) { return display * buttonValue; } - private static int Divide(int display, int buttonValue) + private static long Divide(long display, long buttonValue) { return display / buttonValue; } - private static int Subtract(int display) + private static long Subtract(long display) { return display / 10; } - private static int ToOctal(int display) + private static long ToOctal(long display) { - var nextDisplay = 0; + var nextDisplay = 0L; var i = 1; while (display > 0) @@ -122,8 +104,8 @@ public class Day05 : IPuzzleSolver return nextDisplay; } - private static int Replace(int display, string aValue, string bValue) + private static long Replace(long display, string aValue, string bValue) { - return int.Parse(display.ToString().Replace(aValue, bValue)); + return long.Parse(display.ToString().Replace(aValue, bValue)); } } \ No newline at end of file