Commit
·
01f1eb7
1
Parent(s):
4e38633
Fix bugs
Browse files
data/go/data/humanevalbugs.jsonl
CHANGED
@@ -30,7 +30,7 @@
|
|
30 |
{"task_id": "Go/29", "prompt": "\n// Filter an input list of strings only for ones that start with a given prefix.\n// >>> FilterByPrefix([], 'a')\n// []\n// >>> FilterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n// ['abc', 'array']\nfunc FilterByPrefix(strings []string,prefix string) []string {\n", "import": "", "docstring": "// Filter an input list of strings only for ones that start with a given prefix.\n// >>> FilterByPrefix([], 'a')\n// []\n// >>> FilterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n// ['abc', 'array']\n", "declaration": "\nfunc FilterByPrefix(strings []string,prefix string) []string {\n", "canonical_solution": " if len(strings) == 0 {\n return []string{}\n }\n res := make([]string, 0, len(strings))\n\tfor _, s := range strings {\n\t\tif s[:len(prefix)] == prefix {\n\t\t\tres = append(res, s)\n\t\t}\n\t}\n\treturn res\n}\n\n\n", "test": "func TestFilterByPrefix(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]string{}, FilterByPrefix([]string{}, \"john\"))\n assert.Equal([]string{\"xxx\", \"xxxAAA\", \"xxx\"}, FilterByPrefix([]string{\"xxx\", \"asd\", \"xxy\", \"john doe\", \"xxxAAA\", \"xxx\"}, \"xxx\"))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestFilterByPrefix(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]string{}, FilterByPrefix([]string{}, \"a\"))\n assert.Equal([]string{\"abc\", \"array\"}, FilterByPrefix([]string{\"abc\", \"bcd\", \"cde\", \"array\"}, \"a\"))\n}\n", "buggy_solution": " if len(strings) == 0 {\n return []string{}\n }\n res := make([]string, 0, len(strings))\n\tfor _, s := range strings {\n\t\tif s[:len(prefix)] != prefix {\n\t\t\tres = append(res, s)\n\t\t}\n\t}\n\treturn res\n}\n\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "FilterByPrefix"}
|
31 |
{"task_id": "Go/30", "prompt": "\n// Return only positive numbers in the list.\n// >>> GetPositive([-1, 2, -4, 5, 6])\n// [2, 5, 6]\n// >>> GetPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n// [5, 3, 2, 3, 9, 123, 1]\nfunc GetPositive(l []int) []int {\n", "import": "", "docstring": "// Return only positive numbers in the list.\n// >>> GetPositive([-1, 2, -4, 5, 6])\n// [2, 5, 6]\n// >>> GetPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n// [5, 3, 2, 3, 9, 123, 1]\n", "declaration": "\nfunc GetPositive(l []int) []int {\n", "canonical_solution": " res := make([]int, 0)\n for _, x := range l {\n if x > 0 {\n res = append(res, x)\n }\n }\n return res\n}\n\n\n", "test": "func TestGetPositive(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]int{4, 5, 6}, GetPositive([]int{-1, -2, 4,5, 6}))\n assert.Equal([]int{5, 3, 2, 3, 3, 9, 123, 1}, GetPositive([]int{5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10}))\n assert.Equal([]int{}, GetPositive([]int{-1, -2}))\n assert.Equal([]int{}, GetPositive([]int{}))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestGetPositive(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]int{2, 5, 6}, GetPositive([]int{-1, 2, -4,5, 6}))\n assert.Equal([]int{5, 3, 2, 3, 9, 123, 1}, GetPositive([]int{5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10}))\n}\n", "buggy_solution": " res := make([]int, 0)\n for _, x := range l {\n if x < 0 {\n res = append(res, x)\n }\n }\n return res\n}\n\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "GetPositive"}
|
32 |
{"task_id": "Go/31", "prompt": "\n// Return true if a given number is prime, and false otherwise.\n// >>> IsPrime(6)\n// false\n// >>> IsPrime(101)\n// true\n// >>> IsPrime(11)\n// true\n// >>> IsPrime(13441)\n// true\n// >>> IsPrime(61)\n// true\n// >>> IsPrime(4)\n// false\n// >>> IsPrime(1)\n// false\nfunc IsPrime(n int) bool {\n", "import": "", "docstring": "// Return true if a given number is prime, and false otherwise.\n// >>> IsPrime(6)\n// false\n// >>> IsPrime(101)\n// true\n// >>> IsPrime(11)\n// true\n// >>> IsPrime(13441)\n// true\n// >>> IsPrime(61)\n// true\n// >>> IsPrime(4)\n// false\n// >>> IsPrime(1)\n// false\n", "declaration": "\nfunc IsPrime(n int) bool {\n", "canonical_solution": " if n <= 1 {\n\t\treturn false\n\t}\n\tif n == 2 {\n\t\treturn true\n\t}\n\tif n%2 == 0 {\n\t\treturn false\n\t}\n\tfor i := 3; i*i <= n; i += 2 {\n\t\tif n%i == 0 {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n\n", "test": "func TestIsPrime(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(false, IsPrime(6))\n assert.Equal(true, IsPrime(101))\n assert.Equal(true, IsPrime(11))\n assert.Equal(true, IsPrime(13441))\n assert.Equal(true, IsPrime(61))\n assert.Equal(false, IsPrime(4))\n assert.Equal(false, IsPrime(1))\n assert.Equal(true, IsPrime(5))\n assert.Equal(true, IsPrime(11))\n assert.Equal(true, IsPrime(17))\n assert.Equal(false, IsPrime(5 * 17))\n assert.Equal(false, IsPrime(11 * 7))\n assert.Equal(false, IsPrime(13441 * 19))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestIsPrime(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(false, IsPrime(6))\n assert.Equal(true, IsPrime(101))\n assert.Equal(true, IsPrime(11))\n assert.Equal(true, IsPrime(13441))\n assert.Equal(true, IsPrime(61))\n assert.Equal(false, IsPrime(4))\n assert.Equal(false, IsPrime(1))\n}\n", "buggy_solution": " if n < 1 {\n\t\treturn false\n\t}\n\tif n == 1 {\n\t\treturn true\n\t}\n\tif n%2 == 0 {\n\t\treturn false\n\t}\n\tfor i := 3; i*i <= n; i += 2 {\n\t\tif n%i == 0 {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsPrime"}
|
33 |
-
{"task_id": "Go/32", "prompt": "import (\n \"math\"\n)\n\n// Evaluates polynomial with coefficients xs at point x.\n// return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n\nfunc Poly(xs []int, x float64) float64{\n sum := 0.0\n for i, coeff := range xs {\n sum += float64(coeff) * math.Pow(x,float64(i))\n }\n return sum\n}\n// xs are coefficients of a polynomial.\n// FindZero find x such that Poly(x) = 0.\n// FindZero returns only only zero point, even if there are many.\n// Moreover, FindZero only takes list xs having even number of coefficients\n// and largest non zero coefficient as it guarantees\n// a solution.\n// >>> round(FindZero([1, 2]), 2) # f(x) = 1 + 2x\n// -0.5\n// >>> round(FindZero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n// 1.0\nfunc FindZero(xs []int) float64 {\n", "import": "import (\n \"math\"\n)\n", "docstring": "// xs are coefficients of a polynomial.\n// FindZero find x such that Poly(x) = 0.\n// FindZero returns only only zero point, even if there are many.\n// Moreover, FindZero only takes list xs having even number of coefficients\n// and largest non zero coefficient as it guarantees\n// a solution.\n// >>> round(FindZero([1, 2]), 2) # f(x) = 1 + 2x\n// -0.5\n// >>> round(FindZero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n// 1.0\n", "declaration": "\nfunc FindZero(xs []int) float64 {\n", "canonical_solution": " begin := -1.0\n\tend := 1.0\n\tfor Poly(xs, begin)*Poly(xs, end) > 0 {\n\t\tbegin *= 2\n\t\tend *= 2\n\t}\n\tfor end-begin > 1e-10 {\n\t\tcenter := (begin + end) / 2\n\t\tif Poly(xs, center)*Poly(xs, begin) > 0 {\n\t\t\tbegin = center\n\t\t} else {\n\t\t\tend = center\n\t\t}\n\t}\n\treturn begin\n}\n\n", "test": "func TestFindZero(t *testing.T) {\n assert := assert.New(t)\n randInt := func(min, max int) int {\n rng := rand.New(rand.NewSource(42))\n if min >= max || min == 0 || max == 0 {\n return max\n }\n return rng.Intn(max-min) + min\n }\n copyInts := func(src []int) []int {\n ints := make([]int, 0)\n for _, i := range src {\n ints = append(ints, i)\n }\n return ints\n }\n for i := 0; i < 100; i++ {\n ncoeff := 2 * randInt(1, 4)\n coeffs := make([]int, 0)\n for j := 0; j < ncoeff; j++ {\n coeff := randInt(-10, 10)\n if coeff == 0 {\n coeff = 1\n }\n coeffs = append(coeffs, coeff)\n }\n solution := FindZero(copyInts(coeffs))\n assert.Equal(true, math.Abs(Poly(coeffs,solution))<1e-4)\n }\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"math/rand\"\n \"math\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestFindZero(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, math.Abs(FindZero([]int{1,2})+0.5+rand.NormFloat64()*0.0)<1e-4)\n assert.Equal(true, math.Abs(FindZero([]int{-6,11,-6,1})-1)<1e-4)\n}\n", "buggy_solution": " begin := -1.0\n\tend := 1.0\n\tfor Poly(xs, begin)*Poly(xs, end) > 0 {\n\t\tbegin *= 2\n\t\tend *= 2\n\t}\n\tfor begin-end > 1e-10 {\n\t\tcenter := (begin + end) / 2\n\t\tif Poly(xs, center)*Poly(xs, end) > 0 {\n\t\t\tbegin = center\n\t\t} else {\n\t\t\tend = center\n\t\t}\n\t}\n\treturn
|
34 |
{"task_id": "Go/33", "prompt": "import (\n \"sort\"\n)\n\n// This function takes a list l and returns a list l' such that\n// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n// to the values of the corresponding indicies of l, but sorted.\n// >>> SortThird([1, 2, 3])\n// [1, 2, 3]\n// >>> SortThird([5, 6, 3, 4, 8, 9, 2])\n// [2, 6, 3, 4, 8, 9, 5]\nfunc SortThird(l []int) []int {\n", "import": "import (\n \"sort\"\n)", "docstring": "// This function takes a list l and returns a list l' such that\n// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n// to the values of the corresponding indicies of l, but sorted.\n// >>> SortThird([1, 2, 3])\n// [1, 2, 3]\n// >>> SortThird([5, 6, 3, 4, 8, 9, 2])\n// [2, 6, 3, 4, 8, 9, 5]\n", "declaration": "\nfunc SortThird(l []int) []int {\n", "canonical_solution": " temp := make([]int, 0)\n\tfor i := 0; i < len(l); i = i + 3 {\n\t\ttemp = append(temp, l[i])\n\t}\n\tsort.Ints(temp)\n\tj := 0\n\tfor i := 0; i < len(l); i = i + 3 {\n\t\tl[i] = temp[j]\n\t\tj++\n\t}\n\treturn l\n}\n\n", "test": "func TestSortThird(t *testing.T) {\n assert := assert.New(t)\n\tsame := func(src []int, target []int) bool {\n\t\tfor i := 0; i < len(src); i++ {\n\t\t\tif src[i] != target[i] {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\tassert.Equal(true, same([]int{1, 2, 3}, SortThird([]int{1, 2, 3})))\n\tassert.Equal(true, same([]int{1, 3, -5, 2, -3, 3, 5, 0, 123, 9, -10}, SortThird([]int{5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10})))\n\tassert.Equal(true, same([]int{-10, 8, -12,3, 23, 2, 4, 11, 12, 5}, SortThird([]int{5, 8, -12, 4, 23, 2, 3, 11, 12, -10})))\n\tassert.Equal(true, same([]int{2, 6, 3, 4, 8, 9, 5}, SortThird([]int{5, 6, 3, 4, 8, 9, 2})))\n\tassert.Equal(true, same([]int{2, 8, 3, 4, 6, 9, 5}, SortThird([]int{5, 8, 3, 4, 6, 9, 2})))\n\tassert.Equal(true, same([]int{2, 6, 9, 4, 8, 3, 5}, SortThird([]int{5, 6, 9, 4, 8, 3, 2})))\n\tassert.Equal(true, same([]int{2, 6, 3, 4, 8, 9, 5, 1}, SortThird([]int{5, 6, 3, 4, 8, 9, 2, 1})))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestSortThird(t *testing.T) {\n assert := assert.New(t)\n\tsame := func(src []int, target []int) bool {\n\t\tfor i := 0; i < len(src); i++ {\n\t\t\tif src[i] != target[i] {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\tassert.Equal(true, same([]int{1, 2, 3}, SortThird([]int{1, 2, 3})))\n\tassert.Equal(true, same([]int{2, 6, 3, 4, 8, 9, 5}, SortThird([]int{5, 6, 3, 4, 8, 9, 2})))\n}\n", "buggy_solution": " temp := make([]int, 0)\n\tfor i := 0; i < len(l); i = i + 3 {\n\t\ttemp = append(temp, l[i])\n\t}\n\tj := 0\n\tfor i := 0; i < len(l); i = i + 3 {\n\t\tl[i] = temp[j]\n\t\tj++\n\t}\n\treturn l\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "SortThird"}
|
35 |
{"task_id": "Go/34", "prompt": "import (\n \"sort\"\n)\n\n// Return sorted Unique elements in a list\n// >>> Unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n// [0, 2, 3, 5, 9, 123]\nfunc Unique(l []int) []int {\n", "import": "import (\n \"sort\"\n)", "docstring": "// Return sorted Unique elements in a list\n// >>> Unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n// [0, 2, 3, 5, 9, 123]\n", "declaration": "\nfunc Unique(l []int) []int {\n", "canonical_solution": " set := make(map[int]interface{})\n\tfor _, i := range l {\n\t\tset[i]=nil\n\t}\n\tl = make([]int,0)\n\tfor i, _ := range set {\n\t\tl = append(l, i)\n\t}\n\tsort.Ints(l)\n\treturn l\n}\n\n", "test": "func TestUnique(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]int{0, 2, 3, 5, 9, 123}, Unique([]int{5, 3,5, 2, 3, 3, 9, 0, 123}))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestUnique(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]int{0, 2, 3, 5, 9, 123}, Unique([]int{5, 3,5, 2, 3, 3, 9, 0, 123}))\n}\n", "buggy_solution": " sort.Ints(l)\n\treturn l\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Unique"}
|
36 |
{"task_id": "Go/35", "prompt": "\n// Return maximum element in the list.\n// >>> MaxElement([1, 2, 3])\n// 3\n// >>> MaxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n// 123\nfunc MaxElement(l []int) int {\n", "import": "", "docstring": "// Return maximum element in the list.\n// >>> MaxElement([1, 2, 3])\n// 3\n// >>> MaxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n// 123\n", "declaration": "\nfunc MaxElement(l []int) int {\n", "canonical_solution": " max := l[0]\n\tfor _, x := range l {\n\t\tif x > max {\n\t\t\tmax = x\n\t\t}\n\t}\n\treturn max\n}\n\n", "test": "func TestMaxElement(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(3, MaxElement([]int{1, 2, 3}))\n assert.Equal(124, MaxElement([]int{5, 3, -5, 2, -3, 3, 9,0, 124, 1, -10}))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestMaxElement(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(3, MaxElement([]int{1, 2, 3}))\n assert.Equal(123, MaxElement([]int{5, 3, -5, 2, -3, 3, 9,0, 123, 1, -10}))\n}\n", "buggy_solution": " max := l[0]\n\tfor _, x := range l {\n\t\tif x < max {\n\t\t\tmax = x\n\t\t}\n\t}\n\treturn max\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "MaxElement"}
|
@@ -48,7 +48,7 @@
|
|
48 |
{"task_id": "Go/47", "prompt": "import (\n\t\"sort\"\n)\n\n// Return Median of elements in the list l.\n// >>> Median([3, 1, 2, 4, 5])\n// 3.0\n// >>> Median([-10, 4, 6, 1000, 10, 20])\n// 15.0\nfunc Median(l []int) float64 {\n", "import": "import (\n\t\"sort\"\n)", "docstring": "// Return Median of elements in the list l.\n// >>> Median([3, 1, 2, 4, 5])\n// 3\n// >>> Median([-10, 4, 6, 1000, 10, 20])\n// 15.0\n", "declaration": "\nfunc Median(l []int) float64 {\n", "canonical_solution": " sort.Ints(l)\n\tif len(l)%2==1{\n\t\treturn float64(l[len(l)/2])\n\t}else{\n\t\treturn float64(l[len(l)/2-1]+l[len(l)/2])/2.0\n\t}\n}\n\n", "test": "func TestMedian(t *testing.T) {\n\tassert := assert.New(t)\n\tassert.Equal(3.0, Median([]int{3, 1, 2, 4, 5}))\n\tassert.Equal(8.0, Median([]int{-10, 4, 6, 1000, 10, 20}))\n\tassert.Equal(5.0, Median([]int{5}))\n\tassert.Equal(5.5, Median([]int{6, 5}))\n\tassert.Equal(7.0, Median([]int{8, 1, 3, 9, 9, 2, 7}))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestMedian(t *testing.T) {\n\tassert := assert.New(t)\n\tassert.Equal(3.0, Median([]int{3, 1, 2, 4, 5}))\n\tassert.Equal(8.0, Median([]int{-10, 4, 6, 1000, 10, 20}))\n}\n", "buggy_solution": " sort.Ints(l)\n\tif len(l)%2==1{\n\t\treturn float64(l[len(l)/2])\n\t}else{\n\t\treturn float64(l[len(l)-1/2]+l[len(l)/2])/2.0\n\t}\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Median"}
|
49 |
{"task_id": "Go/48", "prompt": "\n// Checks if given string is a palindrome\n// >>> IsPalindrome('')\n// true\n// >>> IsPalindrome('aba')\n// true\n// >>> IsPalindrome('aaaaa')\n// true\n// >>> IsPalindrome('zbcd')\n// false\nfunc IsPalindrome(text string) bool {\n", "import": "", "docstring": "// Checks if given string is a palindrome\n// >>> IsPalindrome('')\n// true\n// >>> IsPalindrome('aba')\n// true\n// >>> IsPalindrome('aaaaa')\n// true\n// >>> IsPalindrome('zbcd')\n// false\n", "declaration": "\nfunc IsPalindrome(text string) bool {\n", "canonical_solution": " runes := []rune(text)\n result := make([]rune, 0)\n for i := len(runes) - 1; i >= 0; i-- {\n result = append(result, runes[i])\n }\n return text == string(result)\n}\n\n", "test": "func TestIsPalindrome(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, IsPalindrome(\"\"))\n assert.Equal(true, IsPalindrome(\"aba\"))\n assert.Equal(true, IsPalindrome(\"aaaaa\"))\n assert.Equal(false, IsPalindrome(\"zbcd\"))\n assert.Equal(true, IsPalindrome(\"xywyx\"))\n assert.Equal(false, IsPalindrome(\"xywyz\"))\n assert.Equal(false, IsPalindrome(\"xywzx\"))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestIsPalindrome(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, IsPalindrome(\"\"))\n assert.Equal(true, IsPalindrome(\"aba\"))\n assert.Equal(true, IsPalindrome(\"aaaaa\"))\n assert.Equal(false, IsPalindrome(\"zbcd\"))\n}\n", "buggy_solution": " runes := []rune(text)\n result := make([]rune, 0)\n for i := len(runes) - 1; i > 0; i-- {\n result = append(result, runes[i])\n }\n return text == string(result)\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsPalindrome"}
|
50 |
{"task_id": "Go/49", "prompt": "\n// Return 2^n modulo p (be aware of numerics).\n// >>> Modp(3, 5)\n// 3\n// >>> Modp(1101, 101)\n// 2\n// >>> Modp(0, 101)\n// 1\n// >>> Modp(3, 11)\n// 8\n// >>> Modp(100, 101)\n// 1\nfunc Modp(n int,p int) int {\n", "import": "", "docstring": "// Return 2^n modulo p (be aware of numerics).\n// >>> Modp(3, 5)\n// 3\n// >>> Modp(1101, 101)\n// 2\n// >>> Modp(0, 101)\n// 1\n// >>> Modp(3, 11)\n// 8\n// >>> Modp(100, 101)\n// 1\n", "declaration": "\nfunc Modp(n int,p int) int {\n", "canonical_solution": " ret := 1\n for i:= 0; i < n; i++ {\n\t\tret = (2 * ret) % p\n\t}\n return ret\n}\n\n", "test": "func TestModp(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(3, Modp(3, 5))\n assert.Equal(2, Modp(1101, 101))\n assert.Equal(1, Modp(0, 101))\n assert.Equal(8, Modp(3, 11))\n assert.Equal(1, Modp(100, 101))\n assert.Equal(4, Modp(30, 5))\n assert.Equal(3, Modp(31, 5))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestModp(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(3, Modp(3, 5))\n assert.Equal(2, Modp(1101, 101))\n assert.Equal(1, Modp(0, 101))\n assert.Equal(8, Modp(3, 11))\n assert.Equal(1, Modp(100, 101))\n}\n", "buggy_solution": " ret := 0\n for i:= 0; i < n; i++ {\n\t\tret = (2 * ret) % p\n\t}\n return ret\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Modp"}
|
51 |
-
{"task_id": "Go/50", "prompt": "// returns encoded string by shifting every character by 5 in the alphabet.\nfunc EncodeShift(s string) string {\n runes := []rune(s)\n newRunes := make([]rune, 0)\n for _, ch := range runes {\n newRunes = append(newRunes, (ch+5-'a')%26+'a')\n }\n return string(runes)\n}\n\n// takes as input string encoded with EncodeShift function. Returns decoded string.\nfunc DecodeShift(s string) string {\n", "import": "", "docstring": "// returns encoded string by shifting every character by 5 in the alphabet.\n// takes as input string encoded with encode_shift function. Returns decoded string.\n", "declaration": "\nfunc DecodeShift(s string) string {\n", "canonical_solution": " runes := []rune(s)\n newRunes := make([]rune, 0)\n for _, ch := range runes {\n newRunes = append(newRunes, (ch-5-'a')%26+'a')\n }\n return string(runes)\n}\n\n", "test": "func TestDecodeShift(t *testing.T) {\n assert := assert.New(t)\n randInt := func(min, max int) int {\n rng := rand.New(rand.NewSource(time.Now().UnixNano()))\n if min >= max || min == 0 || max == 0 {\n return max\n }\n return rng.Intn(max-min) + min\n }\n for i := 0; i <100 ; i++ {\n runes := make([]rune, 0)\n for j := 0; j < randInt(10,20); j++ {\n runes = append(runes, int32(randInt('a','z')))\n }\n encoded_str := EncodeShift(string(runes))\n assert.Equal(DecodeShift(encoded_str), string(runes))\n }\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"math/rand\"\n \"time\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "", "buggy_solution": " runes := []rune(s)\n newRunes := make([]rune, 0)\n for _, ch := range runes {\n newRunes = append(newRunes,
|
52 |
{"task_id": "Go/51", "prompt": "import (\n \"regexp\"\n)\n\n// RemoveVowels is a function that takes string and returns string without vowels.\n// >>> RemoveVowels('')\n// ''\n// >>> RemoveVowels(\"abcdef\\nghijklm\")\n// 'bcdf\\nghjklm'\n// >>> RemoveVowels('abcdef')\n// 'bcdf'\n// >>> RemoveVowels('aaaaa')\n// ''\n// >>> RemoveVowels('aaBAA')\n// 'B'\n// >>> RemoveVowels('zbcd')\n// 'zbcd'\nfunc RemoveVowels(text string) string {\n", "import": "import (\n \"regexp\"\n)", "docstring": "// RemoveVowels is a function that takes string and returns string without vowels.\n// >>> RemoveVowels('')\n// ''\n// >>> RemoveVowels(\"abcdef\\nghijklm\")\n// 'bcdf\\nghjklm'\n// >>> RemoveVowels('abcdef')\n// 'bcdf'\n// >>> RemoveVowels('aaaaa')\n// ''\n// >>> RemoveVowels('aaBAA')\n// 'B'\n// >>> RemoveVowels('zbcd')\n// 'zbcd'\n", "declaration": "\nfunc RemoveVowels(text string) string {\n ", "canonical_solution": " var re = regexp.MustCompile(\"[aeiouAEIOU]\")\n\ttext = re.ReplaceAllString(text, \"\")\n\treturn text\n}\n\n", "test": "func TestRemoveVowels(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(\"\", RemoveVowels(\"\"))\n assert.Equal(\"bcdf\\nghjklm\", RemoveVowels(\"abcdef\\nghijklm\"))\n assert.Equal(\"fdcb\", RemoveVowels(\"fedcba\"))\n assert.Equal(\"\", RemoveVowels(\"eeeee\"))\n assert.Equal(\"cB\", RemoveVowels(\"acBAA\"))\n assert.Equal(\"cB\", RemoveVowels(\"EcBOO\"))\n assert.Equal(\"ybcd\", RemoveVowels(\"ybcd\"))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestRemoveVowels(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(\"\", RemoveVowels(\"\"))\n assert.Equal(\"bcdf\\nghjklm\", RemoveVowels(\"abcdef\\nghijklm\"))\n assert.Equal(\"bcdf\", RemoveVowels(\"abcdef\"))\n assert.Equal(\"\", RemoveVowels(\"aaaaa\"))\n assert.Equal(\"B\", RemoveVowels(\"aaBAA\"))\n assert.Equal(\"zbcd\", RemoveVowels(\"zbcd\"))\n}\n", "buggy_solution": " var re = regexp.MustCompile(\"[aeiouwyAEIOUWY]\")\n\ttext = re.ReplaceAllString(text, \"\")\n\treturn text\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "RemoveVowels"}
|
53 |
{"task_id": "Go/52", "prompt": "\n// Return true if all numbers in the list l are below threshold t.\n// >>> BelowThreshold([1, 2, 4, 10], 100)\n// true\n// >>> BelowThreshold([1, 20, 4, 10], 5)\n// false\nfunc BelowThreshold(l []int,t int) bool {\n", "import": "", "docstring": "// Return true if all numbers in the list l are below threshold t.\n// >>> BelowThreshold([1, 2, 4, 10], 100)\n// true\n// >>> BelowThreshold([1, 20, 4, 10], 5)\n// false\n", "declaration": "\nfunc BelowThreshold(l []int,t int) bool {\n", "canonical_solution": " for _, n := range l {\n\t\tif n >= t {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n", "test": "func TestBelowThreshold(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, BelowThreshold([]int{1, 2, 4, 10}, 100))\n assert.Equal(false, BelowThreshold([]int{1, 20, 4, 10}, 5))\n assert.Equal(true, BelowThreshold([]int{1, 20, 4, 10}, 21))\n assert.Equal(true, BelowThreshold([]int{1, 20, 4, 10}, 22))\n assert.Equal(true, BelowThreshold([]int{1, 8, 4, 10}, 11))\n assert.Equal(false, BelowThreshold([]int{1, 8, 4, 10}, 10))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestBelowThreshold(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, BelowThreshold([]int{1, 2, 4, 10}, 100))\n assert.Equal(false, BelowThreshold([]int{1, 20, 4, 10}, 5))\n}\n", "buggy_solution": " for _, n := range l {\n\t\tif n >= t {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "BelowThreshold"}
|
54 |
{"task_id": "Go/53", "prompt": "\n// Add two numbers x and y\n// >>> Add(2, 3)\n// 5\n// >>> Add(5, 7)\n// 12\nfunc Add(x int, y int) int {\n", "import": "", "docstring": "// Add two numbers x and y\n// >>> Add(2, 3)\n// 5\n// >>> Add(5, 7)\n// 12\n", "declaration": "\nfunc Add(x int, y int) int {\n", "canonical_solution": " return x + y\n}\n\n", "test": "func TestAdd(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(1, Add(0, 1))\n assert.Equal(1, Add(1, 0))\n assert.Equal(5, Add(2, 3))\n assert.Equal(12, Add(5, 7))\n assert.Equal(12, Add(7, 5))\n for i := 0; i < 100; i++ {\n x := rand.Int31n(1000)\n y := rand.Int31n(1000)\n assert.Equal(int(x+y), Add(int(x), int(y)))\n }\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"math/rand\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestAdd(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(5, Add(2, 3+rand.Intn(1000)*0))\n assert.Equal(12, Add(5, 7))\n}\n", "buggy_solution": " return x + y + y + x\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Add"}
|
|
|
30 |
{"task_id": "Go/29", "prompt": "\n// Filter an input list of strings only for ones that start with a given prefix.\n// >>> FilterByPrefix([], 'a')\n// []\n// >>> FilterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n// ['abc', 'array']\nfunc FilterByPrefix(strings []string,prefix string) []string {\n", "import": "", "docstring": "// Filter an input list of strings only for ones that start with a given prefix.\n// >>> FilterByPrefix([], 'a')\n// []\n// >>> FilterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n// ['abc', 'array']\n", "declaration": "\nfunc FilterByPrefix(strings []string,prefix string) []string {\n", "canonical_solution": " if len(strings) == 0 {\n return []string{}\n }\n res := make([]string, 0, len(strings))\n\tfor _, s := range strings {\n\t\tif s[:len(prefix)] == prefix {\n\t\t\tres = append(res, s)\n\t\t}\n\t}\n\treturn res\n}\n\n\n", "test": "func TestFilterByPrefix(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]string{}, FilterByPrefix([]string{}, \"john\"))\n assert.Equal([]string{\"xxx\", \"xxxAAA\", \"xxx\"}, FilterByPrefix([]string{\"xxx\", \"asd\", \"xxy\", \"john doe\", \"xxxAAA\", \"xxx\"}, \"xxx\"))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestFilterByPrefix(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]string{}, FilterByPrefix([]string{}, \"a\"))\n assert.Equal([]string{\"abc\", \"array\"}, FilterByPrefix([]string{\"abc\", \"bcd\", \"cde\", \"array\"}, \"a\"))\n}\n", "buggy_solution": " if len(strings) == 0 {\n return []string{}\n }\n res := make([]string, 0, len(strings))\n\tfor _, s := range strings {\n\t\tif s[:len(prefix)] != prefix {\n\t\t\tres = append(res, s)\n\t\t}\n\t}\n\treturn res\n}\n\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "FilterByPrefix"}
|
31 |
{"task_id": "Go/30", "prompt": "\n// Return only positive numbers in the list.\n// >>> GetPositive([-1, 2, -4, 5, 6])\n// [2, 5, 6]\n// >>> GetPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n// [5, 3, 2, 3, 9, 123, 1]\nfunc GetPositive(l []int) []int {\n", "import": "", "docstring": "// Return only positive numbers in the list.\n// >>> GetPositive([-1, 2, -4, 5, 6])\n// [2, 5, 6]\n// >>> GetPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n// [5, 3, 2, 3, 9, 123, 1]\n", "declaration": "\nfunc GetPositive(l []int) []int {\n", "canonical_solution": " res := make([]int, 0)\n for _, x := range l {\n if x > 0 {\n res = append(res, x)\n }\n }\n return res\n}\n\n\n", "test": "func TestGetPositive(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]int{4, 5, 6}, GetPositive([]int{-1, -2, 4,5, 6}))\n assert.Equal([]int{5, 3, 2, 3, 3, 9, 123, 1}, GetPositive([]int{5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10}))\n assert.Equal([]int{}, GetPositive([]int{-1, -2}))\n assert.Equal([]int{}, GetPositive([]int{}))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestGetPositive(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]int{2, 5, 6}, GetPositive([]int{-1, 2, -4,5, 6}))\n assert.Equal([]int{5, 3, 2, 3, 9, 123, 1}, GetPositive([]int{5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10}))\n}\n", "buggy_solution": " res := make([]int, 0)\n for _, x := range l {\n if x < 0 {\n res = append(res, x)\n }\n }\n return res\n}\n\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "GetPositive"}
|
32 |
{"task_id": "Go/31", "prompt": "\n// Return true if a given number is prime, and false otherwise.\n// >>> IsPrime(6)\n// false\n// >>> IsPrime(101)\n// true\n// >>> IsPrime(11)\n// true\n// >>> IsPrime(13441)\n// true\n// >>> IsPrime(61)\n// true\n// >>> IsPrime(4)\n// false\n// >>> IsPrime(1)\n// false\nfunc IsPrime(n int) bool {\n", "import": "", "docstring": "// Return true if a given number is prime, and false otherwise.\n// >>> IsPrime(6)\n// false\n// >>> IsPrime(101)\n// true\n// >>> IsPrime(11)\n// true\n// >>> IsPrime(13441)\n// true\n// >>> IsPrime(61)\n// true\n// >>> IsPrime(4)\n// false\n// >>> IsPrime(1)\n// false\n", "declaration": "\nfunc IsPrime(n int) bool {\n", "canonical_solution": " if n <= 1 {\n\t\treturn false\n\t}\n\tif n == 2 {\n\t\treturn true\n\t}\n\tif n%2 == 0 {\n\t\treturn false\n\t}\n\tfor i := 3; i*i <= n; i += 2 {\n\t\tif n%i == 0 {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n\n", "test": "func TestIsPrime(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(false, IsPrime(6))\n assert.Equal(true, IsPrime(101))\n assert.Equal(true, IsPrime(11))\n assert.Equal(true, IsPrime(13441))\n assert.Equal(true, IsPrime(61))\n assert.Equal(false, IsPrime(4))\n assert.Equal(false, IsPrime(1))\n assert.Equal(true, IsPrime(5))\n assert.Equal(true, IsPrime(11))\n assert.Equal(true, IsPrime(17))\n assert.Equal(false, IsPrime(5 * 17))\n assert.Equal(false, IsPrime(11 * 7))\n assert.Equal(false, IsPrime(13441 * 19))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestIsPrime(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(false, IsPrime(6))\n assert.Equal(true, IsPrime(101))\n assert.Equal(true, IsPrime(11))\n assert.Equal(true, IsPrime(13441))\n assert.Equal(true, IsPrime(61))\n assert.Equal(false, IsPrime(4))\n assert.Equal(false, IsPrime(1))\n}\n", "buggy_solution": " if n < 1 {\n\t\treturn false\n\t}\n\tif n == 1 {\n\t\treturn true\n\t}\n\tif n%2 == 0 {\n\t\treturn false\n\t}\n\tfor i := 3; i*i <= n; i += 2 {\n\t\tif n%i == 0 {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsPrime"}
|
33 |
+
{"task_id": "Go/32", "prompt": "import (\n \"math\"\n)\n\n// Evaluates polynomial with coefficients xs at point x.\n// return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n\nfunc Poly(xs []int, x float64) float64{\n sum := 0.0\n for i, coeff := range xs {\n sum += float64(coeff) * math.Pow(x,float64(i))\n }\n return sum\n}\n// xs are coefficients of a polynomial.\n// FindZero find x such that Poly(x) = 0.\n// FindZero returns only only zero point, even if there are many.\n// Moreover, FindZero only takes list xs having even number of coefficients\n// and largest non zero coefficient as it guarantees\n// a solution.\n// >>> round(FindZero([1, 2]), 2) # f(x) = 1 + 2x\n// -0.5\n// >>> round(FindZero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n// 1.0\nfunc FindZero(xs []int) float64 {\n", "import": "import (\n \"math\"\n)\n", "docstring": "// xs are coefficients of a polynomial.\n// FindZero find x such that Poly(x) = 0.\n// FindZero returns only only zero point, even if there are many.\n// Moreover, FindZero only takes list xs having even number of coefficients\n// and largest non zero coefficient as it guarantees\n// a solution.\n// >>> round(FindZero([1, 2]), 2) # f(x) = 1 + 2x\n// -0.5\n// >>> round(FindZero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n// 1.0\n", "declaration": "\nfunc FindZero(xs []int) float64 {\n", "canonical_solution": " begin := -1.0\n\tend := 1.0\n\tfor Poly(xs, begin)*Poly(xs, end) > 0 {\n\t\tbegin *= 2\n\t\tend *= 2\n\t}\n\tfor end-begin > 1e-10 {\n\t\tcenter := (begin + end) / 2\n\t\tif Poly(xs, center)*Poly(xs, begin) > 0 {\n\t\t\tbegin = center\n\t\t} else {\n\t\t\tend = center\n\t\t}\n\t}\n\treturn begin\n}\n\n", "test": "func TestFindZero(t *testing.T) {\n assert := assert.New(t)\n randInt := func(min, max int) int {\n rng := rand.New(rand.NewSource(42))\n if min >= max || min == 0 || max == 0 {\n return max\n }\n return rng.Intn(max-min) + min\n }\n copyInts := func(src []int) []int {\n ints := make([]int, 0)\n for _, i := range src {\n ints = append(ints, i)\n }\n return ints\n }\n for i := 0; i < 100; i++ {\n ncoeff := 2 * randInt(1, 4)\n coeffs := make([]int, 0)\n for j := 0; j < ncoeff; j++ {\n coeff := randInt(-10, 10)\n if coeff == 0 {\n coeff = 1\n }\n coeffs = append(coeffs, coeff)\n }\n solution := FindZero(copyInts(coeffs))\n assert.Equal(true, math.Abs(Poly(coeffs,solution))<1e-4)\n }\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"math/rand\"\n \"math\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestFindZero(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, math.Abs(FindZero([]int{1,2})+0.5+rand.NormFloat64()*0.0)<1e-4)\n assert.Equal(true, math.Abs(FindZero([]int{-6,11,-6,1})-1)<1e-4)\n}\n", "buggy_solution": " begin := -1.0\n\tend := 1.0\n\tfor Poly(xs, begin)*Poly(xs, end) > 0 {\n\t\tbegin *= 2\n\t\tend *= 2\n\t}\n\tfor begin-end > 1e-10 {\n\t\tcenter := (begin + end) / 2\n\t\tif Poly(xs, center)*Poly(xs, end) > 0 {\n\t\t\tbegin = center\n\t\t} else {\n\t\t\tend = center\n\t\t}\n\t}\n\treturn end\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "FindZero"}
|
34 |
{"task_id": "Go/33", "prompt": "import (\n \"sort\"\n)\n\n// This function takes a list l and returns a list l' such that\n// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n// to the values of the corresponding indicies of l, but sorted.\n// >>> SortThird([1, 2, 3])\n// [1, 2, 3]\n// >>> SortThird([5, 6, 3, 4, 8, 9, 2])\n// [2, 6, 3, 4, 8, 9, 5]\nfunc SortThird(l []int) []int {\n", "import": "import (\n \"sort\"\n)", "docstring": "// This function takes a list l and returns a list l' such that\n// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n// to the values of the corresponding indicies of l, but sorted.\n// >>> SortThird([1, 2, 3])\n// [1, 2, 3]\n// >>> SortThird([5, 6, 3, 4, 8, 9, 2])\n// [2, 6, 3, 4, 8, 9, 5]\n", "declaration": "\nfunc SortThird(l []int) []int {\n", "canonical_solution": " temp := make([]int, 0)\n\tfor i := 0; i < len(l); i = i + 3 {\n\t\ttemp = append(temp, l[i])\n\t}\n\tsort.Ints(temp)\n\tj := 0\n\tfor i := 0; i < len(l); i = i + 3 {\n\t\tl[i] = temp[j]\n\t\tj++\n\t}\n\treturn l\n}\n\n", "test": "func TestSortThird(t *testing.T) {\n assert := assert.New(t)\n\tsame := func(src []int, target []int) bool {\n\t\tfor i := 0; i < len(src); i++ {\n\t\t\tif src[i] != target[i] {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\tassert.Equal(true, same([]int{1, 2, 3}, SortThird([]int{1, 2, 3})))\n\tassert.Equal(true, same([]int{1, 3, -5, 2, -3, 3, 5, 0, 123, 9, -10}, SortThird([]int{5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10})))\n\tassert.Equal(true, same([]int{-10, 8, -12,3, 23, 2, 4, 11, 12, 5}, SortThird([]int{5, 8, -12, 4, 23, 2, 3, 11, 12, -10})))\n\tassert.Equal(true, same([]int{2, 6, 3, 4, 8, 9, 5}, SortThird([]int{5, 6, 3, 4, 8, 9, 2})))\n\tassert.Equal(true, same([]int{2, 8, 3, 4, 6, 9, 5}, SortThird([]int{5, 8, 3, 4, 6, 9, 2})))\n\tassert.Equal(true, same([]int{2, 6, 9, 4, 8, 3, 5}, SortThird([]int{5, 6, 9, 4, 8, 3, 2})))\n\tassert.Equal(true, same([]int{2, 6, 3, 4, 8, 9, 5, 1}, SortThird([]int{5, 6, 3, 4, 8, 9, 2, 1})))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestSortThird(t *testing.T) {\n assert := assert.New(t)\n\tsame := func(src []int, target []int) bool {\n\t\tfor i := 0; i < len(src); i++ {\n\t\t\tif src[i] != target[i] {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\tassert.Equal(true, same([]int{1, 2, 3}, SortThird([]int{1, 2, 3})))\n\tassert.Equal(true, same([]int{2, 6, 3, 4, 8, 9, 5}, SortThird([]int{5, 6, 3, 4, 8, 9, 2})))\n}\n", "buggy_solution": " temp := make([]int, 0)\n\tfor i := 0; i < len(l); i = i + 3 {\n\t\ttemp = append(temp, l[i])\n\t}\n\tj := 0\n\tfor i := 0; i < len(l); i = i + 3 {\n\t\tl[i] = temp[j]\n\t\tj++\n\t}\n\treturn l\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "SortThird"}
|
35 |
{"task_id": "Go/34", "prompt": "import (\n \"sort\"\n)\n\n// Return sorted Unique elements in a list\n// >>> Unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n// [0, 2, 3, 5, 9, 123]\nfunc Unique(l []int) []int {\n", "import": "import (\n \"sort\"\n)", "docstring": "// Return sorted Unique elements in a list\n// >>> Unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n// [0, 2, 3, 5, 9, 123]\n", "declaration": "\nfunc Unique(l []int) []int {\n", "canonical_solution": " set := make(map[int]interface{})\n\tfor _, i := range l {\n\t\tset[i]=nil\n\t}\n\tl = make([]int,0)\n\tfor i, _ := range set {\n\t\tl = append(l, i)\n\t}\n\tsort.Ints(l)\n\treturn l\n}\n\n", "test": "func TestUnique(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]int{0, 2, 3, 5, 9, 123}, Unique([]int{5, 3,5, 2, 3, 3, 9, 0, 123}))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestUnique(t *testing.T) {\n assert := assert.New(t)\n assert.Equal([]int{0, 2, 3, 5, 9, 123}, Unique([]int{5, 3,5, 2, 3, 3, 9, 0, 123}))\n}\n", "buggy_solution": " sort.Ints(l)\n\treturn l\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Unique"}
|
36 |
{"task_id": "Go/35", "prompt": "\n// Return maximum element in the list.\n// >>> MaxElement([1, 2, 3])\n// 3\n// >>> MaxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n// 123\nfunc MaxElement(l []int) int {\n", "import": "", "docstring": "// Return maximum element in the list.\n// >>> MaxElement([1, 2, 3])\n// 3\n// >>> MaxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n// 123\n", "declaration": "\nfunc MaxElement(l []int) int {\n", "canonical_solution": " max := l[0]\n\tfor _, x := range l {\n\t\tif x > max {\n\t\t\tmax = x\n\t\t}\n\t}\n\treturn max\n}\n\n", "test": "func TestMaxElement(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(3, MaxElement([]int{1, 2, 3}))\n assert.Equal(124, MaxElement([]int{5, 3, -5, 2, -3, 3, 9,0, 124, 1, -10}))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestMaxElement(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(3, MaxElement([]int{1, 2, 3}))\n assert.Equal(123, MaxElement([]int{5, 3, -5, 2, -3, 3, 9,0, 123, 1, -10}))\n}\n", "buggy_solution": " max := l[0]\n\tfor _, x := range l {\n\t\tif x < max {\n\t\t\tmax = x\n\t\t}\n\t}\n\treturn max\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "MaxElement"}
|
|
|
48 |
{"task_id": "Go/47", "prompt": "import (\n\t\"sort\"\n)\n\n// Return Median of elements in the list l.\n// >>> Median([3, 1, 2, 4, 5])\n// 3.0\n// >>> Median([-10, 4, 6, 1000, 10, 20])\n// 15.0\nfunc Median(l []int) float64 {\n", "import": "import (\n\t\"sort\"\n)", "docstring": "// Return Median of elements in the list l.\n// >>> Median([3, 1, 2, 4, 5])\n// 3\n// >>> Median([-10, 4, 6, 1000, 10, 20])\n// 15.0\n", "declaration": "\nfunc Median(l []int) float64 {\n", "canonical_solution": " sort.Ints(l)\n\tif len(l)%2==1{\n\t\treturn float64(l[len(l)/2])\n\t}else{\n\t\treturn float64(l[len(l)/2-1]+l[len(l)/2])/2.0\n\t}\n}\n\n", "test": "func TestMedian(t *testing.T) {\n\tassert := assert.New(t)\n\tassert.Equal(3.0, Median([]int{3, 1, 2, 4, 5}))\n\tassert.Equal(8.0, Median([]int{-10, 4, 6, 1000, 10, 20}))\n\tassert.Equal(5.0, Median([]int{5}))\n\tassert.Equal(5.5, Median([]int{6, 5}))\n\tassert.Equal(7.0, Median([]int{8, 1, 3, 9, 9, 2, 7}))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestMedian(t *testing.T) {\n\tassert := assert.New(t)\n\tassert.Equal(3.0, Median([]int{3, 1, 2, 4, 5}))\n\tassert.Equal(8.0, Median([]int{-10, 4, 6, 1000, 10, 20}))\n}\n", "buggy_solution": " sort.Ints(l)\n\tif len(l)%2==1{\n\t\treturn float64(l[len(l)/2])\n\t}else{\n\t\treturn float64(l[len(l)-1/2]+l[len(l)/2])/2.0\n\t}\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Median"}
|
49 |
{"task_id": "Go/48", "prompt": "\n// Checks if given string is a palindrome\n// >>> IsPalindrome('')\n// true\n// >>> IsPalindrome('aba')\n// true\n// >>> IsPalindrome('aaaaa')\n// true\n// >>> IsPalindrome('zbcd')\n// false\nfunc IsPalindrome(text string) bool {\n", "import": "", "docstring": "// Checks if given string is a palindrome\n// >>> IsPalindrome('')\n// true\n// >>> IsPalindrome('aba')\n// true\n// >>> IsPalindrome('aaaaa')\n// true\n// >>> IsPalindrome('zbcd')\n// false\n", "declaration": "\nfunc IsPalindrome(text string) bool {\n", "canonical_solution": " runes := []rune(text)\n result := make([]rune, 0)\n for i := len(runes) - 1; i >= 0; i-- {\n result = append(result, runes[i])\n }\n return text == string(result)\n}\n\n", "test": "func TestIsPalindrome(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, IsPalindrome(\"\"))\n assert.Equal(true, IsPalindrome(\"aba\"))\n assert.Equal(true, IsPalindrome(\"aaaaa\"))\n assert.Equal(false, IsPalindrome(\"zbcd\"))\n assert.Equal(true, IsPalindrome(\"xywyx\"))\n assert.Equal(false, IsPalindrome(\"xywyz\"))\n assert.Equal(false, IsPalindrome(\"xywzx\"))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestIsPalindrome(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, IsPalindrome(\"\"))\n assert.Equal(true, IsPalindrome(\"aba\"))\n assert.Equal(true, IsPalindrome(\"aaaaa\"))\n assert.Equal(false, IsPalindrome(\"zbcd\"))\n}\n", "buggy_solution": " runes := []rune(text)\n result := make([]rune, 0)\n for i := len(runes) - 1; i > 0; i-- {\n result = append(result, runes[i])\n }\n return text == string(result)\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsPalindrome"}
|
50 |
{"task_id": "Go/49", "prompt": "\n// Return 2^n modulo p (be aware of numerics).\n// >>> Modp(3, 5)\n// 3\n// >>> Modp(1101, 101)\n// 2\n// >>> Modp(0, 101)\n// 1\n// >>> Modp(3, 11)\n// 8\n// >>> Modp(100, 101)\n// 1\nfunc Modp(n int,p int) int {\n", "import": "", "docstring": "// Return 2^n modulo p (be aware of numerics).\n// >>> Modp(3, 5)\n// 3\n// >>> Modp(1101, 101)\n// 2\n// >>> Modp(0, 101)\n// 1\n// >>> Modp(3, 11)\n// 8\n// >>> Modp(100, 101)\n// 1\n", "declaration": "\nfunc Modp(n int,p int) int {\n", "canonical_solution": " ret := 1\n for i:= 0; i < n; i++ {\n\t\tret = (2 * ret) % p\n\t}\n return ret\n}\n\n", "test": "func TestModp(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(3, Modp(3, 5))\n assert.Equal(2, Modp(1101, 101))\n assert.Equal(1, Modp(0, 101))\n assert.Equal(8, Modp(3, 11))\n assert.Equal(1, Modp(100, 101))\n assert.Equal(4, Modp(30, 5))\n assert.Equal(3, Modp(31, 5))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestModp(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(3, Modp(3, 5))\n assert.Equal(2, Modp(1101, 101))\n assert.Equal(1, Modp(0, 101))\n assert.Equal(8, Modp(3, 11))\n assert.Equal(1, Modp(100, 101))\n}\n", "buggy_solution": " ret := 0\n for i:= 0; i < n; i++ {\n\t\tret = (2 * ret) % p\n\t}\n return ret\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Modp"}
|
51 |
+
{"task_id": "Go/50", "prompt": "// returns encoded string by shifting every character by 5 in the alphabet.\nfunc EncodeShift(s string) string {\n runes := []rune(s)\n newRunes := make([]rune, 0)\n for _, ch := range runes {\n newRunes = append(newRunes, (ch+5-'a')%26+'a')\n }\n return string(runes)\n}\n\n// takes as input string encoded with EncodeShift function. Returns decoded string.\nfunc DecodeShift(s string) string {\n", "import": "", "docstring": "// returns encoded string by shifting every character by 5 in the alphabet.\n// takes as input string encoded with encode_shift function. Returns decoded string.\n", "declaration": "\nfunc DecodeShift(s string) string {\n", "canonical_solution": " runes := []rune(s)\n newRunes := make([]rune, 0)\n for _, ch := range runes {\n newRunes = append(newRunes, (ch-5-'a')%26+'a')\n }\n return string(runes)\n}\n\n", "test": "func TestDecodeShift(t *testing.T) {\n assert := assert.New(t)\n randInt := func(min, max int) int {\n rng := rand.New(rand.NewSource(time.Now().UnixNano()))\n if min >= max || min == 0 || max == 0 {\n return max\n }\n return rng.Intn(max-min) + min\n }\n for i := 0; i <100 ; i++ {\n runes := make([]rune, 0)\n for j := 0; j < randInt(10,20); j++ {\n runes = append(runes, int32(randInt('a','z')))\n }\n encoded_str := EncodeShift(string(runes))\n assert.Equal(DecodeShift(encoded_str), string(runes))\n }\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"math/rand\"\n \"time\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "", "buggy_solution": " runes := []rune(s)\n newRunes := make([]rune, 0)\n for _, ch := range runes {\n newRunes = append(newRunes, 'a'-ch-5%26+ch)\n }\n return string(runes)\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "DecodeShift"}
|
52 |
{"task_id": "Go/51", "prompt": "import (\n \"regexp\"\n)\n\n// RemoveVowels is a function that takes string and returns string without vowels.\n// >>> RemoveVowels('')\n// ''\n// >>> RemoveVowels(\"abcdef\\nghijklm\")\n// 'bcdf\\nghjklm'\n// >>> RemoveVowels('abcdef')\n// 'bcdf'\n// >>> RemoveVowels('aaaaa')\n// ''\n// >>> RemoveVowels('aaBAA')\n// 'B'\n// >>> RemoveVowels('zbcd')\n// 'zbcd'\nfunc RemoveVowels(text string) string {\n", "import": "import (\n \"regexp\"\n)", "docstring": "// RemoveVowels is a function that takes string and returns string without vowels.\n// >>> RemoveVowels('')\n// ''\n// >>> RemoveVowels(\"abcdef\\nghijklm\")\n// 'bcdf\\nghjklm'\n// >>> RemoveVowels('abcdef')\n// 'bcdf'\n// >>> RemoveVowels('aaaaa')\n// ''\n// >>> RemoveVowels('aaBAA')\n// 'B'\n// >>> RemoveVowels('zbcd')\n// 'zbcd'\n", "declaration": "\nfunc RemoveVowels(text string) string {\n ", "canonical_solution": " var re = regexp.MustCompile(\"[aeiouAEIOU]\")\n\ttext = re.ReplaceAllString(text, \"\")\n\treturn text\n}\n\n", "test": "func TestRemoveVowels(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(\"\", RemoveVowels(\"\"))\n assert.Equal(\"bcdf\\nghjklm\", RemoveVowels(\"abcdef\\nghijklm\"))\n assert.Equal(\"fdcb\", RemoveVowels(\"fedcba\"))\n assert.Equal(\"\", RemoveVowels(\"eeeee\"))\n assert.Equal(\"cB\", RemoveVowels(\"acBAA\"))\n assert.Equal(\"cB\", RemoveVowels(\"EcBOO\"))\n assert.Equal(\"ybcd\", RemoveVowels(\"ybcd\"))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestRemoveVowels(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(\"\", RemoveVowels(\"\"))\n assert.Equal(\"bcdf\\nghjklm\", RemoveVowels(\"abcdef\\nghijklm\"))\n assert.Equal(\"bcdf\", RemoveVowels(\"abcdef\"))\n assert.Equal(\"\", RemoveVowels(\"aaaaa\"))\n assert.Equal(\"B\", RemoveVowels(\"aaBAA\"))\n assert.Equal(\"zbcd\", RemoveVowels(\"zbcd\"))\n}\n", "buggy_solution": " var re = regexp.MustCompile(\"[aeiouwyAEIOUWY]\")\n\ttext = re.ReplaceAllString(text, \"\")\n\treturn text\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "RemoveVowels"}
|
53 |
{"task_id": "Go/52", "prompt": "\n// Return true if all numbers in the list l are below threshold t.\n// >>> BelowThreshold([1, 2, 4, 10], 100)\n// true\n// >>> BelowThreshold([1, 20, 4, 10], 5)\n// false\nfunc BelowThreshold(l []int,t int) bool {\n", "import": "", "docstring": "// Return true if all numbers in the list l are below threshold t.\n// >>> BelowThreshold([1, 2, 4, 10], 100)\n// true\n// >>> BelowThreshold([1, 20, 4, 10], 5)\n// false\n", "declaration": "\nfunc BelowThreshold(l []int,t int) bool {\n", "canonical_solution": " for _, n := range l {\n\t\tif n >= t {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n", "test": "func TestBelowThreshold(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, BelowThreshold([]int{1, 2, 4, 10}, 100))\n assert.Equal(false, BelowThreshold([]int{1, 20, 4, 10}, 5))\n assert.Equal(true, BelowThreshold([]int{1, 20, 4, 10}, 21))\n assert.Equal(true, BelowThreshold([]int{1, 20, 4, 10}, 22))\n assert.Equal(true, BelowThreshold([]int{1, 8, 4, 10}, 11))\n assert.Equal(false, BelowThreshold([]int{1, 8, 4, 10}, 10))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestBelowThreshold(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, BelowThreshold([]int{1, 2, 4, 10}, 100))\n assert.Equal(false, BelowThreshold([]int{1, 20, 4, 10}, 5))\n}\n", "buggy_solution": " for _, n := range l {\n\t\tif n >= t {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "BelowThreshold"}
|
54 |
{"task_id": "Go/53", "prompt": "\n// Add two numbers x and y\n// >>> Add(2, 3)\n// 5\n// >>> Add(5, 7)\n// 12\nfunc Add(x int, y int) int {\n", "import": "", "docstring": "// Add two numbers x and y\n// >>> Add(2, 3)\n// 5\n// >>> Add(5, 7)\n// 12\n", "declaration": "\nfunc Add(x int, y int) int {\n", "canonical_solution": " return x + y\n}\n\n", "test": "func TestAdd(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(1, Add(0, 1))\n assert.Equal(1, Add(1, 0))\n assert.Equal(5, Add(2, 3))\n assert.Equal(12, Add(5, 7))\n assert.Equal(12, Add(7, 5))\n for i := 0; i < 100; i++ {\n x := rand.Int31n(1000)\n y := rand.Int31n(1000)\n assert.Equal(int(x+y), Add(int(x), int(y)))\n }\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"math/rand\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestAdd(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(5, Add(2, 3+rand.Intn(1000)*0))\n assert.Equal(12, Add(5, 7))\n}\n", "buggy_solution": " return x + y + y + x\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Add"}
|
data/java/data/humanevalbugs.jsonl
CHANGED
@@ -125,7 +125,7 @@
|
|
125 |
{"task_id": "Java/124", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You have to write a function which validates a given date string and\n returns true if the date is valid otherwise false.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example:\n validDate(\"03-11-2000\") => true\n validDate(\"15-01-2012\") => false\n validDate(\"04-0-2040\") => false\n validDate(\"06-04-2020\") => true\n validDate(\"06/04/2020\") => false\n */\n public boolean validDate(String date) {\n", "canonical_solution": " try {\n date = date.strip();\n String[] dates = date.split(\"-\" );\n String m = dates[0];\n while (!m.isEmpty() && m.charAt(0) == '0') {\n m = m.substring(1);\n }\n String d = dates[1];\n while (!d.isEmpty() && d.charAt(0) == '0') {\n d = d.substring(1);\n }\n String y = dates[2];\n while (!y.isEmpty() && y.charAt(0) == '0') {\n y = y.substring(1);\n }\n int month = Integer.parseInt(m), day = Integer.parseInt(d), year = Integer.parseInt(y);\n if (month < 1 || month > 12) {\n return false;\n }\n if (Arrays.asList(1, 3, 5, 7, 8, 10, 12).contains(month) && (day < 1 || day > 31)) {\n return false;\n }\n if (Arrays.asList(4, 6, 9, 11).contains(month) && (day < 1 || day > 30)) {\n return false;\n }\n if (month == 2 && (day < 1 || day > 29)) {\n return false;\n }\n return true;\n } catch (Exception e) {\n return false;\n }\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.validDate(\"03-11-2000\" ) == true,\n s.validDate(\"15-01-2012\" ) == false,\n s.validDate(\"04-0-2040\" ) == false,\n s.validDate(\"06-04-2020\" ) == true,\n s.validDate(\"01-01-2007\" ) == true,\n s.validDate(\"03-32-2011\" ) == false,\n s.validDate(\"\" ) == false,\n s.validDate(\"04-31-3000\" ) == false,\n s.validDate(\"06-06-2005\" ) == true,\n s.validDate(\"21-31-2000\" ) == false,\n s.validDate(\"04-12-2003\" ) == true,\n s.validDate(\"04122003\" ) == false,\n s.validDate(\"20030412\" ) == false,\n s.validDate(\"2003-04\" ) == false,\n s.validDate(\"2003-04-12\" ) == false,\n s.validDate(\"04-2003\" ) == false\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You have to write a function which validates a given date string and\n returns true if the date is valid otherwise false.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example:\n validDate(\"03-11-2000\") => true\n validDate(\"15-01-2012\") => false\n validDate(\"04-0-2040\") => false\n validDate(\"06-04-2020\") => true\n validDate(\"06/04/2020\") => false", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean validDate(String date) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.validDate(\"03-11-2000\" ) == true,\n s.validDate(\"15-01-2012\" ) == false,\n s.validDate(\"04-0-2040\" ) == false,\n s.validDate(\"06-04-2020\" ) == true,\n s.validDate(\"06/04/2020\" ) == false\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " try {\n date = date.strip();\n String[] dates = date.split(\"-\" );\n String m = dates[1];\n while (!m.isEmpty() && m.charAt(0) == '0') {\n m = m.substring(1);\n }\n String d = dates[0];\n while (!d.isEmpty() && d.charAt(0) == '0') {\n d = d.substring(1);\n }\n String y = dates[2];\n while (!y.isEmpty() && y.charAt(0) == '0') {\n y = y.substring(1);\n }\n int month = Integer.parseInt(m), day = Integer.parseInt(d), year = Integer.parseInt(y);\n if (month < 1 || month > 12) {\n return false;\n }\n if (Arrays.asList(1, 3, 5, 7, 8, 10, 12).contains(month) && (day < 1 || day > 31)) {\n return false;\n }\n if (Arrays.asList(4, 6, 9, 11).contains(month) && (day < 1 || day > 30)) {\n return false;\n }\n if (month == 2 && (day < 1 || day > 29)) {\n return false;\n }\n return true;\n } catch (Exception e) {\n return false;\n }\n }\n}", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "ValidDate"}
|
126 |
{"task_id": "Java/125", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n splitWords(\"Hello world!\") == [\"Hello\", \"world!\"]\n splitWords(\"Hello,world!\") == [\"Hello\", \"world!\"]\n splitWords(\"abcdef\") == 3\n */\n public Object splitWords(String txt) {\n", "canonical_solution": " if (txt.contains(\" \" )) {\n return Arrays.asList(txt.split(\" \" ));\n } else if (txt.contains(\",\" )) {\n return Arrays.asList(txt.split(\"[,\\s]\" ));\n } else {\n int count = 0;\n for (char c : txt.toCharArray()) {\n if (Character.isLowerCase(c) && (c - 'a') % 2 == 1) {\n count += 1;\n }\n }\n return count;\n }\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.splitWords(\"Hello world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"Hello,world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"Hello world,!\" ), Arrays.asList(\"Hello\", \"world,!\" )),\n Objects.equals(s.splitWords(\"Hello,Hello,world !\" ), Arrays.asList(\"Hello,Hello,world\", \"!\" )),\n Objects.equals(s.splitWords(\"abcdef\" ), 3),\n Objects.equals(s.splitWords(\"aaabb\" ), 2),\n Objects.equals(s.splitWords(\"aaaBb\" ), 1),\n Objects.equals(s.splitWords(\"\" ), 0)\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n splitWords(\"Hello world!\") == [\"Hello\", \"world!\"]\n splitWords(\"Hello,world!\") == [\"Hello\", \"world!\"]\n splitWords(\"abcdef\") == 3", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public Object splitWords(String txt) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.splitWords(\"Hello world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"Hello,world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"abcdef\" ), 3)\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " if (txt.contains(\" \" )) {\n return Arrays.asList(txt.split(\",\" ));\n } else if (txt.contains(\",\" )) {\n return Arrays.asList(txt.split(\"[,\\s]\" ));\n } else {\n int count = 0;\n for (char c : txt.toCharArray()) {\n if (Character.isLowerCase(c) && (c - 'a') % 2 == 1) {\n count += 1;\n }\n }\n return count;\n }\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "SplitWords"}
|
127 |
{"task_id": "Java/126", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return false. Assume no negative numbers and only integers.\n\n Examples\n isSorted(Arrays.asList(5)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5)) -> false\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6, 7)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5, 6, 7)) -> false\n isSorted(Arrays.asList(1, 2, 2, 3, 3, 4)) -> true\n isSorted(Arrays.asList(1, 2, 2, 2, 3, 4)) -> false\n */\n public boolean isSorted(List<Integer> lst) {\n", "canonical_solution": " List<Integer> sorted_lst = new ArrayList<>(lst);\n Collections.sort(sorted_lst);\n if (!lst.equals(sorted_lst)) {\n return false;\n }\n for (int i = 0; i < lst.size() - 2; i++) {\n if (lst.get(i) == lst.get(i + 1) && lst.get(i) == lst.get(i + 2)) {\n return false;\n }\n }\n return true;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.isSorted(new ArrayList<>(List.of(5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5, 6, 7))) == false,\n s.isSorted(new ArrayList<>(List.of())) == true,\n s.isSorted(new ArrayList<>(List.of(1))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(3, 2, 1))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 2, 3, 4))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 3, 3, 4))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 3, 3, 4))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4))) == true\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return false. Assume no negative numbers and only integers.\n\n Examples\n isSorted(Arrays.asList(5)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5)) -> false\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6, 7)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5, 6, 7)) -> false\n isSorted(Arrays.asList(1, 2, 2, 3, 3, 4)) -> true\n isSorted(Arrays.asList(1, 2, 2, 2, 3, 4)) -> false", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean isSorted(List<Integer> lst) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.isSorted(new ArrayList<>(List.of(5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5, 6, 7))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 2, 3, 4))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 3, 3, 4))) == true\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<Integer> sorted_lst = new ArrayList<>(lst);\n Collections.sort(sorted_lst);\n if (!lst.equals(sorted_lst)) {\n return false;\n }\n for (int i = 0; i < lst.size() - 2; i++) {\n if (lst.get(i) == lst.get(i + 1)) {\n return false;\n }\n }\n return true;\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "IsSorted"}
|
128 |
-
{"task_id": "Java/127", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two\n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"\n */\n public String intersection(List<Integer> interval1, List<Integer> interval2) {\n", "canonical_solution": " int l = Math.max(interval1.get(0), interval2.get(0));\n int r = Math.min(interval1.get(1), interval2.get(1));\n int length = r - l;\n if (length <= 0) {\n return \"NO\";\n }\n if (length == 1) {\n return \"NO\";\n }\n if (length == 2) {\n return \"YES\";\n }\n for (int i = 2; i < length; i++) {\n if (length % i == 0) {\n return \"NO\";\n }\n }\n return \"YES\";\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(2, 3)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-1, 1), Arrays.asList(0, 4)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-3, -1), Arrays.asList(-5, 5)), \"YES\" ),\n Objects.equals(s.intersection(Arrays.asList(-2, 2), Arrays.asList(-4, 0)), \"YES\" ),\n Objects.equals(s.intersection(Arrays.asList(-11, 2), Arrays.asList(-1, -1)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(3, 5)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(1, 2)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-2, -2), Arrays.asList(-3, -2)), \"NO\" )\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two\n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public String intersection(List<Integer> interval1, List<Integer> interval2) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(2, 3)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-1, 1), Arrays.asList(0, 4)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-3, -1), Arrays.asList(-5, 5)), \"YES\" )\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int l = Math.max(interval1.get(0), interval2.get(0));\n int r = Math.min(interval1.get(1), interval2.get(1));\n int length = r - l;\n if (length
|
129 |
{"task_id": "Java/128", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return None for empty arr.\n\n Example:\n >>> prodSigns(Arrays.asList(1, 2, 2, -4)) == -9\n >>> prodSigns(Arrays.asList(0, 1)) == 0\n >>> prodSigns(Arrays.asList()) == None\n */\n public Optional<Integer> prodSigns(List<Integer> arr) {\n", "canonical_solution": " if (arr.size() == 0) {\n return Optional.empty();\n }\n if (arr.contains(0)) {\n return Optional.of(0);\n }\n int prod = (int) (-2 * (arr.stream().filter(p -> p < 0).count() % 2) + 1);\n return Optional.of(prod * (arr.stream().map(Math::abs).reduce(Integer::sum)).get());\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.prodSigns(Arrays.asList(1, 2, 2, -4)).get() == -9,\n s.prodSigns(Arrays.asList(0, 1)).get() == 0,\n s.prodSigns(Arrays.asList(1, 1, 1, 2, 3, -1, 1)).get() == -10,\n s.prodSigns(List.of()).isEmpty(),\n s.prodSigns(Arrays.asList(2, 4,1, 2, -1, -1, 9)).get() == 20,\n s.prodSigns(Arrays.asList(-1, 1, -1, 1)).get() == 4,\n s.prodSigns(Arrays.asList(-1, 1, 1, 1)).get() == -4,\n s.prodSigns(Arrays.asList(-1, 1, 1, 0)).get() == 0\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return None for empty arr.\n\n Example:\n >>> prodSigns(Arrays.asList(1, 2, 2, -4)) == -9\n >>> prodSigns(Arrays.asList(0, 1)) == 0\n >>> prodSigns(Arrays.asList()) == None", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public Optional<Integer> prodSigns(List<Integer> arr) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.prodSigns(Arrays.asList(1, 2, 2, -4)).get() == -9,\n s.prodSigns(Arrays.asList(0, 1)).get() == 0,\n s.prodSigns(List.of()).isEmpty()\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " if (arr.size() == 0) {\n return Optional.empty();\n }\n if (arr.contains(0)) {\n return Optional.of(0);\n }\n int prod = (int) (-2 * (arr.stream().filter(p -> p < 0).count() % 2) + 1 * 2);\n return Optional.of(prod * (arr.stream().map(Math::abs).reduce(Integer::sum)).get());\n }\n}", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "ProdSigns"}
|
130 |
{"task_id": "Java/129", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given a grid with N rows and N columns (N >= 2) and a positive integer k,\n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n\n Examples:\n\n Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\n Output: [1, 2, 1]\n\n Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\n Output: [1]\n */\n public List<Integer> minPath(List<List<Integer>> grid, int k) {\n", "canonical_solution": " int n = grid.size();\n int val = n * n + 1;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (grid.get(i).get(j) == 1) {\n List<Integer> temp = new ArrayList<>();\n if (i != 0) {\n temp.add(grid.get(i - 1).get(j));\n }\n if (j != 0) {\n temp.add(grid.get(i).get(j - 1));\n }\n if (i != n - 1) {\n temp.add(grid.get(i + 1).get(j));\n }\n if (j != n - 1) {\n temp.add(grid.get(i).get(j + 1));\n }\n val = Collections.min(temp);\n }\n }\n }\n List<Integer> ans = new ArrayList<>();\n for (int i = 0; i < k; i++) {\n if (i % 2 == 0) {\n ans.add(1);\n } else {\n ans.add(val);\n }\n }\n return ans;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.minPath(Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9)), 3).equals(Arrays.asList(1, 2, 1)),\n s.minPath(Arrays.asList(Arrays.asList(5, 9, 3), Arrays.asList(4, 1, 6), Arrays.asList(7, 8, 2)), 1).equals(List.of(1)),\n s.minPath(Arrays.asList(Arrays.asList(1, 2, 3, 4), Arrays.asList(5, 6, 7, 8), Arrays.asList(9, 10, 11, 12), Arrays.asList(13, 14, 15, 16)), 4).equals(Arrays.asList(1, 2, 1, 2)),\n s.minPath(Arrays.asList(Arrays.asList(6, 4, 13, 10), Arrays.asList(5, 7, 12, 1), Arrays.asList(3, 16, 11, 15), Arrays.asList(8, 14, 9, 2)), 7).equals(Arrays.asList(1, 10, 1, 10, 1, 10, 1)),\n s.minPath(Arrays.asList(Arrays.asList(8, 14, 9, 2), Arrays.asList(6, 4, 13, 15), Arrays.asList(5, 7, 1, 12), Arrays.asList(3, 10, 11, 16)), 5).equals(Arrays.asList(1, 7, 1, 7, 1)),\n s.minPath(Arrays.asList(Arrays.asList(11, 8, 7, 2), Arrays.asList(5, 16, 14, 4), Arrays.asList(9, 3, 15, 6), Arrays.asList(12, 13, 10, 1)), 9).equals(Arrays.asList(1, 6, 1, 6, 1, 6, 1, 6, 1)),\n s.minPath(Arrays.asList(Arrays.asList(12, 13, 10, 1), Arrays.asList(9, 3, 15, 6), Arrays.asList(5, 16, 14, 4), Arrays.asList(11, 8, 7, 2)), 12).equals(Arrays.asList(1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6)),\n s.minPath(Arrays.asList(Arrays.asList(2, 7, 4), Arrays.asList(3, 1, 5), Arrays.asList(6, 8, 9)), 8).equals(Arrays.asList(1, 3, 1, 3, 1, 3, 1, 3)),\n s.minPath(Arrays.asList(Arrays.asList(6, 1, 5), Arrays.asList(3, 8, 9), Arrays.asList(2, 7, 4)), 8).equals(Arrays.asList(1, 5, 1, 5, 1, 5, 1, 5)),\n s.minPath(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4)), 10).equals(Arrays.asList(1, 2, 1, 2, 1, 2, 1, 2, 1, 2)),\n s.minPath(Arrays.asList(Arrays.asList(1, 3), Arrays.asList(3, 2)), 10).equals(Arrays.asList(1, 3, 1, 3, 1, 3, 1, 3, 1, 3))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given a grid with N rows and N columns (N >= 2) and a positive integer k,\n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n\n Examples:\n\n Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\n Output: [1, 2, 1]\n\n Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\n Output: [1]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> minPath(List<List<Integer>> grid, int k) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.minPath(Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9)), 3).equals(Arrays.asList(1, 2, 1)),\n s.minPath(Arrays.asList(Arrays.asList(5, 9, 3), Arrays.asList(4, 1, 6), Arrays.asList(7, 8, 2)), 1).equals(List.of(1))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int n = grid.size();\n int val = n * n + 1;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (grid.get(i).get(j) == 1) {\n List<Integer> temp = new ArrayList<>();\n if (i != 0) {\n temp.add(grid.get(i).get(j));\n }\n if (j != 0) {\n temp.add(grid.get(i).get(j));\n }\n if (i != n - 1) {\n temp.add(grid.get(i).get(j));\n }\n if (j != n - 1) {\n temp.add(grid.get(i).get(j));\n }\n val = Collections.min(temp);\n }\n }\n }\n List<Integer> ans = new ArrayList<>();\n for (int i = 0; i < k; i++) {\n if (i == 0) {\n ans.add(1);\n } else {\n ans.add(val);\n }\n }\n return ans;\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Minpath"}
|
131 |
{"task_id": "Java/130", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in\n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8\n You are given a non-negative integer number n, you have to a return a list of the\n first n + 1 numbers of the Tribonacci sequence.\n Examples:\n tri(3) = [1, 3, 2, 8]\n */\n public List<Integer> tri(int n) {\n", "canonical_solution": " if (n == 0) {\n return List.of(1);\n }\n List<Integer> my_tri = new ArrayList<>(Arrays.asList(1, 3));\n for (int i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n my_tri.add(i / 2 + 1);\n } else {\n my_tri.add(my_tri.get(my_tri.size() - 1) + my_tri.get(my_tri.size() - 2) + (i + 3) / 2);\n }\n }\n return my_tri;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.tri(3).equals(Arrays.asList(1, 3, 2, 8)),\n s.tri(4).equals(Arrays.asList(1, 3, 2, 8, 3)),\n s.tri(5).equals(Arrays.asList(1, 3, 2, 8, 3, 15)),\n s.tri(6).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4)),\n s.tri(7).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24)),\n s.tri(8).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24, 5)),\n s.tri(9).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24, 5, 35)),\n s.tri(20).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24, 5, 35, 6, 48, 7, 63, 8, 80, 9, 99, 10, 120, 11)),\n s.tri(0).equals(List.of(1)),\n s.tri(1).equals(Arrays.asList(1, 3))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in\n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8\n You are given a non-negative integer number n, you have to a return a list of the\n first n + 1 numbers of the Tribonacci sequence.\n Examples:\n tri(3) = [1, 3, 2, 8]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> tri(int n) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.tri(3).equals(Arrays.asList(1, 3, 2, 8))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " if (n == 0) {\n return List.of(1);\n }\n List<Integer> my_tri = new ArrayList<>(Arrays.asList(1, 3));\n for (int i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n my_tri.add(i / 2 + 1);\n } else {\n my_tri.add(my_tri.get(my_tri.size() - 1) + my_tri.get(my_tri.size() - 2) + i + (i + 3) / 2);\n }\n }\n return my_tri;\n }\n}", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Tri"}
|
@@ -153,7 +153,7 @@
|
|
153 |
{"task_id": "Java/152", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match.\n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n\n example:\n\n compare(Arrays.asList(1,2,3,4,5,1),Arrays.asList(1,2,3,4,2,-2)) -> [0,0,0,0,3,3]\n compare(Arrays.asList(0,5,0,0,0,4),Arrays.asList(4,1,1,0,0,-2)) -> [4,4,1,0,0,6]\n */\n public List<Integer> compare(List<Integer> game, List<Integer> guess) {\n", "canonical_solution": " List<Integer> result = new ArrayList<>();\n for (int i = 0; i < game.size(); i++) {\n result.add(Math.abs(game.get(i) - guess.get(i)));\n }\n return result;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.compare(Arrays.asList(1, 2, 3, 4, 5, 1), Arrays.asList(1, 2, 3, 4, 2, -2)).equals(Arrays.asList(0, 0, 0, 0, 3, 3)),\n s.compare(Arrays.asList(0,5,0,0,0,4), Arrays.asList(4,1,1,0,0,-2)).equals(Arrays.asList(4,4,1,0,0,6)),\n s.compare(Arrays.asList(1, 2, 3, 4, 5, 1), Arrays.asList(1, 2, 3, 4, 2, -2)).equals(Arrays.asList(0, 0, 0, 0, 3, 3)),\n s.compare(Arrays.asList(0, 0, 0, 0, 0, 0), Arrays.asList(0, 0, 0, 0, 0, 0)).equals(Arrays.asList(0, 0, 0, 0, 0, 0)),\n s.compare(Arrays.asList(1, 2, 3), Arrays.asList(-1, -2, -3)).equals(Arrays.asList(2, 4, 6)),\n s.compare(Arrays.asList(1, 2, 3, 5), Arrays.asList(-1, 2, 3, 4)).equals(Arrays.asList(2, 0, 0, 1))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match.\n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n\n example:\n\n compare(Arrays.asList(1,2,3,4,5,1),Arrays.asList(1,2,3,4,2,-2)) -> [0,0,0,0,3,3]\n compare(Arrays.asList(0,5,0,0,0,4),Arrays.asList(4,1,1,0,0,-2)) -> [4,4,1,0,0,6]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> compare(List<Integer> game, List<Integer> guess) {\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.compare(Arrays.asList(1, 2, 3, 4, 5, 1), Arrays.asList(1, 2, 3, 4, 2, -2)).equals(Arrays.asList(0, 0, 0, 0, 3, 3)),\n s.compare(Arrays.asList(0,5,0,0,0,4), Arrays.asList(4,1,1,0,0,-2)).equals(Arrays.asList(4,4,1,0,0,6))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<Integer> result = new ArrayList<>();\n for (int i = 0; i < game.size(); i++) {\n result.add(Math.abs(game.get(i) - guess.get(i))+Math.abs(guess.get(i) - game.get(i)));\n }\n return result;\n }\n}", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Compare"}
|
154 |
{"task_id": "Java/153", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters\n in the extension's name, the strength is given by the fraction CAP - SM.\n You should find the strongest extension and return a string in this\n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: [\"SErviNGSliCes\", \"Cheese\", \"StuFfed\"] then you should\n return \"Slices.SErviNGSliCes\" since \"SErviNGSliCes\" is the strongest extension\n (its strength is -1).\n Example:\n for StrongestExtension(\"my_class\", [\"AA\", \"Be\", \"CC\"]) == \"my_class.AA\"\n */\n public String StrongestExtension(String class_name, List<String> extensions) {\n", "canonical_solution": " String strong = extensions.get(0);\n int my_val = (int) (strong.chars().filter(Character::isUpperCase).count() - strong.chars().filter(Character::isLowerCase).count());\n for (String s : extensions) {\n int val = (int) (s.chars().filter(Character::isUpperCase).count() - s.chars().filter(Character::isLowerCase).count());\n if (val > my_val) {\n strong = s;\n my_val = val;\n }\n }\n return class_name + \".\" + strong;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.StrongestExtension(\"Watashi\", Arrays.asList(\"tEN\", \"niNE\", \"eIGHt8OKe\")), \"Watashi.eIGHt8OKe\"),\n Objects.equals(s.StrongestExtension(\"Boku123\", Arrays.asList(\"nani\", \"NazeDa\", \"YEs.WeCaNe\", \"32145tggg\")), \"Boku123.YEs.WeCaNe\"),\n Objects.equals(s.StrongestExtension(\"__YESIMHERE\", Arrays.asList(\"t\", \"eMptY\", \"nothing\", \"zeR00\", \"NuLl__\", \"123NoooneB321\")), \"__YESIMHERE.NuLl__\"),\n Objects.equals(s.StrongestExtension(\"K\", Arrays.asList(\"Ta\", \"TAR\", \"t234An\", \"cosSo\")), \"K.TAR\"),\n Objects.equals(s.StrongestExtension(\"__HAHA\", Arrays.asList(\"Tab\", \"123\", \"781345\", \"-_-\")), \"__HAHA.123\"),\n Objects.equals(s.StrongestExtension(\"YameRore\", Arrays.asList(\"HhAas\", \"okIWILL123\", \"WorkOut\", \"Fails\", \"-_-\")), \"YameRore.okIWILL123\"),\n Objects.equals(s.StrongestExtension(\"finNNalLLly\", Arrays.asList(\"Die\", \"NowW\", \"Wow\", \"WoW\")), \"finNNalLLly.WoW\"),\n Objects.equals(s.StrongestExtension(\"_\", Arrays.asList(\"Bb\", \"91245\")), \"_.Bb\"),\n Objects.equals(s.StrongestExtension(\"Sp\", Arrays.asList(\"671235\", \"Bb\")), \"Sp.671235\")\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters\n in the extension's name, the strength is given by the fraction CAP - SM.\n You should find the strongest extension and return a string in this\n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: [\"SErviNGSliCes\", \"Cheese\", \"StuFfed\"] then you should\n return \"Slices.SErviNGSliCes\" since \"SErviNGSliCes\" is the strongest extension\n (its strength is -1).\n Example:\n for StrongestExtension(\"my_class\", [\"AA\", \"Be\", \"CC\"]) == \"my_class.AA\"", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public String StrongestExtension(String class_name, List<String> extensions) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.StrongestExtension(\"my_class\", Arrays.asList(\"AA\", \"Be\", \"CC\")), \"my_class.AA\")\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " String strong = extensions.get(0);\n int my_val = (int) (strong.chars().filter(Character::isUpperCase).count() - strong.chars().filter(Character::isLowerCase).count());\n for (String s : extensions) {\n int val = (int) (s.chars().filter(Character::isUpperCase).count() - s.chars().filter(Character::isLowerCase).count());\n if (val > my_val) {\n strong = s;\n my_val = val;\n }\n }\n return class_name + strong;\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "StrongestExtension"}
|
155 |
{"task_id": "Java/154", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\n cycpatternCheck(\"abcd\",\"abd\") => false\n cycpatternCheck(\"hello\",\"ell\") => true\n cycpatternCheck(\"whassup\",\"psus\") => false\n cycpatternCheck(\"abab\",\"baa\") => true\n cycpatternCheck(\"efef\",\"eeff\") => false\n cycpatternCheck(\"himenss\",\"simen\") => true\n */\n public boolean cycpatternCheck(String a, String b) {\n", "canonical_solution": " int l = b.length();\n String pat = b + b;\n for (int i = 0; i <= a.length() - l; i++) {\n for (int j = 0; j <= l; j++) {\n if (a.substring(i, i + l).equals(pat.substring(j, j + l))) {\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.cycpatternCheck(\"xyzw\", \"xyw\") == false,\n s.cycpatternCheck(\"yello\", \"ell\") == true,\n s.cycpatternCheck(\"whattup\", \"ptut\") == false,\n s.cycpatternCheck(\"efef\", \"fee\") == true,\n s.cycpatternCheck(\"abab\", \"aabb\") == false,\n s.cycpatternCheck(\"winemtt\", \"tinem\") == true\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\n cycpatternCheck(\"abcd\",\"abd\") => false\n cycpatternCheck(\"hello\",\"ell\") => true\n cycpatternCheck(\"whassup\",\"psus\") => false\n cycpatternCheck(\"abab\",\"baa\") => true\n cycpatternCheck(\"efef\",\"eeff\") => false\n cycpatternCheck(\"himenss\",\"simen\") => true", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean cycpatternCheck(String a, String b) {\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.cycpatternCheck(\"abcd\", \"abd\") == false,\n s.cycpatternCheck(\"hello\", \"ell\") == true,\n s.cycpatternCheck(\"whassup\", \"psus\") == false,\n s.cycpatternCheck(\"abab\", \"baa\") == true,\n s.cycpatternCheck(\"efef\", \"eeff\") == false,\n s.cycpatternCheck(\"himenss\", \"simen\") == true\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int l = b.length();\n String pat = b + b;\n for (int i = 0; i <= a.length() - l; i++) {\n for (int j = 0; j <= b.length() - l; j++) {\n if (a.substring(i, i + l).equals(pat.substring(j, j + l))) {\n return true;\n }\n }\n }\n return false;\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "CycpatternCheck"}
|
156 |
-
{"task_id": "Java/155", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given an integer. return a tuple that has the number of even and odd digits respectively.\n \n Example:\n evenOddCount(-12) ==> (1, 1)\n evenOddCount(123) ==> (1, 2)\n */\n public List<Integer> evenOddCount(int num) {\n", "canonical_solution": " int even_count = 0, odd_count = 0;\n for (char i : String.valueOf(Math.abs(num)).toCharArray()) {\n if ((i - '0') % 2 == 0) {\n even_count += 1;\n } else {\n odd_count += 1;\n }\n }\n return Arrays.asList(even_count, odd_count);\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.evenOddCount(7).equals(Arrays.asList(0, 1)),\n s.evenOddCount(-78).equals(Arrays.asList(1, 1)),\n s.evenOddCount(3452).equals(Arrays.asList(2, 2)),\n s.evenOddCount(346211).equals(Arrays.asList(3, 3)),\n s.evenOddCount(-345821).equals(Arrays.asList(3, 3)),\n s.evenOddCount(-2).equals(Arrays.asList(1, 0)),\n s.evenOddCount(-45347).equals(Arrays.asList(2, 3)),\n s.evenOddCount(0).equals(Arrays.asList(1, 0))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given an integer. return a tuple that has the number of even and odd digits respectively.\n \n Example:\n evenOddCount(-12) ==> (1, 1)\n evenOddCount(123) ==> (1, 2)", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> evenOddCount(int num) {\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.evenOddCount(-12).equals(Arrays.asList(1, 1)),\n s.evenOddCount(123).equals(Arrays.asList(1, 2))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int even_count = 0, odd_count = 0;\n for (char i : String.valueOf(Math.abs(num)).toCharArray()) {\n if (i % 2 == 0) {\n even_count += 1;\n }
|
157 |
{"task_id": "Java/156", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given a positive integer, obtain its roman numeral equivalent as a string,\n and return it in lowercase.\n Restrictions: 1 <= num <= 1000\n\n Examples:\n >>> intToMiniRoman(19) == \"xix\"\n >>> intToMiniRoman(152) == \"clii\"\n >>> intToMiniRoman(426) == \"cdxxvi\"\n */\n public String intToMiniRoman(int number) {\n", "canonical_solution": " List<Integer> num = Arrays.asList(1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000);\n List<String> sym = Arrays.asList(\"I\", \"IV\", \"V\", \"IX\", \"X\", \"XL\", \"L\", \"XC\", \"C\", \"CD\", \"D\", \"CM\", \"M\");\n int i = 12;\n String res = \"\";\n while (number > 0) {\n int div = number / num.get(i);\n number %= num.get(i);\n while (div != 0) {\n res += sym.get(i);\n div -= 1;\n }\n i -= 1;\n }\n return res.toLowerCase();\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.intToMiniRoman(19), \"xix\"),\n Objects.equals(s.intToMiniRoman(152), \"clii\"),\n Objects.equals(s.intToMiniRoman(251), \"ccli\"),\n Objects.equals(s.intToMiniRoman(426), \"cdxxvi\"),\n Objects.equals(s.intToMiniRoman(500), \"d\"),\n Objects.equals(s.intToMiniRoman(1), \"i\"),\n Objects.equals(s.intToMiniRoman(4), \"iv\"),\n Objects.equals(s.intToMiniRoman(43), \"xliii\"),\n Objects.equals(s.intToMiniRoman(90), \"xc\"),\n Objects.equals(s.intToMiniRoman(94), \"xciv\"),\n Objects.equals(s.intToMiniRoman(532), \"dxxxii\"),\n Objects.equals(s.intToMiniRoman(900), \"cm\"),\n Objects.equals(s.intToMiniRoman(994), \"cmxciv\"),\n Objects.equals(s.intToMiniRoman(1000), \"m\")\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given a positive integer, obtain its roman numeral equivalent as a string,\n and return it in lowercase.\n Restrictions: 1 <= num <= 1000\n\n Examples:\n >>> intToMiniRoman(19) == \"xix\"\n >>> intToMiniRoman(152) == \"clii\"\n >>> intToMiniRoman(426) == \"cdxxvi\"", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public String intToMiniRoman(int 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 Objects.equals(s.intToMiniRoman(19), \"xix\"),\n Objects.equals(s.intToMiniRoman(152), \"clii\"),\n Objects.equals(s.intToMiniRoman(426), \"cdxxvi\")\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<Integer> num = Arrays.asList(1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000);\n List<String> sym = Arrays.asList(\"I\", \"IV\", \"V\", \"IX\", \"X\", \"XL\", \"L\", \"XC\", \"C\", \"CD\", \"D\", \"CM\", \"M\");\n int i = 12;\n String res = \"\";\n while (number > 0) {\n int div = number / num.get(i);\n while (div != 0) {\n res += sym.get(i);\n div -= 1;\n }\n i -= 1;\n }\n return res.toLowerCase();\n }\n}", "bug_type": "missing logic", "failure_symptoms": "infinite loop", "entry_point": "IntToMiniRoman"}
|
158 |
{"task_id": "Java/157", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given the lengths of the three sides of a triangle. Return true if the three\n sides form a right-angled triangle, false otherwise.\n A right-angled triangle is a triangle in which one angle is right angle or\n 90 degree.\n Example:\n rightAngleTriangle(3, 4, 5) == true\n rightAngleTriangle(1, 2, 3) == false\n */\n public boolean rightAngleTriangle(int a, int b, int c) {\n", "canonical_solution": " return a * a == b * b + c * c || b * b == a * a + c * c || c * c == a * a + b * b;\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.rightAngleTriangle(3, 4, 5) == true,\n s.rightAngleTriangle(1, 2, 3) == false,\n s.rightAngleTriangle(10, 6, 8) == true,\n s.rightAngleTriangle(2, 2, 2) == false,\n s.rightAngleTriangle(7, 24, 25) == true,\n s.rightAngleTriangle(10, 5, 7) == false,\n s.rightAngleTriangle(5, 12, 13) == true,\n s.rightAngleTriangle(15, 8, 17) == true,\n s.rightAngleTriangle(48, 55, 73) == true,\n s.rightAngleTriangle(1, 1, 1) == false,\n s.rightAngleTriangle(2, 2, 10) == false\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given the lengths of the three sides of a triangle. Return true if the three\n sides form a right-angled triangle, false otherwise.\n A right-angled triangle is a triangle in which one angle is right angle or\n 90 degree.\n Example:\n rightAngleTriangle(3, 4, 5) == true\n rightAngleTriangle(1, 2, 3) == false", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean rightAngleTriangle(int a, int b, int c) {\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.rightAngleTriangle(3, 4, 5) == true,\n s.rightAngleTriangle(1, 2, 3) == false\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " return c * c == a * a + b * b;\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "RightAngleTriangle"}
|
159 |
{"task_id": "Java/158", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Write a function that accepts a list of strings.\n The list contains different words. Return the word with maximum number\n of unique characters. If multiple strings have maximum number of unique\n characters, return the one which comes first in lexicographical order.\n\n findMax([\"name\", \"of\", \"string\"]) == \"string\"\n findMax([\"name\", \"enam\", \"game\"]) == \"enam\"\n findMax([\"aaaaaaa\", \"bb\" ,\"cc\"]) == \"\"aaaaaaa\"\n */\n public String findMax(List<String> words) {\n", "canonical_solution": " List<String> words_sort = new ArrayList<>(words);\n words_sort.sort(new Comparator<String>() {\n @Override\n public int compare(String o1, String o2) {\n Set<Character> s1 = new HashSet<>();\n for (char ch : o1.toCharArray()) {\n s1.add(ch);\n }\n Set<Character> s2 = new HashSet<>();\n for (char ch : o2.toCharArray()) {\n s2.add(ch);\n }\n if (s1.size() > s2.size()) {\n return 1;\n } else if (s1.size() < s2.size()) {\n return -1;\n } else {\n return -o1.compareTo(o2);\n }\n }\n });\n return words_sort.get(words_sort.size() - 1);\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.findMax(new ArrayList<>(Arrays.asList(\"name\", \"of\", \"string\"))).equals(\"string\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"name\", \"enam\", \"game\"))).equals(\"enam\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"aaaaaaa\", \"bb\", \"cc\"))).equals(\"aaaaaaa\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"abc\", \"cba\"))).equals(\"abc\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"play\", \"this\", \"game\", \"of\", \"footbott\"))).equals(\"footbott\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"we\", \"are\", \"gonna\", \"rock\"))).equals(\"gonna\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"we\", \"are\", \"a\", \"mad\", \"nation\"))).equals(\"nation\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"this\", \"is\", \"a\", \"prrk\"))).equals(\"this\"),\n s.findMax(new ArrayList<>(List.of(\"b\"))).equals(\"b\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"play\", \"play\", \"play\"))).equals(\"play\")\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Write a function that accepts a list of strings.\n The list contains different words. Return the word with maximum number\n of unique characters. If multiple strings have maximum number of unique\n characters, return the one which comes first in lexicographical order.\n\n findMax([\"name\", \"of\", \"string\"]) == \"string\"\n findMax([\"name\", \"enam\", \"game\"]) == \"enam\"\n findMax([\"aaaaaaa\", \"bb\" ,\"cc\"]) == \"\"aaaaaaa\"", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public String findMax(List<String> words) {\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.findMax(new ArrayList<>(Arrays.asList(\"name\", \"of\", \"string\"))).equals(\"string\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"name\", \"enam\", \"game\"))).equals(\"enam\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"aaaaaaa\", \"bb\", \"cc\"))).equals(\"aaaaaaa\")\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<String> words_sort = new ArrayList<>(words);\n words_sort.sort(new Comparator<String>() {\n @Override\n public int compare(String o1, String o2) {\n Set<Character> s1 = new HashSet<>();\n for (char ch : o1.toCharArray()) {\n s1.add(ch);\n }\n Set<Character> s2 = new HashSet<>();\n for (char ch : o2.toCharArray()) {\n s2.add(ch);\n }\n if (s1.size() > s2.size()) {\n return 1;\n } else {\n return -o1.compareTo(o2);\n }\n }\n });\n return words_sort.get(words_sort.size() - 1);\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "FindMax"}
|
|
|
125 |
{"task_id": "Java/124", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You have to write a function which validates a given date string and\n returns true if the date is valid otherwise false.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example:\n validDate(\"03-11-2000\") => true\n validDate(\"15-01-2012\") => false\n validDate(\"04-0-2040\") => false\n validDate(\"06-04-2020\") => true\n validDate(\"06/04/2020\") => false\n */\n public boolean validDate(String date) {\n", "canonical_solution": " try {\n date = date.strip();\n String[] dates = date.split(\"-\" );\n String m = dates[0];\n while (!m.isEmpty() && m.charAt(0) == '0') {\n m = m.substring(1);\n }\n String d = dates[1];\n while (!d.isEmpty() && d.charAt(0) == '0') {\n d = d.substring(1);\n }\n String y = dates[2];\n while (!y.isEmpty() && y.charAt(0) == '0') {\n y = y.substring(1);\n }\n int month = Integer.parseInt(m), day = Integer.parseInt(d), year = Integer.parseInt(y);\n if (month < 1 || month > 12) {\n return false;\n }\n if (Arrays.asList(1, 3, 5, 7, 8, 10, 12).contains(month) && (day < 1 || day > 31)) {\n return false;\n }\n if (Arrays.asList(4, 6, 9, 11).contains(month) && (day < 1 || day > 30)) {\n return false;\n }\n if (month == 2 && (day < 1 || day > 29)) {\n return false;\n }\n return true;\n } catch (Exception e) {\n return false;\n }\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.validDate(\"03-11-2000\" ) == true,\n s.validDate(\"15-01-2012\" ) == false,\n s.validDate(\"04-0-2040\" ) == false,\n s.validDate(\"06-04-2020\" ) == true,\n s.validDate(\"01-01-2007\" ) == true,\n s.validDate(\"03-32-2011\" ) == false,\n s.validDate(\"\" ) == false,\n s.validDate(\"04-31-3000\" ) == false,\n s.validDate(\"06-06-2005\" ) == true,\n s.validDate(\"21-31-2000\" ) == false,\n s.validDate(\"04-12-2003\" ) == true,\n s.validDate(\"04122003\" ) == false,\n s.validDate(\"20030412\" ) == false,\n s.validDate(\"2003-04\" ) == false,\n s.validDate(\"2003-04-12\" ) == false,\n s.validDate(\"04-2003\" ) == false\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You have to write a function which validates a given date string and\n returns true if the date is valid otherwise false.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example:\n validDate(\"03-11-2000\") => true\n validDate(\"15-01-2012\") => false\n validDate(\"04-0-2040\") => false\n validDate(\"06-04-2020\") => true\n validDate(\"06/04/2020\") => false", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean validDate(String date) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.validDate(\"03-11-2000\" ) == true,\n s.validDate(\"15-01-2012\" ) == false,\n s.validDate(\"04-0-2040\" ) == false,\n s.validDate(\"06-04-2020\" ) == true,\n s.validDate(\"06/04/2020\" ) == false\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " try {\n date = date.strip();\n String[] dates = date.split(\"-\" );\n String m = dates[1];\n while (!m.isEmpty() && m.charAt(0) == '0') {\n m = m.substring(1);\n }\n String d = dates[0];\n while (!d.isEmpty() && d.charAt(0) == '0') {\n d = d.substring(1);\n }\n String y = dates[2];\n while (!y.isEmpty() && y.charAt(0) == '0') {\n y = y.substring(1);\n }\n int month = Integer.parseInt(m), day = Integer.parseInt(d), year = Integer.parseInt(y);\n if (month < 1 || month > 12) {\n return false;\n }\n if (Arrays.asList(1, 3, 5, 7, 8, 10, 12).contains(month) && (day < 1 || day > 31)) {\n return false;\n }\n if (Arrays.asList(4, 6, 9, 11).contains(month) && (day < 1 || day > 30)) {\n return false;\n }\n if (month == 2 && (day < 1 || day > 29)) {\n return false;\n }\n return true;\n } catch (Exception e) {\n return false;\n }\n }\n}", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "ValidDate"}
|
126 |
{"task_id": "Java/125", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n splitWords(\"Hello world!\") == [\"Hello\", \"world!\"]\n splitWords(\"Hello,world!\") == [\"Hello\", \"world!\"]\n splitWords(\"abcdef\") == 3\n */\n public Object splitWords(String txt) {\n", "canonical_solution": " if (txt.contains(\" \" )) {\n return Arrays.asList(txt.split(\" \" ));\n } else if (txt.contains(\",\" )) {\n return Arrays.asList(txt.split(\"[,\\s]\" ));\n } else {\n int count = 0;\n for (char c : txt.toCharArray()) {\n if (Character.isLowerCase(c) && (c - 'a') % 2 == 1) {\n count += 1;\n }\n }\n return count;\n }\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.splitWords(\"Hello world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"Hello,world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"Hello world,!\" ), Arrays.asList(\"Hello\", \"world,!\" )),\n Objects.equals(s.splitWords(\"Hello,Hello,world !\" ), Arrays.asList(\"Hello,Hello,world\", \"!\" )),\n Objects.equals(s.splitWords(\"abcdef\" ), 3),\n Objects.equals(s.splitWords(\"aaabb\" ), 2),\n Objects.equals(s.splitWords(\"aaaBb\" ), 1),\n Objects.equals(s.splitWords(\"\" ), 0)\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n splitWords(\"Hello world!\") == [\"Hello\", \"world!\"]\n splitWords(\"Hello,world!\") == [\"Hello\", \"world!\"]\n splitWords(\"abcdef\") == 3", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public Object splitWords(String txt) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.splitWords(\"Hello world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"Hello,world!\" ), Arrays.asList(\"Hello\", \"world!\" )),\n Objects.equals(s.splitWords(\"abcdef\" ), 3)\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " if (txt.contains(\" \" )) {\n return Arrays.asList(txt.split(\",\" ));\n } else if (txt.contains(\",\" )) {\n return Arrays.asList(txt.split(\"[,\\s]\" ));\n } else {\n int count = 0;\n for (char c : txt.toCharArray()) {\n if (Character.isLowerCase(c) && (c - 'a') % 2 == 1) {\n count += 1;\n }\n }\n return count;\n }\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "SplitWords"}
|
127 |
{"task_id": "Java/126", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return false. Assume no negative numbers and only integers.\n\n Examples\n isSorted(Arrays.asList(5)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5)) -> false\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6, 7)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5, 6, 7)) -> false\n isSorted(Arrays.asList(1, 2, 2, 3, 3, 4)) -> true\n isSorted(Arrays.asList(1, 2, 2, 2, 3, 4)) -> false\n */\n public boolean isSorted(List<Integer> lst) {\n", "canonical_solution": " List<Integer> sorted_lst = new ArrayList<>(lst);\n Collections.sort(sorted_lst);\n if (!lst.equals(sorted_lst)) {\n return false;\n }\n for (int i = 0; i < lst.size() - 2; i++) {\n if (lst.get(i) == lst.get(i + 1) && lst.get(i) == lst.get(i + 2)) {\n return false;\n }\n }\n return true;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.isSorted(new ArrayList<>(List.of(5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5, 6, 7))) == false,\n s.isSorted(new ArrayList<>(List.of())) == true,\n s.isSorted(new ArrayList<>(List.of(1))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(3, 2, 1))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 2, 3, 4))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 3, 3, 4))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 3, 3, 4))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4))) == true\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return false. Assume no negative numbers and only integers.\n\n Examples\n isSorted(Arrays.asList(5)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5)) -> false\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6)) -> true\n isSorted(Arrays.asList(1, 2, 3, 4, 5, 6, 7)) -> true\n isSorted(Arrays.asList(1, 3, 2, 4, 5, 6, 7)) -> false\n isSorted(Arrays.asList(1, 2, 2, 3, 3, 4)) -> true\n isSorted(Arrays.asList(1, 2, 2, 2, 3, 4)) -> false", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean isSorted(List<Integer> lst) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.isSorted(new ArrayList<>(List.of(5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7))) == true,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 3, 2, 4, 5, 6, 7))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 2, 3, 4))) == false,\n s.isSorted(new ArrayList<>(Arrays.asList(1, 2, 2, 3, 3, 4))) == true\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<Integer> sorted_lst = new ArrayList<>(lst);\n Collections.sort(sorted_lst);\n if (!lst.equals(sorted_lst)) {\n return false;\n }\n for (int i = 0; i < lst.size() - 2; i++) {\n if (lst.get(i) == lst.get(i + 1)) {\n return false;\n }\n }\n return true;\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "IsSorted"}
|
128 |
+
{"task_id": "Java/127", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two\n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"\n */\n public String intersection(List<Integer> interval1, List<Integer> interval2) {\n", "canonical_solution": " int l = Math.max(interval1.get(0), interval2.get(0));\n int r = Math.min(interval1.get(1), interval2.get(1));\n int length = r - l;\n if (length <= 0) {\n return \"NO\";\n }\n if (length == 1) {\n return \"NO\";\n }\n if (length == 2) {\n return \"YES\";\n }\n for (int i = 2; i < length; i++) {\n if (length % i == 0) {\n return \"NO\";\n }\n }\n return \"YES\";\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(2, 3)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-1, 1), Arrays.asList(0, 4)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-3, -1), Arrays.asList(-5, 5)), \"YES\" ),\n Objects.equals(s.intersection(Arrays.asList(-2, 2), Arrays.asList(-4, 0)), \"YES\" ),\n Objects.equals(s.intersection(Arrays.asList(-11, 2), Arrays.asList(-1, -1)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(3, 5)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(1, 2)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-2, -2), Arrays.asList(-3, -2)), \"NO\" )\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two\n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public String intersection(List<Integer> interval1, List<Integer> interval2) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.intersection(Arrays.asList(1, 2), Arrays.asList(2, 3)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-1, 1), Arrays.asList(0, 4)), \"NO\" ),\n Objects.equals(s.intersection(Arrays.asList(-3, -1), Arrays.asList(-5, 5)), \"YES\" )\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int l = Math.max(interval1.get(0), interval2.get(0));\n int r = Math.min(interval1.get(1), interval2.get(1));\n int length = r - l;\n if (length == 1) {\n return \"NO\";\n }\n return \"YES\";\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Intersection"}
|
129 |
{"task_id": "Java/128", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return None for empty arr.\n\n Example:\n >>> prodSigns(Arrays.asList(1, 2, 2, -4)) == -9\n >>> prodSigns(Arrays.asList(0, 1)) == 0\n >>> prodSigns(Arrays.asList()) == None\n */\n public Optional<Integer> prodSigns(List<Integer> arr) {\n", "canonical_solution": " if (arr.size() == 0) {\n return Optional.empty();\n }\n if (arr.contains(0)) {\n return Optional.of(0);\n }\n int prod = (int) (-2 * (arr.stream().filter(p -> p < 0).count() % 2) + 1);\n return Optional.of(prod * (arr.stream().map(Math::abs).reduce(Integer::sum)).get());\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.prodSigns(Arrays.asList(1, 2, 2, -4)).get() == -9,\n s.prodSigns(Arrays.asList(0, 1)).get() == 0,\n s.prodSigns(Arrays.asList(1, 1, 1, 2, 3, -1, 1)).get() == -10,\n s.prodSigns(List.of()).isEmpty(),\n s.prodSigns(Arrays.asList(2, 4,1, 2, -1, -1, 9)).get() == 20,\n s.prodSigns(Arrays.asList(-1, 1, -1, 1)).get() == 4,\n s.prodSigns(Arrays.asList(-1, 1, 1, 1)).get() == -4,\n s.prodSigns(Arrays.asList(-1, 1, 1, 0)).get() == 0\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return None for empty arr.\n\n Example:\n >>> prodSigns(Arrays.asList(1, 2, 2, -4)) == -9\n >>> prodSigns(Arrays.asList(0, 1)) == 0\n >>> prodSigns(Arrays.asList()) == None", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public Optional<Integer> prodSigns(List<Integer> arr) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.prodSigns(Arrays.asList(1, 2, 2, -4)).get() == -9,\n s.prodSigns(Arrays.asList(0, 1)).get() == 0,\n s.prodSigns(List.of()).isEmpty()\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " if (arr.size() == 0) {\n return Optional.empty();\n }\n if (arr.contains(0)) {\n return Optional.of(0);\n }\n int prod = (int) (-2 * (arr.stream().filter(p -> p < 0).count() % 2) + 1 * 2);\n return Optional.of(prod * (arr.stream().map(Math::abs).reduce(Integer::sum)).get());\n }\n}", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "ProdSigns"}
|
130 |
{"task_id": "Java/129", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given a grid with N rows and N columns (N >= 2) and a positive integer k,\n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n\n Examples:\n\n Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\n Output: [1, 2, 1]\n\n Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\n Output: [1]\n */\n public List<Integer> minPath(List<List<Integer>> grid, int k) {\n", "canonical_solution": " int n = grid.size();\n int val = n * n + 1;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (grid.get(i).get(j) == 1) {\n List<Integer> temp = new ArrayList<>();\n if (i != 0) {\n temp.add(grid.get(i - 1).get(j));\n }\n if (j != 0) {\n temp.add(grid.get(i).get(j - 1));\n }\n if (i != n - 1) {\n temp.add(grid.get(i + 1).get(j));\n }\n if (j != n - 1) {\n temp.add(grid.get(i).get(j + 1));\n }\n val = Collections.min(temp);\n }\n }\n }\n List<Integer> ans = new ArrayList<>();\n for (int i = 0; i < k; i++) {\n if (i % 2 == 0) {\n ans.add(1);\n } else {\n ans.add(val);\n }\n }\n return ans;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.minPath(Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9)), 3).equals(Arrays.asList(1, 2, 1)),\n s.minPath(Arrays.asList(Arrays.asList(5, 9, 3), Arrays.asList(4, 1, 6), Arrays.asList(7, 8, 2)), 1).equals(List.of(1)),\n s.minPath(Arrays.asList(Arrays.asList(1, 2, 3, 4), Arrays.asList(5, 6, 7, 8), Arrays.asList(9, 10, 11, 12), Arrays.asList(13, 14, 15, 16)), 4).equals(Arrays.asList(1, 2, 1, 2)),\n s.minPath(Arrays.asList(Arrays.asList(6, 4, 13, 10), Arrays.asList(5, 7, 12, 1), Arrays.asList(3, 16, 11, 15), Arrays.asList(8, 14, 9, 2)), 7).equals(Arrays.asList(1, 10, 1, 10, 1, 10, 1)),\n s.minPath(Arrays.asList(Arrays.asList(8, 14, 9, 2), Arrays.asList(6, 4, 13, 15), Arrays.asList(5, 7, 1, 12), Arrays.asList(3, 10, 11, 16)), 5).equals(Arrays.asList(1, 7, 1, 7, 1)),\n s.minPath(Arrays.asList(Arrays.asList(11, 8, 7, 2), Arrays.asList(5, 16, 14, 4), Arrays.asList(9, 3, 15, 6), Arrays.asList(12, 13, 10, 1)), 9).equals(Arrays.asList(1, 6, 1, 6, 1, 6, 1, 6, 1)),\n s.minPath(Arrays.asList(Arrays.asList(12, 13, 10, 1), Arrays.asList(9, 3, 15, 6), Arrays.asList(5, 16, 14, 4), Arrays.asList(11, 8, 7, 2)), 12).equals(Arrays.asList(1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6)),\n s.minPath(Arrays.asList(Arrays.asList(2, 7, 4), Arrays.asList(3, 1, 5), Arrays.asList(6, 8, 9)), 8).equals(Arrays.asList(1, 3, 1, 3, 1, 3, 1, 3)),\n s.minPath(Arrays.asList(Arrays.asList(6, 1, 5), Arrays.asList(3, 8, 9), Arrays.asList(2, 7, 4)), 8).equals(Arrays.asList(1, 5, 1, 5, 1, 5, 1, 5)),\n s.minPath(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4)), 10).equals(Arrays.asList(1, 2, 1, 2, 1, 2, 1, 2, 1, 2)),\n s.minPath(Arrays.asList(Arrays.asList(1, 3), Arrays.asList(3, 2)), 10).equals(Arrays.asList(1, 3, 1, 3, 1, 3, 1, 3, 1, 3))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given a grid with N rows and N columns (N >= 2) and a positive integer k,\n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n\n Examples:\n\n Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\n Output: [1, 2, 1]\n\n Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\n Output: [1]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> minPath(List<List<Integer>> grid, int k) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.minPath(Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9)), 3).equals(Arrays.asList(1, 2, 1)),\n s.minPath(Arrays.asList(Arrays.asList(5, 9, 3), Arrays.asList(4, 1, 6), Arrays.asList(7, 8, 2)), 1).equals(List.of(1))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int n = grid.size();\n int val = n * n + 1;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (grid.get(i).get(j) == 1) {\n List<Integer> temp = new ArrayList<>();\n if (i != 0) {\n temp.add(grid.get(i).get(j));\n }\n if (j != 0) {\n temp.add(grid.get(i).get(j));\n }\n if (i != n - 1) {\n temp.add(grid.get(i).get(j));\n }\n if (j != n - 1) {\n temp.add(grid.get(i).get(j));\n }\n val = Collections.min(temp);\n }\n }\n }\n List<Integer> ans = new ArrayList<>();\n for (int i = 0; i < k; i++) {\n if (i == 0) {\n ans.add(1);\n } else {\n ans.add(val);\n }\n }\n return ans;\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Minpath"}
|
131 |
{"task_id": "Java/130", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in\n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8\n You are given a non-negative integer number n, you have to a return a list of the\n first n + 1 numbers of the Tribonacci sequence.\n Examples:\n tri(3) = [1, 3, 2, 8]\n */\n public List<Integer> tri(int n) {\n", "canonical_solution": " if (n == 0) {\n return List.of(1);\n }\n List<Integer> my_tri = new ArrayList<>(Arrays.asList(1, 3));\n for (int i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n my_tri.add(i / 2 + 1);\n } else {\n my_tri.add(my_tri.get(my_tri.size() - 1) + my_tri.get(my_tri.size() - 2) + (i + 3) / 2);\n }\n }\n return my_tri;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.tri(3).equals(Arrays.asList(1, 3, 2, 8)),\n s.tri(4).equals(Arrays.asList(1, 3, 2, 8, 3)),\n s.tri(5).equals(Arrays.asList(1, 3, 2, 8, 3, 15)),\n s.tri(6).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4)),\n s.tri(7).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24)),\n s.tri(8).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24, 5)),\n s.tri(9).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24, 5, 35)),\n s.tri(20).equals(Arrays.asList(1, 3, 2, 8, 3, 15, 4, 24, 5, 35, 6, 48, 7, 63, 8, 80, 9, 99, 10, 120, 11)),\n s.tri(0).equals(List.of(1)),\n s.tri(1).equals(Arrays.asList(1, 3))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in\n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8\n You are given a non-negative integer number n, you have to a return a list of the\n first n + 1 numbers of the Tribonacci sequence.\n Examples:\n tri(3) = [1, 3, 2, 8]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> tri(int n) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.tri(3).equals(Arrays.asList(1, 3, 2, 8))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " if (n == 0) {\n return List.of(1);\n }\n List<Integer> my_tri = new ArrayList<>(Arrays.asList(1, 3));\n for (int i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n my_tri.add(i / 2 + 1);\n } else {\n my_tri.add(my_tri.get(my_tri.size() - 1) + my_tri.get(my_tri.size() - 2) + i + (i + 3) / 2);\n }\n }\n return my_tri;\n }\n}", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Tri"}
|
|
|
153 |
{"task_id": "Java/152", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match.\n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n\n example:\n\n compare(Arrays.asList(1,2,3,4,5,1),Arrays.asList(1,2,3,4,2,-2)) -> [0,0,0,0,3,3]\n compare(Arrays.asList(0,5,0,0,0,4),Arrays.asList(4,1,1,0,0,-2)) -> [4,4,1,0,0,6]\n */\n public List<Integer> compare(List<Integer> game, List<Integer> guess) {\n", "canonical_solution": " List<Integer> result = new ArrayList<>();\n for (int i = 0; i < game.size(); i++) {\n result.add(Math.abs(game.get(i) - guess.get(i)));\n }\n return result;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n s.compare(Arrays.asList(1, 2, 3, 4, 5, 1), Arrays.asList(1, 2, 3, 4, 2, -2)).equals(Arrays.asList(0, 0, 0, 0, 3, 3)),\n s.compare(Arrays.asList(0,5,0,0,0,4), Arrays.asList(4,1,1,0,0,-2)).equals(Arrays.asList(4,4,1,0,0,6)),\n s.compare(Arrays.asList(1, 2, 3, 4, 5, 1), Arrays.asList(1, 2, 3, 4, 2, -2)).equals(Arrays.asList(0, 0, 0, 0, 3, 3)),\n s.compare(Arrays.asList(0, 0, 0, 0, 0, 0), Arrays.asList(0, 0, 0, 0, 0, 0)).equals(Arrays.asList(0, 0, 0, 0, 0, 0)),\n s.compare(Arrays.asList(1, 2, 3), Arrays.asList(-1, -2, -3)).equals(Arrays.asList(2, 4, 6)),\n s.compare(Arrays.asList(1, 2, 3, 5), Arrays.asList(-1, 2, 3, 4)).equals(Arrays.asList(2, 0, 0, 1))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match.\n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n\n example:\n\n compare(Arrays.asList(1,2,3,4,5,1),Arrays.asList(1,2,3,4,2,-2)) -> [0,0,0,0,3,3]\n compare(Arrays.asList(0,5,0,0,0,4),Arrays.asList(4,1,1,0,0,-2)) -> [4,4,1,0,0,6]", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> compare(List<Integer> game, List<Integer> guess) {\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.compare(Arrays.asList(1, 2, 3, 4, 5, 1), Arrays.asList(1, 2, 3, 4, 2, -2)).equals(Arrays.asList(0, 0, 0, 0, 3, 3)),\n s.compare(Arrays.asList(0,5,0,0,0,4), Arrays.asList(4,1,1,0,0,-2)).equals(Arrays.asList(4,4,1,0,0,6))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<Integer> result = new ArrayList<>();\n for (int i = 0; i < game.size(); i++) {\n result.add(Math.abs(game.get(i) - guess.get(i))+Math.abs(guess.get(i) - game.get(i)));\n }\n return result;\n }\n}", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Compare"}
|
154 |
{"task_id": "Java/153", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters\n in the extension's name, the strength is given by the fraction CAP - SM.\n You should find the strongest extension and return a string in this\n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: [\"SErviNGSliCes\", \"Cheese\", \"StuFfed\"] then you should\n return \"Slices.SErviNGSliCes\" since \"SErviNGSliCes\" is the strongest extension\n (its strength is -1).\n Example:\n for StrongestExtension(\"my_class\", [\"AA\", \"Be\", \"CC\"]) == \"my_class.AA\"\n */\n public String StrongestExtension(String class_name, List<String> extensions) {\n", "canonical_solution": " String strong = extensions.get(0);\n int my_val = (int) (strong.chars().filter(Character::isUpperCase).count() - strong.chars().filter(Character::isLowerCase).count());\n for (String s : extensions) {\n int val = (int) (s.chars().filter(Character::isUpperCase).count() - s.chars().filter(Character::isLowerCase).count());\n if (val > my_val) {\n strong = s;\n my_val = val;\n }\n }\n return class_name + \".\" + strong;\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.StrongestExtension(\"Watashi\", Arrays.asList(\"tEN\", \"niNE\", \"eIGHt8OKe\")), \"Watashi.eIGHt8OKe\"),\n Objects.equals(s.StrongestExtension(\"Boku123\", Arrays.asList(\"nani\", \"NazeDa\", \"YEs.WeCaNe\", \"32145tggg\")), \"Boku123.YEs.WeCaNe\"),\n Objects.equals(s.StrongestExtension(\"__YESIMHERE\", Arrays.asList(\"t\", \"eMptY\", \"nothing\", \"zeR00\", \"NuLl__\", \"123NoooneB321\")), \"__YESIMHERE.NuLl__\"),\n Objects.equals(s.StrongestExtension(\"K\", Arrays.asList(\"Ta\", \"TAR\", \"t234An\", \"cosSo\")), \"K.TAR\"),\n Objects.equals(s.StrongestExtension(\"__HAHA\", Arrays.asList(\"Tab\", \"123\", \"781345\", \"-_-\")), \"__HAHA.123\"),\n Objects.equals(s.StrongestExtension(\"YameRore\", Arrays.asList(\"HhAas\", \"okIWILL123\", \"WorkOut\", \"Fails\", \"-_-\")), \"YameRore.okIWILL123\"),\n Objects.equals(s.StrongestExtension(\"finNNalLLly\", Arrays.asList(\"Die\", \"NowW\", \"Wow\", \"WoW\")), \"finNNalLLly.WoW\"),\n Objects.equals(s.StrongestExtension(\"_\", Arrays.asList(\"Bb\", \"91245\")), \"_.Bb\"),\n Objects.equals(s.StrongestExtension(\"Sp\", Arrays.asList(\"671235\", \"Bb\")), \"Sp.671235\")\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters\n in the extension's name, the strength is given by the fraction CAP - SM.\n You should find the strongest extension and return a string in this\n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: [\"SErviNGSliCes\", \"Cheese\", \"StuFfed\"] then you should\n return \"Slices.SErviNGSliCes\" since \"SErviNGSliCes\" is the strongest extension\n (its strength is -1).\n Example:\n for StrongestExtension(\"my_class\", [\"AA\", \"Be\", \"CC\"]) == \"my_class.AA\"", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public String StrongestExtension(String class_name, List<String> extensions) {\n", "example_test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.StrongestExtension(\"my_class\", Arrays.asList(\"AA\", \"Be\", \"CC\")), \"my_class.AA\")\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " String strong = extensions.get(0);\n int my_val = (int) (strong.chars().filter(Character::isUpperCase).count() - strong.chars().filter(Character::isLowerCase).count());\n for (String s : extensions) {\n int val = (int) (s.chars().filter(Character::isUpperCase).count() - s.chars().filter(Character::isLowerCase).count());\n if (val > my_val) {\n strong = s;\n my_val = val;\n }\n }\n return class_name + strong;\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "StrongestExtension"}
|
155 |
{"task_id": "Java/154", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\n cycpatternCheck(\"abcd\",\"abd\") => false\n cycpatternCheck(\"hello\",\"ell\") => true\n cycpatternCheck(\"whassup\",\"psus\") => false\n cycpatternCheck(\"abab\",\"baa\") => true\n cycpatternCheck(\"efef\",\"eeff\") => false\n cycpatternCheck(\"himenss\",\"simen\") => true\n */\n public boolean cycpatternCheck(String a, String b) {\n", "canonical_solution": " int l = b.length();\n String pat = b + b;\n for (int i = 0; i <= a.length() - l; i++) {\n for (int j = 0; j <= l; j++) {\n if (a.substring(i, i + l).equals(pat.substring(j, j + l))) {\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.cycpatternCheck(\"xyzw\", \"xyw\") == false,\n s.cycpatternCheck(\"yello\", \"ell\") == true,\n s.cycpatternCheck(\"whattup\", \"ptut\") == false,\n s.cycpatternCheck(\"efef\", \"fee\") == true,\n s.cycpatternCheck(\"abab\", \"aabb\") == false,\n s.cycpatternCheck(\"winemtt\", \"tinem\") == true\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\n cycpatternCheck(\"abcd\",\"abd\") => false\n cycpatternCheck(\"hello\",\"ell\") => true\n cycpatternCheck(\"whassup\",\"psus\") => false\n cycpatternCheck(\"abab\",\"baa\") => true\n cycpatternCheck(\"efef\",\"eeff\") => false\n cycpatternCheck(\"himenss\",\"simen\") => true", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean cycpatternCheck(String a, String b) {\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.cycpatternCheck(\"abcd\", \"abd\") == false,\n s.cycpatternCheck(\"hello\", \"ell\") == true,\n s.cycpatternCheck(\"whassup\", \"psus\") == false,\n s.cycpatternCheck(\"abab\", \"baa\") == true,\n s.cycpatternCheck(\"efef\", \"eeff\") == false,\n s.cycpatternCheck(\"himenss\", \"simen\") == true\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int l = b.length();\n String pat = b + b;\n for (int i = 0; i <= a.length() - l; i++) {\n for (int j = 0; j <= b.length() - l; j++) {\n if (a.substring(i, i + l).equals(pat.substring(j, j + l))) {\n return true;\n }\n }\n }\n return false;\n }\n}", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "CycpatternCheck"}
|
156 |
+
{"task_id": "Java/155", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given an integer. return a tuple that has the number of even and odd digits respectively.\n \n Example:\n evenOddCount(-12) ==> (1, 1)\n evenOddCount(123) ==> (1, 2)\n */\n public List<Integer> evenOddCount(int num) {\n", "canonical_solution": " int even_count = 0, odd_count = 0;\n for (char i : String.valueOf(Math.abs(num)).toCharArray()) {\n if ((i - '0') % 2 == 0) {\n even_count += 1;\n } else {\n odd_count += 1;\n }\n }\n return Arrays.asList(even_count, odd_count);\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.evenOddCount(7).equals(Arrays.asList(0, 1)),\n s.evenOddCount(-78).equals(Arrays.asList(1, 1)),\n s.evenOddCount(3452).equals(Arrays.asList(2, 2)),\n s.evenOddCount(346211).equals(Arrays.asList(3, 3)),\n s.evenOddCount(-345821).equals(Arrays.asList(3, 3)),\n s.evenOddCount(-2).equals(Arrays.asList(1, 0)),\n s.evenOddCount(-45347).equals(Arrays.asList(2, 3)),\n s.evenOddCount(0).equals(Arrays.asList(1, 0))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given an integer. return a tuple that has the number of even and odd digits respectively.\n \n Example:\n evenOddCount(-12) ==> (1, 1)\n evenOddCount(123) ==> (1, 2)", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public List<Integer> evenOddCount(int num) {\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.evenOddCount(-12).equals(Arrays.asList(1, 1)),\n s.evenOddCount(123).equals(Arrays.asList(1, 2))\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " int even_count = 0, odd_count = 0;\n for (char i : String.valueOf(Math.abs(num)).toCharArray()) {\n if (i % 2 == 0) {\n even_count += 1;\n }\n }\n return Arrays.asList(even_count, odd_count);\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "EvenOddCount"}
|
157 |
{"task_id": "Java/156", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given a positive integer, obtain its roman numeral equivalent as a string,\n and return it in lowercase.\n Restrictions: 1 <= num <= 1000\n\n Examples:\n >>> intToMiniRoman(19) == \"xix\"\n >>> intToMiniRoman(152) == \"clii\"\n >>> intToMiniRoman(426) == \"cdxxvi\"\n */\n public String intToMiniRoman(int number) {\n", "canonical_solution": " List<Integer> num = Arrays.asList(1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000);\n List<String> sym = Arrays.asList(\"I\", \"IV\", \"V\", \"IX\", \"X\", \"XL\", \"L\", \"XC\", \"C\", \"CD\", \"D\", \"CM\", \"M\");\n int i = 12;\n String res = \"\";\n while (number > 0) {\n int div = number / num.get(i);\n number %= num.get(i);\n while (div != 0) {\n res += sym.get(i);\n div -= 1;\n }\n i -= 1;\n }\n return res.toLowerCase();\n }\n}", "test": "public class Main {\n public static void main(String[] args) {\n Solution s = new Solution();\n List<Boolean> correct = Arrays.asList(\n Objects.equals(s.intToMiniRoman(19), \"xix\"),\n Objects.equals(s.intToMiniRoman(152), \"clii\"),\n Objects.equals(s.intToMiniRoman(251), \"ccli\"),\n Objects.equals(s.intToMiniRoman(426), \"cdxxvi\"),\n Objects.equals(s.intToMiniRoman(500), \"d\"),\n Objects.equals(s.intToMiniRoman(1), \"i\"),\n Objects.equals(s.intToMiniRoman(4), \"iv\"),\n Objects.equals(s.intToMiniRoman(43), \"xliii\"),\n Objects.equals(s.intToMiniRoman(90), \"xc\"),\n Objects.equals(s.intToMiniRoman(94), \"xciv\"),\n Objects.equals(s.intToMiniRoman(532), \"dxxxii\"),\n Objects.equals(s.intToMiniRoman(900), \"cm\"),\n Objects.equals(s.intToMiniRoman(994), \"cmxciv\"),\n Objects.equals(s.intToMiniRoman(1000), \"m\")\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given a positive integer, obtain its roman numeral equivalent as a string,\n and return it in lowercase.\n Restrictions: 1 <= num <= 1000\n\n Examples:\n >>> intToMiniRoman(19) == \"xix\"\n >>> intToMiniRoman(152) == \"clii\"\n >>> intToMiniRoman(426) == \"cdxxvi\"", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public String intToMiniRoman(int 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 Objects.equals(s.intToMiniRoman(19), \"xix\"),\n Objects.equals(s.intToMiniRoman(152), \"clii\"),\n Objects.equals(s.intToMiniRoman(426), \"cdxxvi\")\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<Integer> num = Arrays.asList(1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000);\n List<String> sym = Arrays.asList(\"I\", \"IV\", \"V\", \"IX\", \"X\", \"XL\", \"L\", \"XC\", \"C\", \"CD\", \"D\", \"CM\", \"M\");\n int i = 12;\n String res = \"\";\n while (number > 0) {\n int div = number / num.get(i);\n while (div != 0) {\n res += sym.get(i);\n div -= 1;\n }\n i -= 1;\n }\n return res.toLowerCase();\n }\n}", "bug_type": "missing logic", "failure_symptoms": "infinite loop", "entry_point": "IntToMiniRoman"}
|
158 |
{"task_id": "Java/157", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Given the lengths of the three sides of a triangle. Return true if the three\n sides form a right-angled triangle, false otherwise.\n A right-angled triangle is a triangle in which one angle is right angle or\n 90 degree.\n Example:\n rightAngleTriangle(3, 4, 5) == true\n rightAngleTriangle(1, 2, 3) == false\n */\n public boolean rightAngleTriangle(int a, int b, int c) {\n", "canonical_solution": " return a * a == b * b + c * c || b * b == a * a + c * c || c * c == a * a + b * b;\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.rightAngleTriangle(3, 4, 5) == true,\n s.rightAngleTriangle(1, 2, 3) == false,\n s.rightAngleTriangle(10, 6, 8) == true,\n s.rightAngleTriangle(2, 2, 2) == false,\n s.rightAngleTriangle(7, 24, 25) == true,\n s.rightAngleTriangle(10, 5, 7) == false,\n s.rightAngleTriangle(5, 12, 13) == true,\n s.rightAngleTriangle(15, 8, 17) == true,\n s.rightAngleTriangle(48, 55, 73) == true,\n s.rightAngleTriangle(1, 1, 1) == false,\n s.rightAngleTriangle(2, 2, 10) == false\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Given the lengths of the three sides of a triangle. Return true if the three\n sides form a right-angled triangle, false otherwise.\n A right-angled triangle is a triangle in which one angle is right angle or\n 90 degree.\n Example:\n rightAngleTriangle(3, 4, 5) == true\n rightAngleTriangle(1, 2, 3) == false", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public boolean rightAngleTriangle(int a, int b, int c) {\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.rightAngleTriangle(3, 4, 5) == true,\n s.rightAngleTriangle(1, 2, 3) == false\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " return c * c == a * a + b * b;\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "RightAngleTriangle"}
|
159 |
{"task_id": "Java/158", "prompt": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n /**\n Write a function that accepts a list of strings.\n The list contains different words. Return the word with maximum number\n of unique characters. If multiple strings have maximum number of unique\n characters, return the one which comes first in lexicographical order.\n\n findMax([\"name\", \"of\", \"string\"]) == \"string\"\n findMax([\"name\", \"enam\", \"game\"]) == \"enam\"\n findMax([\"aaaaaaa\", \"bb\" ,\"cc\"]) == \"\"aaaaaaa\"\n */\n public String findMax(List<String> words) {\n", "canonical_solution": " List<String> words_sort = new ArrayList<>(words);\n words_sort.sort(new Comparator<String>() {\n @Override\n public int compare(String o1, String o2) {\n Set<Character> s1 = new HashSet<>();\n for (char ch : o1.toCharArray()) {\n s1.add(ch);\n }\n Set<Character> s2 = new HashSet<>();\n for (char ch : o2.toCharArray()) {\n s2.add(ch);\n }\n if (s1.size() > s2.size()) {\n return 1;\n } else if (s1.size() < s2.size()) {\n return -1;\n } else {\n return -o1.compareTo(o2);\n }\n }\n });\n return words_sort.get(words_sort.size() - 1);\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.findMax(new ArrayList<>(Arrays.asList(\"name\", \"of\", \"string\"))).equals(\"string\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"name\", \"enam\", \"game\"))).equals(\"enam\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"aaaaaaa\", \"bb\", \"cc\"))).equals(\"aaaaaaa\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"abc\", \"cba\"))).equals(\"abc\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"play\", \"this\", \"game\", \"of\", \"footbott\"))).equals(\"footbott\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"we\", \"are\", \"gonna\", \"rock\"))).equals(\"gonna\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"we\", \"are\", \"a\", \"mad\", \"nation\"))).equals(\"nation\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"this\", \"is\", \"a\", \"prrk\"))).equals(\"this\"),\n s.findMax(new ArrayList<>(List.of(\"b\"))).equals(\"b\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"play\", \"play\", \"play\"))).equals(\"play\")\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}", "text": " Write a function that accepts a list of strings.\n The list contains different words. Return the word with maximum number\n of unique characters. If multiple strings have maximum number of unique\n characters, return the one which comes first in lexicographical order.\n\n findMax([\"name\", \"of\", \"string\"]) == \"string\"\n findMax([\"name\", \"enam\", \"game\"]) == \"enam\"\n findMax([\"aaaaaaa\", \"bb\" ,\"cc\"]) == \"\"aaaaaaa\"", "declaration": "import java.util.*;\nimport java.lang.*;\n\nclass Solution {\n public String findMax(List<String> words) {\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.findMax(new ArrayList<>(Arrays.asList(\"name\", \"of\", \"string\"))).equals(\"string\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"name\", \"enam\", \"game\"))).equals(\"enam\"),\n s.findMax(new ArrayList<>(Arrays.asList(\"aaaaaaa\", \"bb\", \"cc\"))).equals(\"aaaaaaa\")\n );\n if (correct.contains(false)) {\n throw new AssertionError();\n }\n }\n}\n", "buggy_solution": " List<String> words_sort = new ArrayList<>(words);\n words_sort.sort(new Comparator<String>() {\n @Override\n public int compare(String o1, String o2) {\n Set<Character> s1 = new HashSet<>();\n for (char ch : o1.toCharArray()) {\n s1.add(ch);\n }\n Set<Character> s2 = new HashSet<>();\n for (char ch : o2.toCharArray()) {\n s2.add(ch);\n }\n if (s1.size() > s2.size()) {\n return 1;\n } else {\n return -o1.compareTo(o2);\n }\n }\n });\n return words_sort.get(words_sort.size() - 1);\n }\n}", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "FindMax"}
|
data/js/data/humanevalbugs.jsonl
CHANGED
@@ -30,7 +30,7 @@
|
|
30 |
{"task_id": "JavaScript/29", "prompt": "/* Filter an input list of strings only for ones that start with a given prefix.\n >>> filterByPrefix([], 'a')\n []\n >>> filterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n ['abc', 'array']\n */\nconst filterByPrefix = (strings, prefix) => {\n", "canonical_solution": " return strings.filter(x => x.startsWith(prefix));\n}\n\n", "test": "const testFilterByPrefix = () => {\n console.assert(\n JSON.stringify(filterByPrefix([], 'john')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterByPrefix(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx')\n ) === JSON.stringify(['xxx', 'xxxAAA', 'xxx'])\n )\n}\n\ntestFilterByPrefix()\n", "declaration": "\nconst filterByPrefix = (strings, prefix) => {\n", "example_test": "const testFilterByPrefix = () => {\n console.assert(\n JSON.stringify(filterByPrefix([], 'a')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n ) === JSON.stringify(['abc', 'array'])\n )\n}\ntestFilterByPrefix()\n", "buggy_solution": " return strings.filter(x => x.endsWith(prefix));\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "FilterByPrefix"}
|
31 |
{"task_id": "JavaScript/30", "prompt": "/*Return only positive numbers in the list.\n >>> getPositive([-1, 2, -4, 5, 6])\n [2, 5, 6]\n >>> getPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n [5, 3, 2, 3, 9, 123, 1]\n */\nconst getPositive = (l) => {\n", "canonical_solution": " return l.filter(e => e > 0);\n}\n\n", "test": "const testGetPositive = () => {\n console.assert(\n JSON.stringify(getPositive([-1, -2, 4, 5, 6])) === JSON.stringify([4, 5, 6])\n )\n console.assert(\n JSON.stringify(getPositive([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([5, 3, 2, 3, 3, 9, 123, 1])\n )\n console.assert(JSON.stringify(getPositive([-1, -2])) === JSON.stringify([]))\n console.assert(JSON.stringify(getPositive([])) === JSON.stringify([]))\n}\n\ntestGetPositive()\n", "declaration": "\nconst getPositive = (l) => {\n", "example_test": "const testGetPositive = () => {\n console.assert(\n JSON.stringify(getPositive([-1, 2, -4, 5, 6])) === JSON.stringify([2, 5, 6])\n )\n console.assert(\n JSON.stringify(getPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([5, 3, 2, 3, 9, 123, 1])\n )\n}\ntestGetPositive()\n", "buggy_solution": " return l.filter(e => e < 0);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "GetPositive"}
|
32 |
{"task_id": "JavaScript/31", "prompt": "/*Return true if a given number is prime, and false otherwise.\n >>> isPrime(6)\n false\n >>> isPrime(101)\n true\n >>> isPrime(11)\n true\n >>> isPrime(13441)\n true\n >>> isPrime(61)\n true\n >>> isPrime(4)\n false\n >>> isPrime(1)\n false\n */\nconst isPrime = (n) => {\n", "canonical_solution": " if (n < 2)\n return false;\n for (let k = 2; k < n - 1; k++)\n if (n % k == 0)\n return false;\n return true;\n}\n\n", "test": "const testIsPrime = () => {\n console.assert(isPrime(6) === false)\n console.assert(isPrime(101) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(13441) === true)\n console.assert(isPrime(61) === true)\n console.assert(isPrime(4) === false)\n console.assert(isPrime(1) === false)\n console.assert(isPrime(5) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(17) === true)\n console.assert(isPrime(5 * 17) === false)\n console.assert(isPrime(11 * 7) === false)\n console.assert(isPrime(13441 * 19) === false)\n}\n\ntestIsPrime()\n", "declaration": "\nconst isPrime = (n) => {\n", "example_test": "const testIsPrime = () => {\n console.assert(isPrime(6) === false)\n console.assert(isPrime(101) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(13441) === true)\n console.assert(isPrime(61) === true)\n console.assert(isPrime(4) === false)\n console.assert(isPrime(1) === false)\n}\ntestIsPrime()\n", "buggy_solution": " if (n < 1)\n return false;\n for (let k = 1; k < n - 1; k++)\n if (n % k == 0)\n return false;\n return true;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsPrime"}
|
33 |
-
{"task_id": "JavaScript/32", "prompt": "/*\n Evaluates polynomial with coefficients xs at point x.\n return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n\n */\nconst poly = (xs, x) => {\n return xs.reduce((prev, item, index) => {\n return prev + item * Math.pow(x, index);\n }, 0);\n}\n\n/*\n xs are coefficients of a polynomial.\n findZero find x such that poly(x) = 0.\n findZero returns only only zero point, even if there are many.\n Moreover, findZero only takes list xs having even number of coefficients\n and largest non zero coefficient as it guarantees\n a solution.\n >>> round(findZero([1, 2]), 2) # f(x) = 1 + 2x\n -0.5\n >>> round(findZero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n 1.0\n */\nconst findZero = (xs) => {\n", "canonical_solution": " var begin = -1.0, end = 1.0;\n while (poly(xs, begin) * poly(xs, end) > 0) {\n begin *= 2.0;\n end *= 2.0;\n }\n while (end - begin > 1e-10) {\n let center = (begin + end) / 2.0;\n if (poly(xs, center) * poly(xs, begin) > 0)\n begin = center;\n else\n end = center;\n }\n return begin;\n}\n\n", "test": "const testfindZero = () => {\n const getRandomIntInclusive = (min = 0, max = 9) => {\n min = Math.ceil(min)\n max = Math.floor(max)\n return Math.floor(Math.random() * (max - min + 1)) + min\n }\n\n for (let i = 0; i < 100; i++) {\n let ncoeff = 2 * getRandomIntInclusive(1, 4);\n let coeffs = [];\n for (let j = 0; j < ncoeff; j++) {\n let coeff = getRandomIntInclusive(-10, 10);\n if (coeff === 0)\n coeff = 1;\n coeffs.push(coeff);\n }\n let solution = findZero(coeffs);\n console.assert(Math.abs(poly(coeffs, solution)) < 1e-4);\n }\n}\n", "declaration": "\nconst poly = (xs, x) => {\n return xs.reduce((prev, item, index) => {\n return prev + item * Math.pow(x, index);\n }, 0);\n}\n\nconst findZero = (xs) => {\n", "example_test": "const testPoly = () => {\n console.assert(Math.abs(findZero([1,2])+0.5 < 1e-4));\n console.assert(Math.abs(findZero([-6,11,-6,1])-1 < 1e-4));\n}\ntestPoly()\n", "buggy_solution": " var begin = -1.0, end = 1.0;\n while (poly(xs, begin) * poly(xs, end) > 0) {\n begin *= 2.0;\n end *= 2.0;\n }\n while (begin - end > 1e-10) {\n let center = (begin + end) / 2.0;\n if (poly(xs, center) * poly(xs, end) > 0)\n begin = center;\n else\n end = center;\n }\n return
|
34 |
{"task_id": "JavaScript/33", "prompt": "/*This function takes a list l and returns a list l' such that\n l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n to the values of the corresponding indicies of l, but sorted.\n >>> sortThird([1, 2, 3])\n [1, 2, 3]\n >>> sortThird([5, 6, 3, 4, 8, 9, 2])\n [2, 6, 3, 4, 8, 9, 5]\n */\nconst sortThird = (l) => {\n", "canonical_solution": " var three = l.filter((item, index) => index % 3 == 0);\n three.sort((a, b) => (a - b));\n return l.map((item, index) => (index % 3 == 0 ? three[index / 3] : item));\n}\n\n", "test": "const testSortThird = () => {\n console.assert(\n JSON.stringify(sortThird([1, 2, 3])) == JSON.stringify([1, 2, 3])\n )\n console.assert(\n JSON.stringify(sortThird([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) ==\n JSON.stringify([1, 3, -5, 2, -3, 3, 5, 0, 123, 9, -10])\n )\n console.assert(\n JSON.stringify(sortThird([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) ==\n JSON.stringify([-10, 8, -12, 3, 23, 2, 4, 11, 12, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 3, 4, 8, 9, 2])) ==\n JSON.stringify([2, 6, 3, 4, 8, 9, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 8, 3, 4, 6, 9, 2])) ==\n JSON.stringify([2, 8, 3, 4, 6, 9, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 9, 4, 8, 3, 2])) ==\n JSON.stringify([2, 6, 9, 4, 8, 3, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 3, 4, 8, 9, 2, 1])) ==\n JSON.stringify([2, 6, 3, 4, 8, 9, 5, 1])\n )\n}\n\ntestSortThird()\n", "declaration": "\nconst sortThird = (l) => {\n", "example_test": "const testSortThird = () => {\n console.assert(\n JSON.stringify(sortThird([1, 2, 3])) == JSON.stringify([1, 2, 3])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 3, 4, 8, 9, 2])) ==\n JSON.stringify([2, 6, 3, 4, 8, 9, 5])\n )\n}\ntestSortThird()\n", "buggy_solution": " var three = l.filter((item, index) => index % 3 == 0);\n return l.map((item, index) => (index % 2 == 0 ? three[index / 3] : item));\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "SortThird"}
|
35 |
{"task_id": "JavaScript/34", "prompt": "/*Return sorted unique elements in a list\n >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [0, 2, 3, 5, 9, 123]\n */\nconst unique = (l) => {\n", "canonical_solution": " return Array.from(new Set(l)).sort((a, b) => (a - b));\n}\n\n", "test": "const testUnique = () => {\n console.assert(\n JSON.stringify(unique([5, 3, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([0, 2, 3, 5, 9, 123])\n )\n}\n\ntestUnique()\n", "declaration": "\nconst unique = (l) => {\n", "example_test": "const testUnique = () => {\n console.assert(\n JSON.stringify(unique([5, 3, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([0, 2, 3, 5, 9, 123])\n )\n}\ntestUnique()\n", "buggy_solution": " return l.sort((a, b) => (a - b));\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Unique"}
|
36 |
{"task_id": "JavaScript/35", "prompt": "/*Return maximum element in the list.\n >>> maxElement([1, 2, 3])\n 3\n >>> maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n 123\n */\nconst maxElement = (l) => {\n", "canonical_solution": " return Math.max(...l);\n}\n\n", "test": "const testMaxElement = () => {\n console.assert(maxElement([1, 2, 3]) === 3)\n console.assert(maxElement([5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) === 124)\n}\n\ntestMaxElement()\n", "declaration": "\nconst maxElement = (l) => {\n", "example_test": "const testMaxElement = () => {\n console.assert(maxElement([1, 2, 3]) === 3)\n console.assert(maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) === 123)\n}\ntestMaxElement()\n", "buggy_solution": " return Math.min(...l);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "MaxElement"}
|
@@ -117,7 +117,7 @@
|
|
117 |
{"task_id": "JavaScript/116", "prompt": "/*\n In this Kata, you have to sort an array of non-negative integers according to\n number of ones in their binary representation in ascending order.\n For similar number of ones, sort based on decimal value.\n\n It must be implemented like this:\n >>> sortArray([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n >>> sortArray([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n >>> sortArray([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]\n */\nconst sortArray = (arr) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[k].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(sortArray([2, 5, 77, 4, 5, 3, 5, 7, 2, 3, 4])) ===\n JSON.stringify([2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77])\n )\n console.assert(\n JSON.stringify(sortArray([3, 6, 44, 12, 32, 5])) ===\n JSON.stringify([32, 3, 5, 6, 12, 44])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n}\n\ntestSortArray()\n", "declaration": "\nconst sortArray = (arr) => {\n", "example_test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n}\ntestSortArray()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[ind].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return arr\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "SortArray"}
|
118 |
{"task_id": "JavaScript/117", "prompt": "/*Given a string s and a natural number n, you have been tasked to implement \n a function that returns a list of all words from string s that contain exactly \n n consonants, in order these words appear in the string s.\n If the string s is empty then the function should return an empty list.\n Note: you may assume the input string contains only letters and spaces.\n Examples:\n selectWords(\"Mary had a little lamb\", 4) ==> [\"little\"]\n selectWords(\"Mary had a little lamb\", 3) ==> [\"Mary\")\n selectWords(\"simple white space\", 2) ==> []\n selectWords(\"Hello world\", 4) ==> [\"world\"]\n selectWords(\"Uncle sam\", 3) ==> [\"Uncle\"]\n */\nconst selectWords = (s, n) => {\n", "canonical_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' && t[i][j] != 'e' && t[i][j] != 'i' && t[i][j] != 'o' && t[i][j] != 'u' && t[i][j] != 'A' &&\n t[i][j] != 'U' && t[i][j] != 'O' && t[i][j] != 'I' && t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n\n console.assert(\n JSON.stringify(selectWords('a b c d e f', 1)) ===\n JSON.stringify(['b', 'c', 'd', 'f'])\n )\n\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n console.assert(JSON.stringify(selectWords('', 4)) === JSON.stringify([]))\n}\n\ntestSelectWords()\n", "declaration": "\nconst selectWords = (s, n) => {\n", "example_test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n}\ntestSelectWords()\n", "buggy_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' || t[i][j] != 'e' || t[i][j] != 'i' || t[i][j] != 'o' || t[i][j] != 'u' || t[i][j] != 'A' ||\n t[i][j] != 'U' || t[i][j] != 'O' || t[i][j] != 'I' || t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "SelectWords"}
|
119 |
{"task_id": "JavaScript/118", "prompt": "/*You are given a word. Your task is to find the closest vowel that stands between \n two consonants from the right side of the word (case sensitive).\n \n Vowels in the beginning and ending doesn't count. Return empty string if you didn't\n find any vowel met the above condition. \n\n You may assume that the given string contains English letter only.\n\n Example:\n getClosestVowel(\"yogurt\") ==> \"u\"\n getClosestVowel(\"FULL\") ==> \"U\"\n getClosestVowel(\"quick\") ==> \"\"\n getClosestVowel(\"ab\") ==> \"\"\n */\nconst getClosestVowel = (word) => {\n", "canonical_solution": " for (let i = word.length - 2; i > 0; i--) {\n if (\n !(word[i] != 'a' && word[i] != 'e' && word[i] != 'i' && word[i] != 'o' && word[i] != 'u' && word[i] != 'A' &&\n word[i] != 'U' && word[i] != 'O' && word[i] != 'I' && word[i] != 'E')\n &&\n (word[i + 1] != 'a' && word[i + 1] != 'e' && word[i + 1] != 'i' && word[i + 1] != 'o' && word[i + 1] != 'u' && word[i + 1] != 'A' &&\n word[i + 1] != 'U' && word[i + 1] != 'O' && word[i + 1] != 'I' && word[i + 1] != 'E')\n &&\n (word[i - 1] != 'a' && word[i - 1] != 'e' && word[i - 1] != 'i' && word[i - 1] != 'o' && word[i - 1] != 'u' && word[i - 1] != 'A' &&\n word[i - 1] != 'U' && word[i - 1] != 'O' && word[i - 1] != 'I' && word[i - 1] != 'E')\n ) {\n return word[i]\n }\n }\n return ''\n}\n\n", "test": "const testGetClosestVowel = () => {\n console.assert(getClosestVowel('yogurt') === 'u')\n console.assert(getClosestVowel('full') === 'u')\n console.assert(getClosestVowel('easy') === '')\n console.assert(getClosestVowel('eAsy') === '')\n console.assert(getClosestVowel('ali') === '')\n console.assert(getClosestVowel('bad') === 'a')\n console.assert(getClosestVowel('most') === 'o')\n console.assert(getClosestVowel('ab') === '')\n console.assert(getClosestVowel('ba') === '')\n console.assert(getClosestVowel('quick') === '')\n console.assert(getClosestVowel('anime') === 'i')\n console.assert(getClosestVowel('Asia') === '')\n console.assert(getClosestVowel('Above') === 'o')\n}\n\ntestGetClosestVowel()\n", "declaration": "\nconst getClosestVowel = (word) => {\n", "example_test": "const testGetClosestVowel = () => {\n console.assert(getClosestVowel('yogurt') === 'u')\n console.assert(getClosestVowel('FULL') === 'U')\n console.assert(getClosestVowel('ab') === '')\n console.assert(getClosestVowel('quick') === '')\n}\ntestGetClosestVowel()\n", "buggy_solution": " for (let i = word.length - 2; i > 0; i--) {\n if (\n (word[i] != 'a' && word[i] != 'e' && word[i] != 'i' && word[i] != 'o' && word[i] != 'u' && word[i] != 'A' &&\n word[i] != 'U' && word[i] != 'O' && word[i] != 'I' && word[i] != 'E')\n &&\n (word[i + 1] != 'a' && word[i + 1] != 'e' && word[i + 1] != 'i' && word[i + 1] != 'o' && word[i + 1] != 'u' && word[i + 1] != 'A' &&\n word[i + 1] != 'U' && word[i + 1] != 'O' && word[i + 1] != 'I' && word[i + 1] != 'E')\n &&\n (word[i - 1] != 'a' && word[i - 1] != 'e' && word[i - 1] != 'i' && word[i - 1] != 'o' && word[i - 1] != 'u' && word[i - 1] != 'A' &&\n word[i - 1] != 'U' && word[i - 1] != 'O' && word[i - 1] != 'I' && word[i - 1] != 'E')\n ) {\n return word[i]\n }\n }\n return ' '\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "GetClosestVowel"}
|
120 |
-
{"task_id": "JavaScript/119", "prompt": "/* You are given a list of two strings, both strings consist of open\n parentheses '(' or close parentheses ')' only.\n Your job is to check if it is possible to concatenate the two strings in\n some order, that the resulting string will be good.\n A string S is considered to be good if and only if all parentheses in S\n are balanced. For example: the string '(())()' is good, while the string\n '())' is not.\n Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.\n Examples:\n matchParens(['()(', ')']) == 'Yes'\n matchParens([')', ')']) == 'No'\n */\nconst matchParens = (lst) => {\n", "canonical_solution": " let w1 = lst[0] + lst[1]\n let y = 0\n let u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n w1 = lst[1] + lst[0]\n y = 0\n u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n return 'No'\n}\n\n", "test": "const testMatchParens = () => {\n console.assert(matchParens(['()(', ')']) === 'Yes')\n console.assert(matchParens([')', ')']) === 'No')\n console.assert(matchParens(['(()(())', '())())']) === 'No')\n console.assert(matchParens([')())', '(()()(']) === 'Yes')\n console.assert(matchParens(['(())))', '(()())((']) === 'Yes')\n console.assert(matchParens(['()', '())']) === 'No')\n console.assert(matchParens(['(()(', '()))()']) === 'Yes')\n console.assert(matchParens(['((((', '((())']) === 'No')\n console.assert(matchParens([')(()', '(()(']) === 'No')\n console.assert(matchParens([')(', ')(']) === 'No')\n console.assert(matchParens(['(', ')']) === 'Yes')\n console.assert(matchParens([')', '(']) === 'Yes')\n}\n", "declaration": "\nconst matchParens = (lst) => {\n", "example_test": "const testMatchParens = () => {\n console.assert(matchParens(['()(', ')']) === 'Yes')\n console.assert(matchParens([')', ')']) === 'No')\n}\ntestMatchParens()\n", "buggy_solution": " let w1 = lst[0] + lst[1]\n let y = 0\n let u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'yes' }\n w1 = lst[1] + lst[0]\n y = 0\n u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'no' }\n return 'yes'\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "MatchParens"}
|
121 |
{"task_id": "JavaScript/120", "prompt": "/*\n Given an array arr of integers and a positive integer k, return a sorted list \n of length k with the maximum k numbers in arr.\n\n Example 1:\n\n Input: arr = [-3, -4, 5], k = 3\n Output: [-4, -3, 5]\n\n Example 2:\n\n Input: arr = [4, -4, 4], k = 2\n Output: [4, 4]\n\n Example 3:\n\n Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1\n Output: [2]\n\n Note:\n 1. The length of the array will be in the range of [1, 1000].\n 2. The elements in the array will be in the range of [-1000, 1000].\n 3. 0 <= k <= len(arr)\n */\nconst maximum = (arr, k) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n if (k == 0) { return [] }\n return p.slice(-k)\n}\n\n", "test": "const testMaximum = () => {\n console.assert(\n JSON.stringify(maximum([-3, -4, 5], 3)) === JSON.stringify([-4, -3, 5])\n )\n console.assert(\n JSON.stringify(maximum([4, -4, 4], 2)) === JSON.stringify([4, 4])\n )\n console.assert(\n JSON.stringify(maximum([-3, 2, 1, 2, -1, -2, 1], 1)) === JSON.stringify([2])\n )\n console.assert(\n JSON.stringify(maximum([123, -123, 20, 0, 1, 2, -3], 3)) ===\n JSON.stringify([2, 20, 123])\n )\n console.assert(\n JSON.stringify(maximum([-123, 20, 0, 1, 2, -3], 4)) ===\n JSON.stringify([0, 1, 2, 20])\n )\n console.assert(\n JSON.stringify(maximum([5, 15, 0, 3, -13, -8, 0], 7)) ===\n JSON.stringify([-13, -8, 0, 0, 3, 5, 15])\n )\n console.assert(\n JSON.stringify(maximum([-1, 0, 2, 5, 3, -10], 2)) === JSON.stringify([3, 5])\n )\n console.assert(\n JSON.stringify(maximum([1, 0, 5, -7], 1)) === JSON.stringify([5])\n )\n console.assert(JSON.stringify(maximum([4, -4], 2)) === JSON.stringify([-4, 4]))\n console.assert(\n JSON.stringify(maximum([-10, 10], 2)) === JSON.stringify([-10, 10])\n )\n console.assert(\n JSON.stringify(maximum([1, 2, 3, -23, 243, -400, 0], 0)) ===\n JSON.stringify([])\n )\n}\n\ntestMaximum()\n", "declaration": "\nconst maximum = (arr, k) => {\n", "example_test": "const testMaximum = () => {\n console.assert(\n JSON.stringify(maximum([-3, -4, 5], 3)) === JSON.stringify([-4, -3, 5])\n )\n console.assert(\n JSON.stringify(maximum([4, -4, 4], 2)) === JSON.stringify([4, 4])\n )\n console.assert(\n JSON.stringify(maximum([-3, 2, 1, 2, -1, -2, 1], 1)) === JSON.stringify([2])\n )\n}\ntestMaximum()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n p[j] = p[ind]\n }\n }\n if (k == 0) { return [] }\n return p.slice(-k)\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Maximum"}
|
122 |
{"task_id": "JavaScript/121", "prompt": "/*Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions.\n \n\n Examples\n solution([5, 8, 7, 1]) ==> 12\n solution([3, 3, 3, 3, 3]) ==> 9\n solution([30, 13, 24, 321]) ==>0\n */\nconst solution = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i += 2) {\n if (lst[i] % 2 == 1) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "test": "const testSolution = () => {\n console.assert(solution([5, 8, 7, 1]) === 12)\n console.assert(solution([3, 3, 3, 3, 3]) === 9)\n console.assert(solution([30, 13, 24, 321]) === 0)\n console.assert(solution([5, 9]) === 5)\n console.assert(solution([2, 4, 8]) === 0)\n console.assert(solution([30, 13, 23, 32]) === 23)\n console.assert(solution([3, 13, 2, 9]) === 3)\n}\n\ntestSolution()\n", "declaration": "\nconst solution = (lst) => {\n", "example_test": "const testSolution = () => {\n console.assert(solution([5, 8, 7, 1]) === 12)\n console.assert(solution([3, 3, 3, 3, 3]) === 9)\n console.assert(solution([30, 13, 24, 321]) === 0)\n}\ntestSolution()\n", "buggy_solution": " let p = 1\n for (let i = 0; i < lst.length; i += 2) {\n if (lst[i] % 2 == 1) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Solution"}
|
123 |
{"task_id": "JavaScript/122", "prompt": "/*\n Given a non-empty array of integers arr and an integer k, return\n the sum of the elements with at most two digits from the first k elements of arr.\n\n Example:\n\n Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4\n Output: 24 # sum of 21 + 3\n\n Constraints:\n 1. 1 <= len(arr) <= 100\n 2. 1 <= k <= len(arr)\n */\nconst addElements = (arr, k) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < k; i++) {\n if (arr[i] < 100 && arr[i] > -100) { p += arr[i] }\n }\n return p\n}\n\n", "test": "const testAddElements = () => {\n console.assert(addElements([1, -2, -3, 41, 57, 76, 87, 88, 99], 3) === -4)\n console.assert(addElements([111, 121, 3, 4000, 5, 6], 2) === 0)\n console.assert(addElements([11, 21, 3, 90, 5, 6, 7, 8, 9], 4) === 125)\n console.assert(addElements([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4) === 24)\n console.assert(addElements([1], 1) === 1)\n}\n\ntestAddElements()\n", "declaration": "\nconst addElements = (arr, k) => {\n", "example_test": "const testAddElements = () => {\n console.assert(addElements([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4) === 24)\n}\ntestAddElements()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] < 100 && arr[i] > -100) { p += arr[i] }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "AddElements"}
|
@@ -149,7 +149,7 @@
|
|
149 |
{"task_id": "JavaScript/148", "prompt": "/* There are eight planets in our solar system: the closerst to the Sun\n is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,\n Uranus, Neptune.\n Write a function that takes two planet names as strings planet1 and planet2.\n The function should return a tuple containing all planets whose orbits are\n located between the orbit of planet1 and the orbit of planet2, sorted by\n the proximity to the sun.\n The function should return an empty tuple if planet1 or planet2\n are not correct planet names.\n Examples\n bf(\"Jupiter\", \"Neptune\") ==> (\"Saturn\", \"Uranus\")\n bf(\"Earth\", \"Mercury\") ==> (\"Venus\")\n bf(\"Mercury\", \"Uranus\") ==> (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")\n */\nconst bf = (planet1, planet2) => {\n", "canonical_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n console.assert(\n JSON.stringify(bf('Neptune', 'Venus')) ===\n JSON.stringify(['Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus'])\n )\n console.assert(JSON.stringify(bf('Earth', 'Earth')) === JSON.stringify([]))\n console.assert(JSON.stringify(bf('Mars', 'Earth')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(bf('Jupiter', 'Makemake')) === JSON.stringify([])\n )\n}\n\ntestBf()\n", "declaration": "\nconst bf = (planet1, planet2) => {\n", "example_test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n}\ntestBf()\n", "buggy_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupyter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Bf"}
|
150 |
{"task_id": "JavaScript/149", "prompt": "/*Write a function that accepts a list of strings as a parameter,\n deletes the strings that have odd lengths from it,\n and returns the resulted list with a sorted order,\n The list is always a list of strings and never an array of numbers,\n and it may contain duplicates.\n The order of the list should be ascending by length of each word, and you\n should return the list sorted by that rule.\n If two words have the same length, sort the list alphabetically.\n The function should return a list of strings in sorted order.\n You may assume that all words will have the same length.\n For example:\n assert list_sort([\"aa\", \"a\", \"aaa\"]) => [\"aa\"]\n assert list_sort([\"ab\", \"a\", \"aaa\", \"cd\"]) => [\"ab\", \"cd\"]\n */\nconst sortedListSum = (lst) => {\n", "canonical_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['school', 'AI', 'asdf', 'b'])) ===\n JSON.stringify(['AI', 'asdf', 'school'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'b', 'c', 'a'])) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'dcba', 'abcd', 'a'])) ===\n JSON.stringify(['abcd', 'dcba'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['AI', 'ai', 'au'])) ===\n JSON.stringify(['AI', 'ai', 'au'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['a', 'b', 'b', 'c', 'c', 'a'])) ===\n JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['aaaa', 'bbbb', 'dd', 'cc'])) ===\n JSON.stringify(['cc', 'dd', 'aaaa', 'bbbb'])\n )\n}\n\ntestSortedListSum()\n", "declaration": "\nconst sortedListSum = (lst) => {\n", "example_test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['ab', 'a', 'aaa', 'cd'])) ===\n JSON.stringify(['ab', 'cd'])\n )\n}\ntestSortedListSum()\n", "buggy_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "SortedListSum"}
|
151 |
{"task_id": "JavaScript/150", "prompt": "/*A simple program which should return the value of x if n is \n a prime number and should return the value of y otherwise.\n\n Examples:\n for xOrY(7, 34, 12) == 34\n for xOrY(15, 8, 5) == 5\n \n */\nconst xOrY = (n, x, y) => {\n", "canonical_solution": " let len = n\n if (len == 1 || len == 0) { return y }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return y }\n }\n return x\n}\n\n", "test": "const testXOrY = () => {\n console.assert(xOrY(7, 34, 12) === 34)\n console.assert(xOrY(15, 8, 5) === 5)\n console.assert(xOrY(3, 33, 5212) === 33)\n console.assert(xOrY(1259, 3, 52) === 3)\n console.assert(xOrY(7919, -1, 12) === -1)\n console.assert(xOrY(3609, 1245, 583) === 583)\n console.assert(xOrY(91, 56, 129) === 129)\n console.assert(xOrY(6, 34, 1234) === 1234)\n console.assert(xOrY(1, 2, 0) === 0)\n console.assert(xOrY(2, 2, 0) === 2)\n}\n\ntestXOrY()\n", "declaration": "\nconst xOrY = (n, x, y) => {\n", "example_test": "const testXOrY = () => {\n console.assert(xOrY(7, 34, 12) === 34)\n console.assert(xOrY(15, 8, 5) === 5)\n}\ntestXOrY()\n", "buggy_solution": " let len = n\n if (len == 1 || len == 0) { return y }\n for (let i = 2; i * i <= len; i++) {\n if (len % i - 1 == 0) { return y }\n }\n return x\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "XOrY"}
|
152 |
-
{"task_id": "JavaScript/151", "prompt": "/* Given a list of numbers, return the sum of squares of the numbers\n in the list that are odd. Ignore numbers that are negative or not integers.\n doubleTheDifference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\n doubleTheDifference([-1, -2, 0]) == 0\n doubleTheDifference([9, -2]) == 81\n doubleTheDifference([0]) == 0\n If the input list is empty, return 0.\n */\nconst doubleTheDifference = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] % 2 == 1 && lst[i] > 0) {\n p += lst[i] * lst[i]\n }\n }\n return p\n}\n\n", "test": "const testDoubleTheDifference = () => {\n console.assert(doubleTheDifference([]) === 0)\n console.assert(doubleTheDifference([5, 4]) === 25)\n console.assert(doubleTheDifference([0.1, 0.2, 0.3]) === 0)\n console.assert(doubleTheDifference([-10, -20, -30]) === 0)\n console.assert(doubleTheDifference([-1, -2, 8]) === 0)\n console.assert(doubleTheDifference([0.2, 3, 5]) === 34)\n let lst = []\n let odd_sum = 0\n for (let i = -99; i < 100; i += 2) {\n if (i % 2 != 0 && i > 0) { odd_sum += i * i }\n lst.push(i)\n }\n console.assert(doubleTheDifference(lst) === odd_sum)\n}\n", "declaration": "\nconst doubleTheDifference = (lst) => {\n", "example_test": "const testDoubleTheDifference = () => {\n console.assert(doubleTheDifference([1,3,2,0]) === 10)\n console.assert(doubleTheDifference([-1,-2,0]) === 0)\n console.assert(doubleTheDifference([9,-2]) === 81)\n console.assert(doubleTheDifference([0]) === 0)\n}\ntestDoubleTheDifference()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "DoubleTheDifference"}
|
153 |
{"task_id": "JavaScript/152", "prompt": "/*I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match. \n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n \n \n example:\n\n compare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\n compare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]\n */\nconst compare = (game, guess) => {\n", "canonical_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i]; }\n return game\n}\n\n", "test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0])) ===\n JSON.stringify([0, 0, 0, 0, 0, 0])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3], [-1, -2, -3])) ===\n JSON.stringify([2, 4, 6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 5], [-1, 2, 3, 4])) ===\n JSON.stringify([2, 0, 0, 1])\n )\n}\n\ntestCompare()\n", "declaration": "\nconst compare = (game, guess) => {\n", "example_test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n}\ntestCompare()\n", "buggy_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i];\n if (guess[i]!=0)\n game[i]-=guess[i]; }\n return game\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Compare"}
|
154 |
{"task_id": "JavaScript/153", "prompt": "/*You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters\n in the extension's name, the strength is given by the fraction CAP - SM.\n You should find the strongest extension and return a string in this\n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should\n return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension\n (its strength is -1).\n Example:\n for strongestExtension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'\n */\nconst strongestExtension = (class_name, extensions) => {\n", "canonical_solution": " let u = 0\n let s = -Infinity\n for (let i = extensions.length - 1; i >= 0; i--) {\n let y = 0\n for (let j = 0; j < extensions[i].length; j++) {\n let k = extensions[i][j].charCodeAt()\n if (k >= 65 && k <= 90) { y += 1 }\n if (k >= 97 && k <= 122) { y -= 1 }\n }\n if (y >= s) {\n s = y;\n u = i;\n }\n }\n return class_name + '.' + extensions[u]\n}\n\n", "test": "const testStrongestExtension = () => {\n console.assert(\n strongestExtension('Watashi', ['tEN', 'niNE', 'eIGHt8OKe']) ===\n 'Watashi.eIGHt8OKe'\n )\n console.assert(\n strongestExtension('Boku123', [\n 'nani',\n 'NazeDa',\n 'YEs.WeCaNe',\n '32145tggg',\n ]) === 'Boku123.YEs.WeCaNe'\n )\n console.assert(\n strongestExtension('__YESIMHERE', [\n 't',\n 'eMptY',\n 'nothing',\n 'zeR00',\n 'NuLl__',\n '123NoooneB321',\n ]) === '__YESIMHERE.NuLl__'\n )\n console.assert(\n strongestExtension('K', ['Ta', 'TAR', 't234An', 'cosSo']) === 'K.TAR'\n )\n console.assert(\n strongestExtension('__HAHA', ['Tab', '123', '781345', '-_-']) ===\n '__HAHA.123'\n )\n console.assert(\n strongestExtension('YameRore', [\n 'HhAas',\n 'okIWILL123',\n 'WorkOut',\n 'Fails',\n '-_-',\n ]) === 'YameRore.okIWILL123'\n )\n console.assert(\n strongestExtension('finNNalLLly', ['Die', 'NowW', 'Wow', 'WoW']) ===\n 'finNNalLLly.WoW'\n )\n console.assert(strongestExtension('_', ['Bb', '91245']) === '_.Bb')\n console.assert(strongestExtension('Sp', ['671235', 'Bb']) === 'Sp.671235')\n}\n\ntestStrongestExtension()\n", "declaration": "\nconst strongestExtension = (class_name, extensions) => {\n", "example_test": "const testStrongestExtension = () => {\n console.assert(\n strongestExtension('my_class', ['AA', 'Be', 'CC']) ===\n 'my_class.AA'\n )\n}\ntestStrongestExtension()\n", "buggy_solution": " let u = 0\n let s = -Infinity\n for (let i = extensions.length - 1; i >= 0; i--) {\n let y = 0\n for (let j = 0; j < extensions[i].length; j++) {\n let k = extensions[i][j].charCodeAt()\n if (k >= 65 && k <= 90) { y += 1 }\n if (k >= 97 && k <= 122) { y -= 1 }\n }\n if (y >= s) {\n s = y;\n u = i;\n }\n }\n return class_name + extensions[u]\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "StrongestExtension"}
|
155 |
{"task_id": "JavaScript/154", "prompt": "/*You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\n cycpatternCheck(\"abcd\",\"abd\") => false\n cycpatternCheck(\"hello\",\"ell\") => true\n cycpatternCheck(\"whassup\",\"psus\") => false\n cycpatternCheck(\"abab\",\"baa\") => true\n cycpatternCheck(\"efef\",\"eeff\") => false\n cycpatternCheck(\"himenss\",\"simen\") => true\n */\nconst cycpatternCheck = (a, b) => {\n", "canonical_solution": " let l = b.length\n let pat = b + b\n for (let i = 0; i < a.length - l + 1; i++) {\n for (let j = 0; j < l + 1; j++) {\n let y = 1\n for (let k = 0; k < l; k++) {\n if (a[i + k] != pat[j + k]) { y = 0 }\n }\n if (y == 1) {\n return true\n }\n }\n }\n return false\n}\n\n", "test": "const testCycpatternCheck = () => {\n console.assert(cycpatternCheck('xyzw', 'xyw') === false)\n console.assert(cycpatternCheck('yello', 'ell') === true)\n console.assert(cycpatternCheck('whattup', 'ptut') === false)\n console.assert(cycpatternCheck('efef', 'fee') === true)\n console.assert(cycpatternCheck('abab', 'aabb') === false)\n console.assert(cycpatternCheck('winemtt', 'tinem') === true)\n}\n\ntestCycpatternCheck()\n", "declaration": "\nconst cycpatternCheck = (a, b) => {\n", "example_test": "const testCycpatternCheck = () => {\n console.assert(cycpatternCheck('abcd', 'abd') === false)\n console.assert(cycpatternCheck('hello', 'ell') === true)\n console.assert(cycpatternCheck('whassup', 'psus') === false)\n console.assert(cycpatternCheck('abab', 'baa') === true)\n console.assert(cycpatternCheck('efef', 'eeff') === false)\n console.assert(cycpatternCheck('himenss', 'simen') === true)\n}\ntestCycpatternCheck()\n", "buggy_solution": " let l = b.length\n let pat = b + b\n for (let i = 0; i < a.length - l + 1; i++) {\n for (let j = 0; j < b.length - l + 1; j++) {\n let y = 1\n for (let k = 0; k < l; k++) {\n if (a[i + k] != pat[j + k]) { y = 0 }\n }\n if (y == 1) {\n return true\n }\n }\n }\n return false\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "CycpatternCheck"}
|
|
|
30 |
{"task_id": "JavaScript/29", "prompt": "/* Filter an input list of strings only for ones that start with a given prefix.\n >>> filterByPrefix([], 'a')\n []\n >>> filterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n ['abc', 'array']\n */\nconst filterByPrefix = (strings, prefix) => {\n", "canonical_solution": " return strings.filter(x => x.startsWith(prefix));\n}\n\n", "test": "const testFilterByPrefix = () => {\n console.assert(\n JSON.stringify(filterByPrefix([], 'john')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterByPrefix(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx')\n ) === JSON.stringify(['xxx', 'xxxAAA', 'xxx'])\n )\n}\n\ntestFilterByPrefix()\n", "declaration": "\nconst filterByPrefix = (strings, prefix) => {\n", "example_test": "const testFilterByPrefix = () => {\n console.assert(\n JSON.stringify(filterByPrefix([], 'a')) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(\n filterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')\n ) === JSON.stringify(['abc', 'array'])\n )\n}\ntestFilterByPrefix()\n", "buggy_solution": " return strings.filter(x => x.endsWith(prefix));\n}\n\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "FilterByPrefix"}
|
31 |
{"task_id": "JavaScript/30", "prompt": "/*Return only positive numbers in the list.\n >>> getPositive([-1, 2, -4, 5, 6])\n [2, 5, 6]\n >>> getPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n [5, 3, 2, 3, 9, 123, 1]\n */\nconst getPositive = (l) => {\n", "canonical_solution": " return l.filter(e => e > 0);\n}\n\n", "test": "const testGetPositive = () => {\n console.assert(\n JSON.stringify(getPositive([-1, -2, 4, 5, 6])) === JSON.stringify([4, 5, 6])\n )\n console.assert(\n JSON.stringify(getPositive([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([5, 3, 2, 3, 3, 9, 123, 1])\n )\n console.assert(JSON.stringify(getPositive([-1, -2])) === JSON.stringify([]))\n console.assert(JSON.stringify(getPositive([])) === JSON.stringify([]))\n}\n\ntestGetPositive()\n", "declaration": "\nconst getPositive = (l) => {\n", "example_test": "const testGetPositive = () => {\n console.assert(\n JSON.stringify(getPositive([-1, 2, -4, 5, 6])) === JSON.stringify([2, 5, 6])\n )\n console.assert(\n JSON.stringify(getPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) ===\n JSON.stringify([5, 3, 2, 3, 9, 123, 1])\n )\n}\ntestGetPositive()\n", "buggy_solution": " return l.filter(e => e < 0);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "GetPositive"}
|
32 |
{"task_id": "JavaScript/31", "prompt": "/*Return true if a given number is prime, and false otherwise.\n >>> isPrime(6)\n false\n >>> isPrime(101)\n true\n >>> isPrime(11)\n true\n >>> isPrime(13441)\n true\n >>> isPrime(61)\n true\n >>> isPrime(4)\n false\n >>> isPrime(1)\n false\n */\nconst isPrime = (n) => {\n", "canonical_solution": " if (n < 2)\n return false;\n for (let k = 2; k < n - 1; k++)\n if (n % k == 0)\n return false;\n return true;\n}\n\n", "test": "const testIsPrime = () => {\n console.assert(isPrime(6) === false)\n console.assert(isPrime(101) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(13441) === true)\n console.assert(isPrime(61) === true)\n console.assert(isPrime(4) === false)\n console.assert(isPrime(1) === false)\n console.assert(isPrime(5) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(17) === true)\n console.assert(isPrime(5 * 17) === false)\n console.assert(isPrime(11 * 7) === false)\n console.assert(isPrime(13441 * 19) === false)\n}\n\ntestIsPrime()\n", "declaration": "\nconst isPrime = (n) => {\n", "example_test": "const testIsPrime = () => {\n console.assert(isPrime(6) === false)\n console.assert(isPrime(101) === true)\n console.assert(isPrime(11) === true)\n console.assert(isPrime(13441) === true)\n console.assert(isPrime(61) === true)\n console.assert(isPrime(4) === false)\n console.assert(isPrime(1) === false)\n}\ntestIsPrime()\n", "buggy_solution": " if (n < 1)\n return false;\n for (let k = 1; k < n - 1; k++)\n if (n % k == 0)\n return false;\n return true;\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsPrime"}
|
33 |
+
{"task_id": "JavaScript/32", "prompt": "/*\n Evaluates polynomial with coefficients xs at point x.\n return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n\n */\nconst poly = (xs, x) => {\n return xs.reduce((prev, item, index) => {\n return prev + item * Math.pow(x, index);\n }, 0);\n}\n\n/*\n xs are coefficients of a polynomial.\n findZero find x such that poly(x) = 0.\n findZero returns only only zero point, even if there are many.\n Moreover, findZero only takes list xs having even number of coefficients\n and largest non zero coefficient as it guarantees\n a solution.\n >>> round(findZero([1, 2]), 2) # f(x) = 1 + 2x\n -0.5\n >>> round(findZero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n 1.0\n */\nconst findZero = (xs) => {\n", "canonical_solution": " var begin = -1.0, end = 1.0;\n while (poly(xs, begin) * poly(xs, end) > 0) {\n begin *= 2.0;\n end *= 2.0;\n }\n while (end - begin > 1e-10) {\n let center = (begin + end) / 2.0;\n if (poly(xs, center) * poly(xs, begin) > 0)\n begin = center;\n else\n end = center;\n }\n return begin;\n}\n\n", "test": "const testfindZero = () => {\n const getRandomIntInclusive = (min = 0, max = 9) => {\n min = Math.ceil(min)\n max = Math.floor(max)\n return Math.floor(Math.random() * (max - min + 1)) + min\n }\n\n for (let i = 0; i < 100; i++) {\n let ncoeff = 2 * getRandomIntInclusive(1, 4);\n let coeffs = [];\n for (let j = 0; j < ncoeff; j++) {\n let coeff = getRandomIntInclusive(-10, 10);\n if (coeff === 0)\n coeff = 1;\n coeffs.push(coeff);\n }\n let solution = findZero(coeffs);\n console.assert(Math.abs(poly(coeffs, solution)) < 1e-4);\n }\n}\ntestfindZero()\n", "declaration": "\nconst poly = (xs, x) => {\n return xs.reduce((prev, item, index) => {\n return prev + item * Math.pow(x, index);\n }, 0);\n}\n\nconst findZero = (xs) => {\n", "example_test": "const testPoly = () => {\n console.assert(Math.abs(findZero([1,2])+0.5 < 1e-4));\n console.assert(Math.abs(findZero([-6,11,-6,1])-1 < 1e-4));\n}\ntestPoly()\n", "buggy_solution": " var begin = -1.0, end = 1.0;\n while (poly(xs, begin) * poly(xs, end) > 0) {\n begin *= 2.0;\n end *= 2.0;\n }\n while (begin - end > 1e-10) {\n let center = (begin + end) / 2.0;\n if (poly(xs, center) * poly(xs, end) > 0)\n begin = center;\n else\n end = center;\n }\n return end;\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "FindZero"}
|
34 |
{"task_id": "JavaScript/33", "prompt": "/*This function takes a list l and returns a list l' such that\n l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n to the values of the corresponding indicies of l, but sorted.\n >>> sortThird([1, 2, 3])\n [1, 2, 3]\n >>> sortThird([5, 6, 3, 4, 8, 9, 2])\n [2, 6, 3, 4, 8, 9, 5]\n */\nconst sortThird = (l) => {\n", "canonical_solution": " var three = l.filter((item, index) => index % 3 == 0);\n three.sort((a, b) => (a - b));\n return l.map((item, index) => (index % 3 == 0 ? three[index / 3] : item));\n}\n\n", "test": "const testSortThird = () => {\n console.assert(\n JSON.stringify(sortThird([1, 2, 3])) == JSON.stringify([1, 2, 3])\n )\n console.assert(\n JSON.stringify(sortThird([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) ==\n JSON.stringify([1, 3, -5, 2, -3, 3, 5, 0, 123, 9, -10])\n )\n console.assert(\n JSON.stringify(sortThird([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) ==\n JSON.stringify([-10, 8, -12, 3, 23, 2, 4, 11, 12, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 3, 4, 8, 9, 2])) ==\n JSON.stringify([2, 6, 3, 4, 8, 9, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 8, 3, 4, 6, 9, 2])) ==\n JSON.stringify([2, 8, 3, 4, 6, 9, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 9, 4, 8, 3, 2])) ==\n JSON.stringify([2, 6, 9, 4, 8, 3, 5])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 3, 4, 8, 9, 2, 1])) ==\n JSON.stringify([2, 6, 3, 4, 8, 9, 5, 1])\n )\n}\n\ntestSortThird()\n", "declaration": "\nconst sortThird = (l) => {\n", "example_test": "const testSortThird = () => {\n console.assert(\n JSON.stringify(sortThird([1, 2, 3])) == JSON.stringify([1, 2, 3])\n )\n console.assert(\n JSON.stringify(sortThird([5, 6, 3, 4, 8, 9, 2])) ==\n JSON.stringify([2, 6, 3, 4, 8, 9, 5])\n )\n}\ntestSortThird()\n", "buggy_solution": " var three = l.filter((item, index) => index % 3 == 0);\n return l.map((item, index) => (index % 2 == 0 ? three[index / 3] : item));\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "SortThird"}
|
35 |
{"task_id": "JavaScript/34", "prompt": "/*Return sorted unique elements in a list\n >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [0, 2, 3, 5, 9, 123]\n */\nconst unique = (l) => {\n", "canonical_solution": " return Array.from(new Set(l)).sort((a, b) => (a - b));\n}\n\n", "test": "const testUnique = () => {\n console.assert(\n JSON.stringify(unique([5, 3, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([0, 2, 3, 5, 9, 123])\n )\n}\n\ntestUnique()\n", "declaration": "\nconst unique = (l) => {\n", "example_test": "const testUnique = () => {\n console.assert(\n JSON.stringify(unique([5, 3, 5, 2, 3, 3, 9, 0, 123])) ===\n JSON.stringify([0, 2, 3, 5, 9, 123])\n )\n}\ntestUnique()\n", "buggy_solution": " return l.sort((a, b) => (a - b));\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Unique"}
|
36 |
{"task_id": "JavaScript/35", "prompt": "/*Return maximum element in the list.\n >>> maxElement([1, 2, 3])\n 3\n >>> maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n 123\n */\nconst maxElement = (l) => {\n", "canonical_solution": " return Math.max(...l);\n}\n\n", "test": "const testMaxElement = () => {\n console.assert(maxElement([1, 2, 3]) === 3)\n console.assert(maxElement([5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) === 124)\n}\n\ntestMaxElement()\n", "declaration": "\nconst maxElement = (l) => {\n", "example_test": "const testMaxElement = () => {\n console.assert(maxElement([1, 2, 3]) === 3)\n console.assert(maxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) === 123)\n}\ntestMaxElement()\n", "buggy_solution": " return Math.min(...l);\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "MaxElement"}
|
|
|
117 |
{"task_id": "JavaScript/116", "prompt": "/*\n In this Kata, you have to sort an array of non-negative integers according to\n number of ones in their binary representation in ascending order.\n For similar number of ones, sort based on decimal value.\n\n It must be implemented like this:\n >>> sortArray([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n >>> sortArray([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n >>> sortArray([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]\n */\nconst sortArray = (arr) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[k].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return p\n}\n\n", "test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n console.assert(JSON.stringify(sortArray([])) === JSON.stringify([]))\n console.assert(\n JSON.stringify(sortArray([2, 5, 77, 4, 5, 3, 5, 7, 2, 3, 4])) ===\n JSON.stringify([2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77])\n )\n console.assert(\n JSON.stringify(sortArray([3, 6, 44, 12, 32, 5])) ===\n JSON.stringify([32, 3, 5, 6, 12, 44])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n console.assert(\n JSON.stringify(sortArray([2, 4, 8, 16, 32])) ===\n JSON.stringify([2, 4, 8, 16, 32])\n )\n}\n\ntestSortArray()\n", "declaration": "\nconst sortArray = (arr) => {\n", "example_test": "const testSortArray = () => {\n console.assert(\n JSON.stringify(sortArray([1, 5, 2, 3, 4])) ===\n JSON.stringify([1, 2, 4, 3, 5])\n )\n console.assert(\n JSON.stringify(sortArray([-2, -3, -4, -5, -6])) ===\n JSON.stringify([-4, -2, -6, -5, -3])\n )\n console.assert(\n JSON.stringify(sortArray([1, 0, 2, 3, 4])) ===\n JSON.stringify([0, 1, 2, 4, 3])\n )\n}\ntestSortArray()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n let w1 = p[ind].toString(2)\n let f1 = 0\n for (let u = 0; u < w1.length; u++) {\n if (w1[u] == '1') { f1++ }\n }\n let w2 = p[ind].toString(2)\n let f2 = 0\n for (let u = 0; u < w2.length; u++) {\n if (w2[u] == '1') { f2++ }\n }\n if (f2 < f1 || (f1 == f2 && p[k] < p[ind])) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n return arr\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "SortArray"}
|
118 |
{"task_id": "JavaScript/117", "prompt": "/*Given a string s and a natural number n, you have been tasked to implement \n a function that returns a list of all words from string s that contain exactly \n n consonants, in order these words appear in the string s.\n If the string s is empty then the function should return an empty list.\n Note: you may assume the input string contains only letters and spaces.\n Examples:\n selectWords(\"Mary had a little lamb\", 4) ==> [\"little\"]\n selectWords(\"Mary had a little lamb\", 3) ==> [\"Mary\")\n selectWords(\"simple white space\", 2) ==> []\n selectWords(\"Hello world\", 4) ==> [\"world\"]\n selectWords(\"Uncle sam\", 3) ==> [\"Uncle\"]\n */\nconst selectWords = (s, n) => {\n", "canonical_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' && t[i][j] != 'e' && t[i][j] != 'i' && t[i][j] != 'o' && t[i][j] != 'u' && t[i][j] != 'A' &&\n t[i][j] != 'U' && t[i][j] != 'O' && t[i][j] != 'I' && t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n\n console.assert(\n JSON.stringify(selectWords('a b c d e f', 1)) ===\n JSON.stringify(['b', 'c', 'd', 'f'])\n )\n\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n console.assert(JSON.stringify(selectWords('', 4)) === JSON.stringify([]))\n}\n\ntestSelectWords()\n", "declaration": "\nconst selectWords = (s, n) => {\n", "example_test": "const testSelectWords = () => {\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 4)) ===\n JSON.stringify(['little'])\n )\n console.assert(\n JSON.stringify(selectWords('simple white space', 2)) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(selectWords('Hello world', 4)) === JSON.stringify(['world'])\n )\n console.assert(\n JSON.stringify(selectWords('Uncle sam', 3)) === JSON.stringify(['Uncle'])\n )\n console.assert(\n JSON.stringify(selectWords('Mary had a little lamb', 3)) ===\n JSON.stringify(['Mary', 'lamb'])\n )\n}\ntestSelectWords()\n", "buggy_solution": " let t = s.split(/\\s/)\n if (s == '') { return [] }\n let k = []\n for (let i = 0; i < t.length; i++) {\n let l = 0\n for (let j = 0; j < t[i].length; j++) {\n if (t[i][j] != 'a' || t[i][j] != 'e' || t[i][j] != 'i' || t[i][j] != 'o' || t[i][j] != 'u' || t[i][j] != 'A' ||\n t[i][j] != 'U' || t[i][j] != 'O' || t[i][j] != 'I' || t[i][j] != 'E') {\n l++\n }\n }\n if (l == n) { k.push(t[i]) }\n }\n return k\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "SelectWords"}
|
119 |
{"task_id": "JavaScript/118", "prompt": "/*You are given a word. Your task is to find the closest vowel that stands between \n two consonants from the right side of the word (case sensitive).\n \n Vowels in the beginning and ending doesn't count. Return empty string if you didn't\n find any vowel met the above condition. \n\n You may assume that the given string contains English letter only.\n\n Example:\n getClosestVowel(\"yogurt\") ==> \"u\"\n getClosestVowel(\"FULL\") ==> \"U\"\n getClosestVowel(\"quick\") ==> \"\"\n getClosestVowel(\"ab\") ==> \"\"\n */\nconst getClosestVowel = (word) => {\n", "canonical_solution": " for (let i = word.length - 2; i > 0; i--) {\n if (\n !(word[i] != 'a' && word[i] != 'e' && word[i] != 'i' && word[i] != 'o' && word[i] != 'u' && word[i] != 'A' &&\n word[i] != 'U' && word[i] != 'O' && word[i] != 'I' && word[i] != 'E')\n &&\n (word[i + 1] != 'a' && word[i + 1] != 'e' && word[i + 1] != 'i' && word[i + 1] != 'o' && word[i + 1] != 'u' && word[i + 1] != 'A' &&\n word[i + 1] != 'U' && word[i + 1] != 'O' && word[i + 1] != 'I' && word[i + 1] != 'E')\n &&\n (word[i - 1] != 'a' && word[i - 1] != 'e' && word[i - 1] != 'i' && word[i - 1] != 'o' && word[i - 1] != 'u' && word[i - 1] != 'A' &&\n word[i - 1] != 'U' && word[i - 1] != 'O' && word[i - 1] != 'I' && word[i - 1] != 'E')\n ) {\n return word[i]\n }\n }\n return ''\n}\n\n", "test": "const testGetClosestVowel = () => {\n console.assert(getClosestVowel('yogurt') === 'u')\n console.assert(getClosestVowel('full') === 'u')\n console.assert(getClosestVowel('easy') === '')\n console.assert(getClosestVowel('eAsy') === '')\n console.assert(getClosestVowel('ali') === '')\n console.assert(getClosestVowel('bad') === 'a')\n console.assert(getClosestVowel('most') === 'o')\n console.assert(getClosestVowel('ab') === '')\n console.assert(getClosestVowel('ba') === '')\n console.assert(getClosestVowel('quick') === '')\n console.assert(getClosestVowel('anime') === 'i')\n console.assert(getClosestVowel('Asia') === '')\n console.assert(getClosestVowel('Above') === 'o')\n}\n\ntestGetClosestVowel()\n", "declaration": "\nconst getClosestVowel = (word) => {\n", "example_test": "const testGetClosestVowel = () => {\n console.assert(getClosestVowel('yogurt') === 'u')\n console.assert(getClosestVowel('FULL') === 'U')\n console.assert(getClosestVowel('ab') === '')\n console.assert(getClosestVowel('quick') === '')\n}\ntestGetClosestVowel()\n", "buggy_solution": " for (let i = word.length - 2; i > 0; i--) {\n if (\n (word[i] != 'a' && word[i] != 'e' && word[i] != 'i' && word[i] != 'o' && word[i] != 'u' && word[i] != 'A' &&\n word[i] != 'U' && word[i] != 'O' && word[i] != 'I' && word[i] != 'E')\n &&\n (word[i + 1] != 'a' && word[i + 1] != 'e' && word[i + 1] != 'i' && word[i + 1] != 'o' && word[i + 1] != 'u' && word[i + 1] != 'A' &&\n word[i + 1] != 'U' && word[i + 1] != 'O' && word[i + 1] != 'I' && word[i + 1] != 'E')\n &&\n (word[i - 1] != 'a' && word[i - 1] != 'e' && word[i - 1] != 'i' && word[i - 1] != 'o' && word[i - 1] != 'u' && word[i - 1] != 'A' &&\n word[i - 1] != 'U' && word[i - 1] != 'O' && word[i - 1] != 'I' && word[i - 1] != 'E')\n ) {\n return word[i]\n }\n }\n return ' '\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "GetClosestVowel"}
|
120 |
+
{"task_id": "JavaScript/119", "prompt": "/* You are given a list of two strings, both strings consist of open\n parentheses '(' or close parentheses ')' only.\n Your job is to check if it is possible to concatenate the two strings in\n some order, that the resulting string will be good.\n A string S is considered to be good if and only if all parentheses in S\n are balanced. For example: the string '(())()' is good, while the string\n '())' is not.\n Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.\n Examples:\n matchParens(['()(', ')']) == 'Yes'\n matchParens([')', ')']) == 'No'\n */\nconst matchParens = (lst) => {\n", "canonical_solution": " let w1 = lst[0] + lst[1]\n let y = 0\n let u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n w1 = lst[1] + lst[0]\n y = 0\n u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'Yes' }\n return 'No'\n}\n\n", "test": "const testMatchParens = () => {\n console.assert(matchParens(['()(', ')']) === 'Yes')\n console.assert(matchParens([')', ')']) === 'No')\n console.assert(matchParens(['(()(())', '())())']) === 'No')\n console.assert(matchParens([')())', '(()()(']) === 'Yes')\n console.assert(matchParens(['(())))', '(()())((']) === 'Yes')\n console.assert(matchParens(['()', '())']) === 'No')\n console.assert(matchParens(['(()(', '()))()']) === 'Yes')\n console.assert(matchParens(['((((', '((())']) === 'No')\n console.assert(matchParens([')(()', '(()(']) === 'No')\n console.assert(matchParens([')(', ')(']) === 'No')\n console.assert(matchParens(['(', ')']) === 'Yes')\n console.assert(matchParens([')', '(']) === 'Yes')\n}\ntestMatchParens()\n", "declaration": "\nconst matchParens = (lst) => {\n", "example_test": "const testMatchParens = () => {\n console.assert(matchParens(['()(', ')']) === 'Yes')\n console.assert(matchParens([')', ')']) === 'No')\n}\ntestMatchParens()\n", "buggy_solution": " let w1 = lst[0] + lst[1]\n let y = 0\n let u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'yes' }\n w1 = lst[1] + lst[0]\n y = 0\n u = 1\n for (let i = 0; i < w1.length; i++) {\n if (w1[i] == '(') { y++ }\n else { y-- }\n if (y < 0) {\n u = 0;\n break;\n }\n }\n if (u == 1 && y == 0) { return 'no' }\n return 'yes'\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "MatchParens"}
|
121 |
{"task_id": "JavaScript/120", "prompt": "/*\n Given an array arr of integers and a positive integer k, return a sorted list \n of length k with the maximum k numbers in arr.\n\n Example 1:\n\n Input: arr = [-3, -4, 5], k = 3\n Output: [-4, -3, 5]\n\n Example 2:\n\n Input: arr = [4, -4, 4], k = 2\n Output: [4, 4]\n\n Example 3:\n\n Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1\n Output: [2]\n\n Note:\n 1. The length of the array will be in the range of [1, 1000].\n 2. The elements in the array will be in the range of [-1000, 1000].\n 3. 0 <= k <= len(arr)\n */\nconst maximum = (arr, k) => {\n", "canonical_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n }\n }\n if (k == 0) { return [] }\n return p.slice(-k)\n}\n\n", "test": "const testMaximum = () => {\n console.assert(\n JSON.stringify(maximum([-3, -4, 5], 3)) === JSON.stringify([-4, -3, 5])\n )\n console.assert(\n JSON.stringify(maximum([4, -4, 4], 2)) === JSON.stringify([4, 4])\n )\n console.assert(\n JSON.stringify(maximum([-3, 2, 1, 2, -1, -2, 1], 1)) === JSON.stringify([2])\n )\n console.assert(\n JSON.stringify(maximum([123, -123, 20, 0, 1, 2, -3], 3)) ===\n JSON.stringify([2, 20, 123])\n )\n console.assert(\n JSON.stringify(maximum([-123, 20, 0, 1, 2, -3], 4)) ===\n JSON.stringify([0, 1, 2, 20])\n )\n console.assert(\n JSON.stringify(maximum([5, 15, 0, 3, -13, -8, 0], 7)) ===\n JSON.stringify([-13, -8, 0, 0, 3, 5, 15])\n )\n console.assert(\n JSON.stringify(maximum([-1, 0, 2, 5, 3, -10], 2)) === JSON.stringify([3, 5])\n )\n console.assert(\n JSON.stringify(maximum([1, 0, 5, -7], 1)) === JSON.stringify([5])\n )\n console.assert(JSON.stringify(maximum([4, -4], 2)) === JSON.stringify([-4, 4]))\n console.assert(\n JSON.stringify(maximum([-10, 10], 2)) === JSON.stringify([-10, 10])\n )\n console.assert(\n JSON.stringify(maximum([1, 2, 3, -23, 243, -400, 0], 0)) ===\n JSON.stringify([])\n )\n}\n\ntestMaximum()\n", "declaration": "\nconst maximum = (arr, k) => {\n", "example_test": "const testMaximum = () => {\n console.assert(\n JSON.stringify(maximum([-3, -4, 5], 3)) === JSON.stringify([-4, -3, 5])\n )\n console.assert(\n JSON.stringify(maximum([4, -4, 4], 2)) === JSON.stringify([4, 4])\n )\n console.assert(\n JSON.stringify(maximum([-3, 2, 1, 2, -1, -2, 1], 1)) === JSON.stringify([2])\n )\n}\ntestMaximum()\n", "buggy_solution": " let p = arr\n for (let j = 0; j < p.length; j++) {\n let ind = j\n for (let k = j + 1; k < p.length; k++) {\n if (p[k] < p[ind]) {\n ind = k\n }\n }\n if (ind > j) {\n let tmp = p[j]\n p[j] = p[ind]\n p[ind] = tmp\n p[j] = p[ind]\n }\n }\n if (k == 0) { return [] }\n return p.slice(-k)\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Maximum"}
|
122 |
{"task_id": "JavaScript/121", "prompt": "/*Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions.\n \n\n Examples\n solution([5, 8, 7, 1]) ==> 12\n solution([3, 3, 3, 3, 3]) ==> 9\n solution([30, 13, 24, 321]) ==>0\n */\nconst solution = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i += 2) {\n if (lst[i] % 2 == 1) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "test": "const testSolution = () => {\n console.assert(solution([5, 8, 7, 1]) === 12)\n console.assert(solution([3, 3, 3, 3, 3]) === 9)\n console.assert(solution([30, 13, 24, 321]) === 0)\n console.assert(solution([5, 9]) === 5)\n console.assert(solution([2, 4, 8]) === 0)\n console.assert(solution([30, 13, 23, 32]) === 23)\n console.assert(solution([3, 13, 2, 9]) === 3)\n}\n\ntestSolution()\n", "declaration": "\nconst solution = (lst) => {\n", "example_test": "const testSolution = () => {\n console.assert(solution([5, 8, 7, 1]) === 12)\n console.assert(solution([3, 3, 3, 3, 3]) === 9)\n console.assert(solution([30, 13, 24, 321]) === 0)\n}\ntestSolution()\n", "buggy_solution": " let p = 1\n for (let i = 0; i < lst.length; i += 2) {\n if (lst[i] % 2 == 1) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Solution"}
|
123 |
{"task_id": "JavaScript/122", "prompt": "/*\n Given a non-empty array of integers arr and an integer k, return\n the sum of the elements with at most two digits from the first k elements of arr.\n\n Example:\n\n Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4\n Output: 24 # sum of 21 + 3\n\n Constraints:\n 1. 1 <= len(arr) <= 100\n 2. 1 <= k <= len(arr)\n */\nconst addElements = (arr, k) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < k; i++) {\n if (arr[i] < 100 && arr[i] > -100) { p += arr[i] }\n }\n return p\n}\n\n", "test": "const testAddElements = () => {\n console.assert(addElements([1, -2, -3, 41, 57, 76, 87, 88, 99], 3) === -4)\n console.assert(addElements([111, 121, 3, 4000, 5, 6], 2) === 0)\n console.assert(addElements([11, 21, 3, 90, 5, 6, 7, 8, 9], 4) === 125)\n console.assert(addElements([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4) === 24)\n console.assert(addElements([1], 1) === 1)\n}\n\ntestAddElements()\n", "declaration": "\nconst addElements = (arr, k) => {\n", "example_test": "const testAddElements = () => {\n console.assert(addElements([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4) === 24)\n}\ntestAddElements()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < arr.length; i++) {\n if (arr[i] < 100 && arr[i] > -100) { p += arr[i] }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "AddElements"}
|
|
|
149 |
{"task_id": "JavaScript/148", "prompt": "/* There are eight planets in our solar system: the closerst to the Sun\n is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,\n Uranus, Neptune.\n Write a function that takes two planet names as strings planet1 and planet2.\n The function should return a tuple containing all planets whose orbits are\n located between the orbit of planet1 and the orbit of planet2, sorted by\n the proximity to the sun.\n The function should return an empty tuple if planet1 or planet2\n are not correct planet names.\n Examples\n bf(\"Jupiter\", \"Neptune\") ==> (\"Saturn\", \"Uranus\")\n bf(\"Earth\", \"Mercury\") ==> (\"Venus\")\n bf(\"Mercury\", \"Uranus\") ==> (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")\n */\nconst bf = (planet1, planet2) => {\n", "canonical_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n console.assert(\n JSON.stringify(bf('Neptune', 'Venus')) ===\n JSON.stringify(['Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus'])\n )\n console.assert(JSON.stringify(bf('Earth', 'Earth')) === JSON.stringify([]))\n console.assert(JSON.stringify(bf('Mars', 'Earth')) === JSON.stringify([]))\n console.assert(\n JSON.stringify(bf('Jupiter', 'Makemake')) === JSON.stringify([])\n )\n}\n\ntestBf()\n", "declaration": "\nconst bf = (planet1, planet2) => {\n", "example_test": "const testBf = () => {\n console.assert(\n JSON.stringify(bf('Jupiter', 'Neptune')) ===\n JSON.stringify(['Saturn', 'Uranus'])\n )\n console.assert(\n JSON.stringify(bf('Earth', 'Mercury')) === JSON.stringify(['Venus'])\n )\n console.assert(\n JSON.stringify(bf('Mercury', 'Uranus')) ===\n JSON.stringify(['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'])\n )\n}\ntestBf()\n", "buggy_solution": " let y = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupyter', 'Saturn', 'Uranus', 'Neptune']\n let u = []\n let lo = -1\n let hi = -1\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet1) { lo = i }\n }\n for (let i = 0; i < 8; i++) {\n if (y[i] == planet2) { hi = i }\n }\n if (lo == -1 || hi == -1 || lo == hi) { return [] }\n if (lo > hi) {\n let tmp = lo;\n lo = hi;\n hi = tmp;\n }\n for (let i = lo + 1; i < hi; i++) {\n u.push(y[i])\n }\n return u\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Bf"}
|
150 |
{"task_id": "JavaScript/149", "prompt": "/*Write a function that accepts a list of strings as a parameter,\n deletes the strings that have odd lengths from it,\n and returns the resulted list with a sorted order,\n The list is always a list of strings and never an array of numbers,\n and it may contain duplicates.\n The order of the list should be ascending by length of each word, and you\n should return the list sorted by that rule.\n If two words have the same length, sort the list alphabetically.\n The function should return a list of strings in sorted order.\n You may assume that all words will have the same length.\n For example:\n assert list_sort([\"aa\", \"a\", \"aaa\"]) => [\"aa\"]\n assert list_sort([\"ab\", \"a\", \"aaa\", \"cd\"]) => [\"ab\", \"cd\"]\n */\nconst sortedListSum = (lst) => {\n", "canonical_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k] = p[k + 1]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['school', 'AI', 'asdf', 'b'])) ===\n JSON.stringify(['AI', 'asdf', 'school'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'b', 'c', 'a'])) === JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['d', 'dcba', 'abcd', 'a'])) ===\n JSON.stringify(['abcd', 'dcba'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['AI', 'ai', 'au'])) ===\n JSON.stringify(['AI', 'ai', 'au'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['a', 'b', 'b', 'c', 'c', 'a'])) ===\n JSON.stringify([])\n )\n console.assert(\n JSON.stringify(sortedListSum(['aaaa', 'bbbb', 'dd', 'cc'])) ===\n JSON.stringify(['cc', 'dd', 'aaaa', 'bbbb'])\n )\n}\n\ntestSortedListSum()\n", "declaration": "\nconst sortedListSum = (lst) => {\n", "example_test": "const testSortedListSum = () => {\n console.assert(\n JSON.stringify(sortedListSum(['aa', 'a', 'aaa'])) === JSON.stringify(['aa'])\n )\n console.assert(\n JSON.stringify(sortedListSum(['ab', 'a', 'aaa', 'cd'])) ===\n JSON.stringify(['ab', 'cd'])\n )\n}\ntestSortedListSum()\n", "buggy_solution": " let p = []\n for (let i = 0; i < lst.length; i++) {\n if (lst[i].length % 2 == 0) {\n p.push(lst[i])\n }\n }\n for (let j = p.length - 2; j >= 0; j--) {\n for (let k = 0; k <= j; k++) {\n let f = 0\n if (p[k].length > p[k + 1].length) { f = 1 }\n if (p[k].length == p[k + 1].length) {\n let r = p[k].length\n for (let l = 0; l < r; l++) {\n if (p[k][l].charCodeAt() > p[k + 1][l].charCodeAt()) {\n f = 1;\n break;\n }\n if (p[k][l].charCodeAt() < p[k + 1][l].charCodeAt()) {\n break;\n }\n }\n }\n if (f == 1) {\n let tmp = p[k]\n p[k + 1] = tmp\n }\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "SortedListSum"}
|
151 |
{"task_id": "JavaScript/150", "prompt": "/*A simple program which should return the value of x if n is \n a prime number and should return the value of y otherwise.\n\n Examples:\n for xOrY(7, 34, 12) == 34\n for xOrY(15, 8, 5) == 5\n \n */\nconst xOrY = (n, x, y) => {\n", "canonical_solution": " let len = n\n if (len == 1 || len == 0) { return y }\n for (let i = 2; i * i <= len; i++) {\n if (len % i == 0) { return y }\n }\n return x\n}\n\n", "test": "const testXOrY = () => {\n console.assert(xOrY(7, 34, 12) === 34)\n console.assert(xOrY(15, 8, 5) === 5)\n console.assert(xOrY(3, 33, 5212) === 33)\n console.assert(xOrY(1259, 3, 52) === 3)\n console.assert(xOrY(7919, -1, 12) === -1)\n console.assert(xOrY(3609, 1245, 583) === 583)\n console.assert(xOrY(91, 56, 129) === 129)\n console.assert(xOrY(6, 34, 1234) === 1234)\n console.assert(xOrY(1, 2, 0) === 0)\n console.assert(xOrY(2, 2, 0) === 2)\n}\n\ntestXOrY()\n", "declaration": "\nconst xOrY = (n, x, y) => {\n", "example_test": "const testXOrY = () => {\n console.assert(xOrY(7, 34, 12) === 34)\n console.assert(xOrY(15, 8, 5) === 5)\n}\ntestXOrY()\n", "buggy_solution": " let len = n\n if (len == 1 || len == 0) { return y }\n for (let i = 2; i * i <= len; i++) {\n if (len % i - 1 == 0) { return y }\n }\n return x\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "XOrY"}
|
152 |
+
{"task_id": "JavaScript/151", "prompt": "/* Given a list of numbers, return the sum of squares of the numbers\n in the list that are odd. Ignore numbers that are negative or not integers.\n doubleTheDifference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\n doubleTheDifference([-1, -2, 0]) == 0\n doubleTheDifference([9, -2]) == 81\n doubleTheDifference([0]) == 0\n If the input list is empty, return 0.\n */\nconst doubleTheDifference = (lst) => {\n", "canonical_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] % 2 == 1 && lst[i] > 0) {\n p += lst[i] * lst[i]\n }\n }\n return p\n}\n\n", "test": "const testDoubleTheDifference = () => {\n console.assert(doubleTheDifference([]) === 0)\n console.assert(doubleTheDifference([5, 4]) === 25)\n console.assert(doubleTheDifference([0.1, 0.2, 0.3]) === 0)\n console.assert(doubleTheDifference([-10, -20, -30]) === 0)\n console.assert(doubleTheDifference([-1, -2, 8]) === 0)\n console.assert(doubleTheDifference([0.2, 3, 5]) === 34)\n let lst = []\n let odd_sum = 0\n for (let i = -99; i < 100; i += 2) {\n if (i % 2 != 0 && i > 0) { odd_sum += i * i }\n lst.push(i)\n }\n console.assert(doubleTheDifference(lst) === odd_sum)\n}\ntestDoubleTheDifference()\n", "declaration": "\nconst doubleTheDifference = (lst) => {\n", "example_test": "const testDoubleTheDifference = () => {\n console.assert(doubleTheDifference([1,3,2,0]) === 10)\n console.assert(doubleTheDifference([-1,-2,0]) === 0)\n console.assert(doubleTheDifference([9,-2]) === 81)\n console.assert(doubleTheDifference([0]) === 0)\n}\ntestDoubleTheDifference()\n", "buggy_solution": " let p = 0\n for (let i = 0; i < lst.length; i++) {\n if (lst[i] > 0) {\n p += lst[i]\n }\n }\n return p\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "DoubleTheDifference"}
|
153 |
{"task_id": "JavaScript/152", "prompt": "/*I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match. \n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n \n \n example:\n\n compare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\n compare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]\n */\nconst compare = (game, guess) => {\n", "canonical_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i]; }\n return game\n}\n\n", "test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0])) ===\n JSON.stringify([0, 0, 0, 0, 0, 0])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3], [-1, -2, -3])) ===\n JSON.stringify([2, 4, 6])\n )\n console.assert(\n JSON.stringify(compare([1, 2, 3, 5], [-1, 2, 3, 4])) ===\n JSON.stringify([2, 0, 0, 1])\n )\n}\n\ntestCompare()\n", "declaration": "\nconst compare = (game, guess) => {\n", "example_test": "const testCompare = () => {\n console.assert(\n JSON.stringify(compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])) ===\n JSON.stringify([0, 0, 0, 0, 3, 3])\n )\n console.assert(\n JSON.stringify(compare([0,5,0,0,0,4],[4,1,1,0,0,-2])) ===\n JSON.stringify([4,4,1,0,0,6])\n )\n}\ntestCompare()\n", "buggy_solution": " for (let i = 0; i < guess.length; i++) {\n game[i] -= guess[i]\n if (game[i]<0)\n game[i]=-game[i];\n if (guess[i]!=0)\n game[i]-=guess[i]; }\n return game\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Compare"}
|
154 |
{"task_id": "JavaScript/153", "prompt": "/*You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters\n in the extension's name, the strength is given by the fraction CAP - SM.\n You should find the strongest extension and return a string in this\n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should\n return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension\n (its strength is -1).\n Example:\n for strongestExtension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'\n */\nconst strongestExtension = (class_name, extensions) => {\n", "canonical_solution": " let u = 0\n let s = -Infinity\n for (let i = extensions.length - 1; i >= 0; i--) {\n let y = 0\n for (let j = 0; j < extensions[i].length; j++) {\n let k = extensions[i][j].charCodeAt()\n if (k >= 65 && k <= 90) { y += 1 }\n if (k >= 97 && k <= 122) { y -= 1 }\n }\n if (y >= s) {\n s = y;\n u = i;\n }\n }\n return class_name + '.' + extensions[u]\n}\n\n", "test": "const testStrongestExtension = () => {\n console.assert(\n strongestExtension('Watashi', ['tEN', 'niNE', 'eIGHt8OKe']) ===\n 'Watashi.eIGHt8OKe'\n )\n console.assert(\n strongestExtension('Boku123', [\n 'nani',\n 'NazeDa',\n 'YEs.WeCaNe',\n '32145tggg',\n ]) === 'Boku123.YEs.WeCaNe'\n )\n console.assert(\n strongestExtension('__YESIMHERE', [\n 't',\n 'eMptY',\n 'nothing',\n 'zeR00',\n 'NuLl__',\n '123NoooneB321',\n ]) === '__YESIMHERE.NuLl__'\n )\n console.assert(\n strongestExtension('K', ['Ta', 'TAR', 't234An', 'cosSo']) === 'K.TAR'\n )\n console.assert(\n strongestExtension('__HAHA', ['Tab', '123', '781345', '-_-']) ===\n '__HAHA.123'\n )\n console.assert(\n strongestExtension('YameRore', [\n 'HhAas',\n 'okIWILL123',\n 'WorkOut',\n 'Fails',\n '-_-',\n ]) === 'YameRore.okIWILL123'\n )\n console.assert(\n strongestExtension('finNNalLLly', ['Die', 'NowW', 'Wow', 'WoW']) ===\n 'finNNalLLly.WoW'\n )\n console.assert(strongestExtension('_', ['Bb', '91245']) === '_.Bb')\n console.assert(strongestExtension('Sp', ['671235', 'Bb']) === 'Sp.671235')\n}\n\ntestStrongestExtension()\n", "declaration": "\nconst strongestExtension = (class_name, extensions) => {\n", "example_test": "const testStrongestExtension = () => {\n console.assert(\n strongestExtension('my_class', ['AA', 'Be', 'CC']) ===\n 'my_class.AA'\n )\n}\ntestStrongestExtension()\n", "buggy_solution": " let u = 0\n let s = -Infinity\n for (let i = extensions.length - 1; i >= 0; i--) {\n let y = 0\n for (let j = 0; j < extensions[i].length; j++) {\n let k = extensions[i][j].charCodeAt()\n if (k >= 65 && k <= 90) { y += 1 }\n if (k >= 97 && k <= 122) { y -= 1 }\n }\n if (y >= s) {\n s = y;\n u = i;\n }\n }\n return class_name + extensions[u]\n}\n\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "StrongestExtension"}
|
155 |
{"task_id": "JavaScript/154", "prompt": "/*You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\n cycpatternCheck(\"abcd\",\"abd\") => false\n cycpatternCheck(\"hello\",\"ell\") => true\n cycpatternCheck(\"whassup\",\"psus\") => false\n cycpatternCheck(\"abab\",\"baa\") => true\n cycpatternCheck(\"efef\",\"eeff\") => false\n cycpatternCheck(\"himenss\",\"simen\") => true\n */\nconst cycpatternCheck = (a, b) => {\n", "canonical_solution": " let l = b.length\n let pat = b + b\n for (let i = 0; i < a.length - l + 1; i++) {\n for (let j = 0; j < l + 1; j++) {\n let y = 1\n for (let k = 0; k < l; k++) {\n if (a[i + k] != pat[j + k]) { y = 0 }\n }\n if (y == 1) {\n return true\n }\n }\n }\n return false\n}\n\n", "test": "const testCycpatternCheck = () => {\n console.assert(cycpatternCheck('xyzw', 'xyw') === false)\n console.assert(cycpatternCheck('yello', 'ell') === true)\n console.assert(cycpatternCheck('whattup', 'ptut') === false)\n console.assert(cycpatternCheck('efef', 'fee') === true)\n console.assert(cycpatternCheck('abab', 'aabb') === false)\n console.assert(cycpatternCheck('winemtt', 'tinem') === true)\n}\n\ntestCycpatternCheck()\n", "declaration": "\nconst cycpatternCheck = (a, b) => {\n", "example_test": "const testCycpatternCheck = () => {\n console.assert(cycpatternCheck('abcd', 'abd') === false)\n console.assert(cycpatternCheck('hello', 'ell') === true)\n console.assert(cycpatternCheck('whassup', 'psus') === false)\n console.assert(cycpatternCheck('abab', 'baa') === true)\n console.assert(cycpatternCheck('efef', 'eeff') === false)\n console.assert(cycpatternCheck('himenss', 'simen') === true)\n}\ntestCycpatternCheck()\n", "buggy_solution": " let l = b.length\n let pat = b + b\n for (let i = 0; i < a.length - l + 1; i++) {\n for (let j = 0; j < b.length - l + 1; j++) {\n let y = 1\n for (let k = 0; k < l; k++) {\n if (a[i + k] != pat[j + k]) { y = 0 }\n }\n if (y == 1) {\n return true\n }\n }\n }\n return false\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "CycpatternCheck"}
|