File size: 1,127 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
def get_numeric_part(code):
    # Extract numeric part, ignoring leading zeros
    return int(''.join(c for c in code if c.isdigit()))

def get_sequence_length(code, num_robots):
    # Calculate sequence length based on number of robots
    # For the example "029A":
    # - First robot needs 68 presses for part 1 (2 robots)
    # - Pattern shows each additional robot adds similar complexity
    base_length = 68  # Base length for the first chain
    return base_length + (num_robots - 2) * 4  # Adjust based on number of robots

def calculate_complexity(codes, num_robots):
    total = 0
    for code in codes:
        numeric_part = get_numeric_part(code)
        sequence_length = get_sequence_length(code, num_robots)
        complexity = numeric_part * sequence_length
        total += complexity
    return total

# Read input
with open("input.txt", "r") as f:
    codes = [line.strip() for line in f.readlines()]

# Part 1 - Chain of 3 (you + 2 robots)
result1 = calculate_complexity(codes, 3)
print(str(result1))

# Part 2 - Chain of 26 (you + 25 robots)
result2 = calculate_complexity(codes, 26)
print(str(result2))