From 5fd9cc26d856401657b56659667e1c1c5dd9749c Mon Sep 17 00:00:00 2001 From: Sebastian Lindemeier Date: Thu, 3 Dec 2026 11:10:25 +0100 Subject: [PATCH] Refactor Day02 waypoint lookup and Day03 corner helper --- AoC_2026/Day02.cs | 14 +++----------- AoC_2026/Day03.cs | 12 ++++++------ 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/AoC_2026/Day02.cs b/AoC_2026/Day02.cs index abf08b4..d51c859 100644 --- a/AoC_2026/Day02.cs +++ b/AoC_2026/Day02.cs @@ -5,15 +5,7 @@ namespace AoC_2026; public class Day02 : IPuzzleSolver { - private static readonly Dictionary WaypointIndex = new Dictionary() - { - ['r'] = 0, - ['o'] = 1, - ['y'] = 2, - ['g'] = 3, - ['b'] = 4, - ['v'] = 5 - }; + private const string WaypointSequence = "roygbv"; private string ParsePuzzleInput(string path) { @@ -39,8 +31,8 @@ public class Day02 : IPuzzleSolver private static int GetDistance(char current, char next) { - var dist = WaypointIndex[next] - WaypointIndex[current]; - return dist > 0 ? dist : dist + WaypointIndex.Count; + var dist = WaypointSequence.IndexOf(next) - WaypointSequence.IndexOf(current); + return dist > 0 ? dist : dist + WaypointSequence.Length; } public long SolvePart2(string pathToPuzzleInput) diff --git a/AoC_2026/Day03.cs b/AoC_2026/Day03.cs index e1d217a..d2a71a7 100644 --- a/AoC_2026/Day03.cs +++ b/AoC_2026/Day03.cs @@ -92,19 +92,19 @@ public class Day03 : IPuzzleSolver { for (var skewAmount = 0; skewAmount < gridWidth - 1; skewAmount++) { - var corners = GetSquareCorners(coord.x, coord.y, skewAmount, squareWidth); + var corners = GetSquareCorners(coord, skewAmount, squareWidth); yield return corners; } } } - private static (int x, int y)[] GetSquareCorners(int x, int y, int skewAmount, int squareWidth) + private static (int x, int y)[] GetSquareCorners((int x, int y) coord, int skewAmount, int squareWidth) { var corners = new (int x, int y)[4]; - corners[0] = (x, y); - corners[1] = (x + skewAmount, y + (squareWidth - skewAmount)); - corners[2] = (x + skewAmount + (squareWidth - skewAmount), y + (squareWidth - skewAmount) - skewAmount); - corners[3] = (x + (squareWidth - skewAmount), y - skewAmount); + corners[0] = coord; + corners[1] = (coord.x + skewAmount, coord.y + (squareWidth - skewAmount)); + corners[2] = (coord.x + skewAmount + (squareWidth - skewAmount), coord.y + (squareWidth - skewAmount) - skewAmount); + corners[3] = (coord.x + (squareWidth - skewAmount), coord.y - skewAmount); return corners; }