33 lines
No EOL
872 B
Python
33 lines
No EOL
872 B
Python
#!/usr/bin/env python
|
|
# 2025 - Advent Of Code 6
|
|
|
|
# file = 'input_example.txt'
|
|
file = 'input.txt'
|
|
|
|
# pylint: disable=consider-using-with
|
|
input_lines = [line.strip('\n') for line in open(file, encoding="utf-8")]
|
|
|
|
operands = []
|
|
for line in range(0, len(input_lines) - 1):
|
|
nums = [ int(x) for x in input_lines[line].split(' ') if x != '']
|
|
operands.append(nums)
|
|
|
|
print(operands)
|
|
|
|
operators = [ x for x in input_lines[-1].split(' ') if x != '']
|
|
print(operators)
|
|
|
|
grand_total = 0
|
|
for c in range(0, len(operators)):
|
|
res = 0 if operators[c] == '+' else 1
|
|
for l in range(0, len(operands)):
|
|
if operators[c] == '+':
|
|
res += operands[l][c]
|
|
elif operators[c] == '*':
|
|
res *= operands[l][c]
|
|
else:
|
|
print('unknown operator')
|
|
print(f'adding {res} to grand total')
|
|
grand_total += res
|
|
|
|
print(f'{grand_total=}') |