What on earth with the trees

This commit is contained in:
Dan Buch 2021-01-03 21:40:14 -05:00
parent 17c3ee9316
commit d402fb4bc7
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

34
aoc2020/day03/solution.py Normal file
View File

@ -0,0 +1,34 @@
import pprint
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())