-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday8.py
63 lines (48 loc) · 1.52 KB
/
day8.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
from utils import readInput
Registers = {}
def eq(reg, val):
return Registers[reg] == val
def neq(reg, val):
return not eq(reg, val)
def largerEqual(reg, val):
return Registers[reg] >= val
def smallerEqual(reg, val):
return Registers[reg] <= val
def larger(reg, val):
return not smallerEqual(reg, val)
def smaller(reg, val):
return not largerEqual(reg, val)
def runConditions(reg, op, value):
conditions = {
'==' : eq,
'!=' : neq,
'<' : smaller,
'<=' : smallerEqual,
'>' : larger,
'>=' : largerEqual,
}
return conditions[op](reg, value)
def runLine(splittedLine, highestSeen):
v = highestSeen
if (runConditions(splittedLine[4], splittedLine[5], int(splittedLine[6]))):
if splittedLine[1] == 'inc':
Registers[splittedLine[0]] += int(splittedLine[2])
elif splittedLine[1] == 'dec':
Registers[splittedLine[0]] -= int(splittedLine[2])
else:
raise Exception('Unknown Opertion' + splittedLine[1])
v = Registers[splittedLine[0]]
return v
def Solution1():
lines = readInput("day8Input.txt")
for eachLine in lines:
splitted = eachLine.split(' ')
Registers[splitted[0]] = 0
highestValue = 0
for eachLine in lines:
splitted = eachLine.split(' ')
lineResult = runLine(splitted, highestValue)
if lineResult > highestValue:
highestValue = lineResult
return (max(Registers.values()), highestValue)
print(Solution1())