s1ghhh commited on
Commit
6cc7768
1 Parent(s): 380561f
data/cpp/data/humanevalpack.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/go/data/humanevalpack.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/java/data/humanevalpack.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/js/data/humanevalpack.jsonl ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"task_id": "JavaScript/163", "prompt": "/*\n Given two positive integers a and b, return the even digits between a\n and b, in ascending order.\n\n For example:\n generateIntegers(2, 8) => [2, 4, 6, 8]\n generateIntegers(8, 2) => [2, 4, 6, 8]\n generateIntegers(10, 14) => []\n */\nconst generateIntegers = (a, b) => {\n", "canonical_solution": " if (a > b) {\n let tmp = a;\n a = b;\n b = tmp;\n }\n let y = []\n for (let i = a; i <= b; i++) {\n if (i == 2 || i == 4 || i == 6 || i == 8) { y.push(i) }\n }\n return y\n}\n\n", "test": "const testGenerateIntegers = () => {\n console.assert(\n JSON.stringify(generateIntegers(2, 10)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(10, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(132, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(17, 89)) === JSON.stringify([])\n )\n}\n\ntestGenerateIntegers()\n", "declaration": "\nconst generateIntegers = (a, b) => {\n", "example_test": "const testGenerateIntegers = () => {\n console.assert(\n JSON.stringify(generateIntegers(2, 8)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(8, 2)) === JSON.stringify([2, 4, 6, 8])\n )\n console.assert(\n JSON.stringify(generateIntegers(10, 14)) === JSON.stringify([])\n )\n}\ntestGenerateIntegers()\n", "buggy_solution": " if (a > b) {\n let tmp = a;\n a = b;\n b = tmp;\n }\n let y = []\n for (let i = a; i > b; i++) {\n if (i == 2 || i == 4 || i == 6 || i == 8) { y.push(i) }\n }\n return y\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "generateIntegers", "signature": "const generateIntegers = (a, b)", "docstring": "Given two positive integers a and b, return the even digits between a\nand b, in ascending order.\nFor example:\ngenerateIntegers(2, 8) => [2, 4, 6, 8]\ngenerateIntegers(8, 2) => [2, 4, 6, 8]\ngenerateIntegers(10, 14) => []", "instruction": "Write a JavaScript function `const generateIntegers = (a, b)` to solve the following problem:\nGiven two positive integers a and b, return the even digits between a\nand b, in ascending order.\nFor example:\ngenerateIntegers(2, 8) => [2, 4, 6, 8]\ngenerateIntegers(8, 2) => [2, 4, 6, 8]\ngenerateIntegers(10, 14) => []"}
2
+ {"task_id": "JavaScript/28", "prompt": "/* Concatenate list of strings into a single string\n >>> concatenate([])\n ''\n >>> concatenate(['a', 'b', 'c'])\n 'abc'\n */\nconst concatenate = (strings) => {\n", "canonical_solution": " return strings.join('');\n}\n\n", "test": "const testConcatenate = () => {\n console.assert(concatenate([]) === '')\n console.assert(concatenate(['x', 'y', 'z']) === 'xyz')\n console.assert(concatenate(['x', 'y', 'z', 'w', 'k']) === 'xyzwk')\n}\n\ntestConcatenate()\n", "declaration": "\nconst concatenate = (strings) => {\n", "example_test": "const testConcatenate = () => {\n console.assert(concatenate([]) === '')\n console.assert(concatenate(['a', 'b', 'c']) === 'abc')\n}\ntestConcatenate()\n", "buggy_solution": " return strings.join(' ');\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "concatenate", "signature": "const concatenate = (strings)", "docstring": "Concatenate list of strings into a single string\n>>> concatenate([])\n''\n>>> concatenate(['a', 'b', 'c'])\n'abc'", "instruction": "Write a JavaScript function `const concatenate = (strings)` to solve the following problem:\nConcatenate list of strings into a single string\n>>> concatenate([])\n''\n>>> concatenate(['a', 'b', 'c'])\n'abc'"}
3
+ {"task_id": "JavaScript/6", "prompt": "/* Input to this function is a string represented multiple groups for nested parentheses separated by spaces.\n For each of the group, output the deepest level of nesting of parentheses.\n E.g. (()()) has maximum two levels of nesting while ((())) has three.\n\n >>> parseNestedParens('(()()) ((())) () ((())()())')\n [2, 3, 1, 3]\n */\nconst parseNestedParens = (paren_string) => {\n", "canonical_solution": " var parseParenGroup = function (s) {\n let depth = 0, max_depth = 0;\n for (const c of s) {\n if (c == '(') {\n depth += 1;\n max_depth = Math.max(max_depth, depth);\n } else {\n depth -= 1;\n }\n }\n return max_depth;\n }\n return paren_string.split(' ')\n .filter(x => x != '')\n .map(x => parseParenGroup(x));\n}\n\n", "test": "const testParseNestedParens = () => {\n console.assert(\n JSON.stringify(parseNestedParens('(()()) ((())) () ((())()())')) ===\n JSON.stringify([2, 3, 1, 3])\n )\n console.assert(\n JSON.stringify(parseNestedParens('() (()) ((())) (((())))')) ===\n JSON.stringify([1, 2, 3, 4])\n )\n console.assert(\n JSON.stringify(parseNestedParens('(()(())((())))')) === JSON.stringify([4])\n )\n}\n\ntestParseNestedParens()\n", "declaration": "\nconst parseNestedParens = (paren_string) => {\n", "example_test": "const testParseNestedParens = () => {\n console.assert(\n JSON.stringify(parseNestedParens('(()()) ((())) () ((())()())')) ===\n JSON.stringify([2, 3, 1, 3])\n )\n}\ntestParseNestedParens()\n", "buggy_solution": " var parseParenGroup = function (s) {\n let depth = 0, max_depth = 0;\n for (const c of s) {\n if (c == '(') {\n depth += 1;\n max_depth = Math.max(max_depth, depth);\n } else {\n max_depth -= 1;\n }\n }\n return max_depth;\n }\n return paren_string.split(' ')\n .filter(x => x != '')\n .map(x => parseParenGroup(x));\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "parseNestedParens", "signature": "const parseNestedParens = (paren_string)", "docstring": "Input to this function is a string represented multiple groups for nested parentheses separated by spaces.\nFor each of the group, output the deepest level of nesting of parentheses.\nE.g. (()()) has maximum two levels of nesting while ((())) has three.\n>>> parseNestedParens('(()()) ((())) () ((())()())')\n[2, 3, 1, 3]", "instruction": "Write a JavaScript function `const parseNestedParens = (paren_string)` to solve the following problem:\nInput to this function is a string represented multiple groups for nested parentheses separated by spaces.\nFor each of the group, output the deepest level of nesting of parentheses.\nE.g. (()()) has maximum two levels of nesting while ((())) has three.\n>>> parseNestedParens('(()()) ((())) () ((())()())')\n[2, 3, 1, 3]"}
4
+ {"task_id": "JavaScript/70", "prompt": "/*\n Given list of integers, return list in strange order.\n Strange sorting, is when you start with the minimum value,\n then maximum of the remaining integers, then minimum and so on.\n\n Examples:\n strangeSortList([1, 2, 3, 4]) == [1, 4, 2, 3]\n strangeSortList([5, 5, 5, 5]) == [5, 5, 5, 5]\n strangeSortList([]) == []\n */\nconst strangeSortList = (lst) => {\n", "canonical_solution": " var res = [], sw = true;\n while (lst.length) {\n res.push(sw ? Math.min(...lst) : Math.max(...lst));\n lst.splice(lst.indexOf(res.at(-1)), 1);\n sw = !sw;\n }\n return res;\n}\n\n", "test": "const testStrangeSortList = () => {\n console.assert(\n JSON.stringify(strangeSortList([1, 2, 3, 4])) ===\n JSON.stringify([1, 4, 2, 3])\n )\n console.assert(\n JSON.stringify(strangeSortList([5, 6, 7, 8, 9])) ===\n JSON.stringify([5, 9, 6, 8, 7])\n )\n console.assert(\n JSON.stringify(strangeSortList([1, 2, 3, 4, 5])) ===\n JSON.stringify([1, 5, 2, 4, 3])\n )\n console.assert(\n JSON.stringify(strangeSortList([5, 6, 7, 8, 9, 1])) ===\n JSON.stringify([1, 9, 5, 8, 6, 7])\n )\n console.assert(\n JSON.stringify(strangeSortList([5, 5, 5, 5])) ===\n JSON.stringify([5, 5, 5, 5])\n )\n console.assert(JSON.stringify(strangeSortList([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(strangeSortList([1, 2, 3, 4, 5, 6, 7, 8])) ===\n JSON.stringify([1, 8, 2, 7, 3, 6, 4, 5])\n )\n console.assert(\n JSON.stringify(strangeSortList([0, 2, 2, 2, 5, 5, -5, -5])) ===\n JSON.stringify([-5, 5, -5, 5, 0, 2, 2, 2])\n )\n console.assert(\n JSON.stringify(strangeSortList([111111])) === JSON.stringify([111111])\n )\n}\n\ntestStrangeSortList()\n", "declaration": "\nconst strangeSortList = (lst) => {\n", "example_test": "const testStrangeSortList = () => {\n console.assert(\n JSON.stringify(strangeSortList([1, 2, 3, 4])) ===\n JSON.stringify([1, 4, 2, 3])\n )\n console.assert(\n JSON.stringify(strangeSortList([5, 5, 5, 5])) ===\n JSON.stringify([5, 5, 5, 5])\n )\n console.assert(JSON.stringify(strangeSortList([])) === JSON.stringify([]))\n}\ntestStrangeSortList()\n", "buggy_solution": " var res = [], sw = false;\n while (lst.length) {\n res.push(sw ? Math.min(...lst) : Math.max(...lst));\n lst.splice(lst.indexOf(res.at(-1)), 1);\n sw = !sw;\n }\n return res;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "strangeSortList", "signature": "const strangeSortList = (lst)", "docstring": "Given list of integers, return list in strange order.\nStrange sorting, is when you start with the minimum value,\nthen maximum of the remaining integers, then minimum and so on.\nExamples:\nstrangeSortList([1, 2, 3, 4]) == [1, 4, 2, 3]\nstrangeSortList([5, 5, 5, 5]) == [5, 5, 5, 5]\nstrangeSortList([]) == []", "instruction": "Write a JavaScript function `const strangeSortList = (lst)` to solve the following problem:\nGiven list of integers, return list in strange order.\nStrange sorting, is when you start with the minimum value,\nthen maximum of the remaining integers, then minimum and so on.\nExamples:\nstrangeSortList([1, 2, 3, 4]) == [1, 4, 2, 3]\nstrangeSortList([5, 5, 5, 5]) == [5, 5, 5, 5]\nstrangeSortList([]) == []"}
5
+ {"task_id": "JavaScript/62", "prompt": "/* xs represent coefficients of a polynomial.\n xs[0] + xs[1] * x + xs[2] * x^2 + ....\n Return derivative of this polynomial in the same form.\n >>> derivative([3, 1, 2, 4, 5])\n [1, 4, 12, 20]\n >>> derivative([1, 2, 3])\n [2, 6]\n */\nconst derivative = (xs) => {\n", "canonical_solution": " return xs.map((x, i) => x * i).slice(1);\n}\n\n", "test": "const testDerivative = () => {\n console.assert(\n JSON.stringify(derivative([3, 1, 2, 4, 5])) ===\n JSON.stringify([1, 4, 12, 20])\n )\n console.assert(\n JSON.stringify(derivative([1, 2, 3])) === JSON.stringify([2, 6])\n )\n console.assert(\n JSON.stringify(derivative([3, 2, 1])) === JSON.stringify([2, 2])\n )\n console.assert(\n JSON.stringify(derivative([3, 2, 1, 0, 4])) ===\n JSON.stringify([2, 2, 0, 16])\n )\n console.assert(JSON.stringify(derivative([1])) === JSON.stringify([]))\n}\n\ntestDerivative()\n", "declaration": "\nconst derivative = (xs) => {\n", "example_test": "const testDerivative = () => {\n console.assert(\n JSON.stringify(derivative([3, 1, 2, 4, 5])) ===\n JSON.stringify([1, 4, 12, 20])\n )\n console.assert(\n JSON.stringify(derivative([1, 2, 3])) === JSON.stringify([2, 6])\n )\n}\ntestDerivative()\n", "buggy_solution": " return xs.map((x, i) => x * i);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "derivative", "signature": "const derivative = (xs)", "docstring": "xs represent coefficients of a polynomial.\nxs[0] + xs[1] * x + xs[2] * x^2 + ....\nReturn derivative of this polynomial in the same form.\n>>> derivative([3, 1, 2, 4, 5])\n[1, 4, 12, 20]\n>>> derivative([1, 2, 3])\n[2, 6]", "instruction": "Write a JavaScript function `const derivative = (xs)` to solve the following problem:\nxs represent coefficients of a polynomial.\nxs[0] + xs[1] * x + xs[2] * x^2 + ....\nReturn derivative of this polynomial in the same form.\n>>> derivative([3, 1, 2, 4, 5])\n[1, 4, 12, 20]\n>>> derivative([1, 2, 3])\n[2, 6]"}
6
+ {"task_id": "JavaScript/57", "prompt": "/*Return true is list elements are monotonically increasing or decreasing.\n >>> monotonic([1, 2, 4, 20])\n true\n >>> monotonic([1, 20, 4, 10])\n false\n >>> monotonic([4, 1, 0, -10])\n true\n */\nconst monotonic = (l) => {\n", "canonical_solution": " var sort1 = [...l].sort((a, b) => a - b);\n var sort2 = [...l].sort((a, b) => b - a);\n if (JSON.stringify(l) === JSON.stringify(sort1) ||\n JSON.stringify(l) === JSON.stringify(sort2))\n return true;\n return false;\n}\n\n", "test": "const testMonotonic = () => {\n console.assert(monotonic([1, 2, 4, 10]) === true)\n console.assert(monotonic([1, 2, 4, 20]) === true)\n console.assert(monotonic([1, 20, 4, 10]) === false)\n console.assert(monotonic([4, 1, 0, -10]) === true)\n console.assert(monotonic([4, 1, 1, 0]) === true)\n console.assert(monotonic([1, 2, 3, 2, 5, 60]) === false)\n console.assert(monotonic([1, 2, 3, 4, 5, 60]) === true)\n console.assert(monotonic([9, 9, 9, 9]) === true)\n}\n\ntestMonotonic()\n", "declaration": "\nconst monotonic = (l) => {\n", "example_test": "const testMonotonic = () => {\n console.assert(monotonic([1, 2, 4, 10]) === true)\n console.assert(monotonic([1, 20, 4, 10]) === false)\n console.assert(monotonic([4, 1, 0, -10]) === true)\n}\ntestMonotonic()\n", "buggy_solution": " var sort1 = [...l].sort((a, b) => a - b);\n var sort2 = [...l].sort((a, b) => b - a);\n if (JSON.stringify(l) === JSON.stringify(sort1) ||\n JSON.stringify(l) === JSON.stringify(sort2))\n return false;\n return true;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "monotonic", "signature": "const monotonic = (l)", "docstring": "Return true is list elements are monotonically increasing or decreasing.\n>>> monotonic([1, 2, 4, 20])\ntrue\n>>> monotonic([1, 20, 4, 10])\nfalse\n>>> monotonic([4, 1, 0, -10])\ntrue", "instruction": "Write a JavaScript function `const monotonic = (l)` to solve the following problem:\nReturn true is list elements are monotonically increasing or decreasing.\n>>> monotonic([1, 2, 4, 20])\ntrue\n>>> monotonic([1, 20, 4, 10])\nfalse\n>>> monotonic([4, 1, 0, -10])\ntrue"}
7
+ {"task_id": "JavaScript/35", "prompt": "/*Return maximum element in the list.\n >>> maxElement([1, 2, 3])\n 3\n >>> maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n 123\n */\nconst maxElement = (l) => {\n", "canonical_solution": " return Math.max(...l);\n}\n\n", "test": "const testMaxElement = () => {\n console.assert(maxElement([1, 2, 3]) === 3)\n console.assert(maxElement([5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) === 124)\n}\n\ntestMaxElement()\n", "declaration": "\nconst maxElement = (l) => {\n", "example_test": "const testMaxElement = () => {\n console.assert(maxElement([1, 2, 3]) === 3)\n console.assert(maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) === 123)\n}\ntestMaxElement()\n", "buggy_solution": " return Math.min(...l);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "maxElement", "signature": "const maxElement = (l)", "docstring": "Return maximum element in the list.\n>>> maxElement([1, 2, 3])\n3\n>>> maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n123", "instruction": "Write a JavaScript function `const maxElement = (l)` to solve the following problem:\nReturn maximum element in the list.\n>>> maxElement([1, 2, 3])\n3\n>>> maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n123"}
8
+ {"task_id": "JavaScript/26", "prompt": "/* From a list of integers, remove all elements that occur more than once.\n Keep order of elements left the same as in the input.\n >>> removeDuplicates([1, 2, 3, 2, 4])\n [1, 3, 4]\n */\nconst removeDuplicates = (numbers) => {\n", "canonical_solution": " var dict = new Object();\n for (const num of numbers) {\n if (num in dict) {\n dict[num] += 1;\n } else {\n dict[num] = 1;\n }\n }\n return numbers.filter(x => dict[x] <= 1);\n}\n\n", "test": "const testRemoveDuplicates = () => {\n console.assert(JSON.stringify(removeDuplicates([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(removeDuplicates([1, 2, 3, 4])) ===\n JSON.stringify([1, 2, 3, 4])\n )\n console.assert(\n JSON.stringify(removeDuplicates([1, 2, 3, 2, 4, 3, 5])) ===\n JSON.stringify([1, 4, 5])\n )\n}\n\ntestRemoveDuplicates()\n", "declaration": "\nconst removeDuplicates = (numbers) => {\n", "example_test": "const testRemoveDuplicates = () => {\n console.assert(\n JSON.stringify(removeDuplicates([1, 2, 3, 2,4])) ===\n JSON.stringify([1,3, 4])\n )\n}\ntestRemoveDuplicates()\n", "buggy_solution": " var dict = new Object();\n for (const num of numbers) {\n if (num in dict) {\n dict[num] += 1;\n } else {\n dict[num] = 1;\n }\n }\n return numbers.filter(x > dict[x] < 1);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "removeDuplicates", "signature": "const removeDuplicates = (numbers)", "docstring": "From a list of integers, remove all elements that occur more than once.\nKeep order of elements left the same as in the input.\n>>> removeDuplicates([1, 2, 3, 2, 4])\n[1, 3, 4]", "instruction": "Write a JavaScript function `const removeDuplicates = (numbers)` to solve the following problem:\nFrom a list of integers, remove all elements that occur more than once.\nKeep order of elements left the same as in the input.\n>>> removeDuplicates([1, 2, 3, 2, 4])\n[1, 3, 4]"}
9
+ {"task_id": "JavaScript/139", "prompt": "/*The Brazilian factorial is defined as:\n brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\n where n > 0\n\n For example:\n >>> specialFactorial(4)\n 288\n\n The function will receive an integer as input and should return the special\n factorial of this integer.\n */\nconst specialFactorial = (n) => {\n", "canonical_solution": " let p = 1;\n let t = 1;\n while (n > 1) {\n let y = p;\n while (y > 0) {\n y--;\n t *= n;\n }\n p++;\n n--;\n }\n return t\n}\n\n", "test": "const testSpecialFactorial = () => {\n console.assert(specialFactorial(4) === 288)\n console.assert(specialFactorial(5) === 34560)\n console.assert(specialFactorial(7) === 125411328000)\n console.assert(specialFactorial(1) === 1)\n}\n\ntestSpecialFactorial()\n", "declaration": "\nconst specialFactorial = (n) => {\n", "example_test": "const testSpecialFactorial = () => {\n console.assert(specialFactorial(4) === 288)\n}\ntestSpecialFactorial()\n", "buggy_solution": " let p = 1;\n let t = 1;\n while (n > 1) {\n let y = p;\n while (y > 0) {\n y--;\n n *= y;\n t *= n;\n }\n p++;\n p++;\n n--;\n }\n return t\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "specialFactorial", "signature": "const specialFactorial = (n)", "docstring": "The Brazilian factorial is defined as:\nbrazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\nwhere n > 0\nFor example:\n>>> specialFactorial(4)\n288\nThe function will receive an integer as input and should return the special\nfactorial of this integer.", "instruction": "Write a JavaScript function `const specialFactorial = (n)` to solve the following problem:\nThe Brazilian factorial is defined as:\nbrazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\nwhere n > 0\nFor example:\n>>> specialFactorial(4)\n288\nThe function will receive an integer as input and should return the special\nfactorial of this integer."}
10
+ {"task_id": "JavaScript/22", "prompt": "/* Filter given list of any python values only for integers\n >>> filterIntegers(['a', 3.14, 5])\n [5]\n >>> filterIntegers([1, 2, 3, 'abc', {}, []])\n [1, 2, 3]\n */\nconst filterIntegers = (values) => {\n", "canonical_solution": " return values.filter(x => Number.isInteger(x));\n}\n\n", "test": "const testFilterIntegers = () => {\n console.assert(JSON.stringify(filterIntegers([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(filterIntegers([4, {}, [], 23.2, 9, 'adasd'])) ===\n JSON.stringify([4, 9])\n )\n console.assert(\n JSON.stringify(filterIntegers([3, 'c', 3, 3, 'a', 'b'])) ===\n JSON.stringify([3, 3, 3])\n )\n}\n\ntestFilterIntegers()\n", "declaration": "\nconst filterIntegers = (values) => {\n", "example_test": "const testFilterIntegers = () => {\n console.assert(JSON.stringify(filterIntegers(['a', 3.14, 5])) === JSON.stringify([5]))\n console.assert(\n JSON.stringify(filterIntegers([1, 2, 3, 'abc', {}, []])) ===\n JSON.stringify([1,2,3])\n )\n}\ntestFilterIntegers()\n", "buggy_solution": " values.filter(x => Number.isInteger(x));\n return values;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "filterIntegers", "signature": "const filterIntegers = (values)", "docstring": "Filter given list of any python values only for integers\n>>> filterIntegers(['a', 3.14, 5])\n[5]\n>>> filterIntegers([1, 2, 3, 'abc', {}, []])\n[1, 2, 3]", "instruction": "Write a JavaScript function `const filterIntegers = (values)` to solve the following problem:\nFilter given list of any python values only for integers\n>>> filterIntegers(['a', 3.14, 5])\n[5]\n>>> filterIntegers([1, 2, 3, 'abc', {}, []])\n[1, 2, 3]"}
11
+ {"task_id": "JavaScript/151", "prompt": "/* Given a list of numbers, return the sum of squares of the numbers\n in the list that are odd. Ignore numbers that are negative or not integers.\n doubleTheDifference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\n doubleTheDifference([-1, -2, 0]) == 0\n doubleTheDifference([9, -2]) == 81\n doubleTheDifference([0]) == 0\n If the input list is empty, return 0.\n */\nconst doubleTheDifference = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] % 2 == 1 && lst[i] > 0) {\n p += lst[i] * lst[i]\n }\n }\n return p\n}\n\n", "test": "const testDoubleTheDifference = () => {\n console.assert(doubleTheDifference([]) === 0)\n console.assert(doubleTheDifference([5, 4]) === 25)\n console.assert(doubleTheDifference([0.1, 0.2, 0.3]) === 0)\n console.assert(doubleTheDifference([-10, -20, -30]) === 0)\n console.assert(doubleTheDifference([-1, -2, 8]) === 0)\n console.assert(doubleTheDifference([0.2, 3, 5]) === 34)\n let lst = []\n let odd_sum = 0\n for (let i = -99; i < 100; i += 2) {\n if (i % 2 != 0 && i > 0) { odd_sum += i * i }\n lst.push(i)\n }\n console.assert(doubleTheDifference(lst) === odd_sum)\n}\ntestDoubleTheDifference()\n", "declaration": "\nconst doubleTheDifference = (lst) => {\n", "example_test": "const testDoubleTheDifference = () => {\n console.assert(doubleTheDifference([1,3,2,0]) === 10)\n console.assert(doubleTheDifference([-1,-2,0]) === 0)\n console.assert(doubleTheDifference([9,-2]) === 81)\n console.assert(doubleTheDifference([0]) === 0)\n}\ntestDoubleTheDifference()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "doubleTheDifference", "signature": "const doubleTheDifference = (lst)", "docstring": "Given a list of numbers, return the sum of squares of the numbers\nin the list that are odd. Ignore numbers that are negative or not integers.\ndoubleTheDifference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\ndoubleTheDifference([-1, -2, 0]) == 0\ndoubleTheDifference([9, -2]) == 81\ndoubleTheDifference([0]) == 0\nIf the input list is empty, return 0.", "instruction": "Write a JavaScript function `const doubleTheDifference = (lst)` to solve the following problem:\nGiven a list of numbers, return the sum of squares of the numbers\nin the list that are odd. Ignore numbers that are negative or not integers.\ndoubleTheDifference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\ndoubleTheDifference([-1, -2, 0]) == 0\ndoubleTheDifference([9, -2]) == 81\ndoubleTheDifference([0]) == 0\nIf the input list is empty, return 0."}
12
+ {"task_id": "JavaScript/108", "prompt": "/*\n Write a function countNums which takes an array of integers and returns\n the number of elements which has a sum of digits > 0.\n If a number is negative, then its first signed digit will be negative:\n e.g. -123 has signed digits -1, 2, and 3.\n >>> countNums([]) == 0\n >>> countNums([-1, 11, -11]) == 1\n >>> countNums([1, 1, 2]) == 3\n */\nconst countNums = (arr) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < arr.length; i++) {\n let h = arr[i]\n if (h > 0) {\n p++;\n continue;\n }\n let k = 0\n h = -h\n while (h >= 10) {\n k += h % 10;\n h = (h - h % 10) / 10;\n }\n k -= h;\n if (k > 0) { p++ }\n }\n return p\n}\n\n", "test": "const testCountNums = () => {\n console.assert(countNums([]) === 0)\n console.assert(countNums([-1, -2, 0]) === 0)\n console.assert(countNums([1, 1, 2, -2, 3, 4, 5]) === 6)\n console.assert(countNums([1, 6, 9, -6, 0, 1, 5]) === 5)\n console.assert(countNums([1, 100, 98, -7, 1, -1]) === 4)\n console.assert(countNums([12, 23, 34, -45, -56, 0]) === 5)\n console.assert(countNums([-0, 1 ** 0]) === 1)\n console.assert(countNums([1]) === 1)\n}\n\ntestCountNums()\n", "declaration": "\nconst countNums = (arr) => {\n", "example_test": "const testCountNums = () => {\n console.assert(countNums([]) === 0)\n console.assert(countNums([-1, 11, -11]) === 1)\n console.assert(countNums([1, 1, 2]) === 3)\n}\ntestCountNums()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < arr.length; i++) {\n let h = arr[i]\n if (h > 0) {\n p++;\n continue;\n }\n let k = 0\n h = -h\n while (h >= 10) {\n k += h % 10 * -1;\n h = (h - h % 10) / 10;\n }\n k -= h;\n if (k > 0) { p++ }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "countNums", "signature": "const countNums = (arr)", "docstring": "Write a function countNums which takes an array of integers and returns\nthe number of elements which has a sum of digits > 0.\nIf a number is negative, then its first signed digit will be negative:\ne.g. -123 has signed digits -1, 2, and 3.\n>>> countNums([]) == 0\n>>> countNums([-1, 11, -11]) == 1\n>>> countNums([1, 1, 2]) == 3", "instruction": "Write a JavaScript function `const countNums = (arr)` to solve the following problem:\nWrite a function countNums which takes an array of integers and returns\nthe number of elements which has a sum of digits > 0.\nIf a number is negative, then its first signed digit will be negative:\ne.g. -123 has signed digits -1, 2, and 3.\n>>> countNums([]) == 0\n>>> countNums([-1, 11, -11]) == 1\n>>> countNums([1, 1, 2]) == 3"}
13
+ {"task_id": "JavaScript/8", "prompt": "/* For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\n Empty sum should be equal to 0 and empty product should be equal to 1.\n >>> sumProduct([])\n (0, 1)\n >>> sumProduct([1, 2, 3, 4])\n (10, 24)\n */\nconst sumProduct = (numbers, int) => {\n", "canonical_solution": " var sum_value = 0, prod_value = 1;\n for (const n of numbers) {\n sum_value += n;\n prod_value *= n;\n }\n return [sum_value, prod_value];\n}\n\n", "test": "const testSumProduct = () => {\n console.assert(JSON.stringify(sumProduct([])) === JSON.stringify([0, 1]))\n console.assert(\n JSON.stringify(sumProduct([1, 1, 1])) === JSON.stringify([3, 1])\n )\n console.assert(\n JSON.stringify(sumProduct([100, 0])) === JSON.stringify([100, 0])\n )\n console.assert(\n JSON.stringify(\n sumProduct([3, 5, 7])) === JSON.stringify([3 + 5 + 7, 3 * 5 * 7])\n )\n console.assert(JSON.stringify(sumProduct([10])) === JSON.stringify([10, 10]))\n}\n\ntestSumProduct()\n", "declaration": "\nconst sumProduct = (numbers, int) => {\n", "example_test": "const testSumProduct = () => {\n console.assert(JSON.stringify(sumProduct([])) === JSON.stringify([0, 1]))\n console.assert(\n JSON.stringify(sumProduct([1, 2,3,4])) === JSON.stringify([10, 24])\n )\n}\ntestSumProduct()\n", "buggy_solution": " var sum_value = 0, prod_value = 0;\n for (const n of numbers) {\n sum_value += n;\n prod_value *= n;\n }\n return [sum_value, prod_value];\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "sumProduct", "signature": "const sumProduct = (numbers, int)", "docstring": "For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\nEmpty sum should be equal to 0 and empty product should be equal to 1.\n>>> sumProduct([])\n(0, 1)\n>>> sumProduct([1, 2, 3, 4])\n(10, 24)", "instruction": "Write a JavaScript function `const sumProduct = (numbers, int)` to solve the following problem:\nFor a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\nEmpty sum should be equal to 0 and empty product should be equal to 1.\n>>> sumProduct([])\n(0, 1)\n>>> sumProduct([1, 2, 3, 4])\n(10, 24)"}
14
+ {"task_id": "JavaScript/7", "prompt": "/* Filter an input list of strings only for ones that contain given substring\n >>> filterBySubstring([], 'a')\n []\n >>> filterBySubstring(['abc', 'bacd', 'cde', 'array'], 'a')\n ['abc', 'bacd', 'array']\n */\nconst filterBySubstring = (strings, substring) => {\n", "canonical_solution": " return strings.filter(x => x.indexOf(substring) != -1);\n}\n\n", "test": "const testFilterBySubstring = () => {\n console.assert(\n JSON.stringify(filterBySubstring([], 'john')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterBySubstring(\n ['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'],\n 'xxx'\n )\n ) === JSON.stringify(['xxx', 'xxxAAA', 'xxx'])\n )\n console.assert(\n JSON.stringify(\n filterBySubstring(\n ['xxx', 'asd', 'aaaxxy', 'john doe', 'xxxAAA', 'xxx'],\n 'xx'\n )\n ) === JSON.stringify(['xxx', 'aaaxxy', 'xxxAAA', 'xxx'])\n )\n console.assert(\n JSON.stringify(\n filterBySubstring(['grunt', 'trumpet', 'prune', 'gruesome'], 'run')\n ) === JSON.stringify(['grunt', 'prune'])\n )\n}\n\ntestFilterBySubstring()\n", "declaration": "\nconst filterBySubstring = (strings, substring) => {\n", "example_test": "const testFilterBySubstring = () => {\n console.assert(\n JSON.stringify(filterBySubstring([], 'a')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterBySubstring(\n ['abc', 'bacd', 'cde', 'array'], 'a'\n )\n ) === JSON.stringify(['abc', 'bacd', 'array'])\n )\n}\ntestFilterBySubstring()\n", "buggy_solution": " return strings.filter(x => substring.indexOf(x) != -1);\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "filterBySubstring", "signature": "const filterBySubstring = (strings, substring)", "docstring": "Filter an input list of strings only for ones that contain given substring\n>>> filterBySubstring([], 'a')\n[]\n>>> filterBySubstring(['abc', 'bacd', 'cde', 'array'], 'a')\n['abc', 'bacd', 'array']", "instruction": "Write a JavaScript function `const filterBySubstring = (strings, substring)` to solve the following problem:\nFilter an input list of strings only for ones that contain given substring\n>>> filterBySubstring([], 'a')\n[]\n>>> filterBySubstring(['abc', 'bacd', 'cde', 'array'], 'a')\n['abc', 'bacd', 'array']"}
15
+ {"task_id": "JavaScript/23", "prompt": "/* Return length of given string\n >>> strlen('')\n 0\n >>> strlen('abc')\n 3\n */\nconst strlen = (string) => {\n", "canonical_solution": " return string.length;\n}\n\n", "test": "const testStrlen = () => {\n console.assert(strlen('') === 0)\n console.assert(strlen('x') === 1)\n console.assert(strlen('asdasnakj') === 9)\n}\n\ntestStrlen()\n", "declaration": "\nconst strlen = (string) => {\n", "example_test": "const testStrlen = () => {\n console.assert(strlen('') === 0)\n console.assert(strlen('abc') === 3)\n}\ntestStrlen()\n", "buggy_solution": " return string.length - 1;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "strlen", "signature": "const strlen = (string)", "docstring": "Return length of given string\n>>> strlen('')\n0\n>>> strlen('abc')\n3", "instruction": "Write a JavaScript function `const strlen = (string)` to solve the following problem:\nReturn length of given string\n>>> strlen('')\n0\n>>> strlen('abc')\n3"}
16
+ {"task_id": "JavaScript/55", "prompt": "/*Return n-th Fibonacci number.\n >>> fib(10)\n 55\n >>> fib(1)\n 1\n >>> fib(8)\n 21\n */\nconst fib = (n) => {\n", "canonical_solution": " if (n == 0)\n return 0;\n if (n == 1)\n return 1;\n return fib(n - 1) + fib(n - 2);\n}\n\n", "test": "const testFib = () => {\n console.assert(fib(10) === 55)\n console.assert(fib(1) === 1)\n console.assert(fib(8) === 21)\n console.assert(fib(11) === 89)\n console.assert(fib(12) === 144)\n}\n\ntestFib()\n", "declaration": "\nconst fib = (n) => {\n", "example_test": "const testFib = () => {\n console.assert(fib(10) === 55)\n console.assert(fib(1) === 1)\n console.assert(fib(8) === 21)\n}\ntestFib()\n", "buggy_solution": " if (n == 0)\n return 0;\n if (n == 1)\n return 1;\n if (n == 2)\n return 2;\n return fib(n - 1) + fib(n - 2);\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "fib", "signature": "const fib = (n)", "docstring": "Return n-th Fibonacci number.\n>>> fib(10)\n55\n>>> fib(1)\n1\n>>> fib(8)\n21", "instruction": "Write a JavaScript function `const fib = (n)` to solve the following problem:\nReturn n-th Fibonacci number.\n>>> fib(10)\n55\n>>> fib(1)\n1\n>>> fib(8)\n21"}
17
+ {"task_id": "JavaScript/59", "prompt": "/*Return the largest prime factor of n. Assume n > 1 and is not a prime.\n >>> largestPrimeFactor(13195)\n 29\n >>> largestPrimeFactor(2048)\n 2\n */\nconst largestPrimeFactor = (n) => {\n", "canonical_solution": " var isPrime = function (k) {\n if (k < 2)\n return false;\n for (let i = 2; i < k - 1; i++)\n if (k % i == 0)\n return false;\n return true;\n }\n\n var largest = 1;\n for (let j = 2; j < n + 1; j++)\n if (n % j == 0 && isPrime(j))\n largest = Math.max(largest, j);\n return largest;\n}\n\n", "test": "const testLargestPrimeFactor = () => {\n console.assert(largestPrimeFactor(15) === 5)\n console.assert(largestPrimeFactor(27) === 3)\n console.assert(largestPrimeFactor(63) === 7)\n console.assert(largestPrimeFactor(330) === 11)\n console.assert(largestPrimeFactor(13195) === 29)\n}\n\ntestLargestPrimeFactor()\n", "declaration": "\nconst largestPrimeFactor = (n) => {\n", "example_test": "const testLargestPrimeFactor = () => {\n console.assert(largestPrimeFactor(2048) === 2)\n console.assert(largestPrimeFactor(13195) === 29)\n}\ntestLargestPrimeFactor()\n", "buggy_solution": " var isPrime = function (k) {\n if (k < 2)\n return false;\n for (let i = 2; i < k - 1; i++)\n if (k % i == 0)\n return false;\n return true;\n }\n\n var largest = 1;\n for (let j = 2; j < n + 1; j++)\n if (n % j == 0 && isPrime(n))\n largest = Math.max(largest, j);\n return largest;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "largestPrimeFactor", "signature": "const largestPrimeFactor = (n)", "docstring": "Return the largest prime factor of n. Assume n > 1 and is not a prime.\n>>> largestPrimeFactor(13195)\n29\n>>> largestPrimeFactor(2048)\n2", "instruction": "Write a JavaScript function `const largestPrimeFactor = (n)` to solve the following problem:\nReturn the largest prime factor of n. Assume n > 1 and is not a prime.\n>>> largestPrimeFactor(13195)\n29\n>>> largestPrimeFactor(2048)\n2"}
18
+ {"task_id": "JavaScript/129", "prompt": "/*\n Given a grid with N rows and N columns (N >= 2) and a positive integer k, \n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n\n Examples:\n\n Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\n Output: [1, 2, 1]\n\n Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\n Output: [1]\n */\nconst minPath = (grid, k) => {\n", "canonical_solution": " let m = 0\n let n = 0\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid.length; j++) {\n if (grid[i][j] == 1) {\n m = i;\n n = j;\n break;\n }\n }\n }\n let min = grid.length * grid.length\n if (m > 0 && grid[m - 1][n] < min) { min = grid[m - 1][n] }\n if (n > 0 && grid[m][n - 1] < min) { min = grid[m][n - 1] }\n if (m < grid.length - 1 && grid[m + 1][n] < min) { min = grid[m + 1][n] }\n if (n < grid.length - 1 && grid[m][n + 1] < min) { min = grid[m][n + 1] }\n let p = []\n for (let i = 0; i < k; i++) {\n if (i % 2 == 0) { p.push(1) }\n else { p.push(min) }\n }\n return p\n}\n\n", "test": "const testMinPath = () => {\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n ],\n 3\n )\n ) === JSON.stringify([1, 2, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [5, 9, 3],\n [4, 1, 6],\n [7, 8, 2],\n ],\n 1\n )\n ) === JSON.stringify([1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n ],\n 4\n )\n ) === JSON.stringify([1, 2, 1, 2])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [6, 4, 13, 10],\n [5, 7, 12, 1],\n [3, 16, 11, 15],\n [8, 14, 9, 2],\n ],\n 7\n )\n ) === JSON.stringify([1, 10, 1, 10, 1, 10, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [8, 14, 9, 2],\n [6, 4, 13, 15],\n [5, 7, 1, 12],\n [3, 10, 11, 16],\n ],\n 5\n )\n ) === JSON.stringify([1, 7, 1, 7, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [11, 8, 7, 2],\n [5, 16, 14, 4],\n [9, 3, 15, 6],\n [12, 13, 10, 1],\n ],\n 9\n )\n ) === JSON.stringify([1, 6, 1, 6, 1, 6, 1, 6, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [12, 13, 10, 1],\n [9, 3, 15, 6],\n [5, 16, 14, 4],\n [11, 8, 7, 2],\n ],\n 12\n )\n ) === JSON.stringify([1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [2, 7, 4],\n [3, 1, 5],\n [6, 8, 9],\n ],\n 8\n )\n ) === JSON.stringify([1, 3, 1, 3, 1, 3, 1, 3])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [6, 1, 5],\n [3, 8, 9],\n [2, 7, 4],\n ],\n 8\n )\n ) === JSON.stringify([1, 5, 1, 5, 1, 5, 1, 5])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2],\n [3, 4],\n ],\n 10\n )\n ) === JSON.stringify([1, 2, 1, 2, 1, 2, 1, 2, 1, 2])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 3],\n [4, 2],\n ],\n 10\n )\n ) === JSON.stringify([1, 3, 1, 3, 1, 3, 1, 3, 1, 3])\n )\n}\n\ntestMinPath()\n", "declaration": "\nconst minPath = (grid, k) => {\n", "example_test": "const testMinPath = () => {\n console.assert(\n JSON.stringify(\n minPath(\n [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n ],\n 3\n )\n ) === JSON.stringify([1, 2, 1])\n )\n console.assert(\n JSON.stringify(\n minPath(\n [\n [5, 9, 3],\n [4, 1, 6],\n [7, 8, 2],\n ],\n 1\n )\n ) === JSON.stringify([1])\n )\n}\ntestMinPath()\n", "buggy_solution": " let m = 0\n let n = 0\n for (let i = 0; i < grid.length; i++) {\n for (let j = 0; j < grid.length; j++) {\n if (grid[i][j] == 1) {\n m = i;\n n = j;\n break;\n }\n }\n }\n let min = grid.length * grid.length\n if (m > 0 && grid[m - 1][n] < min) { min = grid[m][n] }\n if (n > 0 && grid[m][n - 1] < min) { min = grid[m][n] }\n if (m < grid.length - 1 && grid[m + 1][n] < min) { min = grid[m][n] }\n if (n < grid.length - 1 && grid[m][n + 1] < min) { min = grid[m][n] }\n let p = []\n for (let i = 0; i < k; i++) {\n if (i % 2 == 0) { p.push(1) }\n else { p.push(min) }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "minPath", "signature": "const minPath = (grid, k)", "docstring": "Given a grid with N rows and N columns (N >= 2) and a positive integer k,\neach cell of the grid contains a value. Every integer in the range [1, N * N]\ninclusive appears exactly once on the cells of the grid.\nYou have to find the minimum path of length k in the grid. You can start\nfrom any cell, and in each step you can move to any of the neighbor cells,\nin other words, you can go to cells which share an edge with you current\ncell.\nPlease note that a path of length k means visiting exactly k cells (not\nnecessarily distinct).\nYou CANNOT go off the grid.\nA path A (of length k) is considered less than a path B (of length k) if\nafter making the ordered lists of the values on the cells that A and B go\nthrough (let's call them lst_A and lst_B), lst_A is lexicographically less\nthan lst_B, in other words, there exist an integer index i (1 <= i <= k)\nsuch that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\nlst_A[j] = lst_B[j].\nIt is guaranteed that the answer is unique.\nReturn an ordered list of the values on the cells that the minimum path go through.\nExamples:\nInput: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\nOutput: [1, 2, 1]\nInput: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\nOutput: [1]", "instruction": "Write a JavaScript function `const minPath = (grid, k)` to solve the following problem:\nGiven a grid with N rows and N columns (N >= 2) and a positive integer k,\neach cell of the grid contains a value. Every integer in the range [1, N * N]\ninclusive appears exactly once on the cells of the grid.\nYou have to find the minimum path of length k in the grid. You can start\nfrom any cell, and in each step you can move to any of the neighbor cells,\nin other words, you can go to cells which share an edge with you current\ncell.\nPlease note that a path of length k means visiting exactly k cells (not\nnecessarily distinct).\nYou CANNOT go off the grid.\nA path A (of length k) is considered less than a path B (of length k) if\nafter making the ordered lists of the values on the cells that A and B go\nthrough (let's call them lst_A and lst_B), lst_A is lexicographically less\nthan lst_B, in other words, there exist an integer index i (1 <= i <= k)\nsuch that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\nlst_A[j] = lst_B[j].\nIt is guaranteed that the answer is unique.\nReturn an ordered list of the values on the cells that the minimum path go through.\nExamples:\nInput: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\nOutput: [1, 2, 1]\nInput: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\nOutput: [1]"}
19
+ {"task_id": "JavaScript/161", "prompt": "/*You are given a string s.\n if s[i] is a letter, reverse its case from lower to upper or vise versa, \n otherwise keep it as it is.\n If the string contains no letters, reverse the string.\n The function should return the resulted string.\n Examples\n solve(\"1234\") = \"4321\"\n solve(\"ab\") = \"AB\"\n solve(\"#a@C\") = \"#A@c\"\n */\nconst solve = (s) => {\n", "canonical_solution": " let t = 0\n let p = ''\n for (let i = 0; i < s.length; i++) {\n let y = s[i].charCodeAt()\n if (y >= 65 && y <= 90) {\n y += 32;\n t = 1;\n } else if (y >= 97 && y <= 122) {\n y -= 32;\n t = 1;\n }\n p += String.fromCharCode(y)\n }\n if (t == 1) { return p }\n let u = ''\n for (let i = 0; i < p.length; i++) {\n u += p[p.length - i - 1]\n }\n return u\n}\n\n", "test": "const testSolve = () => {\n console.assert(solve('AsDf') === 'aSdF')\n console.assert(solve('1234') === '4321')\n console.assert(solve('ab') === 'AB')\n console.assert(solve('#a@C') === '#A@c')\n console.assert(solve('#AsdfW^45') === '#aSDFw^45')\n console.assert(solve('#6@2') === '2@6#')\n console.assert(solve('#$a^D') === '#$A^d')\n console.assert(solve('#ccc') === '#CCC')\n}\n\ntestSolve()\n", "declaration": "\nconst solve = (s) => {\n", "example_test": "const testSolve = () => {\n console.assert(solve('1234') === '4321')\n console.assert(solve('ab') === 'AB')\n console.assert(solve('#a@C') === '#A@c')\n}\ntestSolve()\n", "buggy_solution": " let t = 0\n let p = ''\n for (let i = 0; i < s.length; i++) {\n let y = s[i].charCodeAt()\n if (y >= 65 && y <= 90) {\n y += 32;\n t = 1;\n }\n p += String.fromCharCode(y)\n }\n if (t == 1) { return p }\n let u = ''\n for (let i = 0; i < p.length; i++) {\n u += p[p.length - i - 1]\n }\n return u\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "solve", "signature": "const solve = (s)", "docstring": "You are given a string s.\nif s[i] is a letter, reverse its case from lower to upper or vise versa,\notherwise keep it as it is.\nIf the string contains no letters, reverse the string.\nThe function should return the resulted string.\nExamples\nsolve(\"1234\") = \"4321\"\nsolve(\"ab\") = \"AB\"\nsolve(\"#a@C\") = \"#A@c\"", "instruction": "Write a JavaScript function `const solve = (s)` to solve the following problem:\nYou are given a string s.\nif s[i] is a letter, reverse its case from lower to upper or vise versa,\notherwise keep it as it is.\nIf the string contains no letters, reverse the string.\nThe function should return the resulted string.\nExamples\nsolve(\"1234\") = \"4321\"\nsolve(\"ab\") = \"AB\"\nsolve(\"#a@C\") = \"#A@c\""}
20
+ {"task_id": "JavaScript/143", "prompt": "/*\n You are given a string representing a sentence,\n the sentence contains some words separated by a space,\n and you have to return a string that contains the words from the original sentence,\n whose lengths are prime numbers,\n the order of the words in the new string should be the same as the original one.\n\n Example 1:\n Input: sentence = \"This is a test\"\n Output: \"is\"\n\n Example 2:\n Input: sentence = \"lets go for swimming\"\n Output: \"go for\"\n\n Constraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n */\nconst wordsInSentence = (sentence) => {\n", "canonical_solution": " let t = sentence.split(/\\s/)\n let p = ''\n for (let j = 0; j < t.length; j++) {\n let len = t[j].length;\n let u = 1\n if (len == 1 || len == 0) { continue }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { u = 0 }\n }\n if (u == 0) { continue }\n if (p == '') { p += t[j] }\n else { p = p + ' ' + t[j] }\n }\n return p\n}\n\n", "test": "const testWordsInSentence = () => {\n console.assert(wordsInSentence('This is a test') === 'is')\n console.assert(wordsInSentence('lets go for swimming') === 'go for')\n console.assert(\n wordsInSentence('there is no place available here') === 'there is no place'\n )\n console.assert(wordsInSentence('Hi I am Hussein') === 'Hi am Hussein')\n console.assert(wordsInSentence('go for it') === 'go for it')\n console.assert(wordsInSentence('here') === '')\n console.assert(wordsInSentence('here is') === 'is')\n}\n\ntestWordsInSentence()\n", "declaration": "\nconst wordsInSentence = (sentence) => {\n", "example_test": "const testWordsInSentence = () => {\n console.assert(wordsInSentence('This is a test') === 'is')\n console.assert(wordsInSentence('lets go for swimming') === 'go for')\n}\ntestWordsInSentence()\n", "buggy_solution": " let t = sentence.split(/\\s/)\n let p = ''\n for (let j = 0; j < t.length; j++) {\n let len = t[j].length;\n let u = 1\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { u = 0 }\n }\n if (u == 0) { continue }\n if (p == '') { p += t[j] }\n else { p = p + ' ' + t[j] }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "wordsInSentence", "signature": "const wordsInSentence = (sentence)", "docstring": "You are given a string representing a sentence,\nthe sentence contains some words separated by a space,\nand you have to return a string that contains the words from the original sentence,\nwhose lengths are prime numbers,\nthe order of the words in the new string should be the same as the original one.\nExample 1:\nInput: sentence = \"This is a test\"\nOutput: \"is\"\nExample 2:\nInput: sentence = \"lets go for swimming\"\nOutput: \"go for\"\nConstraints:\n* 1 <= len(sentence) <= 100\n* sentence contains only letters", "instruction": "Write a JavaScript function `const wordsInSentence = (sentence)` to solve the following problem:\nYou are given a string representing a sentence,\nthe sentence contains some words separated by a space,\nand you have to return a string that contains the words from the original sentence,\nwhose lengths are prime numbers,\nthe order of the words in the new string should be the same as the original one.\nExample 1:\nInput: sentence = \"This is a test\"\nOutput: \"is\"\nExample 2:\nInput: sentence = \"lets go for swimming\"\nOutput: \"go for\"\nConstraints:\n* 1 <= len(sentence) <= 100\n* sentence contains only letters"}
21
+ {"task_id": "JavaScript/50", "prompt": "/*\n returns encoded string by shifting every character by 5 in the alphabet.\n */\nconst encodeShift = (s) => {\n return s.split(\"\").map(ch => String.fromCharCode(\n ((ch.charCodeAt(0) + 5 - \"a\".charCodeAt(0)) % 26) + \"a\".charCodeAt(0)\n )).join(\"\");\n}\n\n/*\n takes as input string encoded with encode_shift function. Returns decoded string.\n */\nconst decodeShift = (s) => {\n", "canonical_solution": " return s.split(\"\").map(ch => String.fromCharCode(\n ((ch.charCodeAt(0) - 5 + 26 - \"a\".charCodeAt(0)) % 26) + \"a\".charCodeAt(0)\n )).join(\"\");\n}\n\n", "test": "const testDecodeShift = () => {\n const letters = new Array(26)\n .fill(null)\n .map((v, i) => String.fromCharCode(97 + i))\n\n for (let i = 0; i < 100; i++) {\n let str = new Array(Math.floor(Math.random() * 20)).fill(null);\n str = str.map(item => letters[Math.floor(Math.random() * letters.length)]).join('');\n let encoded_str = encodeShift(str)\n console.assert(decodeShift(encoded_str) === str)\n }\n\n}\n\ntestDecodeShift()\n", "declaration": "const encodeShift = (s) => {\n return s.split(\"\").map(ch => String.fromCharCode(\n ((ch.charCodeAt(0) + 5 - \"a\".charCodeAt(0)) % 26) + \"a\".charCodeAt(0)\n )).join(\"\");\n}\n\nconst decodeShift = (s) => {\n", "example_test": "", "buggy_solution": " return s.split(\"\").map(ch => String.fromCharCode(\n ((ch.charCodeAt(0) - 5 + 26 - \"a\".charCodeAt(0)) % 26) + ch.charCodeAt(0)\n )).join(\"\");\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "decodeShift", "signature": "const decodeShift = (s)", "docstring": "takes as input string encoded with encode_shift function. Returns decoded string.", "instruction": "Write a JavaScript function `const decodeShift = (s)` to solve the following problem:\ntakes as input string encoded with encode_shift function. Returns decoded string."}
22
+ {"task_id": "JavaScript/155", "prompt": "/*Given an integer. return a tuple that has the number of even and odd digits respectively.\n\n Example:\n evenOddCount(-12) ==> (1, 1)\n evenOddCount(123) ==> (1, 2)\n */\nconst evenOddCount = (num) => {\n", "canonical_solution": " let o = 0\n let e = 0\n if (num < 0) { num = -num }\n while (num > 0) {\n if (num % 2 == 0) { e++ }\n else { o++ }\n num = (num - num % 10) / 10\n }\n return (e, o)\n}\n\n", "test": "const testEvenOddCount = () => {\n console.assert(JSON.stringify(evenOddCount(7)) === JSON.stringify((0, 1)))\n console.assert(JSON.stringify(evenOddCount(-78)) === JSON.stringify((1, 1)))\n console.assert(JSON.stringify(evenOddCount(3452)) === JSON.stringify((2, 2)))\n console.assert(\n JSON.stringify(evenOddCount(346211)) === JSON.stringify((3, 3))\n )\n console.assert(\n JSON.stringify(evenOddCount(-345821)) === JSON.stringify((3, 3))\n )\n console.assert(JSON.stringify(evenOddCount(-2)) === JSON.stringify((1, 0)))\n console.assert(\n JSON.stringify(evenOddCount(-45347)) === JSON.stringify((2, 3))\n )\n console.assert(JSON.stringify(evenOddCount(0)) === JSON.stringify((1, 0)))\n}\n\ntestEvenOddCount()\n", "declaration": "\nconst evenOddCount = (num) => {\n", "example_test": "const testEvenOddCount = () => {\n console.assert(JSON.stringify(evenOddCount(-12)) === JSON.stringify((1, 1)))\n console.assert(JSON.stringify(evenOddCount(123)) === JSON.stringify((1, 2)))\n}\ntestEvenOddCount()\n", "buggy_solution": " let o = 0\n let e = 0\n if (num < 0) { num = -num }\n while (num > 0) {\n if (num % 2 == 0) { e++ }\n else { o++ }\n num = num - num % 10\n }\n return (e, o)\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "evenOddCount", "signature": "const evenOddCount = (num)", "docstring": "Given an integer. return a tuple that has the number of even and odd digits respectively.\nExample:\nevenOddCount(-12) ==> (1, 1)\nevenOddCount(123) ==> (1, 2)", "instruction": "Write a JavaScript function `const evenOddCount = (num)` to solve the following problem:\nGiven an integer. return a tuple that has the number of even and odd digits respectively.\nExample:\nevenOddCount(-12) ==> (1, 1)\nevenOddCount(123) ==> (1, 2)"}
23
+ {"task_id": "JavaScript/107", "prompt": "/*\n Given a positive integer n, return a tuple that has the number of even and odd\n integer palindromes that fall within the range(1, n), inclusive.\n\n Example 1:\n\n Input: 3\n Output: (1, 2)\n Explanation:\n Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.\n\n Example 2:\n\n Input: 12\n Output: (4, 6)\n Explanation:\n Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\n\n Note:\n 1. 1 <= n <= 10^3\n 2. returned tuple has the number of even and odd integer palindromes respectively.\n */\nconst evenOddPalindrome = (n) => {\n", "canonical_solution": " let e = 0\n let o = 0\n for (let i = 1; i <= n; i++) {\n let k = i.toString()\n let p = 1\n for (let j = 0; j < k.length; j++) {\n if (k[j] != k[k.length - j - 1]) {\n p = 0;\n break;\n }\n }\n if (p == 1) {\n if (k % 2 == 0) { e++ }\n else { o++ }\n }\n }\n return (e, o)\n}\n\n", "test": "const testEvenOddPalindrome = () => {\n console.assert(\n JSON.stringify(evenOddPalindrome(123)) === JSON.stringify((8, 13))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(12)) === JSON.stringify((4, 6))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(3)) === JSON.stringify((1, 2))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(63)) === JSON.stringify((6, 8))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(25)) === JSON.stringify((5, 6))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(19)) === JSON.stringify((4, 6))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(9)) === JSON.stringify((4, 5))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(1)) === JSON.stringify((0, 1))\n )\n}\n\ntestEvenOddPalindrome()\n", "declaration": "\nconst evenOddPalindrome = (n) => {\n", "example_test": "const testEvenOddPalindrome = () => {\n console.assert(\n JSON.stringify(evenOddPalindrome(12)) === JSON.stringify((4, 6))\n )\n console.assert(\n JSON.stringify(evenOddPalindrome(3)) === JSON.stringify((1, 2))\n )\n}\ntestEvenOddPalindrome()\n", "buggy_solution": " let e = 0\n let o = 0\n for (let i = 1; i <= n; i++) {\n let k = i.toString()\n let p = 1\n for (let j = 0; j < k.length; j++) {\n if (k[j] != k[k.length - j - 1]) {\n p = 0;\n break;\n }\n }\n if (p == 1) {\n if (k % 2 == 1) { e++ }\n else { o++ }\n }\n }\n return (e, o)\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "evenOddPalindrome", "signature": "const evenOddPalindrome = (n)", "docstring": "Given a positive integer n, return a tuple that has the number of even and odd\ninteger palindromes that fall within the range(1, n), inclusive.\nExample 1:\nInput: 3\nOutput: (1, 2)\nExplanation:\nInteger palindrome are 1, 2, 3. one of them is even, and two of them are odd.\nExample 2:\nInput: 12\nOutput: (4, 6)\nExplanation:\nInteger palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\nNote:\n1. 1 <= n <= 10^3\n2. returned tuple has the number of even and odd integer palindromes respectively.", "instruction": "Write a JavaScript function `const evenOddPalindrome = (n)` to solve the following problem:\nGiven a positive integer n, return a tuple that has the number of even and odd\ninteger palindromes that fall within the range(1, n), inclusive.\nExample 1:\nInput: 3\nOutput: (1, 2)\nExplanation:\nInteger palindrome are 1, 2, 3. one of them is even, and two of them are odd.\nExample 2:\nInput: 12\nOutput: (4, 6)\nExplanation:\nInteger palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\nNote:\n1. 1 <= n <= 10^3\n2. returned tuple has the number of even and odd integer palindromes respectively."}
24
+ {"task_id": "JavaScript/56", "prompt": "/* brackets is a string of \"<\" and \">\".\n return false if every opening bracket has a corresponding closing bracket.\n\n >>> correctBracketing(\"<\")\n false\n >>> correctBracketing(\"<>\")\n false\n >>> correctBracketing(\"<<><>>\")\n false\n >>> correctBracketing(\"><<>\")\n false\n */\nconst correctBracketing = (brackets) => {\n", "canonical_solution": " var depth = 0;\n for (const b of brackets) {\n if (b == \"<\")\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return false;\n }\n return depth == 0;\n}\n\n", "test": "const testCorrectBracketing = () => {\n console.assert(correctBracketing('<>') === true)\n console.assert(correctBracketing('<<><>>') === true)\n console.assert(correctBracketing('<><><<><>><>') === true)\n console.assert(correctBracketing('<><><<<><><>><>><<><><<>>>') === true)\n console.assert(correctBracketing('<<<><>>>>') === false)\n console.assert(correctBracketing('><<>') === false)\n console.assert(correctBracketing('<') === false)\n console.assert(correctBracketing('<<<<') === false)\n console.assert(correctBracketing('>') === false)\n console.assert(correctBracketing('<<>') === false)\n console.assert(correctBracketing('<><><<><>><>><<>') === false)\n console.assert(correctBracketing('<><><<><>><>>><>') === false)\n}\n\ntestCorrectBracketing()\n", "declaration": "\nconst correctBracketing = (brackets) => {\n", "example_test": "const testCorrectBracketing = () => {\n console.assert(correctBracketing('<>') === true)\n console.assert(correctBracketing('<<><>>') === true)\n console.assert(correctBracketing('><<>') === false)\n console.assert(correctBracketing('<') === false)\n}\ntestCorrectBracketing()\n", "buggy_solution": " var depth = 0;\n for (const b of brackets) {\n if (b == \">\")\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return false;\n }\n return depth == 0;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "correctBracketing", "signature": "const correctBracketing = (brackets)", "docstring": "brackets is a string of \"<\" and \">\".\nreturn false if every opening bracket has a corresponding closing bracket.\n>>> correctBracketing(\"<\")\nfalse\n>>> correctBracketing(\"<>\")\nfalse\n>>> correctBracketing(\"<<><>>\")\nfalse\n>>> correctBracketing(\"><<>\")\nfalse", "instruction": "Write a JavaScript function `const correctBracketing = (brackets)` to solve the following problem:\nbrackets is a string of \"<\" and \">\".\nreturn false if every opening bracket has a corresponding closing bracket.\n>>> correctBracketing(\"<\")\nfalse\n>>> correctBracketing(\"<>\")\nfalse\n>>> correctBracketing(\"<<><>>\")\nfalse\n>>> correctBracketing(\"><<>\")\nfalse"}
25
+ {"task_id": "JavaScript/114", "prompt": "/*\n Given an array of integers nums, find the minimum sum of any non-empty sub-array\n of nums.\n Example\n minSubArraySum([2, 3, 4, 1, 2, 4]) == 1\n minSubArraySum([-1, -2, -3]) == -6\n */\nconst minSubArraySum = (nums) => {\n", "canonical_solution": " let min = nums[0]\n for (let i = 0; i < nums.length; i++) {\n for (let j = i + 1; j <= nums.length; j++) {\n let s = 0;\n for (let k = i; k < j; k++) {\n s += nums[k]\n }\n if (s < min) { min = s }\n }\n }\n return min\n}\n\n", "test": "const testMinSubArraySum = () => {\n console.assert(minSubArraySum([2, 3, 4, 1, 2, 4]) === 1)\n console.assert(minSubArraySum([-1, -2, -3]) === -6)\n console.assert(minSubArraySum([-1, -2, -3, 2, -10]) === -14)\n console.assert(minSubArraySum([-9999999999999999]) === -9999999999999999)\n console.assert(minSubArraySum([0, 10, 20, 1000000]) === 0)\n console.assert(minSubArraySum([-1, -2, -3, 10, -5]) === -6)\n console.assert(minSubArraySum([100, -1, -2, -3, 10, -5]) === -6)\n console.assert(minSubArraySum([10, 11, 13, 8, 3, 4]) === 3)\n console.assert(minSubArraySum([100, -33, 32, -1, 0, -2]) === -33)\n console.assert(minSubArraySum([-10]) === -10)\n console.assert(minSubArraySum([7]) === 7)\n console.assert(minSubArraySum([1, -1]) === -1)\n}\n\ntestMinSubArraySum()\n", "declaration": "\nconst minSubArraySum = (nums) => {\n", "example_test": "const testMinSubArraySum = () => {\n console.assert(minSubArraySum([2, 3, 4, 1, 2, 4]) === 1)\n console.assert(minSubArraySum([-1, -2, -3]) === -6)\n}\ntestMinSubArraySum()\n", "buggy_solution": " let min = Math.min(nums)\n for (let i = 0; i < nums.length; i++) {\n for (let j = i + 1; j <= nums.length; j++) {\n let s = 0;\n for (let k = i; k < j; k++) {\n s += nums[k]\n }\n if (s < min) { min = s }\n }\n }\n return min\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "minSubarraySum", "signature": "const minSubArraySum = (nums)", "docstring": "Given an array of integers nums, find the minimum sum of any non-empty sub-array\nof nums.\nExample\nminSubArraySum([2, 3, 4, 1, 2, 4]) == 1\nminSubArraySum([-1, -2, -3]) == -6", "instruction": "Write a JavaScript function `const minSubArraySum = (nums)` to solve the following problem:\nGiven an array of integers nums, find the minimum sum of any non-empty sub-array\nof nums.\nExample\nminSubArraySum([2, 3, 4, 1, 2, 4]) == 1\nminSubArraySum([-1, -2, -3]) == -6"}
26
+ {"task_id": "JavaScript/71", "prompt": "/*\n Given the lengths of the three sides of a triangle. Return the area of\n the triangle rounded to 2 decimal points if the three sides form a valid triangle.\n Otherwise return -1\n Three sides make a valid triangle when the sum of any two sides is greater\n than the third side.\n Example:\n triangleArea(3, 4, 5) == 6.00\n triangleArea(1, 2, 10) == -1\n */\nconst triangleArea = (a, b, c) => {\n", "canonical_solution": " if (a + b <= c || a + c <= b || b + c <= a)\n return -1;\n var s = (a + b + c) / 2;\n var area = Math.pow(s * (s - a) * (s - b) * (s - c), 0.5);\n area = area.toFixed(2);\n return area;\n}\n\n", "test": "const testTriangleArea = () => {\n console.assert(triangleArea(3, 4, 5) == 6.0)\n console.assert(triangleArea(1, 2, 10) == -1)\n console.assert(triangleArea(4, 8, 5) == 8.18)\n console.assert(triangleArea(2, 2, 2) == 1.73)\n console.assert(triangleArea(1, 2, 3) == -1)\n console.assert(triangleArea(10, 5, 7) == 16.25)\n console.assert(triangleArea(2, 6, 3) == -1)\n console.assert(triangleArea(1, 1, 1) == 0.43)\n console.assert(triangleArea(2, 2, 10) == -1)\n}\n\ntestTriangleArea()\n", "declaration": "\nconst triangleArea = (a, b, c) => {\n", "example_test": "const testTriangleArea = () => {\n console.assert(triangleArea(3, 4, 5) == 6.0)\n console.assert(triangleArea(1, 2, 10) == -1)\n}\ntestTriangleArea()\n", "buggy_solution": " if (a + b <= c || a + c <= b || b + c <= a)\n return -1;\n var s = (a + b + c);\n var area = Math.pow(s * (s - a) * (s - b) * (s - c), 0.5);\n area = area.toFixed(2);\n return area;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "triangleArea", "signature": "const triangleArea = (a, b, c)", "docstring": "Given the lengths of the three sides of a triangle. Return the area of\nthe triangle rounded to 2 decimal points if the three sides form a valid triangle.\nOtherwise return -1\nThree sides make a valid triangle when the sum of any two sides is greater\nthan the third side.\nExample:\ntriangleArea(3, 4, 5) == 6.00\ntriangleArea(1, 2, 10) == -1", "instruction": "Write a JavaScript function `const triangleArea = (a, b, c)` to solve the following problem:\nGiven the lengths of the three sides of a triangle. Return the area of\nthe triangle rounded to 2 decimal points if the three sides form a valid triangle.\nOtherwise return -1\nThree sides make a valid triangle when the sum of any two sides is greater\nthan the third side.\nExample:\ntriangleArea(3, 4, 5) == 6.00\ntriangleArea(1, 2, 10) == -1"}
27
+ {"task_id": "JavaScript/1", "prompt": "/* Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n separate those group into separate strings and return the list of those.\n Separate groups are balanced (each open brace is properly closed) and not nested within each other\n Ignore any spaces in the input string.\n >>> separateParenGroups('( ) (( )) (( )( ))')\n ['()', '(())', '(()())']\n */\nconst separateParenGroups = (paren_string) => {\n", "canonical_solution": " var result = [];\n var current_string = [];\n var current_depth = 0;\n\n for (const c of paren_string) {\n if (c == '(') {\n current_depth += 1;\n current_string.push(c);\n } else if (c == ')') {\n current_depth -= 1;\n current_string.push(c);\n if (current_depth == 0) {\n result.push(current_string.join(''));\n current_string = [];\n }\n }\n }\n\n return result;\n}\n\n", "test": "const testSeparateParenGroups = () => {\n console.assert(\n JSON.stringify(separateParenGroups('(()()) ((())) () ((())()())')) ===\n JSON.stringify(['(()())', '((()))', '()', '((())()())'])\n )\n console.assert(\n JSON.stringify(separateParenGroups('() (()) ((())) (((())))')) ===\n JSON.stringify(['()', '(())', '((()))', '(((())))'])\n )\n console.assert(\n JSON.stringify(separateParenGroups('(()(())((())))')) ===\n JSON.stringify(['(()(())((())))'])\n )\n console.assert(\n JSON.stringify(separateParenGroups('( ) (( )) (( )( ))')) ===\n JSON.stringify(['()', '(())', '(()())'])\n )\n}\n\ntestSeparateParenGroups()\n", "declaration": "\nconst separateParenGroups = (paren_string) => {\n", "example_test": "const testSeparateParenGroups = () => {\n console.assert(\n JSON.stringify(separateParenGroups('( ) (( )) (( )( ))')) ===\n JSON.stringify(['()', '(())', '(()())'])\n )\n}\ntestSeparateParenGroups()\n", "buggy_solution": " var result = [];\n var current_string = [];\n var current_depth = 0;\n\n for (const c of paren_string) {\n if (c == '(') {\n current_depth += 1;\n current_string.push(c);\n } else if (c == ')') {\n current_depth -= 1;\n current_string.push(c);\n if (current_depth < 0) {\n result.push(current_string.join(''));\n current_string = [];\n }\n }\n }\n\n return result;\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "separateParenGroups", "signature": "const separateParenGroups = (paren_string)", "docstring": "Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\nseparate those group into separate strings and return the list of those.\nSeparate groups are balanced (each open brace is properly closed) and not nested within each other\nIgnore any spaces in the input string.\n>>> separateParenGroups('( ) (( )) (( )( ))')\n['()', '(())', '(()())']", "instruction": "Write a JavaScript function `const separateParenGroups = (paren_string)` to solve the following problem:\nInput to this function is a string containing multiple groups of nested parentheses. Your goal is to\nseparate those group into separate strings and return the list of those.\nSeparate groups are balanced (each open brace is properly closed) and not nested within each other\nIgnore any spaces in the input string.\n>>> separateParenGroups('( ) (( )) (( )( ))')\n['()', '(())', '(()())']"}
28
+ {"task_id": "JavaScript/40", "prompt": "/*\n triplesSumToZero takes a list of integers as an input.\n it returns true if there are three distinct elements in the list that\n sum to zero, and false otherwise.\n\n >>> triplesSumToZero([1, 3, 5, 0])\n false\n >>> triplesSumToZero([1, 3, -2, 1])\n true\n >>> triplesSumToZero([1, 2, 3, 7])\n false\n >>> triplesSumToZero([2, 4, -5, 3, 9, 7])\n true\n >>> triplesSumToZero([1])\n false\n */\nconst triplesSumToZero = (l) => {\n", "canonical_solution": " for (let i = 0; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n for (let k = j + 1; k < l.length; k++)\n if (l[i] + l[j] + l[k] == 0)\n return true;\n return false;\n}\n\n", "test": "const testTriplesSumToZero = () => {\n console.assert(triplesSumToZero([1, 3, 5, 0]) === false)\n console.assert(triplesSumToZero([1, 3, 5, -1]) === false)\n console.assert(triplesSumToZero([1, 3, -2, 1]) === true)\n console.assert(triplesSumToZero([1, 2, 3, 7]) === false)\n console.assert(triplesSumToZero([1, 2, 5, 7]) === false)\n console.assert(triplesSumToZero([2, 4, -5, 3, 9, 7]) === true)\n console.assert(triplesSumToZero([1]) === false)\n console.assert(triplesSumToZero([1, 3, 5, -100]) === false)\n console.assert(triplesSumToZero([100, 3, 5, -100]) === false)\n}\n\ntestTriplesSumToZero()\n", "declaration": "\nconst triplesSumToZero = (l) => {\n", "example_test": "const testTriplesSumToZero = () => {\n console.assert(triplesSumToZero([1, 3, 5, 0]) === false)\n console.assert(triplesSumToZero([1, 3, -2, 1]) === true)\n console.assert(triplesSumToZero([1, 2, 3, 7]) === false)\n console.assert(triplesSumToZero([2, 4, -5, 3, 9, 7]) === true)\n}\ntestTriplesSumToZero()\n", "buggy_solution": " for (let i = 1; i < l.length; i++)\n for (let j = i + 1; j < l.length; j++)\n for (let k = j + 1; k < l.length; k++)\n if (l[i] + l[j] + l[k] == 0)\n return true;\n return false;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "triplesSumToZero", "signature": "const triplesSumToZero = (l)", "docstring": "triplesSumToZero takes a list of integers as an input.\nit returns true if there are three distinct elements in the list that\nsum to zero, and false otherwise.\n>>> triplesSumToZero([1, 3, 5, 0])\nfalse\n>>> triplesSumToZero([1, 3, -2, 1])\ntrue\n>>> triplesSumToZero([1, 2, 3, 7])\nfalse\n>>> triplesSumToZero([2, 4, -5, 3, 9, 7])\ntrue\n>>> triplesSumToZero([1])\nfalse", "instruction": "Write a JavaScript function `const triplesSumToZero = (l)` to solve the following problem:\ntriplesSumToZero takes a list of integers as an input.\nit returns true if there are three distinct elements in the list that\nsum to zero, and false otherwise.\n>>> triplesSumToZero([1, 3, 5, 0])\nfalse\n>>> triplesSumToZero([1, 3, -2, 1])\ntrue\n>>> triplesSumToZero([1, 2, 3, 7])\nfalse\n>>> triplesSumToZero([2, 4, -5, 3, 9, 7])\ntrue\n>>> triplesSumToZero([1])\nfalse"}
29
+ {"task_id": "JavaScript/152", "prompt": "/*I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match. \n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n \n \n example:\n\n compare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\n compare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]\n */\nconst compare = (game, guess) => {\n", "canonical_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i]; }\n return game\n}\n\n", "test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0])) ===\n JSON.stringify([0, 0, 0, 0, 0, 0])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3], [-1, -2, -3])) ===\n JSON.stringify([2, 4, 6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 5], [-1, 2, 3, 4])) ===\n JSON.stringify([2, 0, 0, 1])\n )\n}\n\ntestCompare()\n", "declaration": "\nconst compare = (game, guess) => {\n", "example_test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n}\ntestCompare()\n", "buggy_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i];\n if (guess[i]!=0)\n game[i]-=guess[i]; }\n return game\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "compare", "signature": "const compare = (game, guess)", "docstring": "I think we all remember that feeling when the result of some long-awaited\nevent is finally known. The feelings and thoughts you have at that moment are\ndefinitely worth noting down and comparing.\nYour task is to determine if a person correctly guessed the results of a number of matches.\nYou are given two arrays of scores and guesses of equal length, where each index shows a match.\nReturn an array of the same length denoting how far off each guess was. If they have guessed correctly,\nthe value is 0, and if not, the value is the absolute difference between the guess and the score.\nexample:\ncompare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\ncompare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]", "instruction": "Write a JavaScript function `const compare = (game, guess)` to solve the following problem:\nI think we all remember that feeling when the result of some long-awaited\nevent is finally known. The feelings and thoughts you have at that moment are\ndefinitely worth noting down and comparing.\nYour task is to determine if a person correctly guessed the results of a number of matches.\nYou are given two arrays of scores and guesses of equal length, where each index shows a match.\nReturn an array of the same length denoting how far off each guess was. If they have guessed correctly,\nthe value is 0, and if not, the value is the absolute difference between the guess and the score.\nexample:\ncompare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\ncompare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]"}
30
+ {"task_id": "JavaScript/87", "prompt": "/*\n You are given a 2 dimensional data, as a nested lists,\n which is similar to matrix, however, unlike matrices,\n each row may contain a different number of columns.\n Given lst, and integer x, find integers x in the list,\n and return list of tuples, [(x1, y1), (x2, y2) ...] such that\n each tuple is a coordinate - (row, columns), starting with 0.\n Sort coordinates initially by rows in ascending order.\n Also, sort coordinates of the row by columns in descending order.\n \n Examples:\n getRow([\n [1,2,3,4,5,6],\n [1,2,3,4,1,6],\n [1,2,3,4,5,1]\n ], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]\n getRow([], 1) == []\n getRow([[], [1], [1, 2, 3]], 3) == [(2, 2)]\n */\nconst getRow = (lst, x) => {\n", "canonical_solution": " let t = []\n for (let i = 0; i < lst.length; i++) {\n for (let j = lst[i].length - 1; j >= 0; j--) {\n if (lst[i][j] == x) {\n t.push((i, j))\n }\n }\n }\n return t\n}\n\n", "test": "const testGetRow = () => {\n console.assert(\n JSON.stringify(\n getRow(\n [\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 1, 6],\n [1, 2, 3, 4, 5, 1],\n ],\n 1\n )\n ) === JSON.stringify([(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)])\n )\n console.assert(\n JSON.stringify(\n getRow(\n [\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n ],\n 2\n )\n ) === JSON.stringify([(0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (5, 1)])\n )\n console.assert(\n JSON.stringify(\n getRow(\n [\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 5, 6],\n [1, 1, 3, 4, 5, 6],\n [1, 2, 1, 4, 5, 6],\n [1, 2, 3, 1, 5, 6],\n [1, 2, 3, 4, 1, 6],\n [1, 2, 3, 4, 5, 1],\n ],\n 1\n )\n ) ===\n JSON.stringify([\n (0, 0),\n (1, 0),\n (2, 1),\n (2, 0),\n (3, 2),\n (3, 0),\n (4, 3),\n (4, 0),\n (5, 4),\n (5, 0),\n (6, 5),\n (6, 0),\n ])\n )\n console.assert(JSON.stringify(getRow([], 1)) === JSON.stringify([]))\n console.assert(JSON.stringify(getRow([[1]], 2)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(getRow([[], [1], [1, 2, 3]], 3)) === JSON.stringify([(2, 2)])\n )\n}\n\ntestGetRow()\n", "declaration": "\nconst getRow = (lst, x) => {\n", "example_test": "const testGetRow = () => {\n console.assert(\n JSON.stringify(\n getRow(\n [\n [1, 2, 3, 4, 5, 6],\n [1, 2, 3, 4, 1, 6],\n [1, 2, 3, 4, 5, 1],\n ],\n 1\n )\n ) === JSON.stringify([(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)])\n )\n console.assert(JSON.stringify(getRow([], 1)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(getRow([[], [1], [1, 2, 3]], 3)) === JSON.stringify([(2, 2)])\n )\n}\ntestGetRow()\n", "buggy_solution": " let t = []\n for (let i = 0; i < lst.length; i++) {\n for (let j = lst[i].length - 1; j >= 0; j--) {\n if (lst[i][j] == x) {\n t.push((j, i))\n }\n }\n }\n return t\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "getRow", "signature": "const getRow = (lst, x)", "docstring": "You are given a 2 dimensional data, as a nested lists,\nwhich is similar to matrix, however, unlike matrices,\neach row may contain a different number of columns.\nGiven lst, and integer x, find integers x in the list,\nand return list of tuples, [(x1, y1), (x2, y2) ...] such that\neach tuple is a coordinate - (row, columns), starting with 0.\nSort coordinates initially by rows in ascending order.\nAlso, sort coordinates of the row by columns in descending order.\nExamples:\ngetRow([\n[1,2,3,4,5,6],\n[1,2,3,4,1,6],\n[1,2,3,4,5,1]\n], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]\ngetRow([], 1) == []\ngetRow([[], [1], [1, 2, 3]], 3) == [(2, 2)]", "instruction": "Write a JavaScript function `const getRow = (lst, x)` to solve the following problem:\nYou are given a 2 dimensional data, as a nested lists,\nwhich is similar to matrix, however, unlike matrices,\neach row may contain a different number of columns.\nGiven lst, and integer x, find integers x in the list,\nand return list of tuples, [(x1, y1), (x2, y2) ...] such that\neach tuple is a coordinate - (row, columns), starting with 0.\nSort coordinates initially by rows in ascending order.\nAlso, sort coordinates of the row by columns in descending order.\nExamples:\ngetRow([\n[1,2,3,4,5,6],\n[1,2,3,4,1,6],\n[1,2,3,4,5,1]\n], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]\ngetRow([], 1) == []\ngetRow([[], [1], [1, 2, 3]], 3) == [(2, 2)]"}
31
+ {"task_id": "JavaScript/138", "prompt": "/*Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\n Example\n isEqualToSumEven(4) == false\n isEqualToSumEven(6) == false\n isEqualToSumEven(8) == true\n */\nconst isEqualToSumEven = (n) => {\n", "canonical_solution": " return (n >= 8 && n % 2 == 0)\n}\n\n", "test": "const testIsEqualToSumEven = () => {\n console.assert(isEqualToSumEven(4) === false)\n console.assert(isEqualToSumEven(6) === false)\n console.assert(isEqualToSumEven(8) === true)\n console.assert(isEqualToSumEven(10) === true)\n console.assert(isEqualToSumEven(11) === false)\n console.assert(isEqualToSumEven(12) === true)\n console.assert(isEqualToSumEven(13) === false)\n console.assert(isEqualToSumEven(16) === true)\n}\n\ntestIsEqualToSumEven()\n", "declaration": "\nconst isEqualToSumEven = (n) => {\n", "example_test": "const testIsEqualToSumEven = () => {\n console.assert(isEqualToSumEven(4) === false)\n console.assert(isEqualToSumEven(6) === false)\n console.assert(isEqualToSumEven(8) === true)\n}\ntestIsEqualToSumEven()\n", "buggy_solution": " return (n >= 8 && n <= 8 && n % 2 == 0)\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "isEqualToSumEven", "signature": "const isEqualToSumEven = (n)", "docstring": "Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\nExample\nisEqualToSumEven(4) == false\nisEqualToSumEven(6) == false\nisEqualToSumEven(8) == true", "instruction": "Write a JavaScript function `const isEqualToSumEven = (n)` to solve the following problem:\nEvaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\nExample\nisEqualToSumEven(4) == false\nisEqualToSumEven(6) == false\nisEqualToSumEven(8) == true"}
32
+ {"task_id": "JavaScript/39", "prompt": "/*\n primeFib returns n-th number that is a Fibonacci number and it's also prime.\n >>> primeFib(1)\n 2\n >>> primeFib(2)\n 3\n >>> primeFib(3)\n 5\n >>> primeFib(4)\n 13\n >>> primeFib(5)\n 89\n */\nconst primeFib = (n) => {\n", "canonical_solution": " var isPrime = function (p) {\n if (p < 2)\n return false;\n for (let k = 2; k < Math.min(Math.floor(Math.sqrt(p)) + 1, p - 1); k++) {\n if (p % k == 0)\n return false;\n }\n return true;\n }\n\n var f = [0, 1];\n while (true) {\n f.push(f.at(-1) + f.at(-2));\n if (isPrime(f.at(-1)))\n n -= 1;\n if (n == 0)\n return f.at(-1);\n }\n}\n\n", "test": "const testPrimeFib = () => {\n console.assert(primeFib(1) === 2)\n console.assert(primeFib(2) === 3)\n console.assert(primeFib(3) === 5)\n console.assert(primeFib(4) === 13)\n console.assert(primeFib(5) === 89)\n console.assert(primeFib(6) === 233)\n console.assert(primeFib(7) === 1597)\n console.assert(primeFib(8) === 28657)\n console.assert(primeFib(9) === 514229)\n console.assert(primeFib(10) === 433494437)\n}\n\ntestPrimeFib()\n", "declaration": "\nconst primeFib = (n) => {\n", "example_test": "const testPrimeFib = () => {\n console.assert(primeFib(1) === 2)\n console.assert(primeFib(2) === 3)\n console.assert(primeFib(3) === 5)\n console.assert(primeFib(4) === 13)\n console.assert(primeFib(5) === 89)\n}\ntestPrimeFib()\n", "buggy_solution": " var isPrime = function (p) {\n if (p < 2)\n return false;\n for (let k = 2; k < Math.min(Math.floor(Math.sqrt(p)), p); k++) {\n if (p % k == 0)\n return false;\n }\n return true;\n }\n\n var f = [0, 1];\n while (true) {\n f.push(f.at(-1) + f.at(-2));\n if (isPrime(f.at(-1)))\n n -= 1;\n if (n == 0)\n return f.at(-1);\n }\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "primeFib", "signature": "const primeFib = (n)", "docstring": "primeFib returns n-th number that is a Fibonacci number and it's also prime.\n>>> primeFib(1)\n2\n>>> primeFib(2)\n3\n>>> primeFib(3)\n5\n>>> primeFib(4)\n13\n>>> primeFib(5)\n89", "instruction": "Write a JavaScript function `const primeFib = (n)` to solve the following problem:\nprimeFib returns n-th number that is a Fibonacci number and it's also prime.\n>>> primeFib(1)\n2\n>>> primeFib(2)\n3\n>>> primeFib(3)\n5\n>>> primeFib(4)\n13\n>>> primeFib(5)\n89"}
data/python/data/humanevalpack.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/rust/data/humanevalpack.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
humanevalpack.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import datasets
4
+
5
+
6
+ _DESCRIPTION = """
7
+ """
8
+
9
+ _HOMEPAGE = "https://github.com/bigcode-project/octopack"
10
+
11
+ def get_url(name):
12
+ url = f"data/{name}/data/humanevalpack.jsonl"
13
+ return url
14
+
15
+ def split_generator(dl_manager, name):
16
+ downloaded_files = dl_manager.download(get_url(name))
17
+ return [
18
+ datasets.SplitGenerator(
19
+ name=datasets.Split.TEST,
20
+ gen_kwargs={
21
+ "filepath": downloaded_files,
22
+ },
23
+ )
24
+ ]
25
+
26
+ class HumanEvalPackConfig(datasets.BuilderConfig):
27
+ """BuilderConfig """
28
+
29
+ def __init__(self, name, description, features, **kwargs):
30
+ super(HumanEvalPackConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
31
+ self.name = name
32
+ self.description = description
33
+ self.features = features
34
+
35
+
36
+ class HumanEvalPack(datasets.GeneratorBasedBuilder):
37
+ VERSION = datasets.Version("1.0.0")
38
+ BUILDER_CONFIGS = [
39
+ HumanEvalPackConfig(
40
+ name="python",
41
+ description="Python HumanEvalPack",
42
+ features=[
43
+ "task_id", "prompt", "declaration", "canonical_solution", "buggy_solution", "bug_type", "failure_symptoms", "import", "test_setup", "test", "example_test", "entry_point", "signature", "docstring", "instruction"
44
+ ]
45
+ ),
46
+ HumanEvalPackConfig(
47
+ name="js",
48
+ description="JavaScript HumanEvalPack",
49
+ features=[
50
+ "task_id", "prompt", "declaration", "canonical_solution", "buggy_solution", "bug_type", "failure_symptoms", "import", "test_setup", "test", "example_test", "entry_point", "signature", "docstring", "instruction"
51
+ ]
52
+ ),
53
+ HumanEvalPackConfig(
54
+ name="java",
55
+ description="Java HumanEvalPack",
56
+ features=[
57
+ "task_id", "prompt", "declaration", "canonical_solution", "buggy_solution", "bug_type", "failure_symptoms", "import", "test_setup", "test", "example_test", "entry_point", "signature", "docstring", "instruction"
58
+ ]
59
+ ),
60
+ HumanEvalPackConfig(
61
+ name="go",
62
+ description="Go HumanEvalPack",
63
+ features=[
64
+ "task_id", "prompt", "declaration", "canonical_solution", "buggy_solution", "bug_type", "failure_symptoms", "import", "test_setup", "test", "example_test", "entry_point", "signature", "docstring", "instruction"
65
+ ]
66
+ ),
67
+ HumanEvalPackConfig(
68
+ name="cpp",
69
+ description="C++ HumanEvalPack",
70
+ features=[
71
+ "task_id", "prompt", "declaration", "canonical_solution", "buggy_solution", "bug_type", "failure_symptoms", "import", "test_setup", "test", "example_test", "entry_point", "signature", "docstring", "instruction"
72
+ ]
73
+ ),
74
+ HumanEvalPackConfig(
75
+ name="rust",
76
+ description="Rust HumanEvalPack",
77
+ features=[
78
+ "task_id", "prompt", "declaration", "canonical_solution", "buggy_solution", "bug_type", "failure_symptoms", "import", "test_setup", "test", "example_test", "entry_point", "signature", "docstring", "instruction"
79
+ ]
80
+ ),
81
+ ]
82
+ DEFAULT_CONFIG_NAME = "python"
83
+
84
+ def _info(self):
85
+ return datasets.DatasetInfo(
86
+ description=_DESCRIPTION,
87
+ features=datasets.Features(
88
+ {
89
+ "task_id": datasets.Value("string"),
90
+ "prompt": datasets.Value("string"),
91
+ "declaration": datasets.Value("string"),
92
+ "canonical_solution": datasets.Value("string"),
93
+ "buggy_solution": datasets.Value("string"),
94
+ "bug_type": datasets.Value("string"),
95
+ "failure_symptoms": datasets.Value("string"),
96
+ "entry_point": datasets.Value("string"),
97
+ "import": datasets.Value("string"),
98
+ "test_setup": datasets.Value("string"),
99
+ "test": datasets.Value("string"),
100
+ "example_test": datasets.Value("string"),
101
+ "signature": datasets.Value("string"),
102
+ "docstring": datasets.Value("string"),
103
+ "instruction": datasets.Value("string"),
104
+ }
105
+ ),
106
+ homepage=_HOMEPAGE,
107
+ )
108
+
109
+ def _split_generators(self, dl_manager):
110
+ if self.config.name == "python":
111
+ return split_generator(dl_manager, self.config.name)
112
+
113
+ elif self.config.name == "cpp":
114
+ return split_generator(dl_manager, self.config.name)
115
+
116
+ elif self.config.name == "go":
117
+ return split_generator(dl_manager, self.config.name)
118
+
119
+ elif self.config.name == "java":
120
+ return split_generator(dl_manager, self.config.name)
121
+
122
+ elif self.config.name == "js":
123
+ return split_generator(dl_manager, self.config.name)
124
+
125
+ elif self.config.name == "rust":
126
+ return split_generator(dl_manager, self.config.name)
127
+
128
+ def _generate_examples(self, filepath):
129
+ key = 0
130
+ with open(filepath) as f:
131
+ for line in f:
132
+ row = json.loads(line)
133
+ key += 1
134
+ yield key, {
135
+ "task_id": row["task_id"],
136
+ "prompt": row["prompt"],
137
+ "declaration": row["declaration"],
138
+ "canonical_solution": row["canonical_solution"],
139
+ "buggy_solution": row["buggy_solution"],
140
+ "bug_type": row["bug_type"],
141
+ "failure_symptoms": row["failure_symptoms"],
142
+ "import": row.get("import", ""), # Only for Go
143
+ "test_setup": row.get("test_setup", ""), # Only for Go
144
+ "test": row["test"],
145
+ "example_test": row["example_test"],
146
+ "entry_point": row["entry_point"],
147
+ "signature": row["signature"],
148
+ "docstring": row["docstring"],
149
+ "instruction": row["instruction"],
150
+ }
151
+ key += 1