-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8b.py
More file actions
47 lines (42 loc) · 1.19 KB
/
8b.py
File metadata and controls
47 lines (42 loc) · 1.19 KB
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
#Advent of code
# 06/16/21 day8 8b
#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}")
if pc >= maxindex:
print(f"pc exceeded program length due to jmp")
break
continue # start processing at new pc, dont increment
else:
print(f"ERROR: syntax {line}")
break
pc += 1 # won't run for a jmp
if pc >= maxindex:
print(f"executing past last instruction. program complete")
break
print(f"final pc = {pc}, acc = {acc}")