-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8a.py
More file actions
41 lines (36 loc) · 979 Bytes
/
8a.py
File metadata and controls
41 lines (36 loc) · 979 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
#Advent of code
# 06/15/21 day8 8a
#import re
filename = "data8.txt"
file = open(filename)
filestr = file.read()
a_list = filestr.split("\n")
maxindex = len(a_list)
print(a_list)
print(f"maxindex={maxindex}, maxcolumns={len(a_list[0])}")
acc = 0
pc = 0
hasrun_list = [0] * maxindex
while pc >= 0:
if hasrun_list[pc] != 0:
print(f"line already run, exiting pc = {pc}, acc = {acc}")
break
hasrun_list[pc] = 1
line = a_list[pc]
oper, arg = line.split(" ")
print(f"pc = {pc}, oper = {oper}, arg = {arg}")
arg_int = int(arg)
if oper == "nop":
print(f"nop exec")
elif oper == "acc":
acc += arg_int
print(f"acc new = {acc}")
elif oper == "jmp":
pc += arg_int
print(f"jmp {arg_int}, new pc = {pc}")
continue # start processing at new pc, dont increment
else:
print(f"ERROR: syntax {line}")
break
pc += 1
print(f"final pc = {pc}, acc = {acc}")