Spaces:
Running
Running
| 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)) |