Why on earch
This commit is contained in:
parent
622c3557b4
commit
8479da896e
@ -1,3 +1,4 @@
|
|||||||
|
import functools
|
||||||
import sys
|
import sys
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
@ -11,21 +12,39 @@ 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)
|
||||||
loc = Loc(x=0, y=0)
|
|
||||||
|
|
||||||
trees_encountered = 0
|
all_trees_encountered = []
|
||||||
|
|
||||||
while loc.y <= (frame_height - 1):
|
for slope in [
|
||||||
at_loc = forest_frame[loc.y][loc.x]
|
Loc(x=1, y=1),
|
||||||
if at_loc == "#":
|
Loc(x=3, y=1),
|
||||||
trees_encountered += 1
|
Loc(x=5, y=1),
|
||||||
|
Loc(x=7, y=1),
|
||||||
|
Loc(x=1, y=2),
|
||||||
|
]:
|
||||||
|
loc = Loc(x=0, y=0)
|
||||||
|
|
||||||
next_x = (loc.x + 3) % frame_width
|
trees_encountered = 0
|
||||||
next_y = loc.y + 1
|
|
||||||
next_loc = Loc(x=next_x, y=next_y)
|
|
||||||
loc = next_loc
|
|
||||||
|
|
||||||
print(f"trees encountered: {trees_encountered}")
|
while loc.y <= (frame_height - 1):
|
||||||
|
at_loc = forest_frame[loc.y][loc.x]
|
||||||
|
if at_loc == "#":
|
||||||
|
trees_encountered += 1
|
||||||
|
|
||||||
|
next_x = (loc.x + slope.x) % frame_width
|
||||||
|
next_y = loc.y + slope.y
|
||||||
|
next_loc = Loc(x=next_x, y=next_y)
|
||||||
|
loc = next_loc
|
||||||
|
|
||||||
|
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…
x
Reference in New Issue
Block a user