Extract Coordinate, IntegerRange and Coordinate3d to new AdventOfCode.HelperClasses project and refactor solution for modularity and type consistency
This commit is contained in:
+7
-10
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user