My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add solution for 2024/23

+30
+30
2024/day23.py
··· 1 + import fileinput 2 + import networkx as nx 3 + 4 + 5 + # Read problem input. 6 + G = nx.Graph() 7 + 8 + for line in fileinput.input(): 9 + a, b = line.strip().split('-') 10 + if a not in G: 11 + G.add_node(a) 12 + if b not in G: 13 + G.add_node(b) 14 + 15 + G.add_edge(a, b) 16 + 17 + 18 + # Solve problem. 19 + part_1 = 0 20 + largest_clique = [] 21 + 22 + for clique in nx.enumerate_all_cliques(G): 23 + if len(clique) > len(largest_clique): 24 + largest_clique = clique 25 + 26 + if len(clique) == 3 and any(n.startswith('t') for n in clique): 27 + part_1 += 1 28 + 29 + print("Part 1:", part_1) 30 + print("Part 2:", ','.join(n for n in sorted(largest_clique)))