2017: d05: ex2: add solution
This commit is contained in:
parent
d69b3b13c4
commit
ca1ceaa487
1 changed files with 28 additions and 0 deletions
28
2017/d05/ex2/ex2.py
Executable file
28
2017/d05/ex2/ex2.py
Executable file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import itertools
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def solve(input: str) -> int:
|
||||||
|
def parse(input: str) -> list[int]:
|
||||||
|
return [int(n) for n in input.splitlines()]
|
||||||
|
|
||||||
|
instructions = parse(input)
|
||||||
|
offset = 0
|
||||||
|
for i in itertools.count():
|
||||||
|
if offset < 0 or offset >= len(instructions):
|
||||||
|
return i
|
||||||
|
delta = -1 if instructions[offset] >= 3 else 1
|
||||||
|
instructions[offset] += delta
|
||||||
|
offset += instructions[offset] - delta # Account for previous increment
|
||||||
|
assert False # Sanity check
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
input = sys.stdin.read()
|
||||||
|
print(solve(input))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue