1
0
Fork 0
advent2017/5/5p1.py

30 lines
531 B
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
inputs = ["part1.txt", "input.txt"]
def solve(filename):
mylist = []
with open(filename, "r") as fp:
for line in fp:
mylist.append(int(line))
pos = 0
total = len(mylist) - 1
steps = 0
while True:
oldpos = pos
pos = pos + mylist[pos]
mylist[oldpos] = mylist[oldpos] + 1
steps = steps + 1
if pos > total:
break
return steps
for puzzle in inputs:
print(puzzle, solve(puzzle))