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

36 lines
644 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
oldvalue = mylist[oldpos]
pos = pos + oldvalue
if oldvalue >= 3:
mylist[oldpos] = oldvalue - 1
else:
mylist[oldpos] = oldvalue + 1
steps = steps + 1
if pos > total:
break
return steps
for puzzle in inputs:
print(puzzle, solve(puzzle))