From 9b12fb9d02500c02b2dce746569d32628b379734 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Mon, 7 Dec 2020 07:20:34 +0100 Subject: [PATCH] day7/python: rename functions --- 2020/day7/day7.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/2020/day7/day7.py b/2020/day7/day7.py index 22b9cc2..8394706 100644 --- a/2020/day7/day7.py +++ b/2020/day7/day7.py @@ -27,24 +27,24 @@ def process_rules(rules): return rules_dict -def can_contain(rules, colour): +def parents_of(rules, colour): parents = set() for parent, children in rules.items(): if colour in children: parents.add(parent) - parents |= can_contain(rules, parent) + parents |= parents_of(rules, parent) return parents -def colour_contains(rules, colour): +def children_of(rules, colour): children = defaultdict(lambda: 0) for child_colour, child_num in rules[colour].items(): children[child_colour] += child_num - for col, num in colour_contains(rules, child_colour).items(): + for col, num in children_of(rules, child_colour).items(): children[col] += child_num * num return children if __name__ == '__main__': bag_rules = [rule.strip() for rule in sys.stdin.readlines()] rules = process_rules(bag_rules) - print(len(can_contain(rules, 'shiny gold'))) - print(sum(colour_contains(rules, 'shiny gold').values())) + print(len(parents_of(rules, 'shiny gold'))) + print(sum(children_of(rules, 'shiny gold').values()))