From 3a5b2553c855559864842757723dbe2c7f4c5c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 9 Dec 2020 07:16:38 +0100 Subject: d7 cleanup --- 20/py/d07.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to '20/py/d07.py') diff --git a/20/py/d07.py b/20/py/d07.py index fc39ad0..e484f2b 100644 --- a/20/py/d07.py +++ b/20/py/d07.py @@ -10,20 +10,7 @@ class Node: self.children = children def __iter__(self): - for child in self.children: - yield child[0] - - def __repr__(self): - return self.name - - -def graph(nodes): - print("digraph G {") - print("rankdir=\"LR\";") - for node in nodes.values(): - for child in node.children: - print(f"\"{node.name}\" -> \"{child[0].name}\" [ label=\"{child[1]}\" ];") - print("}") + yield from child for child, _ in self.children def parse(_in): @@ -49,7 +36,7 @@ def pt1(_in): def pt2(_in): @functools.cache def count_children(node): - return 1 + sum([child[1] * count_children(child[0]) for child in node.children]) + return 1 + sum(child[1] * count_children(child[0]) for child in node.children) nodes = parse(_in) return count_children(nodes["shiny gold"]) - 1 -- cgit v1.2.1