Why on earch

cat-town
Dan Buch 4 years ago
parent 622c3557b4
commit 8479da896e
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

@ -1,3 +1,4 @@
import functools
import sys import sys
import typing import typing
@ -11,6 +12,16 @@ def main() -> int:
forest_frame = [list(line.strip()) for line in sys.stdin.readlines()] forest_frame = [list(line.strip()) for line in sys.stdin.readlines()]
frame_width = len(forest_frame[0]) frame_width = len(forest_frame[0])
frame_height = len(forest_frame) frame_height = len(forest_frame)
all_trees_encountered = []
for slope in [
Loc(x=1, y=1),
Loc(x=3, y=1),
Loc(x=5, y=1),
Loc(x=7, y=1),
Loc(x=1, y=2),
]:
loc = Loc(x=0, y=0) loc = Loc(x=0, y=0)
trees_encountered = 0 trees_encountered = 0
@ -20,12 +31,20 @@ def main() -> int:
if at_loc == "#": if at_loc == "#":
trees_encountered += 1 trees_encountered += 1
next_x = (loc.x + 3) % frame_width next_x = (loc.x + slope.x) % frame_width
next_y = loc.y + 1 next_y = loc.y + slope.y
next_loc = Loc(x=next_x, y=next_y) next_loc = Loc(x=next_x, y=next_y)
loc = next_loc loc = next_loc
print(f"trees encountered: {trees_encountered}") print(
f"(slope right={slope.x} down={slope.y}) trees encountered: {trees_encountered}"
)
all_trees_encountered.append(trees_encountered)
trees_encountered_product = functools.reduce(
lambda x, y: x * y, all_trees_encountered
)
print(f"trees encountered product: {trees_encountered_product}")
return 0 return 0

Loading…
Cancel
Save