-
Notifications
You must be signed in to change notification settings - Fork 0
/
08-2.py
40 lines (35 loc) · 962 Bytes
/
08-2.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
35
36
37
38
39
40
import copy
with open("08-input.txt", "r") as f:
lines = f.readlines()
for i in range(len(lines)):
lines[i] = [0, lines[i]]
def printLines(lines):
for line in lines:
print(line[1])
for j in range(len(lines)):
i = 0
acc = 0
correct_lines = copy.deepcopy(lines)
command, value = lines[j][1].split()
if command == "acc": continue
if command == "jmp":
correct_lines[j][1] = "nop " + value
else:
correct_lines[j][1] = "jmp " + value
program_terminates = False
while correct_lines[i][0] == 0:
correct_lines[i][0] = 1
command, value = correct_lines[i][1].split()
if command == "nop":
i += 1
elif command == "acc":
acc += int(value)
i += 1
else:
i += int(value)
if i == len(correct_lines):
program_terminates = True
break
if program_terminates:
break
print(acc)