Day 5
This commit is contained in:
parent
bced65c985
commit
5d8b2b8ae9
2 changed files with 1094 additions and 0 deletions
24
day5.py
Normal file
24
day5.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
with open('input/day5') as f:
|
||||||
|
puzzle_input = tuple(int(line) for line in f.read().splitlines())
|
||||||
|
|
||||||
|
def step(jumps, index):
|
||||||
|
jump = jumps[index]
|
||||||
|
return (jumps[:index] + (offset(jump),) + jumps[index+1:]), index + jump
|
||||||
|
|
||||||
|
def escape(jumps):
|
||||||
|
index = 0
|
||||||
|
steps = 0
|
||||||
|
while 0 <= index < len(jumps):
|
||||||
|
jumps, index = step(jumps, index)
|
||||||
|
steps += 1
|
||||||
|
return steps
|
||||||
|
|
||||||
|
def offset(jump):
|
||||||
|
return jump+1
|
||||||
|
|
||||||
|
# print(escape(puzzle_input))
|
||||||
|
|
||||||
|
def offset(jump):
|
||||||
|
return jump + (-1)**(jump >= 3)
|
||||||
|
|
||||||
|
print(escape(puzzle_input))
|
||||||
1070
input/day5
Normal file
1070
input/day5
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue