Refactor Day02 waypoint lookup and Day03 corner helper

This commit is contained in:
Sebastian Lindemeier committed 2026-12-03 11:10:25 +01:00
1 parent c5732e107f
commit 5fd9cc26d8
2 files changed
+9 -17

No files matched your search

+3 -11
View File
@@ -5,15 +5,7 @@ namespace AoC_2026;
public class Day02 : IPuzzleSolver<long> public class Day02 : IPuzzleSolver<long>
{ {
private static readonly Dictionary<char,int> WaypointIndex = new Dictionary<char,int>() private const string WaypointSequence = "roygbv";
{
['r'] = 0,
['o'] = 1,
['y'] = 2,
['g'] = 3,
['b'] = 4,
['v'] = 5
};
private string ParsePuzzleInput(string path) private string ParsePuzzleInput(string path)
{ {
@@ -39,8 +31,8 @@ public class Day02 : IPuzzleSolver<long>
private static int GetDistance(char current, char next) private static int GetDistance(char current, char next)
{ {
var dist = WaypointIndex[next] - WaypointIndex[current]; var dist = WaypointSequence.IndexOf(next) - WaypointSequence.IndexOf(current);
return dist > 0 ? dist : dist + WaypointIndex.Count; return dist > 0 ? dist : dist + WaypointSequence.Length;
} }
public long SolvePart2(string pathToPuzzleInput) public long SolvePart2(string pathToPuzzleInput)
+6 -6
View File
@@ -92,19 +92,19 @@ public class Day03 : IPuzzleSolver<long>
{ {
for (var skewAmount = 0; skewAmount < gridWidth - 1; skewAmount++) 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; 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]; var corners = new (int x, int y)[4];
corners[0] = (x, y); corners[0] = coord;
corners[1] = (x + skewAmount, y + (squareWidth - skewAmount)); corners[1] = (coord.x + skewAmount, coord.y + (squareWidth - skewAmount));
corners[2] = (x + skewAmount + (squareWidth - skewAmount), y + (squareWidth - skewAmount) - skewAmount); corners[2] = (coord.x + skewAmount + (squareWidth - skewAmount), coord.y + (squareWidth - skewAmount) - skewAmount);
corners[3] = (x + (squareWidth - skewAmount), y - skewAmount); corners[3] = (coord.x + (squareWidth - skewAmount), coord.y - skewAmount);
return corners; return corners;
} }