Skip to content

Commit c08f483

Browse files
committed
Add day 23, 2024
1 parent e744f4a commit c08f483

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

2024/day23/solution.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
for clique in cliques:
28+
if len(clique) == max_clique_size:
29+
print(",".join(sorted(clique)))

0 commit comments

Comments
 (0)