Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day23(s, *, part2=False):
- graph = networkx.Graph()
- graph.add_edges_from(tuple(line.split('-')) for line in s.splitlines())
- def get_triangles(graph):
- for a in graph:
- for b in graph.neighbors(a):
- if b > a:
- for c in graph.neighbors(a):
- if c > b and graph.has_edge(b, c):
- yield a, b, c
- if not part2:
- triangles = get_triangles(graph)
- return sum(1 for triangle in triangles if any(node[0] == 't' for node in triangle))
- largest_clique = max(networkx.find_cliques(graph), key=len) # (Finds maximal cliques.)
- return ','.join(sorted(largest_clique))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement