Skip to content

Commit

Permalink
2024/06 (#118)
Browse files Browse the repository at this point in the history
* day 06

* fix edge case
  • Loading branch information
wimglenn authored Dec 23, 2024
1 parent 41dccc4 commit 64cff75
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
34 changes: 34 additions & 0 deletions aoc_wim/aoc2024/q06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
--- Day 6: Guard Gallivant ---
https://adventofcode.com/2024/day/6
"""
from aocd import data
from aoc_wim.zgrid import ZGrid


def walk():
z, dz = z0, dz0
seen = {(z, dz)}
while z + dz in grid:
while grid[z + dz] == "#":
dz *= 1j
z += dz
if (z, dz) in seen:
return seen, True
seen.add((z, dz))
return seen, False


grid = ZGrid(data)
z0, dz0 = grid.z("^"), -1j
seen, _ = walk()
path = dict(seen)
print("answer_a:", len(path))

b = 0
path.pop(z0)
for z in path:
grid[z] = "#"
b += walk()[1]
grid[z] = "."
print("answer_b:", b)
12 changes: 12 additions & 0 deletions tests/2024/06/0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
....#.....
.........#
..........
..#.......
.......#..
..........
.#..^.....
........#.
#.........
......#...
41
6

0 comments on commit 64cff75

Please sign in to comment.