Skip to content

Instantly share code, notes, and snippets.

@redspider
Created December 4, 2020 06:04
Show Gist options
  • Save redspider/9b750364dd54be9e3710ae6e755b4c49 to your computer and use it in GitHub Desktop.
Save redspider/9b750364dd54be9e3710ae6e755b4c49 to your computer and use it in GitHub Desktop.
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