Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
premun committed Dec 6, 2024
1 parent 2785155 commit d7ffd8a
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/2024/06/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@
char[,] map = Resources.GetInputFileLines().ParseAsArray();
Coor start = map.AllCoordinates().First(c => map.Get(c) == '^');

var directions = new Dictionary<char, Coor>
{
{ '^', Coor.Up },
{ '>', Coor.Right },
{ 'V', Coor.Down },
{ '<', Coor.Left },
};

Simulate(map);
Simulate(map, start);
var traversedPath = map.AllCoordinates()
.Where(c => map.Get(c) != '.' && map.Get(c) != '#')
.ToList();
Expand All @@ -24,7 +16,7 @@
{
var newMap = Resources.GetInputFileLines().ParseAsArray();
newMap.Set(path, '#');
Simulate(newMap);
Simulate(newMap, start);
}
catch (LoopException)
{
Expand All @@ -35,20 +27,18 @@
Console.WriteLine($"Part 1: {traversedPath.Count}");
Console.WriteLine($"Part 2: {possibleObstaclePositions}");

static void Simulate(char[,] map)
static void Simulate(char[,] map, Coor position)
{
var position = map.AllCoordinates().First(c => map.Get(c) == '^');
var direction = Coor.Up;
map.Set(position, (char)0);

while (true)
{
var current = map.Get(position);
map.Set(position, (char)(current switch
map.Set(position, current switch
{
'.' => 1,
_ => current + 1,
}));
'.' => '0',
_ => (char)(current + 1),
});

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

// We can only come to a field twice (from side and from top/down)
// If we come a third time, it's a loop
if (map.Get(next) != '.' && map.Get(next) > 3)
if (map.Get(next) != '.' && map.Get(next) == '3')
{
throw new LoopException();
}
Expand Down

0 comments on commit d7ffd8a

Please sign in to comment.