Skip to content

Commit d7ffd8a

Browse files
committed
Remove dead code
1 parent 2785155 commit d7ffd8a

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/2024/06/Program.cs

+8-18
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@
44
char[,] map = Resources.GetInputFileLines().ParseAsArray();
55
Coor start = map.AllCoordinates().First(c => map.Get(c) == '^');
66

7-
var directions = new Dictionary<char, Coor>
8-
{
9-
{ '^', Coor.Up },
10-
{ '>', Coor.Right },
11-
{ 'V', Coor.Down },
12-
{ '<', Coor.Left },
13-
};
14-
15-
Simulate(map);
7+
Simulate(map, start);
168
var traversedPath = map.AllCoordinates()
179
.Where(c => map.Get(c) != '.' && map.Get(c) != '#')
1810
.ToList();
@@ -24,7 +16,7 @@
2416
{
2517
var newMap = Resources.GetInputFileLines().ParseAsArray();
2618
newMap.Set(path, '#');
27-
Simulate(newMap);
19+
Simulate(newMap, start);
2820
}
2921
catch (LoopException)
3022
{
@@ -35,20 +27,18 @@
3527
Console.WriteLine($"Part 1: {traversedPath.Count}");
3628
Console.WriteLine($"Part 2: {possibleObstaclePositions}");
3729

38-
static void Simulate(char[,] map)
30+
static void Simulate(char[,] map, Coor position)
3931
{
40-
var position = map.AllCoordinates().First(c => map.Get(c) == '^');
4132
var direction = Coor.Up;
42-
map.Set(position, (char)0);
4333

4434
while (true)
4535
{
4636
var current = map.Get(position);
47-
map.Set(position, (char)(current switch
37+
map.Set(position, current switch
4838
{
49-
'.' => 1,
50-
_ => current + 1,
51-
}));
39+
'.' => '0',
40+
_ => (char)(current + 1),
41+
});
5242

5343
var next = position + direction;
5444
if (!next.InBoundsOf(map))
@@ -64,7 +54,7 @@ static void Simulate(char[,] map)
6454

6555
// We can only come to a field twice (from side and from top/down)
6656
// If we come a third time, it's a loop
67-
if (map.Get(next) != '.' && map.Get(next) > 3)
57+
if (map.Get(next) != '.' && map.Get(next) == '3')
6858
{
6959
throw new LoopException();
7060
}

0 commit comments

Comments
 (0)