This commit is contained in:
2020-12-07 22:02:48 +01:00
parent 1c9a6171dc
commit c0d32dfdbd

View File

@@ -16,13 +16,13 @@ def gettree():
if words[4] == 'no':
continue
if index == 0:
mBag = words[5] + " " + words[6]
mNum = int(words[4])
tree[top_bag][mBag] = mNum
rule = words[5] + " " + words[6]
num = int(words[4])
tree[top_bag][rule] = num
else:
mBag = words[2] + " " + words[3]
mNum = int(words[1])
tree[top_bag][mBag] = mNum
rule = words[2] + " " + words[3]
num = int(words[1])
tree[top_bag][rule] = num
return tree
@@ -35,15 +35,14 @@ def countShine(bag, tree):
sum = 0
for child in tree[bag]:
sum += countShine(child, tree)
return sum
def countBags(bag, tree):
item = tree[bag]
rule = tree[bag]
sum = 0
for child in item:
sum += item[child] + (item[child] * countBags(child, tree))
for child in rule:
sum += rule[child] + (rule[child] * countBags(child, tree))
return sum