name stringlengths 34 63 | language stringclasses 3
values | prompt stringlengths 91 2.81k | suffix stringlengths 0 1.57k | canonical_solution stringlengths 1 219 | tests stringlengths 149 4.98k |
|---|---|---|---|---|---|
humaneval-HumanEval_137_compare_one.json-L54 | py | from typing import Union
def compare_one(a: Union[int, float, str], b: Union[int, float, str]) -> Union[int, float, str, None]:
"""
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values ... | return None
elif isinstance(a, str) and isinstance(b, int):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b
else:
return None
elif isinstance(a, int) and isinstance(b, str):
b_tmp = ... | else: | def check(candidate):
assert candidate(1, 2) == 2
assert candidate(1, 2.5) == 2.5
assert candidate(2, 3) == 3
assert candidate(5, 6) == 6
assert candidate(1, '2,3') == '2,3'
assert candidate('5,1', '6') == '6'
assert candidate('1', '2') == '2'
assert candidate('1', 1) == None
def test_c... |
humaneval-HumanEval_42_incr_list.json-L12 | js | //Return array with elements incremented by 1.
// >>> incr_list([1, 2, 3])
// [2, 3, 4]
// >>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123])
// [6, 4, 6, 3, 4, 4, 10, 1, 124]
function incr_list(l){
var new_list = [];
for(var i = 0; i < l.length; i++){
new_list.push(l[i] + 1);
}
return new_list; | } | const assert = require('node:assert');
function test() {
let candidate = incr_list;
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([3, 2, 1]),[4, 3, 2]);
assert.deepEqual(candidate([5, 2, 5, 2, 3, 3, 9, 0, 123]),[6, 3, 6, 3, 4, 4, 10, 1, 124]);
}
test(); | |
humaneval-HumanEval_95_check_dict_case.json-L41 | js | //Given an object, return true if all keys are strings in lower
// case or all keys are strings in upper case, else return false.
// The function should return false is the given object is empty.
// Examples:
// >>> check_dict_case({"a": "apple", "b": "banana"})
// true
// >>> check_dict_case({"a": "apple", "A": "bana... | }
}
else{
return false;
}
}
return true;
} | } | const assert = require('node:assert');
function test() {
let candidate = check_dict_case;
assert.deepEqual(candidate({"p": "pineapple", "b": "banana"}),true);
assert.deepEqual(candidate({"p": "pineapple", "A": "banana", "B": "banana"}),false);
assert.deepEqual(candidate({"p": "pineapple", "5": "banana", "a": ... |
humaneval-HumanEval_64_vowels_count.json-L19 | js | //Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// >>> vowels_count("abcde")
// 2
// >>> vo... | count++;
}
return count;
}
| if(s[s.length-1]=='y'){ | const assert = require('node:assert');
function test() {
let candidate = vowels_count;
assert.deepEqual(candidate("abcde"),2);
assert.deepEqual(candidate("Alone"),3);
assert.deepEqual(candidate("key"),2);
assert.deepEqual(candidate("bye"),1);
assert.deepEqual(candidate("keY"),2);
assert.deepEqual(candid... |
humaneval-HumanEval_142_sum_squares.json-L24 | js | //"
// This function will take an array of integers. For all entries in the array, the function shall square the integer entry if its index is a
// multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not
// change the entries in the array whose inde... | } | return sum; | const assert = require('node:assert');
function test() {
let candidate = sum_squares;
assert.deepEqual(candidate([1, 2, 3]),6);
assert.deepEqual(candidate([1, 4, 9]),14);
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([1, 1, 1, 1, 1, 1, 1, 1, 1]),9);
assert.deepEqual(candidate([-1, -1, -1, ... |
humaneval-HumanEval_68_pluck.json-L42 | py | from typing import List
def pluck(arr: List[int]) -> List[int]:
"""
"Given an array representing a branch of a tree that has non-negative integer nodes
your task is to pluck one of the nodes and return it.
The plucked node should be the node with the smallest even value.
If multiple nodes with the ... | return [min(evens), arr.index(min(evens))] | def check(candidate):
assert candidate([4, 2, 3]) == [2, 1]
assert candidate([1, 2, 3]) == [2, 1]
assert candidate([]) == []
assert candidate([5, 0, 3, 0, 4, 2]) == [0, 1]
assert candidate([1, 2, 3, 0, 5, 3]) == [0, 3]
assert candidate([5, 4, 8, 4, 8]) == [4, 1]
assert candidate([7, 6, 7, 1]... | |
humaneval-HumanEval_111_histogram.json-L21 | js | //Given a string representing a space separated lowercase letters, return an object
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// >>> histogram("a b c")
// {"a": 1, "b": 1, "c": 1}
// >>> histogram("a ... | if (count[lst[i]]){
count[lst[i]] += 1;
}
else{
count[lst[i]] = 1;
}
}
console.log(count);
var max = 0;
var result = {};
for (var key in count){
if (count[key] > max){
max = count[key];
result = {};
result[key] = max;
}
else if (count[key] === max){
... | for (var i = 0; i < lst.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = histogram;
assert.deepEqual(candidate("a b b a"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c a b"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c d g"),{"a": 1, "b": 1, "c": 1, "d": 1, "g": 1});
assert.deepEqual(candidat... |
humaneval-HumanEval_62_derivative.json-L13 | js | //xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// >>> derivative([3, 1, 2, 4, 5])
// [1, 4, 12, 20]
// >>> derivative([1, 2, 3])
// [2, 6]
function derivative(xs){
let coeff = [];
for(let i = 1; i < xs.length; i++)... | }
| return coeff; | const assert = require('node:assert');
function test() {
let candidate = derivative;
assert.deepEqual(candidate([3, 1, 2, 4, 5]),[1, 4, 12, 20]);
assert.deepEqual(candidate([1, 2, 3]),[2, 6]);
assert.deepEqual(candidate([3, 2, 1]),[2, 2]);
assert.deepEqual(candidate([3, 2, 1, 0, 4]),[2, 2, 0, 16]);
assert... |
humaneval-HumanEval_70_strange_sort_list.json-L21 | py | from typing import List
def strange_sort_list(lst: List[int]) -> List[int]:
"""
Given list of integers, return list in strange order.
Strange sorting, is when you start with the minimum value,
then maximum of the remaining integers, then minimum and so on.
Examples:
>>> strange_sort_list([1, 2... | break
out.append(lst.pop())
return out | if not lst: | def check(candidate):
assert candidate([1, 2, 3, 4]) == [1, 4, 2, 3]
assert candidate([5, 6, 7, 8, 9]) == [5, 9, 6, 8, 7]
assert candidate([1, 2, 3, 4, 5]) == [1, 5, 2, 4, 3]
assert candidate([5, 6, 7, 8, 9, 1]) == [1, 9, 5, 8, 6, 7]
assert candidate([5, 5, 5, 5]) == [5, 5, 5, 5]
assert candidat... |
humaneval-HumanEval_134_check_if_last_char_is_a_letter.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a par... | }
int len = txt.length();
if (txt.substring(len - 1, len).matches("[A-Z]") || txt.substring(len - 1, len).matches("[a-z]")) {
if (len == 1) {
return true;
}
if (txt.substring(len - 2, len - 1).matches(" ")) {
return true;
... | return false; | }
public static void main(String[] args) {
assert(checkIfLastCharIsALetter(("apple")) == (false));
assert(checkIfLastCharIsALetter(("apple pi e")) == (true));
assert(checkIfLastCharIsALetter(("eeeee")) == (false));
assert(checkIfLastCharIsALetter(("A")) == (true));
assert(checkIfLastCharIsAL... |
humaneval-HumanEval_41_car_race_collision.json-L20 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different ... | }
} | return nSquared.longValue(); | }
public static void main(String[] args) {
assert(carRaceCollision((2l)) == (4l));
assert(carRaceCollision((3l)) == (9l));
assert(carRaceCollision((4l)) == (16l));
assert(carRaceCollision((8l)) == (64l));
assert(carRaceCollision((10l)) == (100l));
}
}
|
humaneval-HumanEval_129_minPath.json-L31 | js | //Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in e... | startCell = curr;
}
}
}
let currCell = startCell;
for(let l = 0; l < k; l++){
path.push(currCell);
let neighbours = [];
let x = null;
let y = null;
for(let i = 0; i < n; i++){
for(let j = 0; j < n; j++){
... | if(curr < startCell){ | const assert = require('node:assert');
function test() {
let candidate = minPath;
assert.deepEqual(candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3),[1, 2, 1]);
assert.deepEqual(candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1),[1]);
assert.deepEqual(candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14... |
humaneval-HumanEval_24_largest_divisor.json-L19 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// For a given number n, find the largest number that divides n evenly, smaller than n
// >>> largestDivisor((15l))
// (5l)
pu... | } | } | }
public static void main(String[] args) {
assert(largestDivisor((3l)) == (1l));
assert(largestDivisor((7l)) == (1l));
assert(largestDivisor((10l)) == (5l));
assert(largestDivisor((100l)) == (50l));
assert(largestDivisor((49l)) == (7l));
}
}
|
humaneval-HumanEval_10_make_palindrome.json-L22 | py | def make_palindrome(string: str) -> str:
""" Find the shortest palindrome that begins with a supplied string.
Algorithm idea is simple:
- Find the longest postfix of supplied string that is a palindrome.
- Append to the end of the string reverse of a string prefix that comes before the palindromic suffi... | return string | def check(candidate):
assert candidate('') == ''
assert candidate('x') == 'x'
assert candidate('xyz') == 'xyzyx'
assert candidate('xyx') == 'xyx'
assert candidate('jerry') == 'jerryrrej'
def test_check():
check(make_palindrome)
test_check()
| |
humaneval-HumanEval_68_pluck.json-L38 | py | from typing import List
def pluck(arr: List[int]) -> List[int]:
"""
"Given an array representing a branch of a tree that has non-negative integer nodes
your task is to pluck one of the nodes and return it.
The plucked node should be the node with the smallest even value.
If multiple nodes with the ... | evens = [e for e in arr if e % 2 == 0]
if len(evens) == 0:
return []
return [min(evens), arr.index(min(evens))]
| return [] | def check(candidate):
assert candidate([4, 2, 3]) == [2, 1]
assert candidate([1, 2, 3]) == [2, 1]
assert candidate([]) == []
assert candidate([5, 0, 3, 0, 4, 2]) == [0, 1]
assert candidate([1, 2, 3, 0, 5, 3]) == [0, 3]
assert candidate([5, 4, 8, 4, 8]) == [4, 1]
assert candidate([7, 6, 7, 1]... |
humaneval-HumanEval_49_modp.json-L26 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return 2^n modulo p (be aware of numerics).
// >>> modp((3l), (5l))
// (3l)
// >>> modp((1101l), (101l))
// (2l)
//... | return (sqrt * 2) % p;
}
} | } | }
public static void main(String[] args) {
assert(modp((3l), (5l)) == (3l));
assert(modp((1101l), (101l)) == (2l));
assert(modp((0l), (101l)) == (1l));
assert(modp((3l), (11l)) == (8l));
assert(modp((100l), (101l)) == (1l));
assert(modp((30l), (5l)) == (4l));
assert(modp((31l), (5l))... |
humaneval-HumanEval_144_simplify.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a ... | int x_denom = Integer.parseInt(nums[1]);
int n_denom = Integer.parseInt(n_nums[1]);
int res_num = x_num * n_num;
int res_denom = x_denom * n_denom;
return (res_num % res_denom == 0);
}
} | int n_num = Integer.parseInt(n_nums[0]); | }
public static void main(String[] args) {
assert(simplify(("1/5"), ("5/1")) == (true));
assert(simplify(("1/6"), ("2/1")) == (false));
assert(simplify(("5/1"), ("3/1")) == (true));
assert(simplify(("7/10"), ("10/2")) == (false));
assert(simplify(("2/10"), ("50/10")) == (true));
assert(s... |
humaneval-HumanEval_142_sum_squares.json-L27 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// "
// This function will take an array array list of integers. For all entries in the array list, the function shall square the inte... | }
long ans = 0;
for (int i = 0; i < sz; i++) {
ans += lst.get(i);
}
return ans;
}
} | } | }
public static void main(String[] args) {
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))) == (6l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)9l)))) == (14l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList()))) == (0l... |
humaneval-HumanEval_150_x_or_y.json-L12 | py | def x_or_y(n: int, x: int, y: int) -> int:
"""A simple program which should return the value of x if n is
a prime number and should return the value of y otherwise.
Examples:
>>> x_or_y(7, 34, 12)
34
>>> x_or_y(15, 8, 5)
5
"""
| return y
for i in range(2, n):
if n % i == 0:
return y
return x
| if n < 2: | def check(candidate):
assert candidate(7, 34, 12) == 34
assert candidate(15, 8, 5) == 5
assert candidate(3, 33, 5212) == 33
assert candidate(1259, 3, 52) == 3
assert candidate(7919, -1, 12) == -1
assert candidate(3609, 1245, 583) == 583
assert candidate(91, 56, 129) == 129
assert candida... |
humaneval-HumanEval_129_minPath.json-L45 | js | //Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in e... | y = j;
}
}
}
if(x > 0){
neighbours.push(grid[x - 1][y]);
}
if(x < n - 1){
neighbours.push(grid[x + 1][y]);
}
if(y > 0){
neighbours.push(grid[x][y - 1]);
}
if(y < n - 1){
... | x = i; | const assert = require('node:assert');
function test() {
let candidate = minPath;
assert.deepEqual(candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3),[1, 2, 1]);
assert.deepEqual(candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1),[1]);
assert.deepEqual(candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14... |
humaneval-HumanEval_13_greatest_common_divisor.json-L19 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return a greatest common divisor of two integers a and b
// >>> greatestCommonDivisor((3l), (5l))
// (1l)
// >>> greatestCo... | }
return greatestCommonDivisor(b, a % b);
}
} | return a; | }
public static void main(String[] args) {
assert(greatestCommonDivisor((3l), (7l)) == (1l));
assert(greatestCommonDivisor((10l), (15l)) == (5l));
assert(greatestCommonDivisor((49l), (14l)) == (7l));
assert(greatestCommonDivisor((144l), (60l)) == (12l));
}
}
|
humaneval-HumanEval_82_prime_length.json-L16 | py | def prime_length(string: str) -> bool:
"""Write a function that takes a string and returns True if the string
length is a prime number or False otherwise
Examples
>>> prime_length('Hello')
True
>>> prime_length('abcdcba')
True
>>> prime_length('kittens')
True
>>> prime_length('or... | if (num % i) == 0:
return False
else:
return True
else:
return False
pass
| for i in range(2, num): | def check(candidate):
assert candidate('Hello') == True
assert candidate('abcdcba') == True
assert candidate('kittens') == True
assert candidate('orange') == False
assert candidate('wow') == True
assert candidate('world') == True
assert candidate('MadaM') == True
assert candidate('Wow') ... |
humaneval-HumanEval_6_parse_nested_parens.json-L21 | js | //Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// >>> parse_nested_parens("(()()) ((())) () ((())()())")
//... | maxlevel = 0;
level = 0;
}
}
result.push(maxlevel);
return result;
}
| result.push(maxlevel); | const assert = require('node:assert');
function test() {
let candidate = parse_nested_parens;
assert.deepEqual(candidate("(()()) ((())) () ((())()())"),[2, 3, 1, 3]);
assert.deepEqual(candidate("() (()) ((())) (((())))"),[1, 2, 3, 4]);
assert.deepEqual(candidate("(()(())((())))"),[4]);
}
test(); |
humaneval-HumanEval_17_parse_music.json-L20 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and r... | for (int i = 0; i < chars.length; i++) {
if (chars[i] == 'o') {
if (i + 1 < chars.length && chars[i + 1] == '|') {
res.add((long)2l);
i += 1;
} else {
res.add((long)4l);
}
} else i... | char[] chars = music_string.toCharArray(); | }
public static void main(String[] args) {
assert(parseMusic(("")).equals((new ArrayList<Long>(Arrays.asList()))));
assert(parseMusic(("o o o o")).equals((new ArrayList<Long>(Arrays.asList((long)4l, (long)4l, (long)4l, (long)4l)))));
assert(parseMusic((".| .| .| .|")).equals((new ArrayList<Long>(Arr... |
humaneval-HumanEval_142_sum_squares.json-L26 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// "
// This function will take an array array list of integers. For all entries in the array list, the function shall square the inte... | }
}
long ans = 0;
for (int i = 0; i < sz; i++) {
ans += lst.get(i);
}
return ans;
}
} | lst.set(i, lst.get(i) * lst.get(i) * lst.get(i)); | }
public static void main(String[] args) {
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))) == (6l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)9l)))) == (14l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList()))) == (0l... |
humaneval-HumanEval_61_correct_bracketing.json-L16 | py | def correct_bracketing(brackets: str) -> bool:
""" brackets is a string of "(" and ")".
return True if every opening bracket has a corresponding closing bracket.
>>> correct_bracketing('(')
False
>>> correct_bracketing('()')
True
>>> correct_bracketing('(()())')
True
>>> correct_bra... | count += 1
elif char == ')':
count -= 1
if count < 0:
return False
return count == 0
| if char == '(': | def check(candidate):
assert candidate('()') == True
assert candidate('(()())') == True
assert candidate('()()(()())()') == True
assert candidate('()()((()()())())(()()(()))') == True
assert candidate('((()())))') == False
assert candidate(')(()') == False
assert candidate('(') == False
... |
humaneval-HumanEval_22_filter_integers.json-L13 | js | //Filter given array of any jsthon values only for integers
// >>> filter_integers(["a", 3.14, 5])
// [5]
// >>> filter_integers([1, 2, 3, "abc", {}, []])
// [1, 2, 3]
function filter_integers(values){
var result = [];
values.forEach(function(value){
if(typeof value === "number" && value % 1 === 0){
result.push(... | }
| return result; | const assert = require('node:assert');
function test() {
let candidate = filter_integers;
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([4, {}, [], 23.2, 9, "adasd"]),[4, 9]);
assert.deepEqual(candidate([3, "c", 3, 3, "a", "b"]),[3, 3, 3]);
}
test(); |
humaneval-HumanEval_69_search.json-L22 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given a non-empty array list of positive integers. Return the greatest integer that is greater than
// zero, and has a fre... | for (int i = 0; i < lst.size(); i++) {
long val = lst.get(i);
if (map.containsKey(val)) {
map.put(val, map.get(val) + 1);
} else {
map.put(val, (long)1);
}
if (map.get(val) >= val && val > max) {
max = va... | Long max = (long)-1; | }
public static void main(String[] args) {
assert(search((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)5l, (long)5l, (long)1l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)4l, (long)1l, (long)4l, (long)4l)))) == (4l));
assert(search((new Arra... |
humaneval-HumanEval_151_double_the_difference.json-L17 | js | //Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// >>> double_the_difference([1, 3, 2, 0])
// 10
// >>> double_the_difference([-1, -2, 0])
// 0
// >>> double_the_difference([9, -2])
// 81
// >>> double_the_difference([... | }
return sum;
}
| } | const assert = require('node:assert');
function test() {
let candidate = double_the_difference;
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([5.0, 4.0]),25);
assert.deepEqual(candidate([0.1, 0.2, 0.3]),0);
assert.deepEqual(candidate([-10.0, -20.0, -30.0]),0);
assert.deepEqual(candidate([-... |
humaneval-HumanEval_138_is_equal_to_sum_even.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// >>> isEqualToSum... | long minX = d;
long maxX = n / 4;
while (minX <= maxX) {
long x = (minX + maxX) / 2;
long y = n - 2 * x;
if (y % 2 == 1) {
y--;
}
if (2 * x + y < n) {
minX = x + 1;
} else if (2 * x + y > n) {... | } | }
public static void main(String[] args) {
assert(isEqualToSumEven((4l)) == (false));
assert(isEqualToSumEven((6l)) == (false));
assert(isEqualToSumEven((8l)) == (true));
assert(isEqualToSumEven((10l)) == (true));
assert(isEqualToSumEven((11l)) == (false));
assert(isEqualToSumEven((12l))... |
humaneval-HumanEval_102_choose_num.json-L21 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusi... | }
}
return chosen;
}
} | chosen = i; | }
public static void main(String[] args) {
assert(chooseNum((12l), (15l)) == (14l));
assert(chooseNum((13l), (12l)) == (-1l));
assert(chooseNum((33l), (12354l)) == (12354l));
assert(chooseNum((5234l), (5233l)) == (-1l));
assert(chooseNum((6l), (29l)) == (28l));
assert(chooseNum((27l), (1... |
humaneval-HumanEval_1_separate_paren_groups.json-L11 | js | //Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input stri... | if (paren_string[i] === '('){
count++;
group += paren_string[i];
} else if (paren_string[i] === ')'){
count--;
group += paren_string[i];
}
if (count === 0 && group){
groups.push(group);
group = '';
}
}
... | for (var i = 0; i < paren_string.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = separate_paren_groups;
assert.deepEqual(candidate("(()()) ((())) () ((())()())"),["(()())", "((()))", "()", "((())()())"]);
assert.deepEqual(candidate("() (()) ((())) (((())))"),["()", "(())", "((()))", "(((())))"]);
assert.deepEqual(can... |
humaneval-HumanEval_96_count_up_to.json-L26 | js | //Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// >>> count_up_to(5)
// [2, 3]
// >>> count_up_to(11)
// [2, 3, 5, 7]
// >>> count_up_to(0)
// []
// >>> count_up_to(20)
// [2, 3, 5, 7, 11, 13, 17, 19]
// >... | if (prime) output.push(i);
}
return output;
}
| } | const assert = require('node:assert');
function test() {
let candidate = count_up_to;
assert.deepEqual(candidate(5),[2, 3]);
assert.deepEqual(candidate(6),[2, 3, 5]);
assert.deepEqual(candidate(7),[2, 3, 5]);
assert.deepEqual(candidate(10),[2, 3, 5, 7]);
assert.deepEqual(candidate(0),[]);
assert.deepEqu... |
humaneval-HumanEval_30_get_positive.json-L11 | py | from typing import List
def get_positive(l: List[int]) -> List[int]:
"""Return only positive numbers in the list.
>>> get_positive([-1, 2, -4, 5, 6])
[2, 5, 6]
>>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
[5, 3, 2, 3, 9, 123, 1]
"""
p = [] | if i > 0:
p.append(i)
return p
| for i in l: | def check(candidate):
assert candidate([-1, -2, 4, 5, 6]) == [4, 5, 6]
assert candidate([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 3, 9, 123, 1]
assert candidate([-1, -2]) == []
assert candidate([]) == []
def test_check():
check(get_positive)
test_check()
|
humaneval-HumanEval_8_sum_product.json-L8 | js | //For a given array of integers, return an array consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// >>> sum_product([])
// [0, 1]
// >>> sum_product([1, 2, 3, 4])
// [10, 24]
function sum_product(numbers){
| return [0, 1];
}
let sum = 0;
let product = 1;
for(let i = 0; i < numbers.length; i++){
sum += numbers[i];
product *= numbers[i];
}
return [sum, product];
}
| if(numbers.length == 0){ | const assert = require('node:assert');
function test() {
let candidate = sum_product;
assert.deepEqual(candidate([]),[0, 1]);
assert.deepEqual(candidate([1, 1, 1]),[3, 1]);
assert.deepEqual(candidate([100, 0]),[100, 0]);
assert.deepEqual(candidate([3, 5, 7]),[15, 105]);
assert.deepEqual(candidate([10]),[1... |
humaneval-HumanEval_148_bf.json-L26 | js | //There are eight planets in our solar system: the closerst to the Sun
// is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
// Uranus, Neptune.
// Write a function that takes two planet names as strings planet1 and planet2.
// The function should return an array containing all planets whose orbit... | }
if(!planets[planet1] || !planets[planet2]){
return [];
}
var keys = Object.keys(planets);
var position1 = keys.indexOf(planet1);
var position2 = keys.indexOf(planet2);
if(position1 > position2){
var temp = position1;
position1 = position2;
position2 = temp;
... | 'Neptune':8 | const assert = require('node:assert');
function test() {
let candidate = bf;
assert.deepEqual(candidate("Jupiter", "Neptune"),["Saturn", "Uranus"]);
assert.deepEqual(candidate("Earth", "Mercury"),["Venus"]);
assert.deepEqual(candidate("Mercury", "Uranus"),["Venus", "Earth", "Mars", "Jupiter", "Saturn"]);
as... |
humaneval-HumanEval_119_match_parens.json-L31 | js | //You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses... | const str2 = lst[1];
if (is_good(str1 + str2)){
return 'Yes';
}
if (is_good(str2 + str1)){
return 'Yes';
}
return 'No';
} | const str1 = lst[0]; | const assert = require('node:assert');
function test() {
let candidate = match_parens;
assert.deepEqual(candidate(["()(", ")"]),"Yes");
assert.deepEqual(candidate([")", ")"]),"No");
assert.deepEqual(candidate(["(()(())", "())())"]),"No");
assert.deepEqual(candidate([")())", "(()()("]),"Yes");
assert.deepE... |
humaneval-HumanEval_18_how_many_times.json-L16 | js | //Find how many times a given substring can be found in the original string. Count overlaping cases.
// >>> how_many_times("", "a")
// 0
// >>> how_many_times("aaa", "a")
// 3
// >>> how_many_times("aaaa", "aa")
// 3
function how_many_times(string, substring){
var i = 0;
var count = 0;
while(string.indexOf(substring... | } | const assert = require('node:assert');
function test() {
let candidate = how_many_times;
assert.deepEqual(candidate("", "x"),0);
assert.deepEqual(candidate("xyxyxyx", "x"),4);
assert.deepEqual(candidate("cacacacac", "cac"),4);
assert.deepEqual(candidate("john doe", "john"),1);
}
test(); | |
humaneval-HumanEval_66_digitSum.json-L27 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// ... | } | } | }
public static void main(String[] args) {
assert(digitSum(("")) == (0l));
assert(digitSum(("abAB")) == (131l));
assert(digitSum(("abcCd")) == (67l));
assert(digitSum(("helloE")) == (69l));
assert(digitSum(("woArBld")) == (131l));
assert(digitSum(("aAaaaXa")) == (153l));
assert(digit... |
humaneval-HumanEval_20_find_closest_elements.json-L10 | js | //From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])
// [2.0, 2.2]
// >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])
// [2.... | for (let i = 0; i < numbers.length; i++) {
for (let j = i + 1; j < numbers.length; j++) {
if (Math.abs(numbers[i] - numbers[j]) < closest) {
closest = Math.abs(numbers[i] - numbers[j]);
a = numbers[i];
b = numbers[j];
}
}
}
return a > b ? [b, a] : [a, b];
}
| let b = numbers[1]; | const assert = require('node:assert');
function test() {
let candidate = find_closest_elements;
assert.deepEqual(candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2]),[3.9, 4.0]);
assert.deepEqual(candidate([1.0, 2.0, 5.9, 4.0, 5.0]),[5.0, 5.9]);
assert.deepEqual(candidate([1.0, 2.0, 3.0, 4.0, 5.0, 2.2]),[2.0, 2.2]);
a... |
humaneval-HumanEval_129_minPath.json-L27 | js | //Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in e... | for(let i = 0; i < n; i++){
for(let j = 0; j < n; j++){
let curr = grid[i][j];
if(curr < startCell){
startCell = curr;
}
}
}
let currCell = startCell;
for(let l = 0; l < k; l++){
path.push(currCell);
let neighbours = [];... | let startCell = grid[0][0]; | const assert = require('node:assert');
function test() {
let candidate = minPath;
assert.deepEqual(candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3),[1, 2, 1]);
assert.deepEqual(candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1),[1]);
assert.deepEqual(candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14... |
humaneval-HumanEval_63_fibfib.json-L36 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fib... | }
return memo[(int) n];
}
} | memo[i] = memo[i - 1] + memo[i - 2] + memo[i - 3]; | }
public static void main(String[] args) {
assert(fibfib((2l)) == (1l));
assert(fibfib((1l)) == (0l));
assert(fibfib((5l)) == (4l));
assert(fibfib((8l)) == (24l));
assert(fibfib((10l)) == (81l));
assert(fibfib((12l)) == (274l));
assert(fibfib((14l)) == (927l));
}
}
|
humaneval-HumanEval_143_words_in_sentence.json-L28 | js | //You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Ex... | }).join(' ');
} | return isPrime; | const assert = require('node:assert');
function test() {
let candidate = words_in_sentence;
assert.deepEqual(candidate("This is a test"),"is");
assert.deepEqual(candidate("lets go for swimming"),"go for");
assert.deepEqual(candidate("there is no place available here"),"there is no place");
assert.deepEqual(... |
humaneval-HumanEval_6_parse_nested_parens.json-L31 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group... | } | } | }
public static void main(String[] args) {
assert(parseNestedParens(("(()()) ((())) () ((())()())")).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)1l, (long)3l)))));
assert(parseNestedParens(("() (()) ((())) (((())))")).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, ... |
humaneval-HumanEval_64_vowels_count.json-L27 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
... | }
}
return sum;
}
} | sum++; | }
public static void main(String[] args) {
assert(vowelsCount(("abcde")) == (2l));
assert(vowelsCount(("Alone")) == (3l));
assert(vowelsCount(("key")) == (2l));
assert(vowelsCount(("bye")) == (1l));
assert(vowelsCount(("keY")) == (2l));
assert(vowelsCount(("bYe")) == (1l));
assert(vo... |
humaneval-HumanEval_22_filter_integers.json-L10 | py | from typing import List, Any
def filter_integers(values: List[Any]) -> List[int]:
""" Filter given list of any python values only for integers
>>> filter_integers(['a', 3.14, 5])
[5]
>>> filter_integers([1, 2, 3, 'abc', { }, []])
[1, 2, 3]
"""
| return [n for n in values if isinstance(n, int)] | def check(candidate):
assert candidate([]) == []
assert candidate([4, { }, [], 23.2, 9, 'adasd']) == [4, 9]
assert candidate([3, 'c', 3, 3, 'a', 'b']) == [3, 3, 3]
def test_check():
check(filter_integers)
test_check()
| |
humaneval-HumanEval_37_sort_even.json-L15 | py | from typing import List
def sort_even(l: List[int]) -> List[int]:
"""This function takes a list l and returns a list l' such that
l' is identical to l in the odd indicies, while its values at the even indicies are equal
to the values of the even indicies of l, but sorted.
>>> sort_even([1, 2, 3])
[... | temp.sort()
for i in range(0, len(l), 2):
l[i] = temp[i // 2]
return l | temp.append(l[i]) | def check(candidate):
assert candidate([1, 2, 3]) == [1, 2, 3]
assert candidate([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123]
assert candidate([5, 8, -12, 4, 23, 2, 3, 11, 12, -10]) == [-12, 8, 3, 4, 5, 2, 12, 11, 23, -10]
def test_check():
check(sort_even)
test_c... |
humaneval-HumanEval_111_histogram.json-L36 | js | //Given a string representing a space separated lowercase letters, return an object
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// >>> histogram("a b c")
// {"a": 1, "b": 1, "c": 1}
// >>> histogram("a ... | }
else if (count[key] === max){
result[key] = max;
}
}
return result;
}
| result[key] = max; | const assert = require('node:assert');
function test() {
let candidate = histogram;
assert.deepEqual(candidate("a b b a"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c a b"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c d g"),{"a": 1, "b": 1, "c": 1, "d": 1, "g": 1});
assert.deepEqual(candidat... |
humaneval-HumanEval_83_starts_one_ends.json-L15 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
public st... | String s = "" + i;
if (s.startsWith("1") || s.endsWith("1"))
count++;
}
return count;
}
} | for (long i = lower; i <= upper; i++) { | }
public static void main(String[] args) {
assert(startsOneEnds((1l)) == (1l));
assert(startsOneEnds((2l)) == (18l));
assert(startsOneEnds((3l)) == (180l));
assert(startsOneEnds((4l)) == (1800l));
assert(startsOneEnds((5l)) == (18000l));
}
}
|
humaneval-HumanEval_135_can_arrange.json-L15 | js | //Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// >>> can_arrange([1, 2, 4, 3, 5])
// 3
// >>> can_arrange([1,... | }else{
max = arr[i];
}
}
return res;
}
| res = i; | const assert = require('node:assert');
function test() {
let candidate = can_arrange;
assert.deepEqual(candidate([1, 2, 4, 3, 5]),3);
assert.deepEqual(candidate([1, 2, 4, 5]),-1);
assert.deepEqual(candidate([1, 4, 2, 5, 6, 7, 8, 9, 10]),2);
assert.deepEqual(candidate([4, 8, 5, 7, 3]),4);
assert.deepEqual(... |
humaneval-HumanEval_88_sort_array.json-L23 | py | from typing import List
def sort_array(array: List[int]) -> List[int]:
"""
Given an array of non-negative integers, return a copy of the given array after sorting,
you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
or sort it in descending order if... | return array | return sorted(array, reverse=True) if (array[0] + array[-1]) % 2 == 0 else sorted(array) | def check(candidate):
assert candidate([]) == []
assert candidate([5]) == [5]
assert candidate([2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
assert candidate([2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
assert candidate([2, 1]) == [1, 2]
assert candidate([15, 42, 87, 32, 11, 0]) == [0, 11, 15, 32... |
humaneval-HumanEval_4_mean_absolute_deviation.json-L18 | js | //For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])
//... | }
| return sum_abs_diff / numbers.length; | const assert = require('node:assert');
function test() {
let candidate = mean_absolute_deviation;
assert.deepEqual(candidate([1.0, 2.0]),0.5);
assert.deepEqual(candidate([1.0, 2.0, 3.0, 4.0]),1.0);
assert.deepEqual(candidate([1.0, 2.0, 3.0, 4.0, 5.0]),1.2);
}
test(); |
humaneval-HumanEval_114_minSubArraySum.json-L14 | py | from typing import List
def minSubArraySum(nums: List[int]) -> int:
"""
Given an array of integers nums, find the minimum sum of any non-empty sub-array
of nums.
Example
>>> minSubArraySum([2, 3, 4, 1, 2, 4])
1
>>> minSubArraySum([-1, -2, -3])
-6
"""
for i in range(1, len(nums))... | return min(nums)
| nums[i] = min(nums[i], nums[i] + nums[i - 1]) | def check(candidate):
assert candidate([2, 3, 4, 1, 2, 4]) == 1
assert candidate([-1, -2, -3]) == -6
assert candidate([-1, -2, -3, 2, -10]) == -14
assert candidate([-9999999999999999]) == -9999999999999999
assert candidate([0, 10, 20, 1000000]) == 0
assert candidate([-1, -2, -3, 10, -5]) == -6
... |
humaneval-HumanEval_105_by_length.json-L48 | js | //Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// >>> by_length([2, 1, 1, 4, 5, 8, 2, 3])
// ["Eight"... | }
else if(num == 9){
arr3.push("Nine");
}
}
return arr3;
} | arr3.push("Eight"); | const assert = require('node:assert');
function test() {
let candidate = by_length;
assert.deepEqual(candidate([2, 1, 1, 4, 5, 8, 2, 3]),["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]);
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([1, -1, 55]),["One"]);
assert.deepEqual(can... |
humaneval-HumanEval_108_count_nums.json-L32 | js | //Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// >>> count_nums([])
// 0
// >>> count_nums([-1, 11, -11])
// 1
// >... | return count;
} | } | const assert = require('node:assert');
function test() {
let candidate = count_nums;
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([-1, -2, 0]),0);
assert.deepEqual(candidate([1, 1, 2, -2, 3, 4, 5]),6);
assert.deepEqual(candidate([1, 6, 9, -6, 0, 1, 5]),5);
assert.deepEqual(candidate([1, 1... |
humaneval-HumanEval_81_numerical_letter_grade.json-L43 | js | //It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that ca... | else if (grades[i] > 2.0){
grades_array.push("C+");
}
else if (grades[i] > 1.7){
grades_array.push("C");
}
else if (grades[i] > 1.3){
grades_array.push("C-");
}
else if (grades[i] > 1.0){
grades_array.push("D+");
... | } | const assert = require('node:assert');
function test() {
let candidate = numerical_letter_grade;
assert.deepEqual(candidate([4.0, 3, 1.7, 2, 3.5]),["A+", "B", "C-", "C", "A-"]);
assert.deepEqual(candidate([1.2]),["D+"]);
assert.deepEqual(candidate([0.5]),["D-"]);
assert.deepEqual(candidate([0.0]),["E"]);
... |
humaneval-HumanEval_54_same_chars.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Check if two words have the same characters.
// >>> sameChars(("eabcdzzzz"), ("dddzzzzzzzddeddabc"))
// (true)
// >>> sameC... | } | } | }
public static void main(String[] args) {
assert(sameChars(("eabcdzzzz"), ("dddzzzzzzzddeddabc")) == (true));
assert(sameChars(("abcd"), ("dddddddabc")) == (true));
assert(sameChars(("dddddddabc"), ("abcd")) == (true));
assert(sameChars(("eabcd"), ("dddddddabc")) == (false));
assert(sameCha... |
humaneval-HumanEval_31_is_prime.json-L23 | js | //Return true if a given number is prime, and false otherwise.
// >>> is_prime(6)
// false
// >>> is_prime(101)
// true
// >>> is_prime(11)
// true
// >>> is_prime(13441)
// true
// >>> is_prime(61)
// true
// >>> is_prime(4)
// false
// >>> is_prime(1)
// false
function is_prime(n){
if (n==1) {
return fals... |
if (n%2==0) {
return false;
}
var limit = Math.sqrt(n);
for (var i = 3; i <= limit; i += 2) {
if (n%i==0) {
return false;
}
}
return true;
}
| } | const assert = require('node:assert');
function test() {
let candidate = is_prime;
assert.deepEqual(candidate(6),false);
assert.deepEqual(candidate(101),true);
assert.deepEqual(candidate(11),true);
assert.deepEqual(candidate(13441),true);
assert.deepEqual(candidate(61),true);
assert.deepEqual(candidate(... |
humaneval-HumanEval_158_find_max.json-L21 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that accepts an array array list of strings.
// The array list contains different words. Return the word with maxi... | Set<Character> uniqueCharacters = new HashSet<Character>();
for (char c : word.toCharArray()) {
uniqueCharacters.add(c);
}
wordsToUniqueCharacters.put(word, uniqueCharacters.size());
}
words.sort(new Comparator<String>() {
@Over... | for (String word : words) { | }
public static void main(String[] args) {
assert(findMax((new ArrayList<String>(Arrays.asList((String)"name", (String)"of", (String)"string")))).equals(("string")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"name", (String)"enam", (String)"game")))).equals(("enam")));
assert(find... |
humaneval-HumanEval_7_filter_by_substring.json-L9 | js | //Filter an input array of strings only for ones that contain given substring
// >>> filter_by_substring([], "a")
// []
// >>> filter_by_substring(["abc", "bacd", "cde", "array"], "a")
// ["abc", "bacd", "array"]
function filter_by_substring(strings, substring){
var filtered = [];
for(var i = 0; i < strings.len... | filtered.push(strings[i]);
}
}
return filtered;
} | if(strings[i].includes(substring)){ | const assert = require('node:assert');
function test() {
let candidate = filter_by_substring;
assert.deepEqual(candidate([], "john"),[]);
assert.deepEqual(candidate(["xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"], "xxx"),["xxx", "xxxAAA", "xxx"]);
assert.deepEqual(candidate(["xxx", "asd", "aaaxxy", "john d... |
humaneval-HumanEval_157_right_angle_triangle.json-L13 | js | //Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// >>> right_angle_triangle(3, 4, 5)
// true
// >>> right_angle_triangle(1, 2, 3... | return false;
}
}
| } else { | const assert = require('node:assert');
function test() {
let candidate = right_angle_triangle;
assert.deepEqual(candidate(3, 4, 5),true);
assert.deepEqual(candidate(1, 2, 3),false);
assert.deepEqual(candidate(10, 6, 8),true);
assert.deepEqual(candidate(2, 2, 2),false);
assert.deepEqual(candidate(7, 24, 25... |
humaneval-HumanEval_105_by_length.json-L40 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array array l... | } | } | }
public static void main(String[] args) {
assert(byLength((new ArrayList<Long>(Arrays.asList((long)2l, (long)1l, (long)1l, (long)4l, (long)5l, (long)8l, (long)2l, (long)3l)))).equals((new ArrayList<String>(Arrays.asList((String)"Eight", (String)"Five", (String)"Four", (String)"Three", (String)"Two", (Strin... |
humaneval-HumanEval_88_sort_array.json-L18 | js | //Given an array of non-negative integers, return a cojs of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change t... | newArr = array.sort(function(a, b){return b - a;});
}else{
newArr = array.sort(function(a, b){return a - b;});
}
return newArr;
} | if(sum % 2 === 0){ | const assert = require('node:assert');
function test() {
let candidate = sort_array;
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([5]),[5]);
assert.deepEqual(candidate([2, 4, 3, 0, 1, 5]),[0, 1, 2, 3, 4, 5]);
assert.deepEqual(candidate([2, 4, 3, 0, 1, 5, 6]),[6, 5, 4, 3, 2, 1, 0]);
asser... |
humaneval-HumanEval_123_get_odd_collatz.json-L19 | js | //Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous ... | if(collatz_sequence[i]%2 == 0){
collatz_sequence.push(collatz_sequence[i]/2)
}
else if(collatz_sequence[i]%2 == 1){
collatz_sequence.push(collatz_sequence[i]*3+1)
}
if(collatz_sequence[i]%2 == 1){
odd_numbers.push(collatz_sequence[i])
... | for(var i = 0; i < collatz_sequence.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = get_odd_collatz;
assert.deepEqual(candidate(14),[1, 5, 7, 11, 13, 17]);
assert.deepEqual(candidate(5),[1, 5]);
assert.deepEqual(candidate(12),[1, 3, 5]);
assert.deepEqual(candidate(1),[1]);
}
test(); |
humaneval-HumanEval_1_separate_paren_groups.json-L26 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into s... | } else if (c == ')') {
open_paren--;
temp.append(c);
if (open_paren == 0) {
output.add(temp.toString());
}
}
}
return output;
}
} | temp.append(c); | }
public static void main(String[] args) {
assert(separateParenGroups(("(()()) ((())) () ((())()())")).equals((new ArrayList<String>(Arrays.asList((String)"(()())", (String)"((()))", (String)"()", (String)"((())()())")))));
assert(separateParenGroups(("() (()) ((())) (((())))")).equals((new ArrayList<St... |
humaneval-HumanEval_19_sort_numbers.json-L17 | js | //Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// >>> sort_numbers("three one five")
// "one three five"
function sort_number... | "nine": 9
};
numString.sort(function(a, b){
return numMap[a] - numMap[b];
});
numString = numString.join(" ");
return numString;
} | "eight": 8, | const assert = require('node:assert');
function test() {
let candidate = sort_numbers;
assert.deepEqual(candidate(""),"");
assert.deepEqual(candidate("three"),"three");
assert.deepEqual(candidate("three five nine"),"three five nine");
assert.deepEqual(candidate("five zero four seven nine eight"),"zero four ... |
humaneval-HumanEval_5_intersperse.json-L20 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Insert a number 'delimeter' between every two consecutive elements of input array list `numbers'
// >>> intersperse((new ArrayList<... | }
return result;
}
} | } | }
public static void main(String[] args) {
assert(intersperse((new ArrayList<Long>(Arrays.asList())), (7l)).equals((new ArrayList<Long>(Arrays.asList()))));
assert(intersperse((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)2l))), (8l)).equals((new ArrayList<Long>(Arrays.asList((l... |
humaneval-HumanEval_123_get_odd_collatz.json-L23 | js | //Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous ... | collatz_sequence.push(collatz_sequence[i]*3+1)
}
if(collatz_sequence[i]%2 == 1){
odd_numbers.push(collatz_sequence[i])
odd_count += 1
}
if(collatz_sequence[i] == 1){
break
}
}
if(odd_count != 0){
odd_numbers.sort(fun... | else if(collatz_sequence[i]%2 == 1){ | const assert = require('node:assert');
function test() {
let candidate = get_odd_collatz;
assert.deepEqual(candidate(14),[1, 5, 7, 11, 13, 17]);
assert.deepEqual(candidate(5),[1, 5]);
assert.deepEqual(candidate(12),[1, 3, 5]);
assert.deepEqual(candidate(1),[1]);
}
test(); |
humaneval-HumanEval_90_next_smallest.json-L15 | js | //You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return undefined if there is no such element.
// >>> next_smallest([1, 2, 3, 4, 5])
// 2
// >>> next_smallest([5, 1, 4, 3, 2])
// 2
// >>> next_smallest([])
// undefined
// >>> next_smallest(... | var smallest=Math.min(...lst);
var second_smallest=Number.MAX_VALUE;
for(var i in lst){
if(lst[i]>smallest&&lst[i]<second_smallest){
second_smallest=lst[i];
}
}
if(second_smallest==Number.MAX_VALUE){
return undefined;
}
return second_smallest;
} | } | const assert = require('node:assert');
function test() {
let candidate = next_smallest;
assert.deepEqual(candidate([1, 2, 3, 4, 5]),2);
assert.deepEqual(candidate([5, 1, 4, 3, 2]),2);
assert.deepEqual(candidate([]),undefined);
assert.deepEqual(candidate([1, 1]),undefined);
assert.deepEqual(candidate([1, 1... |
humaneval-HumanEval_160_do_algebra.json-L66 | js | //Given two arrays operator, and operand. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
... | }
| return answer; | const assert = require('node:assert');
function test() {
let candidate = do_algebra;
assert.deepEqual(candidate(["**", "*", "+"], [2, 3, 4, 5]),37);
assert.deepEqual(candidate(["+", "*", "-"], [2, 3, 4, 5]),9);
assert.deepEqual(candidate(["//", "*"], [7, 3, 4]),8);
}
test(); |
humaneval-HumanEval_106_f.json-L26 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Implement the function f that takes n as a parameter,
// and returns an array array list of size n, such that the value of the elem... | v = (i * (i + 1l)) / 2l;
}
ret.add(v);
}
return ret;
}
} | } else { | }
public static void main(String[] args) {
assert(f((5l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l)))));
assert(f((7l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l, (long)720l, (long)28l)))));
assert... |
humaneval-HumanEval_104_unique_digits.json-L37 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of positive integers x. return a sorted array list of all
// elements that hasn't any even digit.
//... | return b;
}
} | Collections.sort(b); | }
public static void main(String[] args) {
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)15l, (long)33l, (long)1422l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)15l, (long)33l)))));
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)152l, (long)323l, ... |
humaneval-HumanEval_124_valid_date.json-L34 | js | //You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12... | return true;
}
return false;
}
| } | const assert = require('node:assert');
function test() {
let candidate = valid_date;
assert.deepEqual(candidate("03-11-2000"),true);
assert.deepEqual(candidate("15-01-2012"),false);
assert.deepEqual(candidate("04-0-2040"),false);
assert.deepEqual(candidate("06-04-2020"),true);
assert.deepEqual(candidate("... |
humaneval-HumanEval_77_iscube.json-L22 | js | //Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// >>> iscube(1)
// true
// >>> iscube(2)
// false
// >>> iscube(-1)
// true
// >>> iscube(64)
// true
// >>> iscube(0)
// true
// >>> iscube(... | } | } | const assert = require('node:assert');
function test() {
let candidate = iscube;
assert.deepEqual(candidate(1),true);
assert.deepEqual(candidate(2),false);
assert.deepEqual(candidate(-1),true);
assert.deepEqual(candidate(64),true);
assert.deepEqual(candidate(180),false);
assert.deepEqual(candidate(1000)... |
humaneval-HumanEval_154_cycpattern_check.json-L17 | js | //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
// >>> cycpattern_check("abcd", "abd")
// false
// >>> cycpattern_check("hello", "ell")
// true
// >>> cycpattern_check("whassup", "psus")
// false
// >>> cycpattern_check("abab", "baa")
// true
... | b = b.slice(1) + b[0];
}
return result;
}
| result = result || a.includes(b); | const assert = require('node:assert');
function test() {
let candidate = cycpattern_check;
assert.deepEqual(candidate("xyzw", "xyw"),false);
assert.deepEqual(candidate("yello", "ell"),true);
assert.deepEqual(candidate("whattup", "ptut"),false);
assert.deepEqual(candidate("efef", "fee"),true);
assert.deepE... |
humaneval-HumanEval_161_solve.json-L26 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as ... | letterNotFound = false;
if (Character.isUpperCase(s.charAt(i))) {
sb.append(Character.toLowerCase(s.charAt(i)));
} else {
sb.append(Character.toUpperCase(s.charAt(i)));
}
} else {
sb.appen... | if (Character.isLetter(s.charAt(i))) { | }
public static void main(String[] args) {
assert(solve(("AsDf")).equals(("aSdF")));
assert(solve(("1234")).equals(("4321")));
assert(solve(("ab")).equals(("AB")));
assert(solve(("#a@C")).equals(("#A@c")));
assert(solve(("#AsdfW^45")).equals(("#aSDFw^45")));
assert(solve(("#6@2")).equals... |
humaneval-HumanEval_40_triples_sum_to_zero.json-L20 | py | from typing import List
def triples_sum_to_zero(l: List[int]) -> bool:
"""
triples_sum_to_zero takes a list of integers as an input.
it returns True if there are three distinct elements in the list that
sum to zero, and False otherwise.
>>> triples_sum_to_zero([1, 3, 5, 0])
False
>>> tripl... | l.sort()
for i in range(len(l)):
for j in range(i + 1, len(l)):
for k in range(j + 1, len(l)):
if l[i] + l[j] + l[k] == 0:
return True
return False
| assert len(l) > 0, "The input list cannot be empty" | def check(candidate):
assert candidate([1, 3, 5, 0]) == False
assert candidate([1, 3, 5, -1]) == False
assert candidate([1, 3, -2, 1]) == True
assert candidate([1, 2, 3, 7]) == False
assert candidate([1, 2, 5, 7]) == False
assert candidate([2, 4, -5, 3, 9, 7]) == True
assert candidate([1]) =... |
humaneval-HumanEval_14_all_prefixes.json-L9 | js | //Return array of all prefixes from shortest to longest of the input string
// >>> all_prefixes("abc")
// ["a", "ab", "abc"]
function all_prefixes(string){
var result = [];
for (var i = 1; i <= string.length; i++){
result.push(string.slice(0, i));
} | }
| return result; | const assert = require('node:assert');
function test() {
let candidate = all_prefixes;
assert.deepEqual(candidate(""),[]);
assert.deepEqual(candidate("asdfgh"),["a", "as", "asd", "asdf", "asdfg", "asdfgh"]);
assert.deepEqual(candidate("WWW"),["W", "WW", "WWW"]);
}
test(); |
humaneval-HumanEval_106_f.json-L23 | js | //Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... | result.push(sum);
sum = 0;
}
}
return result;
} | } | const assert = require('node:assert');
function test() {
let candidate = f;
assert.deepEqual(candidate(5),[1, 2, 6, 24, 15]);
assert.deepEqual(candidate(7),[1, 2, 6, 24, 15, 720, 28]);
assert.deepEqual(candidate(1),[1]);
assert.deepEqual(candidate(3),[1, 2, 6]);
}
test(); |
humaneval-HumanEval_1_separate_paren_groups.json-L13 | py | from typing import List
def separate_paren_groups(paren_string: str) -> List[str]:
""" Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
separate those group into separate strings and return the list of those.
Separate groups are balanced (each open brace ... | open_count = 0
for c in paren_string:
if c == '(':
open_count += 1
elif c == ')':
open_count -= 1
group += c
if open_count == 0:
groups.append(group)
group = ''
return groups
| group = '' | def check(candidate):
assert candidate('(()()) ((())) () ((())()())') == ['(()())', '((()))', '()', '((())()())']
assert candidate('() (()) ((())) (((())))') == ['()', '(())', '((()))', '(((())))']
assert candidate('(()(())((())))') == ['(()(())((())))']
assert candidate('( ) (( )) (( )( ))') == ['()', ... |
humaneval-HumanEval_1_separate_paren_groups.json-L30 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into s... | output.add(temp.toString());
}
}
}
return output;
}
} | if (open_paren == 0) { | }
public static void main(String[] args) {
assert(separateParenGroups(("(()()) ((())) () ((())()())")).equals((new ArrayList<String>(Arrays.asList((String)"(()())", (String)"((()))", (String)"()", (String)"((())()())")))));
assert(separateParenGroups(("() (()) ((())) (((())))")).equals((new ArrayList<St... |
humaneval-HumanEval_109_move_one_ball.json-L33 | js | //We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift o... | else{
return true;
}
} | } | const assert = require('node:assert');
function test() {
let candidate = move_one_ball;
assert.deepEqual(candidate([3, 4, 5, 1, 2]),true);
assert.deepEqual(candidate([3, 5, 10, 1, 2]),true);
assert.deepEqual(candidate([4, 3, 1, 2]),false);
assert.deepEqual(candidate([3, 5, 4, 1, 2]),false);
assert.deepEqu... |
humaneval-HumanEval_113_odd_count.json-L11 | js | //Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// >>> odd_count(["1234567... | var word = lst[i];
var odd_sum = 0;
for (var j = 0; j < word.length; j++){
if (word[j] % 2 == 1){
odd_sum += 1;
}
}
var odd_word = "the number of odd elements " + odd_sum + "n the str" + odd_sum + "ng " + odd_sum + " of the " + odd_sum + "n... | for (var i = 0; i < lst.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = odd_count;
assert.deepEqual(candidate(["1234567"]),["the number of odd elements 4n the str4ng 4 of the 4nput."]);
assert.deepEqual(candidate(["3", "11111111"]),["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd... |
humaneval-HumanEval_96_count_up_to.json-L34 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Implement a function that takes an non-negative integer and returns an array array list of the first n
// integers that are prime n... | arrayList.add(i);
}
}
return arrayList;
}
} | if (isPrime) { | }
public static void main(String[] args) {
assert(countUpTo((5l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l)))));
assert(countUpTo((6l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)5l)))));
assert(countUpTo((7l)).equals((new ArrayList<Long>(Arrays.asList((l... |
humaneval-HumanEval_105_by_length.json-L14 | js | //Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// >>> by_length([2, 1, 1, 4, 5, 8, 2, 3])
// ["Eight"... | for(var i = 0; i < arr.length; i++){
var num = arr[i];
if(num > 0 && num < 10){
arr2.push(num);
}
}
arr2.sort();
arr2.reverse();
var arr3 = [];
for(var i = 0; i < arr2.length; i++){
var num = arr2[i];
if(num == 1){
arr3.push("One");... | var arr2 = []; | const assert = require('node:assert');
function test() {
let candidate = by_length;
assert.deepEqual(candidate([2, 1, 1, 4, 5, 8, 2, 3]),["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]);
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([1, -1, 55]),["One"]);
assert.deepEqual(can... |
humaneval-HumanEval_81_numerical_letter_grade.json-L46 | js | //It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that ca... | else if (grades[i] > 1.7){
grades_array.push("C");
}
else if (grades[i] > 1.3){
grades_array.push("C-");
}
else if (grades[i] > 1.0){
grades_array.push("D+");
}
else if (grades[i] > 0.7){
grades_array.push("D");
... | } | const assert = require('node:assert');
function test() {
let candidate = numerical_letter_grade;
assert.deepEqual(candidate([4.0, 3, 1.7, 2, 3.5]),["A+", "B", "C-", "C", "A-"]);
assert.deepEqual(candidate([1.2]),["D+"]);
assert.deepEqual(candidate([0.5]),["D-"]);
assert.deepEqual(candidate([0.0]),["E"]);
... |
humaneval-HumanEval_122_add_elements.json-L20 | py | from typing import List
def add_elements(arr: List[int], k: int) -> int:
"""
Given a non-empty array of integers arr and an integer k, return
the sum of the elements with at most two digits from the first k elements of arr.
Example:
>>> add_elements([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4)
24
... | return total
| total += num | def check(candidate):
assert candidate([1, -2, -3, 41, 57, 76, 87, 88, 99], 3) == -4
assert candidate([111, 121, 3, 4000, 5, 6], 2) == 0
assert candidate([11, 21, 3, 90, 5, 6, 7, 8, 9], 4) == 125
assert candidate([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4) == 24
assert candidate([1], 1) == 1
def test_che... |
humaneval-HumanEval_151_double_the_difference.json-L18 | js | //Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// >>> double_the_difference([1, 3, 2, 0])
// 10
// >>> double_the_difference([-1, -2, 0])
// 0
// >>> double_the_difference([9, -2])
// 81
// >>> double_the_difference([... | return sum;
}
| } | const assert = require('node:assert');
function test() {
let candidate = double_the_difference;
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([5.0, 4.0]),25);
assert.deepEqual(candidate([0.1, 0.2, 0.3]),0);
assert.deepEqual(candidate([-10.0, -20.0, -30.0]),0);
assert.deepEqual(candidate([-... |
humaneval-HumanEval_86_anti_shuffle.json-L16 | js | //Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank sp... | var temp = str.split("");
temp.sort();
result.push(temp.join(""));
});
return result.join(" ");
} | strings.forEach(function(str){ | const assert = require('node:assert');
function test() {
let candidate = anti_shuffle;
assert.deepEqual(candidate("Hi"),"Hi");
assert.deepEqual(candidate("hello"),"ehllo");
assert.deepEqual(candidate("number"),"bemnru");
assert.deepEqual(candidate("abcd"),"abcd");
assert.deepEqual(candidate("Hello World!!... |
humaneval-HumanEval_70_strange_sort_list.json-L30 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given array list of integers, return array list in strange order.
// Strange sorting, is when you start with the minimum value,
... | if (min <= max) {
result.add(sorted.get(max));
max--;
}
}
return result;
}
} | min++; | }
public static void main(String[] args) {
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)2l, (long)3l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)5l, (long... |
humaneval-HumanEval_21_rescale_to_unit.json-L12 | py | from typing import List
def rescale_to_unit(numbers: List[float]) -> List[float]:
""" Given list of numbers (of at least two elements), apply a linear transform to that list,
such that the smallest number will become 0 and the largest will become 1
>>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0])
[0.0, 0... | return [(val - _min) / (_max - _min) for val in numbers] | def check(candidate):
assert candidate([2.0, 49.9]) == [0.0, 1.0]
assert candidate([100.0, 49.9]) == [1.0, 0.0]
assert candidate([1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
assert candidate([2.0, 1.0, 5.0, 3.0, 4.0]) == [0.25, 0.0, 1.0, 0.5, 0.75]
assert candidate([12.0, 11.0, 15.0, 13... | |
humaneval-HumanEval_5_intersperse.json-L15 | js | //Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// >>> intersperse([], 4)
// []
// >>> intersperse([1, 2, 3], 4)
// [1, 4, 2, 4, 3]
function intersperse(numbers, delimeter){
var result = [];
for(var i = 0; i < numbers.length; i++){
result.push(numbers[i]);
if(i ... | } | const assert = require('node:assert');
function test() {
let candidate = intersperse;
assert.deepEqual(candidate([], 7),[]);
assert.deepEqual(candidate([5, 6, 3, 2], 8),[5, 8, 6, 8, 3, 8, 2]);
assert.deepEqual(candidate([2, 2, 2], 2),[2, 2, 2, 2, 2]);
}
test(); | |
humaneval-HumanEval_96_count_up_to.json-L38 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Implement a function that takes an non-negative integer and returns an array array list of the first n
// integers that are prime n... | }
} | return arrayList; | }
public static void main(String[] args) {
assert(countUpTo((5l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l)))));
assert(countUpTo((6l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)5l)))));
assert(countUpTo((7l)).equals((new ArrayList<Long>(Arrays.asList((l... |
humaneval-HumanEval_51_remove_vowels.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// remove_vowels is a function that takes string and returns string without vowels.
// >>> removeVowels((""))
// ("")
// >>> r... | newText += text.charAt(i);
}
}
return newText;
}
} | if (vowels.indexOf(text.charAt(i)) == -1) { | }
public static void main(String[] args) {
assert(removeVowels(("")).equals(("")));
assert(removeVowels(("abcdef\nghijklm")).equals(("bcdf\nghjklm")));
assert(removeVowels(("fedcba")).equals(("fdcb")));
assert(removeVowels(("eeeee")).equals(("")));
assert(removeVowels(("acBAA")).equals(("cB"... |
humaneval-HumanEval_102_choose_num.json-L16 | js | //This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// >>> choose_num(12, 15)
// 14
// >>> choose_num(13, 12)
// -1
function choose_num(x, y){
var num ... | }
| return num; | const assert = require('node:assert');
function test() {
let candidate = choose_num;
assert.deepEqual(candidate(12, 15),14);
assert.deepEqual(candidate(13, 12),-1);
assert.deepEqual(candidate(33, 12354),12354);
assert.deepEqual(candidate(5234, 5233),-1);
assert.deepEqual(candidate(6, 29),28);
assert.dee... |
humaneval-HumanEval_64_vowels_count.json-L22 | py | def vowels_count(s: str) -> int:
"""Write a function vowels_count which takes a string representing
a word as input and returns the number of vowels in the string.
Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
vowel, but only when it is at the end of the given word.
Example:
... | return count | def check(candidate):
assert candidate('abcde') == 2
assert candidate('Alone') == 3
assert candidate('key') == 2
assert candidate('bye') == 1
assert candidate('keY') == 2
assert candidate('bYe') == 1
assert candidate('ACEDY') == 3
def test_check():
check(vowels_count)
test_check()
| |
humaneval-HumanEval_64_vowels_count.json-L15 | js | //Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// >>> vowels_count("abcde")
// 2
// >>> vo... | count++;
}
}
if(s[s.length-1]=='y'){
count++;
}
return count;
}
| if(vowels.indexOf(s[i])!=-1){ | const assert = require('node:assert');
function test() {
let candidate = vowels_count;
assert.deepEqual(candidate("abcde"),2);
assert.deepEqual(candidate("Alone"),3);
assert.deepEqual(candidate("key"),2);
assert.deepEqual(candidate("bye"),1);
assert.deepEqual(candidate("keY"),2);
assert.deepEqual(candid... |
humaneval-HumanEval_39_prime_fib.json-L26 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// >>> primeFib((1l))
// (2l)
// >>> primeFib... | prev = tmp;
if (BigInteger.valueOf(fib).isProbablePrime(1)) {
count++;
}
}
return fib;
}
} | fib += prev; | }
public static void main(String[] args) {
assert(primeFib((1l)) == (2l));
assert(primeFib((2l)) == (3l));
assert(primeFib((3l)) == (5l));
assert(primeFib((4l)) == (13l));
assert(primeFib((5l)) == (89l));
assert(primeFib((6l)) == (233l));
assert(primeFib((7l)) == (1597l));
assert... |
humaneval-HumanEval_127_intersection.json-L27 | js | //You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Y... | return primes.includes(length) ? "YES" : "NO";
}
| let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]; | const assert = require('node:assert');
function test() {
let candidate = intersection;
assert.deepEqual(candidate([1, 2], [2, 3]),"NO");
assert.deepEqual(candidate([-1, 1], [0, 4]),"NO");
assert.deepEqual(candidate([-3, -1], [-5, 5]),"YES");
assert.deepEqual(candidate([-2, 2], [-4, 0]),"YES");
assert.deep... |
humaneval-HumanEval_4_mean_absolute_deviation.json-L18 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// For a given array list of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute... | }
} | return (float)numbers.stream().mapToDouble(n -> Math.abs(n - mean)).average().getAsDouble(); | }
public static void main(String[] args) {
assert(meanAbsoluteDeviation((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f)))) == (0.5f));
assert(meanAbsoluteDeviation((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f, (float)4.0f)))) == (1.0f));
assert(meanAbsolute... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.