-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday18.py
57 lines (51 loc) · 1.22 KB
/
day18.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
import time
from parse import parse
def part1(input):
def evaluate(input):
if input[-1] == "(":
input.pop()
rez = evaluate(input)
if input[-1] == ")":
input.pop()
else:
rez = int(input.pop())
while len(input)>1 and input[-1] != ")":
if input[-1] == "+":
input.pop()
if input[-1] == "(":
input.pop()
rez += evaluate(input)
if input[-1] == ")":
input.pop()
else:
rez += int(input.pop())
elif input[-1] == "*":
input.pop()
if input[-1] == "(":
input.pop()
rez *= evaluate(input)
if input[-1] == ")":
input.pop()
else:
rez *= int(input.pop())
return rez
sum = 0
for x in input:
sum += evaluate(x)
return sum
def part2(input):
return "pog"
def day18(input, day):
print("Day", day, "part1: ", part1(input))
print("Day", day, "part2: ", part2(input))
if __name__ == "__main__":
day = 18
test = False
# test = True
input=[]
file = "day%d/input.txt" % day
if test:
file = "test.txt"
input = [list(reversed(line.split())) for line in open(file, "r").readlines()]
# print(input[0])
day18(input, day)