feat: solved day 10 part 1 and part 2

This commit is contained in:
Stevan Freeborn
2024-12-10 20:52:40 -06:00
parent ac95a20479
commit 0cb78ca2d1
6 changed files with 223 additions and 128 deletions
+35
View File
@@ -0,0 +1,35 @@
namespace HoofIt;
record Position(int X, int Y, int Height)
{
public bool TryGetNextPosition(Direction direction, string[] grid, out Position nextPosition)
{
var x = X + direction.XD;
var y = Y + direction.YD;
nextPosition = new(x, y, -1);
var isOffGrid = IsOffGrid(nextPosition, grid);
if (isOffGrid)
{
return false;
}
if (int.TryParse(grid[y][x].ToString(), out var nextPositionHeight) is false)
{
return false;
}
nextPosition = nextPosition with { Height = nextPositionHeight };
return true;
}
private static bool IsOffGrid(Position position, string[] grid)
{
return position.X < 0 ||
position.X > grid[0].Length - 1 ||
position.Y > grid.Length - 1 ||
position.Y < 0;
}
}