Skip to content

Commit 46b6e75

Browse files
committed
Add solution to 2024-12-23
1 parent cb4ce21 commit 46b6e75

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

2024/day23/solutions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from itertools import combinations
2+
import networkx as nx
3+
4+
5+
with open("input") as f:
6+
ls = f.read().strip().split("\n")
7+
8+
G = nx.Graph(l.split("-") for l in ls)
9+
cliques = list(nx.find_cliques(G))
10+
11+
# Part 1
12+
conn = set()
13+
for clique in cliques:
14+
for a, b, c in list(combinations(clique, 3)):
15+
if (
16+
"t" in (a[0], b[0], c[0])
17+
and (a, b) in G.edges()
18+
and (b, c) in G.edges()
19+
and (c, a) in G.edges()
20+
):
21+
conn.add((a, b, c))
22+
print(len(conn))
23+
24+
# Part 2
25+
print(",".join(sorted(max(cliques, key=len))))

0 commit comments

Comments
 (0)