Skip to content

Commit

Permalink
Add solution to 2024-12-23
Browse files Browse the repository at this point in the history
  • Loading branch information
fuglede committed Dec 23, 2024
1 parent cb4ce21 commit 46b6e75
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 2024/day23/solutions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from itertools import combinations
import networkx as nx


with open("input") as f:
ls = f.read().strip().split("\n")

G = nx.Graph(l.split("-") for l in ls)
cliques = list(nx.find_cliques(G))

# Part 1
conn = set()
for clique in cliques:
for a, b, c in list(combinations(clique, 3)):
if (
"t" in (a[0], b[0], c[0])
and (a, b) in G.edges()
and (b, c) in G.edges()
and (c, a) in G.edges()
):
conn.add((a, b, c))
print(len(conn))

# Part 2
print(",".join(sorted(max(cliques, key=len))))

0 comments on commit 46b6e75

Please sign in to comment.