summaryrefslogtreecommitdiffstats
path: root/20
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-12-09 07:16:38 +0100
committerGustav Sörnäs <gustav@sornas.net>2020-12-09 07:16:38 +0100
commit3a5b2553c855559864842757723dbe2c7f4c5c87 (patch)
treead4e91a4c3262eef0bfc7b0a6b72846b66afab6f /20
parent82c8bb2d12886ff1d34e71fbd543f04886ca3180 (diff)
downloadaoc-3a5b2553c855559864842757723dbe2c7f4c5c87.tar.gz
d7 cleanup
Diffstat (limited to '20')
-rw-r--r--20/py/d07.py17
1 files changed, 2 insertions, 15 deletions
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