add: day06: part1
This commit is contained in:
17
2025/day06/part1.py
Normal file
17
2025/day06/part1.py
Normal file
@ -0,0 +1,17 @@
|
||||
import math
|
||||
text: str
|
||||
|
||||
with open("input.txt") as f:
|
||||
text = f.read()
|
||||
|
||||
total: int = 0
|
||||
|
||||
lines: list[str] = text.splitlines()
|
||||
numbers: list[list[int]] = [[int(nb_str) for nb_str in line.split(" ") if len(nb_str)] for line in lines[:-1]]
|
||||
for i, operator in enumerate([operator for operator in lines[-1].split(" ") if len(operator)]):
|
||||
if (operator == "+"):
|
||||
total += sum([numbers[j][i] for j in range(len(lines) - 1)])
|
||||
elif (operator == "*"):
|
||||
total += math.prod([numbers[j][i] for j in range(len(lines) - 1)])
|
||||
|
||||
print(total)
|
||||
Reference in New Issue
Block a user