Skip to content

Commit

Permalink
Add solution to 2024-12-06
Browse files Browse the repository at this point in the history
  • Loading branch information
fuglede committed Dec 6, 2024
1 parent 83a34f0 commit b47a9b6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions 2024/day06/solutions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
with open("input") as f:
ls = f.read().strip().split("\n")

board = {i + 1j * j: x for i, l in enumerate(ls) for j, x in enumerate(l)}

# Part 1
start = next(w for w, x in board.items() if x == "^")
walls = {w for w, x in board.items() if x == "#"}
seen = set()
z = start
dz = -1
while z in board:
seen.add(z)
if z + dz in walls:
dz *= -1j
continue
z += dz

print(len(seen))


# Part 2
def loops(x):
new_walls = walls | {x}
z = start
dz = -1
seen = set()
while z in board:
if (z, dz) in seen:
return True
seen.add((z, dz))
if z + dz in new_walls:
dz *= -1j
continue
z += dz
return False


print(sum(map(loops, seen)))

0 comments on commit b47a9b6

Please sign in to comment.