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))))