-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalu.py
63 lines (45 loc) · 1.46 KB
/
alu.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import collections, itertools, re, copy
def get_input():
with open('input', 'r') as file:
contents = file.read().strip().split('\n')
contents = [line.split(' ') for line in contents]
return contents
inst = get_input()
def monad(num, inst):
num = list(str(num))
iter_nums = iter(num)
assert len(num) == 14
vals = {'x': 0, 'y': 0, 'z': 0, 'w': 0}
for line in inst:
oper = line[0]
if oper == 'inp':
vals['w'] = int(next(iter_nums))
else:
oper1 = vals[line[1]]
oper2 = vals[line[2]] if line[2] in vals else int(line[2])
if oper == 'add':
vals[line[1]] = oper1 + oper2
elif oper == 'mul':
vals[line[1]] = oper1 * oper2
elif oper == 'div':
vals[line[1]] = oper1 // oper2
elif oper == 'mod':
vals[line[1]] = oper1 % oper2
elif oper == 'eql':
vals[line[1]] = 1 if oper1 == oper2 else 0
else:
raise Exception('Unknown instruction')
print(line)
print(vals)
return vals['z']
monad(99999999999999, inst)
#step = 0
#states = {}
#for i in range(99999932596000, 11111111111111, -1):
# if '0' in str(i): continue
# step += 1
# if step % 100000 == 0: print(i)
# if monad(i, inst, states) == 0:
# with open(solution, 'a') as file:
# print(i)
# break