day 10 p 1

This commit is contained in:
2023-12-17 21:51:03 -05:00
parent de28311e69
commit f7a7736a8c
2 changed files with 11 additions and 8 deletions

View File

@@ -41,6 +41,7 @@
<None Remove="Problems\AOC2022\Day9\input.txt" />
<None Remove="Problems\AOC2022\Day9\test.txt" />
<None Remove="Problems\AOC2022\Day9\test2.txt" />
<None Remove="problems\aoc2023\day10\input.txt" />
<None Remove="problems\aoc2023\day10\sample.txt" />
<None Remove="problems\aoc2023\day1\input.txt" />
<None Remove="problems\aoc2023\day2\input.txt" />

View File

@@ -15,7 +15,7 @@ internal class PipeMaze : Problem<int, int>
public override void LoadInput()
{
_maze = ReadInputLines("sample.txt");
_maze = ReadInputLines();
}
public override void CalculatePart1()
@@ -48,6 +48,8 @@ internal class PipeMaze : Problem<int, int>
seen.Add(next, dist);
}
}
Part1 = seen.Values.Max();
}
private (int x, int y) GetStartPointPos()
@@ -80,19 +82,19 @@ internal class PipeMaze : Problem<int, int>
private (int x, int y) GetNextPoint((int x, int y) pos, (int x, int y) prev)
{
var curPipe = _maze[pos.y][pos.x];
var dir = (x: pos.x - prev.x, y: pos.y - prev.y);
(int x, int y) = (pos.x - prev.x, pos.y - prev.y);
if (curPipe == 'S')
return GetStartConnections(pos).First(p => p != prev);
return curPipe switch
{
'|' => (pos.x, pos.y + dir.y),
'-' => (pos.x + dir.x, pos.y),
'L' => (pos.x + dir.y, pos.y + dir.x),
'F' => (pos.x - dir.y, pos.y - dir.x),
'J' => (pos.x - dir.y, pos.y - dir.x),
'7' => (pos.x + dir.y, pos.y + dir.x),
'|' => (pos.x, pos.y + y),
'-' => (pos.x + x, pos.y),
'L' => (pos.x + y, pos.y + x),
'F' => (pos.x - y, pos.y - x),
'J' => (pos.x - y, pos.y - x),
'7' => (pos.x + y, pos.y + x),
_ => throw new Exception()
};
}