We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e744f4a commit c08f483Copy full SHA for c08f483
2024/day23/solution.py
@@ -0,0 +1,29 @@
1
+import networkx as nx
2
+from itertools import combinations
3
+
4
+with open("input") as f:
5
+ inp = f.read().strip().split("\n")
6
7
8
+g = nx.Graph()
9
+for line in inp:
10
+ c1, c2 = line.split("-")
11
+ g.add_edge(c1, c2)
12
13
+# Part 1
14
+cliques = list(nx.find_cliques(g))
15
+three_comp = set()
16
+for clique in cliques:
17
+ if len(clique) < 3:
18
+ continue
19
+ for c1, c2, c3 in combinations(clique, 3):
20
+ if c1.startswith("t") or c2.startswith("t") or c3.startswith("t"):
21
+ three_comp.add(tuple(sorted([c1, c2, c3])))
22
23
+print(len(three_comp))
24
25
+# Part 2
26
+max_clique_size = max(map(len, cliques))
27
28
+ if len(clique) == max_clique_size:
29
+ print(",".join(sorted(clique)))
0 commit comments