{
  "name": "quixbugs-python-kth",
  "description": "Fix bug in: kth",
  "dataset": "quixbugs",
  "instruction": "There is a Python file called kth.py in the current directory. It contains a buggy implementation of the kth algorithm. Find and fix the bug. The fix should be minimal - typically a single line change. Do not rewrite the entire function.",
  "setup_files": {
    "kth.py": "def kth(arr, k):\n    pivot = arr[0]\n    below = [x for x in arr if x < pivot]\n    above = [x for x in arr if x > pivot]\n\n    num_less = len(below)\n    num_lessoreq = len(arr) - len(above)\n\n    if k < num_less:\n        return kth(below, k)\n    elif k >= num_lessoreq:\n        return kth(above, k)\n    else:\n        return pivot\n\n\n\n\"\"\"\nQuickSelect\n\nThis is an efficient equivalent to sorted(arr)[k].\n\nInput:\n    arr: A list of ints\n    k: An int\n\nPrecondition:\n    0 <= k < len(arr)\n\nOutput:\n    The kth-lowest element of arr (0-based)\n\"\"\"\n",
    "test_kth.py": "import sys\n\nfrom kth import kth\n\nFUNC_NAME = \"kth\"\ntest_cases = [[[[1, 2, 3, 4, 5, 6, 7], 4], 5], [[[3, 6, 7, 1, 6, 3, 8, 9], 5], 7], [[[3, 6, 7, 1, 6, 3, 8, 9], 2], 3], [[[2, 6, 8, 3, 5, 7], 0], 2], [[[34, 25, 7, 1, 9], 4], 34], [[[45, 2, 6, 8, 42, 90, 322], 1], 6], [[[45, 2, 6, 8, 42, 90, 322], 6], 322]]\n\npassed = 0\nfailed = 0\nfor tc in test_cases:\n    inputs = tc[0]\n    expected = tc[1]\n    try:\n        result = kth(*inputs)\n        if result == expected:\n            passed += 1\n        else:\n            print(f\"FAIL: {FUNC_NAME}({inputs}) = {result}, expected {expected}\")\n            failed += 1\n    except Exception as e:\n        print(f\"ERROR: {FUNC_NAME}({inputs}) raised {e}\")\n        failed += 1\n\nprint(f\"{passed}/{passed+failed} tests passed\")\nif failed > 0:\n    sys.exit(1)\n"
  },
  "verify": "cd $BENCH_WORK_DIR && python3 test_kth.py",
  "timeout": 180000,
  "tags": [
    "quixbugs",
    "python",
    "bug-fix"
  ]
}