-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuzzle8.py
More file actions
59 lines (47 loc) · 895 Bytes
/
Copy pathpuzzle8.py
File metadata and controls
59 lines (47 loc) · 895 Bytes
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np
import sys
"""
nop +0 | 1
acc +1 | 2, 8(!)
jmp +4 | 3
acc +3 | 6
jmp -3 | 7
acc -99 |
acc +1 | 4
jmp -4 | 5
acc +6 |
nop +0 | 1
acc +1 | 2, 8(!)
jmp +4 | 3
acc +1 | 4
jmp -4 | 5
acc +3 | 6
jmp -3 | 7
acc +1 | 8(!)
acc -99 |
acc +6 |
"""
with open('day8.in','r') as infile:
lines = infile.readlines()
N = len(lines)
line_nrs = np.ones(N)*-99
accumulator = 0
i=0
for n in range(N):
line = lines[i].strip()
instruction = line.split()[0]
value = line.split()[1]
if i in line_nrs:
print("DONE",instruction,value,'accumulator=',accumulator)
break
line_nrs[n] = i
if instruction == 'acc':
accumulator += int(value)
print(instruction,value,'acc=',accumulator)
i+=1
elif instruction == 'jmp':
print(instruction,value,'acc=',accumulator)
i+=int(value)
elif instruction == 'nop':
print(instruction,value,'acc=',accumulator)
i+=1