File size: 1,637 Bytes
a4da721
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from collections import defaultdict
from itertools import combinations

def parse_input(file):
    connections = defaultdict(set)
    with open(file, 'r') as f:
        for line in f:
            a, b = line.strip().split('-')
            connections[a].add(b)
            connections[b].add(a)
    return connections

def find_triplets(connections):
    computers = list(connections.keys())
    triplets = []
    
    for a, b, c in combinations(computers, 3):
        if (b in connections[a] and 
            c in connections[a] and 
            c in connections[b]):
            triplets.append((a, b, c))
    
    return triplets

def count_t_triplets(triplets):
    count = 0
    for triplet in triplets:
        if any(comp.startswith('t') for comp in triplet):
            count += 1
    return count

def find_largest_clique(connections):
    computers = list(connections.keys())
    n = len(computers)
    max_clique = []
    
    # Try all possible combinations, starting from largest
    for size in range(n, 0, -1):
        for combo in combinations(computers, size):
            # Check if all computers in combo are connected to each other
            is_clique = all(
                all(b in connections[a] for b in combo if b != a)
                for a in combo
            )
            if is_clique:
                return sorted(combo)
    
    return max_clique

# Part 1
connections = parse_input("input.txt")
triplets = find_triplets(connections)
result1 = str(count_t_triplets(triplets))
print(result1)

# Part 2
largest_clique = find_largest_clique(connections)
result2 = ','.join(largest_clique)
print(result2)