#!/usr/bin/env python # 2025 - Advent Of Code 6 part 2 # file = 'input_example.txt' file = 'input.txt' # pylint: disable=consider-using-with input_lines = [list(line.strip('\n')) for line in open(file, encoding="utf-8")] MAX_X = len(input_lines[0]) MAX_Y = len(input_lines) # for y in range(0, MAX_Y): # for x in range(0, MAX_X): # print(input_lines[y][x], end='') # print() grand_total = 0 operands = [] for c in range(len(input_lines[0]) - 1, -1, -1): res_add = 0 res_mul = 1 num = [] for l in range(0, MAX_Y - 1): if input_lines[l][c] != ' ': num.append(input_lines[l][c]) if num: # print(f'appending {"".join(num)} to operands') operands.append(int("".join(num))) if input_lines[l+1][c] == '+': grand_total += sum(operands) # print(f'adding {sum(operands)}') operands = [] elif input_lines[l+1][c] == '*': total = 1 for x in operands: total *= x grand_total += total # print(f'adding {sum(operands)}') operands = [] print(f'{grand_total=}')