Skip to content

Commit 2ef6759

Browse files
committed
Everybody Codes: solve 2025/16 (rough)
1 parent 9072e12 commit 2ef6759

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""Everyone Codes Day N."""
2+
3+
import logging
4+
import math
5+
from lib import helpers
6+
from lib import parsers
7+
8+
log = logging.info
9+
10+
def solve(part: int, data: str) -> int:
11+
"""Solve the parts."""
12+
if part == 1:
13+
# return sum(sum(1 for _ in range(1, 91, i)) for i in data[0])
14+
return sum(90 // i for i in data[0])
15+
16+
spell = []
17+
cols = data[0]
18+
while any(cols):
19+
i = next(i for i, v in enumerate(cols) if v)
20+
for j in range(i, len(cols), i + 1):
21+
assert cols[j]
22+
cols[j] -= 1
23+
spell.append(i + 1)
24+
if part == 2:
25+
return math.prod(spell)
26+
27+
target = 202520252025000
28+
high = 100
29+
while sum(high // i for i in spell) < target:
30+
high *= 2
31+
low = high // 2
32+
while low + 1 < high:
33+
mid = (high + low) // 2
34+
got = sum(mid // i for i in spell)
35+
if got == target:
36+
return mid
37+
elif got > target:
38+
high = mid - 1
39+
else:
40+
low = mid
41+
return high
42+
43+
44+
45+
46+
47+
PARSER = parsers.parse_ints
48+
TEST_DATA = [
49+
]
50+
TESTS = [
51+
(1, "1,2,3,5,9", 193),
52+
(2, "1,2,2,2,2,3,1,2,3,3,1,3,1,2,3,2,1,4,1,3,2,2,1,3,2,2", 270),
53+
(3, "1,2,2,2,2,3,1,2,3,3,1,3,1,2,3,2,1,4,1,3,2,2,1,3,2,2", 94439495762954),
54+
]
55+
56+
if __name__ == "__main__":
57+
helpers.run_solution(globals())

0 commit comments

Comments
 (0)