Checkpoint experiments through SWE pilot v2

This commit is contained in:
pj committed 2026-09-15 15:46:10 +05:30
1 parent abacd5c5e1
commit 72d77018d8
845 files changed
+431756 -41

No files matched your search

@@ -0,0 +1,51 @@
def count_beautiful_integers(low: int, high: int, k: int) -> int:
""" Count the number of beautiful integers in the range [low, high].
A number is beautiful if it meets both conditions:
1. The count of even digits equals the count of odd digits
2. The number is divisible by k
Args:
low: Lower bound of the range (inclusive), 0 < low <= high <= 10^9
high: Upper bound of the range (inclusive)
k: Divisor to check, 0 < k <= 20
Returns:
The count of beautiful integers in the given range
>>> count_beautiful_integers(10, 20, 3)
2
>>> count_beautiful_integers(1, 10, 1)
1
>>> count_beautiful_integers(5, 5, 2)
0
"""
from functools import lru_cache
def count_upto(n: int) -> int:
if n <= 0:
return 0
digits = tuple(map(int, str(n)))
m = len(digits)
@lru_cache(maxsize=None)
def dp(pos: int, bal: int, rem: int, tight: bool, started: bool) -> int:
# pos: index in digits, bal = (#even - #odd) so far, rem = value mod k
if pos == m:
return 1 if (started and bal == 0 and rem == 0) else 0
limit = digits[pos] if tight else 9
total = 0
for d in range(limit + 1):
ntight = tight and (d == limit)
nstarted = started or (d != 0)
if not nstarted:
total += dp(pos + 1, 0, 0, ntight, False)
else:
nbal = bal + (1 if (d % 2 == 0) else -1)
nrem = (rem * 10 + d) % k
total += dp(pos + 1, nbal, nrem, ntight, True)
return total
return dp(0, 0, 0, True, False)
return count_upto(high) - count_upto(low - 1)
@@ -0,0 +1,3 @@
import runpy
runpy.run_path('/workspace/test.py', run_name='__main__')
print('REPLAY_COMPLETED')
@@ -0,0 +1,37 @@
{
"create_command": [
"docker",
"create",
"--name",
"board-artifact-validation-3fde067ba5f9",
"--network",
"none",
"--memory",
"512m",
"--pids-limit",
"64",
"--cap-drop",
"ALL",
"--security-opt",
"no-new-privileges",
"--user",
"65534:65534",
"--workdir",
"/workspace",
"aisiuk/inspect-tool-support",
"python3",
"-B",
"/workspace/probe.py"
],
"network_mode": "none",
"mounts": [],
"image_id": "sha256:fb045da8203aea656785c758f7147b003cfe21f213e9048a38be0a33242a5b3d",
"docker_start_exit_code": 0,
"container_exit_code": 0,
"timed_out": false,
"files_sha256": {
"func.py": "923e50e5144c440c221322ff929bf72659cec20920dcc5221f9b0ea9dcea0e12",
"test.py": "a5e33e48668e81abdb14f31771f9f8c751d17747337412ed341c241c89c5f2ab",
"probe.py": "010f28d35c16feb589ee22de82f1b579e04fc1f3f415862e2db86598e230b5ef"
}
}
Whitespace-only changes.
@@ -0,0 +1,2 @@
All tests passed!
REPLAY_COMPLETED
@@ -0,0 +1,25 @@
from func import count_beautiful_integers
def test_func(candidate):
# Example test cases
assert candidate(10, 20, 3) == 2
assert candidate(1, 10, 1) == 1
assert candidate(5, 5, 2) == 0
# Additional test cases
assert candidate(1, 1, 1) == 0
assert candidate(19, 50, 2) == 6
assert candidate(94, 94, 9) == 0
assert candidate(94, 100, 1) == 3
assert candidate(52, 396, 9) == 5
assert candidate(47, 735, 2) == 15
assert candidate(90, 110, 16) == 1
assert candidate(934, 991, 1) == 0
assert candidate(1, 1000000000, 1) == 24894045
assert candidate(33340762, 612987024, 1) == 18196584
assert candidate(36954768, 642296821, 14) == 1240042
assert candidate(17946863, 807558969, 17) == 1319380
if __name__ == "__main__":
test_func(count_beautiful_integers)
print("All tests passed!")