AoC 2020 D3: Toboggan Trajectory

Python | Problem statement | Source code | Tags: Brute force

← Previous Back to AoC Index Next →

Part 1

There may be smarter ways to do this, but I just simulated the movement of the toboggan. The map repeats infinitely to the right, so I used modulo to wrap around.

cur = (0, 0)
total = 0
while cur[0] < len(grid):
if grid[cur]:
total += 1
cur = (cur[0] + slope[0], (cur[1] + slope[1]) % len(grid[0]))
python

Part 2

Just repeat part 1 for all slopes and multiply the results.

← Previous Back to AoC Index Next →