From c0d32dfdbddd0b4e3d6f8d8d143a021635cfb2a5 Mon Sep 17 00:00:00 2001 From: Nathan van Ofwegen Date: Mon, 7 Dec 2020 22:02:48 +0100 Subject: [PATCH] joe! --- day7/day7.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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