#!/usr/bin/env python # coding: utf-8 # # Puzzle 2 of AoC 2025 # Author: Victoria Ramírez López # # Date: Dec 3, 2025 # In[60]: # Read input file battery_banks = open('battery_banks.txt', mode ='r') # Open in 'read only' mode # In[61]: # Select 2 batteries per bank to turn on max_joltages = [] for bank in battery_banks: bank_string = bank.strip('\n') bank_joltage = calculate_max_joltage(battery_list[0]) # For part 1 max_joltages.append(bank_joltage) sum_joltages = sum(max_joltages) print(max_joltages) print(sum_joltages) # In[59]: def calculate_max_joltage(bank = ''): # This function calculates the max joltage # that can be achieved in a battery bank # when turning on 2 batteries # input: bank = String # output: max_joltage = int # Create a list containing all the batteries in the bank battery_list = [int(battery) for battery in bank_string] # Find the battery with the highest number max_battery = max(battery_list[:-1]) max_position = battery_list.index(max_battery) if max_position == len(battery_list) - 1: max_joltage = (battery_list[max_position] * 10) + battery_list[-1] else: second_max_battery = max(battery_list[max_position + 1:]) second_max_position = battery_list.index(second_max_battery) max_joltage = (battery_list[max_position] * 10) + battery_list[second_max_position] return max_joltage # In[ ]: ## Unfinished start of part 2 def calculate_max_joltage_12(bank = ''): # This function calculates the max joltage # that can be achieved with a battery bank # when turning on 12 batteries # Create a list containing all the batteries in the bank battery_list = [int(battery) for battery in bank_string] # Find the battery with the highest number max_battery = max(battery_list[:-11]) max_position = battery_list.index(max_battery) if max_position == len(battery_list) - 1: max_joltage_list = [battery_list[i] * 10**(-i-1) for i in range(-12,0)] max_joltage = sum(max_joltage_list) else: for battery in battery_list(