forked from cdubz/advent-of-code-2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maze_part_two.py
33 lines (27 loc) · 823 Bytes
/
maze_part_two.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
--- Part Two ---
Now, the jumps are even stranger: after each jump, if the offset was three or
more, instead decrease it by 1. Otherwise, increase it by 1 as before.
Using this rule with the above example, the process now takes 10 steps, and the
offset values after finding the exit are left as 2 3 2 3 -1.
How many steps does it now take to reach the exit?
"""
def run():
maze = {k: int(v) for k, v in enumerate(open('input.txt').read().split())}
pos = 0
steps = 0
while True:
try:
move = maze[pos]
except KeyError:
print(steps)
break
last_pos = pos
pos = last_pos + move
if move >= 3:
maze[last_pos] -= 1
else:
maze[last_pos] += 1
steps += 1
if __name__ == '__main__':
run()