summaryrefslogtreecommitdiff
path: root/23_2024.py
diff options
context:
space:
mode:
Diffstat (limited to '23_2024.py')
-rw-r--r--23_2024.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/23_2024.py b/23_2024.py
new file mode 100644
index 0000000..401ad7d
--- /dev/null
+++ b/23_2024.py
@@ -0,0 +1,37 @@
+from collections import defaultdict
+import random
+
+input = "data/23_2024.txt"
+data = open(input).read().strip()
+dic = defaultdict(set)
+for line in data.split("\n"):
+ (
+ a,
+ b,
+ ) = line.split("-")
+ dic[a].add(b)
+ dic[b].add(a)
+xs, p1 = sorted(dic.keys()), 0
+for i, a in enumerate(xs):
+ for j in range(i + 1, len(xs)):
+ for k in range(j + 1, len(xs)):
+ b = xs[j]
+ c = xs[k]
+ if a in dic[b] and a in dic[c] and b in dic[c]:
+ if a.startswith("t") or b.startswith("t") or c.startswith("t"):
+ p1 += 1
+print(p1)
+best = None
+for t in range(1000):
+ random.shuffle(xs)
+ clique = []
+ for x in xs:
+ ok = True
+ for y in clique:
+ if x not in dic[y]:
+ ok = False
+ if ok:
+ clique.append(x)
+ if best is None or len(clique) > len(best):
+ best = clique
+print(",".join(sorted(best)))