Skip to content

Commit

Permalink
[2024/6] p1 - add grid path overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlitGhost committed Dec 6, 2024
1 parent 97cc995 commit 84ffacf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions 2024/6/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def move(pos: tuple, dir_: Dir, grid: Grid) -> tuple[tuple, Dir]:

# out of bounds or open, return next position
if not grid.in_bounds(next_pos) or not grid[next_pos] == '#':
return next_pos, dir_
return next_pos.as_tuple(), dir_

# obstacle, rotate right 90 degrees
else:
Expand All @@ -17,7 +17,6 @@ def move(pos: tuple, dir_: Dir, grid: Grid) -> tuple[tuple, Dir]:

def main():
grid = Grid(aoc.read_lines())
print(grid)

pos = grid.find('^')
dir_ = Dir.UP
Expand All @@ -26,8 +25,9 @@ def main():
visited.add(pos)
while grid.in_bounds(pos):
pos, dir_ = move(pos, dir_, grid)
visited.add(pos.as_tuple())
visited.add(pos)

print(grid.render_with_overlays([{pos: 'X' for pos in visited}]))
print("p1:", len(visited) - 1)


Expand Down

0 comments on commit 84ffacf

Please sign in to comment.