Muennighoff
commited on
Commit
•
c23113c
1
Parent(s):
c9a4e2f
Update
Browse files
README.md
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
WIP
|
data/cpp/data/humanevalbugs.jsonl
CHANGED
@@ -108,7 +108,7 @@
|
|
108 |
{"task_id": "CPP/107", "prompt": "/*\nGiven a positive integer n, return a vector that has the number of even and odd\ninteger palindromes that fall within the range(1, n), inclusive.\n\nExample 1:\n\n Input: 3\n Output: (1, 2)\n Explanation:\n Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.\n\nExample 2:\n\n Input: 12\n Output: (4, 6)\n Explanation:\n Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\n\nNote:\n 1. 1 <= n <= 10^3\n 2. returned vector has the number of even and odd integer palindromes respectively.\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nvector<int> even_odd_palindrome(int n){\n", "canonical_solution": " int num1=0,num2=0;\n for (int i=1;i<=n;i++)\n {\n string w=to_string(i);\n string p(w.rbegin(),w.rend());\n if (w==p and i%2==1) num1+=1;\n if (w==p and i%2==0) num2+=1;\n \n }\n return {num2,num1};\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(even_odd_palindrome(123) , {8, 13}));\n assert (issame(even_odd_palindrome(12) , {4, 6}));\n assert (issame(even_odd_palindrome(3) , {1, 2}));\n assert (issame(even_odd_palindrome(63) , {6, 8}));\n assert (issame(even_odd_palindrome(25) , {5, 6}));\n assert (issame(even_odd_palindrome(19) , {4, 6}));\n assert (issame(even_odd_palindrome(9) , {4, 5}));\n assert (issame(even_odd_palindrome(1) , {0, 1}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nvector<int> even_odd_palindrome(int n){\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(even_odd_palindrome(12) , {4, 6}));\n assert (issame(even_odd_palindrome(3) , {1, 2}));\n}\n", "buggy_solution": " int num1=0,num2=0;\n for (int i=1;i<=n;i++)\n {\n string w=to_string(i);\n string p(w.rbegin(),w.rend());\n if (w==p and i%2==1) num1+=1;\n if (w==p and i%2==0) num2+=2;\n \n }\n return {num2,num1};\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "even_odd_palindrome"}
|
109 |
{"task_id": "CPP/108", "prompt": "/*\nWrite a function count_nums which takes a vector of integers and returns\nthe number of elements which has a sum of digits > 0.\nIf a number is negative, then its first signed digit will be negative:\ne.g. -123 has signed digits -1, 2, and 3.\n>>> count_nums({}) == 0\n>>> count_nums({-1, 11, -11}) == 1\n>>> count_nums({1, 1, 2}) == 3\n*/\n#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\nint count_nums(vector<int> n){\n", "canonical_solution": " int num=0;\n for (int i=0;i<n.size();i++)\n if (n[i]>0) num+=1;\n else\n {\n int sum=0;\n int w;\n w=abs(n[i]);\n while (w>=10)\n {\n sum+=w%10;\n w=w/10;\n }\n sum-=w;\n if (sum>0) num+=1;\n }\n return num;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (count_nums({}) == 0);\n assert (count_nums({-1, -2, 0}) == 0);\n assert (count_nums({1, 1, 2, -2, 3, 4, 5}) == 6);\n assert (count_nums({1, 6, 9, -6, 0, 1, 5}) == 5);\n assert (count_nums({1, 100, 98, -7, 1, -1}) == 4);\n assert (count_nums({12, 23, 34, -45, -56, 0}) == 5);\n assert (count_nums({-0, 1}) == 1);\n assert (count_nums({1}) == 1);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nint count_nums(vector<int> n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (count_nums({}) == 0);\n assert (count_nums({-1, 11, -11}) == 1);\n assert (count_nums({1, 1, 2}) == 3);\n}\n", "buggy_solution": " int num=0;\n for (int i=0;i<n.size();i++)\n if (n[i]>0) num+=1;\n else\n {\n int sum=0;\n int w;\n w=abs(n[i]);\n while (w>=10)\n {\n sum+=w%10;\n w=w/10;\n }\n sum-=w*-1;\n if (sum>0) num+=1;\n }\n return num;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "count_nums"}
|
110 |
{"task_id": "CPP/109", "prompt": "/*\nWe have a vector \"arr\" of N integers arr[1], arr[2], ..., arr[N].The\nnumbers in the vector will be randomly ordered. Your task is to determine if\nit is possible to get a vector sorted in non-decreasing order by performing \nthe following operation on the given vector:\n You are allowed to perform right shift operation any number of times.\n\nOne right shift operation means shifting all elements of the vector by one\nposition in the right direction. The last element of the vector will be moved to\nthe starting position in the vector i.e. 0th index. \n\nIf it is possible to obtain the sorted vector by performing the above operation\nthen return true else return false.\nIf the given vector is empty then return true.\n\nNote: The given vector is guaranteed to have unique elements.\n\nFor Example:\n\nmove_one_ball({3, 4, 5, 1, 2})==>true\nExplanation: By performing 2 right shift operations, non-decreasing order can\n be achieved for the given vector.\nmove_one_ball({3, 5, 4, 1, 2})==>false\nExplanation:It is not possible to get non-decreasing order for the given\n vector by performing any number of right shift operations.\n \n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nbool move_one_ball(vector<int> arr){\n", "canonical_solution": " int num=0;\n if (arr.size()==0) return true;\n for (int i=1;i<arr.size();i++)\n if (arr[i]<arr[i-1]) num+=1;\n if (arr[arr.size()-1]>arr[0]) num+=1;\n if (num<2) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (move_one_ball({3, 4, 5, 1, 2})==true);\n assert (move_one_ball({3, 5, 10, 1, 2})==true);\n assert (move_one_ball({4, 3, 1, 2})==false);\n assert (move_one_ball({3, 5, 4, 1, 2})==false);\n assert (move_one_ball({})==true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool move_one_ball(vector<int> arr){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (move_one_ball({3, 4, 5, 1, 2})==true);\n assert (move_one_ball({3, 5, 4, 1, 2})==false);\n}\n", "buggy_solution": " int num=0;\n if (arr.size()==0) return true;\n for (int i=1;i<arr.size();i++)\n if (arr[i]<arr[arr.size()-1]) num+=1;\n if (arr[arr.size()-1]>arr[0]) num+=1;\n if (num<2) return true;\n return false;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "move_one_ball"}
|
111 |
-
{"task_id": "CPP/110", "prompt": "/*\nIn this problem, you will implement a function that takes two vectors of numbers,\nand determines whether it is possible to perform an exchange of elements\nbetween them to make lst1 a vector of only even numbers.\nThere is no limit on the number of exchanged elements between lst1 and lst2.\nIf it is possible to exchange elements between the lst1 and lst2 to make\nall the elements of lst1 to be even, return \"YES\".\nOtherwise, return \"NO\".\nFor example:\nexchange({1, 2, 3, 4}, {1, 2, 3, 4}) => \"YES\"\nexchange({1, 2, 3, 4}, {1, 5, 3, 4}) => \"NO\"\nIt is assumed that the input vectors will be non-empty.\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nstring exchange(vector<int> lst1,vector<int> lst2){\n", "canonical_solution": " int num=0;\n for (int i=0;i<lst1.size();i++)\n if (lst1[i]%2==0) num+=1;\n for (int i=0;i<lst2.size();i++)\n if (lst2[i]%2==0) num+=1;\n if (num>=lst1.size()) return \"YES\";\n return \"NO\";\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (exchange({1, 2, 3, 4}, {1, 2, 3, 4}) == \"YES\");\n assert (exchange({1, 2, 3, 4}, {1, 5, 3, 4}) == \"NO\");\n assert (exchange({1, 2, 3, 4}, {2, 1, 4, 3}) == \"YES\" );\n assert (exchange({5, 7, 3}, {2, 6, 4}) == \"YES\");\n assert (exchange({5, 7, 3}, {2, 6, 3}) == \"NO\" );\n assert (exchange({3, 2, 6, 1, 8, 9}, {3, 5, 5, 1, 1, 1}) == \"NO\");\n assert (exchange({100, 200}, {200, 200}) == \"YES\");\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nstring exchange(vector<int> lst1,vector<int> lst2){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (exchange({1, 2, 3, 4}, {1, 2, 3, 4}) == \"YES\");\n assert (exchange({1, 2, 3, 4}, {1, 5, 3, 4}) == \"NO\");\n}\n", "buggy_solution": " int num=0;\n for (int i=0;i<lst1.size();i++)\n if (lst1[i]%2==0) num+=1;\n for (int i=0;i<lst2.size();i++)\n if (lst2[i]%2==0) num+=1;\n if (num
|
112 |
{"task_id": "CPP/111", "prompt": "/*\nGiven a string representing a space separated lowercase letters, return a map\nof the letter with the most repetition and containing the corresponding count.\nIf several letters have the same occurrence, return all of them.\n\nExample:\nhistogram(\"a b c\") == {{\"a\", 1}, {\"b\", 1}, {\"c\", 1}}\nhistogram(\"a b b a\") == {{\"a\", 2}, {\"b\", 2}}\nhistogram(\"a b c a b\") == {{\"a\", 2}, {\"b\", 2}}\nhistogram(\"b b b b a\") == {{\"b\", 4}}\nhistogram(\"\") == {}\n\n*/\n#include<stdio.h>\n#include<string>\n#include<map>\nusing namespace std;\nmap<char,int> histogram(string test){\n", "canonical_solution": " map<char,int> count={},out={};\n map <char,int>::iterator it;\n int max=0;\n for (int i=0;i<test.length();i++)\n if (test[i]!=' ')\n {\n count[test[i]]+=1;\n if (count[test[i]]>max) max=count[test[i]];\n }\n for (it=count.begin();it!=count.end();it++)\n {\n char w1=it->first;\n int w2=it->second;\n if (w2==max) out[w1]=w2;\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(map<char,int> a,map<char,int> b){\n if (a.size()!=b.size()) return false;\n map <char,int>::iterator it;\n for (it=a.begin();it!=a.end();it++)\n {\n char w1=it->first;\n int w2=it->second;\n if (b.find(w1)==b.end()) return false;\n if (b[w1]!=w2) return false;\n }\n\n return true;\n}\nint main(){\n assert (issame(histogram(\"a b b a\") , {{'a',2},{'b', 2}}));\n assert (issame(histogram(\"a b c a b\") , {{'a', 2},{'b', 2}}));\n assert (issame(histogram(\"a b c d g\") , {{'a', 1}, {'b', 1}, {'c', 1}, {'d', 1}, {'g', 1}}));\n assert (issame(histogram(\"r t g\") , {{'r', 1},{'t', 1},{'g', 1}}));\n assert (issame(histogram(\"b b b b a\") , {{'b', 4}}));\n assert (issame(histogram(\"r t g\") , {{'r', 1},{'t', 1},{'g', 1}}));\n assert (issame(histogram(\"\") , {}));\n assert (issame(histogram(\"a\") , {{'a', 1}}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<map>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nmap<char,int> histogram(string test){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(map<char,int> a,map<char,int> b){\n if (a.size()!=b.size()) return false;\n map <char,int>::iterator it;\n for (it=a.begin();it!=a.end();it++)\n {\n char w1=it->first;\n int w2=it->second;\n if (b.find(w1)==b.end()) return false;\n if (b[w1]!=w2) return false;\n }\n return true;\n}\nint main(){\n assert (issame(histogram(\"a b b a\") , {{'a',2},{'b', 2}}));\n assert (issame(histogram(\"a b c a b\") , {{'a', 2},{'b', 2}}));\n assert (issame(histogram(\"a b c\") , {{'a', 1},{'b', 1},{'c', 1}}));\n assert (issame(histogram(\"b b b b a\") , {{'b', 4}}));\n assert (issame(histogram(\"\") , {}));\n}\n", "buggy_solution": " map<char,int> count={},out={};\n map <char,int>::iterator it;\n int max=0;\n for (int i=1;i<test.length();i++)\n if (test[i]!=' ')\n {\n count[test[i]]+=1;\n if (count[test[i]]>max) max=count[test[i]];\n }\n for (it=count.begin();it!=count.end();it++)\n {\n char w1=it->first;\n int w2=it->second;\n if (w2==max) out[w1]=w2;\n }\n return out;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "histogram"}
|
113 |
{"task_id": "CPP/112", "prompt": "/*\nTask\nWe are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\nthen check if the result string is palindrome.\nA string is called palindrome if it reads the same backward as forward.\nYou should return a vector containing the result string and \"True\"/\"False\" for the check.\nExample\nFor s = \"abcde\", c = \"ae\", the result should be (\"bcd\",\"False\")\nFor s = \"abcdef\", c = \"b\" the result should be (\"acdef\",\"False\")\nFor s = \"abcdedcba\", c = \"ab\", the result should be (\"cdedc\",\"True\")\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\nvector<string> reverse_delete(string s,string c){\n", "canonical_solution": " string n=\"\";\n for (int i=0;i<s.length();i++)\n if (find(c.begin(),c.end(),s[i])==c.end())\n n=n+s[i]; \n if (n.length()==0) return {n,\"True\"};\n string w(n.rbegin(),n.rend());\n if (w==n) return {n,\"True\"};\n return {n,\"False\"};\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(reverse_delete(\"abcde\",\"ae\") , {\"bcd\",\"False\"}));\n assert (issame(reverse_delete(\"abcdef\", \"b\") , {\"acdef\",\"False\"}));\n assert (issame(reverse_delete(\"abcdedcba\",\"ab\") , {\"cdedc\",\"True\"}));\n assert (issame(reverse_delete(\"dwik\",\"w\") , {\"dik\",\"False\"}));\n assert (issame(reverse_delete(\"a\",\"a\") , {\"\",\"True\"}));\n assert (issame(reverse_delete(\"abcdedcba\",\"\") , {\"abcdedcba\",\"True\"}));\n assert (issame(reverse_delete(\"abcdedcba\",\"v\") , {\"abcdedcba\",\"True\"}));\n assert (issame(reverse_delete(\"vabba\",\"v\") , {\"abba\",\"True\"}));\n assert (issame(reverse_delete(\"mamma\", \"mia\") , {\"\", \"True\"}));\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> reverse_delete(string s,string c){\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(reverse_delete(\"abcde\",\"ae\") , {\"bcd\",\"False\"}));\n assert (issame(reverse_delete(\"abcdef\", \"b\") , {\"acdef\",\"False\"}));\n assert (issame(reverse_delete(\"abcdedcba\",\"ab\") , {\"cdedc\",\"True\"}));\n}\n", "buggy_solution": " string n=\"\";\n for (int i=0;i<s.length();i++)\n if (find(c.begin(),c.end(),s[i])==c.end())\n n=n+s[i]; \n if (n.length()==0) return {n,\"True\"};\n string w(n.rbegin(),n.rend());\n if (w==n) return {n,\"False\"};\n return {n,\"True\"};\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "reverse_delete"}
|
114 |
{"task_id": "CPP/113", "prompt": "/*\nGiven a vector of strings, where each string consists of only digits, return a vector.\nEach element i of the output should be 'the number of odd elements in the\nstring i of the input.\" where all the i's should be replaced by the number\nof odd digits in the i'th string of the input.\n\n>>> odd_count({\"1234567\"})\n{'the number of odd elements 4n the str4ng 4 of the 4nput.\"}\n>>> odd_count({\"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*/\n#include<stdio.h>\n#include<vector>\n#include<string>\n#include<map>\nusing namespace std;\nvector<string> odd_count(vector<string> lst){\n", "canonical_solution": " vector<string> out={};\n for (int i=0;i<lst.size();i++)\n {\n int sum=0;\n for (int j=0;j<lst[i].length();j++)\n if (lst[i][j]>=48 and lst[i][j]<=57 and lst[i][j]%2==1)\n sum+=1;\n string s=\"the number of odd elements in the string i of the input.\";\n string s2=\"\";\n for (int j=0;j<s.length();j++)\n if (s[j]=='i') s2=s2+to_string(sum);\n else s2=s2+s[j];\n out.push_back(s2);\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(odd_count({\"1234567\"}) , {\"the number of odd elements 4n the str4ng 4 of the 4nput.\"}));\n assert (issame(odd_count({\"3\",\"11111111\"}) , {\"the number of odd elements 1n the str1ng 1 of the 1nput.\", \"the number of odd elements 8n the str8ng 8 of the 8nput.\"}));\n assert (issame(odd_count({\"271\", \"137\", \"314\"}) , {\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", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\n#include<map>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nvector<string> odd_count(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(odd_count({\"1234567\"}) , {\"the number of odd elements 4n the str4ng 4 of the 4nput.\"}));\n assert (issame(odd_count({\"3\",\"11111111\"}) , {\"the number of odd elements 1n the str1ng 1 of the 1nput.\", \"the number of odd elements 8n the str8ng 8 of the 8nput.\"}));\n}\n", "buggy_solution": " vector<string> out={};\n for (int i=0;i<lst.size();i++)\n {\n int sum=0;\n for (int j=0;j<lst[i].length();j++)\n if (lst[i][j]>=48 and lst[i][j]<=57 and lst[i][j]%2==1)\n sum+=1;\n string s=\"the number of odd elements in the string i of i the input.\";\n string s2=\"\";\n for (int j=0;j<s.length();j++)\n if (s[j]=='i') s2=s2+to_string(sum);\n else s2=s2+s[j];\n out.push_back(s2);\n }\n return out;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "odd_count"}
|
@@ -125,11 +125,11 @@
|
|
125 |
{"task_id": "CPP/124", "prompt": "/*\nYou have to write a function which validates a given date string and\nreturns true if the date is valid otherwise false.\nThe date is valid if all of the following rules are satisfied:\n1. The date string is not empty.\n2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n3. The months should not be less than 1 or higher than 12.\n4. The date should be in the format: mm-dd-yyyy\n\nfor example: \nvalid_date(\"03-11-2000\") => true\n\nvalid_date(\"15-01-2012\") => false\n\nvalid_date(\"04-0-2040\") => false\n\nvalid_date(\"06-04-2020\") => true\n\nvalid_date(\"06/04/2020\") => false\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool valid_date(string date){\n", "canonical_solution": " int mm,dd,yy,i;\n if (date.length()!=10) return false;\n for (int i=0;i<10;i++)\n if (i==2 or i==5)\n {\n if (date[i]!='-') return false;\n }\n else\n if (date[i]<48 or date[i]>57) return false;\n\n mm=atoi(date.substr(0,2).c_str());\n dd=atoi(date.substr(3,2).c_str());\n yy=atoi(date.substr(6,4).c_str());\n if (mm<1 or mm>12) return false;\n if (dd<1 or dd>31) return false;\n if (dd==31 and (mm==4 or mm==6 or mm==9 or mm==11 or mm==2)) return false;\n if (dd==30 and mm==2) return false;\n return true;\n\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (valid_date(\"03-11-2000\") == true);\n assert (valid_date(\"15-01-2012\") == false);\n assert (valid_date(\"04-0-2040\") == false);\n assert (valid_date(\"06-04-2020\") == true);\n assert (valid_date(\"01-01-2007\") == true);\n assert (valid_date(\"03-32-2011\") == false);\n assert (valid_date(\"\") == false);\n assert (valid_date(\"04-31-3000\") == false);\n assert (valid_date(\"06-06-2005\") == true);\n assert (valid_date(\"21-31-2000\") == false);\n assert (valid_date(\"04-12-2003\") == true);\n assert (valid_date(\"04122003\") == false);\n assert (valid_date(\"20030412\") == false);\n assert (valid_date(\"2003-04\") == false);\n assert (valid_date(\"2003-04-12\") == false);\n assert (valid_date(\"04-2003\") == false);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool valid_date(string date){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (valid_date(\"03-11-2000\") == true);\n assert (valid_date(\"15-01-2012\") == false);\n assert (valid_date(\"04-0-2040\") == false);\n assert (valid_date(\"06-04-2020\") == true);\n assert (valid_date(\"06/04/2020\") == false);\n}\n", "buggy_solution": " int dd,mm,yy,i;\n if (date.length()!=10) return false;\n for (int i=0;i<10;i++)\n if (i==2 or i==5)\n {\n if (date[i]!='-') return false;\n }\n else\n if (date[i]<48 or date[i]>57) return false;\n\n dd=atoi(date.substr(0,2).c_str());\n mm=atoi(date.substr(3,2).c_str());\n yy=atoi(date.substr(6,4).c_str());\n if (mm<1 or mm>12) return false;\n if (dd<1 or dd>31) return false;\n if (dd==31 and (mm==4 or mm==6 or mm==9 or mm==11 or mm==2)) return false;\n if (dd==30 and mm==2) return false;\n return true;\n\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "valid_date"}
|
126 |
{"task_id": "CPP/125", "prompt": "/*\nGiven a string of words, return a vector of words split on whitespace, if no whitespaces exists in the text you\nshould split on commas ',' if no commas exists you should return a vector with one element, the number of lower-case letters with odd order in the\nalphabet, ord(\"a\") = 0, ord(\"b\") = 1, ... ord(\"z\") = 25\nExamples\nsplit_words(\"Hello world!\") \u279e {\"Hello\", \"world!\"}\nsplit_words(\"Hello,world!\") \u279e {\"Hello\", \"world!\"}\nsplit_words(\"abcdef\") == {\"3\"} \n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\nvector<string> split_words(string txt){\n", "canonical_solution": " int i;\n string current=\"\";\n vector<string> out={};\n if (find(txt.begin(),txt.end(),' ')!=txt.end())\n {\n txt=txt+' ';\n for (i=0;i<txt.length();i++)\n if (txt[i]==' ') \n {\n if (current.length()>0)out.push_back(current); \n current=\"\";\n }\n else current=current+txt[i];\n return out;\n }\n if (find(txt.begin(),txt.end(),',')!=txt.end())\n {\n txt=txt+',';\n for (i=0;i<txt.length();i++)\n if (txt[i]==',') \n {\n if (current.length()>0)out.push_back(current); \n current=\"\";\n }\n else current=current+txt[i];\n return out;\n }\n int num=0;\n for (i=0;i<txt.length();i++)\n if (txt[i]>=97 and txt[i]<=122 and txt[i]%2==0)\n num+=1;\n return {to_string(num)};\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(split_words(\"Hello world!\") , {\"Hello\",\"world!\"}));\n assert (issame(split_words(\"Hello,world!\") , {\"Hello\",\"world!\"}));\n assert (issame(split_words(\"Hello world,!\") , {\"Hello\",\"world,!\"}));\n assert (issame(split_words(\"Hello,Hello,world !\") , {\"Hello,Hello,world\",\"!\"}));\n assert (issame(split_words(\"abcdef\") , {\"3\"}));\n assert (issame(split_words(\"aaabb\") , {\"2\"}));\n assert (issame(split_words(\"aaaBb\") , {\"1\"}));\n assert (issame(split_words(\"\") ,{\"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>\nvector<string> split_words(string txt){\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(split_words(\"Hello world!\") , {\"Hello\",\"world!\"}));\n assert (issame(split_words(\"Hello,world!\") , {\"Hello\",\"world!\"}));\n assert (issame(split_words(\"abcdef\") , {\"3\"}));\n}\n", "buggy_solution": " int i;\n string current=\"\";\n vector<string> out={};\n if (find(txt.begin(),txt.end(),' ')!=txt.end())\n {\n txt=txt+',';\n for (i=0;i<txt.length();i++)\n if (txt[i]==' ') \n {\n if (current.length()>0)out.push_back(current); \n current=\"\";\n }\n else current=current+txt[i];\n return out;\n }\n if (find(txt.begin(),txt.end(),',')!=txt.end())\n {\n txt=txt+',';\n for (i=0;i<txt.length();i++)\n if (txt[i]==',') \n {\n if (current.length()>0)out.push_back(current); \n current=\"\";\n }\n else current=current+txt[i];\n return out;\n }\n int num=0;\n for (i=0;i<txt.length();i++)\n if (txt[i]>=97 and txt[i]<=122 and txt[i]%2==0)\n num+=1;\n return {to_string(num)};\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "split_words"}
|
127 |
{"task_id": "CPP/126", "prompt": "/*\nGiven a vector of numbers, return whether or not they are sorted\nin ascending order. If vector has more than 1 duplicate of the same\nnumber, return false. Assume no negative numbers and only integers.\n\nExamples\nis_sorted({5}) \u279e true\nis_sorted({1, 2, 3, 4, 5}) \u279e true\nis_sorted({1, 3, 2, 4, 5}) \u279e false\nis_sorted({1, 2, 3, 4, 5, 6}) \u279e true\nis_sorted({1, 2, 3, 4, 5, 6, 7}) \u279e true\nis_sorted({1, 3, 2, 4, 5, 6, 7}) \u279e false\nis_sorted({1, 2, 2, 3, 3, 4}) \u279e true\nis_sorted({1, 2, 2, 2, 3, 4}) \u279e false\n*/\n#include<stdio.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\nbool is_sorted(vector<int> lst){\n", "canonical_solution": " for (int i=1;i<lst.size();i++)\n {\n if (lst[i]<lst[i-1]) return false;\n if (i>=2 and lst[i]==lst[i-1] and lst[i]==lst[i-2]) return false;\n }\n return true;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_sorted({5}) == true);\n assert (is_sorted({1, 2, 3, 4, 5}) == true);\n assert (is_sorted({1, 3, 2, 4, 5}) == false);\n assert (is_sorted({1, 2, 3, 4, 5, 6}) == true);\n assert (is_sorted({1, 2, 3, 4, 5, 6, 7}) == true);\n assert (is_sorted({1, 3, 2, 4, 5, 6, 7}) == false);\n assert (is_sorted({}) == true);\n assert (is_sorted({1}) == true);\n assert (is_sorted({3, 2, 1}) == false);\n assert (is_sorted({1, 2, 2, 2, 3, 4}) == false);\n assert (is_sorted({1, 2, 3, 3, 3, 4}) == false);\n assert (is_sorted({1, 2, 2, 3, 3, 4}) == true);\n assert (is_sorted({1, 2, 3, 4}) == true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool is_sorted(vector<int> lst){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_sorted({5}) == true);\n assert (is_sorted({1, 2, 3, 4, 5}) == true);\n assert (is_sorted({1, 3, 2, 4, 5}) == false);\n assert (is_sorted({1, 2, 3, 4, 5, 6}) == true);\n assert (is_sorted({1, 2, 3, 4, 5, 6, 7}) == true);\n assert (is_sorted({1, 3, 2, 4, 5, 6, 7}) == false);\n assert (is_sorted({1, 2, 2, 2, 3, 4}) == false);\n assert (is_sorted({1, 2, 2, 3, 3, 4}) == true);\n}\n", "buggy_solution": " for (int i=1;i<lst.size();i++)\n {\n if (lst[i]<lst[i-1]) return false;\n if (i>=2 and lst[i]==lst[i-1]) return false;\n }\n return true;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "is_sorted"}
|
128 |
-
{"task_id": "CPP/127", "prompt": "/*\nYou are given two intervals,\nwhere each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\nThe given intervals are closed which means that the interval (start, end)\nincludes both start and end.\nFor each given interval, it is assumed that its start is less or equal its end.\nYour task is to determine whether the length of intersection of these two \nintervals is a prime number.\nExample, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\nwhich its length is 1, which not a prime number.\nIf the length of the intersection is a prime number, return \"YES\",\notherwise, return \"NO\".\nIf the two intervals don't intersect, return \"NO\".\n\n\n{input/output} samples:\nintersection({1, 2}, {2, 3}) ==> \"NO\"\nintersection({-1, 1}, {0, 4}) ==> \"NO\"\nintersection({-3, -1}, {-5, 5}) ==> \"YES\"\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nstring intersection( vector<int> interval1,vector<int> interval2){\n", "canonical_solution": " int inter1,inter2,l,i;\n inter1=max(interval1[0],interval2[0]);\n inter2=min(interval1[1],interval2[1]);\n l=inter2-inter1;\n if (l<2) return \"NO\";\n for (i=2;i*i<=l;i++)\n if (l%i==0) return \"NO\";\n return \"YES\";\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (intersection({1, 2}, {2, 3}) == \"NO\");\n assert (intersection({-1, 1}, {0, 4}) == \"NO\");\n assert (intersection({-3, -1}, {-5, 5}) == \"YES\");\n assert (intersection({-2, 2}, {-4, 0}) == \"YES\");\n assert (intersection({-11, 2}, {-1, -1}) == \"NO\");\n assert (intersection({1, 2}, {3, 5}) == \"NO\");\n assert (intersection({1, 2}, {1, 2}) == \"NO\");\n assert (intersection({-2, -2}, {-3, -2}) == \"NO\");\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>\nstring intersection( vector<int> interval1,vector<int> interval2){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (intersection({1, 2}, {2, 3}) == \"NO\");\n assert (intersection({-1, 1}, {0, 4}) == \"NO\");\n assert (intersection({-3, -1}, {-5, 5}) == \"YES\");\n}\n", "buggy_solution": " int inter1,inter2,l,i;\n inter1=max(interval1[0],interval2[0]);\n inter2=min(interval1[1],interval2[1]);\n l=inter2
|
129 |
{"task_id": "CPP/128", "prompt": "/*\nYou are given a vector arr of integers and you need to return\nsum of magnitudes of integers multiplied by product of all signs\nof each number in the vector, represented by 1, -1 or 0.\nNote: return -32768 for empty arr.\n\nExample:\n>>> prod_signs({1, 2, 2, -4}) == -9\n>>> prod_signs({0, 1}) == 0\n>>> prod_signs({}) == -32768\n*/\n#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\nint prod_signs(vector<int> arr){\n", "canonical_solution": " if (arr.size()==0) return -32768;\n int i,sum=0,prods=1;\n for (i=0;i<arr.size();i++)\n {\n sum+=abs(arr[i]);\n if (arr[i]==0) prods=0;\n if (arr[i]<0) prods=-prods;\n }\n return sum*prods;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (prod_signs({1, 2, 2, -4}) == -9);\n assert (prod_signs({0, 1}) == 0);\n assert (prod_signs({1, 1, 1, 2, 3, -1, 1}) == -10);\n assert (prod_signs({}) == -32768);\n assert (prod_signs({2, 4,1, 2, -1, -1, 9}) == 20);\n assert (prod_signs({-1, 1, -1, 1}) == 4);\n assert (prod_signs({-1, 1, 1, 1}) == -4);\n assert (prod_signs({-1, 1, 1, 0}) == 0);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint prod_signs(vector<int> arr){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (prod_signs({1, 2, 2, -4}) == -9);\n assert (prod_signs({0, 1}) == 0);\n assert (prod_signs({}) == -32768);\n}\n", "buggy_solution": " if (arr.size()==0) return -32768;\n int i,sum=0,prods=1;\n for (i=0;i<arr.size();i++)\n {\n sum+=abs(arr[i])*2;\n if (arr[i]==0) prods=0;\n if (arr[i]<0) prods=-prods;\n }\n return sum*prods;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "prod_signs"}
|
130 |
{"task_id": "CPP/129", "prompt": "/*\nGiven a grid with N rows and N columns (N >= 2) and a positive integer k, \neach cell of the grid contains a value. Every integer in the range {1, N * N}\ninclusive appears exactly once on the cells of the grid.\n\nYou have to find the minimum path of length k in the grid. You can start\nfrom any cell, and in each step you can move to any of the neighbor cells,\nin other words, you can go to cells which share an edge with you current\ncell.\nPlease note that a path of length k means visiting exactly k cells (not\nnecessarily distinct).\nYou CANNOT go off the grid.\nA path A (of length k) is considered less than a path B (of length k) if\nafter making the ordered vectors of the values on the cells that A and B go\nthrough (let's call them lst_A and lst_B), lst_A is lexicographically less\nthan lst_B, in other words, there exist an integer index i (1 <= i <= k)\nsuch that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\nlst_A[j] = lst_B[j].\nIt is guaranteed that the answer is unique.\nReturn an ordered vector of the values on the cells that the minimum path go through.\n\nExamples:\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*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nvector<int> minPath(vector<vector<int>> grid, int k){\n", "canonical_solution": " int i,j,x,y,min;\n for (i=0;i<grid.size();i++)\n for (j=0;j<grid[i].size();j++)\n if (grid[i][j]==1) {\n x=i;y=j;\n }\n min=grid.size()*grid.size();\n if (x>0 and grid[x-1][y]<min) min=grid[x-1][y];\n if (x<grid.size()-1 and grid[x+1][y]<min) min=grid[x+1][y];\n if (y>0 and grid[x][y-1]<min) min=grid[x][y-1];\n if (y<grid.size()-1 and grid[x][y+1]<min) min=grid[x][y+1];\n vector<int> out={};\n for (i=0;i<k;i++)\n if (i%2==0) out.push_back(1);\n else out.push_back(min);\n return out;\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(minPath({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, 3) , {1, 2, 1}));\n assert (issame(minPath({{5, 9, 3}, {4, 1, 6}, {7, 8, 2}}, 1) , {1}));\n assert (issame(minPath({{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}, 4) , {1, 2, 1, 2}));\n assert (issame(minPath({{6, 4, 13, 10}, {5, 7, 12, 1}, {3, 16, 11, 15}, {8, 14, 9, 2}}, 7) , {1, 10, 1, 10, 1, 10, 1}));\n assert (issame(minPath({{8, 14, 9, 2}, {6, 4, 13, 15}, {5, 7, 1, 12}, {3, 10, 11, 16}}, 5) , {1, 7, 1, 7, 1}));\n assert (issame(minPath({{11, 8, 7, 2}, {5, 16, 14, 4}, {9, 3, 15, 6}, {12, 13, 10, 1}}, 9) , {1, 6, 1, 6, 1, 6, 1, 6, 1}));\n assert (issame(minPath({{12, 13, 10, 1}, {9, 3, 15, 6}, {5, 16, 14, 4}, {11, 8, 7, 2}}, 12) , {1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6}));\n assert (issame(minPath({{2, 7, 4}, {3, 1, 5}, {6, 8, 9}}, 8) , {1, 3, 1, 3, 1, 3, 1, 3}));\n assert (issame(minPath({{6, 1, 5}, {3, 8, 9}, {2, 7, 4}}, 8) , {1, 5, 1, 5, 1, 5, 1, 5}));\n assert (issame(minPath({{1, 2}, {3, 4}}, 10) , {1, 2, 1, 2, 1, 2, 1, 2, 1, 2}));\n assert (issame(minPath({{1, 3}, {3, 2}}, 10) , {1, 3, 1, 3, 1, 3, 1, 3, 1, 3}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nvector<int> minPath(vector<vector<int>> grid, int k){\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(minPath({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, 3) , {1, 2, 1}));\n assert (issame(minPath({{5, 9, 3}, {4, 1, 6}, {7, 8, 2}}, 1) , {1}));\n}\n", "buggy_solution": " int i,j,x,y,min;\n for (i=0;i<grid.size();i++)\n for (j=0;j<grid[i].size();j++)\n if (grid[i][j]==1) {\n x=i;y=j;\n }\n min=grid.size()*grid.size();\n if (x>0 and grid[x-1][y]<min) min=grid[x-1][y];\n if (x<grid.size()-1 and grid[x+1][y]<min) min=grid[x][y];\n if (y>0 and grid[x][y-1]<min) min=grid[x][y];\n if (y<grid.size()-1 and grid[x][y+1]<min) min=grid[x][y];\n vector<int> out={};\n for (i=0;i<k;i++)\n if (i%2==0) out.push_back(1);\n else out.push_back(min);\n return out;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "minPath"}
|
131 |
{"task_id": "CPP/130", "prompt": "/*\nEveryone knows Fibonacci sequence, it was studied deeply by mathematicians in \nthe last couple centuries. However, what people don't know is Tribonacci sequence.\nTribonacci sequence is defined by the recurrence:\ntri(1) = 3\ntri(n) = 1 + n / 2, if n is even.\ntri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\nFor example:\ntri(2) = 1 + (2 / 2) = 2\ntri(4) = 3\ntri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8 \nYou are given a non-negative integer number n, you have to a return a vector of the \nfirst n + 1 numbers of the Tribonacci sequence.\nExamples:\ntri(3) = {1, 3, 2, 8}\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nvector<int> tri(int n){\n", "canonical_solution": " vector<int> out={1,3};\n if (n==0) return {1};\n for (int i=2;i<=n;i++)\n {\n if (i%2==0) out.push_back(1+i/2);\n else out.push_back(out[i-1]+out[i-2]+1+(i+1)/2);\n }\n return out;\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(tri(3) , {1, 3, 2, 8}));\n assert (issame(tri(4) , {1, 3, 2, 8, 3}));\n assert (issame(tri(5) , {1, 3, 2, 8, 3, 15}));\n assert (issame(tri(6) , {1, 3, 2, 8, 3, 15, 4}));\n assert (issame(tri(7) , {1, 3, 2, 8, 3, 15, 4, 24}));\n assert (issame(tri(8) , {1, 3, 2, 8, 3, 15, 4, 24, 5}));\n assert (issame(tri(9) , {1, 3, 2, 8, 3, 15, 4, 24, 5, 35}));\n assert (issame(tri(20) , {1, 3, 2, 8, 3, 15, 4, 24, 5, 35, 6, 48, 7, 63, 8, 80, 9, 99, 10, 120, 11}));\n assert (issame(tri(0) , {1}));\n assert (issame(tri(1) , {1, 3}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nvector<int> tri(int n){\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(tri(3) , {1, 3, 2, 8}));\n}\n", "buggy_solution": " vector<int> out={1,3};\n if (n==0) return {1};\n for (int i=2;i<=n;i++)\n {\n if (i%2==0) out.push_back(1+i/2);\n else out.push_back(out[i-1]+out[i-2]+1+i+(i+1)/2);\n }\n return out;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "tri"}
|
132 |
-
{"task_id": "CPP/131", "prompt": "/*\nGiven a positive integer n, return the product of the odd digits.\nReturn 0 if all digits are even.\nFor example:\ndigits(1) == 1\ndigits(4) == 0\ndigits(235) == 15\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nint digits(int n){\n", "canonical_solution": " int prod=1,has=0;\n string s=to_string(n);\n for (int i=0;i<s.length();i++)\n if (s[i]%2==1) \n {\n has=1;\n prod=prod*(s[i]-48);\n }\n if (has==0) return 0;\n return prod;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (digits(5) == 5);\n assert (digits(54) == 5);\n assert (digits(120) ==1);\n assert (digits(5014) == 5);\n assert (digits(98765) == 315);\n assert (digits(5576543) == 2625);\n assert (digits(2468) == 0);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint digits(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (digits(1) == 1);\n assert (digits(4) == 0);\n assert (digits(235) ==15);\n}\n", "buggy_solution": " int prod=1,has=0;\n string s=to_string(n);\n for (int i=0;i<s.length();i++)\n if (s[i]%2==1) \n {\n has=1;\n prod=
|
133 |
{"task_id": "CPP/132", "prompt": "/*\nCreate a function that takes a string as input which contains only square brackets.\nThe function should return true if and only if there is a valid subsequence of brackets\nwhere at least one bracket in the subsequence is nested.\n\nis_nested(\"[[]]\") \u279e true\nis_nested(\"[]]]]]]][[[[[]\") \u279e false\nis_nested(\"[][]\") \u279e false\nis_nested(\"[]\") \u279e false\nis_nested(\"[[][]]\") \u279e true\nis_nested(\"[[]][[\") \u279e true\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool is_nested(string str){\n", "canonical_solution": " int count=0,maxcount=0;\n for (int i=0;i<str.length();i++)\n {\n if (str[i]=='[') count+=1;\n if (str[i]==']') count-=1;\n if (count<0) count=0;\n if (count>maxcount) maxcount=count;\n if (count<=maxcount-2) return true;\n }\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_nested(\"[[]]\") == true);\n assert (is_nested(\"[]]]]]]][[[[[]\") == false);\n assert (is_nested(\"[][]\") == false);\n assert (is_nested((\"[]\")) == false);\n assert (is_nested(\"[[[[]]]]\") == true);\n assert (is_nested(\"[]]]]]]]]]]\") == false);\n assert (is_nested(\"[][][[]]\") == true);\n assert (is_nested(\"[[]\") == false);\n assert (is_nested(\"[]]\") == false);\n assert (is_nested(\"[[]][[\") == true);\n assert (is_nested(\"[[][]]\") == true);\n assert (is_nested(\"\") == false);\n assert (is_nested(\"[[[[[[[[\") == false);\n assert (is_nested(\"]]]]]]]]\") == false);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool is_nested(string str){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_nested(\"[[]]\") == true);\n assert (is_nested(\"[]]]]]]][[[[[]\") == false);\n assert (is_nested(\"[][]\") == false);\n assert (is_nested(\"[]\") == false);\n assert (is_nested(\"[[]][[\") == true);\n assert (is_nested(\"[[][]]\") == true);\n}\n", "buggy_solution": " int count=0,maxcount=0;\n for (int i=0;i<str.length();i++)\n {\n if (str[i]=='(') count+=1;\n if (str[i]==')') count-=1;\n if (count<0) count=0;\n if (count>maxcount) maxcount=count;\n if (count<=maxcount-2) return true;\n }\n return false;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "is_nested"}
|
134 |
{"task_id": "CPP/133", "prompt": "/*\nYou are given a vector of numbers.\nYou need to return the sum of squared numbers in the given vector,\nround each element in the vector to the upper int(Ceiling) first.\nExamples:\nFor lst = {1,2,3} the output should be 14\nFor lst = {1,4,9} the output should be 98\nFor lst = {1,3,5,7} the output should be 84\nFor lst = {1.4,4.2,0} the output should be 29\nFor lst = {-2.4,1,1} the output should be 6\n\n\n*/\n#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\nint sum_squares(vector<float> lst){\n", "canonical_solution": " int sum=0;\n for (int i=0;i<lst.size();i++)\n sum+=ceil(lst[i])*ceil(lst[i]);\n return sum;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (sum_squares({1,2,3})==14);\n assert (sum_squares({1.0,2,3})==14);\n assert (sum_squares({1,3,5,7})==84);\n assert (sum_squares({1.4,4.2,0})==29);\n assert (sum_squares({-2.4,1,1})==6);\n assert (sum_squares({100,1,15,2})==10230);\n assert (sum_squares({10000,10000})==200000000);\n assert (sum_squares({-1.4,4.6,6.3})==75);\n assert (sum_squares({-1.4,17.9,18.9,19.9})==1086);\n assert (sum_squares({0})==0);\n assert (sum_squares({-1})==1);\n assert (sum_squares({-1,1,0})==2);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint sum_squares(vector<float> lst){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (sum_squares({1,2,3})==14);\n assert (sum_squares({1,4,9})==98);\n assert (sum_squares({1,3,5,7})==84);\n assert (sum_squares({1.4,4.2,0})==29);\n assert (sum_squares({-2.4,1,1})==6);\n}\n", "buggy_solution": " int sum=0;\n for (int i=0;i<lst.size();i++)\n sum+=ceil(lst[i])*2;\n return sum;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "sum_squares"}
|
135 |
{"task_id": "CPP/134", "prompt": "/*\nCreate a function that returns true if the last character\nof a given string is an alphabetical character and is not\na part of a word, and false otherwise.\nNote: \"word\" is a group of characters separated by space.\n\nExamples:\ncheck_if_last_char_is_a_letter(\"apple pie\") \u279e false\ncheck_if_last_char_is_a_letter(\"apple pi e\") \u279e true\ncheck_if_last_char_is_a_letter(\"apple pi e \") \u279e false\ncheck_if_last_char_is_a_letter(\"\") \u279e false \n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool check_if_last_char_is_a_letter(string txt){\n", "canonical_solution": " if (txt.length()==0) return false;\n char chr=txt[txt.length()-1];\n if (chr<65 or (chr>90 and chr<97) or chr>122) return false;\n if (txt.length()==1) return true;\n chr=txt[txt.length()-2];\n if ((chr>=65 and chr<=90) or (chr>=97 and chr<=122)) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (check_if_last_char_is_a_letter(\"apple\") == false);\n assert (check_if_last_char_is_a_letter(\"apple pi e\") == true);\n assert (check_if_last_char_is_a_letter(\"eeeee\") == false);\n assert (check_if_last_char_is_a_letter(\"A\") == true);\n assert (check_if_last_char_is_a_letter(\"Pumpkin pie \") == false);\n assert (check_if_last_char_is_a_letter(\"Pumpkin pie 1\") == false);\n assert (check_if_last_char_is_a_letter(\"\") == false);\n assert (check_if_last_char_is_a_letter(\"eeeee e \") == false);\n assert (check_if_last_char_is_a_letter(\"apple pie\") == false);\n assert (check_if_last_char_is_a_letter(\"apple pi e \") == false);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool check_if_last_char_is_a_letter(string txt){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (check_if_last_char_is_a_letter(\"apple pi e\") == true);\n assert (check_if_last_char_is_a_letter(\"\") == false);\n assert (check_if_last_char_is_a_letter(\"apple pie\") == false);\n assert (check_if_last_char_is_a_letter(\"apple pi e \") == false);\n}\n", "buggy_solution": " if (txt.length()==0) return false;\n char chr=txt[txt.length()-1];\n if (chr<10 or (chr>50 and chr<57) or chr>200) return false;\n if (txt.length()==1) return true;\n chr=txt[txt.length()-2];\n if ((chr>=30 and chr<=37) or (chr>=21 and chr<=42)) return false;\n return true;\n}\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "check_if_last_char_is_a_letter"}
|
@@ -138,7 +138,7 @@
|
|
138 |
{"task_id": "CPP/137", "prompt": "/*\nCreate a function that takes integers, floats, or strings representing\nreal numbers, and returns the larger variable in its given variable type.\nReturn \"None\" if the values are equal.\nNote: If a real number is represented as a string, the floating point might be . or ,\n\ncompare_one(1, 2.5) \u279e 2.5\ncompare_one(1, \"2,3\") \u279e \"2,3\"\ncompare_one(\"5,1\", \"6\") \u279e \"6\"\ncompare_one(\"1\", 1) \u279e \"None\"\n*/\n#include<stdio.h>\n#include<string>\n#include<algorithm>\n#include<boost/any.hpp>\nusing namespace std;\nboost::any compare_one(boost::any a,boost::any b){\n", "canonical_solution": " double numa,numb;\n boost::any out;\n \n if (a.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(a);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1);\n numa=atof(s.c_str());\n \n }\n else \n {\n if (a.type()==typeid(int)) numa=boost::any_cast<int>(a);\n if (a.type()==typeid(double)) numa=boost::any_cast<double>(a);\n }\n if (b.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(b);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1);\n numb=atof(s.c_str());\n }\n else \n {\n if (b.type()==typeid(int)) numb=boost::any_cast<int>(b);\n if (b.type()==typeid(double)) numb=boost::any_cast<double>(b);\n }\n\n if (numa==numb) return string(\"None\");\n if (numa<numb) return b;\n if (numa>numb) return a;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (boost::any_cast<int>(compare_one(1, 2)) == 2);\n assert (boost::any_cast<double>(compare_one(1, 2.5))== 2.5);\n assert (boost::any_cast<int>(compare_one(2, 3)) == 3);\n assert (boost::any_cast<int>(compare_one(5, 6)) == 6);\n assert (boost::any_cast<string>(compare_one(1, string(\"2,3\")))== \"2,3\");\n assert (boost::any_cast<string>(compare_one(string(\"5,1\"), string(\"6\"))) == \"6\");\n assert (boost::any_cast<string>(compare_one(string(\"1\"), string(\"2\"))) == \"2\");\n assert (boost::any_cast<string>(compare_one(string(\"1\"), 1)) == \"None\");\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\n#include<boost/any.hpp>\nusing namespace std;\n#include<stdlib.h>\nboost::any compare_one(boost::any a,boost::any b){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (boost::any_cast<double>(compare_one(1, 2.5))== 2.5);\n assert (boost::any_cast<string>(compare_one(1, string(\"2,3\")))== \"2,3\");\n assert (boost::any_cast<string>(compare_one(string(\"5,1\"), string(\"6\"))) == \"6\");\n assert (boost::any_cast<string>(compare_one(string(\"1\"), 1)) == \"None\");\n}\n", "buggy_solution": " double numa,numb;\n boost::any out;\n \n if (a.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(a);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1);\n numa=atof(s.c_str());\n \n }\n else \n {\n if (a.type()==typeid(int)) numa=boost::any_cast<int>(a);\n if (a.type()==typeid(double)) numa=boost::any_cast<double>(a);\n }\n if (b.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(b);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1)+',';\n numb=atof(s.c_str());\n }\n else \n {\n if (b.type()==typeid(int)) numb=boost::any_cast<int>(b);\n if (b.type()==typeid(double)) numb=boost::any_cast<double>(b);\n }\n\n if (numa==numb) return string(\"None\");\n if (numa<numb) return b;\n if (numa>numb) return a;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "compare_one"}
|
139 |
{"task_id": "CPP/138", "prompt": "/*\nEvaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\nExample\nis_equal_to_sum_even(4) == false\nis_equal_to_sum_even(6) == false\nis_equal_to_sum_even(8) == true\n*/\n#include<stdio.h>\nusing namespace std;\nbool is_equal_to_sum_even(int n){\n", "canonical_solution": " if (n%2==0 and n>=8) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_equal_to_sum_even(4) == false);\n assert (is_equal_to_sum_even(6) == false);\n assert (is_equal_to_sum_even(8) == true);\n assert (is_equal_to_sum_even(10) == true);\n assert (is_equal_to_sum_even(11) == false);\n assert (is_equal_to_sum_even(12) == true);\n assert (is_equal_to_sum_even(13) == false);\n assert (is_equal_to_sum_even(16) == true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool is_equal_to_sum_even(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_equal_to_sum_even(4) == false);\n assert (is_equal_to_sum_even(6) == false);\n assert (is_equal_to_sum_even(8) == true);\n}\n", "buggy_solution": " if (n%2==0 and n>=8 and n <=8) return true;\n return false;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "is_equal_to_sum_even"}
|
140 |
{"task_id": "CPP/139", "prompt": "/*\nThe Brazilian factorial is defined as:\nbrazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\nwhere n > 0\n\nFor example:\n>>> special_factorial(4)\n288\n\nThe function will receive an integer as input and should return the special\nfactorial of this integer.\n*/\n#include<stdio.h>\nusing namespace std;\nlong long special_factorial(int n){\n", "canonical_solution": " long long fact=1,bfact=1;\n for (int i=1;i<=n;i++)\n {\n fact=fact*i;\n bfact=bfact*fact;\n }\n return bfact;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (special_factorial(4) == 288);\n assert (special_factorial(5) == 34560);\n assert (special_factorial(7) == 125411328000);\n assert (special_factorial(1) == 1);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nlong long special_factorial(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (special_factorial(4) == 288);\n}\n", "buggy_solution": " long long fact=1,bfact=1;\n for (int i=1;i<=n;i++)\n {\n i=i*n;\n fact=fact*i;\n bfact=bfact*fact;\n }\n return bfact;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "special_factorial"}
|
141 |
-
{"task_id": "CPP/140", "prompt": "/*\nGiven a string text, replace all spaces in it with underscores, \nand if a string has more than 2 consecutive spaces, \nthen replace all consecutive spaces with - \n\nfix_spaces(\"Example\") == \"Example\"\nfix_spaces(\"Example 1\") == \"Example_1\"\nfix_spaces(\" Example 2\") == \"_Example_2\"\nfix_spaces(\" Example 3\") == \"_Example-3\"\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring fix_spaces(string text){\n", "canonical_solution": " string out=\"\";\n int spacelen=0;\n for (int i=0;i<text.length();i++)\n if (text[i]==' ') spacelen+=1;\n else\n {\n if (spacelen==1) out=out+'_';\n if (spacelen==2) out=out+\"__\";\n if (spacelen>2) out=out+'-';\n spacelen=0;\n out=out+text[i];\n }\n if (spacelen==1) out=out+'_';\n if (spacelen==2) out=out+\"__\";\n if (spacelen>2) out=out+'-';\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (fix_spaces(\"Example\") == \"Example\");\n assert (fix_spaces(\"Mudasir Hanif \") == \"Mudasir_Hanif_\");\n assert (fix_spaces(\"Yellow Yellow Dirty Fellow\") == \"Yellow_Yellow__Dirty__Fellow\");\n assert (fix_spaces(\"Exa mple\") == \"Exa-mple\");\n assert (fix_spaces(\" Exa 1 2 2 mple\") == \"-Exa_1_2_2_mple\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring fix_spaces(string text){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (fix_spaces(\"Example\") == \"Example\");\n assert (fix_spaces(\"Example 1\") == \"Example_1\");\n assert (fix_spaces(\" Example 2\") == \"_Example_2\");\n assert (fix_spaces(\" Example 3\") == \"_Example-3\");\n}\n", "buggy_solution": " string out=\"\";\n int spacelen=0;\n for (int i=0;i<text.length();i++)\n if (text[i]=='
|
142 |
{"task_id": "CPP/141", "prompt": "/*\nCreate a function which takes a string representing a file's name, and returns\n\"Yes\" if the the file's name is valid, and returns \"No\" otherwise.\nA file's name is considered to be valid if and only if all the following conditions \nare met:\n- There should not be more than three digits ('0'-'9') in the file's name.\n- The file's name contains exactly one dot \".\"\n- The substring before the dot should not be empty, and it starts with a letter from \nthe latin alphapet ('a'-'z' and 'A'-'Z').\n- The substring after the dot should be one of these: {'txt\", \"exe\", \"dll\"}\nExamples:\nfile_name_check(\"example.txt\") => \"Yes\"\nfile_name_check(\"1example.dll\") => \"No\" // (the name should start with a latin alphapet letter)\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring file_name_check(string file_name){\n", "canonical_solution": " int numdigit=0,numdot=0;\n if (file_name.length()<5) return \"No\";\n char w=file_name[0];\n if (w<65 or (w>90 and w<97) or w>122) return \"No\";\n string last=file_name.substr(file_name.length()-4,4);\n if (last!=\".txt\" and last!=\".exe\" and last!=\".dll\") return \"No\";\n for (int i=0;i<file_name.length();i++)\n {\n if (file_name[i]>=48 and file_name[i]<=57) numdigit+=1;\n if (file_name[i]=='.') numdot+=1;\n }\n if (numdigit>3 or numdot!=1) return \"No\";\n return \"Yes\"; \n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (file_name_check(\"example.txt\") == \"Yes\");\n assert (file_name_check(\"1example.dll\") == \"No\");\n assert (file_name_check(\"s1sdf3.asd\") == \"No\");\n assert (file_name_check(\"K.dll\") == \"Yes\");\n assert (file_name_check(\"MY16FILE3.exe\") == \"Yes\");\n assert (file_name_check(\"His12FILE94.exe\") == \"No\");\n assert (file_name_check(\"_Y.txt\") == \"No\");\n assert (file_name_check(\"?aREYA.exe\") == \"No\");\n assert (file_name_check(\"/this_is_valid.dll\") == \"No\");\n assert (file_name_check(\"this_is_valid.wow\") == \"No\");\n assert (file_name_check(\"this_is_valid.txt\") == \"Yes\");\n assert (file_name_check(\"this_is_valid.txtexe\") == \"No\");\n assert (file_name_check(\"#this2_i4s_5valid.ten\") == \"No\");\n assert (file_name_check(\"@this1_is6_valid.exe\") == \"No\");\n assert (file_name_check(\"this_is_12valid.6exe4.txt\") == \"No\");\n assert (file_name_check(\"all.exe.txt\") == \"No\");\n assert (file_name_check(\"I563_No.exe\") == \"Yes\");\n assert (file_name_check(\"Is3youfault.txt\") == \"Yes\");\n assert (file_name_check(\"no_one#knows.dll\") == \"Yes\");\n assert (file_name_check(\"1I563_Yes3.exe\") == \"No\");\n assert (file_name_check(\"I563_Yes3.txtt\") == \"No\");\n assert (file_name_check(\"final..txt\") == \"No\");\n assert (file_name_check(\"final132\") == \"No\");\n assert (file_name_check(\"_f4indsartal132.\") == \"No\");\n assert (file_name_check(\".txt\") == \"No\");\n assert (file_name_check(\"s.\") == \"No\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<math.h>\n#include<stdlib.h>\nstring file_name_check(string file_name){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (file_name_check(\"example.txt\") == \"Yes\");\n assert (file_name_check(\"1example.dll\") == \"No\");\n}\n", "buggy_solution": " int numdigit=0,numdot=0;\n if (file_name.length()<5) return \"No\";\n char w=file_name[0];\n if (w<65 or (w>90 and w<97) or w>122) return \"No\";\n string last=file_name.substr(file_name.length()-4,4);\n if (last!=\".txt\" and last!=\".exe\" and last!=\".dll\") return \"No\";\n for (int i=0;i<file_name.length();i++)\n {\n if (file_name[i]>=48 and file_name[i]<=57) numdigit+=1;\n }\n if (numdigit>3 or numdot!=1) return \"No\";\n return \"Yes\"; \n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "file_name_check"}
|
143 |
{"task_id": "CPP/142", "prompt": "/*\n\"\nThis function will take a vector of integers. For all entries in the vector, the function shall square the integer entry if its index is a \nmultiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not \nchange the entries in the vector whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. \n\nExamples:\nFor lst = {1,2,3} the output should be 6\nFor lst = {} the output should be 0\nFor lst = {-1,-5,2,-1,-5} the output should be -126\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nint sum_squares(vector<int> lst){\n", "canonical_solution": " int sum=0;\n for (int i=0;i<lst.size();i++)\n if (i%3==0) sum+=lst[i]*lst[i];\n else if (i%4==0) sum+=lst[i]*lst[i]*lst[i];\n else sum+=lst[i];\n return sum;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (sum_squares({1,2,3}) == 6);\n assert (sum_squares({1,4,9}) == 14);\n assert (sum_squares({}) == 0);\n assert (sum_squares({1,1,1,1,1,1,1,1,1}) == 9);\n assert (sum_squares({-1,-1,-1,-1,-1,-1,-1,-1,-1}) == -3);\n assert (sum_squares({0}) == 0);\n assert (sum_squares({-1,-5,2,-1,-5}) == -126);\n assert (sum_squares({-56,-99,1,0,-2}) == 3030);\n assert (sum_squares({-1,0,0,0,0,0,0,0,-1}) == 0);\n assert (sum_squares({-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37}) == -14196);\n assert (sum_squares({-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10}) == -1448);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint sum_squares(vector<int> lst){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (sum_squares({1,2,3}) == 6);\n assert (sum_squares({}) == 0);\n assert (sum_squares({-1,-5,2,-1,-5}) == -126);\n}\n", "buggy_solution": " int sum=0;\n for (int i=0;i<lst.size();i++)\n if (i%3==0) sum+=lst[i]*lst[i];\n else sum+=lst[i];\n return sum;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sum_squares"}
|
144 |
{"task_id": "CPP/143", "prompt": "/*\nYou are given a string representing a sentence,\nthe sentence contains some words separated by a space,\nand you have to return a string that contains the words from the original sentence,\nwhose lengths are prime numbers,\nthe order of the words in the new string should be the same as the original one.\n\nExample 1:\n Input: sentence = \"This is a test\"\n Output: \"is\"\n\nExample 2:\n Input: sentence = \"lets go for swimming\"\n Output: \"go for\"\n\nConstraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring words_in_sentence(string sentence){\n", "canonical_solution": " string out=\"\";\n string current=\"\";\n sentence=sentence+' ';\n\n for (int i=0;i<sentence.size();i++)\n if (sentence[i]!=' ') current=current+sentence[i];\n else\n {\n bool isp=true;\n int l=current.length();\n if (l<2) isp=false;\n for (int j=2;j*j<=l;j++)\n if (l%j==0) isp=false;\n if (isp) out=out+current+' ';\n current=\"\"; \n }\n if (out.length()>0)\n out.pop_back();\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (words_in_sentence(\"This is a test\") == \"is\");\n assert (words_in_sentence(\"lets go for swimming\") == \"go for\");\n assert (words_in_sentence(\"there is no place available here\") == \"there is no place\");\n assert (words_in_sentence(\"Hi I am Hussein\") == \"Hi am Hussein\");\n assert (words_in_sentence(\"go for it\") == \"go for it\");\n assert (words_in_sentence(\"here\") == \"\");\n assert (words_in_sentence(\"here is\") == \"is\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring words_in_sentence(string sentence){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (words_in_sentence(\"This is a test\") == \"is\");\n assert (words_in_sentence(\"lets go for swimming\") == \"go for\");\n}\n", "buggy_solution": " string out=\"\";\n string current=\"\";\n sentence=sentence+' ';\n\n for (int i=0;i<sentence.size();i++)\n if (sentence[i]!=' ') current=current+sentence[i];\n else\n {\n bool isp=true;\n int l=current.length();\n if (l<2) isp=false;\n for (int j=2;j*j<=l;j++)\n if (l%j==0) isp=false;\n if (isp) out=out+current+' ';\n current=\"\"; \n }\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "words_in_sentence"}
|
@@ -161,4 +161,4 @@
|
|
161 |
{"task_id": "CPP/160", "prompt": "/*\nGiven two vectors operator, and operand. The first vector has basic algebra operations, and \nthe second vector is a vector of integers. Use the two given vectors to build the algebric \nexpression and return the evaluation of this expression.\n\nThe basic algebra operations:\nAddition ( + ) \nSubtraction ( - ) \nMultiplication ( * ) \nFloor division ( // ) \nExponentiation ( ** ) \n\nExample:\noperator{\"+\", \"*\", \"-\"}\nvector = {2, 3, 4, 5}\nresult = 2 + 3 * 4 - 5\n=> result = 9\n\nNote:\n The length of operator vector is equal to the length of operand vector minus one.\n Operand is a vector of of non-negative integers.\n Operator vector has at least one operator, and operand vector has at least two operands.\n\n*/\n#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nint do_algebra(vector<string> operato, vector<int> operand){\n", "canonical_solution": " vector<int> num={};\n vector<int> posto={};\n for (int i=0;i<operand.size();i++)\n posto.push_back(i);\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"**\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n operand[posto[i]]=pow(operand[posto[i]],operand[posto[i+1]]);\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"*\" or operato[i]==\"//\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"*\")\n operand[posto[i]]=operand[posto[i]]*operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]/operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"+\" or operato[i]==\"-\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"+\")\n operand[posto[i]]=operand[posto[i]]+operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]-operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n return operand[0];\n\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (do_algebra({\"**\", \"*\", \"+\"}, {2, 3, 4, 5}) == 37);\n assert (do_algebra({\"+\", \"*\", \"-\"}, {2, 3, 4, 5}) == 9);\n assert (do_algebra({\"//\", \"*\"}, {7, 3, 4}) == 8);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nint do_algebra(vector<string> operato, vector<int> operand){\n", "example_test": "", "buggy_solution": " vector<int> num={};\n vector<int> posto={};\n for (int i=0;i<operand.size();i++)\n posto.push_back(i);\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"**\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n operand[posto[i]]=pow(operand[posto[i+1]],operand[posto[i+1]]);\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"*\" or operato[i]==\"//\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"*\")\n operand[posto[i]]=operand[posto[i]]*operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]/operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"+\" or operato[i]==\"-\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"+\")\n operand[posto[i]]=operand[posto[i]]+operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]-operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n return operand[0];\n\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "do_algebra"}
|
162 |
{"task_id": "CPP/161", "prompt": "/*\nYou are given a string s.\nif s[i] is a letter, reverse its case from lower to upper or vise versa, \notherwise keep it as it is.\nIf the string contains no letters, reverse the string.\nThe function should return the resulted string.\nExamples\nsolve(\"1234\") = \"4321\"\nsolve(\"ab\") = \"AB\"\nsolve(\"#a@C\") = \"#A@c\"\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring solve(string s){\n", "canonical_solution": " int nletter=0;\n string out=\"\";\n for (int i=0;i<s.length();i++)\n {\n char w=s[i];\n if (w>=65 and w<=90) w=w+32;\n else if (w>=97 and w<=122) w=w-32;\n else nletter+=1;\n out=out+w;\n }\n if (nletter==s.length())\n {\n string p(s.rbegin(),s.rend());\n return p;\n }\n else return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (solve(\"AsDf\") == \"aSdF\");\n assert (solve(\"1234\") == \"4321\");\n assert (solve(\"ab\") == \"AB\");\n assert (solve(\"#a@C\") == \"#A@c\");\n assert (solve(\"#AsdfW^45\") == \"#aSDFw^45\");\n assert (solve(\"#6@2\") == \"2@6#\");\n assert (solve(\"#$a^D\") == \"#$A^d\");\n assert (solve(\"#ccc\") == \"#CCC\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring solve(string s){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (solve(\"1234\") == \"4321\");\n assert (solve(\"ab\") == \"AB\");\n assert (solve(\"#a@C\") == \"#A@c\");\n}\n", "buggy_solution": " int nletter=0;\n string out=\"\";\n for (int i=0;i<s.length();i++)\n {\n char w=s[i];\n if (w>=65 and w<=90) w=w+32;\n else nletter+=1;\n out=out+w;\n }\n if (nletter==s.length())\n {\n string p(s.rbegin(),s.rend());\n return p;\n }\n else return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "solve"}
|
163 |
{"task_id": "CPP/162", "prompt": "/*\nGiven a string 'text\", return its md5 hash equivalent string.\nIf 'text\" is an empty string, return None.\n\n>>> string_to_md5(\"Hello world\") == \"3e25960a79dbc69b674cd4ec67a72c62\"\n*/\n#include<stdio.h>\n#include<string>\n#include<openssl/md5.h>\nusing namespace std;\nstring string_to_md5(string text){\n", "canonical_solution": " unsigned char md[16];\n if (text.length()==0) return \"None\";\n MD5_CTX c;\n int i;\n MD5_Init(&c);\n MD5_Update(&c, (unsigned char*)text.c_str(), text.length());\n MD5_Final(md, &c);\n string out_str=\"\";\n for (int i=0;i<16;i++)\n {\n char w;\n if (md[i]<160) w=48+md[i]/16;\n else w=87+md[i]/16;\n out_str=out_str+w;\n if (md[i]%16<10) w=48+md[i]%16;\n else w=87+md[i]%16;\n out_str=out_str+w;\n }\n return out_str;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (string_to_md5(\"Hello world\") == \"3e25960a79dbc69b674cd4ec67a72c62\");\n assert (string_to_md5(\"\") == \"None\");\n assert (string_to_md5(\"A B C\") == \"0ef78513b0cb8cef12743f5aeb35f888\");\n assert (string_to_md5(\"password\") == \"5f4dcc3b5aa765d61d8327deb882cf99\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\n#include<openssl/md5.h>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring string_to_md5(string text){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (string_to_md5(\"Hello world\") == \"3e25960a79dbc69b674cd4ec67a72c62\");\n}\n", "buggy_solution": " unsigned char md[16];\n if (text.length()==0) return \"None\";\n MD5_CTX c;\n int i;\n MD5_Init(&c);\n MD5_Update(&c, (unsigned char*)text.c_str(), text.length());\n MD5_Final(md, &c);\n string out_str=\"\";\n for (int i=0;i<16;i++)\n {\n char w;\n if (md[i]<160) w=48+md[i]/16;\n else w=87+md[i]/16;\n out_str=out_str+w;\n if (md[i]%16<87) w=48+md[i]%16;\n else w=48+md[i]%16;\n out_str=out_str+w;\n }\n return out_str;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "string_to_md5"}
|
164 |
-
{"task_id": "CPP/163", "prompt": "/*\nGiven two positive integers a and b, return the even digits between a\nand b, in ascending order.\n\nFor example:\ngenerate_integers(2, 8) => {2, 4, 6, 8}\ngenerate_integers(8, 2) => {2, 4, 6, 8}\ngenerate_integers(10, 14) => {}\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nvector<int> generate_integers(int a,int b){\n", "canonical_solution": " int m;\n if (b<a)\n {\n m=a;a=b;b=m;\n }\n\n vector<int> out={};\n for (int i=a;i<=b;i++)\n if (i<10 and i%2==0) out.push_back(i);\n return out;\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(generate_integers(2, 10) , {2, 4, 6, 8}));\n assert (issame(generate_integers(10, 2) , {2, 4, 6, 8}));\n assert (issame(generate_integers(132, 2) , {2, 4, 6, 8}));\n assert (issame(generate_integers(17,89) , {}));\n}\n", "declaration": "#include<stdio.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nvector<int> generate_integers(int a,int b){\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(generate_integers(2, 8) , {2, 4, 6, 8}));\n assert (issame(generate_integers(8, 2) , {2, 4, 6, 8}));\n assert (issame(generate_integers(10,14) , {}));\n}\n", "buggy_solution": " int m;\n if (b<a)\n {\n m=a;a=b;b=m;\n }\n\n vector<int> out={};\n for (int i=a;i<b;i++)\n if (i
|
|
|
108 |
{"task_id": "CPP/107", "prompt": "/*\nGiven a positive integer n, return a vector that has the number of even and odd\ninteger palindromes that fall within the range(1, n), inclusive.\n\nExample 1:\n\n Input: 3\n Output: (1, 2)\n Explanation:\n Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.\n\nExample 2:\n\n Input: 12\n Output: (4, 6)\n Explanation:\n Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\n\nNote:\n 1. 1 <= n <= 10^3\n 2. returned vector has the number of even and odd integer palindromes respectively.\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nvector<int> even_odd_palindrome(int n){\n", "canonical_solution": " int num1=0,num2=0;\n for (int i=1;i<=n;i++)\n {\n string w=to_string(i);\n string p(w.rbegin(),w.rend());\n if (w==p and i%2==1) num1+=1;\n if (w==p and i%2==0) num2+=1;\n \n }\n return {num2,num1};\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(even_odd_palindrome(123) , {8, 13}));\n assert (issame(even_odd_palindrome(12) , {4, 6}));\n assert (issame(even_odd_palindrome(3) , {1, 2}));\n assert (issame(even_odd_palindrome(63) , {6, 8}));\n assert (issame(even_odd_palindrome(25) , {5, 6}));\n assert (issame(even_odd_palindrome(19) , {4, 6}));\n assert (issame(even_odd_palindrome(9) , {4, 5}));\n assert (issame(even_odd_palindrome(1) , {0, 1}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nvector<int> even_odd_palindrome(int n){\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(even_odd_palindrome(12) , {4, 6}));\n assert (issame(even_odd_palindrome(3) , {1, 2}));\n}\n", "buggy_solution": " int num1=0,num2=0;\n for (int i=1;i<=n;i++)\n {\n string w=to_string(i);\n string p(w.rbegin(),w.rend());\n if (w==p and i%2==1) num1+=1;\n if (w==p and i%2==0) num2+=2;\n \n }\n return {num2,num1};\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "even_odd_palindrome"}
|
109 |
{"task_id": "CPP/108", "prompt": "/*\nWrite a function count_nums which takes a vector of integers and returns\nthe number of elements which has a sum of digits > 0.\nIf a number is negative, then its first signed digit will be negative:\ne.g. -123 has signed digits -1, 2, and 3.\n>>> count_nums({}) == 0\n>>> count_nums({-1, 11, -11}) == 1\n>>> count_nums({1, 1, 2}) == 3\n*/\n#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\nint count_nums(vector<int> n){\n", "canonical_solution": " int num=0;\n for (int i=0;i<n.size();i++)\n if (n[i]>0) num+=1;\n else\n {\n int sum=0;\n int w;\n w=abs(n[i]);\n while (w>=10)\n {\n sum+=w%10;\n w=w/10;\n }\n sum-=w;\n if (sum>0) num+=1;\n }\n return num;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (count_nums({}) == 0);\n assert (count_nums({-1, -2, 0}) == 0);\n assert (count_nums({1, 1, 2, -2, 3, 4, 5}) == 6);\n assert (count_nums({1, 6, 9, -6, 0, 1, 5}) == 5);\n assert (count_nums({1, 100, 98, -7, 1, -1}) == 4);\n assert (count_nums({12, 23, 34, -45, -56, 0}) == 5);\n assert (count_nums({-0, 1}) == 1);\n assert (count_nums({1}) == 1);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nint count_nums(vector<int> n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (count_nums({}) == 0);\n assert (count_nums({-1, 11, -11}) == 1);\n assert (count_nums({1, 1, 2}) == 3);\n}\n", "buggy_solution": " int num=0;\n for (int i=0;i<n.size();i++)\n if (n[i]>0) num+=1;\n else\n {\n int sum=0;\n int w;\n w=abs(n[i]);\n while (w>=10)\n {\n sum+=w%10;\n w=w/10;\n }\n sum-=w*-1;\n if (sum>0) num+=1;\n }\n return num;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "count_nums"}
|
110 |
{"task_id": "CPP/109", "prompt": "/*\nWe have a vector \"arr\" of N integers arr[1], arr[2], ..., arr[N].The\nnumbers in the vector will be randomly ordered. Your task is to determine if\nit is possible to get a vector sorted in non-decreasing order by performing \nthe following operation on the given vector:\n You are allowed to perform right shift operation any number of times.\n\nOne right shift operation means shifting all elements of the vector by one\nposition in the right direction. The last element of the vector will be moved to\nthe starting position in the vector i.e. 0th index. \n\nIf it is possible to obtain the sorted vector by performing the above operation\nthen return true else return false.\nIf the given vector is empty then return true.\n\nNote: The given vector is guaranteed to have unique elements.\n\nFor Example:\n\nmove_one_ball({3, 4, 5, 1, 2})==>true\nExplanation: By performing 2 right shift operations, non-decreasing order can\n be achieved for the given vector.\nmove_one_ball({3, 5, 4, 1, 2})==>false\nExplanation:It is not possible to get non-decreasing order for the given\n vector by performing any number of right shift operations.\n \n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nbool move_one_ball(vector<int> arr){\n", "canonical_solution": " int num=0;\n if (arr.size()==0) return true;\n for (int i=1;i<arr.size();i++)\n if (arr[i]<arr[i-1]) num+=1;\n if (arr[arr.size()-1]>arr[0]) num+=1;\n if (num<2) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (move_one_ball({3, 4, 5, 1, 2})==true);\n assert (move_one_ball({3, 5, 10, 1, 2})==true);\n assert (move_one_ball({4, 3, 1, 2})==false);\n assert (move_one_ball({3, 5, 4, 1, 2})==false);\n assert (move_one_ball({})==true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool move_one_ball(vector<int> arr){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (move_one_ball({3, 4, 5, 1, 2})==true);\n assert (move_one_ball({3, 5, 4, 1, 2})==false);\n}\n", "buggy_solution": " int num=0;\n if (arr.size()==0) return true;\n for (int i=1;i<arr.size();i++)\n if (arr[i]<arr[arr.size()-1]) num+=1;\n if (arr[arr.size()-1]>arr[0]) num+=1;\n if (num<2) return true;\n return false;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "move_one_ball"}
|
111 |
+
{"task_id": "CPP/110", "prompt": "/*\nIn this problem, you will implement a function that takes two vectors of numbers,\nand determines whether it is possible to perform an exchange of elements\nbetween them to make lst1 a vector of only even numbers.\nThere is no limit on the number of exchanged elements between lst1 and lst2.\nIf it is possible to exchange elements between the lst1 and lst2 to make\nall the elements of lst1 to be even, return \"YES\".\nOtherwise, return \"NO\".\nFor example:\nexchange({1, 2, 3, 4}, {1, 2, 3, 4}) => \"YES\"\nexchange({1, 2, 3, 4}, {1, 5, 3, 4}) => \"NO\"\nIt is assumed that the input vectors will be non-empty.\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nstring exchange(vector<int> lst1,vector<int> lst2){\n", "canonical_solution": " int num=0;\n for (int i=0;i<lst1.size();i++)\n if (lst1[i]%2==0) num+=1;\n for (int i=0;i<lst2.size();i++)\n if (lst2[i]%2==0) num+=1;\n if (num>=lst1.size()) return \"YES\";\n return \"NO\";\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (exchange({1, 2, 3, 4}, {1, 2, 3, 4}) == \"YES\");\n assert (exchange({1, 2, 3, 4}, {1, 5, 3, 4}) == \"NO\");\n assert (exchange({1, 2, 3, 4}, {2, 1, 4, 3}) == \"YES\" );\n assert (exchange({5, 7, 3}, {2, 6, 4}) == \"YES\");\n assert (exchange({5, 7, 3}, {2, 6, 3}) == \"NO\" );\n assert (exchange({3, 2, 6, 1, 8, 9}, {3, 5, 5, 1, 1, 1}) == \"NO\");\n assert (exchange({100, 200}, {200, 200}) == \"YES\");\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nstring exchange(vector<int> lst1,vector<int> lst2){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (exchange({1, 2, 3, 4}, {1, 2, 3, 4}) == \"YES\");\n assert (exchange({1, 2, 3, 4}, {1, 5, 3, 4}) == \"NO\");\n}\n", "buggy_solution": " int num=0;\n for (int i=0;i<lst1.size();i++)\n if (lst1[i]%2==0) num+=1;\n for (int i=0;i<lst2.size();i++)\n if (lst2[i]%2==0) num+=1;\n if (num<lst1.size()) return \"YES\";\n return \"NO\";\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "exchange"}
|
112 |
{"task_id": "CPP/111", "prompt": "/*\nGiven a string representing a space separated lowercase letters, return a map\nof the letter with the most repetition and containing the corresponding count.\nIf several letters have the same occurrence, return all of them.\n\nExample:\nhistogram(\"a b c\") == {{\"a\", 1}, {\"b\", 1}, {\"c\", 1}}\nhistogram(\"a b b a\") == {{\"a\", 2}, {\"b\", 2}}\nhistogram(\"a b c a b\") == {{\"a\", 2}, {\"b\", 2}}\nhistogram(\"b b b b a\") == {{\"b\", 4}}\nhistogram(\"\") == {}\n\n*/\n#include<stdio.h>\n#include<string>\n#include<map>\nusing namespace std;\nmap<char,int> histogram(string test){\n", "canonical_solution": " map<char,int> count={},out={};\n map <char,int>::iterator it;\n int max=0;\n for (int i=0;i<test.length();i++)\n if (test[i]!=' ')\n {\n count[test[i]]+=1;\n if (count[test[i]]>max) max=count[test[i]];\n }\n for (it=count.begin();it!=count.end();it++)\n {\n char w1=it->first;\n int w2=it->second;\n if (w2==max) out[w1]=w2;\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(map<char,int> a,map<char,int> b){\n if (a.size()!=b.size()) return false;\n map <char,int>::iterator it;\n for (it=a.begin();it!=a.end();it++)\n {\n char w1=it->first;\n int w2=it->second;\n if (b.find(w1)==b.end()) return false;\n if (b[w1]!=w2) return false;\n }\n\n return true;\n}\nint main(){\n assert (issame(histogram(\"a b b a\") , {{'a',2},{'b', 2}}));\n assert (issame(histogram(\"a b c a b\") , {{'a', 2},{'b', 2}}));\n assert (issame(histogram(\"a b c d g\") , {{'a', 1}, {'b', 1}, {'c', 1}, {'d', 1}, {'g', 1}}));\n assert (issame(histogram(\"r t g\") , {{'r', 1},{'t', 1},{'g', 1}}));\n assert (issame(histogram(\"b b b b a\") , {{'b', 4}}));\n assert (issame(histogram(\"r t g\") , {{'r', 1},{'t', 1},{'g', 1}}));\n assert (issame(histogram(\"\") , {}));\n assert (issame(histogram(\"a\") , {{'a', 1}}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<map>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nmap<char,int> histogram(string test){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(map<char,int> a,map<char,int> b){\n if (a.size()!=b.size()) return false;\n map <char,int>::iterator it;\n for (it=a.begin();it!=a.end();it++)\n {\n char w1=it->first;\n int w2=it->second;\n if (b.find(w1)==b.end()) return false;\n if (b[w1]!=w2) return false;\n }\n return true;\n}\nint main(){\n assert (issame(histogram(\"a b b a\") , {{'a',2},{'b', 2}}));\n assert (issame(histogram(\"a b c a b\") , {{'a', 2},{'b', 2}}));\n assert (issame(histogram(\"a b c\") , {{'a', 1},{'b', 1},{'c', 1}}));\n assert (issame(histogram(\"b b b b a\") , {{'b', 4}}));\n assert (issame(histogram(\"\") , {}));\n}\n", "buggy_solution": " map<char,int> count={},out={};\n map <char,int>::iterator it;\n int max=0;\n for (int i=1;i<test.length();i++)\n if (test[i]!=' ')\n {\n count[test[i]]+=1;\n if (count[test[i]]>max) max=count[test[i]];\n }\n for (it=count.begin();it!=count.end();it++)\n {\n char w1=it->first;\n int w2=it->second;\n if (w2==max) out[w1]=w2;\n }\n return out;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "histogram"}
|
113 |
{"task_id": "CPP/112", "prompt": "/*\nTask\nWe are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\nthen check if the result string is palindrome.\nA string is called palindrome if it reads the same backward as forward.\nYou should return a vector containing the result string and \"True\"/\"False\" for the check.\nExample\nFor s = \"abcde\", c = \"ae\", the result should be (\"bcd\",\"False\")\nFor s = \"abcdef\", c = \"b\" the result should be (\"acdef\",\"False\")\nFor s = \"abcdedcba\", c = \"ab\", the result should be (\"cdedc\",\"True\")\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\nvector<string> reverse_delete(string s,string c){\n", "canonical_solution": " string n=\"\";\n for (int i=0;i<s.length();i++)\n if (find(c.begin(),c.end(),s[i])==c.end())\n n=n+s[i]; \n if (n.length()==0) return {n,\"True\"};\n string w(n.rbegin(),n.rend());\n if (w==n) return {n,\"True\"};\n return {n,\"False\"};\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(reverse_delete(\"abcde\",\"ae\") , {\"bcd\",\"False\"}));\n assert (issame(reverse_delete(\"abcdef\", \"b\") , {\"acdef\",\"False\"}));\n assert (issame(reverse_delete(\"abcdedcba\",\"ab\") , {\"cdedc\",\"True\"}));\n assert (issame(reverse_delete(\"dwik\",\"w\") , {\"dik\",\"False\"}));\n assert (issame(reverse_delete(\"a\",\"a\") , {\"\",\"True\"}));\n assert (issame(reverse_delete(\"abcdedcba\",\"\") , {\"abcdedcba\",\"True\"}));\n assert (issame(reverse_delete(\"abcdedcba\",\"v\") , {\"abcdedcba\",\"True\"}));\n assert (issame(reverse_delete(\"vabba\",\"v\") , {\"abba\",\"True\"}));\n assert (issame(reverse_delete(\"mamma\", \"mia\") , {\"\", \"True\"}));\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> reverse_delete(string s,string c){\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(reverse_delete(\"abcde\",\"ae\") , {\"bcd\",\"False\"}));\n assert (issame(reverse_delete(\"abcdef\", \"b\") , {\"acdef\",\"False\"}));\n assert (issame(reverse_delete(\"abcdedcba\",\"ab\") , {\"cdedc\",\"True\"}));\n}\n", "buggy_solution": " string n=\"\";\n for (int i=0;i<s.length();i++)\n if (find(c.begin(),c.end(),s[i])==c.end())\n n=n+s[i]; \n if (n.length()==0) return {n,\"True\"};\n string w(n.rbegin(),n.rend());\n if (w==n) return {n,\"False\"};\n return {n,\"True\"};\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "reverse_delete"}
|
114 |
{"task_id": "CPP/113", "prompt": "/*\nGiven a vector of strings, where each string consists of only digits, return a vector.\nEach element i of the output should be 'the number of odd elements in the\nstring i of the input.\" where all the i's should be replaced by the number\nof odd digits in the i'th string of the input.\n\n>>> odd_count({\"1234567\"})\n{'the number of odd elements 4n the str4ng 4 of the 4nput.\"}\n>>> odd_count({\"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*/\n#include<stdio.h>\n#include<vector>\n#include<string>\n#include<map>\nusing namespace std;\nvector<string> odd_count(vector<string> lst){\n", "canonical_solution": " vector<string> out={};\n for (int i=0;i<lst.size();i++)\n {\n int sum=0;\n for (int j=0;j<lst[i].length();j++)\n if (lst[i][j]>=48 and lst[i][j]<=57 and lst[i][j]%2==1)\n sum+=1;\n string s=\"the number of odd elements in the string i of the input.\";\n string s2=\"\";\n for (int j=0;j<s.length();j++)\n if (s[j]=='i') s2=s2+to_string(sum);\n else s2=s2+s[j];\n out.push_back(s2);\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(odd_count({\"1234567\"}) , {\"the number of odd elements 4n the str4ng 4 of the 4nput.\"}));\n assert (issame(odd_count({\"3\",\"11111111\"}) , {\"the number of odd elements 1n the str1ng 1 of the 1nput.\", \"the number of odd elements 8n the str8ng 8 of the 8nput.\"}));\n assert (issame(odd_count({\"271\", \"137\", \"314\"}) , {\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", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\n#include<map>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nvector<string> odd_count(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(odd_count({\"1234567\"}) , {\"the number of odd elements 4n the str4ng 4 of the 4nput.\"}));\n assert (issame(odd_count({\"3\",\"11111111\"}) , {\"the number of odd elements 1n the str1ng 1 of the 1nput.\", \"the number of odd elements 8n the str8ng 8 of the 8nput.\"}));\n}\n", "buggy_solution": " vector<string> out={};\n for (int i=0;i<lst.size();i++)\n {\n int sum=0;\n for (int j=0;j<lst[i].length();j++)\n if (lst[i][j]>=48 and lst[i][j]<=57 and lst[i][j]%2==1)\n sum+=1;\n string s=\"the number of odd elements in the string i of i the input.\";\n string s2=\"\";\n for (int j=0;j<s.length();j++)\n if (s[j]=='i') s2=s2+to_string(sum);\n else s2=s2+s[j];\n out.push_back(s2);\n }\n return out;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "odd_count"}
|
|
|
125 |
{"task_id": "CPP/124", "prompt": "/*\nYou have to write a function which validates a given date string and\nreturns true if the date is valid otherwise false.\nThe date is valid if all of the following rules are satisfied:\n1. The date string is not empty.\n2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n3. The months should not be less than 1 or higher than 12.\n4. The date should be in the format: mm-dd-yyyy\n\nfor example: \nvalid_date(\"03-11-2000\") => true\n\nvalid_date(\"15-01-2012\") => false\n\nvalid_date(\"04-0-2040\") => false\n\nvalid_date(\"06-04-2020\") => true\n\nvalid_date(\"06/04/2020\") => false\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool valid_date(string date){\n", "canonical_solution": " int mm,dd,yy,i;\n if (date.length()!=10) return false;\n for (int i=0;i<10;i++)\n if (i==2 or i==5)\n {\n if (date[i]!='-') return false;\n }\n else\n if (date[i]<48 or date[i]>57) return false;\n\n mm=atoi(date.substr(0,2).c_str());\n dd=atoi(date.substr(3,2).c_str());\n yy=atoi(date.substr(6,4).c_str());\n if (mm<1 or mm>12) return false;\n if (dd<1 or dd>31) return false;\n if (dd==31 and (mm==4 or mm==6 or mm==9 or mm==11 or mm==2)) return false;\n if (dd==30 and mm==2) return false;\n return true;\n\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (valid_date(\"03-11-2000\") == true);\n assert (valid_date(\"15-01-2012\") == false);\n assert (valid_date(\"04-0-2040\") == false);\n assert (valid_date(\"06-04-2020\") == true);\n assert (valid_date(\"01-01-2007\") == true);\n assert (valid_date(\"03-32-2011\") == false);\n assert (valid_date(\"\") == false);\n assert (valid_date(\"04-31-3000\") == false);\n assert (valid_date(\"06-06-2005\") == true);\n assert (valid_date(\"21-31-2000\") == false);\n assert (valid_date(\"04-12-2003\") == true);\n assert (valid_date(\"04122003\") == false);\n assert (valid_date(\"20030412\") == false);\n assert (valid_date(\"2003-04\") == false);\n assert (valid_date(\"2003-04-12\") == false);\n assert (valid_date(\"04-2003\") == false);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool valid_date(string date){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (valid_date(\"03-11-2000\") == true);\n assert (valid_date(\"15-01-2012\") == false);\n assert (valid_date(\"04-0-2040\") == false);\n assert (valid_date(\"06-04-2020\") == true);\n assert (valid_date(\"06/04/2020\") == false);\n}\n", "buggy_solution": " int dd,mm,yy,i;\n if (date.length()!=10) return false;\n for (int i=0;i<10;i++)\n if (i==2 or i==5)\n {\n if (date[i]!='-') return false;\n }\n else\n if (date[i]<48 or date[i]>57) return false;\n\n dd=atoi(date.substr(0,2).c_str());\n mm=atoi(date.substr(3,2).c_str());\n yy=atoi(date.substr(6,4).c_str());\n if (mm<1 or mm>12) return false;\n if (dd<1 or dd>31) return false;\n if (dd==31 and (mm==4 or mm==6 or mm==9 or mm==11 or mm==2)) return false;\n if (dd==30 and mm==2) return false;\n return true;\n\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "valid_date"}
|
126 |
{"task_id": "CPP/125", "prompt": "/*\nGiven a string of words, return a vector of words split on whitespace, if no whitespaces exists in the text you\nshould split on commas ',' if no commas exists you should return a vector with one element, the number of lower-case letters with odd order in the\nalphabet, ord(\"a\") = 0, ord(\"b\") = 1, ... ord(\"z\") = 25\nExamples\nsplit_words(\"Hello world!\") \u279e {\"Hello\", \"world!\"}\nsplit_words(\"Hello,world!\") \u279e {\"Hello\", \"world!\"}\nsplit_words(\"abcdef\") == {\"3\"} \n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\nvector<string> split_words(string txt){\n", "canonical_solution": " int i;\n string current=\"\";\n vector<string> out={};\n if (find(txt.begin(),txt.end(),' ')!=txt.end())\n {\n txt=txt+' ';\n for (i=0;i<txt.length();i++)\n if (txt[i]==' ') \n {\n if (current.length()>0)out.push_back(current); \n current=\"\";\n }\n else current=current+txt[i];\n return out;\n }\n if (find(txt.begin(),txt.end(),',')!=txt.end())\n {\n txt=txt+',';\n for (i=0;i<txt.length();i++)\n if (txt[i]==',') \n {\n if (current.length()>0)out.push_back(current); \n current=\"\";\n }\n else current=current+txt[i];\n return out;\n }\n int num=0;\n for (i=0;i<txt.length();i++)\n if (txt[i]>=97 and txt[i]<=122 and txt[i]%2==0)\n num+=1;\n return {to_string(num)};\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(split_words(\"Hello world!\") , {\"Hello\",\"world!\"}));\n assert (issame(split_words(\"Hello,world!\") , {\"Hello\",\"world!\"}));\n assert (issame(split_words(\"Hello world,!\") , {\"Hello\",\"world,!\"}));\n assert (issame(split_words(\"Hello,Hello,world !\") , {\"Hello,Hello,world\",\"!\"}));\n assert (issame(split_words(\"abcdef\") , {\"3\"}));\n assert (issame(split_words(\"aaabb\") , {\"2\"}));\n assert (issame(split_words(\"aaaBb\") , {\"1\"}));\n assert (issame(split_words(\"\") ,{\"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>\nvector<string> split_words(string txt){\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(split_words(\"Hello world!\") , {\"Hello\",\"world!\"}));\n assert (issame(split_words(\"Hello,world!\") , {\"Hello\",\"world!\"}));\n assert (issame(split_words(\"abcdef\") , {\"3\"}));\n}\n", "buggy_solution": " int i;\n string current=\"\";\n vector<string> out={};\n if (find(txt.begin(),txt.end(),' ')!=txt.end())\n {\n txt=txt+',';\n for (i=0;i<txt.length();i++)\n if (txt[i]==' ') \n {\n if (current.length()>0)out.push_back(current); \n current=\"\";\n }\n else current=current+txt[i];\n return out;\n }\n if (find(txt.begin(),txt.end(),',')!=txt.end())\n {\n txt=txt+',';\n for (i=0;i<txt.length();i++)\n if (txt[i]==',') \n {\n if (current.length()>0)out.push_back(current); \n current=\"\";\n }\n else current=current+txt[i];\n return out;\n }\n int num=0;\n for (i=0;i<txt.length();i++)\n if (txt[i]>=97 and txt[i]<=122 and txt[i]%2==0)\n num+=1;\n return {to_string(num)};\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "split_words"}
|
127 |
{"task_id": "CPP/126", "prompt": "/*\nGiven a vector of numbers, return whether or not they are sorted\nin ascending order. If vector has more than 1 duplicate of the same\nnumber, return false. Assume no negative numbers and only integers.\n\nExamples\nis_sorted({5}) \u279e true\nis_sorted({1, 2, 3, 4, 5}) \u279e true\nis_sorted({1, 3, 2, 4, 5}) \u279e false\nis_sorted({1, 2, 3, 4, 5, 6}) \u279e true\nis_sorted({1, 2, 3, 4, 5, 6, 7}) \u279e true\nis_sorted({1, 3, 2, 4, 5, 6, 7}) \u279e false\nis_sorted({1, 2, 2, 3, 3, 4}) \u279e true\nis_sorted({1, 2, 2, 2, 3, 4}) \u279e false\n*/\n#include<stdio.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\nbool is_sorted(vector<int> lst){\n", "canonical_solution": " for (int i=1;i<lst.size();i++)\n {\n if (lst[i]<lst[i-1]) return false;\n if (i>=2 and lst[i]==lst[i-1] and lst[i]==lst[i-2]) return false;\n }\n return true;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_sorted({5}) == true);\n assert (is_sorted({1, 2, 3, 4, 5}) == true);\n assert (is_sorted({1, 3, 2, 4, 5}) == false);\n assert (is_sorted({1, 2, 3, 4, 5, 6}) == true);\n assert (is_sorted({1, 2, 3, 4, 5, 6, 7}) == true);\n assert (is_sorted({1, 3, 2, 4, 5, 6, 7}) == false);\n assert (is_sorted({}) == true);\n assert (is_sorted({1}) == true);\n assert (is_sorted({3, 2, 1}) == false);\n assert (is_sorted({1, 2, 2, 2, 3, 4}) == false);\n assert (is_sorted({1, 2, 3, 3, 3, 4}) == false);\n assert (is_sorted({1, 2, 2, 3, 3, 4}) == true);\n assert (is_sorted({1, 2, 3, 4}) == true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool is_sorted(vector<int> lst){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_sorted({5}) == true);\n assert (is_sorted({1, 2, 3, 4, 5}) == true);\n assert (is_sorted({1, 3, 2, 4, 5}) == false);\n assert (is_sorted({1, 2, 3, 4, 5, 6}) == true);\n assert (is_sorted({1, 2, 3, 4, 5, 6, 7}) == true);\n assert (is_sorted({1, 3, 2, 4, 5, 6, 7}) == false);\n assert (is_sorted({1, 2, 2, 2, 3, 4}) == false);\n assert (is_sorted({1, 2, 2, 3, 3, 4}) == true);\n}\n", "buggy_solution": " for (int i=1;i<lst.size();i++)\n {\n if (lst[i]<lst[i-1]) return false;\n if (i>=2 and lst[i]==lst[i-1]) return false;\n }\n return true;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "is_sorted"}
|
128 |
+
{"task_id": "CPP/127", "prompt": "/*\nYou are given two intervals,\nwhere each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\nThe given intervals are closed which means that the interval (start, end)\nincludes both start and end.\nFor each given interval, it is assumed that its start is less or equal its end.\nYour task is to determine whether the length of intersection of these two \nintervals is a prime number.\nExample, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\nwhich its length is 1, which not a prime number.\nIf the length of the intersection is a prime number, return \"YES\",\notherwise, return \"NO\".\nIf the two intervals don't intersect, return \"NO\".\n\n\n{input/output} samples:\nintersection({1, 2}, {2, 3}) ==> \"NO\"\nintersection({-1, 1}, {0, 4}) ==> \"NO\"\nintersection({-3, -1}, {-5, 5}) ==> \"YES\"\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nstring intersection( vector<int> interval1,vector<int> interval2){\n", "canonical_solution": " int inter1,inter2,l,i;\n inter1=max(interval1[0],interval2[0]);\n inter2=min(interval1[1],interval2[1]);\n l=inter2-inter1;\n if (l<2) return \"NO\";\n for (i=2;i*i<=l;i++)\n if (l%i==0) return \"NO\";\n return \"YES\";\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (intersection({1, 2}, {2, 3}) == \"NO\");\n assert (intersection({-1, 1}, {0, 4}) == \"NO\");\n assert (intersection({-3, -1}, {-5, 5}) == \"YES\");\n assert (intersection({-2, 2}, {-4, 0}) == \"YES\");\n assert (intersection({-11, 2}, {-1, -1}) == \"NO\");\n assert (intersection({1, 2}, {3, 5}) == \"NO\");\n assert (intersection({1, 2}, {1, 2}) == \"NO\");\n assert (intersection({-2, -2}, {-3, -2}) == \"NO\");\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>\nstring intersection( vector<int> interval1,vector<int> interval2){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (intersection({1, 2}, {2, 3}) == \"NO\");\n assert (intersection({-1, 1}, {0, 4}) == \"NO\");\n assert (intersection({-3, -1}, {-5, 5}) == \"YES\");\n}\n", "buggy_solution": " int inter1,inter2,l,i;\n inter1=max(interval1[0],interval2[0]);\n inter2=min(interval1[1],interval2[1]);\n l=inter2;\n if (l<2) return \"NO\";\n return \"YES\";\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "intersection"}
|
129 |
{"task_id": "CPP/128", "prompt": "/*\nYou are given a vector arr of integers and you need to return\nsum of magnitudes of integers multiplied by product of all signs\nof each number in the vector, represented by 1, -1 or 0.\nNote: return -32768 for empty arr.\n\nExample:\n>>> prod_signs({1, 2, 2, -4}) == -9\n>>> prod_signs({0, 1}) == 0\n>>> prod_signs({}) == -32768\n*/\n#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\nint prod_signs(vector<int> arr){\n", "canonical_solution": " if (arr.size()==0) return -32768;\n int i,sum=0,prods=1;\n for (i=0;i<arr.size();i++)\n {\n sum+=abs(arr[i]);\n if (arr[i]==0) prods=0;\n if (arr[i]<0) prods=-prods;\n }\n return sum*prods;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (prod_signs({1, 2, 2, -4}) == -9);\n assert (prod_signs({0, 1}) == 0);\n assert (prod_signs({1, 1, 1, 2, 3, -1, 1}) == -10);\n assert (prod_signs({}) == -32768);\n assert (prod_signs({2, 4,1, 2, -1, -1, 9}) == 20);\n assert (prod_signs({-1, 1, -1, 1}) == 4);\n assert (prod_signs({-1, 1, 1, 1}) == -4);\n assert (prod_signs({-1, 1, 1, 0}) == 0);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint prod_signs(vector<int> arr){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (prod_signs({1, 2, 2, -4}) == -9);\n assert (prod_signs({0, 1}) == 0);\n assert (prod_signs({}) == -32768);\n}\n", "buggy_solution": " if (arr.size()==0) return -32768;\n int i,sum=0,prods=1;\n for (i=0;i<arr.size();i++)\n {\n sum+=abs(arr[i])*2;\n if (arr[i]==0) prods=0;\n if (arr[i]<0) prods=-prods;\n }\n return sum*prods;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "prod_signs"}
|
130 |
{"task_id": "CPP/129", "prompt": "/*\nGiven a grid with N rows and N columns (N >= 2) and a positive integer k, \neach cell of the grid contains a value. Every integer in the range {1, N * N}\ninclusive appears exactly once on the cells of the grid.\n\nYou have to find the minimum path of length k in the grid. You can start\nfrom any cell, and in each step you can move to any of the neighbor cells,\nin other words, you can go to cells which share an edge with you current\ncell.\nPlease note that a path of length k means visiting exactly k cells (not\nnecessarily distinct).\nYou CANNOT go off the grid.\nA path A (of length k) is considered less than a path B (of length k) if\nafter making the ordered vectors of the values on the cells that A and B go\nthrough (let's call them lst_A and lst_B), lst_A is lexicographically less\nthan lst_B, in other words, there exist an integer index i (1 <= i <= k)\nsuch that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\nlst_A[j] = lst_B[j].\nIt is guaranteed that the answer is unique.\nReturn an ordered vector of the values on the cells that the minimum path go through.\n\nExamples:\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*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nvector<int> minPath(vector<vector<int>> grid, int k){\n", "canonical_solution": " int i,j,x,y,min;\n for (i=0;i<grid.size();i++)\n for (j=0;j<grid[i].size();j++)\n if (grid[i][j]==1) {\n x=i;y=j;\n }\n min=grid.size()*grid.size();\n if (x>0 and grid[x-1][y]<min) min=grid[x-1][y];\n if (x<grid.size()-1 and grid[x+1][y]<min) min=grid[x+1][y];\n if (y>0 and grid[x][y-1]<min) min=grid[x][y-1];\n if (y<grid.size()-1 and grid[x][y+1]<min) min=grid[x][y+1];\n vector<int> out={};\n for (i=0;i<k;i++)\n if (i%2==0) out.push_back(1);\n else out.push_back(min);\n return out;\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(minPath({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, 3) , {1, 2, 1}));\n assert (issame(minPath({{5, 9, 3}, {4, 1, 6}, {7, 8, 2}}, 1) , {1}));\n assert (issame(minPath({{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}, 4) , {1, 2, 1, 2}));\n assert (issame(minPath({{6, 4, 13, 10}, {5, 7, 12, 1}, {3, 16, 11, 15}, {8, 14, 9, 2}}, 7) , {1, 10, 1, 10, 1, 10, 1}));\n assert (issame(minPath({{8, 14, 9, 2}, {6, 4, 13, 15}, {5, 7, 1, 12}, {3, 10, 11, 16}}, 5) , {1, 7, 1, 7, 1}));\n assert (issame(minPath({{11, 8, 7, 2}, {5, 16, 14, 4}, {9, 3, 15, 6}, {12, 13, 10, 1}}, 9) , {1, 6, 1, 6, 1, 6, 1, 6, 1}));\n assert (issame(minPath({{12, 13, 10, 1}, {9, 3, 15, 6}, {5, 16, 14, 4}, {11, 8, 7, 2}}, 12) , {1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6}));\n assert (issame(minPath({{2, 7, 4}, {3, 1, 5}, {6, 8, 9}}, 8) , {1, 3, 1, 3, 1, 3, 1, 3}));\n assert (issame(minPath({{6, 1, 5}, {3, 8, 9}, {2, 7, 4}}, 8) , {1, 5, 1, 5, 1, 5, 1, 5}));\n assert (issame(minPath({{1, 2}, {3, 4}}, 10) , {1, 2, 1, 2, 1, 2, 1, 2, 1, 2}));\n assert (issame(minPath({{1, 3}, {3, 2}}, 10) , {1, 3, 1, 3, 1, 3, 1, 3, 1, 3}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nvector<int> minPath(vector<vector<int>> grid, int k){\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(minPath({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, 3) , {1, 2, 1}));\n assert (issame(minPath({{5, 9, 3}, {4, 1, 6}, {7, 8, 2}}, 1) , {1}));\n}\n", "buggy_solution": " int i,j,x,y,min;\n for (i=0;i<grid.size();i++)\n for (j=0;j<grid[i].size();j++)\n if (grid[i][j]==1) {\n x=i;y=j;\n }\n min=grid.size()*grid.size();\n if (x>0 and grid[x-1][y]<min) min=grid[x-1][y];\n if (x<grid.size()-1 and grid[x+1][y]<min) min=grid[x][y];\n if (y>0 and grid[x][y-1]<min) min=grid[x][y];\n if (y<grid.size()-1 and grid[x][y+1]<min) min=grid[x][y];\n vector<int> out={};\n for (i=0;i<k;i++)\n if (i%2==0) out.push_back(1);\n else out.push_back(min);\n return out;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "minPath"}
|
131 |
{"task_id": "CPP/130", "prompt": "/*\nEveryone knows Fibonacci sequence, it was studied deeply by mathematicians in \nthe last couple centuries. However, what people don't know is Tribonacci sequence.\nTribonacci sequence is defined by the recurrence:\ntri(1) = 3\ntri(n) = 1 + n / 2, if n is even.\ntri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\nFor example:\ntri(2) = 1 + (2 / 2) = 2\ntri(4) = 3\ntri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8 \nYou are given a non-negative integer number n, you have to a return a vector of the \nfirst n + 1 numbers of the Tribonacci sequence.\nExamples:\ntri(3) = {1, 3, 2, 8}\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nvector<int> tri(int n){\n", "canonical_solution": " vector<int> out={1,3};\n if (n==0) return {1};\n for (int i=2;i<=n;i++)\n {\n if (i%2==0) out.push_back(1+i/2);\n else out.push_back(out[i-1]+out[i-2]+1+(i+1)/2);\n }\n return out;\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(tri(3) , {1, 3, 2, 8}));\n assert (issame(tri(4) , {1, 3, 2, 8, 3}));\n assert (issame(tri(5) , {1, 3, 2, 8, 3, 15}));\n assert (issame(tri(6) , {1, 3, 2, 8, 3, 15, 4}));\n assert (issame(tri(7) , {1, 3, 2, 8, 3, 15, 4, 24}));\n assert (issame(tri(8) , {1, 3, 2, 8, 3, 15, 4, 24, 5}));\n assert (issame(tri(9) , {1, 3, 2, 8, 3, 15, 4, 24, 5, 35}));\n assert (issame(tri(20) , {1, 3, 2, 8, 3, 15, 4, 24, 5, 35, 6, 48, 7, 63, 8, 80, 9, 99, 10, 120, 11}));\n assert (issame(tri(0) , {1}));\n assert (issame(tri(1) , {1, 3}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nvector<int> tri(int n){\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(tri(3) , {1, 3, 2, 8}));\n}\n", "buggy_solution": " vector<int> out={1,3};\n if (n==0) return {1};\n for (int i=2;i<=n;i++)\n {\n if (i%2==0) out.push_back(1+i/2);\n else out.push_back(out[i-1]+out[i-2]+1+i+(i+1)/2);\n }\n return out;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "tri"}
|
132 |
+
{"task_id": "CPP/131", "prompt": "/*\nGiven a positive integer n, return the product of the odd digits.\nReturn 0 if all digits are even.\nFor example:\ndigits(1) == 1\ndigits(4) == 0\ndigits(235) == 15\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nint digits(int n){\n", "canonical_solution": " int prod=1,has=0;\n string s=to_string(n);\n for (int i=0;i<s.length();i++)\n if (s[i]%2==1) \n {\n has=1;\n prod=prod*(s[i]-48);\n }\n if (has==0) return 0;\n return prod;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (digits(5) == 5);\n assert (digits(54) == 5);\n assert (digits(120) ==1);\n assert (digits(5014) == 5);\n assert (digits(98765) == 315);\n assert (digits(5576543) == 2625);\n assert (digits(2468) == 0);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint digits(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (digits(1) == 1);\n assert (digits(4) == 0);\n assert (digits(235) ==15);\n}\n", "buggy_solution": " int prod=1,has=0;\n string s=to_string(n);\n for (int i=0;i<s.length();i++)\n if (s[i]%2==1) \n {\n has=1;\n prod=48*prod*(s[i]-48);\n }\n if (has==0) return 0;\n return prod;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "digits"}
|
133 |
{"task_id": "CPP/132", "prompt": "/*\nCreate a function that takes a string as input which contains only square brackets.\nThe function should return true if and only if there is a valid subsequence of brackets\nwhere at least one bracket in the subsequence is nested.\n\nis_nested(\"[[]]\") \u279e true\nis_nested(\"[]]]]]]][[[[[]\") \u279e false\nis_nested(\"[][]\") \u279e false\nis_nested(\"[]\") \u279e false\nis_nested(\"[[][]]\") \u279e true\nis_nested(\"[[]][[\") \u279e true\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool is_nested(string str){\n", "canonical_solution": " int count=0,maxcount=0;\n for (int i=0;i<str.length();i++)\n {\n if (str[i]=='[') count+=1;\n if (str[i]==']') count-=1;\n if (count<0) count=0;\n if (count>maxcount) maxcount=count;\n if (count<=maxcount-2) return true;\n }\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_nested(\"[[]]\") == true);\n assert (is_nested(\"[]]]]]]][[[[[]\") == false);\n assert (is_nested(\"[][]\") == false);\n assert (is_nested((\"[]\")) == false);\n assert (is_nested(\"[[[[]]]]\") == true);\n assert (is_nested(\"[]]]]]]]]]]\") == false);\n assert (is_nested(\"[][][[]]\") == true);\n assert (is_nested(\"[[]\") == false);\n assert (is_nested(\"[]]\") == false);\n assert (is_nested(\"[[]][[\") == true);\n assert (is_nested(\"[[][]]\") == true);\n assert (is_nested(\"\") == false);\n assert (is_nested(\"[[[[[[[[\") == false);\n assert (is_nested(\"]]]]]]]]\") == false);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool is_nested(string str){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_nested(\"[[]]\") == true);\n assert (is_nested(\"[]]]]]]][[[[[]\") == false);\n assert (is_nested(\"[][]\") == false);\n assert (is_nested(\"[]\") == false);\n assert (is_nested(\"[[]][[\") == true);\n assert (is_nested(\"[[][]]\") == true);\n}\n", "buggy_solution": " int count=0,maxcount=0;\n for (int i=0;i<str.length();i++)\n {\n if (str[i]=='(') count+=1;\n if (str[i]==')') count-=1;\n if (count<0) count=0;\n if (count>maxcount) maxcount=count;\n if (count<=maxcount-2) return true;\n }\n return false;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "is_nested"}
|
134 |
{"task_id": "CPP/133", "prompt": "/*\nYou are given a vector of numbers.\nYou need to return the sum of squared numbers in the given vector,\nround each element in the vector to the upper int(Ceiling) first.\nExamples:\nFor lst = {1,2,3} the output should be 14\nFor lst = {1,4,9} the output should be 98\nFor lst = {1,3,5,7} the output should be 84\nFor lst = {1.4,4.2,0} the output should be 29\nFor lst = {-2.4,1,1} the output should be 6\n\n\n*/\n#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\nint sum_squares(vector<float> lst){\n", "canonical_solution": " int sum=0;\n for (int i=0;i<lst.size();i++)\n sum+=ceil(lst[i])*ceil(lst[i]);\n return sum;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (sum_squares({1,2,3})==14);\n assert (sum_squares({1.0,2,3})==14);\n assert (sum_squares({1,3,5,7})==84);\n assert (sum_squares({1.4,4.2,0})==29);\n assert (sum_squares({-2.4,1,1})==6);\n assert (sum_squares({100,1,15,2})==10230);\n assert (sum_squares({10000,10000})==200000000);\n assert (sum_squares({-1.4,4.6,6.3})==75);\n assert (sum_squares({-1.4,17.9,18.9,19.9})==1086);\n assert (sum_squares({0})==0);\n assert (sum_squares({-1})==1);\n assert (sum_squares({-1,1,0})==2);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint sum_squares(vector<float> lst){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (sum_squares({1,2,3})==14);\n assert (sum_squares({1,4,9})==98);\n assert (sum_squares({1,3,5,7})==84);\n assert (sum_squares({1.4,4.2,0})==29);\n assert (sum_squares({-2.4,1,1})==6);\n}\n", "buggy_solution": " int sum=0;\n for (int i=0;i<lst.size();i++)\n sum+=ceil(lst[i])*2;\n return sum;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "sum_squares"}
|
135 |
{"task_id": "CPP/134", "prompt": "/*\nCreate a function that returns true if the last character\nof a given string is an alphabetical character and is not\na part of a word, and false otherwise.\nNote: \"word\" is a group of characters separated by space.\n\nExamples:\ncheck_if_last_char_is_a_letter(\"apple pie\") \u279e false\ncheck_if_last_char_is_a_letter(\"apple pi e\") \u279e true\ncheck_if_last_char_is_a_letter(\"apple pi e \") \u279e false\ncheck_if_last_char_is_a_letter(\"\") \u279e false \n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool check_if_last_char_is_a_letter(string txt){\n", "canonical_solution": " if (txt.length()==0) return false;\n char chr=txt[txt.length()-1];\n if (chr<65 or (chr>90 and chr<97) or chr>122) return false;\n if (txt.length()==1) return true;\n chr=txt[txt.length()-2];\n if ((chr>=65 and chr<=90) or (chr>=97 and chr<=122)) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (check_if_last_char_is_a_letter(\"apple\") == false);\n assert (check_if_last_char_is_a_letter(\"apple pi e\") == true);\n assert (check_if_last_char_is_a_letter(\"eeeee\") == false);\n assert (check_if_last_char_is_a_letter(\"A\") == true);\n assert (check_if_last_char_is_a_letter(\"Pumpkin pie \") == false);\n assert (check_if_last_char_is_a_letter(\"Pumpkin pie 1\") == false);\n assert (check_if_last_char_is_a_letter(\"\") == false);\n assert (check_if_last_char_is_a_letter(\"eeeee e \") == false);\n assert (check_if_last_char_is_a_letter(\"apple pie\") == false);\n assert (check_if_last_char_is_a_letter(\"apple pi e \") == false);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool check_if_last_char_is_a_letter(string txt){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (check_if_last_char_is_a_letter(\"apple pi e\") == true);\n assert (check_if_last_char_is_a_letter(\"\") == false);\n assert (check_if_last_char_is_a_letter(\"apple pie\") == false);\n assert (check_if_last_char_is_a_letter(\"apple pi e \") == false);\n}\n", "buggy_solution": " if (txt.length()==0) return false;\n char chr=txt[txt.length()-1];\n if (chr<10 or (chr>50 and chr<57) or chr>200) return false;\n if (txt.length()==1) return true;\n chr=txt[txt.length()-2];\n if ((chr>=30 and chr<=37) or (chr>=21 and chr<=42)) return false;\n return true;\n}\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "check_if_last_char_is_a_letter"}
|
|
|
138 |
{"task_id": "CPP/137", "prompt": "/*\nCreate a function that takes integers, floats, or strings representing\nreal numbers, and returns the larger variable in its given variable type.\nReturn \"None\" if the values are equal.\nNote: If a real number is represented as a string, the floating point might be . or ,\n\ncompare_one(1, 2.5) \u279e 2.5\ncompare_one(1, \"2,3\") \u279e \"2,3\"\ncompare_one(\"5,1\", \"6\") \u279e \"6\"\ncompare_one(\"1\", 1) \u279e \"None\"\n*/\n#include<stdio.h>\n#include<string>\n#include<algorithm>\n#include<boost/any.hpp>\nusing namespace std;\nboost::any compare_one(boost::any a,boost::any b){\n", "canonical_solution": " double numa,numb;\n boost::any out;\n \n if (a.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(a);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1);\n numa=atof(s.c_str());\n \n }\n else \n {\n if (a.type()==typeid(int)) numa=boost::any_cast<int>(a);\n if (a.type()==typeid(double)) numa=boost::any_cast<double>(a);\n }\n if (b.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(b);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1);\n numb=atof(s.c_str());\n }\n else \n {\n if (b.type()==typeid(int)) numb=boost::any_cast<int>(b);\n if (b.type()==typeid(double)) numb=boost::any_cast<double>(b);\n }\n\n if (numa==numb) return string(\"None\");\n if (numa<numb) return b;\n if (numa>numb) return a;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (boost::any_cast<int>(compare_one(1, 2)) == 2);\n assert (boost::any_cast<double>(compare_one(1, 2.5))== 2.5);\n assert (boost::any_cast<int>(compare_one(2, 3)) == 3);\n assert (boost::any_cast<int>(compare_one(5, 6)) == 6);\n assert (boost::any_cast<string>(compare_one(1, string(\"2,3\")))== \"2,3\");\n assert (boost::any_cast<string>(compare_one(string(\"5,1\"), string(\"6\"))) == \"6\");\n assert (boost::any_cast<string>(compare_one(string(\"1\"), string(\"2\"))) == \"2\");\n assert (boost::any_cast<string>(compare_one(string(\"1\"), 1)) == \"None\");\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\n#include<boost/any.hpp>\nusing namespace std;\n#include<stdlib.h>\nboost::any compare_one(boost::any a,boost::any b){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (boost::any_cast<double>(compare_one(1, 2.5))== 2.5);\n assert (boost::any_cast<string>(compare_one(1, string(\"2,3\")))== \"2,3\");\n assert (boost::any_cast<string>(compare_one(string(\"5,1\"), string(\"6\"))) == \"6\");\n assert (boost::any_cast<string>(compare_one(string(\"1\"), 1)) == \"None\");\n}\n", "buggy_solution": " double numa,numb;\n boost::any out;\n \n if (a.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(a);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1);\n numa=atof(s.c_str());\n \n }\n else \n {\n if (a.type()==typeid(int)) numa=boost::any_cast<int>(a);\n if (a.type()==typeid(double)) numa=boost::any_cast<double>(a);\n }\n if (b.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(b);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1)+',';\n numb=atof(s.c_str());\n }\n else \n {\n if (b.type()==typeid(int)) numb=boost::any_cast<int>(b);\n if (b.type()==typeid(double)) numb=boost::any_cast<double>(b);\n }\n\n if (numa==numb) return string(\"None\");\n if (numa<numb) return b;\n if (numa>numb) return a;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "compare_one"}
|
139 |
{"task_id": "CPP/138", "prompt": "/*\nEvaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\nExample\nis_equal_to_sum_even(4) == false\nis_equal_to_sum_even(6) == false\nis_equal_to_sum_even(8) == true\n*/\n#include<stdio.h>\nusing namespace std;\nbool is_equal_to_sum_even(int n){\n", "canonical_solution": " if (n%2==0 and n>=8) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_equal_to_sum_even(4) == false);\n assert (is_equal_to_sum_even(6) == false);\n assert (is_equal_to_sum_even(8) == true);\n assert (is_equal_to_sum_even(10) == true);\n assert (is_equal_to_sum_even(11) == false);\n assert (is_equal_to_sum_even(12) == true);\n assert (is_equal_to_sum_even(13) == false);\n assert (is_equal_to_sum_even(16) == true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool is_equal_to_sum_even(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_equal_to_sum_even(4) == false);\n assert (is_equal_to_sum_even(6) == false);\n assert (is_equal_to_sum_even(8) == true);\n}\n", "buggy_solution": " if (n%2==0 and n>=8 and n <=8) return true;\n return false;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "is_equal_to_sum_even"}
|
140 |
{"task_id": "CPP/139", "prompt": "/*\nThe Brazilian factorial is defined as:\nbrazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\nwhere n > 0\n\nFor example:\n>>> special_factorial(4)\n288\n\nThe function will receive an integer as input and should return the special\nfactorial of this integer.\n*/\n#include<stdio.h>\nusing namespace std;\nlong long special_factorial(int n){\n", "canonical_solution": " long long fact=1,bfact=1;\n for (int i=1;i<=n;i++)\n {\n fact=fact*i;\n bfact=bfact*fact;\n }\n return bfact;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (special_factorial(4) == 288);\n assert (special_factorial(5) == 34560);\n assert (special_factorial(7) == 125411328000);\n assert (special_factorial(1) == 1);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nlong long special_factorial(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (special_factorial(4) == 288);\n}\n", "buggy_solution": " long long fact=1,bfact=1;\n for (int i=1;i<=n;i++)\n {\n i=i*n;\n fact=fact*i;\n bfact=bfact*fact;\n }\n return bfact;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "special_factorial"}
|
141 |
+
{"task_id": "CPP/140", "prompt": "/*\nGiven a string text, replace all spaces in it with underscores, \nand if a string has more than 2 consecutive spaces, \nthen replace all consecutive spaces with - \n\nfix_spaces(\"Example\") == \"Example\"\nfix_spaces(\"Example 1\") == \"Example_1\"\nfix_spaces(\" Example 2\") == \"_Example_2\"\nfix_spaces(\" Example 3\") == \"_Example-3\"\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring fix_spaces(string text){\n", "canonical_solution": " string out=\"\";\n int spacelen=0;\n for (int i=0;i<text.length();i++)\n if (text[i]==' ') spacelen+=1;\n else\n {\n if (spacelen==1) out=out+'_';\n if (spacelen==2) out=out+\"__\";\n if (spacelen>2) out=out+'-';\n spacelen=0;\n out=out+text[i];\n }\n if (spacelen==1) out=out+'_';\n if (spacelen==2) out=out+\"__\";\n if (spacelen>2) out=out+'-';\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (fix_spaces(\"Example\") == \"Example\");\n assert (fix_spaces(\"Mudasir Hanif \") == \"Mudasir_Hanif_\");\n assert (fix_spaces(\"Yellow Yellow Dirty Fellow\") == \"Yellow_Yellow__Dirty__Fellow\");\n assert (fix_spaces(\"Exa mple\") == \"Exa-mple\");\n assert (fix_spaces(\" Exa 1 2 2 mple\") == \"-Exa_1_2_2_mple\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring fix_spaces(string text){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (fix_spaces(\"Example\") == \"Example\");\n assert (fix_spaces(\"Example 1\") == \"Example_1\");\n assert (fix_spaces(\" Example 2\") == \"_Example_2\");\n assert (fix_spaces(\" Example 3\") == \"_Example-3\");\n}\n", "buggy_solution": " string out=\"\";\n int spacelen=0;\n for (int i=0;i<text.length();i++)\n if (text[i]==' ') spacelen+=1;\n else\n {\n if (spacelen==1) out=out+'__';\n if (spacelen==2) out=out+\"__\";\n if (spacelen>2) out=out+'--';\n spacelen=0;\n out=out+text[i];\n }\n if (spacelen==1) out=out+'_';\n if (spacelen==2) out=out+\"___\";\n if (spacelen>2) out=out+'-';\n return out;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "fix_spaces"}
|
142 |
{"task_id": "CPP/141", "prompt": "/*\nCreate a function which takes a string representing a file's name, and returns\n\"Yes\" if the the file's name is valid, and returns \"No\" otherwise.\nA file's name is considered to be valid if and only if all the following conditions \nare met:\n- There should not be more than three digits ('0'-'9') in the file's name.\n- The file's name contains exactly one dot \".\"\n- The substring before the dot should not be empty, and it starts with a letter from \nthe latin alphapet ('a'-'z' and 'A'-'Z').\n- The substring after the dot should be one of these: {'txt\", \"exe\", \"dll\"}\nExamples:\nfile_name_check(\"example.txt\") => \"Yes\"\nfile_name_check(\"1example.dll\") => \"No\" // (the name should start with a latin alphapet letter)\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring file_name_check(string file_name){\n", "canonical_solution": " int numdigit=0,numdot=0;\n if (file_name.length()<5) return \"No\";\n char w=file_name[0];\n if (w<65 or (w>90 and w<97) or w>122) return \"No\";\n string last=file_name.substr(file_name.length()-4,4);\n if (last!=\".txt\" and last!=\".exe\" and last!=\".dll\") return \"No\";\n for (int i=0;i<file_name.length();i++)\n {\n if (file_name[i]>=48 and file_name[i]<=57) numdigit+=1;\n if (file_name[i]=='.') numdot+=1;\n }\n if (numdigit>3 or numdot!=1) return \"No\";\n return \"Yes\"; \n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (file_name_check(\"example.txt\") == \"Yes\");\n assert (file_name_check(\"1example.dll\") == \"No\");\n assert (file_name_check(\"s1sdf3.asd\") == \"No\");\n assert (file_name_check(\"K.dll\") == \"Yes\");\n assert (file_name_check(\"MY16FILE3.exe\") == \"Yes\");\n assert (file_name_check(\"His12FILE94.exe\") == \"No\");\n assert (file_name_check(\"_Y.txt\") == \"No\");\n assert (file_name_check(\"?aREYA.exe\") == \"No\");\n assert (file_name_check(\"/this_is_valid.dll\") == \"No\");\n assert (file_name_check(\"this_is_valid.wow\") == \"No\");\n assert (file_name_check(\"this_is_valid.txt\") == \"Yes\");\n assert (file_name_check(\"this_is_valid.txtexe\") == \"No\");\n assert (file_name_check(\"#this2_i4s_5valid.ten\") == \"No\");\n assert (file_name_check(\"@this1_is6_valid.exe\") == \"No\");\n assert (file_name_check(\"this_is_12valid.6exe4.txt\") == \"No\");\n assert (file_name_check(\"all.exe.txt\") == \"No\");\n assert (file_name_check(\"I563_No.exe\") == \"Yes\");\n assert (file_name_check(\"Is3youfault.txt\") == \"Yes\");\n assert (file_name_check(\"no_one#knows.dll\") == \"Yes\");\n assert (file_name_check(\"1I563_Yes3.exe\") == \"No\");\n assert (file_name_check(\"I563_Yes3.txtt\") == \"No\");\n assert (file_name_check(\"final..txt\") == \"No\");\n assert (file_name_check(\"final132\") == \"No\");\n assert (file_name_check(\"_f4indsartal132.\") == \"No\");\n assert (file_name_check(\".txt\") == \"No\");\n assert (file_name_check(\"s.\") == \"No\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<math.h>\n#include<stdlib.h>\nstring file_name_check(string file_name){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (file_name_check(\"example.txt\") == \"Yes\");\n assert (file_name_check(\"1example.dll\") == \"No\");\n}\n", "buggy_solution": " int numdigit=0,numdot=0;\n if (file_name.length()<5) return \"No\";\n char w=file_name[0];\n if (w<65 or (w>90 and w<97) or w>122) return \"No\";\n string last=file_name.substr(file_name.length()-4,4);\n if (last!=\".txt\" and last!=\".exe\" and last!=\".dll\") return \"No\";\n for (int i=0;i<file_name.length();i++)\n {\n if (file_name[i]>=48 and file_name[i]<=57) numdigit+=1;\n }\n if (numdigit>3 or numdot!=1) return \"No\";\n return \"Yes\"; \n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "file_name_check"}
|
143 |
{"task_id": "CPP/142", "prompt": "/*\n\"\nThis function will take a vector of integers. For all entries in the vector, the function shall square the integer entry if its index is a \nmultiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not \nchange the entries in the vector whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. \n\nExamples:\nFor lst = {1,2,3} the output should be 6\nFor lst = {} the output should be 0\nFor lst = {-1,-5,2,-1,-5} the output should be -126\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nint sum_squares(vector<int> lst){\n", "canonical_solution": " int sum=0;\n for (int i=0;i<lst.size();i++)\n if (i%3==0) sum+=lst[i]*lst[i];\n else if (i%4==0) sum+=lst[i]*lst[i]*lst[i];\n else sum+=lst[i];\n return sum;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (sum_squares({1,2,3}) == 6);\n assert (sum_squares({1,4,9}) == 14);\n assert (sum_squares({}) == 0);\n assert (sum_squares({1,1,1,1,1,1,1,1,1}) == 9);\n assert (sum_squares({-1,-1,-1,-1,-1,-1,-1,-1,-1}) == -3);\n assert (sum_squares({0}) == 0);\n assert (sum_squares({-1,-5,2,-1,-5}) == -126);\n assert (sum_squares({-56,-99,1,0,-2}) == 3030);\n assert (sum_squares({-1,0,0,0,0,0,0,0,-1}) == 0);\n assert (sum_squares({-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37}) == -14196);\n assert (sum_squares({-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10}) == -1448);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint sum_squares(vector<int> lst){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (sum_squares({1,2,3}) == 6);\n assert (sum_squares({}) == 0);\n assert (sum_squares({-1,-5,2,-1,-5}) == -126);\n}\n", "buggy_solution": " int sum=0;\n for (int i=0;i<lst.size();i++)\n if (i%3==0) sum+=lst[i]*lst[i];\n else sum+=lst[i];\n return sum;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sum_squares"}
|
144 |
{"task_id": "CPP/143", "prompt": "/*\nYou are given a string representing a sentence,\nthe sentence contains some words separated by a space,\nand you have to return a string that contains the words from the original sentence,\nwhose lengths are prime numbers,\nthe order of the words in the new string should be the same as the original one.\n\nExample 1:\n Input: sentence = \"This is a test\"\n Output: \"is\"\n\nExample 2:\n Input: sentence = \"lets go for swimming\"\n Output: \"go for\"\n\nConstraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring words_in_sentence(string sentence){\n", "canonical_solution": " string out=\"\";\n string current=\"\";\n sentence=sentence+' ';\n\n for (int i=0;i<sentence.size();i++)\n if (sentence[i]!=' ') current=current+sentence[i];\n else\n {\n bool isp=true;\n int l=current.length();\n if (l<2) isp=false;\n for (int j=2;j*j<=l;j++)\n if (l%j==0) isp=false;\n if (isp) out=out+current+' ';\n current=\"\"; \n }\n if (out.length()>0)\n out.pop_back();\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (words_in_sentence(\"This is a test\") == \"is\");\n assert (words_in_sentence(\"lets go for swimming\") == \"go for\");\n assert (words_in_sentence(\"there is no place available here\") == \"there is no place\");\n assert (words_in_sentence(\"Hi I am Hussein\") == \"Hi am Hussein\");\n assert (words_in_sentence(\"go for it\") == \"go for it\");\n assert (words_in_sentence(\"here\") == \"\");\n assert (words_in_sentence(\"here is\") == \"is\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring words_in_sentence(string sentence){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (words_in_sentence(\"This is a test\") == \"is\");\n assert (words_in_sentence(\"lets go for swimming\") == \"go for\");\n}\n", "buggy_solution": " string out=\"\";\n string current=\"\";\n sentence=sentence+' ';\n\n for (int i=0;i<sentence.size();i++)\n if (sentence[i]!=' ') current=current+sentence[i];\n else\n {\n bool isp=true;\n int l=current.length();\n if (l<2) isp=false;\n for (int j=2;j*j<=l;j++)\n if (l%j==0) isp=false;\n if (isp) out=out+current+' ';\n current=\"\"; \n }\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "words_in_sentence"}
|
|
|
161 |
{"task_id": "CPP/160", "prompt": "/*\nGiven two vectors operator, and operand. The first vector has basic algebra operations, and \nthe second vector is a vector of integers. Use the two given vectors to build the algebric \nexpression and return the evaluation of this expression.\n\nThe basic algebra operations:\nAddition ( + ) \nSubtraction ( - ) \nMultiplication ( * ) \nFloor division ( // ) \nExponentiation ( ** ) \n\nExample:\noperator{\"+\", \"*\", \"-\"}\nvector = {2, 3, 4, 5}\nresult = 2 + 3 * 4 - 5\n=> result = 9\n\nNote:\n The length of operator vector is equal to the length of operand vector minus one.\n Operand is a vector of of non-negative integers.\n Operator vector has at least one operator, and operand vector has at least two operands.\n\n*/\n#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nint do_algebra(vector<string> operato, vector<int> operand){\n", "canonical_solution": " vector<int> num={};\n vector<int> posto={};\n for (int i=0;i<operand.size();i++)\n posto.push_back(i);\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"**\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n operand[posto[i]]=pow(operand[posto[i]],operand[posto[i+1]]);\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"*\" or operato[i]==\"//\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"*\")\n operand[posto[i]]=operand[posto[i]]*operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]/operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"+\" or operato[i]==\"-\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"+\")\n operand[posto[i]]=operand[posto[i]]+operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]-operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n return operand[0];\n\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (do_algebra({\"**\", \"*\", \"+\"}, {2, 3, 4, 5}) == 37);\n assert (do_algebra({\"+\", \"*\", \"-\"}, {2, 3, 4, 5}) == 9);\n assert (do_algebra({\"//\", \"*\"}, {7, 3, 4}) == 8);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nint do_algebra(vector<string> operato, vector<int> operand){\n", "example_test": "", "buggy_solution": " vector<int> num={};\n vector<int> posto={};\n for (int i=0;i<operand.size();i++)\n posto.push_back(i);\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"**\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n operand[posto[i]]=pow(operand[posto[i+1]],operand[posto[i+1]]);\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"*\" or operato[i]==\"//\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"*\")\n operand[posto[i]]=operand[posto[i]]*operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]/operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"+\" or operato[i]==\"-\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"+\")\n operand[posto[i]]=operand[posto[i]]+operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]-operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n return operand[0];\n\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "do_algebra"}
|
162 |
{"task_id": "CPP/161", "prompt": "/*\nYou are given a string s.\nif s[i] is a letter, reverse its case from lower to upper or vise versa, \notherwise keep it as it is.\nIf the string contains no letters, reverse the string.\nThe function should return the resulted string.\nExamples\nsolve(\"1234\") = \"4321\"\nsolve(\"ab\") = \"AB\"\nsolve(\"#a@C\") = \"#A@c\"\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring solve(string s){\n", "canonical_solution": " int nletter=0;\n string out=\"\";\n for (int i=0;i<s.length();i++)\n {\n char w=s[i];\n if (w>=65 and w<=90) w=w+32;\n else if (w>=97 and w<=122) w=w-32;\n else nletter+=1;\n out=out+w;\n }\n if (nletter==s.length())\n {\n string p(s.rbegin(),s.rend());\n return p;\n }\n else return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (solve(\"AsDf\") == \"aSdF\");\n assert (solve(\"1234\") == \"4321\");\n assert (solve(\"ab\") == \"AB\");\n assert (solve(\"#a@C\") == \"#A@c\");\n assert (solve(\"#AsdfW^45\") == \"#aSDFw^45\");\n assert (solve(\"#6@2\") == \"2@6#\");\n assert (solve(\"#$a^D\") == \"#$A^d\");\n assert (solve(\"#ccc\") == \"#CCC\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring solve(string s){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (solve(\"1234\") == \"4321\");\n assert (solve(\"ab\") == \"AB\");\n assert (solve(\"#a@C\") == \"#A@c\");\n}\n", "buggy_solution": " int nletter=0;\n string out=\"\";\n for (int i=0;i<s.length();i++)\n {\n char w=s[i];\n if (w>=65 and w<=90) w=w+32;\n else nletter+=1;\n out=out+w;\n }\n if (nletter==s.length())\n {\n string p(s.rbegin(),s.rend());\n return p;\n }\n else return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "solve"}
|
163 |
{"task_id": "CPP/162", "prompt": "/*\nGiven a string 'text\", return its md5 hash equivalent string.\nIf 'text\" is an empty string, return None.\n\n>>> string_to_md5(\"Hello world\") == \"3e25960a79dbc69b674cd4ec67a72c62\"\n*/\n#include<stdio.h>\n#include<string>\n#include<openssl/md5.h>\nusing namespace std;\nstring string_to_md5(string text){\n", "canonical_solution": " unsigned char md[16];\n if (text.length()==0) return \"None\";\n MD5_CTX c;\n int i;\n MD5_Init(&c);\n MD5_Update(&c, (unsigned char*)text.c_str(), text.length());\n MD5_Final(md, &c);\n string out_str=\"\";\n for (int i=0;i<16;i++)\n {\n char w;\n if (md[i]<160) w=48+md[i]/16;\n else w=87+md[i]/16;\n out_str=out_str+w;\n if (md[i]%16<10) w=48+md[i]%16;\n else w=87+md[i]%16;\n out_str=out_str+w;\n }\n return out_str;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (string_to_md5(\"Hello world\") == \"3e25960a79dbc69b674cd4ec67a72c62\");\n assert (string_to_md5(\"\") == \"None\");\n assert (string_to_md5(\"A B C\") == \"0ef78513b0cb8cef12743f5aeb35f888\");\n assert (string_to_md5(\"password\") == \"5f4dcc3b5aa765d61d8327deb882cf99\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\n#include<openssl/md5.h>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring string_to_md5(string text){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (string_to_md5(\"Hello world\") == \"3e25960a79dbc69b674cd4ec67a72c62\");\n}\n", "buggy_solution": " unsigned char md[16];\n if (text.length()==0) return \"None\";\n MD5_CTX c;\n int i;\n MD5_Init(&c);\n MD5_Update(&c, (unsigned char*)text.c_str(), text.length());\n MD5_Final(md, &c);\n string out_str=\"\";\n for (int i=0;i<16;i++)\n {\n char w;\n if (md[i]<160) w=48+md[i]/16;\n else w=87+md[i]/16;\n out_str=out_str+w;\n if (md[i]%16<87) w=48+md[i]%16;\n else w=48+md[i]%16;\n out_str=out_str+w;\n }\n return out_str;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "string_to_md5"}
|
164 |
+
{"task_id": "CPP/163", "prompt": "/*\nGiven two positive integers a and b, return the even digits between a\nand b, in ascending order.\n\nFor example:\ngenerate_integers(2, 8) => {2, 4, 6, 8}\ngenerate_integers(8, 2) => {2, 4, 6, 8}\ngenerate_integers(10, 14) => {}\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nvector<int> generate_integers(int a,int b){\n", "canonical_solution": " int m;\n if (b<a)\n {\n m=a;a=b;b=m;\n }\n\n vector<int> out={};\n for (int i=a;i<=b;i++)\n if (i<10 and i%2==0) out.push_back(i);\n return out;\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(generate_integers(2, 10) , {2, 4, 6, 8}));\n assert (issame(generate_integers(10, 2) , {2, 4, 6, 8}));\n assert (issame(generate_integers(132, 2) , {2, 4, 6, 8}));\n assert (issame(generate_integers(17,89) , {}));\n}\n", "declaration": "#include<stdio.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nvector<int> generate_integers(int a,int b){\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(generate_integers(2, 8) , {2, 4, 6, 8}));\n assert (issame(generate_integers(8, 2) , {2, 4, 6, 8}));\n assert (issame(generate_integers(10,14) , {}));\n}\n", "buggy_solution": " int m;\n if (b<a)\n {\n m=a;a=b;b=m;\n }\n\n vector<int> out={};\n for (int i=a;i<b;i++)\n if (i>10 and i%2==0) out.push_back(i);\n return out;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "generate_integers"}
|
data/go/data/humanevalbugs.jsonl
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
data/java/data/humanevalbugs.jsonl
CHANGED
@@ -37,7 +37,7 @@
|
|
37 |
{"task_id": "Java/36", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n >>> fizzBuzz(50)\n 0\n >>> fizzBuzz(78)\n 2\n >>> fizzBuzz(79)\n 3\n */\n public int fizzBuzz(int n) {\n", "canonical_solution": " int result = 0;\n for (int i = 1; i < n; i++) {\n if (i % 11 == 0 || i % 13 == 0) {\n char[] digits = String.valueOf(i).toCharArray();\n for (char c : digits) {\n if (c == '7') {\n result += 1;\n }\n }\n }\n }\n return result;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.fizzBuzz(50) == 0,\n s.fizzBuzz(78) == 2,\n s.fizzBuzz(79) == 3,\n s.fizzBuzz(100) == 3,\n s.fizzBuzz(200) == 6,\n s.fizzBuzz(4000) == 192,\n s.fizzBuzz(10000) == 639,\n s.fizzBuzz(100000) == 8026\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n >>> fizzBuzz(50)\n 0\n >>> fizzBuzz(78)\n 2\n >>> fizzBuzz(79)\n 3", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public int fizzBuzz(int n) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.fizzBuzz(50) == 0,\n s.fizzBuzz(78) == 2,\n s.fizzBuzz(79) == 3\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int result = 0;\n for (int i = 1; i < n; i++) {\n if (i % 11 == 0 && i % 13 == 0) {\n char[] digits = String.valueOf(i).toCharArray();\n for (char c : digits) {\n if (c == '7') {\n result += 1;\n }\n }\n }\n }\n return result;\n }\n}", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "FizzBuzz"}
|
38 |
{"task_id": "Java/37", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n This function takes a list l and returns a list l' such that\n l' is identical to l in the odd indicies, while its values at the even indicies are equal\n to the values of the even indicies of l, but sorted.\n >>> sortEven(Arrays.asList(1, 2, 3))\n [1, 2, 3]\n >>> sortEven(Arrays.asList(5, 6, 3, 4))\n [3, 6, 5, 4]\n */\n public List<Integer> sortEven(List<Integer> l) {\n", "canonical_solution": " List<Integer> even = new ArrayList<>();\n for (int i = 0; i < l.size(); i += 2) {\n even.add(l.get(i));\n }\n Collections.sort(even);\n List<Integer> result = l;\n for (int i = 0; i < l.size(); i += 2) {\n result.set(i, even.get(i / 2));\n }\n return result;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.sortEven(new ArrayList<>(Arrays.asList(1, 2, 3))).equals(Arrays.asList(1, 2, 3)),\n s.sortEven(new ArrayList<>(Arrays.asList(5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10))).equals(Arrays.asList(-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123)),\n s.sortEven(new ArrayList<>(Arrays.asList(5, 8, -12, 4, 23, 2, 3, 11, 12, -10))).equals(Arrays.asList(-12, 8, 3, 4, 5, 2, 12, 11, 23, -10))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " This function takes a list l and returns a list l' such that\n l' is identical to l in the odd indicies, while its values at the even indicies are equal\n to the values of the even indicies of l, but sorted.\n >>> sortEven(Arrays.asList(1, 2, 3))\n [1, 2, 3]\n >>> sortEven(Arrays.asList(5, 6, 3, 4))\n [3, 6, 5, 4]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> sortEven(List<Integer> l) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.sortEven(new ArrayList<>(Arrays.asList(1, 2, 3))).equals(Arrays.asList(1, 2, 3)),\n s.sortEven(new ArrayList<>(Arrays.asList(5,6,3,4))).equals(Arrays.asList(3,6,5,4))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<Integer> even = new ArrayList<>();\n for (int i = 0; i < l.size(); i += 2) {\n even.add(l.get(i));\n }\n Collections.sort(l);\n List<Integer> result = l;\n for (int i = 0; i < l.size(); i += 2) {\n result.set(i, even.get(i / 2));\n }\n return result;\n }\n}", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "SortEven"}
|
39 |
{"task_id": "Java/38", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n returns encoded string by cycling groups of three characters.\n */\n public String encodeCyclic(String s) {\n // split string to groups. Each of length 3.\n List<String> groups = new ArrayList<>();\n for (int i = 0; i < s.length(); i += 3) {\n groups.add(s.substring(i, Math.min(i + 3, s.length())));\n }\n // cycle elements in each group. Unless group has fewer elements than 3.\n for (int i = 0; i < groups.size(); i++) {\n if (groups.get(i).length() == 3) {\n groups.set(i, groups.get(i).substring(1) + groups.get(i).charAt(0));\n }\n }\n return String.join(\"\", groups);\n }\n\n /**\n takes as input string encoded with encodeCyclic function. Returns decoded string.\n */\n public String decodeCyclic(String s) {\n", "canonical_solution": " return encodeCyclic(encodeCyclic(s));\n }\n}", "test": "public class Main {\n static char[] letters = \"abcdefghijklmnopqrstuvwxyz\".toCharArray();\n static Random rand = new Random(42);\n public static String random_string(int length) {\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < length; i++) {\n sb.append(letters[rand.nextInt(26)]);\n }\n return sb.toString();\n }\n public static void main(String[] args) {\n Solution s = new Solution();\n for (int i = 0; i < 100; i++) {\n String str = random_string(rand.nextInt(10) + 10);\n String encode_str = s.encodeCyclic(str);\n if (!s.decodeCyclic(encode_str).equals(str)) {\n throw new AssertionError();\n }\n }\n }\n}", "text": " takes as input string encoded with encodeCyclic function. Returns decoded string.", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n returns encoded string by cycling groups of three characters.\n */\n public String encodeCyclic(String s) {\n // split string to groups. Each of length 3.\n List<String> groups = new ArrayList<>();\n for (int i = 0; i < s.length(); i += 3) {\n groups.add(s.substring(i, Math.min(i + 3, s.length())));\n }\n // cycle elements in each group. Unless group has fewer elements than 3.\n for (int i = 0; i < groups.size(); i++) {\n if (groups.get(i).length() == 3) {\n groups.set(i, groups.get(i).substring(1) + groups.get(i).charAt(0));\n }\n }\n return String.join(\"\", groups);\n }\n\n public String decodeCyclic(String s) {\n", "example_test": "", "buggy_solution": " return encodeCyclic(s);\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "DecodeCyclic"}
|
40 |
-
{"task_id": "Java/39", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n primeFib returns n-th number that is a Fibonacci number and it's also prime.\n >>> primeFib(1)\n 2\n >>> primeFib(2)\n 3\n >>> primeFib(3)\n 5\n >>> primeFib(4)\n 13\n >>> primeFib(5)\n 89\n */\n public int primeFib(int n) {\n", "canonical_solution": " int f0 = 0, f1 = 1;\n while (true) {\n int p = f0 + f1;\n boolean is_prime = p >= 2;\n for (int k = 2; k < Math.min(Math.sqrt(p) + 1, p - 1); k++) {\n if (p % k == 0) {\n is_prime = false;\n break;\n }\n }\n if (is_prime) {\n n -= 1;\n }\n if (n == 0) {\n return p;\n }\n f0 = f1;\n f1 = p;\n }\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.primeFib(1) == 2,\n s.primeFib(2) == 3,\n s.primeFib(3) == 5,\n s.primeFib(4) == 13,\n s.primeFib(5) == 89,\n s.primeFib(6) == 233,\n s.primeFib(7) == 1597,\n s.primeFib(8) == 28657,\n s.primeFib(9) == 514229,\n s.primeFib(10) == 433494437\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " primeFib returns n-th number that is a Fibonacci number and it's also prime.\n >>> primeFib(1)\n 2\n >>> primeFib(2)\n 3\n >>> primeFib(3)\n 5\n >>> primeFib(4)\n 13\n >>> primeFib(5)\n 89", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public int primeFib(int n) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.primeFib(1) == 2,\n s.primeFib(2) == 3,\n s.primeFib(3) == 5,\n s.primeFib(4) == 13,\n s.primeFib(5) == 89\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int f0 = 0, f1 =
|
41 |
{"task_id": "Java/40", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n triplesSumToZero takes a list of integers as an input.\n it returns True if there are three distinct elements in the list that\n sum to zero, and False otherwise.\n\n >>> triplesSumToZero(Arrays.asList(1, 3, 5, 0))\n false\n >>> triplesSumToZero(Arrays.asList(1, 3, -2, 1))\n true\n >>> triplesSumToZero(Arrays.asList(1, 2, 3, 7))\n false\n >>> triplesSumToZero(Arrays.asList(2, 4, -5, 3, 9, 7))\n true\n >>> triplesSumToZero(Arrays.asList(1))\n false\n */\n public boolean triplesSumToZero(List<Integer> l) {\n", "canonical_solution": " for (int i = 0; i < l.size(); i++) {\n for (int j = i + 1; j < l.size(); j++) {\n for (int k = j + 1; k < l.size(); k++) {\n if (l.get(i) + l.get(j) + l.get(k) == 0) {\n return true;\n }\n }\n }\n }\n return false;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 3, 5, 0))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 3, 5, -1))),\n s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 3, -2, 1))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 2, 3, 7))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 2, 5, 7))),\n s.triplesSumToZero(new ArrayList<>(Arrays.asList(2, 4, -5, 3, 9, 7))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 3, 5, -100))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(100, 3, 5, -100)))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " triplesSumToZero takes a list of integers as an input.\n it returns True if there are three distinct elements in the list that\n sum to zero, and False otherwise.\n\n >>> triplesSumToZero(Arrays.asList(1, 3, 5, 0))\n false\n >>> triplesSumToZero(Arrays.asList(1, 3, -2, 1))\n true\n >>> triplesSumToZero(Arrays.asList(1, 2, 3, 7))\n false\n >>> triplesSumToZero(Arrays.asList(2, 4, -5, 3, 9, 7))\n true\n >>> triplesSumToZero(Arrays.asList(1))\n false", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean triplesSumToZero(List<Integer> l) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 3, 5, 0))),\n s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 3, -2, 1))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 2, 3, 7))),\n s.triplesSumToZero(new ArrayList<>(Arrays.asList(2, 4, -5, 3, 9, 7)))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " for (int i = 1; i < l.size(); i++) {\n for (int j = i + 1; j < l.size(); j++) {\n for (int k = j + 1; k < l.size(); k++) {\n if (l.get(i) + l.get(j) + l.get(k) == 0) {\n return true;\n }\n }\n }\n }\n return false;\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "TriplesSumToZero"}
|
42 |
{"task_id": "Java/41", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Imagine a road that's a perfectly straight infinitely long line.\n n cars are driving left to right; simultaneously, a different set of n cars\n are driving right to left. The two sets of cars start out being very far from\n each other. All cars move in the same speed. Two cars are said to collide\n when a car that's moving left to right hits a car that's moving right to left.\n However, the cars are infinitely sturdy and strong; as a result, they continue moving\n in their trajectory as if they did not collide.\n\n This function outputs the number of such collisions.\n */\n public int carRaceCollision(int n) {\n", "canonical_solution": " return n * n;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.carRaceCollision(2) == 4,\n s.carRaceCollision(3) == 9,\n s.carRaceCollision(4) == 16,\n s.carRaceCollision(8) == 64,\n s.carRaceCollision(10) == 100\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Imagine a road that's a perfectly straight infinitely long line.\n n cars are driving left to right; simultaneously, a different set of n cars\n are driving right to left. The two sets of cars start out being very far from\n each other. All cars move in the same speed. Two cars are said to collide\n when a car that's moving left to right hits a car that's moving right to left.\n However, the cars are infinitely sturdy and strong; as a result, they continue moving\n in their trajectory as if they did not collide.\n\n This function outputs the number of such collisions.", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public int carRaceCollision(int n) {\n", "example_test": "", "buggy_solution": " return n * n * n;\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "CarRaceCollision"}
|
43 |
{"task_id": "Java/42", "prompt": "import java.util.*;\nimport java.lang.*;\nimport java.util.stream.Collectors;\n\nclass Solution {\n /**\n Return list with elements incremented by 1.\n >>> incrList(Arrays.asList(1, 2, 3))\n [2, 3, 4]\n >>> incrList(Arrays.asList(5, 3, 5, 2, 3, 3, 9, 0, 123))\n [6, 4, 6, 3, 4, 4, 10, 1, 124]\n */\n public List<Integer> incrList(List<Integer> l) {\n", "canonical_solution": " return l.stream().map(p -> p + 1).collect(Collectors.toList());\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.incrList(new ArrayList<>(Arrays.asList())).equals(List.of()),\n s.incrList(new ArrayList<>(Arrays.asList(3, 2, 1))).equals(Arrays.asList(4, 3, 2)),\n s.incrList(new ArrayList<>(Arrays.asList(5, 2, 5, 2, 3, 3, 9, 0, 123))).equals(Arrays.asList(6, 3, 6, 3, 4, 4, 10, 1, 124))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Return list with elements incremented by 1.\n >>> incrList(Arrays.asList(1, 2, 3))\n [2, 3, 4]\n >>> incrList(Arrays.asList(5, 3, 5, 2, 3, 3, 9, 0, 123))\n [6, 4, 6, 3, 4, 4, 10, 1, 124]", "declaration": "import java.util.*;\nimport java.lang.*;\nimport java.util.stream.Collectors;\n\nclass Solution {\n public List<Integer> incrList(List<Integer> l) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.incrList(new ArrayList<>(Arrays.asList(1, 2, 3))).equals(Arrays.asList(2, 3, 4)),\n s.incrList(new ArrayList<>(Arrays.asList(5, 2, 5, 2, 3, 3, 9, 0, 123))).equals(Arrays.asList(6, 3, 6, 3, 4, 4, 10, 1, 124))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " return l.stream().map(p -> p + 2).collect(Collectors.toList());\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IncrList"}
|
@@ -125,9 +125,9 @@
|
|
125 |
{"task_id": "Java/124", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You have to write a function which validates a given date string and\n returns true if the date is valid otherwise false.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example:\n validDate(\"03-11-2000\") => true\n validDate(\"15-01-2012\") => false\n validDate(\"04-0-2040\") => false\n validDate(\"06-04-2020\") => true\n validDate(\"06/04/2020\") => false\n */\n public boolean validDate(String date) {\n", "canonical_solution": " try {\n date = date.strip();\n String[] dates = date.split(\"-\" );\n String m = dates[0];\n while (!m.isEmpty() && m.charAt(0) == '0') {\n m = m.substring(1);\n }\n String d = dates[1];\n while (!d.isEmpty() && d.charAt(0) == '0') {\n d = d.substring(1);\n }\n String y = dates[2];\n while (!y.isEmpty() && y.charAt(0) == '0') {\n y = y.substring(1);\n }\n int month = Integer.parseInt(m), day = Integer.parseInt(d), year = Integer.parseInt(y);\n if (month < 1 || month > 12) {\n return false;\n }\n if (Arrays.asList(1, 3, 5, 7, 8, 10, 12).contains(month) && (day < 1 || day > 31)) {\n return false;\n }\n if (Arrays.asList(4, 6, 9, 11).contains(month) && (day < 1 || day > 30)) {\n return false;\n }\n if (month == 2 && (day < 1 || day > 29)) {\n return false;\n }\n return true;\n } catch (Exception e) {\n return false;\n }\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.validDate(\"03-11-2000\" ) == true,\n s.validDate(\"15-01-2012\" ) == false,\n s.validDate(\"04-0-2040\" ) == false,\n s.validDate(\"06-04-2020\" ) == true,\n s.validDate(\"01-01-2007\" ) == true,\n s.validDate(\"03-32-2011\" ) == false,\n s.validDate(\"\" ) == false,\n s.validDate(\"04-31-3000\" ) == false,\n s.validDate(\"06-06-2005\" ) == true,\n s.validDate(\"21-31-2000\" ) == false,\n s.validDate(\"04-12-2003\" ) == true,\n s.validDate(\"04122003\" ) == false,\n s.validDate(\"20030412\" ) == false,\n s.validDate(\"2003-04\" ) == false,\n s.validDate(\"2003-04-12\" ) == false,\n s.validDate(\"04-2003\" ) == false\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You have to write a function which validates a given date string and\n returns true if the date is valid otherwise false.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example:\n validDate(\"03-11-2000\") => true\n validDate(\"15-01-2012\") => false\n validDate(\"04-0-2040\") => false\n validDate(\"06-04-2020\") => true\n validDate(\"06/04/2020\") => false", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean validDate(String date) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.validDate(\"03-11-2000\" ) == true,\n s.validDate(\"15-01-2012\" ) == false,\n s.validDate(\"04-0-2040\" ) == false,\n s.validDate(\"06-04-2020\" ) == true,\n s.validDate(\"06/04/2020\" ) == false\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " try {\n date = date.strip();\n String[] dates = date.split(\"-\" );\n String m = dates[1];\n while (!m.isEmpty() && m.charAt(0) == '0') {\n m = m.substring(1);\n }\n String d = dates[0];\n while (!d.isEmpty() && d.charAt(0) == '0') {\n d = d.substring(1);\n }\n String y = dates[2];\n while (!y.isEmpty() && y.charAt(0) == '0') {\n y = y.substring(1);\n }\n int month = Integer.parseInt(m), day = Integer.parseInt(d), year = Integer.parseInt(y);\n if (month < 1 || month > 12) {\n return false;\n }\n if (Arrays.asList(1, 3, 5, 7, 8, 10, 12).contains(month) && (day < 1 || day > 31)) {\n return false;\n }\n if (Arrays.asList(4, 6, 9, 11).contains(month) && (day < 1 || day > 30)) {\n return false;\n }\n if (month == 2 && (day < 1 || day > 29)) {\n return false;\n }\n return true;\n } catch (Exception e) {\n return false;\n }\n }\n}", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "ValidDate"}
|
126 |
{"task_id": "Java/125", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n splitWords(\"Hello world!\") == [\"Hello\", \"world!\"]\n splitWords(\"Hello,world!\") == [\"Hello\", \"world!\"]\n splitWords(\"abcdef\") == 3\n */\n public Object splitWords(String txt) {\n", "canonical_solution": " if (txt.contains(\" \" )) {\n return Arrays.asList(txt.split(\" \" ));\n } else if (txt.contains(\",\" )) {\n return Arrays.asList(txt.split(\"[,\\s]\" ));\n } else {\n int count = 0;\n for (char c : txt.toCharArray()) {\n if (Character.isLowerCase(c) && (c - 'a') % 2 == 1) {\n count += 1;\n }\n }\n return count;\n }\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.splitWords(\"Hello world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"Hello,world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"Hello world,!\" ), Arrays.asList(\"Hello\", \"world,!\" )),\n Objects.equals(s.splitWords(\"Hello,Hello,world !\" ), Arrays.asList(\"Hello,Hello,world\", \"!\" )),\n Objects.equals(s.splitWords(\"abcdef\" ), 3),\n Objects.equals(s.splitWords(\"aaabb\" ), 2),\n Objects.equals(s.splitWords(\"aaaBb\" ), 1),\n Objects.equals(s.splitWords(\"\" ), 0)\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n splitWords(\"Hello world!\") == [\"Hello\", \"world!\"]\n splitWords(\"Hello,world!\") == [\"Hello\", \"world!\"]\n splitWords(\"abcdef\") == 3", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public Object splitWords(String txt) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.splitWords(\"Hello world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"Hello,world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"abcdef\" ), 3)\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " if (txt.contains(\" \" )) {\n return Arrays.asList(txt.split(\",\" ));\n } else if (txt.contains(\",\" )) {\n return Arrays.asList(txt.split(\"[,\\s]\" ));\n } else {\n int count = 0;\n for (char c : txt.toCharArray()) {\n if (Character.isLowerCase(c) && (c - 'a') % 2 == 1) {\n count += 1;\n }\n }\n return count;\n }\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "SplitWords"}
|
127 |
{"task_id": "Java/126", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n 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\n Examples\n isSorted(Arrays.asList(5)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5)) -> false\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6, 7)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5, 6, 7)) -> false\n isSorted(Arrays.asList(1, 2, 2, 3, 3, 4)) -> true\n isSorted(Arrays.asList(1, 2, 2, 2, 3, 4)) -> false\n */\n public boolean isSorted(List<Integer> lst) {\n", "canonical_solution": " List<Integer> sorted_lst = new ArrayList<>(lst);\n Collections.sort(sorted_lst);\n if (!lst.equals(sorted_lst)) {\n return false;\n }\n for (int i = 0; i < lst.size() - 2; i++) {\n if (lst.get(i) == lst.get(i + 1) && lst.get(i) == lst.get(i + 2)) {\n return false;\n }\n }\n return true;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.isSorted(new ArrayList<>(List.of(5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5, 6, 7))) == false,\n s.isSorted(new ArrayList<>(List.of())) == true,\n s.isSorted(new ArrayList<>(List.of(1))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(3, 2, 1))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 2, 3, 4))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 3, 3, 4))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 3, 3, 4))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4))) == true\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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\n Examples\n isSorted(Arrays.asList(5)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5)) -> false\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6, 7)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5, 6, 7)) -> false\n isSorted(Arrays.asList(1, 2, 2, 3, 3, 4)) -> true\n isSorted(Arrays.asList(1, 2, 2, 2, 3, 4)) -> false", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean isSorted(List<Integer> lst) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.isSorted(new ArrayList<>(List.of(5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5, 6, 7))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 2, 3, 4))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 3, 3, 4))) == true\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<Integer> sorted_lst = new ArrayList<>(lst);\n Collections.sort(sorted_lst);\n if (!lst.equals(sorted_lst)) {\n return false;\n }\n for (int i = 0; i < lst.size() - 2; i++) {\n if (lst.get(i) == lst.get(i + 1)) {\n return false;\n }\n }\n return true;\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "IsSorted"}
|
128 |
-
{"task_id": "Java/127", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n 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 */\n public String intersection(List<Integer> interval1, List<Integer> interval2) {\n", "canonical_solution": " int l = Math.max(interval1.get(0), interval2.get(0));\n int r = Math.min(interval1.get(1), interval2.get(1));\n int length = r - l;\n if (length <= 0) {\n return \"NO\";\n }\n if (length == 1) {\n return \"NO\";\n }\n if (length == 2) {\n return \"YES\";\n }\n for (int i = 2; i < length; i++) {\n if (length % i == 0) {\n return \"NO\";\n }\n }\n return \"YES\";\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(2, 3)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-1, 1), Arrays.asList(0, 4)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-3, -1), Arrays.asList(-5, 5)), \"YES\" ),\n Objects.equals(s.intersection(Arrays.asList(-2, 2), Arrays.asList(-4, 0)), \"YES\" ),\n Objects.equals(s.intersection(Arrays.asList(-11, 2), Arrays.asList(-1, -1)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(3, 5)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(1, 2)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-2, -2), Arrays.asList(-3, -2)), \"NO\" )\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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\"", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public String intersection(List<Integer> interval1, List<Integer> interval2) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(2, 3)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-1, 1), Arrays.asList(0, 4)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-3, -1), Arrays.asList(-5, 5)), \"YES\" )\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int l = Math.max(interval1.get(0), interval2.get(0));\n int r = Math.min(interval1.get(1), interval2.get(1));\n int length = r - l;\n if (length <= 0) {\n return \"NO\";\n }\n if (length == 1) {\n return \"NO\";\n }\n
|
129 |
{"task_id": "Java/128", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\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 None for empty arr.\n\n Example:\n >>> prodSigns(Arrays.asList(1, 2, 2, -4)) == -9\n >>> prodSigns(Arrays.asList(0, 1)) == 0\n >>> prodSigns(Arrays.asList()) == None\n */\n public Optional<Integer> prodSigns(List<Integer> arr) {\n", "canonical_solution": " if (arr.size() == 0) {\n return Optional.empty();\n }\n if (arr.contains(0)) {\n return Optional.of(0);\n }\n int prod = (int) (-2 * (arr.stream().filter(p -> p < 0).count() % 2) + 1);\n return Optional.of(prod * (arr.stream().map(Math::abs).reduce(Integer::sum)).get());\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.prodSigns(Arrays.asList(1, 2, 2, -4)).get() == -9,\n s.prodSigns(Arrays.asList(0, 1)).get() == 0,\n s.prodSigns(Arrays.asList(1, 1, 1, 2, 3, -1, 1)).get() == -10,\n s.prodSigns(List.of()).isEmpty(),\n s.prodSigns(Arrays.asList(2, 4,1, 2, -1, -1, 9)).get() == 20,\n s.prodSigns(Arrays.asList(-1, 1, -1, 1)).get() == 4,\n s.prodSigns(Arrays.asList(-1, 1, 1, 1)).get() == -4,\n s.prodSigns(Arrays.asList(-1, 1, 1, 0)).get() == 0\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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 None for empty arr.\n\n Example:\n >>> prodSigns(Arrays.asList(1, 2, 2, -4)) == -9\n >>> prodSigns(Arrays.asList(0, 1)) == 0\n >>> prodSigns(Arrays.asList()) == None", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public Optional<Integer> prodSigns(List<Integer> arr) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.prodSigns(Arrays.asList(1, 2, 2, -4)).get() == -9,\n s.prodSigns(Arrays.asList(0, 1)).get() == 0,\n s.prodSigns(List.of()).isEmpty()\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " if (arr.size() == 0) {\n return Optional.empty();\n }\n if (arr.contains(0)) {\n return Optional.of(0);\n }\n int prod = (int) (-2 * (arr.stream().filter(p -> p < 0).count() % 2) + 1 * 2);\n return Optional.of(prod * (arr.stream().map(Math::abs).reduce(Integer::sum)).get());\n }\n}", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "ProdSigns"}
|
130 |
-
{"task_id": "Java/129", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\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 */\n public List<Integer> minPath(List<List<Integer>> grid, int k) {\n", "canonical_solution": " int n = grid.size();\n int val = n * n + 1;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (grid.get(i).get(j) == 1) {\n List<Integer> temp = new ArrayList<>();\n if (i != 0) {\n temp.add(grid.get(i - 1).get(j));\n }\n if (j != 0) {\n temp.add(grid.get(i).get(j - 1));\n }\n if (i != n - 1) {\n temp.add(grid.get(i + 1).get(j));\n }\n if (j != n - 1) {\n temp.add(grid.get(i).get(j + 1));\n }\n val = Collections.min(temp);\n }\n }\n }\n List<Integer> ans = new ArrayList<>();\n for (int i = 0; i < k; i++) {\n if (i % 2 == 0) {\n ans.add(1);\n } else {\n ans.add(val);\n }\n }\n return ans;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.minPath(Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9)), 3).equals(Arrays.asList(1, 2, 1)),\n s.minPath(Arrays.asList(Arrays.asList(5, 9, 3), Arrays.asList(4, 1, 6), Arrays.asList(7, 8, 2)), 1).equals(List.of(1)),\n s.minPath(Arrays.asList(Arrays.asList(1, 2, 3, 4), Arrays.asList(5, 6, 7, 8), Arrays.asList(9, 10, 11, 12), Arrays.asList(13, 14, 15, 16)), 4).equals(Arrays.asList(1, 2, 1, 2)),\n s.minPath(Arrays.asList(Arrays.asList(6, 4, 13, 10), Arrays.asList(5, 7, 12, 1), Arrays.asList(3, 16, 11, 15), Arrays.asList(8, 14, 9, 2)), 7).equals(Arrays.asList(1, 10, 1, 10, 1, 10, 1)),\n s.minPath(Arrays.asList(Arrays.asList(8, 14, 9, 2), Arrays.asList(6, 4, 13, 15), Arrays.asList(5, 7, 1, 12), Arrays.asList(3, 10, 11, 16)), 5).equals(Arrays.asList(1, 7, 1, 7, 1)),\n s.minPath(Arrays.asList(Arrays.asList(11, 8, 7, 2), Arrays.asList(5, 16, 14, 4), Arrays.asList(9, 3, 15, 6), Arrays.asList(12, 13, 10, 1)), 9).equals(Arrays.asList(1, 6, 1, 6, 1, 6, 1, 6, 1)),\n s.minPath(Arrays.asList(Arrays.asList(12, 13, 10, 1), Arrays.asList(9, 3, 15, 6), Arrays.asList(5, 16, 14, 4), Arrays.asList(11, 8, 7, 2)), 12).equals(Arrays.asList(1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6)),\n s.minPath(Arrays.asList(Arrays.asList(2, 7, 4), Arrays.asList(3, 1, 5), Arrays.asList(6, 8, 9)), 8).equals(Arrays.asList(1, 3, 1, 3, 1, 3, 1, 3)),\n s.minPath(Arrays.asList(Arrays.asList(6, 1, 5), Arrays.asList(3, 8, 9), Arrays.asList(2, 7, 4)), 8).equals(Arrays.asList(1, 5, 1, 5, 1, 5, 1, 5)),\n s.minPath(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4)), 10).equals(Arrays.asList(1, 2, 1, 2, 1, 2, 1, 2, 1, 2)),\n s.minPath(Arrays.asList(Arrays.asList(1, 3), Arrays.asList(3, 2)), 10).equals(Arrays.asList(1, 3, 1, 3, 1, 3, 1, 3, 1, 3))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> minPath(List<List<Integer>> grid, int k) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.minPath(Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9)), 3).equals(Arrays.asList(1, 2, 1)),\n s.minPath(Arrays.asList(Arrays.asList(5, 9, 3), Arrays.asList(4, 1, 6), Arrays.asList(7, 8, 2)), 1).equals(List.of(1))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int n = grid.size();\n int val = n * n + 1;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (grid.get(i).get(j) == 1) {\n List<Integer> temp = new ArrayList<>();\n if (i != 0) {\n temp.add(grid.get(i).get(j));\n }\n if (j != 0) {\n temp.add(grid.get(i).get(j));\n }\n if (i != n - 1) {\n temp.add(grid.get(i).get(j));\n }\n if (j != n - 1) {\n temp.add(grid.get(i).get(j));\n }\n val = Collections.min(temp);\n }\n }\n }\n List<Integer> ans = new ArrayList<>();\n for (int i = 0; i < k; i++) {\n if (i
|
131 |
{"task_id": "Java/130", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n 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 */\n public List<Integer> tri(int n) {\n", "canonical_solution": " if (n == 0) {\n return List.of(1);\n }\n List<Integer> my_tri = new ArrayList<>(Arrays.asList(1, 3));\n for (int i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n my_tri.add(i / 2 + 1);\n } else {\n my_tri.add(my_tri.get(my_tri.size() - 1) + my_tri.get(my_tri.size() - 2) + (i + 3) / 2);\n }\n }\n return my_tri;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.tri(3).equals(Arrays.asList(1, 3, 2, 8)),\n s.tri(4).equals(Arrays.asList(1, 3, 2, 8, 3)),\n s.tri(5).equals(Arrays.asList(1, 3, 2, 8, 3, 15)),\n s.tri(6).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4)),\n s.tri(7).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24)),\n s.tri(8).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24, 5)),\n s.tri(9).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24, 5, 35)),\n s.tri(20).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24, 5, 35, 6, 48, 7, 63, 8, 80, 9, 99, 10, 120, 11)),\n s.tri(0).equals(List.of(1)),\n s.tri(1).equals(Arrays.asList(1, 3))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> tri(int n) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.tri(3).equals(Arrays.asList(1, 3, 2, 8))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " if (n == 0) {\n return List.of(1);\n }\n List<Integer> my_tri = new ArrayList<>(Arrays.asList(1, 3));\n for (int i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n my_tri.add(i / 2 + 1);\n } else {\n my_tri.add(my_tri.get(my_tri.size() - 1) + my_tri.get(my_tri.size() - 2) + i + (i + 3) / 2);\n }\n }\n return my_tri;\n }\n}", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Tri"}
|
132 |
{"task_id": "Java/131", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n 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 */\n public int digits(int n) {\n", "canonical_solution": " int product = 1, odd_count = 0;\n for (char digit : String.valueOf(n).toCharArray()) {\n int int_digit = digit - '0';\n if (int_digit % 2 == 1) {\n product *= int_digit;\n odd_count += 1;\n }\n }\n if (odd_count == 0) {\n return 0;\n } else {\n return product;\n }\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.digits(5) == 5,\n s.digits(54) == 5,\n s.digits(120) == 1,\n s.digits(5014) == 5,\n s.digits(98765) == 315,\n s.digits(5576543) == 2625\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public int digits(int n) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.digits(1) == 1,\n s.digits(4) == 0,\n s.digits(235) == 15\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int product = 1, odd_count = 0;\n for (char digit : String.valueOf(n).toCharArray()) {\n int int_digit = digit - '0';\n if (int_digit % 2 == 1) {\n product *= product*int_digit;\n odd_count += 1;\n }\n }\n if (odd_count == 0) {\n return 0;\n } else {\n return product;\n }\n }\n}", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Digits"}
|
133 |
{"task_id": "Java/132", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\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\n isNested(\"[[]]\") -> true\n isNested(\"[]]]]]]][[[[[]\") -> false\n isNested(\"[][]\") -> false\n isNested(\"[]\") -> false\n isNested(\"[[][]]\") -> true\n isNested(\"[[]][[\") -> true\n */\n public boolean isNested(String string) {\n", "canonical_solution": " List<Integer> opening_bracket_index = new ArrayList<>(), closing_bracket_index = new ArrayList<>();\n for (int i = 0; i < string.length(); i++) {\n if (string.charAt(i) == '[') {\n opening_bracket_index.add(i);\n } else {\n closing_bracket_index.add(i);\n }\n }\n Collections.reverse(closing_bracket_index);\n int i = 0, l = closing_bracket_index.size();\n for (int idx : opening_bracket_index) {\n if (i < l && idx < closing_bracket_index.get(i)) {\n i += 1;\n }\n }\n return i >= 2;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.isNested(\"[[]]\" ),\n !s.isNested(\"[]]]]]]][[[[[]\" ),\n !s.isNested(\"[][]\" ),\n !s.isNested(\"[]\" ),\n s.isNested(\"[[[[]]]]\" ),\n !s.isNested(\"[]]]]]]]]]]\" ),\n s.isNested(\"[][][[]]\" ),\n !s.isNested(\"[[]\" ),\n !s.isNested(\"[]]\" ),\n s.isNested(\"[[]][[\" ),\n s.isNested(\"[[][]]\" ),\n !s.isNested(\"\" ),\n !s.isNested(\"[[[[[[[[\" ),\n !s.isNested(\"]]]]]]]]\" )\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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\n isNested(\"[[]]\") -> true\n isNested(\"[]]]]]]][[[[[]\") -> false\n isNested(\"[][]\") -> false\n isNested(\"[]\") -> false\n isNested(\"[[][]]\") -> true\n isNested(\"[[]][[\") -> true", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean isNested(String string) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.isNested(\"[[]]\" ),\n !s.isNested(\"[]]]]]]][[[[[]\" ),\n !s.isNested(\"[][]\" ),\n !s.isNested(\"[]\" ),\n s.isNested(\"[[]][[\" ),\n s.isNested(\"[[][]]\" )\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<Integer> opening_bracket_index = new ArrayList<>(), closing_bracket_index = new ArrayList<>();\n for (int i = 0; i < string.length(); i++) {\n if (string.charAt(i) == '(') {\n opening_bracket_index.add(i);\n } else {\n closing_bracket_index.add(i);\n }\n }\n Collections.reverse(closing_bracket_index);\n int i = 0, l = closing_bracket_index.size();\n for (int idx : opening_bracket_index) {\n if (i < l && idx < closing_bracket_index.get(i)) {\n i += 1;\n }\n }\n return i >= 2;\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsNested"}
|
|
|
37 |
{"task_id": "Java/36", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n >>> fizzBuzz(50)\n 0\n >>> fizzBuzz(78)\n 2\n >>> fizzBuzz(79)\n 3\n */\n public int fizzBuzz(int n) {\n", "canonical_solution": " int result = 0;\n for (int i = 1; i < n; i++) {\n if (i % 11 == 0 || i % 13 == 0) {\n char[] digits = String.valueOf(i).toCharArray();\n for (char c : digits) {\n if (c == '7') {\n result += 1;\n }\n }\n }\n }\n return result;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.fizzBuzz(50) == 0,\n s.fizzBuzz(78) == 2,\n s.fizzBuzz(79) == 3,\n s.fizzBuzz(100) == 3,\n s.fizzBuzz(200) == 6,\n s.fizzBuzz(4000) == 192,\n s.fizzBuzz(10000) == 639,\n s.fizzBuzz(100000) == 8026\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n >>> fizzBuzz(50)\n 0\n >>> fizzBuzz(78)\n 2\n >>> fizzBuzz(79)\n 3", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public int fizzBuzz(int n) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.fizzBuzz(50) == 0,\n s.fizzBuzz(78) == 2,\n s.fizzBuzz(79) == 3\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int result = 0;\n for (int i = 1; i < n; i++) {\n if (i % 11 == 0 && i % 13 == 0) {\n char[] digits = String.valueOf(i).toCharArray();\n for (char c : digits) {\n if (c == '7') {\n result += 1;\n }\n }\n }\n }\n return result;\n }\n}", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "FizzBuzz"}
|
38 |
{"task_id": "Java/37", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n This function takes a list l and returns a list l' such that\n l' is identical to l in the odd indicies, while its values at the even indicies are equal\n to the values of the even indicies of l, but sorted.\n >>> sortEven(Arrays.asList(1, 2, 3))\n [1, 2, 3]\n >>> sortEven(Arrays.asList(5, 6, 3, 4))\n [3, 6, 5, 4]\n */\n public List<Integer> sortEven(List<Integer> l) {\n", "canonical_solution": " List<Integer> even = new ArrayList<>();\n for (int i = 0; i < l.size(); i += 2) {\n even.add(l.get(i));\n }\n Collections.sort(even);\n List<Integer> result = l;\n for (int i = 0; i < l.size(); i += 2) {\n result.set(i, even.get(i / 2));\n }\n return result;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.sortEven(new ArrayList<>(Arrays.asList(1, 2, 3))).equals(Arrays.asList(1, 2, 3)),\n s.sortEven(new ArrayList<>(Arrays.asList(5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10))).equals(Arrays.asList(-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123)),\n s.sortEven(new ArrayList<>(Arrays.asList(5, 8, -12, 4, 23, 2, 3, 11, 12, -10))).equals(Arrays.asList(-12, 8, 3, 4, 5, 2, 12, 11, 23, -10))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " This function takes a list l and returns a list l' such that\n l' is identical to l in the odd indicies, while its values at the even indicies are equal\n to the values of the even indicies of l, but sorted.\n >>> sortEven(Arrays.asList(1, 2, 3))\n [1, 2, 3]\n >>> sortEven(Arrays.asList(5, 6, 3, 4))\n [3, 6, 5, 4]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> sortEven(List<Integer> l) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.sortEven(new ArrayList<>(Arrays.asList(1, 2, 3))).equals(Arrays.asList(1, 2, 3)),\n s.sortEven(new ArrayList<>(Arrays.asList(5,6,3,4))).equals(Arrays.asList(3,6,5,4))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<Integer> even = new ArrayList<>();\n for (int i = 0; i < l.size(); i += 2) {\n even.add(l.get(i));\n }\n Collections.sort(l);\n List<Integer> result = l;\n for (int i = 0; i < l.size(); i += 2) {\n result.set(i, even.get(i / 2));\n }\n return result;\n }\n}", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "SortEven"}
|
39 |
{"task_id": "Java/38", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n returns encoded string by cycling groups of three characters.\n */\n public String encodeCyclic(String s) {\n // split string to groups. Each of length 3.\n List<String> groups = new ArrayList<>();\n for (int i = 0; i < s.length(); i += 3) {\n groups.add(s.substring(i, Math.min(i + 3, s.length())));\n }\n // cycle elements in each group. Unless group has fewer elements than 3.\n for (int i = 0; i < groups.size(); i++) {\n if (groups.get(i).length() == 3) {\n groups.set(i, groups.get(i).substring(1) + groups.get(i).charAt(0));\n }\n }\n return String.join(\"\", groups);\n }\n\n /**\n takes as input string encoded with encodeCyclic function. Returns decoded string.\n */\n public String decodeCyclic(String s) {\n", "canonical_solution": " return encodeCyclic(encodeCyclic(s));\n }\n}", "test": "public class Main {\n static char[] letters = \"abcdefghijklmnopqrstuvwxyz\".toCharArray();\n static Random rand = new Random(42);\n public static String random_string(int length) {\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < length; i++) {\n sb.append(letters[rand.nextInt(26)]);\n }\n return sb.toString();\n }\n public static void main(String[] args) {\n Solution s = new Solution();\n for (int i = 0; i < 100; i++) {\n String str = random_string(rand.nextInt(10) + 10);\n String encode_str = s.encodeCyclic(str);\n if (!s.decodeCyclic(encode_str).equals(str)) {\n throw new AssertionError();\n }\n }\n }\n}", "text": " takes as input string encoded with encodeCyclic function. Returns decoded string.", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n returns encoded string by cycling groups of three characters.\n */\n public String encodeCyclic(String s) {\n // split string to groups. Each of length 3.\n List<String> groups = new ArrayList<>();\n for (int i = 0; i < s.length(); i += 3) {\n groups.add(s.substring(i, Math.min(i + 3, s.length())));\n }\n // cycle elements in each group. Unless group has fewer elements than 3.\n for (int i = 0; i < groups.size(); i++) {\n if (groups.get(i).length() == 3) {\n groups.set(i, groups.get(i).substring(1) + groups.get(i).charAt(0));\n }\n }\n return String.join(\"\", groups);\n }\n\n public String decodeCyclic(String s) {\n", "example_test": "", "buggy_solution": " return encodeCyclic(s);\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "DecodeCyclic"}
|
40 |
+
{"task_id": "Java/39", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n primeFib returns n-th number that is a Fibonacci number and it's also prime.\n >>> primeFib(1)\n 2\n >>> primeFib(2)\n 3\n >>> primeFib(3)\n 5\n >>> primeFib(4)\n 13\n >>> primeFib(5)\n 89\n */\n public int primeFib(int n) {\n", "canonical_solution": " int f0 = 0, f1 = 1;\n while (true) {\n int p = f0 + f1;\n boolean is_prime = p >= 2;\n for (int k = 2; k < Math.min(Math.sqrt(p) + 1, p - 1); k++) {\n if (p % k == 0) {\n is_prime = false;\n break;\n }\n }\n if (is_prime) {\n n -= 1;\n }\n if (n == 0) {\n return p;\n }\n f0 = f1;\n f1 = p;\n }\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.primeFib(1) == 2,\n s.primeFib(2) == 3,\n s.primeFib(3) == 5,\n s.primeFib(4) == 13,\n s.primeFib(5) == 89,\n s.primeFib(6) == 233,\n s.primeFib(7) == 1597,\n s.primeFib(8) == 28657,\n s.primeFib(9) == 514229,\n s.primeFib(10) == 433494437\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " primeFib returns n-th number that is a Fibonacci number and it's also prime.\n >>> primeFib(1)\n 2\n >>> primeFib(2)\n 3\n >>> primeFib(3)\n 5\n >>> primeFib(4)\n 13\n >>> primeFib(5)\n 89", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public int primeFib(int n) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.primeFib(1) == 2,\n s.primeFib(2) == 3,\n s.primeFib(3) == 5,\n s.primeFib(4) == 13,\n s.primeFib(5) == 89\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int f0 = 0, f1 = 0;\n while (true) {\n int p = f0 + f1;\n boolean is_prime = p >= 2;\n for (int k = 2; k < Math.min(Math.sqrt(p), p); k++) {\n if (p % k == 0) {\n is_prime = false;\n break;\n }\n }\n if (is_prime) {\n n -= 1;\n }\n if (n == 0) {\n return p;\n }\n f0 = f1;\n f1 = p;\n }\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "PrimeFib"}
|
41 |
{"task_id": "Java/40", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n triplesSumToZero takes a list of integers as an input.\n it returns True if there are three distinct elements in the list that\n sum to zero, and False otherwise.\n\n >>> triplesSumToZero(Arrays.asList(1, 3, 5, 0))\n false\n >>> triplesSumToZero(Arrays.asList(1, 3, -2, 1))\n true\n >>> triplesSumToZero(Arrays.asList(1, 2, 3, 7))\n false\n >>> triplesSumToZero(Arrays.asList(2, 4, -5, 3, 9, 7))\n true\n >>> triplesSumToZero(Arrays.asList(1))\n false\n */\n public boolean triplesSumToZero(List<Integer> l) {\n", "canonical_solution": " for (int i = 0; i < l.size(); i++) {\n for (int j = i + 1; j < l.size(); j++) {\n for (int k = j + 1; k < l.size(); k++) {\n if (l.get(i) + l.get(j) + l.get(k) == 0) {\n return true;\n }\n }\n }\n }\n return false;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 3, 5, 0))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 3, 5, -1))),\n s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 3, -2, 1))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 2, 3, 7))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 2, 5, 7))),\n s.triplesSumToZero(new ArrayList<>(Arrays.asList(2, 4, -5, 3, 9, 7))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 3, 5, -100))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(100, 3, 5, -100)))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " triplesSumToZero takes a list of integers as an input.\n it returns True if there are three distinct elements in the list that\n sum to zero, and False otherwise.\n\n >>> triplesSumToZero(Arrays.asList(1, 3, 5, 0))\n false\n >>> triplesSumToZero(Arrays.asList(1, 3, -2, 1))\n true\n >>> triplesSumToZero(Arrays.asList(1, 2, 3, 7))\n false\n >>> triplesSumToZero(Arrays.asList(2, 4, -5, 3, 9, 7))\n true\n >>> triplesSumToZero(Arrays.asList(1))\n false", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean triplesSumToZero(List<Integer> l) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 3, 5, 0))),\n s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 3, -2, 1))),\n !s.triplesSumToZero(new ArrayList<>(Arrays.asList(1, 2, 3, 7))),\n s.triplesSumToZero(new ArrayList<>(Arrays.asList(2, 4, -5, 3, 9, 7)))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " for (int i = 1; i < l.size(); i++) {\n for (int j = i + 1; j < l.size(); j++) {\n for (int k = j + 1; k < l.size(); k++) {\n if (l.get(i) + l.get(j) + l.get(k) == 0) {\n return true;\n }\n }\n }\n }\n return false;\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "TriplesSumToZero"}
|
42 |
{"task_id": "Java/41", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Imagine a road that's a perfectly straight infinitely long line.\n n cars are driving left to right; simultaneously, a different set of n cars\n are driving right to left. The two sets of cars start out being very far from\n each other. All cars move in the same speed. Two cars are said to collide\n when a car that's moving left to right hits a car that's moving right to left.\n However, the cars are infinitely sturdy and strong; as a result, they continue moving\n in their trajectory as if they did not collide.\n\n This function outputs the number of such collisions.\n */\n public int carRaceCollision(int n) {\n", "canonical_solution": " return n * n;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.carRaceCollision(2) == 4,\n s.carRaceCollision(3) == 9,\n s.carRaceCollision(4) == 16,\n s.carRaceCollision(8) == 64,\n s.carRaceCollision(10) == 100\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Imagine a road that's a perfectly straight infinitely long line.\n n cars are driving left to right; simultaneously, a different set of n cars\n are driving right to left. The two sets of cars start out being very far from\n each other. All cars move in the same speed. Two cars are said to collide\n when a car that's moving left to right hits a car that's moving right to left.\n However, the cars are infinitely sturdy and strong; as a result, they continue moving\n in their trajectory as if they did not collide.\n\n This function outputs the number of such collisions.", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public int carRaceCollision(int n) {\n", "example_test": "", "buggy_solution": " return n * n * n;\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "CarRaceCollision"}
|
43 |
{"task_id": "Java/42", "prompt": "import java.util.*;\nimport java.lang.*;\nimport java.util.stream.Collectors;\n\nclass Solution {\n /**\n Return list with elements incremented by 1.\n >>> incrList(Arrays.asList(1, 2, 3))\n [2, 3, 4]\n >>> incrList(Arrays.asList(5, 3, 5, 2, 3, 3, 9, 0, 123))\n [6, 4, 6, 3, 4, 4, 10, 1, 124]\n */\n public List<Integer> incrList(List<Integer> l) {\n", "canonical_solution": " return l.stream().map(p -> p + 1).collect(Collectors.toList());\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.incrList(new ArrayList<>(Arrays.asList())).equals(List.of()),\n s.incrList(new ArrayList<>(Arrays.asList(3, 2, 1))).equals(Arrays.asList(4, 3, 2)),\n s.incrList(new ArrayList<>(Arrays.asList(5, 2, 5, 2, 3, 3, 9, 0, 123))).equals(Arrays.asList(6, 3, 6, 3, 4, 4, 10, 1, 124))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Return list with elements incremented by 1.\n >>> incrList(Arrays.asList(1, 2, 3))\n [2, 3, 4]\n >>> incrList(Arrays.asList(5, 3, 5, 2, 3, 3, 9, 0, 123))\n [6, 4, 6, 3, 4, 4, 10, 1, 124]", "declaration": "import java.util.*;\nimport java.lang.*;\nimport java.util.stream.Collectors;\n\nclass Solution {\n public List<Integer> incrList(List<Integer> l) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.incrList(new ArrayList<>(Arrays.asList(1, 2, 3))).equals(Arrays.asList(2, 3, 4)),\n s.incrList(new ArrayList<>(Arrays.asList(5, 2, 5, 2, 3, 3, 9, 0, 123))).equals(Arrays.asList(6, 3, 6, 3, 4, 4, 10, 1, 124))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " return l.stream().map(p -> p + 2).collect(Collectors.toList());\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IncrList"}
|
|
|
125 |
{"task_id": "Java/124", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You have to write a function which validates a given date string and\n returns true if the date is valid otherwise false.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example:\n validDate(\"03-11-2000\") => true\n validDate(\"15-01-2012\") => false\n validDate(\"04-0-2040\") => false\n validDate(\"06-04-2020\") => true\n validDate(\"06/04/2020\") => false\n */\n public boolean validDate(String date) {\n", "canonical_solution": " try {\n date = date.strip();\n String[] dates = date.split(\"-\" );\n String m = dates[0];\n while (!m.isEmpty() && m.charAt(0) == '0') {\n m = m.substring(1);\n }\n String d = dates[1];\n while (!d.isEmpty() && d.charAt(0) == '0') {\n d = d.substring(1);\n }\n String y = dates[2];\n while (!y.isEmpty() && y.charAt(0) == '0') {\n y = y.substring(1);\n }\n int month = Integer.parseInt(m), day = Integer.parseInt(d), year = Integer.parseInt(y);\n if (month < 1 || month > 12) {\n return false;\n }\n if (Arrays.asList(1, 3, 5, 7, 8, 10, 12).contains(month) && (day < 1 || day > 31)) {\n return false;\n }\n if (Arrays.asList(4, 6, 9, 11).contains(month) && (day < 1 || day > 30)) {\n return false;\n }\n if (month == 2 && (day < 1 || day > 29)) {\n return false;\n }\n return true;\n } catch (Exception e) {\n return false;\n }\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.validDate(\"03-11-2000\" ) == true,\n s.validDate(\"15-01-2012\" ) == false,\n s.validDate(\"04-0-2040\" ) == false,\n s.validDate(\"06-04-2020\" ) == true,\n s.validDate(\"01-01-2007\" ) == true,\n s.validDate(\"03-32-2011\" ) == false,\n s.validDate(\"\" ) == false,\n s.validDate(\"04-31-3000\" ) == false,\n s.validDate(\"06-06-2005\" ) == true,\n s.validDate(\"21-31-2000\" ) == false,\n s.validDate(\"04-12-2003\" ) == true,\n s.validDate(\"04122003\" ) == false,\n s.validDate(\"20030412\" ) == false,\n s.validDate(\"2003-04\" ) == false,\n s.validDate(\"2003-04-12\" ) == false,\n s.validDate(\"04-2003\" ) == false\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You have to write a function which validates a given date string and\n returns true if the date is valid otherwise false.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example:\n validDate(\"03-11-2000\") => true\n validDate(\"15-01-2012\") => false\n validDate(\"04-0-2040\") => false\n validDate(\"06-04-2020\") => true\n validDate(\"06/04/2020\") => false", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean validDate(String date) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.validDate(\"03-11-2000\" ) == true,\n s.validDate(\"15-01-2012\" ) == false,\n s.validDate(\"04-0-2040\" ) == false,\n s.validDate(\"06-04-2020\" ) == true,\n s.validDate(\"06/04/2020\" ) == false\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " try {\n date = date.strip();\n String[] dates = date.split(\"-\" );\n String m = dates[1];\n while (!m.isEmpty() && m.charAt(0) == '0') {\n m = m.substring(1);\n }\n String d = dates[0];\n while (!d.isEmpty() && d.charAt(0) == '0') {\n d = d.substring(1);\n }\n String y = dates[2];\n while (!y.isEmpty() && y.charAt(0) == '0') {\n y = y.substring(1);\n }\n int month = Integer.parseInt(m), day = Integer.parseInt(d), year = Integer.parseInt(y);\n if (month < 1 || month > 12) {\n return false;\n }\n if (Arrays.asList(1, 3, 5, 7, 8, 10, 12).contains(month) && (day < 1 || day > 31)) {\n return false;\n }\n if (Arrays.asList(4, 6, 9, 11).contains(month) && (day < 1 || day > 30)) {\n return false;\n }\n if (month == 2 && (day < 1 || day > 29)) {\n return false;\n }\n return true;\n } catch (Exception e) {\n return false;\n }\n }\n}", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "ValidDate"}
|
126 |
{"task_id": "Java/125", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n splitWords(\"Hello world!\") == [\"Hello\", \"world!\"]\n splitWords(\"Hello,world!\") == [\"Hello\", \"world!\"]\n splitWords(\"abcdef\") == 3\n */\n public Object splitWords(String txt) {\n", "canonical_solution": " if (txt.contains(\" \" )) {\n return Arrays.asList(txt.split(\" \" ));\n } else if (txt.contains(\",\" )) {\n return Arrays.asList(txt.split(\"[,\\s]\" ));\n } else {\n int count = 0;\n for (char c : txt.toCharArray()) {\n if (Character.isLowerCase(c) && (c - 'a') % 2 == 1) {\n count += 1;\n }\n }\n return count;\n }\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.splitWords(\"Hello world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"Hello,world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"Hello world,!\" ), Arrays.asList(\"Hello\", \"world,!\" )),\n Objects.equals(s.splitWords(\"Hello,Hello,world !\" ), Arrays.asList(\"Hello,Hello,world\", \"!\" )),\n Objects.equals(s.splitWords(\"abcdef\" ), 3),\n Objects.equals(s.splitWords(\"aaabb\" ), 2),\n Objects.equals(s.splitWords(\"aaaBb\" ), 1),\n Objects.equals(s.splitWords(\"\" ), 0)\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n splitWords(\"Hello world!\") == [\"Hello\", \"world!\"]\n splitWords(\"Hello,world!\") == [\"Hello\", \"world!\"]\n splitWords(\"abcdef\") == 3", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public Object splitWords(String txt) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.splitWords(\"Hello world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"Hello,world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"abcdef\" ), 3)\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " if (txt.contains(\" \" )) {\n return Arrays.asList(txt.split(\",\" ));\n } else if (txt.contains(\",\" )) {\n return Arrays.asList(txt.split(\"[,\\s]\" ));\n } else {\n int count = 0;\n for (char c : txt.toCharArray()) {\n if (Character.isLowerCase(c) && (c - 'a') % 2 == 1) {\n count += 1;\n }\n }\n return count;\n }\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "SplitWords"}
|
127 |
{"task_id": "Java/126", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n 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\n Examples\n isSorted(Arrays.asList(5)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5)) -> false\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6, 7)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5, 6, 7)) -> false\n isSorted(Arrays.asList(1, 2, 2, 3, 3, 4)) -> true\n isSorted(Arrays.asList(1, 2, 2, 2, 3, 4)) -> false\n */\n public boolean isSorted(List<Integer> lst) {\n", "canonical_solution": " List<Integer> sorted_lst = new ArrayList<>(lst);\n Collections.sort(sorted_lst);\n if (!lst.equals(sorted_lst)) {\n return false;\n }\n for (int i = 0; i < lst.size() - 2; i++) {\n if (lst.get(i) == lst.get(i + 1) && lst.get(i) == lst.get(i + 2)) {\n return false;\n }\n }\n return true;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.isSorted(new ArrayList<>(List.of(5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5, 6, 7))) == false,\n s.isSorted(new ArrayList<>(List.of())) == true,\n s.isSorted(new ArrayList<>(List.of(1))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(3, 2, 1))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 2, 3, 4))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 3, 3, 4))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 3, 3, 4))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4))) == true\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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\n Examples\n isSorted(Arrays.asList(5)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5)) -> false\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6, 7)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5, 6, 7)) -> false\n isSorted(Arrays.asList(1, 2, 2, 3, 3, 4)) -> true\n isSorted(Arrays.asList(1, 2, 2, 2, 3, 4)) -> false", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean isSorted(List<Integer> lst) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.isSorted(new ArrayList<>(List.of(5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5, 6, 7))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 2, 3, 4))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 3, 3, 4))) == true\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<Integer> sorted_lst = new ArrayList<>(lst);\n Collections.sort(sorted_lst);\n if (!lst.equals(sorted_lst)) {\n return false;\n }\n for (int i = 0; i < lst.size() - 2; i++) {\n if (lst.get(i) == lst.get(i + 1)) {\n return false;\n }\n }\n return true;\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "IsSorted"}
|
128 |
+
{"task_id": "Java/127", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n 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 */\n public String intersection(List<Integer> interval1, List<Integer> interval2) {\n", "canonical_solution": " int l = Math.max(interval1.get(0), interval2.get(0));\n int r = Math.min(interval1.get(1), interval2.get(1));\n int length = r - l;\n if (length <= 0) {\n return \"NO\";\n }\n if (length == 1) {\n return \"NO\";\n }\n if (length == 2) {\n return \"YES\";\n }\n for (int i = 2; i < length; i++) {\n if (length % i == 0) {\n return \"NO\";\n }\n }\n return \"YES\";\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(2, 3)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-1, 1), Arrays.asList(0, 4)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-3, -1), Arrays.asList(-5, 5)), \"YES\" ),\n Objects.equals(s.intersection(Arrays.asList(-2, 2), Arrays.asList(-4, 0)), \"YES\" ),\n Objects.equals(s.intersection(Arrays.asList(-11, 2), Arrays.asList(-1, -1)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(3, 5)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(1, 2)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-2, -2), Arrays.asList(-3, -2)), \"NO\" )\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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\"", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public String intersection(List<Integer> interval1, List<Integer> interval2) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(2, 3)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-1, 1), Arrays.asList(0, 4)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-3, -1), Arrays.asList(-5, 5)), \"YES\" )\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int l = Math.max(interval1.get(0), interval2.get(0));\n int r = Math.min(interval1.get(1), interval2.get(1));\n int length = r - l;\n if (length <= 0) {\n return \"NO\";\n }\n if (length == 1) {\n return \"NO\";\n }\n return \"YES\";\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Intersection"}
|
129 |
{"task_id": "Java/128", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\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 None for empty arr.\n\n Example:\n >>> prodSigns(Arrays.asList(1, 2, 2, -4)) == -9\n >>> prodSigns(Arrays.asList(0, 1)) == 0\n >>> prodSigns(Arrays.asList()) == None\n */\n public Optional<Integer> prodSigns(List<Integer> arr) {\n", "canonical_solution": " if (arr.size() == 0) {\n return Optional.empty();\n }\n if (arr.contains(0)) {\n return Optional.of(0);\n }\n int prod = (int) (-2 * (arr.stream().filter(p -> p < 0).count() % 2) + 1);\n return Optional.of(prod * (arr.stream().map(Math::abs).reduce(Integer::sum)).get());\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.prodSigns(Arrays.asList(1, 2, 2, -4)).get() == -9,\n s.prodSigns(Arrays.asList(0, 1)).get() == 0,\n s.prodSigns(Arrays.asList(1, 1, 1, 2, 3, -1, 1)).get() == -10,\n s.prodSigns(List.of()).isEmpty(),\n s.prodSigns(Arrays.asList(2, 4,1, 2, -1, -1, 9)).get() == 20,\n s.prodSigns(Arrays.asList(-1, 1, -1, 1)).get() == 4,\n s.prodSigns(Arrays.asList(-1, 1, 1, 1)).get() == -4,\n s.prodSigns(Arrays.asList(-1, 1, 1, 0)).get() == 0\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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 None for empty arr.\n\n Example:\n >>> prodSigns(Arrays.asList(1, 2, 2, -4)) == -9\n >>> prodSigns(Arrays.asList(0, 1)) == 0\n >>> prodSigns(Arrays.asList()) == None", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public Optional<Integer> prodSigns(List<Integer> arr) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.prodSigns(Arrays.asList(1, 2, 2, -4)).get() == -9,\n s.prodSigns(Arrays.asList(0, 1)).get() == 0,\n s.prodSigns(List.of()).isEmpty()\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " if (arr.size() == 0) {\n return Optional.empty();\n }\n if (arr.contains(0)) {\n return Optional.of(0);\n }\n int prod = (int) (-2 * (arr.stream().filter(p -> p < 0).count() % 2) + 1 * 2);\n return Optional.of(prod * (arr.stream().map(Math::abs).reduce(Integer::sum)).get());\n }\n}", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "ProdSigns"}
|
130 |
+
{"task_id": "Java/129", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\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 */\n public List<Integer> minPath(List<List<Integer>> grid, int k) {\n", "canonical_solution": " int n = grid.size();\n int val = n * n + 1;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (grid.get(i).get(j) == 1) {\n List<Integer> temp = new ArrayList<>();\n if (i != 0) {\n temp.add(grid.get(i - 1).get(j));\n }\n if (j != 0) {\n temp.add(grid.get(i).get(j - 1));\n }\n if (i != n - 1) {\n temp.add(grid.get(i + 1).get(j));\n }\n if (j != n - 1) {\n temp.add(grid.get(i).get(j + 1));\n }\n val = Collections.min(temp);\n }\n }\n }\n List<Integer> ans = new ArrayList<>();\n for (int i = 0; i < k; i++) {\n if (i % 2 == 0) {\n ans.add(1);\n } else {\n ans.add(val);\n }\n }\n return ans;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.minPath(Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9)), 3).equals(Arrays.asList(1, 2, 1)),\n s.minPath(Arrays.asList(Arrays.asList(5, 9, 3), Arrays.asList(4, 1, 6), Arrays.asList(7, 8, 2)), 1).equals(List.of(1)),\n s.minPath(Arrays.asList(Arrays.asList(1, 2, 3, 4), Arrays.asList(5, 6, 7, 8), Arrays.asList(9, 10, 11, 12), Arrays.asList(13, 14, 15, 16)), 4).equals(Arrays.asList(1, 2, 1, 2)),\n s.minPath(Arrays.asList(Arrays.asList(6, 4, 13, 10), Arrays.asList(5, 7, 12, 1), Arrays.asList(3, 16, 11, 15), Arrays.asList(8, 14, 9, 2)), 7).equals(Arrays.asList(1, 10, 1, 10, 1, 10, 1)),\n s.minPath(Arrays.asList(Arrays.asList(8, 14, 9, 2), Arrays.asList(6, 4, 13, 15), Arrays.asList(5, 7, 1, 12), Arrays.asList(3, 10, 11, 16)), 5).equals(Arrays.asList(1, 7, 1, 7, 1)),\n s.minPath(Arrays.asList(Arrays.asList(11, 8, 7, 2), Arrays.asList(5, 16, 14, 4), Arrays.asList(9, 3, 15, 6), Arrays.asList(12, 13, 10, 1)), 9).equals(Arrays.asList(1, 6, 1, 6, 1, 6, 1, 6, 1)),\n s.minPath(Arrays.asList(Arrays.asList(12, 13, 10, 1), Arrays.asList(9, 3, 15, 6), Arrays.asList(5, 16, 14, 4), Arrays.asList(11, 8, 7, 2)), 12).equals(Arrays.asList(1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6)),\n s.minPath(Arrays.asList(Arrays.asList(2, 7, 4), Arrays.asList(3, 1, 5), Arrays.asList(6, 8, 9)), 8).equals(Arrays.asList(1, 3, 1, 3, 1, 3, 1, 3)),\n s.minPath(Arrays.asList(Arrays.asList(6, 1, 5), Arrays.asList(3, 8, 9), Arrays.asList(2, 7, 4)), 8).equals(Arrays.asList(1, 5, 1, 5, 1, 5, 1, 5)),\n s.minPath(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4)), 10).equals(Arrays.asList(1, 2, 1, 2, 1, 2, 1, 2, 1, 2)),\n s.minPath(Arrays.asList(Arrays.asList(1, 3), Arrays.asList(3, 2)), 10).equals(Arrays.asList(1, 3, 1, 3, 1, 3, 1, 3, 1, 3))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> minPath(List<List<Integer>> grid, int k) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.minPath(Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9)), 3).equals(Arrays.asList(1, 2, 1)),\n s.minPath(Arrays.asList(Arrays.asList(5, 9, 3), Arrays.asList(4, 1, 6), Arrays.asList(7, 8, 2)), 1).equals(List.of(1))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int n = grid.size();\n int val = n * n + 1;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (grid.get(i).get(j) == 1) {\n List<Integer> temp = new ArrayList<>();\n if (i != 0) {\n temp.add(grid.get(i).get(j));\n }\n if (j != 0) {\n temp.add(grid.get(i).get(j));\n }\n if (i != n - 1) {\n temp.add(grid.get(i).get(j));\n }\n if (j != n - 1) {\n temp.add(grid.get(i).get(j));\n }\n val = Collections.min(temp);\n }\n }\n }\n List<Integer> ans = new ArrayList<>();\n for (int i = 0; i < k; i++) {\n if (i == 0) {\n ans.add(1);\n } else {\n ans.add(val);\n }\n }\n return ans;\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Minpath"}
|
131 |
{"task_id": "Java/130", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n 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 */\n public List<Integer> tri(int n) {\n", "canonical_solution": " if (n == 0) {\n return List.of(1);\n }\n List<Integer> my_tri = new ArrayList<>(Arrays.asList(1, 3));\n for (int i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n my_tri.add(i / 2 + 1);\n } else {\n my_tri.add(my_tri.get(my_tri.size() - 1) + my_tri.get(my_tri.size() - 2) + (i + 3) / 2);\n }\n }\n return my_tri;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.tri(3).equals(Arrays.asList(1, 3, 2, 8)),\n s.tri(4).equals(Arrays.asList(1, 3, 2, 8, 3)),\n s.tri(5).equals(Arrays.asList(1, 3, 2, 8, 3, 15)),\n s.tri(6).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4)),\n s.tri(7).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24)),\n s.tri(8).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24, 5)),\n s.tri(9).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24, 5, 35)),\n s.tri(20).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24, 5, 35, 6, 48, 7, 63, 8, 80, 9, 99, 10, 120, 11)),\n s.tri(0).equals(List.of(1)),\n s.tri(1).equals(Arrays.asList(1, 3))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> tri(int n) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.tri(3).equals(Arrays.asList(1, 3, 2, 8))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " if (n == 0) {\n return List.of(1);\n }\n List<Integer> my_tri = new ArrayList<>(Arrays.asList(1, 3));\n for (int i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n my_tri.add(i / 2 + 1);\n } else {\n my_tri.add(my_tri.get(my_tri.size() - 1) + my_tri.get(my_tri.size() - 2) + i + (i + 3) / 2);\n }\n }\n return my_tri;\n }\n}", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Tri"}
|
132 |
{"task_id": "Java/131", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n 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 */\n public int digits(int n) {\n", "canonical_solution": " int product = 1, odd_count = 0;\n for (char digit : String.valueOf(n).toCharArray()) {\n int int_digit = digit - '0';\n if (int_digit % 2 == 1) {\n product *= int_digit;\n odd_count += 1;\n }\n }\n if (odd_count == 0) {\n return 0;\n } else {\n return product;\n }\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.digits(5) == 5,\n s.digits(54) == 5,\n s.digits(120) == 1,\n s.digits(5014) == 5,\n s.digits(98765) == 315,\n s.digits(5576543) == 2625\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public int digits(int n) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.digits(1) == 1,\n s.digits(4) == 0,\n s.digits(235) == 15\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int product = 1, odd_count = 0;\n for (char digit : String.valueOf(n).toCharArray()) {\n int int_digit = digit - '0';\n if (int_digit % 2 == 1) {\n product *= product*int_digit;\n odd_count += 1;\n }\n }\n if (odd_count == 0) {\n return 0;\n } else {\n return product;\n }\n }\n}", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Digits"}
|
133 |
{"task_id": "Java/132", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\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\n isNested(\"[[]]\") -> true\n isNested(\"[]]]]]]][[[[[]\") -> false\n isNested(\"[][]\") -> false\n isNested(\"[]\") -> false\n isNested(\"[[][]]\") -> true\n isNested(\"[[]][[\") -> true\n */\n public boolean isNested(String string) {\n", "canonical_solution": " List<Integer> opening_bracket_index = new ArrayList<>(), closing_bracket_index = new ArrayList<>();\n for (int i = 0; i < string.length(); i++) {\n if (string.charAt(i) == '[') {\n opening_bracket_index.add(i);\n } else {\n closing_bracket_index.add(i);\n }\n }\n Collections.reverse(closing_bracket_index);\n int i = 0, l = closing_bracket_index.size();\n for (int idx : opening_bracket_index) {\n if (i < l && idx < closing_bracket_index.get(i)) {\n i += 1;\n }\n }\n return i >= 2;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.isNested(\"[[]]\" ),\n !s.isNested(\"[]]]]]]][[[[[]\" ),\n !s.isNested(\"[][]\" ),\n !s.isNested(\"[]\" ),\n s.isNested(\"[[[[]]]]\" ),\n !s.isNested(\"[]]]]]]]]]]\" ),\n s.isNested(\"[][][[]]\" ),\n !s.isNested(\"[[]\" ),\n !s.isNested(\"[]]\" ),\n s.isNested(\"[[]][[\" ),\n s.isNested(\"[[][]]\" ),\n !s.isNested(\"\" ),\n !s.isNested(\"[[[[[[[[\" ),\n !s.isNested(\"]]]]]]]]\" )\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " 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\n isNested(\"[[]]\") -> true\n isNested(\"[]]]]]]][[[[[]\") -> false\n isNested(\"[][]\") -> false\n isNested(\"[]\") -> false\n isNested(\"[[][]]\") -> true\n isNested(\"[[]][[\") -> true", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean isNested(String string) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.isNested(\"[[]]\" ),\n !s.isNested(\"[]]]]]]][[[[[]\" ),\n !s.isNested(\"[][]\" ),\n !s.isNested(\"[]\" ),\n s.isNested(\"[[]][[\" ),\n s.isNested(\"[[][]]\" )\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<Integer> opening_bracket_index = new ArrayList<>(), closing_bracket_index = new ArrayList<>();\n for (int i = 0; i < string.length(); i++) {\n if (string.charAt(i) == '(') {\n opening_bracket_index.add(i);\n } else {\n closing_bracket_index.add(i);\n }\n }\n Collections.reverse(closing_bracket_index);\n int i = 0, l = closing_bracket_index.size();\n for (int idx : opening_bracket_index) {\n if (i < l && idx < closing_bracket_index.get(i)) {\n i += 1;\n }\n }\n return i >= 2;\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsNested"}
|
data/js/data/humanevalbugs.jsonl
CHANGED
The diff for this file is too large to render.
See raw diff
|
|