Last active
December 3, 2020 11:23
-
-
Save xpqz/2a4ecacbd3801ec02f35a59d6454ed06 to your computer and use it in GitHub Desktop.
Advent of Code 2020, Day03 in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Day 3: Toboggan Trajectory | |
https://adventofcode.com/2020/day/3 | |
Stefan Kruger | |
""" | |
from math import ceil, prod | |
def path(d, dy, dx): | |
return ((dy * i, (dx * i) % len(d[0])) for i in range(ceil(len(d) / dy))) | |
def trees(d, dy, dx): | |
return sum(d[y][x] == '#' for (y, x) in path(d, dy, dx)) | |
with open('data/test.txt') as f: | |
data = list(f.read().splitlines()) | |
result = [trees(data, *v) for v in [[1, 1], [1, 3], [1, 5], [1, 7], [2, 1]]] | |
print(f"Part1: {result[1]}\nPart2: {prod(result)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment