-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq8_2.py
38 lines (35 loc) · 1.4 KB
/
q8_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
registers = {}
max_val = 0
with open('in.txt', 'r') as in_file:
for line in in_file:
register, operation, amount, _, depends_on_register, logic_operation,\
logic_operand = line.strip().split()
amount, logic_operand = int(amount), int(logic_operand)
registers.setdefault(register, 0)
registers.setdefault(depends_on_register, 0)
perform = False
if logic_operation == "==":
if registers[depends_on_register] == logic_operand:
perform = True
elif logic_operation == ">=":
if registers[depends_on_register] >= logic_operand:
perform = True
elif logic_operation == "<=":
if registers[depends_on_register] <= logic_operand:
perform = True
elif logic_operation == ">":
if registers[depends_on_register] > logic_operand:
perform = True
elif logic_operation == "<":
if registers[depends_on_register] < logic_operand:
perform = True
elif logic_operation == "!=":
if registers[depends_on_register] != logic_operand:
perform = True
if perform:
if operation == "inc":
registers[register] += amount
else:
registers[register] -= amount
max_val = max(max_val, registers[register])
print max_val