-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAOC7b_20.py
61 lines (53 loc) · 1022 Bytes
/
AOC7b_20.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
#!/usr/bin/python
with open("AOC7.txt", "r") as file:
data = file.read().replace("\n", ";")
mylist = data.split(";")
logic = []
key = []
res = []
for k in mylist:
k = k.split(" ")
temp = []
if k[4] != "no":
i = 4
while i < len(k):
temp.append(k[i])
temp.append(k[i+1]+" "+k[i+2])
i += 4
logic.append(temp)
key.append(k[0]+" "+k[1])
i=0
gold = logic[key.index("shiny gold")]
while i <len(gold):
res.append(gold[i])
i +=1
#print(gold)
up = len(res)
lo = 0
print(res)
while up != lo:
for k in res[lo:up]:
if not k.isnumeric():
for m in key:
if k in m:
i=0
sol = logic[key.index(m)]
while i < len(sol):
if sol[i].isnumeric():
n = int(sol[i])*int(res[res.index(k)-1])
res.append(str(n))
else:
res.append(sol[i])
i += 1
lo=up
up=len(res)
print(res[lo:up])
i=0
check=0
while i < len(res):
check +=int(res[i])
i +=2
print(check)
print(res)
#print(key)
#print(logic)