box-o-sand/aoc2020/day03/solution.py
2021-01-03 21:40:57 -05:00

34 lines
700 B
Python

import sys
import typing
class Loc(typing.NamedTuple):
x: int
y: int
def main() -> int:
forest_frame = [list(line.strip()) for line in sys.stdin.readlines()]
frame_width = len(forest_frame[0])
frame_height = len(forest_frame)
loc = Loc(x=0, y=0)
trees_encountered = 0
while loc.y <= (frame_height - 1):
at_loc = forest_frame[loc.y][loc.x]
if at_loc == "#":
trees_encountered += 1
next_x = (loc.x + 3) % frame_width
next_y = loc.y + 1
next_loc = Loc(x=next_x, y=next_y)
loc = next_loc
print(f"trees encountered: {trees_encountered}")
return 0
if __name__ == "__main__":
sys.exit(main())