2017: d05: ex1: add solution
This commit is contained in:
parent
f33f53335a
commit
abd946c749
1 changed files with 27 additions and 0 deletions
27
2017/d05/ex1/ex1.py
Executable file
27
2017/d05/ex1/ex1.py
Executable file
|
|
@ -0,0 +1,27 @@
|
||||||
|
#!/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
|
||||||
|
instructions[offset] += 1
|
||||||
|
offset += instructions[offset] - 1 # 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