diff --git a/day7/day7.py b/day7/day7.py index d7aef07..2b97fbb 100644 --- a/day7/day7.py +++ b/day7/day7.py @@ -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