-
Notifications
You must be signed in to change notification settings - Fork 0
/
day5.py
34 lines (28 loc) · 899 Bytes
/
day5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def Solution1(inputFile):
instructions = []
with open(inputFile, "r") as f:
for eachLine in f:
instructions.append(int(eachLine.strip()))
curr = 0
steps = 0
while (curr < len(instructions) and curr >= 0):
steps += 1
next = curr + instructions[curr]
instructions[curr] = instructions[curr]+1
curr = next
return steps
def Solution2(inputFile):
instructions = []
with open(inputFile, "r") as f:
for eachLine in f:
instructions.append(int(eachLine.strip()))
curr = 0
steps = 0
while (curr < len(instructions) and curr >= 0):
steps += 1
offset = instructions[curr]
instructions[curr] = instructions[curr]+1 if offset < 3 else instructions[curr]-1
curr = curr+offset
return steps
print(Solution1("day5Input.txt"))
print(Solution2("day5Input.txt"))