advent24-llm / day23 /solution_gemini-1.5-pro.py
jerpint's picture
Add solution files
a4da721
from itertools import combinations
def solve():
with open("./input.txt") as f:
lines = f.readlines()
graph = {}
for line in lines:
a, b = line.strip().split('-')
graph.setdefault(a, set()).add(b)
graph.setdefault(b, set()).add(a)
# Part 1
three_connected_count = 0
for combo in combinations(graph.keys(), 3):
a, b, c = combo
if b in graph[a] and c in graph[a] and a in graph[b] and c in graph[b] and a in graph[c] and b in graph[c]:
if any(x.startswith('t') for x in combo):
three_connected_count += 1
print(three_connected_count)
# Part 2
max_clique_size = 0
max_clique = None
for i in range(1, len(graph) + 1):
for combo in combinations(graph.keys(), i):
is_clique = True
for pair in combinations(combo, 2):
if pair[1] not in graph[pair[0]]:
is_clique = False
break
if is_clique:
if len(combo) > max_clique_size:
max_clique_size = len(combo)
max_clique = sorted(list(combo))
print(",".join(max_clique))
solve()