{"task_id": "CPP/0", "prompt": "/\nCheck if in given vector of numbers, are any two numbers closer to each other than\ngiven threshold.\n>>> has_close_elements({1.0, 2.0, 3.0}, 0.5)\nfalse\n>>> has_close_elements({1.0, 2.8, 3.0, 4.0, 5.0, 2.0}, 0.3)\ntrue\n/\n#include<stdio.h>\n#include\n#include<math.h>\nusing namespace std;\nbool has_close_elements(vector numbers, float threshold){\n", "canonical_solution": " int i,j;\n \n for (i=0;i<numbers.size();i++)\n for (j=i+1;j<numbers.size();j++)\n if (abs(numbers[i]-numbers[j])<threshold)\n return true;\n\n return false;\n}\n\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n vector a={1.0, 2.0, 3.9, 4.0, 5.0, 2.2};\n assert (has_close_elements(a, 0.3)==true);\n assert (has_close_elements(a, 0.05) == false);\n\n assert (has_close_elements({1.0, 2.0, 5.9, 4.0, 5.0}, 0.95) == true);\n assert (has_close_elements({1.0, 2.0, 5.9, 4.0, 5.0}, 0.8) ==false);\n assert (has_close_elements({1.0, 2.0, 3.0, 4.0, 5.0}, 2.0) == true);\n assert (has_close_elements({1.1, 2.2, 3.1, 4.1, 5.1}, 1.0) == true);\n assert (has_close_elements({1.1, 2.2, 3.1, 4.1, 5.1}, 0.5) == false);\n \n}\n", "declaration": "#include<stdio.h>\n#include\n#include<math.h>\nusing namespace std;\n#include\n#include<stdlib.h>\nbool has_close_elements(vector numbers, float threshold){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (has_close_elements({1.0, 2.0, 3.0}, 0.5) == false && \"failure 1\");\n assert (has_close_elements({1.0, 2.8, 3.0, 4.0, 5.0, 2.0}, 0.3) && \"failure 2\") ;\n}\n"}
{"task_id": "CPP/1", "prompt": "/\nInput to this function is a string containing multiple groups of nested parentheses. Your goal is to\nseparate those group into separate strings and return the vector of those.\nSeparate groups are balanced (each open brace is properly closed) and not nested within each other\nIgnore any spaces in the input string.\n>>> separate_paren_groups(\"( ) (( )) (( )( ))\")\n{\"()\", \"(())\", \"(()())\"}\n/\n#include<stdio.h>\n#include\n#include\nusing namespace std;\nvector separate_paren_groups(string paren_string){\n", "canonical_solution": " vector all_parens;\n string current_paren;\n int level=0;\n char chr;\n int i;\n for (i=0;i<paren_string.length();i++)\n {\n chr=paren_string[i];\n if (chr=='(')\n {\n level+=1;\n current_paren+=chr;\n }\n if (chr==')')\n {\n level-=1;\n current_paren+=chr;\n if (level==0){\n all_parens.push_back(current_paren);\n current_paren=\"\";\n }\n }\n }\n return all_parens;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector a,vectorb){\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(separate_paren_groups(\"(()()) ((())) () ((())()())\"),{\"(()())\", \"((()))\", \"()\", \"((())()())\"}));\n assert (issame(separate_paren_groups(\"() (()) ((())) (((())))\"), {\"()\", \"(())\", \"((()))\", \"(((())))\" }));\n assert (issame(separate_paren_groups(\"(()(())((())))\") ,{ \"(()(())((())))\" }));\n assert (issame(separate_paren_groups(\"( ) (( )) (( )( ))\") ,{\"()\", \"(())\", \"(()())\"}));\n}", "declaration": "#include<stdio.h>\n#include\n#include\nusing namespace std;\n#include\n#include<math.h>\n#include<stdlib.h>\nvector separate_paren_groups(string paren_string){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector a,vectorb){\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(separate_paren_groups(\"( ) (( )) (( )( ))\") ,{\"()\", \"(())\", \"(()())\"}));\n}\n"}
{"task_id": "CPP/2", "prompt": "/\nGiven a positive floating point number, it can be decomposed into\nand integer part (largest integer smaller than given number) and decimals\n(leftover part always smaller than 1).\n\nReturn the decimal part of the number.\n>>> truncate_number(3.5)\n0.5\n/\n#include<stdio.h>\n#include<math.h>\nusing namespace std;\nfloat truncate_number(float number){\n", "canonical_solution": " return number-int(number);\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (truncate_number(3.5) == 0.5); \n assert (abs(truncate_number(1.33) - 0.33) < 1e-4);\n assert (abs(truncate_number(123.456) - 0.456) < 1e-4);\n}", "declaration": "#include<stdio.h>\n#include<math.h>\nusing namespace std;\n#include\n#include<stdlib.h>\nfloat truncate_number(float number){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (truncate_number(3.5) == 0.5); \n}\n"}
{"task_id": "CPP/3", "prompt": "/\nYou\"re given a vector of deposit and withdrawal operations on a bank account that starts with\nzero balance. Your task is to detect if at any point the balance of account falls below zero, and\nat that point function should return true. Otherwise it should return false.\n>>> below_zero({1, 2, 3})\nfalse\n>>> below_zero({1, 2, -4, 5})\ntrue\n/\n#include<stdio.h>\n#include\nusing namespace std;\nbool below_zero(vector operations){\n", "canonical_solution": " int num=0;\n for (int i=0;i<operations.size();i++)\n {\n num+=operations[i];\n if (num<0) return true;\n }\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (below_zero({}) == false);\n assert (below_zero({1, 2, -3, 1, 2, -3}) == false);\n assert (below_zero({1, 2, -4, 5, 6}) == true);\n assert (below_zero({1, -1, 2, -2, 5, -5, 4, -4}) == false);\n assert (below_zero({1, -1, 2, -2, 5, -5, 4, -5}) == true);\n assert (below_zero({1, -2, 2, -2, 5, -5, 4, -4}) == true);\n}", "declaration": "#include<stdio.h>\n#include\nusing namespace std;\n#include\n#include<math.h>\n#include<stdlib.h>\nbool below_zero(vector operations){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (below_zero({1, 2, 3}) == false);\n assert (below_zero({1, 2, -4, 5}) == true);\n}\n"}
{"task_id": "CPP/4", "prompt": "/\nFor a given vector of input numbers, calculate Mean Absolute Deviation\naround the mean of this dataset.\nMean Absolute Deviation is the average absolute difference between each\nelement and a centerpoint (mean in this case):\nMAD = average | x - x_mean |\n>>> mean_absolute_deviation({1.0, 2.0, 3.0, 4.0})\n1.0\n/\n#include<stdio.h>\n#include<math.h>\n#include\nusing namespace std;\nfloat mean_absolute_deviation(vector numbers){\n", "canonical_solution": " float sum=0;\n float avg,msum,mavg;\n int i=0;\n for (i=0;i<numbers.size();i++)\n sum+=numbers[i];\n avg=sum/numbers.size();\n msum=0;\n for (i=0;i<numbers.size();i++)\n msum+=abs(numbers[i]-avg);\n return msum/numbers.size();\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (abs(mean_absolute_deviation({1.0, 2.0, 3.0}) - 2.0/3.0) < 1e-4);\n assert (abs(mean_absolute_deviation({1.0, 2.0, 3.0, 4.0}) - 1.0) < 1e-4);\n assert (abs(mean_absolute_deviation({1.0, 2.0, 3.0, 4.0, 5.0}) - 6.0/5.0) < 1e-4);\n}", "declaration": "#include<stdio.h>\n#include<math.h>\n#include\nusing namespace std;\n#include\n#include<stdlib.h>\nfloat mean_absolute_deviation(vector numbers){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (abs(mean_absolute_deviation({1.0, 2.0, 3.0, 4.0}) - 1.0) < 1e-4);\n}\n"}
{"task_id": "CPP/5", "prompt": "/*\nInsert a number \"delimeter\" between every two consecutive elements of input vector numbers\"\n>>> intersperse({}, 4)\n{}\n>>> intersperse({1, 2, 3}, 4)\n{1, 4, 2, 4, 3}\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nvector<int> intersperse(vector<int> numbers, int delimeter){ \n", "canonical_solution": " vector<int> out={};\n if (numbers.size()>0) out.push_back(numbers[0]);\n for (int i=1;i<numbers.size();i++)\n {\n out.push_back(delimeter);\n out.push_back(numbers[i]);\n\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(intersperse({}, 7), {}));\n \n assert (issame(intersperse({5, 6, 3, 2}, 8),{5, 8, 6, 8, 3, 8, 2}));\n assert (issame(intersperse({2, 2, 2}, 2),{2, 2, 2, 2, 2}));\n}", "declaration": "#include<stdio.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nvector<int> intersperse(vector<int> numbers, int delimeter){ \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(intersperse({}, 4), {}));\n assert (issame(intersperse({1, 2, 3}, 4),{1, 4, 2, 4, 3}));\n}\n"} 
{"task_id": "Go/0", "prompt": "import (\n \"math\"\n)\n\n// Check if in given list of numbers, are any two numbers closer to each other than given threshold.\n// >>> HasCloseElements([]float64{1.0, 2.0, 3.0}, 0.5)\n// false\n// >>> HasCloseElements([]float64{1.0, 2.8, 3.0, 4.0, 5.0, 2.0}, 0.3)\n// true\nfunc HasCloseElements(numbers []float64, threshold float64) bool {\n", "import": "import (\n \"math\"\n)\n", "docstring": "// Check if in given list of numbers, are any two numbers closer to each other than given threshold.\n// >>> HasCloseElements([]float64{1.0, 2.0, 3.0}, 0.5)\n// false\n// >>> HasCloseElements([]float64{1.0, 2.8, 3.0, 4.0, 5.0, 2.0}, 0.3)\n// true\n", "declaration": "\nfunc HasCloseElements(numbers []float64, threshold float64) bool {\n", "canonical_solution": " for i := 0; i < len(numbers); i++ {\n for j := i + 1; j < len(numbers); j++ {\n var distance float64 = math.Abs(numbers[i] - numbers[j])\n if distance < threshold {\n return true\n }\n }\n }\n return false\n}\n\n", "test": "func TestHasCloseElements(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, HasCloseElements([]float64{11.0, 2.0, 3.9, 4.0, 5.0, 2.2}, 0.3))\n assert.Equal(false, HasCloseElements([]float64{1.0, 2.0, 3.9, 4.0, 5.0, 2.2}, 0.05))\n assert.Equal(true, HasCloseElements([]float64{1.0, 2.0, 5.9, 4.0, 5.0}, 0.95))\n assert.Equal(false, HasCloseElements([]float64{1.0, 2.0, 5.9, 4.0, 5.0}, 0.8))\n assert.Equal(true, HasCloseElements([]float64{1.0, 2.0, 3.0, 4.0, 5.0, 2.0}, 0.1))\n assert.Equal(true, HasCloseElements([]float64{1.1, 2.2, 3.1, 4.1, 5.1}, 1.0))\n assert.Equal(false, HasCloseElements([]float64{1.1, 2.2, 3.1, 4.1, 5.1}, 0.5))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestHasCloseElements(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(false, HasCloseElements([]float64{1.0, 2.0, 3.0}, 0.5))\n assert.Equal(true, HasCloseElements([]float64{1.0, 2.8, 3.0, 4.0, 5.0, 2.0}, 0.3))\n}\n"} 
{"task_id": "Go/1", "prompt": "\n// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n// separate those group into separate strings and return the list of those.\n// Separate groups are balanced (each open brace is properly closed) and not nested within each other\n// Ignore any spaces in the input string.\n// >>> SeparateParenGroups('( ) (( )) (( )( ))')\n// ['()', '(())', '(()())']\nfunc SeparateParenGroups(paren_string string) []string {\n", "import": "", "docstring": "// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n// separate those group into separate strings and return the list of those.\n// Separate groups are balanced (each open brace is properly closed) and not nested within each other\n// Ignore any spaces in the input string.\n// >>> SeparateParenGroups('( ) (( )) (( )( ))')\n// ['()', '(())', '(()())']\n", "declaration": "\nfunc SeparateParenGroups(paren_string string) []string {\n", "canonical_solution": " result := make([]string, 0)\n current_string := make([]rune, 0)\n current_depth := 0\n\n for _, c := range paren_string {\n if c == '(' {\n current_depth += 1\n current_string = append(current_string, c)\n }else if c== ')'{\n current_depth -= 1\n current_string = append(current_string, c)\n\n if current_depth == 0{\n result = append(result, string(current_string))\n current_string = make([]rune, 0)\n }\n }\n\n }\n return result\n}\n\n", "test": "func TestSeparateParenGroups(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]string{\"(()())\", \"((()))\", \"()\", \"((())()())\"}, SeparateParenGroups(\"(()()) ((())) () ((())()())\"))\n assert.Equal([]string{\"()\", \"(())\", \"((()))\", \"(((())))\"}, SeparateParenGroups(\"() (()) ((())) (((())))\"))\n assert.Equal([]string{\"(()(())((())))\"}, SeparateParenGroups(\"(()(())((())))\"))\n assert.Equal([]string{\"()\", \"(())\", \"(()())\"}, SeparateParenGroups(\"( ) (( )) (( )( ))\"))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestSeparateParenGroups(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]string{\"()\", \"(())\", \"(()())\"}, SeparateParenGroups(\"( ) (( )) (( )( ))\"))\n}\n"} 
{"task_id": "Go/2", "prompt": "import (\n \"math\"\n)\n\n// Given a positive floating point number, it can be decomposed into\n// and integer part (largest integer smaller than given number) and decimals\n// (leftover part always smaller than 1).\n// \n// Return the decimal part of the number.\n// >>> TruncateNumber(3.5)\n// 0.5\nfunc TruncateNumber(number float64) float64 {\n", "import": "import (\n \"math\"\n)\n", "docstring": "// Given a positive floating point number, it can be decomposed into\n// and integer part (largest integer smaller than given number) and decimals\n// (leftover part always smaller than 1).\n// \n// Return the decimal part of the number.\n// >>> TruncateNumber(3.5)\n// 0.5\n", "declaration": "\nfunc TruncateNumber(number float64) float64 {\n", "canonical_solution": " return math.Mod(number,1)\n}\n\n", "test": "func TestTruncateNumber(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(0.5, TruncateNumber(3.5))\n assert.Equal(true, math.Abs(TruncateNumber(1.33)-0.33) < 1e-6)\n assert.Equal(true, math.Abs(TruncateNumber(123.456)-0.456) < 1e-6)\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestTruncateNumber(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(0.5, TruncateNumber(3.5))\n}\n"} 
{"task_id": "Go/3", "prompt": "\n// You're given a list of deposit and withdrawal operations on a bank account that starts with\n// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n// at that point function should return true. Otherwise it should return false.\n// >>> BelowZero([1, 2, 3])\n// false\n// >>> BelowZero([1, 2, -4, 5])\n// true\nfunc BelowZero(operations []int) bool {\n", "import": "", "docstring": "// You're given a list of deposit and withdrawal operations on a bank account that starts with\n// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n// at that point function should return true. Otherwise it should return false.\n// >>> BelowZero([1, 2, 3])\n// false\n// >>> BelowZero([1, 2, -4, 5])\n// true\n", "declaration": "\nfunc BelowZero(operations []int) bool {\n", "canonical_solution": " balance := 0\n for _, op := range operations {\n balance += op\n if balance < 0 {\n return true\n }\n }\n return false\n}\n\n", "test": "func TestBelowZero(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(false, BelowZero([]int{}))\n assert.Equal(false, BelowZero([]int{1, 2, -3, 1, 2, -3}))\n assert.Equal(true, BelowZero([]int{1, 2, -4, 5, 6}))\n assert.Equal(false, BelowZero([]int{1, -1, 2, -2, 5, -5, 4, -4}))\n assert.Equal(true, BelowZero([]int{1, -1, 2, -2, 5, -5, 4, -5}))\n assert.Equal(true, BelowZero([]int{1, -2, 2, -2, 5, -5, 4, -4}))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestBelowZero(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(false, BelowZero([]int{1, 2, 3}))\n assert.Equal(true, BelowZero([]int{1, 2, -4, 5}))\n}\n"} 
{"task_id": "Go/4", "prompt": "import (\n \"math\"\n)\n\n// For a given list of input numbers, calculate Mean Absolute Deviation\n// around the mean of this dataset.\n// Mean Absolute Deviation is the average absolute difference between each\n// element and a centerpoint (mean in this case):\n// MAD = average | x - x_mean |\n// >>> MeanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0])\n// 1.0\nfunc MeanAbsoluteDeviation(numbers []float64) float64 {\n", "import": "import (\n \"math\"\n)\n", "docstring": "// For a given list of input numbers, calculate Mean Absolute Deviation\n// around the mean of this dataset.\n// Mean Absolute Deviation is the average absolute difference between each\n// element and a centerpoint (mean in this case):\n// MAD = average | x - x_mean |\n// >>> MeanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0])\n// 1.0\n", "declaration": "\nfunc MeanAbsoluteDeviation(numbers []float64) float64 {\n", "canonical_solution": " sum := func(numbers []float64) float64 {\n sum := 0.0\n for _, num := range numbers {\n sum += num\n }\n return sum\n }\n\n mean := sum(numbers) / float64(len(numbers))\n numList := make([]float64, 0)\n for _, x := range numbers {\n numList = append(numList, math.Abs(x-mean))\n }\n return sum(numList) / float64(len(numbers))\n}\n\n", "test": "func TestMeanAbsoluteDeviation(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, math.Abs(MeanAbsoluteDeviation([]float64{1.0, 2.0, 3.0})-2.0/3.0) < 1e-6)\n assert.Equal(true, math.Abs(MeanAbsoluteDeviation([]float64{1.0, 2.0, 3.0, 4.0})-1.0) < 1e-6)\n assert.Equal(true, math.Abs(MeanAbsoluteDeviation([]float64{1.0, 2.0, 3.0, 4.0, 5.0})-6.0/5.0) < 1e-6)\n\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestMeanAbsoluteDeviation(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, math.Abs(MeanAbsoluteDeviation([]float64{1.0, 2.0, 3.0, 4.0})-1.0) < 1e-6)\n}\n"} 
{"task_id": "Go/5", "prompt": "\n// Insert a number 'delimeter' between every two consecutive elements of input list numbers'\n// >>> Intersperse([], 4)\n// []\n// >>> Intersperse([1, 2, 3], 4)\n// [1, 4, 2, 4, 3]\nfunc Intersperse(numbers []int, delimeter int) []int {\n", "import": "", "docstring": "// Insert a number 'delimeter' between every two consecutive elements of input list numbers'\n// >>> Intersperse([], 4)\n// []\n// >>> Intersperse([1, 2, 3], 4)\n// [1, 4, 2, 4, 3]\n", "declaration": "\nfunc Intersperse(numbers []int, delimeter int) []int {\n", "canonical_solution": " result := make([]int, 0)\n if len(numbers) == 0 {\n return result\n }\n for i := 0; i < len(numbers)-1; i++ {\n n := numbers[i]\n result = append(result, n)\n result = append(result, delimeter)\n }\n result = append(result, numbers[len(numbers)-1])\n return result\n}\n\n", "test": "func TestIntersperse(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]int{}, Intersperse([]int{}, 7))\n assert.Equal([]int{5, 8, 6, 8, 3, 8, 2}, Intersperse([]int{5, 6, 3, 2}, 8))\n assert.Equal([]int{2, 2, 2, 2, 2}, Intersperse([]int{2, 2, 2}, 2))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestIntersperse(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]int{}, Intersperse([]int{}, 4))\n assert.Equal([]int{1,4,2,4,3}, Intersperse([]int{1,2,3}, 4))\n}\n"} 
{"task_id": "Java/0", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Check if in given list of numbers, are any two numbers closer to each other than given threshold.\n >>> hasCloseElements(Arrays.asList(1.0, 2.0, 3.0), 0.5)\n false\n >>> hasCloseElements(Arrays.asList(1.0, 2.8, 3.0, 4.0, 5.0, 2.0), 0.3)\n true\n */\n public boolean hasCloseElements(List<Double> numbers, double threshold) {\n", "canonical_solution": " for (int i = 0; i < numbers.size(); i++) {\n for (int j = i + 1; j < numbers.size(); j++) {\n double distance = Math.abs(numbers.get(i) - numbers.get(j));\n if (distance < threshold) return true;\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.hasCloseElements(new ArrayList<>(Arrays.asList(11.0, 2.0, 3.9, 4.0, 5.0, 2.2)), 0.3),\n !s.hasCloseElements(new ArrayList<>(Arrays.asList(1.0, 2.0, 3.9, 4.0, 5.0, 2.2)), 0.05),\n s.hasCloseElements(new ArrayList<>(Arrays.asList(1.0, 2.0, 5.9, 4.0, 5.0)), 0.95),\n !s.hasCloseElements(new ArrayList<>(Arrays.asList(1.0, 2.0, 5.9, 4.0, 5.0)), 0.8),\n s.hasCloseElements(new ArrayList<>(Arrays.asList(1.0, 2.0, 3.0, 4.0, 5.0, 2.0)), 0.1),\n s.hasCloseElements(new ArrayList<>(Arrays.asList(1.1, 2.2, 3.1, 4.1, 5.1)), 1.0),\n !s.hasCloseElements(new ArrayList<>(Arrays.asList(1.1, 2.2, 3.1, 4.1, 5.1)), 0.5)\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Check if in given list of numbers, are any two numbers closer to each other than given threshold.\n >>> hasCloseElements(Arrays.asList(1.0, 2.0, 3.0), 0.5)\n false\n >>> hasCloseElements(Arrays.asList(1.0, 2.8, 3.0, 4.0, 5.0, 2.0), 0.3)\n true", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean hasCloseElements(List<Double> numbers, double threshold) {\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.hasCloseElements(new ArrayList<>(Arrays.asList(1.0, 2.0, 3.0)), 0.5),\n s.hasCloseElements(new ArrayList<>(Arrays.asList(1.0, 2.8, 3.0, 4.0, 5.0, 2.0)), 0.3)\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n"} 
{"task_id": "Java/1", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n separate those group into separate strings and return the list of those.\n Separate groups are balanced (each open brace is properly closed) and not nested within each other\n Ignore any spaces in the input string.\n >>> separateParenGroups(\"( ) (( )) (( )( ))\")\n [\"()\", \"(())\", \"(()())\"]\n */\n public List<String> separateParenGroups(String paren_string) {\n", "canonical_solution": " List<String> result = new ArrayList<>();\n StringBuilder current_string = new StringBuilder();\n int current_depth = 0;\n\n for (char c : paren_string.toCharArray()) {\n if (c == '(') {\n current_depth += 1;\n current_string.append(c);\n } else if (c == ')') {\n current_depth -= 1;\n current_string.append(c);\n\n if (current_depth == 0) {\n result.add(current_string.toString());\n current_string.setLength(0);\n }\n }\n }\n return result;\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.separateParenGroups(\"(()()) ((())) () ((())()())\").equals(Arrays.asList(\n \"(()())\", \"((()))\", \"()\", \"((())()())\"\n )),\n s.separateParenGroups(\"() (()) ((())) (((())))\").equals(Arrays.asList(\n \"()\", \"(())\", \"((()))\", \"(((())))\"\n )),\n s.separateParenGroups(\"(()(())((())))\").equals(Arrays.asList(\n \"(()(())((())))\"\n )),\n s.separateParenGroups(\"( ) (( )) (( )( ))\").equals(Arrays.asList(\"()\", \"(())\", \"(()())\"))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n separate those group into separate strings and return the list of those.\n Separate groups are balanced (each open brace is properly closed) and not nested within each other\n Ignore any spaces in the input string.\n >>> separateParenGroups(\"( ) (( )) (( )( ))\")\n [\"()\", \"(())\", \"(()())\"]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<String> separateParenGroups(String paren_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.separateParenGroups(\"( ) (( )) (( )( ))\").equals(Arrays.asList(\"()\", \"(())\", \"(()())\"))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n"} 
{"task_id": "Java/2", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n\n Return the decimal part of the number.\n >>> truncateNumber(3.5)\n 0.5\n */\n public double truncateNumber(double number) {\n", "canonical_solution": " return number % 1.0;\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.truncateNumber(3.5) == 0.5,\n Math.abs(s.truncateNumber(1.33) - 0.33) < 1e-6,\n Math.abs(s.truncateNumber(123.456) - 0.456) < 1e-6\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n\n Return the decimal part of the number.\n >>> truncateNumber(3.5)\n 0.5", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public double truncateNumber(double number) {\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.truncateNumber(3.5) == 0.5\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n"} 
{"task_id": "Java/3", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You're given a list of deposit and withdrawal operations on a bank account that starts with\n zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n at that point function should return True. Otherwise it should return False.\n >>> belowZero(Arrays.asList(1, 2, 3))\n false\n >>> belowZero(Arrays.asList(1, 2, -4, 5))\n true\n */\n public boolean belowZero(List<Integer> operations) {\n", "canonical_solution": " int balance = 0;\n\n for (int op : operations) {\n balance += op;\n if (balance < 0) {\n return true;\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.belowZero(new ArrayList<>(Arrays.asList())),\n !s.belowZero(new ArrayList<>(Arrays.asList(1, 2, -3, 1, 2, -3))),\n s.belowZero(new ArrayList<>(Arrays.asList(1, 2, -4, 5, 6))),\n !s.belowZero(new ArrayList<>(Arrays.asList(1, -1, 2, -2, 5, -5, 4, -4))),\n s.belowZero(new ArrayList<>(Arrays.asList(1, -1, 2, -2, 5, -5, 4, -5))),\n s.belowZero(new ArrayList<>(Arrays.asList(1, -2, 2, -2, 5, -5, 4, -4)))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You're given a list of deposit and withdrawal operations on a bank account that starts with\n zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n at that point function should return True. Otherwise it should return False.\n >>> belowZero(Arrays.asList(1, 2, 3))\n false\n >>> belowZero(Arrays.asList(1, 2, -4, 5))\n true", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean belowZero(List<Integer> operations) {\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.belowZero(new ArrayList<>(Arrays.asList(1, 2, 3))),\n s.belowZero(new ArrayList<>(Arrays.asList(1, 2, -4, 5)))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n"} 
{"task_id": "Java/4", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n For a given list of input numbers, calculate Mean Absolute Deviation\n around the mean of this dataset.\n Mean Absolute Deviation is the average absolute difference between each\n element and a centerpoint (mean in this case):\n MAD = average | x - x_mean |\n >>> meanAbsoluteDeviation(Arrays.asList(1.0, 2.0, 3.0, 4.0))\n 1.0\n */\n public double meanAbsoluteDeviation(List<Double> numbers) {\n", "canonical_solution": " double sum = 0.0;\n for (double num : numbers) {\n sum += num;\n }\n double mean = sum / numbers.size();\n double sum_abs_diff = 0.0;\n for (double num : numbers) {\n sum_abs_diff += Math.abs(num - mean);\n }\n return sum_abs_diff / numbers.size();\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 Math.abs(s.meanAbsoluteDeviation(new ArrayList<>(Arrays.asList(1.0, 2.0, 3.0))) - 2.0/3.0) < 1e-6,\n Math.abs(s.meanAbsoluteDeviation(new ArrayList<>(Arrays.asList(1.0, 2.0, 3.0, 4.0))) - 1.0) < 1e-6,\n Math.abs(s.meanAbsoluteDeviation(new ArrayList<>(Arrays.asList(1.0, 2.0, 3.0, 4.0, 5.0))) - 6.0/5.0) < 1e-6\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " For a given list of input numbers, calculate Mean Absolute Deviation\n around the mean of this dataset.\n Mean Absolute Deviation is the average absolute difference between each\n element and a centerpoint (mean in this case):\n MAD = average | x - x_mean |\n >>> meanAbsoluteDeviation(Arrays.asList(1.0, 2.0, 3.0, 4.0))\n 1.0", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public double meanAbsoluteDeviation(List<Double> numbers) {\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 Math.abs(s.meanAbsoluteDeviation(new ArrayList<>(Arrays.asList(1.0, 2.0, 3.0, 4.0))) - 1.0) < 1e-6\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n"} 
{"task_id": "JavaScript/0", "prompt": "/* Check if in given list of numbers, are any two numbers closer to each other than\n given threshold.\n >>> hasCloseElements([1.0, 2.0, 3.0], 0.5)\n false\n >>> hasCloseElements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)\n true\n */\nconst hasCloseElements = (numbers, threshold) => {\n", "canonical_solution": " for (let i = 0; i < numbers.length; i++) {\n for (let j = 0; j < numbers.length; j++) {\n if (i != j) {\n let distance = Math.abs(numbers[i] - numbers[j]);\n if (distance < threshold) {\n return true;\n }\n }\n }\n }\n return false;\n}\n\n", "test": "const testHasCloseElements = () => {\n console.assert(hasCloseElements([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.3) === true)\n console.assert(\n hasCloseElements([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.05) === false\n )\n console.assert(hasCloseElements([1.0, 2.0, 5.9, 4.0, 5.0], 0.95) === true)\n console.assert(hasCloseElements([1.0, 2.0, 5.9, 4.0, 5.0], 0.8) === false)\n console.assert(hasCloseElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0], 0.1) === true)\n console.assert(hasCloseElements([1.1, 2.2, 3.1, 4.1, 5.1], 1.0) === true)\n console.assert(hasCloseElements([1.1, 2.2, 3.1, 4.1, 5.1], 0.5) === false)\n}\n\ntestHasCloseElements()\n", "declaration": "\nconst hasCloseElements = (numbers, threshold) => {\n", "example_test": "const testHasCloseElements = () => {\n console.assert(hasCloseElements([1.0, 2.0, 3.0], 0.5) === false)\n console.assert(\n hasCloseElements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3) === true\n )\n}\ntestHasCloseElements()\n"} 
{"task_id": "JavaScript/1", "prompt": "/* Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n separate those group into separate strings and return the list of those.\n Separate groups are balanced (each open brace is properly closed) and not nested within each other\n Ignore any spaces in the input string.\n >>> separateParenGroups('( ) (( )) (( )( ))')\n ['()', '(())', '(()())']\n */\nconst separateParenGroups = (paren_string) => {\n", "canonical_solution": " var result = [];\n var current_string = [];\n var current_depth = 0;\n\n for (const c of paren_string) {\n if (c == '(') {\n current_depth += 1;\n current_string.push(c);\n } else if (c == ')') {\n current_depth -= 1;\n current_string.push(c);\n if (current_depth == 0) {\n result.push(current_string.join(''));\n current_string = [];\n }\n }\n }\n\n return result;\n}\n\n", "test": "const testSeparateParenGroups = () => {\n console.assert(\n JSON.stringify(separateParenGroups('(()()) ((())) () ((())()())')) ===\n JSON.stringify(['(()())', '((()))', '()', '((())()())'])\n )\n console.assert(\n JSON.stringify(separateParenGroups('() (()) ((())) (((())))')) ===\n JSON.stringify(['()', '(())', '((()))', '(((())))'])\n )\n console.assert(\n JSON.stringify(separateParenGroups('(()(())((())))')) ===\n JSON.stringify(['(()(())((())))'])\n )\n console.assert(\n JSON.stringify(separateParenGroups('( ) (( )) (( )( ))')) ===\n JSON.stringify(['()', '(())', '(()())'])\n )\n}\n\ntestSeparateParenGroups()\n", "declaration": "\nconst separateParenGroups = (paren_string) => {\n", "example_test": "const testSeparateParenGroups = () => {\n console.assert(\n JSON.stringify(separateParenGroups('( ) (( )) (( )( ))')) ===\n JSON.stringify(['()', '(())', '(()())'])\n )\n}\ntestSeparateParenGroups()\n"} 
{"task_id": "JavaScript/2", "prompt": "/* Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n\n Return the decimal part of the number.\n >>> truncateNumber(3.5)\n 0.5\n */\nconst truncateNumber = (number) => {\n", "canonical_solution": " return number % 1.0;\n}\n\n", "test": "const testTruncateNumber = () => {\n console.assert(truncateNumber(3.5) === 0.5)\n\n console.assert(Math.abs(truncateNumber(1.33) - 0.33) < 1e-6)\n\n console.assert(Math.abs(truncateNumber(123.456 - 0.456) < 1e-6))\n}\n\ntestTruncateNumber()\n", "declaration": "\nconst truncateNumber = (number) => {\n", "example_test": "const testTruncateNumber = () => {\n console.assert(truncateNumber(3.5) === 0.5)\n}\ntestTruncateNumber()\n"} 
{"task_id": "JavaScript/3", "prompt": "/* You're given a list of deposit and withdrawal operations on a bank account that starts with\n zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n at that point function should return true. Otherwise it should return false.\n >>> belowZero([1, 2, 3])\n false\n >>> belowZero([1, 2, -4, 5])\n true\n */\nconst belowZero = (operations) => {\n", "canonical_solution": " var balance = 0;\n for (const op of operations) {\n balance += op;\n if (balance < 0) {\n return true;\n }\n }\n return false;\n}\n\n", "test": "const testBelowZero = () => {\n console.assert(belowZero([]) === false)\n console.assert(belowZero([1, 2, -3, 1, 2, -3]) === false)\n console.assert(belowZero([1, 2, -4, 5, 6]) === true)\n console.assert(belowZero([1, -1, 2, -2, 5, -5, 4, -4]) === false)\n console.assert(belowZero([1, -1, 2, -2, 5, -5, 4, -5]) === true)\n console.assert(belowZero([1, -2, 2, -2, 5, -5, 4, -4]) === true)\n}\n\ntestBelowZero()\n", "declaration": "\nconst belowZero = (operations) => {\n", "example_test": "const testBelowZero = () => {\n console.assert(belowZero([1, 2, 3]) === false)\n console.assert(belowZero([1, 2, -4, 5]) === true)\n}\ntestBelowZero()\n"} 
{"task_id": "JavaScript/4", "prompt": "/* For a given list of input numbers, calculate Mean Absolute Deviation\n around the mean of this dataset.\n Mean Absolute Deviation is the average absolute difference between each\n element and a centerpoint (mean in this case):\n MAD = average | x - x_mean |\n >>> meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0])\n 1.0\n */\nconst meanAbsoluteDeviation = (numbers) => {\n", "canonical_solution": " var mean = numbers.reduce((prev, item) => {\n return prev + item;\n }, 0) / numbers.length;\n return numbers.reduce((prev, item) => {\n return prev + Math.abs(item - mean);\n }, 0) / numbers.length;\n\n}\n\n", "test": "const testMeanAbsoluteDeviation = () => {\n console.assert(\n Math.abs(meanAbsoluteDeviation([1.0, 2.0, 3.0]) - 2.0 / 3.0) < 1e-6\n )\n console.assert(\n Math.abs(meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0]) - 1.0) < 1e-6\n )\n console.assert(\n Math.abs(meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0, 5.0]) - 6.0 / 5.0) < 1e-6\n )\n}\n\ntestMeanAbsoluteDeviation()\n", "declaration": "\nconst meanAbsoluteDeviation = (numbers) => {\n", "example_test": "const testMeanAbsoluteDeviation = () => {\n console.assert(\n Math.abs(meanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0]) - 1.0) < 1e-6\n )\n}\ntestMeanAbsoluteDeviation()\n"} 
{"task_id": "JavaScript/5", "prompt": "/* Insert a number 'delimeter' between every two consecutive elements of input list numbers'\n >>> intersperse([], 4)\n []\n >>> intersperse([1, 2, 3], 4)\n [1, 4, 2, 4, 3]\n */\nconst intersperse = (numbers, delimeter) => {\n", "canonical_solution": " if (!Array.isArray(numbers) || numbers.length == 0)\n return [];\n var result = [];\n for (const n of numbers) {\n result.push(n, delimeter);\n }\n result.pop();\n return result;\n}\n\n", "test": "const testIntersperse = () => {\n console.assert(JSON.stringify(intersperse([], 7)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(\n intersperse([5, 6, 3, 2], 8)) === JSON.stringify([5, 8, 6, 8, 3, 8, 2])\n )\n console.assert(\n JSON.stringify(\n intersperse([2, 2, 2], 2)) === JSON.stringify([2, 2, 2, 2, 2])\n )\n}\n\ntestIntersperse()\n", "declaration": "\nconst intersperse = (numbers, delimeter) => {\n", "example_test": "const testIntersperse = () => {\n console.assert(JSON.stringify(intersperse([], 4)) === JSON.stringify([]))\n console.assert(\n JSON.stringify(\n intersperse([1,2,3], 4)) === JSON.stringify([1,4,2,4,3])\n )\n}\ntestIntersperse()\n"}
{"task_id": "Python/0", "prompt": "from typing import List\n\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n \"\"\" Check if in given list of numbers, are any two numbers closer to each other than\n given threshold.\n >>> has_close_elements([1.0, 2.0, 3.0], 0.5)\n False\n >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)\n True\n \"\"\"\n", "canonical_solution": " for idx, elem in enumerate(numbers):\n for idx2, elem2 in enumerate(numbers):\n if idx != idx2:\n distance = abs(elem - elem2)\n if distance < threshold:\n return True\n\n return False\n", "test": "\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(has_close_elements):\n assert has_close_elements([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.3) == True\n assert has_close_elements([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.05) == False\n assert has_close_elements([1.0, 2.0, 5.9, 4.0, 5.0], 0.95) == True\n assert has_close_elements([1.0, 2.0, 5.9, 4.0, 5.0], 0.8) == False\n assert has_close_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0], 0.1) == True\n assert has_close_elements([1.1, 2.2, 3.1, 4.1, 5.1], 1.0) == True\n assert has_close_elements([1.1, 2.2, 3.1, 4.1, 5.1], 0.5) == False\n\ncheck(has_close_elements)", "text": " Check if in given list of numbers, are any two numbers closer to each other than\n given threshold.\n >>> has_close_elements([1.0, 2.0, 3.0], 0.5)\n False\n >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)\n True", "declaration": "from typing import List\n\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n", "example_test": "def check(has_close_elements):\n assert has_close_elements([1.0, 2.0, 3.0], 0.5) == False\n assert has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3) == True\ncheck(has_close_elements)\n"}
{"task_id": "Python/1", "prompt": "from typing import List\n\n\ndef separate_paren_groups(paren_string: str) -> List[str]:\n \"\"\" Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n separate those group into separate strings and return the list of those.\n Separate groups are balanced (each open brace is properly closed) and not nested within each other\n Ignore any spaces in the input string.\n >>> separate_paren_groups('( ) (( )) (( )( ))')\n ['()', '(())', '(()())']\n \"\"\"\n", "canonical_solution": " result = []\n current_string = []\n current_depth = 0\n\n for c in paren_string:\n if c == '(':\n current_depth += 1\n current_string.append(c)\n elif c == ')':\n current_depth -= 1\n current_string.append(c)\n\n if current_depth == 0:\n result.append(''.join(current_string))\n current_string.clear()\n\n return result\n", "test": "\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(separate_paren_groups):\n assert separate_paren_groups('(()()) ((())) () ((())()())') == [\n '(()())', '((()))', '()', '((())()())'\n ]\n assert separate_paren_groups('() (()) ((())) (((())))') == [\n '()', '(())', '((()))', '(((())))'\n ]\n assert separate_paren_groups('(()(())((())))') == [\n '(()(())((())))'\n ]\n assert separate_paren_groups('( ) (( )) (( )( ))') == ['()', '(())', '(()())']\n\ncheck(separate_paren_groups)", "text": " Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n separate those group into separate strings and return the list of those.\n Separate groups are balanced (each open brace is properly closed) and not nested within each other\n Ignore any spaces in the input string.\n >>> separate_paren_groups('( ) (( )) (( )( ))')\n ['()', '(())', '(()())']", "declaration": "from typing import List\n\n\ndef separate_paren_groups(paren_string: str) -> List[str]:\n", "example_test": "def check(separate_paren_groups):\n assert separate_paren_groups('( ) (( )) (( )( ))') == ['()', '(())', '(()())']\ncheck(separate_paren_groups)\n"}
{"task_id": "Python/2", "prompt": "\n\ndef truncate_number(number: float) -> float:\n \"\"\" Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n\n Return the decimal part of the number.\n >>> truncate_number(3.5)\n 0.5\n \"\"\"\n", "canonical_solution": " return number % 1.0\n", "test": "\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(truncate_number):\n assert truncate_number(3.5) == 0.5\n assert abs(truncate_number(1.33) - 0.33) < 1e-6\n assert abs(truncate_number(123.456) - 0.456) < 1e-6\n\ncheck(truncate_number)", "text": " Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n\n Return the decimal part of the number.\n >>> truncate_number(3.5)\n 0.5", "declaration": "def truncate_number(number: float) -> float:\n", "example_test": "def check(truncate_number):\n assert truncate_number(3.5) == 0.5\ncheck(truncate_number)\n"}
{"task_id": "Python/3", "prompt": "from typing import List\n\n\ndef below_zero(operations: List[int]) -> bool:\n \"\"\" You're given a list of deposit and withdrawal operations on a bank account that starts with\n zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n at that point function should return True. Otherwise it should return False.\n >>> below_zero([1, 2, 3])\n False\n >>> below_zero([1, 2, -4, 5])\n True\n \"\"\"\n", "canonical_solution": " balance = 0\n\n for op in operations:\n balance += op\n if balance < 0:\n return True\n\n return False\n", "test": "\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(below_zero):\n assert below_zero([]) == False\n assert below_zero([1, 2, -3, 1, 2, -3]) == False\n assert below_zero([1, 2, -4, 5, 6]) == True\n assert below_zero([1, -1, 2, -2, 5, -5, 4, -4]) == False\n assert below_zero([1, -1, 2, -2, 5, -5, 4, -5]) == True\n assert below_zero([1, -2, 2, -2, 5, -5, 4, -4]) == True\n\ncheck(below_zero)", "text": " You're given a list of deposit and withdrawal operations on a bank account that starts with\n zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n at that point function should return True. Otherwise it should return False.\n >>> below_zero([1, 2, 3])\n False\n >>> below_zero([1, 2, -4, 5])\n True", "declaration": "from typing import List\n\n\ndef below_zero(operations: List[int]) -> bool:\n", "example_test": "def check(below_zero):\n assert below_zero([1, 2, 3]) == False\n assert below_zero([1, 2, -4, 5]) == True\ncheck(below_zero)\n"}
{"task_id": "Python/4", "prompt": "from typing import List\n\n\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n \"\"\" For a given list of input numbers, calculate Mean Absolute Deviation\n around the mean of this dataset.\n Mean Absolute Deviation is the average absolute difference between each\n element and a centerpoint (mean in this case):\n MAD = average | x - x_mean |\n >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])\n 1.0\n \"\"\"\n", "canonical_solution": " mean = sum(numbers) / len(numbers)\n return sum(abs(x - mean) for x in numbers) / len(numbers)\n", "test": "\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(mean_absolute_deviation):\n assert abs(mean_absolute_deviation([1.0, 2.0, 3.0]) - 2.0/3.0) < 1e-6\n assert abs(mean_absolute_deviation([1.0, 2.0, 3.0, 4.0]) - 1.0) < 1e-6\n assert abs(mean_absolute_deviation([1.0, 2.0, 3.0, 4.0, 5.0]) - 6.0/5.0) < 1e-6\n\ncheck(mean_absolute_deviation)", "text": " For a given list of input numbers, calculate Mean Absolute Deviation\n around the mean of this dataset.\n Mean Absolute Deviation is the average absolute difference between each\n element and a centerpoint (mean in this case):\n MAD = average | x - x_mean |\n >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])\n 1.0", "declaration": "from typing import List\n\n\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n", "example_test": "def check(mean_absolute_deviation):\n assert abs(mean_absolute_deviation([1.0, 2.0, 3.0, 4.0]) - 1.0) < 1e-6\ncheck(mean_absolute_deviation)\n"}
{"task_id": "Python/5", "prompt": "from typing import List\n\n\ndef intersperse(numbers: List[int], delimeter: int) -> List[int]:\n \"\"\" Insert a number 'delimeter' between every two consecutive elements of input list numbers'\n >>> intersperse([], 4)\n []\n >>> intersperse([1, 2, 3], 4)\n [1, 4, 2, 4, 3]\n \"\"\"\n", "canonical_solution": " if not numbers:\n return []\n\n result = []\n\n for n in numbers[:-1]:\n result.append(n)\n result.append(delimeter)\n\n result.append(numbers[-1])\n\n return result\n", "test": "\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(intersperse):\n assert intersperse([], 7) == []\n assert intersperse([5, 6, 3, 2], 8) == [5, 8, 6, 8, 3, 8, 2]\n assert intersperse([2, 2, 2], 2) == [2, 2, 2, 2, 2]\n\ncheck(intersperse)", "text": " Insert a number 'delimeter' between every two consecutive elements of input list numbers'\n >>> intersperse([], 4)\n []\n >>> intersperse([1, 2, 3], 4)\n [1, 4, 2, 4, 3]", "declaration": "from typing import List\n\n\ndef intersperse(numbers: List[int], delimeter: int) -> List[int]:\n", "example_test": "def check(intersperse):\n assert intersperse([], 4) == []\n assert intersperse([1,2,3], 4) == [1,4,2,4,3]\ncheck(intersperse)\n"}