Commit
·
1e6d4d6
1
Parent(s):
e2ae247
Fix entry names
Browse files
data/cpp/data/humanevalbugs.jsonl
CHANGED
@@ -145,7 +145,7 @@
|
|
145 |
{"task_id": "CPP/144", "prompt": "/*\nYour task is to implement a function that will simplify the expression\nx * n. The function returns true if x * n evaluates to a whole number and false\notherwise. Both x and n, are string representation of a fraction, and have the following format,\n<numerator>/<denominator> where both numerator and denominator are positive whole numbers.\n\nYou can assume that x, and n are valid fractions, and do not have zero as denominator.\n\nsimplify(\"1/5\", \"5/1\") = true\nsimplify(\"1/6\", \"2/1\") = false\nsimplify(\"7/10\", \"10/2\") = false\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool simplify(string x,string n){\n", "canonical_solution": " int a,b,c,d,i;\n for (i=0;i<x.size();i++)\n if (x[i]=='/') \n {\n a=atoi(x.substr(0,i).c_str());\n b=atoi(x.substr(i+1).c_str());\n }\n for (i=0;i<n.size();i++)\n if (n[i]=='/') \n {\n c=atoi(n.substr(0,i).c_str());\n d=atoi(n.substr(i+1).c_str());\n }\n if ((a*c)%(b*d)==0) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (simplify(\"1/5\", \"5/1\") == true);\n assert (simplify(\"1/6\", \"2/1\") == false);\n assert (simplify(\"5/1\", \"3/1\") == true);\n assert (simplify(\"7/10\", \"10/2\") == false);\n assert (simplify(\"2/10\", \"50/10\") == true);\n assert (simplify(\"7/2\", \"4/2\") == true);\n assert (simplify(\"11/6\", \"6/1\") == true);\n assert (simplify(\"2/3\", \"5/2\") == false);\n assert (simplify(\"5/2\", \"3/5\") == false);\n assert (simplify(\"2/4\", \"8/4\") == true);\n assert (simplify(\"2/4\", \"4/2\") == true);\n assert (simplify(\"1/5\", \"5/1\") == true);\n assert (simplify(\"1/5\", \"1/5\") == false);\n}\n", "declaration": "#include<stdio.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<math.h>\n#include<stdlib.h>\nbool simplify(string x,string n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (simplify(\"1/5\", \"5/1\") == true);\n assert (simplify(\"1/6\", \"2/1\") == false);\n assert (simplify(\"7/10\", \"10/2\") == false);\n}\n", "buggy_solution": " int a,b,c,d,i;\n for (i=0;i<x.size();i++)\n if (x[i]=='/') \n {\n a=atoi(x.substr(0,i).c_str());\n b=atoi(x.substr(i+1).c_str());\n }\n for (i=0;i<n.size();i++)\n if (n[i]=='/') \n {\n c=atoi(n.substr(0,i).c_str());\n d=atoi(n.substr(i+1).c_str());\n a=atoi(n.substr(0,i).c_str());\n b=atoi(n.substr(i+1).c_str());\n }\n if ((a*c)%(b*d)==0) return true;\n return false;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "simplify"}
|
146 |
{"task_id": "CPP/145", "prompt": "/*\nWrite a function which sorts the given vector of integers\nin ascending order according to the sum of their digits.\nNote: if there are several items with similar sum of their digits,\norder them based on their index in original vector.\n\nFor example:\n>>> order_by_points({1, 11, -1, -11, -12}) == {-1, -11, 1, -12, 11}\n>>> order_by_points({}) == {}\n*/\n#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\nvector<int> order_by_points(vector<int> nums){\n", "canonical_solution": " vector<int> sumdigit={};\n for (int i=0;i<nums.size();i++)\n {\n string w=to_string(abs(nums[i]));\n int sum=0;\n for (int j=1;j<w.length();j++)\n sum+=w[j]-48;\n if (nums[i]>0) sum+=w[0]-48;\n else sum-=w[0]-48;\n sumdigit.push_back(sum);\n }\n int m;\n for (int i=0;i<nums.size();i++)\n for (int j=1;j<nums.size();j++)\n if (sumdigit[j-1]>sumdigit[j])\n {\n m=sumdigit[j];sumdigit[j]=sumdigit[j-1];sumdigit[j-1]=m;\n m=nums[j];nums[j]=nums[j-1];nums[j-1]=m;\n }\n \n return nums;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(order_by_points({1, 11, -1, -11, -12}) , {-1, -11, 1, -12, 11}));\n assert (issame(order_by_points({1234,423,463,145,2,423,423,53,6,37,3457,3,56,0,46}) , {0, 2, 3, 6, 53, 423, 423, 423, 1234, 145, 37, 46, 56, 463, 3457}));\n assert (issame(order_by_points({}) , {}));\n assert (issame(order_by_points({1, -11, -32, 43, 54, -98, 2, -3}) , {-3, -32, -98, -11, 1, 2, 43, 54}));\n assert (issame(order_by_points({1,2,3,4,5,6,7,8,9,10,11}) , {1, 10, 2, 11, 3, 4, 5, 6, 7, 8, 9}));\n assert (issame(order_by_points({0,6,6,-76,-21,23,4}) , {-76, -21, 0, 4, 23, 6, 6}));\n \n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nvector<int> order_by_points(vector<int> nums){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(order_by_points({1, 11, -1, -11, -12}) , {-1, -11, 1, -12, 11}));\n assert (issame(order_by_points({}) , {}));\n}\n", "buggy_solution": " vector<int> sumdigit={};\n for (int i=0;i<nums.size();i++)\n {\n string w=to_string(abs(nums[i]));\n int sum=0;\n for (int j=1;j<w.length();j++)\n sum+=w[j]-48;\n if (nums[i]>0) sum+=w[0]-48;\n else sum-=w[0]-48;\n sumdigit.push_back(sum);\n }\n int m;\n for (int i=0;i<nums.size();i++)\n for (int j=1;j<nums.size();j++)\n if (sumdigit[j-1]>sumdigit[j])\n {\n m=sumdigit[j];sumdigit[j]=sumdigit[j-1];sumdigit[j-1]=m;sumdigit[j]=m;\n m=nums[j];nums[j]=nums[j-1];nums[j-1]=m;nums[j]=m;\n }\n \n return nums;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "order_by_points"}
|
147 |
{"task_id": "CPP/146", "prompt": "/*\nWrite a function that takes a vector of numbers as input and returns \nthe number of elements in the vector that are greater than 10 and both \nfirst and last digits of a number are odd (1, 3, 5, 7, 9).\nFor example:\nspecialFilter({15, -73, 14, -15}) => 1 \nspecialFilter({33, -2, -3, 45, 21, 109}) => 2\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nint specialFilter(vector<int> nums){\n", "canonical_solution": " int num=0;\n for (int i=0;i<nums.size();i++)\n if (nums[i]>10)\n {\n string w=to_string(nums[i]);\n if (w[0]%2==1 and w[w.length()-1]%2==1) num+=1;\n }\n return num;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (specialFilter({5, -2, 1, -5}) == 0 );\n assert (specialFilter({15, -73, 14, -15}) == 1);\n assert (specialFilter({33, -2, -3, 45, 21, 109}) == 2);\n assert (specialFilter({43, -12, 93, 125, 121, 109}) == 4);\n assert (specialFilter({71, -2, -33, 75, 21, 19}) == 3);\n assert (specialFilter({1}) == 0 );\n assert (specialFilter({}) == 0 );\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint specialFilter(vector<int> nums){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (specialFilter({15, -73, 14, -15}) == 1);\n assert (specialFilter({33, -2, -3, 45, 21, 109}) == 2);\n}\n", "buggy_solution": " int num=0;\n for (int i=0;i<nums.size();i++)\n if (nums[i]>10)\n {\n string w=to_string(nums[i]);\n if (w[0]%2==1 and w[w.length()-1]%2==1 and w[w.length()-1]%2==0) num+=1;\n }\n return num;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "specialFilter"}
|
148 |
-
{"task_id": "CPP/147", "prompt": "/*\nYou are given a positive integer n. You have to create an integer vector a of length n.\n For each i (1 \u2264 i \u2264 n), the value of a{i} = i * i - i + 1.\n Return the number of triples (a{i}, a{j}, a{k}) of a where i < j < k, \nand a[i] + a[j] + a[k] is a multiple of 3.\n\nExample :\n Input: n = 5\n Output: 1\n Explanation: \n a = {1, 3, 7, 13, 21}\n The only valid triple is (1, 7, 13).\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nint get_matrix_triples(int n){\n", "canonical_solution": " vector<int> a;\n vector<vector<int>> sum={{0,0,0}};\n vector<vector<int>> sum2={{0,0,0}};\n for (int i=1;i<=n;i++)\n {\n a.push_back((i*i-i+1)%3);\n sum.push_back(sum[sum.size()-1]);\n sum[i][a[i-1]]+=1;\n }\n for (int times=1;times<3;times++)\n {\n for (int i=1;i<=n;i++)\n {\n sum2.push_back(sum2[sum2.size()-1]);\n if (i>=1)\n for (int j=0;j<=2;j++)\n sum2[i][(a[i-1]+j)%3]+=sum[i-1][j];\n }\n sum=sum2;\n sum2={{0,0,0}};\n }\n\n return sum[n][0];\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (get_matrix_triples(5) == 1);\n assert (get_matrix_triples(6) == 4);\n assert (get_matrix_triples(10) == 36);\n assert (get_matrix_triples(100) == 53361);\n}\n", "declaration": "#include<stdio.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nint get_matrix_triples(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (get_matrix_triples(5) == 1);\n}\n", "buggy_solution": " vector<int> a;\n vector<vector<int>> sum={{0,0,0}};\n vector<vector<int>> sum2={{0,0,0}};\n for (int i=1;i<=n;i++)\n {\n a.push_back((i*i)%3);\n sum.push_back(sum[sum.size()-1]);\n sum[i][a[i-1]]+=1;\n }\n for (int times=1;times<3;times++)\n {\n for (int i=1;i<=n;i++)\n {\n sum2.push_back(sum2[sum2.size()-1]);\n if (i>=1)\n for (int j=0;j<=2;j++)\n sum2[i][(a[i-1]+j)%3]+=sum[i-1][j];\n }\n sum=sum2;\n sum2={{0,0,0}};\n }\n\n return sum[n][0];\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "
|
149 |
{"task_id": "CPP/148", "prompt": "/*\nThere are eight planets in our solar system: the closerst to the Sun \nis Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, \nUranus, Neptune.\nWrite a function that takes two planet names as strings planet1 and planet2. \nThe function should return a vector containing all planets whose orbits are \nlocated between the orbit of planet1 and the orbit of planet2, sorted by \nthe proximity to the sun. \nThe function should return an empty vector if planet1 or planet2\nare not correct planet names. \nExamples\nbf(\"Jupiter\", \"Neptune\") ==> {\"Saturn\", \"Uranus\"}\nbf(\"Earth\", \"Mercury\") ==> {\"Venus\"}\nbf(\"Mercury\", \"Uranus\") ==> {\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\"}\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nvector<string> bf(string planet1,string planet2){\n", "canonical_solution": " vector<string> planets={\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupiter\",\"Saturn\",\"Uranus\",\"Neptune\"};\n int pos1=-1,pos2=-1,m;\n for (m=0;m<planets.size();m++)\n {\n if (planets[m]==planet1) pos1=m;\n if (planets[m]==planet2) pos2=m;\n }\n if (pos1==-1 or pos2==-1) return {};\n if (pos1>pos2) {m=pos1;pos1=pos2;pos2=m;}\n vector<string> out={};\n for (m=pos1+1;m<pos2;m++)\n out.push_back(planets[m]);\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<string> a,vector<string>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(bf(\"Jupiter\", \"Neptune\") , {\"Saturn\", \"Uranus\"}));\n assert (issame(bf(\"Earth\", \"Mercury\") , {\"Venus\",}));\n assert (issame(bf(\"Mercury\", \"Uranus\") , {\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\"}));\n assert (issame(bf(\"Neptune\", \"Venus\") , {\"Earth\", \"Mars\", \"Jupiter\", \"Saturn\", \"Uranus\"}));\n assert (issame(bf(\"Earth\", \"Earth\") , {}));\n assert (issame(bf(\"Mars\", \"Earth\") , {}));\n assert (issame(bf(\"Jupiter\", \"Makemake\") , {}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nvector<string> bf(string planet1,string planet2){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<string> a,vector<string>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(bf(\"Jupiter\", \"Neptune\") , {\"Saturn\", \"Uranus\"}));\n assert (issame(bf(\"Earth\", \"Mercury\") , {\"Venus\",}));\n assert (issame(bf(\"Mercury\", \"Uranus\") , {\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\"}));\n}\n", "buggy_solution": " vector<string> planets={\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupyter\",\"Saturn\",\"Uranus\",\"Neptune\"};\n int pos1=-1,pos2=-1,m;\n for (m=0;m<planets.size();m++)\n {\n if (planets[m]==planet1) pos1=m;\n if (planets[m]==planet2) pos2=m;\n }\n if (pos1==-1 or pos2==-1) return {};\n if (pos1>pos2) {m=pos1;pos1=pos2;pos2=m;}\n vector<string> out={};\n for (m=pos1+1;m<pos2;m++)\n out.push_back(planets[m]);\n return out;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "bf"}
|
150 |
{"task_id": "CPP/149", "prompt": "/*\nWrite a function that accepts a vector of strings as a parameter,\ndeletes the strings that have odd lengths from it,\nand returns the resulted vector with a sorted order,\nThe vector is always a vector of strings and never a vector of numbers,\nand it may contain duplicates.\nThe order of the vector should be ascending by length of each word, and you\nshould return the vector sorted by that rule.\nIf two words have the same length, sort the vector alphabetically.\nThe function should return a vector of strings in sorted order.\nYou may assume that all words will have the same length.\nFor example:\nassert vector_sort({\"aa\", \"a\", \"aaa\"}) => {\"aa\"}\nassert vector_sort({\"ab\", \"a\", \"aaa\", \"cd\"}) => {\"ab\", \"cd\"}\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\nvector<string> sorted_list_sum(vector<string> lst){\n", "canonical_solution": " vector<string> out={};\n for (int i=0;i<lst.size();i++)\n if (lst[i].length()%2==0) out.push_back(lst[i]);\n string mid;\n sort(out.begin(),out.end());\n for (int i=0;i<out.size();i++)\n for (int j=1;j<out.size();j++)\n if (out[j].length()<out[j-1].length())\n {\n mid=out[j];out[j]=out[j-1];out[j-1]=mid;\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<string> a,vector<string>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(sorted_list_sum({\"aa\", \"a\", \"aaa\"}) , {\"aa\"}));\n assert (issame(sorted_list_sum({\"school\", \"AI\", \"asdf\", \"b\"}) , {\"AI\", \"asdf\", \"school\"}));\n assert (issame(sorted_list_sum({\"d\", \"b\", \"c\", \"a\"}) , {}));\n assert (issame(sorted_list_sum({\"d\", \"dcba\", \"abcd\", \"a\"}) , {\"abcd\", \"dcba\"}));\n assert (issame(sorted_list_sum({\"AI\", \"ai\", \"au\"}) , {\"AI\", \"ai\", \"au\"}));\n assert (issame(sorted_list_sum({\"a\", \"b\", \"b\", \"c\", \"c\", \"a\"}) , {}));\n assert (issame(sorted_list_sum({\"aaaa\", \"bbbb\", \"dd\", \"cc\"}) , {\"cc\", \"dd\", \"aaaa\", \"bbbb\"}));\n}\n", "declaration": "#include<stdio.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<math.h>\n#include<stdlib.h>\nvector<string> sorted_list_sum(vector<string> lst){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<string> a,vector<string>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(sorted_list_sum({\"aa\", \"a\", \"aaa\"}) , {\"aa\"}));\n assert (issame(sorted_list_sum({\"ab\", \"a\", \"aaa\", \"cd\"}) , {\"ab\", \"cd\"}));\n}\n", "buggy_solution": " vector<string> out={};\n for (int i=0;i<lst.size();i++)\n if (lst[i].length()%2==0) out.push_back(lst[i]);\n string mid;\n for (int i=0;i<out.size();i++)\n for (int j=1;j<out.size();j++)\n if (out[j].length()<out[j-1].length())\n {\n mid=out[j];out[j]=out[j-1];out[j-1]=mid;\n }\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sorted_list_sum"}
|
151 |
{"task_id": "CPP/150", "prompt": "/*\nA simple program which should return the value of x if n is \na prime number and should return the value of y otherwise.\n\nExamples:\nfor x_or_y(7, 34, 12) == 34\nfor x_or_y(15, 8, 5) == 5\n\n*/\n#include<stdio.h>\nusing namespace std;\nint x_or_y(int n,int x,int y){\n", "canonical_solution": " bool isp=true;\n if (n<2) isp=false;\n for (int i=2;i*i<=n;i++)\n if (n%i==0) isp=false;\n if (isp) return x;\n return y;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (x_or_y(7, 34, 12) == 34);\n assert (x_or_y(15, 8, 5) == 5);\n assert (x_or_y(3, 33, 5212) == 33);\n assert (x_or_y(1259, 3, 52) == 3);\n assert (x_or_y(7919, -1, 12) == -1);\n assert (x_or_y(3609, 1245, 583) == 583);\n assert (x_or_y(91, 56, 129) == 129);\n assert (x_or_y(6, 34, 1234) == 1234);\n assert (x_or_y(1, 2, 0) == 0);\n assert (x_or_y(2, 2, 0) == 2);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint x_or_y(int n,int x,int y){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (x_or_y(7, 34, 12) == 34);\n assert (x_or_y(15, 8, 5) == 5);\n}\n", "buggy_solution": " bool isp=true;\n if (n<2) isp=false;\n for (int i=2;i*i<=n;i++)\n if (n%i-1==0) isp=false;\n if (isp) return x;\n return y;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "x_or_y"}
|
|
|
145 |
{"task_id": "CPP/144", "prompt": "/*\nYour task is to implement a function that will simplify the expression\nx * n. The function returns true if x * n evaluates to a whole number and false\notherwise. Both x and n, are string representation of a fraction, and have the following format,\n<numerator>/<denominator> where both numerator and denominator are positive whole numbers.\n\nYou can assume that x, and n are valid fractions, and do not have zero as denominator.\n\nsimplify(\"1/5\", \"5/1\") = true\nsimplify(\"1/6\", \"2/1\") = false\nsimplify(\"7/10\", \"10/2\") = false\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool simplify(string x,string n){\n", "canonical_solution": " int a,b,c,d,i;\n for (i=0;i<x.size();i++)\n if (x[i]=='/') \n {\n a=atoi(x.substr(0,i).c_str());\n b=atoi(x.substr(i+1).c_str());\n }\n for (i=0;i<n.size();i++)\n if (n[i]=='/') \n {\n c=atoi(n.substr(0,i).c_str());\n d=atoi(n.substr(i+1).c_str());\n }\n if ((a*c)%(b*d)==0) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (simplify(\"1/5\", \"5/1\") == true);\n assert (simplify(\"1/6\", \"2/1\") == false);\n assert (simplify(\"5/1\", \"3/1\") == true);\n assert (simplify(\"7/10\", \"10/2\") == false);\n assert (simplify(\"2/10\", \"50/10\") == true);\n assert (simplify(\"7/2\", \"4/2\") == true);\n assert (simplify(\"11/6\", \"6/1\") == true);\n assert (simplify(\"2/3\", \"5/2\") == false);\n assert (simplify(\"5/2\", \"3/5\") == false);\n assert (simplify(\"2/4\", \"8/4\") == true);\n assert (simplify(\"2/4\", \"4/2\") == true);\n assert (simplify(\"1/5\", \"5/1\") == true);\n assert (simplify(\"1/5\", \"1/5\") == false);\n}\n", "declaration": "#include<stdio.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<math.h>\n#include<stdlib.h>\nbool simplify(string x,string n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (simplify(\"1/5\", \"5/1\") == true);\n assert (simplify(\"1/6\", \"2/1\") == false);\n assert (simplify(\"7/10\", \"10/2\") == false);\n}\n", "buggy_solution": " int a,b,c,d,i;\n for (i=0;i<x.size();i++)\n if (x[i]=='/') \n {\n a=atoi(x.substr(0,i).c_str());\n b=atoi(x.substr(i+1).c_str());\n }\n for (i=0;i<n.size();i++)\n if (n[i]=='/') \n {\n c=atoi(n.substr(0,i).c_str());\n d=atoi(n.substr(i+1).c_str());\n a=atoi(n.substr(0,i).c_str());\n b=atoi(n.substr(i+1).c_str());\n }\n if ((a*c)%(b*d)==0) return true;\n return false;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "simplify"}
|
146 |
{"task_id": "CPP/145", "prompt": "/*\nWrite a function which sorts the given vector of integers\nin ascending order according to the sum of their digits.\nNote: if there are several items with similar sum of their digits,\norder them based on their index in original vector.\n\nFor example:\n>>> order_by_points({1, 11, -1, -11, -12}) == {-1, -11, 1, -12, 11}\n>>> order_by_points({}) == {}\n*/\n#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\nvector<int> order_by_points(vector<int> nums){\n", "canonical_solution": " vector<int> sumdigit={};\n for (int i=0;i<nums.size();i++)\n {\n string w=to_string(abs(nums[i]));\n int sum=0;\n for (int j=1;j<w.length();j++)\n sum+=w[j]-48;\n if (nums[i]>0) sum+=w[0]-48;\n else sum-=w[0]-48;\n sumdigit.push_back(sum);\n }\n int m;\n for (int i=0;i<nums.size();i++)\n for (int j=1;j<nums.size();j++)\n if (sumdigit[j-1]>sumdigit[j])\n {\n m=sumdigit[j];sumdigit[j]=sumdigit[j-1];sumdigit[j-1]=m;\n m=nums[j];nums[j]=nums[j-1];nums[j-1]=m;\n }\n \n return nums;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(order_by_points({1, 11, -1, -11, -12}) , {-1, -11, 1, -12, 11}));\n assert (issame(order_by_points({1234,423,463,145,2,423,423,53,6,37,3457,3,56,0,46}) , {0, 2, 3, 6, 53, 423, 423, 423, 1234, 145, 37, 46, 56, 463, 3457}));\n assert (issame(order_by_points({}) , {}));\n assert (issame(order_by_points({1, -11, -32, 43, 54, -98, 2, -3}) , {-3, -32, -98, -11, 1, 2, 43, 54}));\n assert (issame(order_by_points({1,2,3,4,5,6,7,8,9,10,11}) , {1, 10, 2, 11, 3, 4, 5, 6, 7, 8, 9}));\n assert (issame(order_by_points({0,6,6,-76,-21,23,4}) , {-76, -21, 0, 4, 23, 6, 6}));\n \n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nvector<int> order_by_points(vector<int> nums){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(order_by_points({1, 11, -1, -11, -12}) , {-1, -11, 1, -12, 11}));\n assert (issame(order_by_points({}) , {}));\n}\n", "buggy_solution": " vector<int> sumdigit={};\n for (int i=0;i<nums.size();i++)\n {\n string w=to_string(abs(nums[i]));\n int sum=0;\n for (int j=1;j<w.length();j++)\n sum+=w[j]-48;\n if (nums[i]>0) sum+=w[0]-48;\n else sum-=w[0]-48;\n sumdigit.push_back(sum);\n }\n int m;\n for (int i=0;i<nums.size();i++)\n for (int j=1;j<nums.size();j++)\n if (sumdigit[j-1]>sumdigit[j])\n {\n m=sumdigit[j];sumdigit[j]=sumdigit[j-1];sumdigit[j-1]=m;sumdigit[j]=m;\n m=nums[j];nums[j]=nums[j-1];nums[j-1]=m;nums[j]=m;\n }\n \n return nums;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "order_by_points"}
|
147 |
{"task_id": "CPP/146", "prompt": "/*\nWrite a function that takes a vector of numbers as input and returns \nthe number of elements in the vector that are greater than 10 and both \nfirst and last digits of a number are odd (1, 3, 5, 7, 9).\nFor example:\nspecialFilter({15, -73, 14, -15}) => 1 \nspecialFilter({33, -2, -3, 45, 21, 109}) => 2\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nint specialFilter(vector<int> nums){\n", "canonical_solution": " int num=0;\n for (int i=0;i<nums.size();i++)\n if (nums[i]>10)\n {\n string w=to_string(nums[i]);\n if (w[0]%2==1 and w[w.length()-1]%2==1) num+=1;\n }\n return num;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (specialFilter({5, -2, 1, -5}) == 0 );\n assert (specialFilter({15, -73, 14, -15}) == 1);\n assert (specialFilter({33, -2, -3, 45, 21, 109}) == 2);\n assert (specialFilter({43, -12, 93, 125, 121, 109}) == 4);\n assert (specialFilter({71, -2, -33, 75, 21, 19}) == 3);\n assert (specialFilter({1}) == 0 );\n assert (specialFilter({}) == 0 );\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint specialFilter(vector<int> nums){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (specialFilter({15, -73, 14, -15}) == 1);\n assert (specialFilter({33, -2, -3, 45, 21, 109}) == 2);\n}\n", "buggy_solution": " int num=0;\n for (int i=0;i<nums.size();i++)\n if (nums[i]>10)\n {\n string w=to_string(nums[i]);\n if (w[0]%2==1 and w[w.length()-1]%2==1 and w[w.length()-1]%2==0) num+=1;\n }\n return num;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "specialFilter"}
|
148 |
+
{"task_id": "CPP/147", "prompt": "/*\nYou are given a positive integer n. You have to create an integer vector a of length n.\n For each i (1 \u2264 i \u2264 n), the value of a{i} = i * i - i + 1.\n Return the number of triples (a{i}, a{j}, a{k}) of a where i < j < k, \nand a[i] + a[j] + a[k] is a multiple of 3.\n\nExample :\n Input: n = 5\n Output: 1\n Explanation: \n a = {1, 3, 7, 13, 21}\n The only valid triple is (1, 7, 13).\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nint get_matrix_triples(int n){\n", "canonical_solution": " vector<int> a;\n vector<vector<int>> sum={{0,0,0}};\n vector<vector<int>> sum2={{0,0,0}};\n for (int i=1;i<=n;i++)\n {\n a.push_back((i*i-i+1)%3);\n sum.push_back(sum[sum.size()-1]);\n sum[i][a[i-1]]+=1;\n }\n for (int times=1;times<3;times++)\n {\n for (int i=1;i<=n;i++)\n {\n sum2.push_back(sum2[sum2.size()-1]);\n if (i>=1)\n for (int j=0;j<=2;j++)\n sum2[i][(a[i-1]+j)%3]+=sum[i-1][j];\n }\n sum=sum2;\n sum2={{0,0,0}};\n }\n\n return sum[n][0];\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (get_matrix_triples(5) == 1);\n assert (get_matrix_triples(6) == 4);\n assert (get_matrix_triples(10) == 36);\n assert (get_matrix_triples(100) == 53361);\n}\n", "declaration": "#include<stdio.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nint get_matrix_triples(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (get_matrix_triples(5) == 1);\n}\n", "buggy_solution": " vector<int> a;\n vector<vector<int>> sum={{0,0,0}};\n vector<vector<int>> sum2={{0,0,0}};\n for (int i=1;i<=n;i++)\n {\n a.push_back((i*i)%3);\n sum.push_back(sum[sum.size()-1]);\n sum[i][a[i-1]]+=1;\n }\n for (int times=1;times<3;times++)\n {\n for (int i=1;i<=n;i++)\n {\n sum2.push_back(sum2[sum2.size()-1]);\n if (i>=1)\n for (int j=0;j<=2;j++)\n sum2[i][(a[i-1]+j)%3]+=sum[i-1][j];\n }\n sum=sum2;\n sum2={{0,0,0}};\n }\n\n return sum[n][0];\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "get_matrix_triples"}
|
149 |
{"task_id": "CPP/148", "prompt": "/*\nThere are eight planets in our solar system: the closerst to the Sun \nis Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, \nUranus, Neptune.\nWrite a function that takes two planet names as strings planet1 and planet2. \nThe function should return a vector containing all planets whose orbits are \nlocated between the orbit of planet1 and the orbit of planet2, sorted by \nthe proximity to the sun. \nThe function should return an empty vector if planet1 or planet2\nare not correct planet names. \nExamples\nbf(\"Jupiter\", \"Neptune\") ==> {\"Saturn\", \"Uranus\"}\nbf(\"Earth\", \"Mercury\") ==> {\"Venus\"}\nbf(\"Mercury\", \"Uranus\") ==> {\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\"}\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nvector<string> bf(string planet1,string planet2){\n", "canonical_solution": " vector<string> planets={\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupiter\",\"Saturn\",\"Uranus\",\"Neptune\"};\n int pos1=-1,pos2=-1,m;\n for (m=0;m<planets.size();m++)\n {\n if (planets[m]==planet1) pos1=m;\n if (planets[m]==planet2) pos2=m;\n }\n if (pos1==-1 or pos2==-1) return {};\n if (pos1>pos2) {m=pos1;pos1=pos2;pos2=m;}\n vector<string> out={};\n for (m=pos1+1;m<pos2;m++)\n out.push_back(planets[m]);\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<string> a,vector<string>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(bf(\"Jupiter\", \"Neptune\") , {\"Saturn\", \"Uranus\"}));\n assert (issame(bf(\"Earth\", \"Mercury\") , {\"Venus\",}));\n assert (issame(bf(\"Mercury\", \"Uranus\") , {\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\"}));\n assert (issame(bf(\"Neptune\", \"Venus\") , {\"Earth\", \"Mars\", \"Jupiter\", \"Saturn\", \"Uranus\"}));\n assert (issame(bf(\"Earth\", \"Earth\") , {}));\n assert (issame(bf(\"Mars\", \"Earth\") , {}));\n assert (issame(bf(\"Jupiter\", \"Makemake\") , {}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nvector<string> bf(string planet1,string planet2){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<string> a,vector<string>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(bf(\"Jupiter\", \"Neptune\") , {\"Saturn\", \"Uranus\"}));\n assert (issame(bf(\"Earth\", \"Mercury\") , {\"Venus\",}));\n assert (issame(bf(\"Mercury\", \"Uranus\") , {\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\"}));\n}\n", "buggy_solution": " vector<string> planets={\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupyter\",\"Saturn\",\"Uranus\",\"Neptune\"};\n int pos1=-1,pos2=-1,m;\n for (m=0;m<planets.size();m++)\n {\n if (planets[m]==planet1) pos1=m;\n if (planets[m]==planet2) pos2=m;\n }\n if (pos1==-1 or pos2==-1) return {};\n if (pos1>pos2) {m=pos1;pos1=pos2;pos2=m;}\n vector<string> out={};\n for (m=pos1+1;m<pos2;m++)\n out.push_back(planets[m]);\n return out;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "bf"}
|
150 |
{"task_id": "CPP/149", "prompt": "/*\nWrite a function that accepts a vector of strings as a parameter,\ndeletes the strings that have odd lengths from it,\nand returns the resulted vector with a sorted order,\nThe vector is always a vector of strings and never a vector of numbers,\nand it may contain duplicates.\nThe order of the vector should be ascending by length of each word, and you\nshould return the vector sorted by that rule.\nIf two words have the same length, sort the vector alphabetically.\nThe function should return a vector of strings in sorted order.\nYou may assume that all words will have the same length.\nFor example:\nassert vector_sort({\"aa\", \"a\", \"aaa\"}) => {\"aa\"}\nassert vector_sort({\"ab\", \"a\", \"aaa\", \"cd\"}) => {\"ab\", \"cd\"}\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\nvector<string> sorted_list_sum(vector<string> lst){\n", "canonical_solution": " vector<string> out={};\n for (int i=0;i<lst.size();i++)\n if (lst[i].length()%2==0) out.push_back(lst[i]);\n string mid;\n sort(out.begin(),out.end());\n for (int i=0;i<out.size();i++)\n for (int j=1;j<out.size();j++)\n if (out[j].length()<out[j-1].length())\n {\n mid=out[j];out[j]=out[j-1];out[j-1]=mid;\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<string> a,vector<string>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(sorted_list_sum({\"aa\", \"a\", \"aaa\"}) , {\"aa\"}));\n assert (issame(sorted_list_sum({\"school\", \"AI\", \"asdf\", \"b\"}) , {\"AI\", \"asdf\", \"school\"}));\n assert (issame(sorted_list_sum({\"d\", \"b\", \"c\", \"a\"}) , {}));\n assert (issame(sorted_list_sum({\"d\", \"dcba\", \"abcd\", \"a\"}) , {\"abcd\", \"dcba\"}));\n assert (issame(sorted_list_sum({\"AI\", \"ai\", \"au\"}) , {\"AI\", \"ai\", \"au\"}));\n assert (issame(sorted_list_sum({\"a\", \"b\", \"b\", \"c\", \"c\", \"a\"}) , {}));\n assert (issame(sorted_list_sum({\"aaaa\", \"bbbb\", \"dd\", \"cc\"}) , {\"cc\", \"dd\", \"aaaa\", \"bbbb\"}));\n}\n", "declaration": "#include<stdio.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<math.h>\n#include<stdlib.h>\nvector<string> sorted_list_sum(vector<string> lst){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<string> a,vector<string>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(sorted_list_sum({\"aa\", \"a\", \"aaa\"}) , {\"aa\"}));\n assert (issame(sorted_list_sum({\"ab\", \"a\", \"aaa\", \"cd\"}) , {\"ab\", \"cd\"}));\n}\n", "buggy_solution": " vector<string> out={};\n for (int i=0;i<lst.size();i++)\n if (lst[i].length()%2==0) out.push_back(lst[i]);\n string mid;\n for (int i=0;i<out.size();i++)\n for (int j=1;j<out.size();j++)\n if (out[j].length()<out[j-1].length())\n {\n mid=out[j];out[j]=out[j-1];out[j-1]=mid;\n }\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sorted_list_sum"}
|
151 |
{"task_id": "CPP/150", "prompt": "/*\nA simple program which should return the value of x if n is \na prime number and should return the value of y otherwise.\n\nExamples:\nfor x_or_y(7, 34, 12) == 34\nfor x_or_y(15, 8, 5) == 5\n\n*/\n#include<stdio.h>\nusing namespace std;\nint x_or_y(int n,int x,int y){\n", "canonical_solution": " bool isp=true;\n if (n<2) isp=false;\n for (int i=2;i*i<=n;i++)\n if (n%i==0) isp=false;\n if (isp) return x;\n return y;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (x_or_y(7, 34, 12) == 34);\n assert (x_or_y(15, 8, 5) == 5);\n assert (x_or_y(3, 33, 5212) == 33);\n assert (x_or_y(1259, 3, 52) == 3);\n assert (x_or_y(7919, -1, 12) == -1);\n assert (x_or_y(3609, 1245, 583) == 583);\n assert (x_or_y(91, 56, 129) == 129);\n assert (x_or_y(6, 34, 1234) == 1234);\n assert (x_or_y(1, 2, 0) == 0);\n assert (x_or_y(2, 2, 0) == 2);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint x_or_y(int n,int x,int y){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (x_or_y(7, 34, 12) == 34);\n assert (x_or_y(15, 8, 5) == 5);\n}\n", "buggy_solution": " bool isp=true;\n if (n<2) isp=false;\n for (int i=2;i*i<=n;i++)\n if (n%i-1==0) isp=false;\n if (isp) return x;\n return y;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "x_or_y"}
|
data/java/data/humanevalbugs.jsonl
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
data/js/data/humanevalbugs.jsonl
CHANGED
@@ -64,7 +64,7 @@
|
|
64 |
{"task_id": "JavaScript/63", "prompt": "/*The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\n fibfib(0) == 0\n fibfib(1) == 0\n fibfib(2) == 1\n fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).\n Please write a function to efficiently compute the n-th element of the fibfib number sequence.\n >>> fibfib(1)\n 0\n >>> fibfib(5)\n 4\n >>> fibfib(8)\n 24\n */\nconst fibfib = (n) => {\n", "canonical_solution": " if (n == 0 || n == 1)\n return 0;\n if (n == 2)\n return 1;\n return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3);\n}\n\n", "test": "const testFibfib = () => {\n console.assert(fibfib(2) === 1)\n console.assert(fibfib(1) === 0)\n console.assert(fibfib(5) === 4)\n console.assert(fibfib(8) === 24)\n console.assert(fibfib(10) === 81)\n console.assert(fibfib(12) === 274)\n console.assert(fibfib(14) === 927)\n}\n\ntestFibfib()\n", "declaration": "\nconst fibfib = (n) => {\n", "example_test": "const testFibfib = () => {\n console.assert(fibfib(1) === 0)\n console.assert(fibfib(5) === 4)\n console.assert(fibfib(8) === 24)\n}\ntestFibfib()\n", "buggy_solution": " if (n == 0 || n == 1)\n return n;\n if (n == 2)\n return 2;\n return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fibfib"}
|
65 |
{"task_id": "JavaScript/64", "prompt": "/*Write a function vowelsCount which takes a string representing\n a word as input and returns the number of vowels in the string.\n Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a\n vowel, but only when it is at the end of the given word.\n\n Example:\n >>> vowelsCount(\"abcde\")\n 2\n >>> vowelsCount(\"ACEDY\")\n 3\n */\nconst vowelsCount = (s) => {\n", "canonical_solution": " var vowels = \"aeiouAEIOU\";\n var n_vowels = s.split('').reduce((prev, item) => {\n return prev + (vowels.includes(item));\n }, 0);\n if (s.at(-1) == 'y' || s.at(-1) == 'Y')\n n_vowels += 1;\n return n_vowels;\n}\n\n", "test": "const testVowelsCount = () => {\n console.assert(vowelsCount('abcde') === 2)\n console.assert(vowelsCount('Alone') === 3)\n console.assert(vowelsCount('key') === 2)\n console.assert(vowelsCount('bye') === 1)\n console.assert(vowelsCount('keY') === 2)\n console.assert(vowelsCount('bYe') === 1)\n console.assert(vowelsCount('ACEDY') === 3)\n}\n\ntestVowelsCount()\n", "declaration": "\nconst vowelsCount = (s) => {\n", "example_test": "const testVowelsCount = () => {\n console.assert(vowelsCount('abcde') === 2)\n console.assert(vowelsCount('ACEDY') === 3)\n}\ntestVowelsCount()\n", "buggy_solution": " var vowels = \"aeiouyAEIOUY\";\n var n_vowels = s.split('').reduce((prev, item) => {\n return prev + (vowels.includes(item));\n }, 0);\n return n_vowels;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "vowelsCount"}
|
66 |
{"task_id": "JavaScript/65", "prompt": "/*Circular shift the digits of the integer x, shift the digits right by shift\n and return the result as a string.\n If shift > number of digits, return digits reversed.\n >>> circularShift(12, 1)\n \"21\"\n >>> circularShift(12, 2)\n \"12\"\n */\nconst circularShift = (x, shift) => {\n", "canonical_solution": " s = x.toString();\n if (shift > s.length)\n return s.split('').reverse().join('');\n else\n return s.slice(-shift) + s.slice(0, -shift);\n}\n\n", "test": "const testCircularShift = () => {\n console.assert(circularShift(100, 2) === '001')\n console.assert(circularShift(12, 2) === '12')\n console.assert(circularShift(97, 8) === '79')\n console.assert(circularShift(12, 1) === '21')\n console.assert(circularShift(11, 101) === '11')\n}\n\ntestCircularShift()\n", "declaration": "\nconst circularShift = (x, shift) => {\n", "example_test": "const testCircularShift = () => {\n console.assert(circularShift(12, 2) === '12')\n console.assert(circularShift(12, 1) === '21')\n}\ntestCircularShift()\n", "buggy_solution": " s = x.toString();\n if (shift > s.length)\n return s.split('').reverse().join('');\n else\n return s.slice(0, -shift) + s.slice(-shift);\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "circularShift"}
|
67 |
-
{"task_id": "JavaScript/66", "prompt": "/*Task\n Write a function that takes a string as input and returns the sum of the upper characters only'\n ASCII codes.\n\n Examples:\n digitSum(\"\") => 0\n digitSum(\"abAB\") => 131\n digitSum(\"abcCd\") => 67\n digitSum(\"helloE\") => 69\n digitSum(\"woArBld\") => 131\n digitSum(\"aAaaaXa\") => 153\n */\nconst digitSum = (s) => {\n", "canonical_solution": " if (s == '') return 0;\n return s.split('').reduce((prev, char) => {\n let ord_char = char.charCodeAt(0)\n return prev + (ord_char > 64 && ord_char < 91 ? ord_char : 0);\n }, 0);\n}\n\n", "test": "const testDigitSum = () => {\n console.assert(digitSum('') === 0)\n console.assert(digitSum('abAB') === 131)\n console.assert(digitSum('abcCd') === 67)\n console.assert(digitSum('helloE') === 69)\n console.assert(digitSum('woArBld') === 131)\n console.assert(digitSum('aAaaaXa') === 153)\n console.assert(digitSum(' How are yOu?') === 151)\n console.assert(digitSum('You arE Very Smart') === 327)\n}\n\ntestDigitSum()\n", "declaration": "\nconst digitSum = (s) => {\n", "example_test": "const testDigitSum = () => {\n console.assert(digitSum('') === 0)\n console.assert(digitSum('abAB') === 131)\n console.assert(digitSum('abcCd') === 67)\n console.assert(digitSum('helloE') === 69)\n console.assert(digitSum('woArBld') === 131)\n console.assert(digitSum('aAaaaXa') === 153)\n}\ntestDigitSum()\n", "buggy_solution": " if (s == '') return 0;\n return s.split('').reduce((prev, char) => {\n let ord_char = char.charCodeAt(0)\n return prev + (ord_char > 64 && ord_char < 100 ? ord_char : 0);\n }, 0);\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "
|
68 |
{"task_id": "JavaScript/67", "prompt": "/*\n In this task, you will be given a string that represents a number of apples and oranges\n that are distributed in a basket of fruit this basket contains\n apples, oranges, and mango fruits. Given the string that represents the total number of\n the oranges and apples and an integer that represent the total number of the fruits\n in the basket return the number of the mango fruits in the basket.\n for examble:\n fruitDistribution(\"5 apples and 6 oranges\", 19) ->19 - 5 - 6 = 8\n fruitDistribution(\"0 apples and 1 oranges\",3) -> 3 - 0 - 1 = 2\n fruitDistribution(\"2 apples and 3 oranges\", 100) -> 100 - 2 - 3 = 95\n fruitDistribution(\"100 apples and 1 oranges\",120) -> 120 - 100 - 1 = 19\n */\nconst fruitDistribution = (s, n) => {\n", "canonical_solution": " var lis = [];\n for (const i of s.split(\" \"))\n if (!isNaN(i))\n lis.push(Number(i))\n return n - lis.reduce(((prev, item) => prev + item), 0);\n}\n\n", "test": "const testFruitDistribution = () => {\n console.assert(fruitDistribution('5 apples and 6 oranges', 19) === 8)\n console.assert(fruitDistribution('5 apples and 6 oranges', 21) === 10)\n console.assert(fruitDistribution('0 apples and 1 oranges', 3) === 2)\n console.assert(fruitDistribution('1 apples and 0 oranges', 3) === 2)\n console.assert(fruitDistribution('2 apples and 3 oranges', 100) === 95)\n console.assert(fruitDistribution('2 apples and 3 oranges', 5) === 0)\n console.assert(fruitDistribution('1 apples and 100 oranges', 120) === 19)\n}\n\ntestFruitDistribution()\n", "declaration": "\nconst fruitDistribution = (s, n) => {\n", "example_test": "const testFruitDistribution = () => {\n console.assert(fruitDistribution('5 apples and 6 oranges', 19) === 8)\n console.assert(fruitDistribution('0 apples and 1 oranges', 3) === 2)\n console.assert(fruitDistribution('2 apples and 3 oranges', 100) === 95)\n console.assert(fruitDistribution('1 apples and 100 oranges', 120) === 19)\n}\ntestFruitDistribution()\n", "buggy_solution": " var lis = [];\n for (const i of s.split(\" \"))\n if (!isNaN(i))\n lis.push(Number(i))\n return n - 1 - lis.reduce(((prev, item) => prev + item), 0);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fruitDistribution"}
|
69 |
{"task_id": "JavaScript/68", "prompt": "/*\n \"Given an array representing a branch of a tree that has non-negative integer nodes\n your task is to pluck one of the nodes and return it.\n The plucked node should be the node with the smallest even value.\n If multiple nodes with the same smallest even value are found return the node that has smallest index.\n\n The plucked node should be returned in a list, [ smalest_value, its index ],\n If there are no even values or the given array is empty, return [].\n\n Example 1:\n Input: [4,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index.\n\n Example 2:\n Input: [1,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index.\n\n Example 3:\n Input: []\n Output: []\n\n Example 4:\n Input: [5, 0, 3, 0, 4, 2]\n Output: [0, 1]\n Explanation: 0 is the smallest value, but there are two zeros,\n so we will choose the first zero, which has the smallest index.\n\n Constraints:\n * 1 <= nodes.length <= 10000\n * 0 <= node.value\n */\nconst pluck = (arr) => {\n", "canonical_solution": " if (arr.length == 0) return [];\n var evens = arr.filter(x => x % 2 == 0);\n if (evens.length == 0) return [];\n return [Math.min(...evens), arr.indexOf(Math.min(...evens))];\n}\n\n", "test": "const testPluck = () => {\n console.assert(JSON.stringify(pluck([4, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([1, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(pluck([5, 0, 3, 0, 4, 2])) === JSON.stringify([0, 1])\n )\n console.assert(\n JSON.stringify(pluck([1, 2, 3, 0, 5, 3])) === JSON.stringify([0, 3])\n )\n console.assert(\n JSON.stringify(pluck([5, 4, 8, 4, 8])) === JSON.stringify([4, 1])\n )\n console.assert(JSON.stringify(pluck([7, 6, 7, 1])) === JSON.stringify([6, 1]))\n console.assert(JSON.stringify(pluck([7, 9, 7, 1])) === JSON.stringify([]))\n}\n\ntestPluck()\n", "declaration": "\nconst pluck = (arr) => {\n", "example_test": "const testPluck = () => {\n console.assert(JSON.stringify(pluck([4, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([1, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(pluck([5, 0, 3, 0, 4, 2])) === JSON.stringify([0, 1])\n )\n}\ntestPluck()\n", "buggy_solution": " if (arr.length == 0) return [];\n var evens = arr.filter(x => x % 2 == 0);\n if (evens.length == 0) return [];\n return [arr.indexOf(Math.min(...evens)), Math.min(...evens)];\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "pluck"}
|
70 |
{"task_id": "JavaScript/69", "prompt": "/*\n You are given a non-empty list of positive integers. Return the greatest integer that is greater than\n zero, and has a frequency greater than or equal to the value of the integer itself.\n The frequency of an integer is the number of times it appears in the list.\n If no such a value exist, return -1.\n Examples:\n search([4, 1, 2, 2, 3, 1])) == 2\n search([1, 2, 2, 3, 3, 3, 4, 4, 4])) == 3\n search([5, 5, 4, 4, 4])) == -1\n */\nconst search = (lst) => {\n", "canonical_solution": " var frq = new Array(Math.max(...lst) + 1).fill(0);\n for (const i of lst)\n frq[i] += 1;\n var ans = -1;\n for (let i = 1; i < frq.length; i++)\n if (frq[i] >= i)\n ans = i;\n return ans;\n}\n\n", "test": "const testSearch = () => {\n console.assert(search([5, 5, 5, 5, 1]) === 1)\n console.assert(search([4, 1, 4, 1, 4, 4]) === 4)\n console.assert(search([3, 3]) === -1)\n console.assert(search([8, 8, 8, 8, 8, 8, 8, 8]) === 8)\n console.assert(search([2, 3, 3, 2, 2]) === 2)\n console.assert(\n search([\n 2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1,\n ]) === 1\n )\n console.assert(search([3, 2, 8, 2]) === 2)\n console.assert(search([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]) === 1)\n console.assert(search([8, 8, 3, 6, 5, 6, 4]) === -1)\n console.assert(\n search([\n 6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5,\n 7, 9,\n ]) === 1\n )\n console.assert(search([1, 9, 10, 1, 3]) === 1)\n console.assert(\n search([\n 6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3,\n 10,\n ]) === 5\n )\n console.assert(search([1]) === 1)\n console.assert(\n search([\n 8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5,\n ]) === 4\n )\n console.assert(\n search([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]) === 2\n )\n console.assert(search([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]) === 1)\n console.assert(\n search([\n 9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7,\n 10, 2, 8, 10, 9, 4,\n ]) === 4\n )\n console.assert(\n search([\n 2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7,\n ]) === 4\n )\n console.assert(\n search([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]) === 2\n )\n console.assert(\n search([\n 5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8,\n ]) === -1\n )\n console.assert(search([10]) === -1)\n console.assert(search([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]) === 2)\n console.assert(search([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]) === 1)\n console.assert(\n search([\n 7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6,\n ]) === 1\n )\n console.assert(search([3, 10, 10, 9, 2]) === -1)\n}\n\ntestSearch()\n", "declaration": "\nconst search = (lst) => {\n", "example_test": "const testSearch = () => {\n console.assert(search([4, 1, 2, 2, 3, 1]) === 2)\n console.assert(search([1, 2, 2, 3, 3, 3, 4, 4, 4]) === 3)\n console.assert(search([5, 5, 4, 4, 4]) === -1)\n}\ntestSearch()\n", "buggy_solution": " var frq = new Array(Math.max(...lst) + 1).fill(0);\n for (const i of lst)\n frq[i] += 1;\n var ans = 0;\n for (let i = 1; i < frq.length; i++)\n if (frq[i] >= i)\n ans = i;\n return ans;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "search"}
|
@@ -112,7 +112,7 @@
|
|
112 |
{"task_id": "JavaScript/111", "prompt": "/*Given a string representing a space separated lowercase letters, return a dictionary\n of the letter with the most repetition and containing the corresponding count.\n If several letters have the same occurrence, return all of them.\n \n Example:\n histogram('a b c') == {'a': 1, 'b': 1, 'c': 1}\n histogram('a b b a') == {'a': 2, 'b': 2}\n histogram('a b c a b') == {'a': 2, 'b': 2}\n histogram('b b b b a') == {'b': 4}\n histogram('') == {}\n\n */\nconst histogram = (test) => {\n", "canonical_solution": " let d = {}\n let t = test.split(/\\s/)\n if (test == '') { t = [] }\n for (m in t) {\n if (t[m] in d) {\n d[t[m]]++\n }\n else {\n d[t[m]] = 1\n }\n }\n s = Object.keys(d).sort(function (a, b) { return - d[a] + d[b]; });\n if (s.length == 0) { return {} }\n let g = d[s[0]]\n let l = {}\n for (let ss=0; ss<s.length; ss++) {\n if (d[s[ss]] == g) {\n l[s[ss]] = d[s[ss]]\n }\n }\n return l\n}\n\n", "test": "const testHistogram = () => {\n console.assert(\n JSON.stringify(histogram('a b b a')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c a b')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c d g')) ===\n JSON.stringify({ a: 1, b: 1, c: 1, d: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('r t g')) === JSON.stringify({ r: 1, t: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('b b b b a')) === JSON.stringify({ b: 4 })\n )\n console.assert(\n JSON.stringify(histogram('r t g')) === JSON.stringify({ r: 1, t: 1, g: 1 })\n )\n console.assert(JSON.stringify(histogram('')) === JSON.stringify({}))\n console.assert(JSON.stringify(histogram('a')) === JSON.stringify({ a: 1 }))\n}\n\ntestHistogram()\n", "declaration": "\nconst histogram = (test) => {\n", "example_test": "const testHistogram = () => {\n console.assert(\n JSON.stringify(histogram('a b b a')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c a b')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c d g')) ===\n JSON.stringify({ a: 1, b: 1, c: 1, d: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('a b c')) === JSON.stringify({ a: 1, b: 1, c: 1 })\n )\n console.assert(\n JSON.stringify(histogram('b b b b a')) === JSON.stringify({ b: 4 })\n )\n console.assert(JSON.stringify(histogram('')) === JSON.stringify({}))\n}\ntestHistogram()\n", "buggy_solution": " let d = {}\n let t = test.split(/\\s/)\n if (test == '') { t = [] }\n for (m in t) {\n if (t[m] in d) {\n d[t[m]]++\n }\n else {\n d[t[m]] = 1\n }\n }\n s = Object.keys(d).sort(function (a, b) { return - d[a] + d[b]; });\n if (s.length == 0) { return {} }\n let g = d[s[0]]\n let l = {}\n for (let ss=1; ss<s.length; ss++) {\n if (d[s[ss]] == g) {\n l[s[ss]] = d[s[ss]]\n }\n }\n return l\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "histogram"}
|
113 |
{"task_id": "JavaScript/112", "prompt": "/*Task\n We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\n then check if the result string is palindrome.\n A string is called palindrome if it reads the same backward as forward.\n You should return a tuple containing the result string and true/false for the check.\n Example\n For s = \"abcde\", c = \"ae\", the result should be ('bcd',false)\n For s = \"abcdef\", c = \"b\" the result should be ('acdef',false)\n For s = \"abcdedcba\", c = \"ab\", the result should be ('cdedc',true)\n */\nconst reverseDelete = (s, c) => {\n", "canonical_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let y = 1\n for (let j = 0; j < c.length; j++) {\n if (s[i] == c[j]) {\n y = 0\n }\n }\n if (y == 1) {\n t += s[i]\n }\n }\n let isPalindrome = true\n for (let i = 0; i < Math.floor(t.length / 2); i++) {\n if (t[i] != t[t.length - i - 1]) {\n isPalindrome = false\n break\n }\n }\n return [t, isPalindrome];\n}\n\n", "test": "const testReverseDelete = () => {\n console.assert(JSON.stringify(reverseDelete('abcde', 'ae')) ===\n JSON.stringify(['bcd', false]))\n console.assert(JSON.stringify(reverseDelete('abcdef', 'b')) ===\n JSON.stringify(['acdef', false]))\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'ab')) ===\n JSON.stringify(['cdedc', true]))\n console.assert(JSON.stringify(reverseDelete('dwik', 'w')) ===\n JSON.stringify(['dik', false]))\n console.assert(JSON.stringify(reverseDelete('a', 'a')) ===\n JSON.stringify(['', true]))\n console.assert(JSON.stringify(reverseDelete('abcdedcba', '')) ===\n JSON.stringify(['abcdedcba', true]))\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'v')) ===\n JSON.stringify(['abcdedcba', true]))\n console.assert(JSON.stringify(reverseDelete('vabba', 'v')) ===\n JSON.stringify(['abba', true]))\n console.assert(JSON.stringify(reverseDelete('mamma', 'mia')) ===\n JSON.stringify(['', true]))\n}\n\ntestReverseDelete()\n", "declaration": "\nconst reverseDelete = (s, c) => {\n", "example_test": "const testReverseDelete = () => {\n console.assert(JSON.stringify(reverseDelete('abcde', 'ae'))) ===\n JSON.stringify(['bcd', false])\n console.assert(JSON.stringify(reverseDelete('abcdef', 'b'))) ===\n JSON.stringify(['acdef', false])\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'ab'))) ===\n JSON.stringify(['cdedc', true])\n}\ntestReverseDelete()\n", "buggy_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let y = 1\n for (let j = 0; j < c.length; j++) {\n if (s[i] == c[j]) {\n y = 0\n }\n }\n if (y == 1) {\n t += s[i]\n }\n }\n let isPalindrome = false\n for (let i = 0; i < Math.floor(t.length / 2); i++) {\n if (t[i] != t[t.length - i - 1]) {\n isPalindrome = true\n break\n }\n }\n return [t, isPalindrome];\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "reverseDelete"}
|
114 |
{"task_id": "JavaScript/113", "prompt": "/*Given a list of strings, where each string consists of only digits, return a list.\n Each element i of the output should be \"the number of odd elements in the\n string i of the input.\" where all the i's should be replaced by the number\n of odd digits in the i'th string of the input.\n\n >>> oddCount(['1234567'])\n [\"the number of odd elements 4n the str4ng 4 of the 4nput.\"]\n >>> oddCount(['3',\"11111111\"])\n [\"the number of odd elements 1n the str1ng 1 of the 1nput.\",\n \"the number of odd elements 8n the str8ng 8 of the 8nput.\"]\n */\nconst oddCount = (lst) => {\n", "canonical_solution": " let d = []\n for (let i = 0; i < lst.length; i++) {\n let p = 0;\n let h = lst[i].length\n for (let j = 0; j < h; j++) {\n if (lst[i][j].charCodeAt() % 2 == 1) { p++ }\n }\n p = p.toString()\n d.push('the number of odd elements ' + p + 'n the str' + p + 'ng ' + p + ' of the ' + p + 'nput.')\n }\n return d\n}\n\n", "test": "const testOddCount = () => {\n console.assert(\n JSON.stringify(oddCount(['1234567'])) ===\n JSON.stringify([\n 'the number of odd elements 4n the str4ng 4 of the 4nput.',\n ])\n )\n console.assert(JSON.stringify(\n oddCount(['3', '11111111'])) ===\n JSON.stringify([\n 'the number of odd elements 1n the str1ng 1 of the 1nput.',\n 'the number of odd elements 8n the str8ng 8 of the 8nput.',\n ])\n )\n console.assert(\n JSON.stringify(oddCount(['271', '137', '314'])) ===\n JSON.stringify([\n 'the number of odd elements 2n the str2ng 2 of the 2nput.',\n 'the number of odd elements 3n the str3ng 3 of the 3nput.',\n 'the number of odd elements 2n the str2ng 2 of the 2nput.',\n ])\n )\n}\n\ntestOddCount()\n", "declaration": "\nconst oddCount = (lst) => {\n", "example_test": "const testOddCount = () => {\n console.assert(\n JSON.stringify(oddCount(['1234567'])) ===\n JSON.stringify([\n 'the number of odd elements 4n the str4ng 4 of the 4nput.',\n ])\n )\n console.assert(JSON.stringify(\n oddCount(['3', '11111111'])) ===\n JSON.stringify([\n 'the number of odd elements 1n the str1ng 1 of the 1nput.',\n 'the number of odd elements 8n the str8ng 8 of the 8nput.',\n ])\n )\n}\ntestOddCount()\n", "buggy_solution": " let d = []\n for (let i = 0; i < lst.length; i++) {\n let p = 0;\n let h = lst[i].length\n for (let j = 0; j < h; j++) {\n if (lst[i][j].charCodeAt() % 2 == 1) { p++ }\n }\n p = p.toString()\n d.push('the number of odd elements ' + p + 'n the str' + p + 'ng ' + p + ' of ' p + ' the ' + p + 'nput.')\n }\n return d\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "oddCount"}
|
115 |
-
{"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": "
|
116 |
{"task_id": "JavaScript/115", "prompt": "/*\n You are given a rectangular grid of wells. Each row represents a single well,\n and each 1 in a row represents a single unit of water.\n Each well has a corresponding bucket that can be used to extract water from it, \n and all buckets have the same capacity.\n Your task is to use the buckets to empty the wells.\n Output the number of times you need to lower the buckets.\n\n Example 1:\n Input: \n grid : [[0,0,1,0], [0,1,0,0], [1,1,1,1]]\n bucket_capacity : 1\n Output: 6\n\n Example 2:\n Input: \n grid : [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]]\n bucket_capacity : 2\n Output: 5\n \n Example 3:\n Input: \n grid : [[0,0,0], [0,0,0]]\n bucket_capacity : 5\n Output: 0\n\n Constraints:\n * all wells have the same length\n * 1 <= grid.length <= 10^2\n * 1 <= grid[:,1].length <= 10^2\n * grid[i][j] -> 0 | 1\n * 1 <= capacity <= 10\n */\nconst maxFill = (grid, capacity) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < grid.length; i++) {\n let m = 0\n for (let j = 0; j < grid[i].length; j++) {\n if (grid[i][j] == 1) { m++ }\n }\n while (m > 0) {\n m -= capacity;\n p++;\n }\n }\n return p\n}\n\n", "test": "const testMaxFill = () => {\n console.assert(\n maxFill(\n [\n [0, 0, 1, 0],\n [0, 1, 0, 0],\n [1, 1, 1, 1],\n ],\n 1\n ) === 6\n )\n console.assert(\n maxFill(\n [\n [0, 0, 1, 1],\n [0, 0, 0, 0],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n ],\n 2\n ) === 5\n )\n console.assert(\n maxFill(\n [\n [0, 0, 0],\n [0, 0, 0],\n ],\n 5\n ) === 0\n )\n console.assert(\n maxFill(\n [\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n ],\n 2\n ) === 4\n )\n console.assert(\n maxFill(\n [\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n ],\n 9\n ) === 2\n )\n}\n\ntestMaxFill()\n", "declaration": "\nconst maxFill = (grid, capacity) => {\n", "example_test": "const testMaxFill = () => {\n console.assert(\n maxFill(\n [\n [0, 0, 1, 0],\n [0, 1, 0, 0],\n [1, 1, 1, 1],\n ],\n 1\n ) === 6\n )\n console.assert(\n maxFill(\n [\n [0, 0, 1, 1],\n [0, 0, 0, 0],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n ],\n 2\n ) === 5\n )\n console.assert(\n maxFill(\n [\n [0, 0, 0],\n [0, 0, 0],\n ],\n 5\n ) === 0\n )\n}\ntestMaxFill()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < grid.length; i++) {\n let m = 0\n for (let j = 1; j < grid[i].length; j++) {\n if (grid[i][j] == 1) { m++ }\n }\n while (m > 0) {\n m -= capacity;\n p++;\n }\n }\n return p\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "maxFill"}
|
117 |
{"task_id": "JavaScript/116", "prompt": "/*\n In this Kata, you have to sort an array of non-negative integers according to\n number of ones in their binary representation in ascending order.\n For similar number of ones, sort based on decimal value.\n\n It must be implemented like this:\n >>> sortArray([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n >>> sortArray([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n >>> sortArray([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]\n */\nconst sortArray = (arr) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[k].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(sortArray([2, 5, 77, 4, 5, 3, 5, 7, 2, 3, 4])) ===\n JSON.stringify([2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77])\n )\n console.assert(\n JSON.stringify(sortArray([3, 6, 44, 12, 32, 5])) ===\n JSON.stringify([32, 3, 5, 6, 12, 44])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n}\n\ntestSortArray()\n", "declaration": "\nconst sortArray = (arr) => {\n", "example_test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n}\ntestSortArray()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[ind].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return arr\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "sortArray"}
|
118 |
{"task_id": "JavaScript/117", "prompt": "/*Given a string s and a natural number n, you have been tasked to implement \n a function that returns a list of all words from string s that contain exactly \n n consonants, in order these words appear in the string s.\n If the string s is empty then the function should return an empty list.\n Note: you may assume the input string contains only letters and spaces.\n Examples:\n selectWords(\"Mary had a little lamb\", 4) ==> [\"little\"]\n selectWords(\"Mary had a little lamb\", 3) ==> [\"Mary\")\n selectWords(\"simple white space\", 2) ==> []\n selectWords(\"Hello world\", 4) ==> [\"world\"]\n selectWords(\"Uncle sam\", 3) ==> [\"Uncle\"]\n */\nconst selectWords = (s, n) => {\n", "canonical_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' && t[i][j] != 'e' && t[i][j] != 'i' && t[i][j] != 'o' && t[i][j] != 'u' && t[i][j] != 'A' &&\n t[i][j] != 'U' && t[i][j] != 'O' && t[i][j] != 'I' && t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n\n console.assert(\n JSON.stringify(selectWords('a b c d e f', 1)) ===\n JSON.stringify(['b', 'c', 'd', 'f'])\n )\n\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n console.assert(JSON.stringify(selectWords('', 4)) === JSON.stringify([]))\n}\n\ntestSelectWords()\n", "declaration": "\nconst selectWords = (s, n) => {\n", "example_test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n}\ntestSelectWords()\n", "buggy_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' || t[i][j] != 'e' || t[i][j] != 'i' || t[i][j] != 'o' || t[i][j] != 'u' || t[i][j] != 'A' ||\n t[i][j] != 'U' || t[i][j] != 'O' || t[i][j] != 'I' || t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "selectWords"}
|
@@ -127,7 +127,7 @@
|
|
127 |
{"task_id": "JavaScript/126", "prompt": "/* Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return false. Assume no negative numbers and only integers.\n Examples\n isSorted([5]) \u279e true\n isSorted([1, 2, 3, 4, 5]) \u279e true\n isSorted([1, 3, 2, 4, 5]) \u279e false\n isSorted([1, 2, 3, 4, 5, 6]) \u279e true\n isSorted([1, 2, 3, 4, 5, 6, 7]) \u279e true\n isSorted([1, 3, 2, 4, 5, 6, 7]) \u279e false\n isSorted([1, 2, 2, 3, 3, 4]) \u279e true\n isSorted([1, 2, 2, 2, 3, 4]) \u279e false\n */\nconst isSorted = (lst) => {\n", "canonical_solution": " if (lst.length == 0) { return true }\n let dup = 1\n let pre = lst[0]\n for (let i = 1; i < lst.length; i++) {\n if (lst[i] < pre) { return false }\n if (lst[i] == pre) {\n dup += 1;\n if (dup == 3) { return false }\n } else {\n pre = lst[i]\n dup = 1\n }\n }\n return true\n}\n\n", "test": "const testIsSorted = () => {\n console.assert(isSorted([5]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5]) === false)\n console.assert(isSorted([1, 2, 3, 4, 5, 6]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5, 6, 7]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5, 6, 7]) === false)\n console.assert(isSorted([]) === true)\n console.assert(isSorted([1]) === true)\n console.assert(isSorted([3, 2, 1]) === false)\n console.assert(isSorted([1, 2, 2, 2, 3, 4]) === false)\n console.assert(isSorted([1, 2, 3, 3, 3, 4]) === false)\n console.assert(isSorted([1, 2, 2, 3, 3, 4]) === true)\n console.assert(isSorted([1, 2, 3, 4]) === true)\n}\n\ntestIsSorted()\n", "declaration": "\nconst isSorted = (lst) => {\n", "example_test": "const testIsSorted = () => {\n console.assert(isSorted([5]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5]) === false)\n console.assert(isSorted([1, 2, 3, 4, 5, 6]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5, 6, 7]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5, 6, 7]) === false)\n console.assert(isSorted([1, 2, 2, 2, 3, 4]) === false)\n console.assert(isSorted([1, 2, 2, 3, 3, 4]) === true)\n}\ntestIsSorted()\n", "buggy_solution": " if (lst.length == 0) { return true }\n let dup = 1\n let pre = lst[0]\n for (let i = 1; i < lst.length; i++) {\n if (lst[i] < pre) { return false }\n if (lst[i] == pre) {\n dup += 1;\n if (dup == 3) { return false }\n } else {\n pre = lst[i]\n }\n }\n return true\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "isSorted"}
|
128 |
{"task_id": "JavaScript/127", "prompt": "/*You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two \n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"\n */\nconst intersection = (interval1, interval2) => {\n", "canonical_solution": " let lo = interval1[0]\n if (interval2[0] > lo) { lo = interval2[0] }\n let hi = interval1[1]\n if (interval2[1] < hi) { hi = interval2[1] }\n let len = 0\n if (hi > lo) { len = hi - lo }\n if (len == 1 || len == 0) { return 'NO' }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return 'NO' }\n }\n return 'YES'\n}\n\n", "test": "const testIntersection = () => {\n console.assert(intersection([1, 2], [2, 3]) === 'NO')\n console.assert(intersection([-1, 1], [0, 4]) === 'NO')\n console.assert(intersection([-3, -1], [-5, 5]) === 'YES')\n console.assert(intersection([-2, 2], [-4, 0]) === 'YES')\n console.assert(intersection([-11, 2], [-1, -1]) === 'NO')\n console.assert(intersection([1, 2], [3, 5]) === 'NO')\n console.assert(intersection([1, 2], [1, 2]) === 'NO')\n console.assert(intersection([-2, -2], [-3, -2]) === 'NO')\n}\n\ntestIntersection()\n", "declaration": "\nconst intersection = (interval1, interval2) => {\n", "example_test": "const testIntersection = () => {\n console.assert(intersection([1, 2], [2, 3]) === 'NO')\n console.assert(intersection([-1, 1], [0, 4]) === 'NO')\n console.assert(intersection([-3, -1], [-5, 5]) === 'YES')\n}\ntestIntersection()\n", "buggy_solution": " let lo = interval1[0]\n if (interval2[0] > lo) { lo = interval2[0] }\n let hi = interval1[1]\n if (interval2[1] < hi) { hi = interval2[1] }\n let len = 0\n if (hi > lo) { len = hi }\n if (len == 1 || len == 0) { return 'NO' }\n return 'YES'\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "intersection"}
|
129 |
{"task_id": "JavaScript/128", "prompt": "/*\n You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return null for empty arr.\n\n Example:\n >>> prodSigns([1, 2, 2, -4]) == -9\n >>> prodSigns([0, 1]) == 0\n >>> prodSigns([]) == null\n */\nconst prodSigns = (arr) => {\n", "canonical_solution": " if (arr.length == 0) { return null }\n let n = 1\n let s = 0\n for (let i = 0; i < arr.length; i++) {\n s += arr[i]\n if (arr[i] == 0) { return 0 }\n if (arr[i] < 0) { n = -n; s -= 2 * arr[i] }\n }\n return s * n\n}\n\n", "test": "const testProdSigns = () => {\n console.assert(prodSigns([1, 2, 2, -4]) === -9)\n console.assert(prodSigns([0, 1]) === 0)\n console.assert(prodSigns([1, 1, 1, 2, 3, -1, 1]) === -10)\n console.assert(prodSigns([]) === null)\n console.assert(prodSigns([2, 4, 1, 2, -1, -1, 9]) === 20)\n console.assert(prodSigns([-1, 1, -1, 1]) === 4)\n console.assert(prodSigns([-1, 1, 1, 1]) === -4)\n console.assert(prodSigns([-1, 1, 1, 0]) === 0)\n}\n\ntestProdSigns()\n", "declaration": "\nconst prodSigns = (arr) => {\n", "example_test": "const testProdSigns = () => {\n console.assert(prodSigns([1, 2, 2, -4]) === -9)\n console.assert(prodSigns([0, 1]) === 0)\n console.assert(prodSigns([]) === null)\n}\ntestProdSigns()\n", "buggy_solution": " if (arr.length == 0) { return null }\n let n = 1\n let s = 0\n for (let i = 0; i < arr.length; i++) {\n s += arr[i]\n if (arr[i] == 0) { return 0 }\n if (arr[i] < 0) { n = -n; s -= 2 * arr[i] }\n }\n return s * n * 2\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "prodSigns"}
|
130 |
-
{"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": "
|
131 |
{"task_id": "JavaScript/130", "prompt": "/*Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in \n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8 \n You are given a non-negative integer number n, you have to a return a list of the \n first n + 1 numbers of the Tribonacci sequence.\n Examples:\n tri(3) = [1, 3, 2, 8]\n */\nconst tri = (n) => {\n", "canonical_solution": " if (n == 0) { return [1] }\n if (n == 1) { return [1, 3] }\n let p = [1, 3]\n for (let i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n p.push(1 + i / 2)\n }\n else {\n p.push(p[i - 2] + p[i - 1] + 1 + (i + 1) / 2)\n }\n }\n return p\n}\n\n", "test": "const testTri = () => {\n console.assert(JSON.stringify(tri(3)) === JSON.stringify([1, 3, 2.0, 8.0]))\n\n console.assert(\n JSON.stringify(tri(4)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0])\n )\n console.assert(\n JSON.stringify(tri(5)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0])\n )\n console.assert(\n JSON.stringify(tri(6)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0])\n )\n console.assert(\n JSON.stringify(tri(7)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0])\n )\n console.assert(\n JSON.stringify(tri(8)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0])\n )\n console.assert(\n JSON.stringify(tri(9)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0])\n )\n console.assert(\n JSON.stringify(tri(20)) ===\n JSON.stringify([\n 1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0, 6.0, 48.0, 7.0, 63.0,\n 8.0, 80.0, 9.0, 99.0, 10.0, 120.0, 11.0,\n ])\n )\n console.assert(JSON.stringify(tri(0)) === JSON.stringify([1]))\n console.assert(JSON.stringify(tri(1)) === JSON.stringify([1, 3]))\n}\n\ntestTri()\n", "declaration": "\nconst tri = (n) => {\n", "example_test": "const testTri = () => {\n console.assert(JSON.stringify(tri(3)) === JSON.stringify([1, 3, 2.0, 8.0]))\n}\ntestTri()\n", "buggy_solution": " if (n == 0) { return [1] }\n if (n == 1) { return [1, 3] }\n let p = [1, 3]\n for (let i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n p.push(1 + i / 2)\n }\n else {\n p.push(p[i - 2] + p[i - 1] + 1 + i + (i + 1) / 2)\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "tri"}
|
132 |
{"task_id": "JavaScript/131", "prompt": "/*Given a positive integer n, return the product of the odd digits.\n Return 0 if all digits are even.\n For example:\n digits(1) == 1\n digits(4) == 0\n digits(235) == 15\n */\nconst digits = (n) => {\n", "canonical_solution": " let p = 1\n let k = 1\n while (n > 0) {\n let y = n % 10\n if (y % 2 == 1) {\n p *= y; k = 0;\n }\n n = (n - n % 10) / 10\n }\n if (k == 0) { return p }\n return 0\n}\n\n", "test": "const testDigits = () => {\n console.assert(digits(5) === 5)\n console.assert(digits(54) === 5)\n console.assert(digits(120) === 1)\n console.assert(digits(5014) === 5)\n console.assert(digits(98765) === 315)\n console.assert(digits(5576543) === 2625)\n console.assert(digits(2468) === 0)\n}\n\ntestDigits()\n", "declaration": "\nconst digits = (n) => {\n", "example_test": "const testDigits = () => {\n console.assert(digits(1) === 1)\n console.assert(digits(4) === 0)\n console.assert(digits(235) === 15)\n}\ntestDigits()\n", "buggy_solution": " let p = 1\n let k = 1\n while (n > 0) {\n let y = n % 10\n if (y % 2 == 1) {\n p *= p*y; k = 0;\n }\n n = (n - n % 10) / 10\n }\n if (k == 0) { return p }\n return 0\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "digits"}
|
133 |
{"task_id": "JavaScript/132", "prompt": "/*\n Create a function that takes a string as input which contains only square brackets.\n The function should return true if and only if there is a valid subsequence of brackets\n where at least one bracket in the subsequence is nested.\n isNested('[[]]') \u279e true\n isNested('[]]]]]]][[[[[]') \u279e false\n isNested('[][]') \u279e false\n isNested('[]') \u279e false\n isNested('[[][]]') \u279e true\n isNested('[[]][[') \u279e true\n */\nconst isNested = (string) => {\n", "canonical_solution": " let opening_bracket_index = []\n let closing_bracket_index1 = []\n for (let i = 0; i < string.length; i++) {\n if (string[i] == '[') {\n opening_bracket_index.push(i)\n }\n else {\n closing_bracket_index1.push(i)\n }\n }\n let closing_bracket_index = []\n for (let i = 0; i < closing_bracket_index1.length; i++) {\n closing_bracket_index.push(closing_bracket_index1[closing_bracket_index1.length - i - 1])\n }\n let cnt = 0\n let i = 0\n let l = closing_bracket_index.length\n for (let k = 0; k < opening_bracket_index.length; k++) {\n if (i < l && opening_bracket_index[k] < closing_bracket_index[i]) {\n cnt += 1;\n i += 1;\n }\n }\n return cnt >= 2\n}\n\n", "test": "const testIsNested = () => {\n console.assert(isNested('[[]]') === true)\n console.assert(isNested('[]]]]]]][[[[[]') === false)\n console.assert(isNested('[][]') === false)\n console.assert(isNested('[]') === false)\n console.assert(isNested('[[[[]]]]') === true)\n console.assert(isNested('[]]]]]]]]]]') === false)\n console.assert(isNested('[][][[]]') === true)\n console.assert(isNested('[[]') === false)\n console.assert(isNested('[]]') === false)\n console.assert(isNested('[[]][[') === true)\n console.assert(isNested('[[][]]') === true)\n console.assert(isNested('') === false)\n console.assert(isNested('[[[[[[[[') === false)\n console.assert(isNested(']]]]]]]]') === false)\n}\n\ntestIsNested()\n", "declaration": "\nconst isNested = (string) => {\n", "example_test": "const testIsNested = () => {\n console.assert(isNested('[[]]') === true)\n console.assert(isNested('[]]]]]]][[[[[]') === false)\n console.assert(isNested('[][]') === false)\n console.assert(isNested('[]') === false)\n console.assert(isNested('[[]][[') === true)\n console.assert(isNested('[[][]]') === true)\n}\ntestIsNested()\n", "buggy_solution": " let opening_bracket_index = []\n let closing_bracket_index1 = []\n for (let i = 0; i < string.length; i++) {\n if (string[i] == '(') {\n opening_bracket_index.push(i)\n }\n else {\n closing_bracket_index1.push(i)\n }\n }\n let closing_bracket_index = []\n for (let i = 0; i < closing_bracket_index1.length; i++) {\n closing_bracket_index.push(closing_bracket_index1[closing_bracket_index1.length - i - 1])\n }\n let cnt = 0\n let i = 0\n let l = closing_bracket_index.length\n for (let k = 0; k < opening_bracket_index.length; k++) {\n if (i < l && opening_bracket_index[k] < closing_bracket_index[i]) {\n cnt += 1;\n i += 1;\n }\n }\n return cnt >= 2\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "isNested"}
|
@@ -144,7 +144,7 @@
|
|
144 |
{"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"}
|
145 |
{"task_id": "JavaScript/144", "prompt": "/*Your task is to implement a function that will simplify the expression\n x * n. The function returns true if x * n evaluates to a whole number and false\n otherwise. Both x and n, are string representation of a fraction, and have the following format,\n <numerator>/<denominator> where both numerator and denominator are positive whole numbers.\n\n You can assume that x, and n are valid fractions, and do not have zero as denominator.\n\n simplify(\"1/5\", \"5/1\") = true\n simplify(\"1/6\", \"2/1\") = false\n simplify(\"7/10\", \"10/2\") = false\n */\nconst simplify = (x, n) => {\n", "canonical_solution": " let a = x.split(/\\//)\n let b = n.split(/\\//)\n let m = Number(a[0]) * Number(b[0])\n let r = Number(a[1]) * Number(b[1])\n return m % r == 0\n}\n\n", "test": "const testSimplify = () => {\n console.assert(simplify('1/5', '5/1') === true)\n console.assert(simplify('1/6', '2/1') === false)\n console.assert(simplify('5/1', '3/1') === true)\n console.assert(simplify('7/10', '10/2') === false)\n console.assert(simplify('2/10', '50/10') === true)\n console.assert(simplify('7/2', '4/2') === true)\n console.assert(simplify('11/6', '6/1') === true)\n console.assert(simplify('2/3', '5/2') === false)\n console.assert(simplify('5/2', '3/5') === false)\n console.assert(simplify('2/4', '8/4') === true)\n console.assert(simplify('2/4', '4/2') === true)\n console.assert(simplify('1/5', '5/1') === true)\n console.assert(simplify('1/5', '1/5') === false)\n}\n\ntestSimplify()\n", "declaration": "\nconst simplify = (x, n) => {\n", "example_test": "const testSimplify = () => {\n console.assert(simplify('1/5', '5/1') === true)\n console.assert(simplify('1/6', '2/1') === false)\n console.assert(simplify('7/10', '10/2') === false)\n}\ntestSimplify()\n", "buggy_solution": " let a = x.split(/\\//)\n let b = n.split(/\\//)\n let m = r * Number(a[0]) * Number(b[0])\n let r = m * Number(a[1]) * Number(b[1])\n let m = r * Number(a[1])\n let r = m * Number(b[1])\n return m % r == 0\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "simplify"}
|
146 |
{"task_id": "JavaScript/145", "prompt": "/*\n Write a function which sorts the given list of integers\n in ascending order according to the sum of their digits.\n Note: if there are several items with similar sum of their digits,\n order them based on their index in original list.\n\n For example:\n >>> orderByPoints([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]\n >>> orderByPoints([]) == []\n */\nconst orderByPoints = (nums) => {\n", "canonical_solution": " let p = nums\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let m = 0\n let n = 0\n let h = p[k]\n let d = p[k + 1]\n let y = 1\n let u = 1\n if (h < 0) { y = -1; h = -h; }\n if (d < 0) { u = -1; d = -d; }\n while (h >= 10) {\n m += h % 10;\n h = (h - h % 10) / 10;\n }\n m += y * h\n while (d >= 10) {\n n += d % 10;\n d = (d - d % 10) / 10;\n }\n n += u * d\n if (m > n) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "test": "const testOrderByPoints = () => {\n console.assert(\n JSON.stringify(orderByPoints([1, 11, -1, -11, -12])) ===\n JSON.stringify([-1, -11, 1, -12, 11])\n )\n console.assert(\n JSON.stringify(\n orderByPoints([\n 1234, 423, 463, 145, 2, 423, 423, 53, 6, 37, 3457, 3, 56, 0, 46,\n ])\n ) ===\n JSON.stringify([\n 0, 2, 3, 6, 53, 423, 423, 423, 1234, 145, 37, 46, 56, 463, 3457,\n ])\n )\n console.assert(JSON.stringify(orderByPoints([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(orderByPoints([1, -11, -32, 43, 54, -98, 2, -3])) ===\n JSON.stringify([-3, -32, -98, -11, 1, 2, 43, 54])\n )\n console.assert(\n JSON.stringify(orderByPoints([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])) ===\n JSON.stringify([1, 10, 2, 11, 3, 4, 5, 6, 7, 8, 9])\n )\n console.assert(\n JSON.stringify(orderByPoints([0, 6, 6, -76, -21, 23, 4])) ===\n JSON.stringify([-76, -21, 0, 4, 23, 6, 6])\n )\n}\n\ntestOrderByPoints()\n", "declaration": "\nconst orderByPoints = (nums) => {\n", "example_test": "const testOrderByPoints = () => {\n console.assert(\n JSON.stringify(orderByPoints([1, 11, -1, -11, -12])) ===\n JSON.stringify([-1, -11, 1, -12, 11])\n )\n console.assert(JSON.stringify(orderByPoints([])) === JSON.stringify([]))\n}\ntestOrderByPoints()\n", "buggy_solution": " let p = nums\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let m = 0\n let n = 0\n let h = p[k]\n let d = p[k + 1]\n let y = 1\n let u = 1\n if (h < 0) { y = -1; h = -h; }\n if (d < 0) { u = -1; d = -d; }\n while (h >= 10) {\n m += h % 10;\n h = (h - h % 10) / 10;\n }\n m += y * h + h\n while (d >= 10) {\n n += d % 10;\n d = (d - d % 10) / 10;\n }\n n += u * d\n if (m > n) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "orderByPoints"}
|
147 |
-
{"task_id": "JavaScript/146", "prompt": "/*Write a function that takes an array of numbers as input and returns \n the number of elements in the array that are greater than 10 and both \n first and last digits of a number are odd (1, 3, 5, 7, 9).\n For example:\n specialFilter([15, -73, 14, -15]) => 1 \n specialFilter([33, -2, -3, 45, 21, 109]) => 2\n */\nconst specialFilter = (nums) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < nums.length; i++) {\n if (nums[i] < 10) { continue }\n let y = nums[i].toString()\n if (Number(y[0]) % 2 == 1 && Number(y[y.length - 1]) % 2 == 1) {\n p++\n }\n }\n return p\n}\n\n", "test": "const testSpecialFilter = () => {\n console.assert(specialFilter([5, -2, 1, -5]) === 0)\n console.assert(specialFilter([15, -73, 14, -15]) === 1)\n console.assert(specialFilter([33, -2, -3, 45, 21, 109]) === 2)\n console.assert(specialFilter([43, -12, 93, 125, 121, 109]) === 4)\n console.assert(specialFilter([71, -2, -33, 75, 21, 19]) === 3)\n console.assert(specialFilter([1]) === 0)\n console.assert(specialFilter([]) === 0)\n}\n\ntestSpecialFilter()\n", "declaration": "\nconst specialFilter = (nums) => {\n", "example_test": "const testSpecialFilter = () => {\n console.assert(specialFilter([15, -73, 14, -15]) === 1)\n console.assert(specialFilter([33, -2, -3, 45, 21, 109]) === 2)\n}\ntestSpecialFilter()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < nums.length; i++) {\n if (nums[i] < 10) { continue }\n let y = nums[i].toString()\n if (Number(y[0]) % 2 == 1 && Number(y[y.length - 1]) % 2 == 1 && Number(y[y.length - 1]) % 2 == 0) {\n p++\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "
|
148 |
{"task_id": "JavaScript/147", "prompt": "/*\n You are given a positive integer n. You have to create an integer array a of length n.\n For each i (1 \u2264 i \u2264 n), the value of a[i] = i * i - i + 1.\n Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, \n and a[i] + a[j] + a[k] is a multiple of 3.\n\n Example :\n Input: n = 5\n Output: 1\n Explanation: \n a = [1, 3, 7, 13, 21]\n The only valid triple is (1, 7, 13).\n */\nconst getMaxTriples = (n) => {\n", "canonical_solution": " let y = []\n for (let i = 1; i <= n; i++) {\n y.push(i * i - i + 1)\n }\n let u = 0\n for (let i = 0; i < n - 2; i++) {\n for (let j = i + 1; j < n - 1; j++) {\n for (let k = j + 1; k < n; k++) {\n if ((y[i] + y[j] + y[k]) % 3 == 0) { u++ }\n }\n }\n }\n return u\n}\n\n", "test": "const testGetMaxTriples = () => {\n console.assert(getMaxTriples(5) === 1)\n console.assert(getMaxTriples(6) === 4)\n console.assert(getMaxTriples(10) === 36)\n console.assert(getMaxTriples(100) === 53361)\n}\n\ntestGetMaxTriples()\n", "declaration": "\nconst getMaxTriples = (n) => {\n", "example_test": "const testGetMaxTriples = () => {\n console.assert(getMaxTriples(5) === 1)\n}\ntestGetMaxTriples()\n", "buggy_solution": " let y = []\n for (let i = 1; i <= n; i++) {\n y.push(i)\n }\n let u = 0\n for (let i = 0; i < n - 2; i++) {\n for (let j = i + 1; j < n - 1; j++) {\n for (let k = j + 1; k < n; k++) {\n if ((y[i] + y[j] + y[k]) % 3 == 0) { u++ }\n }\n }\n }\n return u\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "getMaxTriples"}
|
149 |
{"task_id": "JavaScript/148", "prompt": "/* There are eight planets in our solar system: the closerst to the Sun\n is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,\n Uranus, Neptune.\n Write a function that takes two planet names as strings planet1 and planet2.\n The function should return a tuple containing all planets whose orbits are\n located between the orbit of planet1 and the orbit of planet2, sorted by\n the proximity to the sun.\n The function should return an empty tuple if planet1 or planet2\n are not correct planet names.\n Examples\n bf(\"Jupiter\", \"Neptune\") ==> (\"Saturn\", \"Uranus\")\n bf(\"Earth\", \"Mercury\") ==> (\"Venus\")\n bf(\"Mercury\", \"Uranus\") ==> (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")\n */\nconst bf = (planet1, planet2) => {\n", "canonical_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n console.assert(\n JSON.stringify(bf('Neptune', 'Venus')) ===\n JSON.stringify(['Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus'])\n )\n console.assert(JSON.stringify(bf('Earth', 'Earth')) === JSON.stringify([]))\n console.assert(JSON.stringify(bf('Mars', 'Earth')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(bf('Jupiter', 'Makemake')) === JSON.stringify([])\n )\n}\n\ntestBf()\n", "declaration": "\nconst bf = (planet1, planet2) => {\n", "example_test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n}\ntestBf()\n", "buggy_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupyter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "bf"}
|
150 |
{"task_id": "JavaScript/149", "prompt": "/*Write a function that accepts a list of strings as a parameter,\n deletes the strings that have odd lengths from it,\n and returns the resulted list with a sorted order,\n The list is always a list of strings and never an array of numbers,\n and it may contain duplicates.\n The order of the list should be ascending by length of each word, and you\n should return the list sorted by that rule.\n If two words have the same length, sort the list alphabetically.\n The function should return a list of strings in sorted order.\n You may assume that all words will have the same length.\n For example:\n assert list_sort([\"aa\", \"a\", \"aaa\"]) => [\"aa\"]\n assert list_sort([\"ab\", \"a\", \"aaa\", \"cd\"]) => [\"ab\", \"cd\"]\n */\nconst sortedListSum = (lst) => {\n", "canonical_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['school', 'AI', 'asdf', 'b'])) ===\n JSON.stringify(['AI', 'asdf', 'school'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'b', 'c', 'a'])) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'dcba', 'abcd', 'a'])) ===\n JSON.stringify(['abcd', 'dcba'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['AI', 'ai', 'au'])) ===\n JSON.stringify(['AI', 'ai', 'au'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['a', 'b', 'b', 'c', 'c', 'a'])) ===\n JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['aaaa', 'bbbb', 'dd', 'cc'])) ===\n JSON.stringify(['cc', 'dd', 'aaaa', 'bbbb'])\n )\n}\n\ntestSortedListSum()\n", "declaration": "\nconst sortedListSum = (lst) => {\n", "example_test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['ab', 'a', 'aaa', 'cd'])) ===\n JSON.stringify(['ab', 'cd'])\n )\n}\ntestSortedListSum()\n", "buggy_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sortedListSum"}
|
|
|
64 |
{"task_id": "JavaScript/63", "prompt": "/*The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\n fibfib(0) == 0\n fibfib(1) == 0\n fibfib(2) == 1\n fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).\n Please write a function to efficiently compute the n-th element of the fibfib number sequence.\n >>> fibfib(1)\n 0\n >>> fibfib(5)\n 4\n >>> fibfib(8)\n 24\n */\nconst fibfib = (n) => {\n", "canonical_solution": " if (n == 0 || n == 1)\n return 0;\n if (n == 2)\n return 1;\n return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3);\n}\n\n", "test": "const testFibfib = () => {\n console.assert(fibfib(2) === 1)\n console.assert(fibfib(1) === 0)\n console.assert(fibfib(5) === 4)\n console.assert(fibfib(8) === 24)\n console.assert(fibfib(10) === 81)\n console.assert(fibfib(12) === 274)\n console.assert(fibfib(14) === 927)\n}\n\ntestFibfib()\n", "declaration": "\nconst fibfib = (n) => {\n", "example_test": "const testFibfib = () => {\n console.assert(fibfib(1) === 0)\n console.assert(fibfib(5) === 4)\n console.assert(fibfib(8) === 24)\n}\ntestFibfib()\n", "buggy_solution": " if (n == 0 || n == 1)\n return n;\n if (n == 2)\n return 2;\n return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fibfib"}
|
65 |
{"task_id": "JavaScript/64", "prompt": "/*Write a function vowelsCount which takes a string representing\n a word as input and returns the number of vowels in the string.\n Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a\n vowel, but only when it is at the end of the given word.\n\n Example:\n >>> vowelsCount(\"abcde\")\n 2\n >>> vowelsCount(\"ACEDY\")\n 3\n */\nconst vowelsCount = (s) => {\n", "canonical_solution": " var vowels = \"aeiouAEIOU\";\n var n_vowels = s.split('').reduce((prev, item) => {\n return prev + (vowels.includes(item));\n }, 0);\n if (s.at(-1) == 'y' || s.at(-1) == 'Y')\n n_vowels += 1;\n return n_vowels;\n}\n\n", "test": "const testVowelsCount = () => {\n console.assert(vowelsCount('abcde') === 2)\n console.assert(vowelsCount('Alone') === 3)\n console.assert(vowelsCount('key') === 2)\n console.assert(vowelsCount('bye') === 1)\n console.assert(vowelsCount('keY') === 2)\n console.assert(vowelsCount('bYe') === 1)\n console.assert(vowelsCount('ACEDY') === 3)\n}\n\ntestVowelsCount()\n", "declaration": "\nconst vowelsCount = (s) => {\n", "example_test": "const testVowelsCount = () => {\n console.assert(vowelsCount('abcde') === 2)\n console.assert(vowelsCount('ACEDY') === 3)\n}\ntestVowelsCount()\n", "buggy_solution": " var vowels = \"aeiouyAEIOUY\";\n var n_vowels = s.split('').reduce((prev, item) => {\n return prev + (vowels.includes(item));\n }, 0);\n return n_vowels;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "vowelsCount"}
|
66 |
{"task_id": "JavaScript/65", "prompt": "/*Circular shift the digits of the integer x, shift the digits right by shift\n and return the result as a string.\n If shift > number of digits, return digits reversed.\n >>> circularShift(12, 1)\n \"21\"\n >>> circularShift(12, 2)\n \"12\"\n */\nconst circularShift = (x, shift) => {\n", "canonical_solution": " s = x.toString();\n if (shift > s.length)\n return s.split('').reverse().join('');\n else\n return s.slice(-shift) + s.slice(0, -shift);\n}\n\n", "test": "const testCircularShift = () => {\n console.assert(circularShift(100, 2) === '001')\n console.assert(circularShift(12, 2) === '12')\n console.assert(circularShift(97, 8) === '79')\n console.assert(circularShift(12, 1) === '21')\n console.assert(circularShift(11, 101) === '11')\n}\n\ntestCircularShift()\n", "declaration": "\nconst circularShift = (x, shift) => {\n", "example_test": "const testCircularShift = () => {\n console.assert(circularShift(12, 2) === '12')\n console.assert(circularShift(12, 1) === '21')\n}\ntestCircularShift()\n", "buggy_solution": " s = x.toString();\n if (shift > s.length)\n return s.split('').reverse().join('');\n else\n return s.slice(0, -shift) + s.slice(-shift);\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "circularShift"}
|
67 |
+
{"task_id": "JavaScript/66", "prompt": "/*Task\n Write a function that takes a string as input and returns the sum of the upper characters only'\n ASCII codes.\n\n Examples:\n digitSum(\"\") => 0\n digitSum(\"abAB\") => 131\n digitSum(\"abcCd\") => 67\n digitSum(\"helloE\") => 69\n digitSum(\"woArBld\") => 131\n digitSum(\"aAaaaXa\") => 153\n */\nconst digitSum = (s) => {\n", "canonical_solution": " if (s == '') return 0;\n return s.split('').reduce((prev, char) => {\n let ord_char = char.charCodeAt(0)\n return prev + (ord_char > 64 && ord_char < 91 ? ord_char : 0);\n }, 0);\n}\n\n", "test": "const testDigitSum = () => {\n console.assert(digitSum('') === 0)\n console.assert(digitSum('abAB') === 131)\n console.assert(digitSum('abcCd') === 67)\n console.assert(digitSum('helloE') === 69)\n console.assert(digitSum('woArBld') === 131)\n console.assert(digitSum('aAaaaXa') === 153)\n console.assert(digitSum(' How are yOu?') === 151)\n console.assert(digitSum('You arE Very Smart') === 327)\n}\n\ntestDigitSum()\n", "declaration": "\nconst digitSum = (s) => {\n", "example_test": "const testDigitSum = () => {\n console.assert(digitSum('') === 0)\n console.assert(digitSum('abAB') === 131)\n console.assert(digitSum('abcCd') === 67)\n console.assert(digitSum('helloE') === 69)\n console.assert(digitSum('woArBld') === 131)\n console.assert(digitSum('aAaaaXa') === 153)\n}\ntestDigitSum()\n", "buggy_solution": " if (s == '') return 0;\n return s.split('').reduce((prev, char) => {\n let ord_char = char.charCodeAt(0)\n return prev + (ord_char > 64 && ord_char < 100 ? ord_char : 0);\n }, 0);\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "digitSum"}
|
68 |
{"task_id": "JavaScript/67", "prompt": "/*\n In this task, you will be given a string that represents a number of apples and oranges\n that are distributed in a basket of fruit this basket contains\n apples, oranges, and mango fruits. Given the string that represents the total number of\n the oranges and apples and an integer that represent the total number of the fruits\n in the basket return the number of the mango fruits in the basket.\n for examble:\n fruitDistribution(\"5 apples and 6 oranges\", 19) ->19 - 5 - 6 = 8\n fruitDistribution(\"0 apples and 1 oranges\",3) -> 3 - 0 - 1 = 2\n fruitDistribution(\"2 apples and 3 oranges\", 100) -> 100 - 2 - 3 = 95\n fruitDistribution(\"100 apples and 1 oranges\",120) -> 120 - 100 - 1 = 19\n */\nconst fruitDistribution = (s, n) => {\n", "canonical_solution": " var lis = [];\n for (const i of s.split(\" \"))\n if (!isNaN(i))\n lis.push(Number(i))\n return n - lis.reduce(((prev, item) => prev + item), 0);\n}\n\n", "test": "const testFruitDistribution = () => {\n console.assert(fruitDistribution('5 apples and 6 oranges', 19) === 8)\n console.assert(fruitDistribution('5 apples and 6 oranges', 21) === 10)\n console.assert(fruitDistribution('0 apples and 1 oranges', 3) === 2)\n console.assert(fruitDistribution('1 apples and 0 oranges', 3) === 2)\n console.assert(fruitDistribution('2 apples and 3 oranges', 100) === 95)\n console.assert(fruitDistribution('2 apples and 3 oranges', 5) === 0)\n console.assert(fruitDistribution('1 apples and 100 oranges', 120) === 19)\n}\n\ntestFruitDistribution()\n", "declaration": "\nconst fruitDistribution = (s, n) => {\n", "example_test": "const testFruitDistribution = () => {\n console.assert(fruitDistribution('5 apples and 6 oranges', 19) === 8)\n console.assert(fruitDistribution('0 apples and 1 oranges', 3) === 2)\n console.assert(fruitDistribution('2 apples and 3 oranges', 100) === 95)\n console.assert(fruitDistribution('1 apples and 100 oranges', 120) === 19)\n}\ntestFruitDistribution()\n", "buggy_solution": " var lis = [];\n for (const i of s.split(\" \"))\n if (!isNaN(i))\n lis.push(Number(i))\n return n - 1 - lis.reduce(((prev, item) => prev + item), 0);\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fruitDistribution"}
|
69 |
{"task_id": "JavaScript/68", "prompt": "/*\n \"Given an array representing a branch of a tree that has non-negative integer nodes\n your task is to pluck one of the nodes and return it.\n The plucked node should be the node with the smallest even value.\n If multiple nodes with the same smallest even value are found return the node that has smallest index.\n\n The plucked node should be returned in a list, [ smalest_value, its index ],\n If there are no even values or the given array is empty, return [].\n\n Example 1:\n Input: [4,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index.\n\n Example 2:\n Input: [1,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index.\n\n Example 3:\n Input: []\n Output: []\n\n Example 4:\n Input: [5, 0, 3, 0, 4, 2]\n Output: [0, 1]\n Explanation: 0 is the smallest value, but there are two zeros,\n so we will choose the first zero, which has the smallest index.\n\n Constraints:\n * 1 <= nodes.length <= 10000\n * 0 <= node.value\n */\nconst pluck = (arr) => {\n", "canonical_solution": " if (arr.length == 0) return [];\n var evens = arr.filter(x => x % 2 == 0);\n if (evens.length == 0) return [];\n return [Math.min(...evens), arr.indexOf(Math.min(...evens))];\n}\n\n", "test": "const testPluck = () => {\n console.assert(JSON.stringify(pluck([4, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([1, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(pluck([5, 0, 3, 0, 4, 2])) === JSON.stringify([0, 1])\n )\n console.assert(\n JSON.stringify(pluck([1, 2, 3, 0, 5, 3])) === JSON.stringify([0, 3])\n )\n console.assert(\n JSON.stringify(pluck([5, 4, 8, 4, 8])) === JSON.stringify([4, 1])\n )\n console.assert(JSON.stringify(pluck([7, 6, 7, 1])) === JSON.stringify([6, 1]))\n console.assert(JSON.stringify(pluck([7, 9, 7, 1])) === JSON.stringify([]))\n}\n\ntestPluck()\n", "declaration": "\nconst pluck = (arr) => {\n", "example_test": "const testPluck = () => {\n console.assert(JSON.stringify(pluck([4, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([1, 2, 3])) === JSON.stringify([2, 1]))\n console.assert(JSON.stringify(pluck([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(pluck([5, 0, 3, 0, 4, 2])) === JSON.stringify([0, 1])\n )\n}\ntestPluck()\n", "buggy_solution": " if (arr.length == 0) return [];\n var evens = arr.filter(x => x % 2 == 0);\n if (evens.length == 0) return [];\n return [arr.indexOf(Math.min(...evens)), Math.min(...evens)];\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "pluck"}
|
70 |
{"task_id": "JavaScript/69", "prompt": "/*\n You are given a non-empty list of positive integers. Return the greatest integer that is greater than\n zero, and has a frequency greater than or equal to the value of the integer itself.\n The frequency of an integer is the number of times it appears in the list.\n If no such a value exist, return -1.\n Examples:\n search([4, 1, 2, 2, 3, 1])) == 2\n search([1, 2, 2, 3, 3, 3, 4, 4, 4])) == 3\n search([5, 5, 4, 4, 4])) == -1\n */\nconst search = (lst) => {\n", "canonical_solution": " var frq = new Array(Math.max(...lst) + 1).fill(0);\n for (const i of lst)\n frq[i] += 1;\n var ans = -1;\n for (let i = 1; i < frq.length; i++)\n if (frq[i] >= i)\n ans = i;\n return ans;\n}\n\n", "test": "const testSearch = () => {\n console.assert(search([5, 5, 5, 5, 1]) === 1)\n console.assert(search([4, 1, 4, 1, 4, 4]) === 4)\n console.assert(search([3, 3]) === -1)\n console.assert(search([8, 8, 8, 8, 8, 8, 8, 8]) === 8)\n console.assert(search([2, 3, 3, 2, 2]) === 2)\n console.assert(\n search([\n 2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1,\n ]) === 1\n )\n console.assert(search([3, 2, 8, 2]) === 2)\n console.assert(search([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]) === 1)\n console.assert(search([8, 8, 3, 6, 5, 6, 4]) === -1)\n console.assert(\n search([\n 6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5,\n 7, 9,\n ]) === 1\n )\n console.assert(search([1, 9, 10, 1, 3]) === 1)\n console.assert(\n search([\n 6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3,\n 10,\n ]) === 5\n )\n console.assert(search([1]) === 1)\n console.assert(\n search([\n 8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5,\n ]) === 4\n )\n console.assert(\n search([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]) === 2\n )\n console.assert(search([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]) === 1)\n console.assert(\n search([\n 9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7,\n 10, 2, 8, 10, 9, 4,\n ]) === 4\n )\n console.assert(\n search([\n 2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7,\n ]) === 4\n )\n console.assert(\n search([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]) === 2\n )\n console.assert(\n search([\n 5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8,\n ]) === -1\n )\n console.assert(search([10]) === -1)\n console.assert(search([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]) === 2)\n console.assert(search([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]) === 1)\n console.assert(\n search([\n 7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6,\n ]) === 1\n )\n console.assert(search([3, 10, 10, 9, 2]) === -1)\n}\n\ntestSearch()\n", "declaration": "\nconst search = (lst) => {\n", "example_test": "const testSearch = () => {\n console.assert(search([4, 1, 2, 2, 3, 1]) === 2)\n console.assert(search([1, 2, 2, 3, 3, 3, 4, 4, 4]) === 3)\n console.assert(search([5, 5, 4, 4, 4]) === -1)\n}\ntestSearch()\n", "buggy_solution": " var frq = new Array(Math.max(...lst) + 1).fill(0);\n for (const i of lst)\n frq[i] += 1;\n var ans = 0;\n for (let i = 1; i < frq.length; i++)\n if (frq[i] >= i)\n ans = i;\n return ans;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "search"}
|
|
|
112 |
{"task_id": "JavaScript/111", "prompt": "/*Given a string representing a space separated lowercase letters, return a dictionary\n of the letter with the most repetition and containing the corresponding count.\n If several letters have the same occurrence, return all of them.\n \n Example:\n histogram('a b c') == {'a': 1, 'b': 1, 'c': 1}\n histogram('a b b a') == {'a': 2, 'b': 2}\n histogram('a b c a b') == {'a': 2, 'b': 2}\n histogram('b b b b a') == {'b': 4}\n histogram('') == {}\n\n */\nconst histogram = (test) => {\n", "canonical_solution": " let d = {}\n let t = test.split(/\\s/)\n if (test == '') { t = [] }\n for (m in t) {\n if (t[m] in d) {\n d[t[m]]++\n }\n else {\n d[t[m]] = 1\n }\n }\n s = Object.keys(d).sort(function (a, b) { return - d[a] + d[b]; });\n if (s.length == 0) { return {} }\n let g = d[s[0]]\n let l = {}\n for (let ss=0; ss<s.length; ss++) {\n if (d[s[ss]] == g) {\n l[s[ss]] = d[s[ss]]\n }\n }\n return l\n}\n\n", "test": "const testHistogram = () => {\n console.assert(\n JSON.stringify(histogram('a b b a')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c a b')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c d g')) ===\n JSON.stringify({ a: 1, b: 1, c: 1, d: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('r t g')) === JSON.stringify({ r: 1, t: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('b b b b a')) === JSON.stringify({ b: 4 })\n )\n console.assert(\n JSON.stringify(histogram('r t g')) === JSON.stringify({ r: 1, t: 1, g: 1 })\n )\n console.assert(JSON.stringify(histogram('')) === JSON.stringify({}))\n console.assert(JSON.stringify(histogram('a')) === JSON.stringify({ a: 1 }))\n}\n\ntestHistogram()\n", "declaration": "\nconst histogram = (test) => {\n", "example_test": "const testHistogram = () => {\n console.assert(\n JSON.stringify(histogram('a b b a')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c a b')) === JSON.stringify({ a: 2, b: 2 })\n )\n console.assert(\n JSON.stringify(histogram('a b c d g')) ===\n JSON.stringify({ a: 1, b: 1, c: 1, d: 1, g: 1 })\n )\n console.assert(\n JSON.stringify(histogram('a b c')) === JSON.stringify({ a: 1, b: 1, c: 1 })\n )\n console.assert(\n JSON.stringify(histogram('b b b b a')) === JSON.stringify({ b: 4 })\n )\n console.assert(JSON.stringify(histogram('')) === JSON.stringify({}))\n}\ntestHistogram()\n", "buggy_solution": " let d = {}\n let t = test.split(/\\s/)\n if (test == '') { t = [] }\n for (m in t) {\n if (t[m] in d) {\n d[t[m]]++\n }\n else {\n d[t[m]] = 1\n }\n }\n s = Object.keys(d).sort(function (a, b) { return - d[a] + d[b]; });\n if (s.length == 0) { return {} }\n let g = d[s[0]]\n let l = {}\n for (let ss=1; ss<s.length; ss++) {\n if (d[s[ss]] == g) {\n l[s[ss]] = d[s[ss]]\n }\n }\n return l\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "histogram"}
|
113 |
{"task_id": "JavaScript/112", "prompt": "/*Task\n We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\n then check if the result string is palindrome.\n A string is called palindrome if it reads the same backward as forward.\n You should return a tuple containing the result string and true/false for the check.\n Example\n For s = \"abcde\", c = \"ae\", the result should be ('bcd',false)\n For s = \"abcdef\", c = \"b\" the result should be ('acdef',false)\n For s = \"abcdedcba\", c = \"ab\", the result should be ('cdedc',true)\n */\nconst reverseDelete = (s, c) => {\n", "canonical_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let y = 1\n for (let j = 0; j < c.length; j++) {\n if (s[i] == c[j]) {\n y = 0\n }\n }\n if (y == 1) {\n t += s[i]\n }\n }\n let isPalindrome = true\n for (let i = 0; i < Math.floor(t.length / 2); i++) {\n if (t[i] != t[t.length - i - 1]) {\n isPalindrome = false\n break\n }\n }\n return [t, isPalindrome];\n}\n\n", "test": "const testReverseDelete = () => {\n console.assert(JSON.stringify(reverseDelete('abcde', 'ae')) ===\n JSON.stringify(['bcd', false]))\n console.assert(JSON.stringify(reverseDelete('abcdef', 'b')) ===\n JSON.stringify(['acdef', false]))\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'ab')) ===\n JSON.stringify(['cdedc', true]))\n console.assert(JSON.stringify(reverseDelete('dwik', 'w')) ===\n JSON.stringify(['dik', false]))\n console.assert(JSON.stringify(reverseDelete('a', 'a')) ===\n JSON.stringify(['', true]))\n console.assert(JSON.stringify(reverseDelete('abcdedcba', '')) ===\n JSON.stringify(['abcdedcba', true]))\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'v')) ===\n JSON.stringify(['abcdedcba', true]))\n console.assert(JSON.stringify(reverseDelete('vabba', 'v')) ===\n JSON.stringify(['abba', true]))\n console.assert(JSON.stringify(reverseDelete('mamma', 'mia')) ===\n JSON.stringify(['', true]))\n}\n\ntestReverseDelete()\n", "declaration": "\nconst reverseDelete = (s, c) => {\n", "example_test": "const testReverseDelete = () => {\n console.assert(JSON.stringify(reverseDelete('abcde', 'ae'))) ===\n JSON.stringify(['bcd', false])\n console.assert(JSON.stringify(reverseDelete('abcdef', 'b'))) ===\n JSON.stringify(['acdef', false])\n console.assert(JSON.stringify(reverseDelete('abcdedcba', 'ab'))) ===\n JSON.stringify(['cdedc', true])\n}\ntestReverseDelete()\n", "buggy_solution": " let t = ''\n for (let i = 0; i < s.length; i++) {\n let y = 1\n for (let j = 0; j < c.length; j++) {\n if (s[i] == c[j]) {\n y = 0\n }\n }\n if (y == 1) {\n t += s[i]\n }\n }\n let isPalindrome = false\n for (let i = 0; i < Math.floor(t.length / 2); i++) {\n if (t[i] != t[t.length - i - 1]) {\n isPalindrome = true\n break\n }\n }\n return [t, isPalindrome];\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "reverseDelete"}
|
114 |
{"task_id": "JavaScript/113", "prompt": "/*Given a list of strings, where each string consists of only digits, return a list.\n Each element i of the output should be \"the number of odd elements in the\n string i of the input.\" where all the i's should be replaced by the number\n of odd digits in the i'th string of the input.\n\n >>> oddCount(['1234567'])\n [\"the number of odd elements 4n the str4ng 4 of the 4nput.\"]\n >>> oddCount(['3',\"11111111\"])\n [\"the number of odd elements 1n the str1ng 1 of the 1nput.\",\n \"the number of odd elements 8n the str8ng 8 of the 8nput.\"]\n */\nconst oddCount = (lst) => {\n", "canonical_solution": " let d = []\n for (let i = 0; i < lst.length; i++) {\n let p = 0;\n let h = lst[i].length\n for (let j = 0; j < h; j++) {\n if (lst[i][j].charCodeAt() % 2 == 1) { p++ }\n }\n p = p.toString()\n d.push('the number of odd elements ' + p + 'n the str' + p + 'ng ' + p + ' of the ' + p + 'nput.')\n }\n return d\n}\n\n", "test": "const testOddCount = () => {\n console.assert(\n JSON.stringify(oddCount(['1234567'])) ===\n JSON.stringify([\n 'the number of odd elements 4n the str4ng 4 of the 4nput.',\n ])\n )\n console.assert(JSON.stringify(\n oddCount(['3', '11111111'])) ===\n JSON.stringify([\n 'the number of odd elements 1n the str1ng 1 of the 1nput.',\n 'the number of odd elements 8n the str8ng 8 of the 8nput.',\n ])\n )\n console.assert(\n JSON.stringify(oddCount(['271', '137', '314'])) ===\n JSON.stringify([\n 'the number of odd elements 2n the str2ng 2 of the 2nput.',\n 'the number of odd elements 3n the str3ng 3 of the 3nput.',\n 'the number of odd elements 2n the str2ng 2 of the 2nput.',\n ])\n )\n}\n\ntestOddCount()\n", "declaration": "\nconst oddCount = (lst) => {\n", "example_test": "const testOddCount = () => {\n console.assert(\n JSON.stringify(oddCount(['1234567'])) ===\n JSON.stringify([\n 'the number of odd elements 4n the str4ng 4 of the 4nput.',\n ])\n )\n console.assert(JSON.stringify(\n oddCount(['3', '11111111'])) ===\n JSON.stringify([\n 'the number of odd elements 1n the str1ng 1 of the 1nput.',\n 'the number of odd elements 8n the str8ng 8 of the 8nput.',\n ])\n )\n}\ntestOddCount()\n", "buggy_solution": " let d = []\n for (let i = 0; i < lst.length; i++) {\n let p = 0;\n let h = lst[i].length\n for (let j = 0; j < h; j++) {\n if (lst[i][j].charCodeAt() % 2 == 1) { p++ }\n }\n p = p.toString()\n d.push('the number of odd elements ' + p + 'n the str' + p + 'ng ' + p + ' of ' p + ' the ' + p + 'nput.')\n }\n return d\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "oddCount"}
|
115 |
+
{"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"}
|
116 |
{"task_id": "JavaScript/115", "prompt": "/*\n You are given a rectangular grid of wells. Each row represents a single well,\n and each 1 in a row represents a single unit of water.\n Each well has a corresponding bucket that can be used to extract water from it, \n and all buckets have the same capacity.\n Your task is to use the buckets to empty the wells.\n Output the number of times you need to lower the buckets.\n\n Example 1:\n Input: \n grid : [[0,0,1,0], [0,1,0,0], [1,1,1,1]]\n bucket_capacity : 1\n Output: 6\n\n Example 2:\n Input: \n grid : [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]]\n bucket_capacity : 2\n Output: 5\n \n Example 3:\n Input: \n grid : [[0,0,0], [0,0,0]]\n bucket_capacity : 5\n Output: 0\n\n Constraints:\n * all wells have the same length\n * 1 <= grid.length <= 10^2\n * 1 <= grid[:,1].length <= 10^2\n * grid[i][j] -> 0 | 1\n * 1 <= capacity <= 10\n */\nconst maxFill = (grid, capacity) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < grid.length; i++) {\n let m = 0\n for (let j = 0; j < grid[i].length; j++) {\n if (grid[i][j] == 1) { m++ }\n }\n while (m > 0) {\n m -= capacity;\n p++;\n }\n }\n return p\n}\n\n", "test": "const testMaxFill = () => {\n console.assert(\n maxFill(\n [\n [0, 0, 1, 0],\n [0, 1, 0, 0],\n [1, 1, 1, 1],\n ],\n 1\n ) === 6\n )\n console.assert(\n maxFill(\n [\n [0, 0, 1, 1],\n [0, 0, 0, 0],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n ],\n 2\n ) === 5\n )\n console.assert(\n maxFill(\n [\n [0, 0, 0],\n [0, 0, 0],\n ],\n 5\n ) === 0\n )\n console.assert(\n maxFill(\n [\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n ],\n 2\n ) === 4\n )\n console.assert(\n maxFill(\n [\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n ],\n 9\n ) === 2\n )\n}\n\ntestMaxFill()\n", "declaration": "\nconst maxFill = (grid, capacity) => {\n", "example_test": "const testMaxFill = () => {\n console.assert(\n maxFill(\n [\n [0, 0, 1, 0],\n [0, 1, 0, 0],\n [1, 1, 1, 1],\n ],\n 1\n ) === 6\n )\n console.assert(\n maxFill(\n [\n [0, 0, 1, 1],\n [0, 0, 0, 0],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n ],\n 2\n ) === 5\n )\n console.assert(\n maxFill(\n [\n [0, 0, 0],\n [0, 0, 0],\n ],\n 5\n ) === 0\n )\n}\ntestMaxFill()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < grid.length; i++) {\n let m = 0\n for (let j = 1; j < grid[i].length; j++) {\n if (grid[i][j] == 1) { m++ }\n }\n while (m > 0) {\n m -= capacity;\n p++;\n }\n }\n return p\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "maxFill"}
|
117 |
{"task_id": "JavaScript/116", "prompt": "/*\n In this Kata, you have to sort an array of non-negative integers according to\n number of ones in their binary representation in ascending order.\n For similar number of ones, sort based on decimal value.\n\n It must be implemented like this:\n >>> sortArray([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n >>> sortArray([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n >>> sortArray([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]\n */\nconst sortArray = (arr) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[k].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(sortArray([2, 5, 77, 4, 5, 3, 5, 7, 2, 3, 4])) ===\n JSON.stringify([2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77])\n )\n console.assert(\n JSON.stringify(sortArray([3, 6, 44, 12, 32, 5])) ===\n JSON.stringify([32, 3, 5, 6, 12, 44])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n}\n\ntestSortArray()\n", "declaration": "\nconst sortArray = (arr) => {\n", "example_test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n}\ntestSortArray()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[ind].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return arr\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "sortArray"}
|
118 |
{"task_id": "JavaScript/117", "prompt": "/*Given a string s and a natural number n, you have been tasked to implement \n a function that returns a list of all words from string s that contain exactly \n n consonants, in order these words appear in the string s.\n If the string s is empty then the function should return an empty list.\n Note: you may assume the input string contains only letters and spaces.\n Examples:\n selectWords(\"Mary had a little lamb\", 4) ==> [\"little\"]\n selectWords(\"Mary had a little lamb\", 3) ==> [\"Mary\")\n selectWords(\"simple white space\", 2) ==> []\n selectWords(\"Hello world\", 4) ==> [\"world\"]\n selectWords(\"Uncle sam\", 3) ==> [\"Uncle\"]\n */\nconst selectWords = (s, n) => {\n", "canonical_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' && t[i][j] != 'e' && t[i][j] != 'i' && t[i][j] != 'o' && t[i][j] != 'u' && t[i][j] != 'A' &&\n t[i][j] != 'U' && t[i][j] != 'O' && t[i][j] != 'I' && t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n\n console.assert(\n JSON.stringify(selectWords('a b c d e f', 1)) ===\n JSON.stringify(['b', 'c', 'd', 'f'])\n )\n\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n console.assert(JSON.stringify(selectWords('', 4)) === JSON.stringify([]))\n}\n\ntestSelectWords()\n", "declaration": "\nconst selectWords = (s, n) => {\n", "example_test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n}\ntestSelectWords()\n", "buggy_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' || t[i][j] != 'e' || t[i][j] != 'i' || t[i][j] != 'o' || t[i][j] != 'u' || t[i][j] != 'A' ||\n t[i][j] != 'U' || t[i][j] != 'O' || t[i][j] != 'I' || t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "selectWords"}
|
|
|
127 |
{"task_id": "JavaScript/126", "prompt": "/* Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return false. Assume no negative numbers and only integers.\n Examples\n isSorted([5]) \u279e true\n isSorted([1, 2, 3, 4, 5]) \u279e true\n isSorted([1, 3, 2, 4, 5]) \u279e false\n isSorted([1, 2, 3, 4, 5, 6]) \u279e true\n isSorted([1, 2, 3, 4, 5, 6, 7]) \u279e true\n isSorted([1, 3, 2, 4, 5, 6, 7]) \u279e false\n isSorted([1, 2, 2, 3, 3, 4]) \u279e true\n isSorted([1, 2, 2, 2, 3, 4]) \u279e false\n */\nconst isSorted = (lst) => {\n", "canonical_solution": " if (lst.length == 0) { return true }\n let dup = 1\n let pre = lst[0]\n for (let i = 1; i < lst.length; i++) {\n if (lst[i] < pre) { return false }\n if (lst[i] == pre) {\n dup += 1;\n if (dup == 3) { return false }\n } else {\n pre = lst[i]\n dup = 1\n }\n }\n return true\n}\n\n", "test": "const testIsSorted = () => {\n console.assert(isSorted([5]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5]) === false)\n console.assert(isSorted([1, 2, 3, 4, 5, 6]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5, 6, 7]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5, 6, 7]) === false)\n console.assert(isSorted([]) === true)\n console.assert(isSorted([1]) === true)\n console.assert(isSorted([3, 2, 1]) === false)\n console.assert(isSorted([1, 2, 2, 2, 3, 4]) === false)\n console.assert(isSorted([1, 2, 3, 3, 3, 4]) === false)\n console.assert(isSorted([1, 2, 2, 3, 3, 4]) === true)\n console.assert(isSorted([1, 2, 3, 4]) === true)\n}\n\ntestIsSorted()\n", "declaration": "\nconst isSorted = (lst) => {\n", "example_test": "const testIsSorted = () => {\n console.assert(isSorted([5]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5]) === false)\n console.assert(isSorted([1, 2, 3, 4, 5, 6]) === true)\n console.assert(isSorted([1, 2, 3, 4, 5, 6, 7]) === true)\n console.assert(isSorted([1, 3, 2, 4, 5, 6, 7]) === false)\n console.assert(isSorted([1, 2, 2, 2, 3, 4]) === false)\n console.assert(isSorted([1, 2, 2, 3, 3, 4]) === true)\n}\ntestIsSorted()\n", "buggy_solution": " if (lst.length == 0) { return true }\n let dup = 1\n let pre = lst[0]\n for (let i = 1; i < lst.length; i++) {\n if (lst[i] < pre) { return false }\n if (lst[i] == pre) {\n dup += 1;\n if (dup == 3) { return false }\n } else {\n pre = lst[i]\n }\n }\n return true\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "isSorted"}
|
128 |
{"task_id": "JavaScript/127", "prompt": "/*You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two \n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"\n */\nconst intersection = (interval1, interval2) => {\n", "canonical_solution": " let lo = interval1[0]\n if (interval2[0] > lo) { lo = interval2[0] }\n let hi = interval1[1]\n if (interval2[1] < hi) { hi = interval2[1] }\n let len = 0\n if (hi > lo) { len = hi - lo }\n if (len == 1 || len == 0) { return 'NO' }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return 'NO' }\n }\n return 'YES'\n}\n\n", "test": "const testIntersection = () => {\n console.assert(intersection([1, 2], [2, 3]) === 'NO')\n console.assert(intersection([-1, 1], [0, 4]) === 'NO')\n console.assert(intersection([-3, -1], [-5, 5]) === 'YES')\n console.assert(intersection([-2, 2], [-4, 0]) === 'YES')\n console.assert(intersection([-11, 2], [-1, -1]) === 'NO')\n console.assert(intersection([1, 2], [3, 5]) === 'NO')\n console.assert(intersection([1, 2], [1, 2]) === 'NO')\n console.assert(intersection([-2, -2], [-3, -2]) === 'NO')\n}\n\ntestIntersection()\n", "declaration": "\nconst intersection = (interval1, interval2) => {\n", "example_test": "const testIntersection = () => {\n console.assert(intersection([1, 2], [2, 3]) === 'NO')\n console.assert(intersection([-1, 1], [0, 4]) === 'NO')\n console.assert(intersection([-3, -1], [-5, 5]) === 'YES')\n}\ntestIntersection()\n", "buggy_solution": " let lo = interval1[0]\n if (interval2[0] > lo) { lo = interval2[0] }\n let hi = interval1[1]\n if (interval2[1] < hi) { hi = interval2[1] }\n let len = 0\n if (hi > lo) { len = hi }\n if (len == 1 || len == 0) { return 'NO' }\n return 'YES'\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "intersection"}
|
129 |
{"task_id": "JavaScript/128", "prompt": "/*\n You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return null for empty arr.\n\n Example:\n >>> prodSigns([1, 2, 2, -4]) == -9\n >>> prodSigns([0, 1]) == 0\n >>> prodSigns([]) == null\n */\nconst prodSigns = (arr) => {\n", "canonical_solution": " if (arr.length == 0) { return null }\n let n = 1\n let s = 0\n for (let i = 0; i < arr.length; i++) {\n s += arr[i]\n if (arr[i] == 0) { return 0 }\n if (arr[i] < 0) { n = -n; s -= 2 * arr[i] }\n }\n return s * n\n}\n\n", "test": "const testProdSigns = () => {\n console.assert(prodSigns([1, 2, 2, -4]) === -9)\n console.assert(prodSigns([0, 1]) === 0)\n console.assert(prodSigns([1, 1, 1, 2, 3, -1, 1]) === -10)\n console.assert(prodSigns([]) === null)\n console.assert(prodSigns([2, 4, 1, 2, -1, -1, 9]) === 20)\n console.assert(prodSigns([-1, 1, -1, 1]) === 4)\n console.assert(prodSigns([-1, 1, 1, 1]) === -4)\n console.assert(prodSigns([-1, 1, 1, 0]) === 0)\n}\n\ntestProdSigns()\n", "declaration": "\nconst prodSigns = (arr) => {\n", "example_test": "const testProdSigns = () => {\n console.assert(prodSigns([1, 2, 2, -4]) === -9)\n console.assert(prodSigns([0, 1]) === 0)\n console.assert(prodSigns([]) === null)\n}\ntestProdSigns()\n", "buggy_solution": " if (arr.length == 0) { return null }\n let n = 1\n let s = 0\n for (let i = 0; i < arr.length; i++) {\n s += arr[i]\n if (arr[i] == 0) { return 0 }\n if (arr[i] < 0) { n = -n; s -= 2 * arr[i] }\n }\n return s * n * 2\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "prodSigns"}
|
130 |
+
{"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"}
|
131 |
{"task_id": "JavaScript/130", "prompt": "/*Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in \n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8 \n You are given a non-negative integer number n, you have to a return a list of the \n first n + 1 numbers of the Tribonacci sequence.\n Examples:\n tri(3) = [1, 3, 2, 8]\n */\nconst tri = (n) => {\n", "canonical_solution": " if (n == 0) { return [1] }\n if (n == 1) { return [1, 3] }\n let p = [1, 3]\n for (let i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n p.push(1 + i / 2)\n }\n else {\n p.push(p[i - 2] + p[i - 1] + 1 + (i + 1) / 2)\n }\n }\n return p\n}\n\n", "test": "const testTri = () => {\n console.assert(JSON.stringify(tri(3)) === JSON.stringify([1, 3, 2.0, 8.0]))\n\n console.assert(\n JSON.stringify(tri(4)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0])\n )\n console.assert(\n JSON.stringify(tri(5)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0])\n )\n console.assert(\n JSON.stringify(tri(6)) === JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0])\n )\n console.assert(\n JSON.stringify(tri(7)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0])\n )\n console.assert(\n JSON.stringify(tri(8)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0])\n )\n console.assert(\n JSON.stringify(tri(9)) ===\n JSON.stringify([1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0])\n )\n console.assert(\n JSON.stringify(tri(20)) ===\n JSON.stringify([\n 1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0, 6.0, 48.0, 7.0, 63.0,\n 8.0, 80.0, 9.0, 99.0, 10.0, 120.0, 11.0,\n ])\n )\n console.assert(JSON.stringify(tri(0)) === JSON.stringify([1]))\n console.assert(JSON.stringify(tri(1)) === JSON.stringify([1, 3]))\n}\n\ntestTri()\n", "declaration": "\nconst tri = (n) => {\n", "example_test": "const testTri = () => {\n console.assert(JSON.stringify(tri(3)) === JSON.stringify([1, 3, 2.0, 8.0]))\n}\ntestTri()\n", "buggy_solution": " if (n == 0) { return [1] }\n if (n == 1) { return [1, 3] }\n let p = [1, 3]\n for (let i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n p.push(1 + i / 2)\n }\n else {\n p.push(p[i - 2] + p[i - 1] + 1 + i + (i + 1) / 2)\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "tri"}
|
132 |
{"task_id": "JavaScript/131", "prompt": "/*Given a positive integer n, return the product of the odd digits.\n Return 0 if all digits are even.\n For example:\n digits(1) == 1\n digits(4) == 0\n digits(235) == 15\n */\nconst digits = (n) => {\n", "canonical_solution": " let p = 1\n let k = 1\n while (n > 0) {\n let y = n % 10\n if (y % 2 == 1) {\n p *= y; k = 0;\n }\n n = (n - n % 10) / 10\n }\n if (k == 0) { return p }\n return 0\n}\n\n", "test": "const testDigits = () => {\n console.assert(digits(5) === 5)\n console.assert(digits(54) === 5)\n console.assert(digits(120) === 1)\n console.assert(digits(5014) === 5)\n console.assert(digits(98765) === 315)\n console.assert(digits(5576543) === 2625)\n console.assert(digits(2468) === 0)\n}\n\ntestDigits()\n", "declaration": "\nconst digits = (n) => {\n", "example_test": "const testDigits = () => {\n console.assert(digits(1) === 1)\n console.assert(digits(4) === 0)\n console.assert(digits(235) === 15)\n}\ntestDigits()\n", "buggy_solution": " let p = 1\n let k = 1\n while (n > 0) {\n let y = n % 10\n if (y % 2 == 1) {\n p *= p*y; k = 0;\n }\n n = (n - n % 10) / 10\n }\n if (k == 0) { return p }\n return 0\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "digits"}
|
133 |
{"task_id": "JavaScript/132", "prompt": "/*\n Create a function that takes a string as input which contains only square brackets.\n The function should return true if and only if there is a valid subsequence of brackets\n where at least one bracket in the subsequence is nested.\n isNested('[[]]') \u279e true\n isNested('[]]]]]]][[[[[]') \u279e false\n isNested('[][]') \u279e false\n isNested('[]') \u279e false\n isNested('[[][]]') \u279e true\n isNested('[[]][[') \u279e true\n */\nconst isNested = (string) => {\n", "canonical_solution": " let opening_bracket_index = []\n let closing_bracket_index1 = []\n for (let i = 0; i < string.length; i++) {\n if (string[i] == '[') {\n opening_bracket_index.push(i)\n }\n else {\n closing_bracket_index1.push(i)\n }\n }\n let closing_bracket_index = []\n for (let i = 0; i < closing_bracket_index1.length; i++) {\n closing_bracket_index.push(closing_bracket_index1[closing_bracket_index1.length - i - 1])\n }\n let cnt = 0\n let i = 0\n let l = closing_bracket_index.length\n for (let k = 0; k < opening_bracket_index.length; k++) {\n if (i < l && opening_bracket_index[k] < closing_bracket_index[i]) {\n cnt += 1;\n i += 1;\n }\n }\n return cnt >= 2\n}\n\n", "test": "const testIsNested = () => {\n console.assert(isNested('[[]]') === true)\n console.assert(isNested('[]]]]]]][[[[[]') === false)\n console.assert(isNested('[][]') === false)\n console.assert(isNested('[]') === false)\n console.assert(isNested('[[[[]]]]') === true)\n console.assert(isNested('[]]]]]]]]]]') === false)\n console.assert(isNested('[][][[]]') === true)\n console.assert(isNested('[[]') === false)\n console.assert(isNested('[]]') === false)\n console.assert(isNested('[[]][[') === true)\n console.assert(isNested('[[][]]') === true)\n console.assert(isNested('') === false)\n console.assert(isNested('[[[[[[[[') === false)\n console.assert(isNested(']]]]]]]]') === false)\n}\n\ntestIsNested()\n", "declaration": "\nconst isNested = (string) => {\n", "example_test": "const testIsNested = () => {\n console.assert(isNested('[[]]') === true)\n console.assert(isNested('[]]]]]]][[[[[]') === false)\n console.assert(isNested('[][]') === false)\n console.assert(isNested('[]') === false)\n console.assert(isNested('[[]][[') === true)\n console.assert(isNested('[[][]]') === true)\n}\ntestIsNested()\n", "buggy_solution": " let opening_bracket_index = []\n let closing_bracket_index1 = []\n for (let i = 0; i < string.length; i++) {\n if (string[i] == '(') {\n opening_bracket_index.push(i)\n }\n else {\n closing_bracket_index1.push(i)\n }\n }\n let closing_bracket_index = []\n for (let i = 0; i < closing_bracket_index1.length; i++) {\n closing_bracket_index.push(closing_bracket_index1[closing_bracket_index1.length - i - 1])\n }\n let cnt = 0\n let i = 0\n let l = closing_bracket_index.length\n for (let k = 0; k < opening_bracket_index.length; k++) {\n if (i < l && opening_bracket_index[k] < closing_bracket_index[i]) {\n cnt += 1;\n i += 1;\n }\n }\n return cnt >= 2\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "isNested"}
|
|
|
144 |
{"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"}
|
145 |
{"task_id": "JavaScript/144", "prompt": "/*Your task is to implement a function that will simplify the expression\n x * n. The function returns true if x * n evaluates to a whole number and false\n otherwise. Both x and n, are string representation of a fraction, and have the following format,\n <numerator>/<denominator> where both numerator and denominator are positive whole numbers.\n\n You can assume that x, and n are valid fractions, and do not have zero as denominator.\n\n simplify(\"1/5\", \"5/1\") = true\n simplify(\"1/6\", \"2/1\") = false\n simplify(\"7/10\", \"10/2\") = false\n */\nconst simplify = (x, n) => {\n", "canonical_solution": " let a = x.split(/\\//)\n let b = n.split(/\\//)\n let m = Number(a[0]) * Number(b[0])\n let r = Number(a[1]) * Number(b[1])\n return m % r == 0\n}\n\n", "test": "const testSimplify = () => {\n console.assert(simplify('1/5', '5/1') === true)\n console.assert(simplify('1/6', '2/1') === false)\n console.assert(simplify('5/1', '3/1') === true)\n console.assert(simplify('7/10', '10/2') === false)\n console.assert(simplify('2/10', '50/10') === true)\n console.assert(simplify('7/2', '4/2') === true)\n console.assert(simplify('11/6', '6/1') === true)\n console.assert(simplify('2/3', '5/2') === false)\n console.assert(simplify('5/2', '3/5') === false)\n console.assert(simplify('2/4', '8/4') === true)\n console.assert(simplify('2/4', '4/2') === true)\n console.assert(simplify('1/5', '5/1') === true)\n console.assert(simplify('1/5', '1/5') === false)\n}\n\ntestSimplify()\n", "declaration": "\nconst simplify = (x, n) => {\n", "example_test": "const testSimplify = () => {\n console.assert(simplify('1/5', '5/1') === true)\n console.assert(simplify('1/6', '2/1') === false)\n console.assert(simplify('7/10', '10/2') === false)\n}\ntestSimplify()\n", "buggy_solution": " let a = x.split(/\\//)\n let b = n.split(/\\//)\n let m = r * Number(a[0]) * Number(b[0])\n let r = m * Number(a[1]) * Number(b[1])\n let m = r * Number(a[1])\n let r = m * Number(b[1])\n return m % r == 0\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "simplify"}
|
146 |
{"task_id": "JavaScript/145", "prompt": "/*\n Write a function which sorts the given list of integers\n in ascending order according to the sum of their digits.\n Note: if there are several items with similar sum of their digits,\n order them based on their index in original list.\n\n For example:\n >>> orderByPoints([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]\n >>> orderByPoints([]) == []\n */\nconst orderByPoints = (nums) => {\n", "canonical_solution": " let p = nums\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let m = 0\n let n = 0\n let h = p[k]\n let d = p[k + 1]\n let y = 1\n let u = 1\n if (h < 0) { y = -1; h = -h; }\n if (d < 0) { u = -1; d = -d; }\n while (h >= 10) {\n m += h % 10;\n h = (h - h % 10) / 10;\n }\n m += y * h\n while (d >= 10) {\n n += d % 10;\n d = (d - d % 10) / 10;\n }\n n += u * d\n if (m > n) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "test": "const testOrderByPoints = () => {\n console.assert(\n JSON.stringify(orderByPoints([1, 11, -1, -11, -12])) ===\n JSON.stringify([-1, -11, 1, -12, 11])\n )\n console.assert(\n JSON.stringify(\n orderByPoints([\n 1234, 423, 463, 145, 2, 423, 423, 53, 6, 37, 3457, 3, 56, 0, 46,\n ])\n ) ===\n JSON.stringify([\n 0, 2, 3, 6, 53, 423, 423, 423, 1234, 145, 37, 46, 56, 463, 3457,\n ])\n )\n console.assert(JSON.stringify(orderByPoints([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(orderByPoints([1, -11, -32, 43, 54, -98, 2, -3])) ===\n JSON.stringify([-3, -32, -98, -11, 1, 2, 43, 54])\n )\n console.assert(\n JSON.stringify(orderByPoints([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])) ===\n JSON.stringify([1, 10, 2, 11, 3, 4, 5, 6, 7, 8, 9])\n )\n console.assert(\n JSON.stringify(orderByPoints([0, 6, 6, -76, -21, 23, 4])) ===\n JSON.stringify([-76, -21, 0, 4, 23, 6, 6])\n )\n}\n\ntestOrderByPoints()\n", "declaration": "\nconst orderByPoints = (nums) => {\n", "example_test": "const testOrderByPoints = () => {\n console.assert(\n JSON.stringify(orderByPoints([1, 11, -1, -11, -12])) ===\n JSON.stringify([-1, -11, 1, -12, 11])\n )\n console.assert(JSON.stringify(orderByPoints([])) === JSON.stringify([]))\n}\ntestOrderByPoints()\n", "buggy_solution": " let p = nums\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let m = 0\n let n = 0\n let h = p[k]\n let d = p[k + 1]\n let y = 1\n let u = 1\n if (h < 0) { y = -1; h = -h; }\n if (d < 0) { u = -1; d = -d; }\n while (h >= 10) {\n m += h % 10;\n h = (h - h % 10) / 10;\n }\n m += y * h + h\n while (d >= 10) {\n n += d % 10;\n d = (d - d % 10) / 10;\n }\n n += u * d\n if (m > n) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "orderByPoints"}
|
147 |
+
{"task_id": "JavaScript/146", "prompt": "/*Write a function that takes an array of numbers as input and returns \n the number of elements in the array that are greater than 10 and both \n first and last digits of a number are odd (1, 3, 5, 7, 9).\n For example:\n specialFilter([15, -73, 14, -15]) => 1 \n specialFilter([33, -2, -3, 45, 21, 109]) => 2\n */\nconst specialFilter = (nums) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < nums.length; i++) {\n if (nums[i] < 10) { continue }\n let y = nums[i].toString()\n if (Number(y[0]) % 2 == 1 && Number(y[y.length - 1]) % 2 == 1) {\n p++\n }\n }\n return p\n}\n\n", "test": "const testSpecialFilter = () => {\n console.assert(specialFilter([5, -2, 1, -5]) === 0)\n console.assert(specialFilter([15, -73, 14, -15]) === 1)\n console.assert(specialFilter([33, -2, -3, 45, 21, 109]) === 2)\n console.assert(specialFilter([43, -12, 93, 125, 121, 109]) === 4)\n console.assert(specialFilter([71, -2, -33, 75, 21, 19]) === 3)\n console.assert(specialFilter([1]) === 0)\n console.assert(specialFilter([]) === 0)\n}\n\ntestSpecialFilter()\n", "declaration": "\nconst specialFilter = (nums) => {\n", "example_test": "const testSpecialFilter = () => {\n console.assert(specialFilter([15, -73, 14, -15]) === 1)\n console.assert(specialFilter([33, -2, -3, 45, 21, 109]) === 2)\n}\ntestSpecialFilter()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < nums.length; i++) {\n if (nums[i] < 10) { continue }\n let y = nums[i].toString()\n if (Number(y[0]) % 2 == 1 && Number(y[y.length - 1]) % 2 == 1 && Number(y[y.length - 1]) % 2 == 0) {\n p++\n }\n }\n return p\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "specialFilter"}
|
148 |
{"task_id": "JavaScript/147", "prompt": "/*\n You are given a positive integer n. You have to create an integer array a of length n.\n For each i (1 \u2264 i \u2264 n), the value of a[i] = i * i - i + 1.\n Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, \n and a[i] + a[j] + a[k] is a multiple of 3.\n\n Example :\n Input: n = 5\n Output: 1\n Explanation: \n a = [1, 3, 7, 13, 21]\n The only valid triple is (1, 7, 13).\n */\nconst getMaxTriples = (n) => {\n", "canonical_solution": " let y = []\n for (let i = 1; i <= n; i++) {\n y.push(i * i - i + 1)\n }\n let u = 0\n for (let i = 0; i < n - 2; i++) {\n for (let j = i + 1; j < n - 1; j++) {\n for (let k = j + 1; k < n; k++) {\n if ((y[i] + y[j] + y[k]) % 3 == 0) { u++ }\n }\n }\n }\n return u\n}\n\n", "test": "const testGetMaxTriples = () => {\n console.assert(getMaxTriples(5) === 1)\n console.assert(getMaxTriples(6) === 4)\n console.assert(getMaxTriples(10) === 36)\n console.assert(getMaxTriples(100) === 53361)\n}\n\ntestGetMaxTriples()\n", "declaration": "\nconst getMaxTriples = (n) => {\n", "example_test": "const testGetMaxTriples = () => {\n console.assert(getMaxTriples(5) === 1)\n}\ntestGetMaxTriples()\n", "buggy_solution": " let y = []\n for (let i = 1; i <= n; i++) {\n y.push(i)\n }\n let u = 0\n for (let i = 0; i < n - 2; i++) {\n for (let j = i + 1; j < n - 1; j++) {\n for (let k = j + 1; k < n; k++) {\n if ((y[i] + y[j] + y[k]) % 3 == 0) { u++ }\n }\n }\n }\n return u\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "getMaxTriples"}
|
149 |
{"task_id": "JavaScript/148", "prompt": "/* There are eight planets in our solar system: the closerst to the Sun\n is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,\n Uranus, Neptune.\n Write a function that takes two planet names as strings planet1 and planet2.\n The function should return a tuple containing all planets whose orbits are\n located between the orbit of planet1 and the orbit of planet2, sorted by\n the proximity to the sun.\n The function should return an empty tuple if planet1 or planet2\n are not correct planet names.\n Examples\n bf(\"Jupiter\", \"Neptune\") ==> (\"Saturn\", \"Uranus\")\n bf(\"Earth\", \"Mercury\") ==> (\"Venus\")\n bf(\"Mercury\", \"Uranus\") ==> (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")\n */\nconst bf = (planet1, planet2) => {\n", "canonical_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n console.assert(\n JSON.stringify(bf('Neptune', 'Venus')) ===\n JSON.stringify(['Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus'])\n )\n console.assert(JSON.stringify(bf('Earth', 'Earth')) === JSON.stringify([]))\n console.assert(JSON.stringify(bf('Mars', 'Earth')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(bf('Jupiter', 'Makemake')) === JSON.stringify([])\n )\n}\n\ntestBf()\n", "declaration": "\nconst bf = (planet1, planet2) => {\n", "example_test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n}\ntestBf()\n", "buggy_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupyter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "bf"}
|
150 |
{"task_id": "JavaScript/149", "prompt": "/*Write a function that accepts a list of strings as a parameter,\n deletes the strings that have odd lengths from it,\n and returns the resulted list with a sorted order,\n The list is always a list of strings and never an array of numbers,\n and it may contain duplicates.\n The order of the list should be ascending by length of each word, and you\n should return the list sorted by that rule.\n If two words have the same length, sort the list alphabetically.\n The function should return a list of strings in sorted order.\n You may assume that all words will have the same length.\n For example:\n assert list_sort([\"aa\", \"a\", \"aaa\"]) => [\"aa\"]\n assert list_sort([\"ab\", \"a\", \"aaa\", \"cd\"]) => [\"ab\", \"cd\"]\n */\nconst sortedListSum = (lst) => {\n", "canonical_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['school', 'AI', 'asdf', 'b'])) ===\n JSON.stringify(['AI', 'asdf', 'school'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'b', 'c', 'a'])) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'dcba', 'abcd', 'a'])) ===\n JSON.stringify(['abcd', 'dcba'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['AI', 'ai', 'au'])) ===\n JSON.stringify(['AI', 'ai', 'au'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['a', 'b', 'b', 'c', 'c', 'a'])) ===\n JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['aaaa', 'bbbb', 'dd', 'cc'])) ===\n JSON.stringify(['cc', 'dd', 'aaaa', 'bbbb'])\n )\n}\n\ntestSortedListSum()\n", "declaration": "\nconst sortedListSum = (lst) => {\n", "example_test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['ab', 'a', 'aaa', 'cd'])) ===\n JSON.stringify(['ab', 'cd'])\n )\n}\ntestSortedListSum()\n", "buggy_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sortedListSum"}
|
data/rust/data/humanevalbugs.jsonl
CHANGED
The diff for this file is too large to render.
See raw diff
|
|