Skip to content

Commit 6166e6d

Browse files
committed
Day 7: Part 2 done!
1 parent ed5b176 commit 6166e6d

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

day07/day07.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
def count_bags(graph, node):
88
number = 1
99
for subnode, amount in G[node].items():
10-
print(subnode, amount)
1110
subnum = count_bags(G, subnode)
1211
number += amount['num'] * subnum
13-
print(subnum, number)
1412
return number
1513

1614
if __name__ == "__main__":
@@ -26,26 +24,8 @@ def count_bags(graph, node):
2624
for m in matches:
2725
amount = int(m.group("amount"))
2826
color = m.group("color")
29-
#G.add_node(color)
3027
G.add_edge(left, color, num=int(amount))
3128

3229
print("Part 1: ", len(nx.ancestors(G, 'shiny gold')))
33-
print(nx.descendants(G, 'shiny gold'))
34-
print(G['shiny gold'])
35-
print(count_bags(G, 'shiny gold'))
36-
# print(nx.dfs_predecessors(G,"shiny gold"))
37-
# print(nx.dfs_successors(G,"shiny gold"))
38-
# print(len(nx.dfs_predecessors(G,"shiny gold")))
39-
# print(list(nx.edge_dfs(G,'shiny gold', orientation='reverse')))
40-
# print(list(nx.dfs_edges(G,'shiny gold')))
41-
42-
# print(
43-
# "part 1: ",
44-
# sum([check_group(group) for group in groups]),
45-
# " answered yes",
46-
# )
47-
# print(
48-
# "part 2: ",
49-
# sum([check_group(group, False) for group in groups]),
50-
# " answered yes",
51-
# )
30+
# dont count the topmost shiny gold bag!
31+
print("Part 2: ", count_bags(G, 'shiny gold')-1)

0 commit comments

Comments
 (0)