Extract Coordinate, IntegerRange and Coordinate3d to new AdventOfCode.HelperClasses project and refactor solution for modularity and type consistency

This commit is contained in:
Sebastian Lindemeier
2025-12-12 13:14:17 +01:00
parent 85516cd783
commit aaf32260d0
13 changed files with 119 additions and 143 deletions
+7 -10
View File
@@ -1,8 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using AdvenOfCode.Contracts;
using Coordinate = (int x, int y);
using AdvenOfCode.Contracts;
using AdventOfCode.HelperClasses;
namespace AoC_2025;
@@ -64,7 +61,7 @@ public class Day04 : IPuzzleSolver<long>
{
var indexedCharacters = gridLine.Index();
var validRolls = indexedCharacters.Where(tuple => tuple.Item == '@');
var rollCoordinates = validRolls.Select(tuple => (xIndex, tuple.Index));
var rollCoordinates = validRolls.Select(tuple => new Coordinate(xIndex, tuple.Index));
return rollCoordinates;
}
@@ -79,12 +76,12 @@ public class Day04 : IPuzzleSolver<long>
{
Coordinate[] neighbourDirections =
[
(-1, -1), (-1, 0), (-1, 1),
(0, -1), (0, 1),
(1, -1), (1, 0), (1, 1),
new(-1, -1), new(-1, 0), new(-1, 1),
new(0, -1), new(0, 1),
new(1, -1), new(1, 0), new(1, 1),
];
var possibleNeighbours = neighbourDirections
.Select(direction => (coordinate.x + direction.x, coordinate.y + direction.y));
.Select(direction => coordinate + direction);
var actualNeighbours = possibleNeighbours
.Where(coord => coordinates.Contains(coord))
.ToArray();