Datasets:

Languages:
code
ArXiv:
Tags:
code
License:
Muennighoff commited on
Commit
ac18780
·
1 Parent(s): b03a2fe
Files changed (1) hide show
  1. data/cpp/data/humanevalbugs.jsonl +1 -1
data/cpp/data/humanevalbugs.jsonl CHANGED
@@ -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]==' ') 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"}
 
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==2) out=out+'_';\n if (spacelen==3) out=out+\"_\";\n if (spacelen>3) 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"}