-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7-2.py
37 lines (35 loc) · 978 Bytes
/
7-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
f = open("Day7Bags.txt", "r")
d = f.read().split("\n")
total = 0
can = list()
cant = list()
temp = list()
running = True
while running:
temp = list(can)
for y in d:
bags = y.replace(" contain ", "-").split('-')
#print(bags)
for z in bags[1].split(','):
inside = z[2:].lstrip(" ").rstrip(".")
if inside in cant:
continue
if inside == "other bag":
cant.append(bags[0])
break
print(inside)
if bags[0] == "shiny gold bag" and not (inside in can):
can.append(inside)
total = total + int(z[:1])
#print("Gold")
if bags[0] in can:
can.append(inside)
total = total + int(z[:1])
if temp == can:
running = False
test = input()
print()
if "shiny gold bag" in can:
can.remove("shiny gold bag")
print(can)
print(total)