From 3dd208c0882fec08a2af5efbfecb607442c65459 Mon Sep 17 00:00:00 2001
From: felixm <mail@felixm.de>
Date: Tue, 24 Dec 2024 11:33:35 -0500
Subject: [PATCH] Solve 2024 day 23

---
 2024/d23.py | 43 +++++++++++++++++++++++++++++++++++++++++++
 README.md   |  2 +-
 2 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 2024/d23.py

diff --git a/2024/d23.py b/2024/d23.py
new file mode 100644
index 0000000..4df9d4d
--- /dev/null
+++ b/2024/d23.py
@@ -0,0 +1,43 @@
+from lib import get_data
+from collections import defaultdict
+
+data = get_data(__file__)
+g = defaultdict(set)
+
+for line in data.splitlines():
+    a, b = line.split("-")
+    g[a].add(b)
+    g[b].add(a)
+
+
+cs = set()
+for a, bs in g.items():
+    for b in bs:
+        for c in g[b]:
+            if c in bs:
+                cs.add(tuple(sorted([a, b, c])))
+
+cs = [t for t in cs if any(x.startswith("t") for x in t)]
+print(len(cs))
+
+
+def find_largest_clique(graph):
+    def bron_kerbosch(r, p, x, max_clique):
+        if not p and not x:
+            if len(r) > len(max_clique[0]):
+                max_clique[0] = r.copy()
+            return
+
+        for v in p.copy():
+            neighbors = graph[v]
+            bron_kerbosch(r | {v}, p & neighbors, x & neighbors, max_clique)
+            p.remove(v)
+            x.add(v)
+
+    max_clique = [set()]
+    bron_kerbosch(set(), set(graph.keys()), set(), max_clique)
+    return max_clique[0]
+
+
+cs = find_largest_clique(g)
+print(",".join(sorted(cs)))
diff --git a/README.md b/README.md
index c449071..2280fd9 100644
--- a/README.md
+++ b/README.md
@@ -313,6 +313,6 @@ and focus. Of course, learning more algorithms and techniques helps.
 - Day 20: `01:08:53  3637      0   01:53:01   2837      0`
 - Day 21: `00:48:40   215      0          -      -      -`
 - Day 22: `00:13:04  1930      0   00:28:29    739      0`
-- Day 23:
+- Day 23: `   >24h  20096      0       >24h  17620      0`
 - Day 24:
 - Day 25: