2025 - Day 6 part 2
This commit is contained in:
parent
95747a5924
commit
4f287fdb14
1 changed files with 41 additions and 0 deletions
41
2025/6/6_2.py
Normal file
41
2025/6/6_2.py
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
#!/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=}')
|
||||||
Loading…
Reference in a new issue