Compare commits
2 Commits
00000120e2
...
000001407e
| Author | SHA1 | Date | |
|---|---|---|---|
|
000001407e
|
|||
|
000001301f
|
@@ -54,7 +54,7 @@ def get(
|
|||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
return f.read().strip()
|
return f.read().rstrip("\n")
|
||||||
|
|
||||||
|
|
||||||
def get_or_download(
|
def get_or_download(
|
||||||
|
|||||||
4
data/example/2025/06.txt
Normal file
4
data/example/2025/06.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
123 328 51 64
|
||||||
|
45 64 387 23
|
||||||
|
6 98 215 314
|
||||||
|
* + * +
|
||||||
52
src/solution/year_2025/day_06.py
Normal file
52
src/solution/year_2025/day_06.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import functools
|
||||||
|
import math
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
def part_1(input_data: str) -> Any:
|
||||||
|
lines = input_data.splitlines()
|
||||||
|
numbers = [list(map(int, line.split())) for line in lines[:-1]]
|
||||||
|
signs = lines[-1].split()
|
||||||
|
|
||||||
|
c = 0
|
||||||
|
for i, x in enumerate(signs):
|
||||||
|
acc = [n[i] for n in numbers]
|
||||||
|
c += sum(acc) if x == "+" else math.prod(acc)
|
||||||
|
|
||||||
|
return c
|
||||||
|
|
||||||
|
|
||||||
|
def part_2(input_data: str) -> Any:
|
||||||
|
lines = input_data.splitlines()
|
||||||
|
numbers = [[int(s) if s != " " else None for s in line] for line in lines[:-1]]
|
||||||
|
signs = [s if s != " " else None for s in lines[-1]]
|
||||||
|
|
||||||
|
idx = len(signs) - 1
|
||||||
|
c = 0
|
||||||
|
|
||||||
|
while idx >= 0:
|
||||||
|
acc = []
|
||||||
|
|
||||||
|
while True:
|
||||||
|
_digits = [n[idx] for n in numbers]
|
||||||
|
digits = [n for n in _digits if n is not None]
|
||||||
|
acc.append(functools.reduce(lambda acc, x: acc * 10 + x, digits))
|
||||||
|
|
||||||
|
sign = signs[idx]
|
||||||
|
|
||||||
|
if sign is not None:
|
||||||
|
c += sum(acc) if sign == "+" else math.prod(acc)
|
||||||
|
idx -= 2
|
||||||
|
break
|
||||||
|
|
||||||
|
idx -= 1
|
||||||
|
|
||||||
|
return c
|
||||||
|
|
||||||
|
|
||||||
|
def test_part_1(example_data):
|
||||||
|
assert part_1(example_data) == 4277556
|
||||||
|
|
||||||
|
|
||||||
|
def test_part_2(example_data):
|
||||||
|
assert part_2(example_data) == 3263827
|
||||||
Reference in New Issue
Block a user