Spaces:
Sleeping
Sleeping
File size: 1,475 Bytes
cacd58c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # server/tasks/task_easy.py
TASK_EASY = {
"task_id": "task_easy",
"difficulty": "easy",
"num_tests": 4,
"description": (
"Fix the off-by-one error in the `find_max_subarray_sum` function. "
"It should return the maximum contiguous subarray sum (Kadane's algorithm). "
"Currently it misses the last element."
),
# The broken version the agent sees
"buggy_code": """\
def find_max_subarray_sum(nums: list[int]) -> int:
if not nums:
return 0
max_sum = current_sum = nums[0]
# BUG: range stops one short
for i in range(1, len(nums) - 1):
current_sum = max(nums[i], current_sum + nums[i])
max_sum = max(max_sum, current_sum)
return max_sum
""",
# The correct solution (used by task_generator)
"clean_code": """\
def find_max_subarray_sum(nums: list[int]) -> int:
if not nums:
return 0
max_sum = current_sum = nums[0]
for i in range(1, len(nums)):
current_sum = max(nums[i], current_sum + nums[i])
max_sum = max(max_sum, current_sum)
return max_sum
""",
# Hidden test suite — agent never sees this directly
"test_suite": """\
def test_basic():
assert find_max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == 6
def test_all_negative():
assert find_max_subarray_sum([-3, -1, -2]) == -1
def test_single():
assert find_max_subarray_sum([42]) == 42
def test_empty():
assert find_max_subarray_sum([]) == 0
""",
}
|