From 46b6e75a7f4acfa221950a332216b7c880212376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Fuglede=20J=C3=B8rgensen?= Date: Mon, 23 Dec 2024 06:12:38 +0100 Subject: [PATCH] Add solution to 2024-12-23 --- 2024/day23/solutions.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 2024/day23/solutions.py diff --git a/2024/day23/solutions.py b/2024/day23/solutions.py new file mode 100644 index 0000000..9de16e7 --- /dev/null +++ b/2024/day23/solutions.py @@ -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))))