What on earth with the trees
This commit is contained in:
parent
17c3ee9316
commit
d402fb4bc7
34
aoc2020/day03/solution.py
Normal file
34
aoc2020/day03/solution.py
Normal 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())
|
Loading…
Reference in New Issue
Block a user