Created
December 4, 2020 06:04
-
-
Save redspider/9b750364dd54be9e3710ae6e755b4c49 to your computer and use it in GitHub Desktop.
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
WIDTH = len(INPUT.split("\n")[0]) | |
# Part 1 | |
trees = 0 | |
for i, line in enumerate(INPUT.split("\n")): | |
if line[i * 3 % WIDTH] == '#': | |
trees += 1 | |
print(trees) | |
WIDTH = len(INPUT.split("\n")[0]) | |
# Part 2 | |
product = 1 | |
for right_shift, down_shift in [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)]: | |
trees = 0 | |
for i, line in enumerate(INPUT.split("\n")): | |
if i % down_shift == 0: | |
if line[int(i * (right_shift / down_shift)) % WIDTH] == '#': | |
trees += 1 | |
product *= trees | |
print(product) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment