Commit
·
6188674
1
Parent(s):
1e6d4d6
iscuber
Browse files
data/cpp/data/humanevalbugs.jsonl
CHANGED
@@ -75,7 +75,7 @@
|
|
75 |
{"task_id": "CPP/74", "prompt": "/*\nWrite a function that accepts two vectors of strings and returns the vector that has \ntotal number of chars in the all strings of the vector less than the other vector.\n\nif the two vectors have the same number of chars, return the first vector.\n\nExamples\ntotal_match({}, {}) \u279e {}\ntotal_match({\"hi\", \"admin\"}, {\"hI\", \"Hi\"}) \u279e {\"hI\", \"Hi\"}\ntotal_match({\"hi\", \"admin\"}, {\"hi\", \"hi\", \"admin\", \"project\"}) \u279e {\"hi\", \"admin\"}\ntotal_match({\"hi\", \"admin\"}, {\"hI\", \"hi\", \"hi\"}) \u279e {\"hI\", \"hi\", \"hi\"}\ntotal_match({\"4\"}, {\"1\", \"2\", \"3\", \"4\", \"5\"}) \u279e {\"4\"}\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nvector<string> total_match(vector<string> lst1,vector<string> lst2){\n", "canonical_solution": " int num1,num2,i;\n num1=0;num2=0;\n for (i=0;i<lst1.size();i++)\n num1+=lst1[i].length();\n for (i=0;i<lst2.size();i++)\n num2+=lst2[i].length();\n if (num1>num2) return lst2;\n return lst1;\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(total_match({}, {}) , {}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hi\", \"hi\"}) , {\"hi\", \"hi\"}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hi\", \"hi\", \"admin\", \"project\"}) , {\"hi\", \"admin\"}));\n assert (issame(total_match({\"4\"}, {\"1\", \"2\", \"3\", \"4\", \"5\"}) , {\"4\"}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hI\", \"Hi\"}) , {\"hI\", \"Hi\"}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hI\", \"hi\", \"hi\"}) , {\"hI\", \"hi\", \"hi\"}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hI\", \"hi\", \"hii\"}) , {\"hi\", \"admin\"}));\n assert (issame(total_match({}, {\"this\"}) , {}));\n assert (issame(total_match({\"this\"}, {}) , {}));\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> total_match(vector<string> lst1,vector<string> lst2){\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(total_match({}, {}) , {}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hi\", \"hi\", \"admin\", \"project\"}) , {\"hi\", \"admin\"}));\n assert (issame(total_match({\"4\"}, {\"1\", \"2\", \"3\", \"4\", \"5\"}) , {\"4\"}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hI\", \"Hi\"}) , {\"hI\", \"Hi\"}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hI\", \"hi\", \"hi\"}) , {\"hI\", \"hi\", \"hi\"}));\n}\n", "buggy_solution": " int num1,num2,i;\n num1=0;num2=0;\n for (i=0;i<lst1.size();i++)\n num1+=lst1[i].length();\n for (i=0;i<lst2.size();i++)\n num2+=lst2[i].length();\n if (num1>num2) return lst1;\n return lst2;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "total_match"}
|
76 |
{"task_id": "CPP/75", "prompt": "/*\nWrite a function that returns true if the given number is the multiplication of 3 prime numbers\nand false otherwise.\nKnowing that (a) is less then 100. \nExample:\nis_multiply_prime(30) == true\n30 = 2 * 3 * 5\n*/\n#include<stdio.h>\nusing namespace std;\nbool is_multiply_prime(int a){\n", "canonical_solution": " int num=0;\n for (int i=2;i*i<=a;i++)\n while (a%i==0 and a>i)\n {\n a=a/i;\n num+=1;\n }\n if (num==2) return true;\n return false; \n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_multiply_prime(5) == false);\n assert (is_multiply_prime(30) == true);\n assert (is_multiply_prime(8) == true);\n assert (is_multiply_prime(10) == false);\n assert (is_multiply_prime(125) == true);\n assert (is_multiply_prime(3 * 5 * 7) == true);\n assert (is_multiply_prime(3 * 6 * 7) == false);\n assert (is_multiply_prime(9 * 9 * 9) == false);\n assert (is_multiply_prime(11 * 9 * 9) == false);\n assert (is_multiply_prime(11 * 13 * 7) == true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool is_multiply_prime(int a){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_multiply_prime(30) == true);\n}\n", "buggy_solution": " int num=0;\n for (int i=0;i*i<=a;i++)\n while (a%i==0 and a>i)\n {\n a=a/i;\n num+=1;\n }\n if (num==2) return true;\n return false; \n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "is_multiply_prime"}
|
77 |
{"task_id": "CPP/76", "prompt": "/*\nYour task is to write a function that returns true if a number x is a simple\npower of n and false in other cases.\nx is a simple power of n if n**int=x\nFor example:\nis_simple_power(1, 4) => true\nis_simple_power(2, 2) => true\nis_simple_power(8, 2) => true\nis_simple_power(3, 2) => false\nis_simple_power(3, 1) => false\nis_simple_power(5, 3) => false\n*/\n#include<stdio.h>\n#include<math.h>\nusing namespace std;\nbool is_simple_power(int x,int n){\n", "canonical_solution": " int p=1,count=0;\n while (p<=x and count<100)\n {\n if (p==x) return true;\n p=p*n;count+=1;\n }\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_simple_power(1, 4)== true);\n assert (is_simple_power(2, 2)==true);\n assert (is_simple_power(8, 2)==true);\n assert (is_simple_power(3, 2)==false);\n assert (is_simple_power(3, 1)==false);\n assert (is_simple_power(5, 3)==false);\n assert (is_simple_power(16, 2)== true);\n assert (is_simple_power(143214, 16)== false);\n assert (is_simple_power(4, 2)==true);\n assert (is_simple_power(9, 3)==true);\n assert (is_simple_power(16, 4)==true);\n assert (is_simple_power(24, 2)==false);\n assert (is_simple_power(128, 4)==false);\n assert (is_simple_power(12, 6)==false);\n assert (is_simple_power(1, 1)==true);\n assert (is_simple_power(1, 12)==true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool is_simple_power(int x,int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_simple_power(1, 4)== true);\n assert (is_simple_power(2, 2)==true);\n assert (is_simple_power(8, 2)==true);\n assert (is_simple_power(3, 2)==false);\n assert (is_simple_power(3, 1)==false);\n assert (is_simple_power(5, 3)==false);\n}\n", "buggy_solution": " int p=1,count=0;\n while (p<=x)\n {\n if (p==x) return true;\n count=p*n;x+=1;p+=1;\n }\n return false;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "infinite loop", "entry_point": "is_simple_power"}
|
78 |
-
{"task_id": "CPP/77", "prompt": "/*\nWrite a function that takes an integer a and returns true \nif this ingeger is a cube of some integer number.\nNote: you may assume the input is always valid.\nExamples:\niscube(1) ==> true\niscube(2) ==> false\niscube(-1) ==> true\niscube(64) ==> true\niscube(0) ==> true\niscube(180) ==> false\n*/\n#include<stdio.h>\n#include<math.h>\nusing namespace std;\nbool iscuber(int a){\n", "canonical_solution": " for (int i=0;i*i*i<=abs(a);i++)\n if (i*i*i==abs(a)) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (iscuber(1) == true);\n assert (iscuber(2) == false);\n assert (iscuber(-1) == true);\n assert (iscuber(64) == true);\n assert (iscuber(180) == false);\n assert (iscuber(1000) == true);\n assert (iscuber(0) == true);\n assert (iscuber(1729) == false);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool iscuber(int a){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (iscuber(1) == true);\n assert (iscuber(2) == false);\n assert (iscuber(-1) == true);\n assert (iscuber(64) == true);\n assert (iscuber(180) == false);\n assert (iscuber(0) == true);\n}\n", "buggy_solution": " for (int i=0;i*i*i<=abs(a);i++)\n if (i*i==abs(a)) return true;\n return false;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "
|
79 |
{"task_id": "CPP/78", "prompt": "/*\nYou have been tasked to write a function that receives \na hexadecimal number as a string and counts the number of hexadecimal \ndigits that are primes (prime number, or a prime, is a natural number \ngreater than 1 that is not a product of two smaller natural numbers).\nHexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.\nPrime numbers are 2, 3, 5, 7, 11, 13, 17,...\nSo you have to determine a number of the following digits: 2, 3, 5, 7, \nB (=decimal 11), D (=decimal 13).\nNote: you may assume the input is always correct or empty string, \nand symbols A,B,C,D,E,F are always uppercase.\nExamples:\nFor num = \"AB\" the output should be 1.\nFor num = \"1077E\" the output should be 2.\nFor num = \"ABED1A33\" the output should be 4.\nFor num = \"123456789ABCDEF0\" the output should be 6.\nFor num = \"2020\" the output should be 2.\n*/\n#include<stdio.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\nint hex_key(string num){\n", "canonical_solution": " string key=\"2357BD\";\n int out=0;\n for (int i=0;i<num.length();i++)\n if (find(key.begin(),key.end(),num[i])!=key.end()) out+=1;\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (hex_key(\"AB\") == 1 );\n assert (hex_key(\"1077E\") == 2 );\n assert (hex_key(\"ABED1A33\") == 4 );\n assert (hex_key(\"2020\") == 2 );\n assert (hex_key(\"123456789ABCDEF0\") == 6 );\n assert (hex_key(\"112233445566778899AABBCCDDEEFF00\") == 12 );\n assert (hex_key(\"\") == 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 hex_key(string num){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (hex_key(\"AB\") == 1 );\n assert (hex_key(\"1077E\") == 2 );\n assert (hex_key(\"ABED1A33\") == 4 );\n assert (hex_key(\"2020\") == 2 );\n assert (hex_key(\"123456789ABCDEF0\") == 6 );\n}\n", "buggy_solution": " string key=\"2357BD\";\n int out=1;\n for (int i=0;i<num.length();i++)\n if (find(key.begin(),key.end(),num[i])!=key.end()) out+=1;\n return out;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "hex_key"}
|
80 |
{"task_id": "CPP/79", "prompt": "/*\nYou will be given a number in decimal form and your task is to convert it to\nbinary format. The function should return a string, with each character representing a binary\nnumber. Each character in the string will be '0' or '1'.\n\nThere will be an extra couple of characters \"db\" at the beginning and at the end of the string.\nThe extra characters are there to help with the format.\n\nExamples:\ndecimal_to_binary(15) // returns \"db1111db\"\ndecimal_to_binary(32) // returns \"db100000db\"\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring decimal_to_binary(int decimal){\n", "canonical_solution": " string out=\"\";\n if (decimal==0) return \"db0db\";\n while (decimal>0)\n {\n out=to_string(decimal%2)+out;\n decimal=decimal/2;\n }\n out=\"db\"+out+\"db\";\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (decimal_to_binary(0) == \"db0db\");\n assert (decimal_to_binary(32) == \"db100000db\");\n assert (decimal_to_binary(103) == \"db1100111db\");\n assert (decimal_to_binary(15) == \"db1111db\");\n\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nstring decimal_to_binary(int decimal){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (decimal_to_binary(32) == \"db100000db\");\n assert (decimal_to_binary(15) == \"db1111db\");\n}\n", "buggy_solution": " string out=\"\";\n if (decimal==0) return \"db0db\";\n while (decimal>0)\n {\n out=to_string(decimal%2)+out;\n decimal=decimal/2;\n }\n out=\"db\"+out+\"d\";\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "decimal_to_binary"}
|
81 |
{"task_id": "CPP/80", "prompt": "/*\nYou are given a string s.\nYour task is to check if the string is happy or not.\nA string is happy if its length is at least 3 and every 3 consecutive letters are distinct\nFor example:\nis_happy(\"a\") => false\nis_happy(\"aa\") => false\nis_happy(\"abcd\") => true\nis_happy(\"aabb\") => false\nis_happy(\"adb\") => true\nis_happy(\"xyy\") => false\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool is_happy(string s){\n", "canonical_solution": " if (s.length()<3) return false;\n for (int i=2;i<s.length();i++)\n if (s[i]==s[i-1] or s[i]==s[i-2]) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_happy(\"a\") == false );\n assert (is_happy(\"aa\") == false );\n assert (is_happy(\"abcd\") == true );\n assert (is_happy(\"aabb\") == false );\n assert (is_happy(\"adb\") == true );\n assert (is_happy(\"xyy\") == false );\n assert (is_happy(\"iopaxpoi\") == true );\n assert (is_happy(\"iopaxioi\") == false );\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool is_happy(string s){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_happy(\"a\") == false );\n assert (is_happy(\"aa\") == false );\n assert (is_happy(\"abcd\") == true );\n assert (is_happy(\"aabb\") == false );\n assert (is_happy(\"adb\") == true );\n assert (is_happy(\"xyy\") == false );\n}\n", "buggy_solution": " if (s.length()<3) return false;\n for (int i=2;i<s.length();i++)\n if (s[i]==s[i-1] and s[i]==s[i-2]) return false;\n return true;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "is_happy"}
|
|
|
75 |
{"task_id": "CPP/74", "prompt": "/*\nWrite a function that accepts two vectors of strings and returns the vector that has \ntotal number of chars in the all strings of the vector less than the other vector.\n\nif the two vectors have the same number of chars, return the first vector.\n\nExamples\ntotal_match({}, {}) \u279e {}\ntotal_match({\"hi\", \"admin\"}, {\"hI\", \"Hi\"}) \u279e {\"hI\", \"Hi\"}\ntotal_match({\"hi\", \"admin\"}, {\"hi\", \"hi\", \"admin\", \"project\"}) \u279e {\"hi\", \"admin\"}\ntotal_match({\"hi\", \"admin\"}, {\"hI\", \"hi\", \"hi\"}) \u279e {\"hI\", \"hi\", \"hi\"}\ntotal_match({\"4\"}, {\"1\", \"2\", \"3\", \"4\", \"5\"}) \u279e {\"4\"}\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nvector<string> total_match(vector<string> lst1,vector<string> lst2){\n", "canonical_solution": " int num1,num2,i;\n num1=0;num2=0;\n for (i=0;i<lst1.size();i++)\n num1+=lst1[i].length();\n for (i=0;i<lst2.size();i++)\n num2+=lst2[i].length();\n if (num1>num2) return lst2;\n return lst1;\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(total_match({}, {}) , {}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hi\", \"hi\"}) , {\"hi\", \"hi\"}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hi\", \"hi\", \"admin\", \"project\"}) , {\"hi\", \"admin\"}));\n assert (issame(total_match({\"4\"}, {\"1\", \"2\", \"3\", \"4\", \"5\"}) , {\"4\"}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hI\", \"Hi\"}) , {\"hI\", \"Hi\"}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hI\", \"hi\", \"hi\"}) , {\"hI\", \"hi\", \"hi\"}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hI\", \"hi\", \"hii\"}) , {\"hi\", \"admin\"}));\n assert (issame(total_match({}, {\"this\"}) , {}));\n assert (issame(total_match({\"this\"}, {}) , {}));\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> total_match(vector<string> lst1,vector<string> lst2){\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(total_match({}, {}) , {}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hi\", \"hi\", \"admin\", \"project\"}) , {\"hi\", \"admin\"}));\n assert (issame(total_match({\"4\"}, {\"1\", \"2\", \"3\", \"4\", \"5\"}) , {\"4\"}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hI\", \"Hi\"}) , {\"hI\", \"Hi\"}));\n assert (issame(total_match({\"hi\", \"admin\"}, {\"hI\", \"hi\", \"hi\"}) , {\"hI\", \"hi\", \"hi\"}));\n}\n", "buggy_solution": " int num1,num2,i;\n num1=0;num2=0;\n for (i=0;i<lst1.size();i++)\n num1+=lst1[i].length();\n for (i=0;i<lst2.size();i++)\n num2+=lst2[i].length();\n if (num1>num2) return lst1;\n return lst2;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "total_match"}
|
76 |
{"task_id": "CPP/75", "prompt": "/*\nWrite a function that returns true if the given number is the multiplication of 3 prime numbers\nand false otherwise.\nKnowing that (a) is less then 100. \nExample:\nis_multiply_prime(30) == true\n30 = 2 * 3 * 5\n*/\n#include<stdio.h>\nusing namespace std;\nbool is_multiply_prime(int a){\n", "canonical_solution": " int num=0;\n for (int i=2;i*i<=a;i++)\n while (a%i==0 and a>i)\n {\n a=a/i;\n num+=1;\n }\n if (num==2) return true;\n return false; \n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_multiply_prime(5) == false);\n assert (is_multiply_prime(30) == true);\n assert (is_multiply_prime(8) == true);\n assert (is_multiply_prime(10) == false);\n assert (is_multiply_prime(125) == true);\n assert (is_multiply_prime(3 * 5 * 7) == true);\n assert (is_multiply_prime(3 * 6 * 7) == false);\n assert (is_multiply_prime(9 * 9 * 9) == false);\n assert (is_multiply_prime(11 * 9 * 9) == false);\n assert (is_multiply_prime(11 * 13 * 7) == true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool is_multiply_prime(int a){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_multiply_prime(30) == true);\n}\n", "buggy_solution": " int num=0;\n for (int i=0;i*i<=a;i++)\n while (a%i==0 and a>i)\n {\n a=a/i;\n num+=1;\n }\n if (num==2) return true;\n return false; \n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "is_multiply_prime"}
|
77 |
{"task_id": "CPP/76", "prompt": "/*\nYour task is to write a function that returns true if a number x is a simple\npower of n and false in other cases.\nx is a simple power of n if n**int=x\nFor example:\nis_simple_power(1, 4) => true\nis_simple_power(2, 2) => true\nis_simple_power(8, 2) => true\nis_simple_power(3, 2) => false\nis_simple_power(3, 1) => false\nis_simple_power(5, 3) => false\n*/\n#include<stdio.h>\n#include<math.h>\nusing namespace std;\nbool is_simple_power(int x,int n){\n", "canonical_solution": " int p=1,count=0;\n while (p<=x and count<100)\n {\n if (p==x) return true;\n p=p*n;count+=1;\n }\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_simple_power(1, 4)== true);\n assert (is_simple_power(2, 2)==true);\n assert (is_simple_power(8, 2)==true);\n assert (is_simple_power(3, 2)==false);\n assert (is_simple_power(3, 1)==false);\n assert (is_simple_power(5, 3)==false);\n assert (is_simple_power(16, 2)== true);\n assert (is_simple_power(143214, 16)== false);\n assert (is_simple_power(4, 2)==true);\n assert (is_simple_power(9, 3)==true);\n assert (is_simple_power(16, 4)==true);\n assert (is_simple_power(24, 2)==false);\n assert (is_simple_power(128, 4)==false);\n assert (is_simple_power(12, 6)==false);\n assert (is_simple_power(1, 1)==true);\n assert (is_simple_power(1, 12)==true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool is_simple_power(int x,int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_simple_power(1, 4)== true);\n assert (is_simple_power(2, 2)==true);\n assert (is_simple_power(8, 2)==true);\n assert (is_simple_power(3, 2)==false);\n assert (is_simple_power(3, 1)==false);\n assert (is_simple_power(5, 3)==false);\n}\n", "buggy_solution": " int p=1,count=0;\n while (p<=x)\n {\n if (p==x) return true;\n count=p*n;x+=1;p+=1;\n }\n return false;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "infinite loop", "entry_point": "is_simple_power"}
|
78 |
+
{"task_id": "CPP/77", "prompt": "/*\nWrite a function that takes an integer a and returns true \nif this ingeger is a cube of some integer number.\nNote: you may assume the input is always valid.\nExamples:\niscube(1) ==> true\niscube(2) ==> false\niscube(-1) ==> true\niscube(64) ==> true\niscube(0) ==> true\niscube(180) ==> false\n*/\n#include<stdio.h>\n#include<math.h>\nusing namespace std;\nbool iscuber(int a){\n", "canonical_solution": " for (int i=0;i*i*i<=abs(a);i++)\n if (i*i*i==abs(a)) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (iscuber(1) == true);\n assert (iscuber(2) == false);\n assert (iscuber(-1) == true);\n assert (iscuber(64) == true);\n assert (iscuber(180) == false);\n assert (iscuber(1000) == true);\n assert (iscuber(0) == true);\n assert (iscuber(1729) == false);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool iscuber(int a){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (iscuber(1) == true);\n assert (iscuber(2) == false);\n assert (iscuber(-1) == true);\n assert (iscuber(64) == true);\n assert (iscuber(180) == false);\n assert (iscuber(0) == true);\n}\n", "buggy_solution": " for (int i=0;i*i*i<=abs(a);i++)\n if (i*i==abs(a)) return true;\n return false;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "iscuber"}
|
79 |
{"task_id": "CPP/78", "prompt": "/*\nYou have been tasked to write a function that receives \na hexadecimal number as a string and counts the number of hexadecimal \ndigits that are primes (prime number, or a prime, is a natural number \ngreater than 1 that is not a product of two smaller natural numbers).\nHexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.\nPrime numbers are 2, 3, 5, 7, 11, 13, 17,...\nSo you have to determine a number of the following digits: 2, 3, 5, 7, \nB (=decimal 11), D (=decimal 13).\nNote: you may assume the input is always correct or empty string, \nand symbols A,B,C,D,E,F are always uppercase.\nExamples:\nFor num = \"AB\" the output should be 1.\nFor num = \"1077E\" the output should be 2.\nFor num = \"ABED1A33\" the output should be 4.\nFor num = \"123456789ABCDEF0\" the output should be 6.\nFor num = \"2020\" the output should be 2.\n*/\n#include<stdio.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\nint hex_key(string num){\n", "canonical_solution": " string key=\"2357BD\";\n int out=0;\n for (int i=0;i<num.length();i++)\n if (find(key.begin(),key.end(),num[i])!=key.end()) out+=1;\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (hex_key(\"AB\") == 1 );\n assert (hex_key(\"1077E\") == 2 );\n assert (hex_key(\"ABED1A33\") == 4 );\n assert (hex_key(\"2020\") == 2 );\n assert (hex_key(\"123456789ABCDEF0\") == 6 );\n assert (hex_key(\"112233445566778899AABBCCDDEEFF00\") == 12 );\n assert (hex_key(\"\") == 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 hex_key(string num){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (hex_key(\"AB\") == 1 );\n assert (hex_key(\"1077E\") == 2 );\n assert (hex_key(\"ABED1A33\") == 4 );\n assert (hex_key(\"2020\") == 2 );\n assert (hex_key(\"123456789ABCDEF0\") == 6 );\n}\n", "buggy_solution": " string key=\"2357BD\";\n int out=1;\n for (int i=0;i<num.length();i++)\n if (find(key.begin(),key.end(),num[i])!=key.end()) out+=1;\n return out;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "hex_key"}
|
80 |
{"task_id": "CPP/79", "prompt": "/*\nYou will be given a number in decimal form and your task is to convert it to\nbinary format. The function should return a string, with each character representing a binary\nnumber. Each character in the string will be '0' or '1'.\n\nThere will be an extra couple of characters \"db\" at the beginning and at the end of the string.\nThe extra characters are there to help with the format.\n\nExamples:\ndecimal_to_binary(15) // returns \"db1111db\"\ndecimal_to_binary(32) // returns \"db100000db\"\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring decimal_to_binary(int decimal){\n", "canonical_solution": " string out=\"\";\n if (decimal==0) return \"db0db\";\n while (decimal>0)\n {\n out=to_string(decimal%2)+out;\n decimal=decimal/2;\n }\n out=\"db\"+out+\"db\";\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (decimal_to_binary(0) == \"db0db\");\n assert (decimal_to_binary(32) == \"db100000db\");\n assert (decimal_to_binary(103) == \"db1100111db\");\n assert (decimal_to_binary(15) == \"db1111db\");\n\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nstring decimal_to_binary(int decimal){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (decimal_to_binary(32) == \"db100000db\");\n assert (decimal_to_binary(15) == \"db1111db\");\n}\n", "buggy_solution": " string out=\"\";\n if (decimal==0) return \"db0db\";\n while (decimal>0)\n {\n out=to_string(decimal%2)+out;\n decimal=decimal/2;\n }\n out=\"db\"+out+\"d\";\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "decimal_to_binary"}
|
81 |
{"task_id": "CPP/80", "prompt": "/*\nYou are given a string s.\nYour task is to check if the string is happy or not.\nA string is happy if its length is at least 3 and every 3 consecutive letters are distinct\nFor example:\nis_happy(\"a\") => false\nis_happy(\"aa\") => false\nis_happy(\"abcd\") => true\nis_happy(\"aabb\") => false\nis_happy(\"adb\") => true\nis_happy(\"xyy\") => false\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool is_happy(string s){\n", "canonical_solution": " if (s.length()<3) return false;\n for (int i=2;i<s.length();i++)\n if (s[i]==s[i-1] or s[i]==s[i-2]) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_happy(\"a\") == false );\n assert (is_happy(\"aa\") == false );\n assert (is_happy(\"abcd\") == true );\n assert (is_happy(\"aabb\") == false );\n assert (is_happy(\"adb\") == true );\n assert (is_happy(\"xyy\") == false );\n assert (is_happy(\"iopaxpoi\") == true );\n assert (is_happy(\"iopaxioi\") == false );\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool is_happy(string s){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_happy(\"a\") == false );\n assert (is_happy(\"aa\") == false );\n assert (is_happy(\"abcd\") == true );\n assert (is_happy(\"aabb\") == false );\n assert (is_happy(\"adb\") == true );\n assert (is_happy(\"xyy\") == false );\n}\n", "buggy_solution": " if (s.length()<3) return false;\n for (int i=2;i<s.length();i++)\n if (s[i]==s[i-1] and s[i]==s[i-2]) return false;\n return true;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "is_happy"}
|
data/rust/data/humanevalbugs.jsonl
CHANGED
@@ -75,7 +75,7 @@
|
|
75 |
{"task_id": "Rust/74", "prompt": "\n/*\n\n Write a function that accepts two lists of strings and returns the list that has \n total number of chars in the all strings of the list less than the other list.\n\n if the two lists have the same number of chars, return the first list.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn total_match(lst1:Vec<&str>, lst2:Vec<&str>) -> Vec<String>{\n\n", "canonical_solution": "\n let total_1: usize = lst1\n .iter()\n .fold(0, |acc: usize, str: &&str| acc + str.chars().count());\n let total_2: usize = lst2\n .iter()\n .fold(0, |acc: usize, str: &&str| acc + str.chars().count());\n\n if total_1 <= total_2 {\n return lst1.into_iter().map(|x| x.to_string()).collect();\n } else {\n return lst2.into_iter().map(|x| x.to_string()).collect();\n }\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_total_match() {\n let v_empty: Vec<String> = vec![];\n assert!(total_match(vec![], vec![]) == v_empty);\n assert!(total_match(vec![\"hi\", \"admin\"], vec![\"hi\", \"hi\"]) == vec![\"hi\", \"hi\"]);\n assert!(\n total_match(vec![\"hi\", \"admin\"], vec![\"hi\", \"hi\", \"admin\", \"project\"])\n == vec![\"hi\", \"admin\"]\n );\n assert!(total_match(vec![\"4\"], vec![\"1\", \"2\", \"3\", \"4\", \"5\"]) == vec![\"4\"]);\n assert!(total_match(vec![\"hi\", \"admin\"], vec![\"hI\", \"Hi\"]) == vec![\"hI\", \"Hi\"]);\n assert!(total_match(vec![\"hi\", \"admin\"], vec![\"hI\", \"hi\", \"hi\"]) == vec![\"hI\", \"hi\", \"hi\"]);\n assert!(total_match(vec![\"hi\", \"admin\"], vec![\"hI\", \"hi\", \"hii\"]) == vec![\"hi\", \"admin\"]);\n assert!(total_match(vec![], vec![\"this\"]) == v_empty);\n assert!(total_match(vec![\"this\"], vec![]) == v_empty);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let total_1: usize = lst1\n .iter()\n .fold(0, |acc: usize, str: &&str| acc + str.chars().count());\n let total_2: usize = lst2\n .iter()\n .fold(0, |acc: usize, str: &&str| acc + str.chars().count());\n\n if total_1 <= total_2 {\n return lst2.into_iter().map(|x| x.to_string()).collect();\n } else {\n return lst1.into_iter().map(|x| x.to_string()).collect();\n }\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "total_match"}
|
76 |
{"task_id": "Rust/75", "prompt": "\n/*\nWrite a function that returns true if the given number is the multiplication of 3 prime numbers\n and false otherwise.\n Knowing that (a) is less then 100.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn is_multiply_prime(a: i32) -> bool {\n\n", "canonical_solution": "\n let mut a1 = a;\n let mut num = 0;\n for i in 2..a {\n while a1 % i == 0 && a1 > i {\n a1 /= i;\n num += 1;\n }\n }\n if num == 2 {\n return true;\n }\n return false;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_is_multiply_prime() {\n assert!(is_multiply_prime(5) == false);\n assert!(is_multiply_prime(30) == true);\n assert!(is_multiply_prime(8) == true);\n assert!(is_multiply_prime(10) == false);\n assert!(is_multiply_prime(125) == true);\n assert!(is_multiply_prime(3 * 5 * 7) == true);\n assert!(is_multiply_prime(3 * 6 * 7) == false);\n assert!(is_multiply_prime(9 * 9 * 9) == false);\n assert!(is_multiply_prime(11 * 9 * 9) == false);\n assert!(is_multiply_prime(11 * 13 * 7) == true);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut a1 = a;\n let mut num = 0;\n for i in 0..a {\n while a1 % i == 0 && a1 > i {\n a1 /= i;\n num += 1;\n }\n }\n if num == 2 {\n return true;\n }\n return false;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "is_multiply_prime"}
|
77 |
{"task_id": "Rust/76", "prompt": "\n/*\nYour task is to write a function that returns true if a number x is a simple\n power of n and false in other cases.\n x is a simple power of n if n**int=x\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn is_simple_power(x:i32, n:i32) -> bool{\n\n", "canonical_solution": "\n let mut p: i32 = 1;\n let mut count: i32 = 0;\n\n while p <= x && count < 100 {\n if p == x {\n return true;\n };\n p = p * n;\n count += 1;\n }\n return false;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_is_simple_power() {\n assert!(is_simple_power(1, 4) == true);\n assert!(is_simple_power(2, 2) == true);\n assert!(is_simple_power(8, 2) == true);\n assert!(is_simple_power(3, 2) == false);\n assert!(is_simple_power(3, 1) == false);\n assert!(is_simple_power(5, 3) == false);\n assert!(is_simple_power(16, 2) == true);\n assert!(is_simple_power(143214, 16) == false);\n assert!(is_simple_power(4, 2) == true);\n assert!(is_simple_power(9, 3) == true);\n assert!(is_simple_power(16, 4) == true);\n assert!(is_simple_power(24, 2) == false);\n assert!(is_simple_power(128, 4) == false);\n assert!(is_simple_power(12, 6) == false);\n assert!(is_simple_power(1, 1) == true);\n assert!(is_simple_power(1, 12) == true);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut p: i32 = 1;\n let mut count: i32 = 0;\n\n while n <= x && count < 100 {\n if p == x {\n return true;\n };\n p = p * n;\n count += 1;\n }\n return false;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "infinite loop", "entry_point": "is_simple_power"}
|
78 |
-
{"task_id": "Rust/77", "prompt": "\n/*\n\n Write a function that takes an integer a and returns True \n if this ingeger is a cube of some integer number.\n Note: you may assume the input is always valid.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn iscuber(a:i32) -> bool{\n\n", "canonical_solution": "\n let a1: f64 = i32::abs(a) as f64;\n let sqrt_3 = f64::powf(a1, 1.0 / 3.0).ceil();\n\n return i32::pow(sqrt_3 as i32, 3) == a1 as i32;\n}\n\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_iscuber() {\n assert!(iscuber(1) == true);\n assert!(iscuber(2) == false);\n assert!(iscuber(-1) == true);\n assert!(iscuber(64) == true);\n assert!(iscuber(180) == false);\n assert!(iscuber(1000) == true);\n assert!(iscuber(0) == true);\n assert!(iscuber(1729) == false);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let a1: f64 = i32::abs(a) as f64;\n let sqrt_3 = f64::powf(a1, 1.0 / 3.0).ceil();\n\n return sqrt_3 as i32 == a1 as i32;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "
|
79 |
{"task_id": "Rust/78", "prompt": "\n/*\nYou have been tasked to write a function that receives \n a hexadecimal number as a string and counts the number of hexadecimal \n digits that are primes (prime number, or a prime, is a natural number \n greater than 1 that is not a product of two smaller natural numbers).\n Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.\n Prime numbers are 2, 3, 5, 7, 11, 13, 17,...\n So you have to determine a number of the following digits: 2, 3, 5, 7, \n B (=decimal 11), D (=decimal 13).\n Note: you may assume the input is always correct or empty string, \n and symbols A,B,C,D,E,F are always uppercase.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn hex_key(num:&str) -> i32{\n\n", "canonical_solution": "\n let primes: Vec<&str> = vec![\"2\", \"3\", \"5\", \"7\", \"B\", \"D\"];\n let mut total: i32 = 0;\n for i in 0..num.len() {\n if primes.contains(&num.get(i..i + 1).unwrap()) {\n total += 1;\n }\n }\n return total;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n\n #[test]\n fn test_hex_key() {\n assert!(hex_key(\"AB\") == 1);\n assert!(hex_key(\"1077E\") == 2);\n assert!(hex_key(\"ABED1A33\") == 4);\n assert!(hex_key(\"2020\") == 2);\n assert!(hex_key(\"123456789ABCDEF0\") == 6);\n assert!(hex_key(\"112233445566778899AABBCCDDEEFF00\") == 12);\n assert!(hex_key(\"\") == 0);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let primes: Vec<&str> = vec![\"2\", \"3\", \"5\", \"7\", \"B\", \"D\"];\n let mut total: i32 = 1;\n for i in 0..num.len() {\n if primes.contains(&num.get(i..i + 1).unwrap()) {\n total += 1;\n }\n }\n return total;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "hex_key"}
|
80 |
{"task_id": "Rust/79", "prompt": "\n/*\nYou will be given a number in decimal form and your task is to convert it to\n binary format. The function should return a string, with each character representing a binary\n number. Each character in the string will be '0' or '1'.\n\n There will be an extra couple of characters 'db' at the beginning and at the end of the string.\n The extra characters are there to help with the format.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn decimal_to_binary(decimal:i32) -> String{\n\n", "canonical_solution": "\n let mut d_cp = decimal;\n let mut out: String = String::from(\"\");\n if d_cp == 0 {\n return \"db0db\".to_string();\n }\n while d_cp > 0 {\n out = (d_cp % 2).to_string() + &out;\n d_cp = d_cp / 2;\n }\n out = \"db\".to_string() + &out + &\"db\".to_string();\n return out;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_decimal_to_binary() {\n assert!(decimal_to_binary(0) == \"db0db\".to_string());\n assert!(decimal_to_binary(32) == \"db100000db\".to_string());\n assert!(decimal_to_binary(103) == \"db1100111db\".to_string());\n assert!(decimal_to_binary(15) == \"db1111db\".to_string());\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut d_cp = decimal;\n let mut out: String = String::from(\"\");\n if d_cp == 0 {\n return \"db0d\".to_string();\n }\n while d_cp > 0 {\n out = (d_cp % 2).to_string() + &out;\n d_cp = d_cp / 2;\n }\n out = \"db\".to_string() + &out + &\"db\".to_string();\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "decimal_to_binary"}
|
81 |
{"task_id": "Rust/80", "prompt": "\n/*\nYou are given a string s.\n Your task is to check if the string is happy or not.\n A string is happy if its length is at least 3 and every 3 consecutive letters are distinct\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn is_happy(s:&str) -> bool{\n\n", "canonical_solution": "\n let str: Vec<char> = s.chars().into_iter().collect();\n if str.len() < 3 {\n return false;\n }\n for i in 2..str.len() {\n if str[i] == str[i - 1] || str[i] == str[i - 2] {\n return false;\n }\n }\n return true;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_is_happy() {\n assert!(is_happy(\"a\") == false);\n assert!(is_happy(\"aa\") == false);\n assert!(is_happy(\"abcd\") == true);\n assert!(is_happy(\"aabb\") == false);\n assert!(is_happy(\"adb\") == true);\n assert!(is_happy(\"xyy\") == false);\n assert!(is_happy(\"iopaxpoi\") == true);\n assert!(is_happy(\"iopaxioi\") == false);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let str: Vec<char> = s.chars().into_iter().collect();\n if str.len() < 3 {\n return false;\n }\n for i in 2..str.len() {\n if str[i] == str[i - 1] && str[i] == str[i - 2] {\n return false;\n }\n }\n return true;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "is_happy"}
|
|
|
75 |
{"task_id": "Rust/74", "prompt": "\n/*\n\n Write a function that accepts two lists of strings and returns the list that has \n total number of chars in the all strings of the list less than the other list.\n\n if the two lists have the same number of chars, return the first list.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn total_match(lst1:Vec<&str>, lst2:Vec<&str>) -> Vec<String>{\n\n", "canonical_solution": "\n let total_1: usize = lst1\n .iter()\n .fold(0, |acc: usize, str: &&str| acc + str.chars().count());\n let total_2: usize = lst2\n .iter()\n .fold(0, |acc: usize, str: &&str| acc + str.chars().count());\n\n if total_1 <= total_2 {\n return lst1.into_iter().map(|x| x.to_string()).collect();\n } else {\n return lst2.into_iter().map(|x| x.to_string()).collect();\n }\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_total_match() {\n let v_empty: Vec<String> = vec![];\n assert!(total_match(vec![], vec![]) == v_empty);\n assert!(total_match(vec![\"hi\", \"admin\"], vec![\"hi\", \"hi\"]) == vec![\"hi\", \"hi\"]);\n assert!(\n total_match(vec![\"hi\", \"admin\"], vec![\"hi\", \"hi\", \"admin\", \"project\"])\n == vec![\"hi\", \"admin\"]\n );\n assert!(total_match(vec![\"4\"], vec![\"1\", \"2\", \"3\", \"4\", \"5\"]) == vec![\"4\"]);\n assert!(total_match(vec![\"hi\", \"admin\"], vec![\"hI\", \"Hi\"]) == vec![\"hI\", \"Hi\"]);\n assert!(total_match(vec![\"hi\", \"admin\"], vec![\"hI\", \"hi\", \"hi\"]) == vec![\"hI\", \"hi\", \"hi\"]);\n assert!(total_match(vec![\"hi\", \"admin\"], vec![\"hI\", \"hi\", \"hii\"]) == vec![\"hi\", \"admin\"]);\n assert!(total_match(vec![], vec![\"this\"]) == v_empty);\n assert!(total_match(vec![\"this\"], vec![]) == v_empty);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let total_1: usize = lst1\n .iter()\n .fold(0, |acc: usize, str: &&str| acc + str.chars().count());\n let total_2: usize = lst2\n .iter()\n .fold(0, |acc: usize, str: &&str| acc + str.chars().count());\n\n if total_1 <= total_2 {\n return lst2.into_iter().map(|x| x.to_string()).collect();\n } else {\n return lst1.into_iter().map(|x| x.to_string()).collect();\n }\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "total_match"}
|
76 |
{"task_id": "Rust/75", "prompt": "\n/*\nWrite a function that returns true if the given number is the multiplication of 3 prime numbers\n and false otherwise.\n Knowing that (a) is less then 100.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn is_multiply_prime(a: i32) -> bool {\n\n", "canonical_solution": "\n let mut a1 = a;\n let mut num = 0;\n for i in 2..a {\n while a1 % i == 0 && a1 > i {\n a1 /= i;\n num += 1;\n }\n }\n if num == 2 {\n return true;\n }\n return false;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_is_multiply_prime() {\n assert!(is_multiply_prime(5) == false);\n assert!(is_multiply_prime(30) == true);\n assert!(is_multiply_prime(8) == true);\n assert!(is_multiply_prime(10) == false);\n assert!(is_multiply_prime(125) == true);\n assert!(is_multiply_prime(3 * 5 * 7) == true);\n assert!(is_multiply_prime(3 * 6 * 7) == false);\n assert!(is_multiply_prime(9 * 9 * 9) == false);\n assert!(is_multiply_prime(11 * 9 * 9) == false);\n assert!(is_multiply_prime(11 * 13 * 7) == true);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut a1 = a;\n let mut num = 0;\n for i in 0..a {\n while a1 % i == 0 && a1 > i {\n a1 /= i;\n num += 1;\n }\n }\n if num == 2 {\n return true;\n }\n return false;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "is_multiply_prime"}
|
77 |
{"task_id": "Rust/76", "prompt": "\n/*\nYour task is to write a function that returns true if a number x is a simple\n power of n and false in other cases.\n x is a simple power of n if n**int=x\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn is_simple_power(x:i32, n:i32) -> bool{\n\n", "canonical_solution": "\n let mut p: i32 = 1;\n let mut count: i32 = 0;\n\n while p <= x && count < 100 {\n if p == x {\n return true;\n };\n p = p * n;\n count += 1;\n }\n return false;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_is_simple_power() {\n assert!(is_simple_power(1, 4) == true);\n assert!(is_simple_power(2, 2) == true);\n assert!(is_simple_power(8, 2) == true);\n assert!(is_simple_power(3, 2) == false);\n assert!(is_simple_power(3, 1) == false);\n assert!(is_simple_power(5, 3) == false);\n assert!(is_simple_power(16, 2) == true);\n assert!(is_simple_power(143214, 16) == false);\n assert!(is_simple_power(4, 2) == true);\n assert!(is_simple_power(9, 3) == true);\n assert!(is_simple_power(16, 4) == true);\n assert!(is_simple_power(24, 2) == false);\n assert!(is_simple_power(128, 4) == false);\n assert!(is_simple_power(12, 6) == false);\n assert!(is_simple_power(1, 1) == true);\n assert!(is_simple_power(1, 12) == true);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut p: i32 = 1;\n let mut count: i32 = 0;\n\n while n <= x && count < 100 {\n if p == x {\n return true;\n };\n p = p * n;\n count += 1;\n }\n return false;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "infinite loop", "entry_point": "is_simple_power"}
|
78 |
+
{"task_id": "Rust/77", "prompt": "\n/*\n\n Write a function that takes an integer a and returns True \n if this ingeger is a cube of some integer number.\n Note: you may assume the input is always valid.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn iscuber(a:i32) -> bool{\n\n", "canonical_solution": "\n let a1: f64 = i32::abs(a) as f64;\n let sqrt_3 = f64::powf(a1, 1.0 / 3.0).ceil();\n\n return i32::pow(sqrt_3 as i32, 3) == a1 as i32;\n}\n\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_iscuber() {\n assert!(iscuber(1) == true);\n assert!(iscuber(2) == false);\n assert!(iscuber(-1) == true);\n assert!(iscuber(64) == true);\n assert!(iscuber(180) == false);\n assert!(iscuber(1000) == true);\n assert!(iscuber(0) == true);\n assert!(iscuber(1729) == false);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let a1: f64 = i32::abs(a) as f64;\n let sqrt_3 = f64::powf(a1, 1.0 / 3.0).ceil();\n\n return sqrt_3 as i32 == a1 as i32;\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "iscuber"}
|
79 |
{"task_id": "Rust/78", "prompt": "\n/*\nYou have been tasked to write a function that receives \n a hexadecimal number as a string and counts the number of hexadecimal \n digits that are primes (prime number, or a prime, is a natural number \n greater than 1 that is not a product of two smaller natural numbers).\n Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.\n Prime numbers are 2, 3, 5, 7, 11, 13, 17,...\n So you have to determine a number of the following digits: 2, 3, 5, 7, \n B (=decimal 11), D (=decimal 13).\n Note: you may assume the input is always correct or empty string, \n and symbols A,B,C,D,E,F are always uppercase.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn hex_key(num:&str) -> i32{\n\n", "canonical_solution": "\n let primes: Vec<&str> = vec![\"2\", \"3\", \"5\", \"7\", \"B\", \"D\"];\n let mut total: i32 = 0;\n for i in 0..num.len() {\n if primes.contains(&num.get(i..i + 1).unwrap()) {\n total += 1;\n }\n }\n return total;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n\n #[test]\n fn test_hex_key() {\n assert!(hex_key(\"AB\") == 1);\n assert!(hex_key(\"1077E\") == 2);\n assert!(hex_key(\"ABED1A33\") == 4);\n assert!(hex_key(\"2020\") == 2);\n assert!(hex_key(\"123456789ABCDEF0\") == 6);\n assert!(hex_key(\"112233445566778899AABBCCDDEEFF00\") == 12);\n assert!(hex_key(\"\") == 0);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let primes: Vec<&str> = vec![\"2\", \"3\", \"5\", \"7\", \"B\", \"D\"];\n let mut total: i32 = 1;\n for i in 0..num.len() {\n if primes.contains(&num.get(i..i + 1).unwrap()) {\n total += 1;\n }\n }\n return total;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "hex_key"}
|
80 |
{"task_id": "Rust/79", "prompt": "\n/*\nYou will be given a number in decimal form and your task is to convert it to\n binary format. The function should return a string, with each character representing a binary\n number. Each character in the string will be '0' or '1'.\n\n There will be an extra couple of characters 'db' at the beginning and at the end of the string.\n The extra characters are there to help with the format.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn decimal_to_binary(decimal:i32) -> String{\n\n", "canonical_solution": "\n let mut d_cp = decimal;\n let mut out: String = String::from(\"\");\n if d_cp == 0 {\n return \"db0db\".to_string();\n }\n while d_cp > 0 {\n out = (d_cp % 2).to_string() + &out;\n d_cp = d_cp / 2;\n }\n out = \"db\".to_string() + &out + &\"db\".to_string();\n return out;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_decimal_to_binary() {\n assert!(decimal_to_binary(0) == \"db0db\".to_string());\n assert!(decimal_to_binary(32) == \"db100000db\".to_string());\n assert!(decimal_to_binary(103) == \"db1100111db\".to_string());\n assert!(decimal_to_binary(15) == \"db1111db\".to_string());\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut d_cp = decimal;\n let mut out: String = String::from(\"\");\n if d_cp == 0 {\n return \"db0d\".to_string();\n }\n while d_cp > 0 {\n out = (d_cp % 2).to_string() + &out;\n d_cp = d_cp / 2;\n }\n out = \"db\".to_string() + &out + &\"db\".to_string();\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "decimal_to_binary"}
|
81 |
{"task_id": "Rust/80", "prompt": "\n/*\nYou are given a string s.\n Your task is to check if the string is happy or not.\n A string is happy if its length is at least 3 and every 3 consecutive letters are distinct\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn is_happy(s:&str) -> bool{\n\n", "canonical_solution": "\n let str: Vec<char> = s.chars().into_iter().collect();\n if str.len() < 3 {\n return false;\n }\n for i in 2..str.len() {\n if str[i] == str[i - 1] || str[i] == str[i - 2] {\n return false;\n }\n }\n return true;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_is_happy() {\n assert!(is_happy(\"a\") == false);\n assert!(is_happy(\"aa\") == false);\n assert!(is_happy(\"abcd\") == true);\n assert!(is_happy(\"aabb\") == false);\n assert!(is_happy(\"adb\") == true);\n assert!(is_happy(\"xyy\") == false);\n assert!(is_happy(\"iopaxpoi\") == true);\n assert!(is_happy(\"iopaxioi\") == false);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let str: Vec<char> = s.chars().into_iter().collect();\n if str.len() < 3 {\n return false;\n }\n for i in 2..str.len() {\n if str[i] == str[i - 1] && str[i] == str[i - 2] {\n return false;\n }\n }\n return true;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "is_happy"}
|