Created
December 23, 2024 12:01
-
-
Save nickponline/408de698a6368cc3045ed680c66d4561 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://adventofcode.com/2024/day/23 | |
| import networkx as nx, re | |
| graph = nx.Graph() | |
| with open('2024-23.in') as f: | |
| graph.add_edges_from([(source, target) for source, target in re.findall(r'(\w+)-(\w+)', f.read())]) | |
| cliques = list(nx.enumerate_all_cliques(graph)) | |
| def solve_part_1(cliques, size=3, prefix='t'): | |
| return len([c for c in cliques if len(c) == size and any(n.startswith(prefix) for n in c)]) | |
| def solve_part_2(cliques): | |
| largest_clique = max(cliques, key=len) | |
| return ",".join(sorted(largest_clique)) | |
| print(solve_part_1(cliques, 3, 't')) | |
| print(solve_part_2(cliques)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment