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_69_search.json-L32 | 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... | }
return max;
}
} | } | }
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_120_maximum.json-L34 | py | from typing import List
def maximum(arr: List[int], k: int) -> List[int]:
"""
Given an array arr of integers and a positive integer k, return a sorted list
of length k with the maximum k numbers in arr.
Example 1:
>>> maximum([-3, -4, 5], 3)
[-4, -3, 5]
Example 2:
>>> maximum([4, -... | return [max(arr)]
else:
max_num = max(arr)
arr.remove(max_num)
return [max_num] + get_max(arr, k - 1)
return sorted(get_max(arr, k))
| elif k == 1: | def check(candidate):
assert candidate([-3, -4, 5], 3) == [-4, -3, 5]
assert candidate([4, -4, 4], 2) == [4, 4]
assert candidate([-3, 2, 1, 2, -1, -2, 1], 1) == [2]
assert candidate([123, -123, 20, 0, 1, 2, -3], 3) == [2, 20, 123]
assert candidate([-123, 20, 0, 1, 2, -3], 4) == [0, 1, 2, 20]
ass... |
humaneval-HumanEval_135_can_arrange.json-L17 | 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,... | }
}
return res;
}
| max = arr[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_111_histogram.json-L26 | py | from typing import Dict
def histogram(test: str) -> Dict[str, int]:
"""Given a string representing a space separated lowercase letters, return a dictionary
of the letter with the most repetition and containing the corresponding count.
If several letters have the same occurrence, return all of them.
... | most_count = letters[letter]
for letter in letters:
if letters[letter] == most_count:
result[letter] = most_count
return result
| if letters[letter] >= most_count: | def check(candidate):
assert candidate('a b b a') == { 'a': 2, 'b': 2 }
assert candidate('a b c a b') == { 'a': 2, 'b': 2 }
assert candidate('a b c d g') == { 'a': 1, 'b': 1, 'c': 1, 'd': 1, 'g': 1 }
assert candidate('r t g') == { 'r': 1, 't': 1, 'g': 1 }
assert candidate('b b b b a') == { 'b': 4 }
... |
humaneval-HumanEval_114_minSubArraySum.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 {
// Given an array array list of integers nums, find the minimum sum of any non-empty sub-array array list
// of nums.
// Example
... | } | } | }
public static void main(String[] args) {
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l, (long)1l, (long)2l, (long)4l)))) == (1l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l)))) == (-6l));
assert(minSubArraySum((... |
humaneval-HumanEval_149_sorted_list_sum.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 that accepts an array array list of strings as a parameter,
// deletes the strings that have odd lengths from it,
... | result.add(s);
}
}
Collections.sort(result, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
if (s1.length() == s2.length()) {
return s1.compareTo(s2);
}
... | if (s.length() % 2 == 0) { | }
public static void main(String[] args) {
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"aa", (String)"a", (String)"aaa")))).equals((new ArrayList<String>(Arrays.asList((String)"aa")))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"school", (String)"AI", (Stri... |
humaneval-HumanEval_128_prod_signs.json-L34 | py | from typing import List, Optional
def prod_signs(arr: List[int]) -> Optional[int]:
"""
You are given an array arr of integers and you need to return
sum of magnitudes of integers multiplied by product of all signs
of each number in the array, represented by 1, -1 or 0.
Note: return None for empty a... | return sum(map(abs, arr)) * product(sign_arr) | sign_arr.append(0) | def check(candidate):
assert candidate([1, 2, 2, -4]) == -9
assert candidate([0, 1]) == 0
assert candidate([1, 1, 1, 2, 3, -1, 1]) == -10
assert candidate([]) == None
assert candidate([2, 4, 1, 2, -1, -1, 9]) == 20
assert candidate([-1, 1, -1, 1]) == 4
assert candidate([-1, 1, 1, 1]) == -4
... |
humaneval-HumanEval_160_do_algebra.json-L42 | 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 ( - )
... | operator.splice(count, 1);
count = 0;
do_again = true;
break;
default:
count++;
do_again = false;
}
}
answer = operand[0];
operand.splice(0, 1);
while(operand.length > 0){
switch(operator[0]){
case '+':
answer += operand[0];
bre... | operand.splice(count + 1, 1); | 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_154_cycpattern_check.json-L20 | py | def cycpattern_check(a: str, b: str) -> bool:
"""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')
... | return False
| b = b[1:] + b[0] | def check(candidate):
assert candidate('xyzw', 'xyw') == False
assert candidate('yello', 'ell') == True
assert candidate('whattup', 'ptut') == False
assert candidate('efef', 'fee') == True
assert candidate('abab', 'aabb') == False
assert candidate('winemtt', 'tinem') == True
def test_check():
... |
humaneval-HumanEval_75_is_multiply_prime.json-L11 | js | //Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// >>> is_multiply_prime(30)
// true
// 30 = 2 * 3 * 5
function is_multiply_prime(a){
a = Math.abs(a);
const prime = [2, 3, 5, 7, 11, 13, 1... | let check = [];
while(a != 1){
if(a % prime[i] == 0){
a = a / prime[i];
check.push(prime[i]);
}else{
i++;
}
}
if(check.length == 3){
return true;
}else{
return false;
}
} | let i = 0; | const assert = require('node:assert');
function test() {
let candidate = is_multiply_prime;
assert.deepEqual(candidate(5),false);
assert.deepEqual(candidate(30),true);
assert.deepEqual(candidate(8),true);
assert.deepEqual(candidate(10),false);
assert.deepEqual(candidate(125),true);
assert.deepEqual(cand... |
humaneval-HumanEval_27_flip_case.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 string, flip lowercase characters to uppercase and uppercase to lowercase.
// >>> flipCase(("Hello"))
// ("hELLO")
... | }
return answer;
}
} | } | }
public static void main(String[] args) {
assert(flipCase(("")).equals(("")));
assert(flipCase(("Hello!")).equals(("hELLO!")));
assert(flipCase(("These violent delights have violent ends")).equals(("tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS")));
}
}
|
humaneval-HumanEval_137_compare_one.json-L40 | js | //Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return undefined if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// >>> compare_one(1, 2.5)
// 2.5
//... | }
| } | const assert = require('node:assert');
function test() {
let candidate = compare_one;
assert.deepEqual(candidate(1, 2),2);
assert.deepEqual(candidate(1, 2.5),2.5);
assert.deepEqual(candidate(2, 3),3);
assert.deepEqual(candidate(5, 6),6);
assert.deepEqual(candidate(1, "2,3"),"2,3");
assert.deepEqual(cand... |
humaneval-HumanEval_156_int_to_mini_roman.json-L37 | js | //Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// >>> int_to_mini_roman(19)
// "xix"
// >>> int_to_mini_roman(152)
// "clii"
// >>> int_to_mini_roman(426)
// "cdxxvi"
function int_to_mini_roman(number){
var r... | }
return output;
}
| } | const assert = require('node:assert');
function test() {
let candidate = int_to_mini_roman;
assert.deepEqual(candidate(19),"xix");
assert.deepEqual(candidate(152),"clii");
assert.deepEqual(candidate(251),"ccli");
assert.deepEqual(candidate(426),"cdxxvi");
assert.deepEqual(candidate(500),"d");
assert.dee... |
humaneval-HumanEval_94_skjkasdkd.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 {
// You are given an array array list of integers.
// You need to find the largest prime value and return the sum of its digits.
//... | if (item == 2) {
counter = 1;
}
else {
int l = 1;
while (l <= (int) number) {
if (number % l == 0) {
counter++;
}
l++;
}
}
... | } | }
public static void main(String[] args) {
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l, (long)2l, (long)1l, (long)3l, (long)5l, (long)7l, (long)4l, (long)5l, (long)5l, (long)5l, (long)2l, (long)181l, (long)32l, (long)4l, (long)32l, (long)3l, (long)2l, (long)32l, (long)324l, (long)... |
humaneval-HumanEval_138_is_equal_to_sum_even.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 {
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// >>> isEqualToSum... | return false;
}
long d = 2;
if (n % 2 == 1) {
d = 1;
}
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 (n < 4) { | }
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_27_flip_case.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 string, flip lowercase characters to uppercase and uppercase to lowercase.
// >>> flipCase(("Hello"))
// ("hELLO")
... | }
}
return answer;
}
} | answer += Character.toLowerCase(string.charAt(i)); | }
public static void main(String[] args) {
assert(flipCase(("")).equals(("")));
assert(flipCase(("Hello!")).equals(("hELLO!")));
assert(flipCase(("These violent delights have violent ends")).equals(("tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS")));
}
}
|
humaneval-HumanEval_43_pairs_sum_to_zero.json-L16 | js | //pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// >>> pairs_sum_to_zero([1, 3, 5, 0])
// false
// >>> pairs_sum_to_zero([1, 3, -2, 1])
// false
// >>> pairs_sum_to_zero([1, 2, 3, 7])
// false
// >>>... | var j = i+1
while (j < l.length){
if ((l[i] + l[j]) === 0){
return true
}
j = j + 1
}
i = i + 1
}
return false
}
| while (i < l.length){ | const assert = require('node:assert');
function test() {
let candidate = pairs_sum_to_zero;
assert.deepEqual(candidate([1, 3, 5, 0]),false);
assert.deepEqual(candidate([1, 3, -2, 1]),false);
assert.deepEqual(candidate([1, 2, 3, 7]),false);
assert.deepEqual(candidate([2, 4, -5, 3, 5, 7]),true);
assert.deep... |
humaneval-HumanEval_56_correct_bracketing.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 {
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correc... | for (int i = 0; i < brackets.length(); i++) {
char c = brackets.charAt(i);
if (c == '<') {
open++;
} else {
open--;
}
if (open < 0) {
return false;
}
}
return open == 0;
}
... | int open = 0; | }
public static void main(String[] args) {
assert(correctBracketing(("<>")) == (true));
assert(correctBracketing(("<<><>>")) == (true));
assert(correctBracketing(("<><><<><>><>")) == (true));
assert(correctBracketing(("<><><<<><><>><>><<><><<>>>")) == (true));
assert(correctBracketing(("<<<>... |
humaneval-HumanEval_146_specialFilter.json-L43 | 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 takes an array array list of numbers as input and returns
// the number of elements in the array array list ... | } | } | }
public static void main(String[] args) {
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)5l, (long)-2l, (long)1l, (long)-5l)))) == (0l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)15l, (long)-73l, (long)14l, (long)-15l)))) == (1l));
assert(specialFilter((new Array... |
humaneval-HumanEval_117_select_words.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 {
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array array list of all w... | case 'i':
case 'o':
case 'u':
break;
default:
consonants++;
break;
}
}
if (consonants == n) {
ret.add(word);
... | case 'e': | }
public static void main(String[] args) {
assert(selectWords(("Mary had a little lamb"), (4l)).equals((new ArrayList<String>(Arrays.asList((String)"little")))));
assert(selectWords(("Mary had a little lamb"), (3l)).equals((new ArrayList<String>(Arrays.asList((String)"Mary", (String)"lamb")))));
ass... |
humaneval-HumanEval_39_prime_fib.json-L49 | js | //prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// >>> prime_fib(1)
// 2
// >>> prime_fib(2)
// 3
// >>> prime_fib(3)
// 5
// >>> prime_fib(4)
// 13
// >>> prime_fib(5)
// 89
function prime_fib(n){
function isPrime(number){
if(number <= 3){
return number > 1;
... | } | return fib(fibNum - 1); | const assert = require('node:assert');
function test() {
let candidate = prime_fib;
assert.deepEqual(candidate(1),2);
assert.deepEqual(candidate(2),3);
assert.deepEqual(candidate(3),5);
assert.deepEqual(candidate(4),13);
assert.deepEqual(candidate(5),89);
assert.deepEqual(candidate(6),233);
assert.dee... |
humaneval-HumanEval_64_vowels_count.json-L12 | 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... | var count = 0;
for(var i=0; i<s.length; i++){
if(vowels.indexOf(s[i])!=-1){
count++;
}
}
if(s[s.length-1]=='y'){
count++;
}
return count;
}
| var vowels = ['a','e','i','o','u']; | 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_33_sort_third.json-L32 | 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 an array array list l and returns an array array list l' such that
// l' is identical to l in the indicies that... | l_e.set(i, min);
}
}
}
int j = 0;
for (int i = 0; i < l.size(); i++) {
if (i % 3 == 0) {
l_s.add(l_e.get(j));
j++;
} else {
l_s.add(l_r.get(i - j));
}
}
... | l_e.set(j, l_e.get(i)); | }
public static void main(String[] args) {
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)5l)))));
assert(sortThird((n... |
humaneval-HumanEval_73_smallest_change.json-L12 | js | //Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// >>> smallest_change([1, 2, 3... | for(let i = 0; i < arr.length/2; i++){
if(arr[i] != arr[arr.length - 1 - i]){
changes++;
}
}
return changes;
} | let changes = 0; | const assert = require('node:assert');
function test() {
let candidate = smallest_change;
assert.deepEqual(candidate([1, 2, 3, 5, 4, 7, 9, 6]),4);
assert.deepEqual(candidate([1, 2, 3, 4, 3, 2, 2]),1);
assert.deepEqual(candidate([1, 4, 2]),1);
assert.deepEqual(candidate([1, 4, 4, 2]),1);
assert.deepEqual(c... |
humaneval-HumanEval_14_all_prefixes.json-L11 | py | from typing import List
def all_prefixes(string: str) -> List[str]:
""" Return list of all prefixes from shortest to longest of the input string
>>> all_prefixes('abc')
['a', 'ab', 'abc']
"""
prefixes = []
for i in range(len(string)):
prefixes.append(string[:i+1]) | return prefixes | def check(candidate):
assert candidate('') == []
assert candidate('asdfgh') == ['a', 'as', 'asd', 'asdf', 'asdfg', 'asdfgh']
assert candidate('WWW') == ['W', 'WW', 'WWW']
def test_check():
check(all_prefixes)
test_check()
| |
humaneval-HumanEval_8_sum_product.json-L11 | 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){
if(numbers.length... | let product = 1;
for(let i = 0; i < numbers.length; i++){
sum += numbers[i];
product *= numbers[i];
}
return [sum, product];
}
| let sum = 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_76_is_simple_power.json-L20 | js | //Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// >>> is_simple_power(1, 4)
// true
// >>> is_simple_power(2, 2)
// true
// >>> is_simple_power(8, 2)
// true
// >>> is_simple_power(3, 2)
// fa... | if(x < n){
return false;
}
if(x % n !== 0){
return false;
}
return is_simple_power(x/n, n);
}
| } | const assert = require('node:assert');
function test() {
let candidate = is_simple_power;
assert.deepEqual(candidate(16, 2),true);
assert.deepEqual(candidate(143214, 16),false);
assert.deepEqual(candidate(4, 2),true);
assert.deepEqual(candidate(9, 3),true);
assert.deepEqual(candidate(16, 4),true);
asser... |
humaneval-HumanEval_119_match_parens.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 {
// You are given an array array list of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
... | }
if (c1 == 0 || c2 == 0) return "Yes";
else return "No";
}
} | if (c2 < 0) break; | }
public static void main(String[] args) {
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"()(", (String)")")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")", (String)")")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.a... |
humaneval-HumanEval_49_modp.json-L18 | py | def modp(n: int, p: int) -> int:
"""Return 2^n modulo p (be aware of numerics).
>>> modp(3, 5)
3
>>> modp(1101, 101)
2
>>> modp(0, 101)
1
>>> modp(3, 11)
8
>>> modp(100, 101)
1
"""
if p <= 0:
raise ValueError("modp: invalid p")
if n < 0:
raise Valu... | return 1 if n == 0 else 2**(n % (p-1)) % p | def check(candidate):
assert candidate(3, 5) == 3
assert candidate(1101, 101) == 2
assert candidate(0, 101) == 1
assert candidate(3, 11) == 8
assert candidate(100, 101) == 1
assert candidate(30, 5) == 4
assert candidate(31, 5) == 3
def test_check():
check(modp)
test_check()
| |
humaneval-HumanEval_33_sort_third.json-L20 | js | //This function takes an array l and returns an array l' such that
// 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
// to the values of the corresponding indicies of l, but sorted.
// >>> sort_third([1, 2, 3])
// [1, 2, 3]
//... | y.sort();
k=0;
for(let i=0;i<l.length;i++){
if(i%3==0){
x[i]=y[k];
k=k+1;
}
}
return x;
} | } | const assert = require('node:assert');
function test() {
let candidate = sort_third;
assert.deepEqual(candidate([5, 6, 3, 4, 8, 9, 2]),[2, 6, 3, 4, 8, 9, 5]);
assert.deepEqual(candidate([5, 8, 3, 4, 6, 9, 2]),[2, 8, 3, 4, 6, 9, 5]);
assert.deepEqual(candidate([5, 6, 9, 4, 8, 3, 2]),[2, 6, 9, 4, 8, 3, 5]);
a... |
humaneval-HumanEval_160_do_algebra.json-L65 | 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_107_even_odd_palindrome.json-L35 | js | //Given a positive integer n, return an array that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// >>> even_odd_palindrome(3)
// [1, 2]
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// >>... | }
return [even, odd];
} | } | const assert = require('node:assert');
function test() {
let candidate = even_odd_palindrome;
assert.deepEqual(candidate(123),[8, 13]);
assert.deepEqual(candidate(12),[4, 6]);
assert.deepEqual(candidate(3),[1, 2]);
assert.deepEqual(candidate(63),[6, 8]);
assert.deepEqual(candidate(25),[5, 6]);
assert.de... |
humaneval-HumanEval_161_solve.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 string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as ... | StringBuilder sb = new StringBuilder();
if (s.length() == 0) return s;
for (int i = 0; i < s.length(); i++) {
if (Character.isLetter(s.charAt(i))) {
letterNotFound = false;
if (Character.isUpperCase(s.charAt(i))) {
sb.append(Charact... | boolean letterNotFound = true; | }
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_156_int_to_mini_roman.json-L57 | 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, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <=... | num -= 10;
}
if (num >= 9) {
res += "ix";
num -= 9;
}
if (num >= 5) {
res += "v";
num -= 5;
}
if (num >= 4) {
res += "iv";
num -= 4;
}
while (num >= 1) {
res +=... | res += "x"; | }
public static void main(String[] args) {
assert(intToMiniRoman((19l)).equals(("xix")));
assert(intToMiniRoman((152l)).equals(("clii")));
assert(intToMiniRoman((251l)).equals(("ccli")));
assert(intToMiniRoman((426l)).equals(("cdxxvi")));
assert(intToMiniRoman((500l)).equals(("d")));
ass... |
humaneval-HumanEval_146_specialFilter.json-L23 | 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 takes an array array list of numbers as input and returns
// the number of elements in the array array list ... | long[] digits = getDigits(n);
return digits[digits.length - 1];
}
public long[] getDigits(long n) {
ArrayList<Long> digits = new ArrayList<Long>();
while (n != 0) {
digits.add(n % 10);
n /= 10... | public long getLastDigit(long n) { | }
public static void main(String[] args) {
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)5l, (long)-2l, (long)1l, (long)-5l)))) == (0l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)15l, (long)-73l, (long)14l, (long)-15l)))) == (1l));
assert(specialFilter((new Array... |
humaneval-HumanEval_150_x_or_y.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 {
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// E... | return x;
} else {
return y;
}
}
} | if (nBig.isProbablePrime(100)) { | }
public static void main(String[] args) {
assert(xOrY((7l), (34l), (12l)) == (34l));
assert(xOrY((15l), (8l), (5l)) == (5l));
assert(xOrY((3l), (33l), (5212l)) == (33l));
assert(xOrY((1259l), (3l), (52l)) == (3l));
assert(xOrY((7919l), (-1l), (12l)) == (-1l));
assert(xOrY((3609l), (1245... |
humaneval-HumanEval_58_common.json-L17 | 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 sorted unique common elements for two array lists.
// >>> common((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (lon... | .collect(Collectors.toSet())
);
}
} | .filter(l2::contains) | }
public static void main(String[] args) {
assert(common((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)3l, (long)34l, (long)653l, (long)2l, (long)5l))), (new ArrayList<Long>(Arrays.asList((long)5l, (long)7l, (long)1l, (long)5l, (long)9l, (long)653l, (long)121l)))).equals((new ArrayList<Long>(... |
humaneval-HumanEval_20_find_closest_elements.json-L22 | py | from typing import List, Tuple
def find_closest_elements(numbers: List[float]) -> Tuple[float, float]:
""" From a supplied list 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... | if numbers[i] > numbers[j]:
temp = abs(numbers[i] - numbers[j])
temp_index = i
temp2_index = j
if numbers[temp_index] > numbers[temp2_index]:
temp, temp2 = numbers[temp2_index], numbers[temp_index]
else:
temp, temp2 = nu... | elif abs(numbers[i] - numbers[j]) == temp: | def check(candidate):
assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2]) == (3.9, 4.0)
assert candidate([1.0, 2.0, 5.9, 4.0, 5.0]) == (5.0, 5.9)
assert candidate([1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
assert candidate([1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
assert candidate([1.1, 2.2, 3.1... |
humaneval-HumanEval_160_do_algebra.json-L21 | 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 ( - )
... | let temp;
let answer;
while(count < operator.length){
switch(operator[count]){
case '*':
operand[count] = operand[count] * operand[count + 1];
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
case '//':
... | let count = 0; | 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_86_anti_shuffle.json-L21 | 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... | } | return result.join(" "); | 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_61_correct_bracketing.json-L16 | js | //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_bracketing(")(()")
// false
function correct_bracketing(brackets)... | else if (brackets[i] == ")"){
if (opens.length > 0){
opens.pop();
}
else {
return false;
}
}
}
if (opens.length == 0){
return true;
}
else {
return false;
}
} | } | const assert = require('node:assert');
function test() {
let candidate = correct_bracketing;
assert.deepEqual(candidate("()"),true);
assert.deepEqual(candidate("(()())"),true);
assert.deepEqual(candidate("()()(()())()"),true);
assert.deepEqual(candidate("()()((()()())())(()()(()))"),true);
assert.deepEqua... |
humaneval-HumanEval_39_prime_fib.json-L19 | js | //prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// >>> prime_fib(1)
// 2
// >>> prime_fib(2)
// 3
// >>> prime_fib(3)
// 5
// >>> prime_fib(4)
// 13
// >>> prime_fib(5)
// 89
function prime_fib(n){
function isPrime(number){
if(number <= 3){
return number > 1;
... | else{
for(var i = 5; i * i <= number; i += 6){
if(number % i == 0 || number % (i + 2) == 0){
return false;
}
}
return true;
}
}
function fib(num){
var a = 1, b = 0, temp;
while (num >= 0)... | } | const assert = require('node:assert');
function test() {
let candidate = prime_fib;
assert.deepEqual(candidate(1),2);
assert.deepEqual(candidate(2),3);
assert.deepEqual(candidate(3),5);
assert.deepEqual(candidate(4),13);
assert.deepEqual(candidate(5),89);
assert.deepEqual(candidate(6),233);
assert.dee... |
humaneval-HumanEval_68_pluck.json-L41 | 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))]
| 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_125_split_words.json-L23 | js | //Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// >>> split... | }
}
}
return count;
}
} | count++; | const assert = require('node:assert');
function test() {
let candidate = split_words;
assert.deepEqual(candidate("Hello world!"),["Hello", "world!"]);
assert.deepEqual(candidate("Hello,world!"),["Hello", "world!"]);
assert.deepEqual(candidate("Hello world,!"),["Hello", "world,!"]);
assert.deepEqual(candidat... |
humaneval-HumanEval_149_sorted_list_sum.json-L41 | 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 as a parameter,
// deletes the strings that have odd lengths from it,
... | } | } | }
public static void main(String[] args) {
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"aa", (String)"a", (String)"aaa")))).equals((new ArrayList<String>(Arrays.asList((String)"aa")))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"school", (String)"AI", (Stri... |
humaneval-HumanEval_160_do_algebra.json-L26 | 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 ( - )
... | operand[count] = operand[count] * operand[count + 1];
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
case '//':
operand[count] = Math.floor(operand[count] / operand[count + 1]);
operand.splice(count + 1, 1... | case '*': | 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_48_is_palindrome.json-L12 | js | //Checks if given string is a palindrome
// >>> is_palindrome("")
// true
// >>> is_palindrome("aba")
// true
// >>> is_palindrome("aaaaa")
// true
// >>> is_palindrome("zbcd")
// false
function is_palindrome(text){
return text == text.split("").reverse().join(""); | } | const assert = require('node:assert');
function test() {
let candidate = is_palindrome;
assert.deepEqual(candidate(""),true);
assert.deepEqual(candidate("aba"),true);
assert.deepEqual(candidate("aaaaa"),true);
assert.deepEqual(candidate("zbcd"),false);
assert.deepEqual(candidate("xywyx"),true);
assert.d... | |
humaneval-HumanEval_73_smallest_change.json-L23 | 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 arr of integers, find the minimum number of elements that
// need to be changed to make the array array l... | if (arr.get(first) != arr.get(last)) {
count++;
}
first++;
last--;
}
return count;
}
} | while (first < last) { | }
public static void main(String[] args) {
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)5l, (long)4l, (long)7l, (long)9l, (long)6l)))) == (4l));
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)3l, (lon... |
humaneval-HumanEval_24_largest_divisor.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 number n, find the largest number that divides n evenly, smaller than n
// >>> largestDivisor((15l))
// (5l)
pu... | }
} | return 1; | }
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_160_do_algebra.json-L56 | 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 ( - )
... | answer += operand[0];
break;
case '-':
answer -= operand[0];
break;
}
operand.splice(0, 1);
operator.splice(0, 1);
}
return answer;
}
| case '+': | 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_64_vowels_count.json-L23 | 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.
... | sum++;
}
if (sUpper.charAt(i) == 'Y' && i == lastIndex) {
sum++;
}
}
return sum;
}
} | if (sUpper.charAt(i) == 'A' || sUpper.charAt(i) == 'E' || sUpper.charAt(i) == 'I' || sUpper.charAt(i) == 'O' || sUpper.charAt(i) == 'U') { | }
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_90_next_smallest.json-L19 | 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(... | second_smallest=lst[i];
}
}
if(second_smallest==Number.MAX_VALUE){
return undefined;
}
return second_smallest;
} | if(lst[i]>smallest&&lst[i]<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_131_digits.json-L31 | js | //Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// >>> digits(1)
// 1
// >>> digits(4)
// 0
// >>> digits(235)
// 15
function digits(n){
if(!n){
return "error";
}
if(n < 0){
return "error";
}
var temp = 0;
va... | } | const assert = require('node:assert');
function test() {
let candidate = digits;
assert.deepEqual(candidate(5),5);
assert.deepEqual(candidate(54),5);
assert.deepEqual(candidate(120),1);
assert.deepEqual(candidate(5014),5);
assert.deepEqual(candidate(98765),315);
assert.deepEqual(candidate(5576543),2625)... | |
humaneval-HumanEval_111_histogram.json-L27 | py | from typing import Dict
def histogram(test: str) -> Dict[str, int]:
"""Given a string representing a space separated lowercase letters, return a dictionary
of the letter with the most repetition and containing the corresponding count.
If several letters have the same occurrence, return all of them.
... | for letter in letters:
if letters[letter] == most_count:
result[letter] = most_count
return result
| most_count = letters[letter] | def check(candidate):
assert candidate('a b b a') == { 'a': 2, 'b': 2 }
assert candidate('a b c a b') == { 'a': 2, 'b': 2 }
assert candidate('a b c d g') == { 'a': 1, 'b': 1, 'c': 1, 'd': 1, 'g': 1 }
assert candidate('r t g') == { 'r': 1, 't': 1, 'g': 1 }
assert candidate('b b b b a') == { 'b': 4 }
... |
humaneval-HumanEval_161_solve.json-L39 | 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 ... | return sb.toString();
}
} | } | }
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_26_remove_duplicates.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 {
// From an array array list of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in ... | Long key = numbers.get(i);
if (hashmap.get(key) == 1) {
out.add(key);
}
}
return out;
}
} | for (int i = 0; i < numbers.size(); i++) { | }
public static void main(String[] args) {
assert(removeDuplicates((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(removeDuplicates((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((lon... |
humaneval-HumanEval_158_find_max.json-L36 | js | //Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// >>> find_max(["name", "of", "string"])
/... | }
return max_unique_word;
} | } | const assert = require('node:assert');
function test() {
let candidate = find_max;
assert.deepEqual(candidate(["name", "of", "string"]),"string");
assert.deepEqual(candidate(["name", "enam", "game"]),"enam");
assert.deepEqual(candidate(["aaaaaaa", "bb", "cc"]),"aaaaaaa");
assert.deepEqual(candidate(["abc", ... |
humaneval-HumanEval_11_string_xor.json-L26 | js | //Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// >>> string_xor("010", "110")
// "100"
function string_xor(a, b){
var arrayA = [];
var arrayB = [];
var arrayXOR = [];
var result = '';
for (var i = 0; i < a.length; i++) {... | } | const assert = require('node:assert');
function test() {
let candidate = string_xor;
assert.deepEqual(candidate("111000", "101010"),"010010");
assert.deepEqual(candidate("1", "1"),"0");
assert.deepEqual(candidate("0101", "0000"),"0101");
}
test(); | |
humaneval-HumanEval_4_mean_absolute_deviation.json-L14 | py | from typing import List
def mean_absolute_deviation(numbers: List[float]) -> float:
""" For a given list 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 c... |
print(mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])) | return sum(absolute_deviations) / len(absolute_deviations) | def check(candidate):
assert candidate([1.0, 2.0]) == 0.5
assert candidate([1.0, 2.0, 3.0, 4.0]) == 1.0
assert candidate([1.0, 2.0, 3.0, 4.0, 5.0]) == 1.2
def test_check():
check(mean_absolute_deviation)
test_check()
|
humaneval-HumanEval_158_find_max.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 {
// Write a function that accepts an array array list of strings.
// The array list contains different words. Return the word with maxi... | for (String word : words) {
Set<Character> uniqueCharacters = new HashSet<Character>();
for (char c : word.toCharArray()) {
uniqueCharacters.add(c);
}
wordsToUniqueCharacters.put(word, uniqueCharacters.size());
}
words.sort(new Comp... | Map<String, Integer> wordsToUniqueCharacters = new HashMap<String, Integer>(); | }
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_29_filter_by_prefix.json-L10 | js | //Filter an input array of strings only for ones that start with a given prefix.
// >>> filter_by_prefix([], "a")
// []
// >>> filter_by_prefix(["abc", "bcd", "cde", "array"], "a")
// ["abc", "array"]
function filter_by_prefix(strings, prefix){
return strings.filter( function(str){
return str.startsWith(pre... | } | const assert = require('node:assert');
function test() {
let candidate = filter_by_prefix;
assert.deepEqual(candidate([], "john"),[]);
assert.deepEqual(candidate(["xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"], "xxx"),["xxx", "xxxAAA", "xxx"]);
}
test(); | |
humaneval-HumanEval_148_bf.json-L47 | 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 {
// There are eight planets in our solar system: the closerst to the Sun
// is Mercury, the next one is Venus, then Earth, Mars, Jupit... | } | } | }
public static void main(String[] args) {
assert(bf(("Jupiter"), ("Neptune")).equals((new ArrayList<String>(Arrays.asList((String)"Saturn", (String)"Uranus")))));
assert(bf(("Earth"), ("Mercury")).equals((new ArrayList<String>(Arrays.asList((String)"Venus")))));
assert(bf(("Mercury"), ("Uranus")).e... |
humaneval-HumanEval_90_next_smallest.json-L20 | py | from typing import List, Optional
def next_smallest(lst: List[int]) -> Optional[int]:
"""
You are given a list of integers.
Write a function next_smallest() that returns the 2nd smallest element of the list.
Return None if there is no such element.
>>> next_smallest([1, 2, 3, 4, 5])
2
>>> n... | for i in range(2, len(lst)):
if lst[i] < min1:
min2 = min1
min1 = lst[i]
elif lst[i] < min2:
min2 = lst[i]
return min2 if min1 != min2 else None
| min2 = max(lst[0], lst[1]) | def check(candidate):
assert candidate([1, 2, 3, 4, 5]) == 2
assert candidate([5, 1, 4, 3, 2]) == 2
assert candidate([]) == None
assert candidate([1, 1]) == None
assert candidate([1, 1, 1, 1, 0]) == 1
assert candidate([1, 1]) == None
assert candidate([-35, 34, 12, -45]) == -35
def test_chec... |
humaneval-HumanEval_156_int_to_mini_roman.json-L25 | py | def int_to_mini_roman(number: int) -> str:
"""
Given a positive integer, obtain its roman numeral equivalent as a string,
and return it in lowercase.
Restrictions: 1 <= num <= 1000
Examples:
>>> int_to_mini_roman(19)
'xix'
>>> int_to_mini_roman(152)
'clii'
>>> int_to_mini_roman(... | 5: 'v',
4: 'iv',
1: 'i'
}
roman_numeral = ''
for key in sorted(roman_numerals.keys(), reverse=True):
roman_numeral += roman_numerals[key] * (number // key)
number = number % key
return roman_numeral
| 9: 'ix', | def check(candidate):
assert candidate(19) == 'xix'
assert candidate(152) == 'clii'
assert candidate(251) == 'ccli'
assert candidate(426) == 'cdxxvi'
assert candidate(500) == 'd'
assert candidate(1) == 'i'
assert candidate(4) == 'iv'
assert candidate(43) == 'xliii'
assert candidate(9... |
humaneval-HumanEval_158_find_max.json-L19 | py | from typing import List
def find_max(words: List[str]) -> str:
"""Write a function that accepts a list of strings.
The list contains different words. Return the word with maximum number
of unique characters. If multiple strings have maximum number of unique
characters, return the one which comes first ... | if unique_num > max_num:
max_num = unique_num
max_word = word
elif unique_num == max_num:
if word < max_word:
max_word = word
return max_word
| unique_num = len(set(word)) | def check(candidate):
assert candidate(['name', 'of', 'string']) == 'string'
assert candidate(['name', 'enam', 'game']) == 'enam'
assert candidate(['aaaaaaa', 'bb', 'cc']) == 'aaaaaaa'
assert candidate(['abc', 'cba']) == 'abc'
assert candidate(['play', 'this', 'game', 'of', 'footbott']) == 'footbott... |
humaneval-HumanEval_83_starts_one_ends.json-L6 | py | def starts_one_ends(n: int) -> int:
"""
Given a positive integer n, return the count of the numbers of n-digit
positive integers that start or end with 1.
"""
| for i in range(10**(n-1), 10**n):
if i // 10**(n-1) == 1 or i % 10 == 1:
count += 1
return count
| count = 0 | def check(candidate):
assert candidate(1) == 1
assert candidate(2) == 18
assert candidate(3) == 180
assert candidate(4) == 1800
assert candidate(5) == 18000
def test_check():
check(starts_one_ends)
test_check()
|
humaneval-HumanEval_48_is_palindrome.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 {
// Checks if given string is a palindrome
// >>> isPalindrome((""))
// (true)
// >>> isPalindrome(("aba"))
// (true)
/... | }
} | return isPalindrome; | }
public static void main(String[] args) {
assert(isPalindrome(("")) == (true));
assert(isPalindrome(("aba")) == (true));
assert(isPalindrome(("aaaaa")) == (true));
assert(isPalindrome(("zbcd")) == (false));
assert(isPalindrome(("xywyx")) == (true));
assert(isPalindrome(("xywyz")) == (fa... |
humaneval-HumanEval_81_numerical_letter_grade.json-L48 | py | from typing import List
def numerical_letter_grade(grades: List[float]) -> List[str]:
"""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.
Sh... | elif x > 1.0:
final.append('D+')
elif x > 0.7:
final.append('D')
elif x > 0.0:
final.append('D-')
else:
final.append('E')
return final
| final.append('C-') | def check(candidate):
assert candidate([4.0, 3, 1.7, 2, 3.5]) == ['A+', 'B', 'C-', 'C', 'A-']
assert candidate([1.2]) == ['D+']
assert candidate([0.5]) == ['D-']
assert candidate([0.0]) == ['E']
assert candidate([1.0, 0.3, 1.5, 2.8, 3.3]) == ['D', 'D-', 'C-', 'B', 'B+']
assert candidate([0.0, 0.... |
humaneval-HumanEval_156_int_to_mini_roman.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 {
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <=... | String res = "";
if (num == 0)
return "";
while (num >= 1000) {
res += "m";
num -= 1000;
}
if (num >= 900) {
res += "cm";
num -= 900;
}
if (num >= 500) {
res += "d";
num -= 500;
... | int num = (int) number; | }
public static void main(String[] args) {
assert(intToMiniRoman((19l)).equals(("xix")));
assert(intToMiniRoman((152l)).equals(("clii")));
assert(intToMiniRoman((251l)).equals(("ccli")));
assert(intToMiniRoman((426l)).equals(("cdxxvi")));
assert(intToMiniRoman((500l)).equals(("d")));
ass... |
humaneval-HumanEval_95_check_dict_case.json-L25 | 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 hash map, return true if all keys are strings in lower
// case or all keys are strings in upper case, else return false.
... | }
boolean allLowerCase = dict.keySet().stream().allMatch(k -> k.matches("^[a-z]+$"));
boolean allUpperCase = dict.keySet().stream().allMatch(k -> k.matches("^[A-Z]+$"));
return allLowerCase || allUpperCase;
}
} | return false; | }
public static void main(String[] args) {
assert(checkDictCase((new HashMap<String,String>(Map.of("p", "pineapple", "b", "banana")))) == (true));
assert(checkDictCase((new HashMap<String,String>(Map.of("p", "pineapple", "A", "banana", "B", "banana")))) == (false));
assert(checkDictCase((new HashMap... |
humaneval-HumanEval_18_how_many_times.json-L13 | 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... | }
return count;
} | i = string.indexOf(substring, i) + 1; | 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_19_sort_numbers.json-L10 | py | def sort_numbers(numbers: str) -> str:
""" 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... | for word in sorted(words, key=lambda x: mapper[x]):
res += ' ' + word
return res.strip()
| mapper = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9} | def check(candidate):
assert candidate('') == ''
assert candidate('three') == 'three'
assert candidate('three five nine') == 'three five nine'
assert candidate('five zero four seven nine eight') == 'zero four five seven eight nine'
assert candidate('six five four three two one zero') == 'zero one tw... |
humaneval-HumanEval_37_sort_even.json-L32 | 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 an array array list l and returns an array array list l' such that
// l' is identical to l in the odd indicies,... | res.add(num);
}
index++;
}
return res;
}
} | } else { | }
public static void main(String[] args) {
assert(sortEven((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))));
assert(sortEven((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)-5l, (long)2l, (long)-3... |
humaneval-HumanEval_13_greatest_common_divisor.json-L12 | js | //Return a greatest common divisor of two integers a and b
// >>> greatest_common_divisor(3, 5)
// 1
// >>> greatest_common_divisor(25, 15)
// 5
function greatest_common_divisor(a, b){
let max = Math.max(a, b)
let min = Math.min(a, b)
if (max % min == 0) {
return min
} else { | }
}
| return greatest_common_divisor(min, max % min) | const assert = require('node:assert');
function test() {
let candidate = greatest_common_divisor;
assert.deepEqual(candidate(3, 7),1);
assert.deepEqual(candidate(10, 15),5);
assert.deepEqual(candidate(49, 14),7);
assert.deepEqual(candidate(144, 60),12);
}
test(); |
humaneval-HumanEval_25_factorize.json-L25 | 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 array list of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be array l... | if (n > 1)
factors.add(n);
return factors;
}
} | } | }
public static void main(String[] args) {
assert(factorize((2l)).equals((new ArrayList<Long>(Arrays.asList((long)2l)))));
assert(factorize((4l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)2l)))));
assert(factorize((8l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)2l, (l... |
humaneval-HumanEval_15_string_sequence.json-L8 | js | //Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// >>> string_sequence(0)
// "0"
// >>> string_sequence(5)
// "0 1 2 3 4 5"
function string_sequence(n){
let arr = []; | arr.push(i);
}
return arr.join(" ");
}
| for(let i = 0; i <= n; i++){ | const assert = require('node:assert');
function test() {
let candidate = string_sequence;
assert.deepEqual(candidate(0),"0");
assert.deepEqual(candidate(3),"0 1 2 3");
assert.deepEqual(candidate(10),"0 1 2 3 4 5 6 7 8 9 10");
}
test(); |
humaneval-HumanEval_131_digits.json-L15 | py | def digits(n: int) -> int:
"""Given a positive integer n, return the product of the odd digits.
Return 0 if all digits are even.
For example:
>>> digits(1)
1
>>> digits(4)
0
>>> digits(235)
15
"""
if n < 10:
return n if n % 2 == 1 else 0
d, m = divmod(n, 10) | return digits(d) * (m if m % 2 == 1 else 1) | def check(candidate):
assert candidate(5) == 5
assert candidate(54) == 5
assert candidate(120) == 1
assert candidate(5014) == 5
assert candidate(98765) == 315
assert candidate(5576543) == 2625
assert candidate(2468) == 0
def test_check():
check(digits)
test_check()
| |
humaneval-HumanEval_75_is_multiply_prime.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 {
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Know... | a /= 2;
}
for (long i = 3; i <= Math.sqrt(a); i += 2) {
while (a % i == 0) {
arr.add(i);
a /= i;
}
}
if (a > 2) {
arr.add(a);
}
return arr.size() == 3;
}
} | arr.add(2l); | }
public static void main(String[] args) {
assert(isMultiplyPrime((5l)) == (false));
assert(isMultiplyPrime((30l)) == (true));
assert(isMultiplyPrime((8l)) == (true));
assert(isMultiplyPrime((10l)) == (false));
assert(isMultiplyPrime((125l)) == (true));
assert(isMultiplyPrime((105l)) == ... |
humaneval-HumanEval_129_minPath.json-L56 | 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... | neighbours.push(grid[x][y - 1]);
}
if(y < n - 1){
neighbours.push(grid[x][y + 1]);
}
let nextCell = neighbours[0];
for(let i = 0; i < neighbours.length; i++){
let curr = neighbours[i];
if(curr < nextCell){
nextCell =... | if(y > 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-L21 | js | //The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// >>>... | }
return fibfib(n-1) + fibfib(n-2) + fibfib(n-3);
}
| return 1; | const assert = require('node:assert');
function test() {
let candidate = fibfib;
assert.deepEqual(candidate(2),1);
assert.deepEqual(candidate(1),0);
assert.deepEqual(candidate(5),4);
assert.deepEqual(candidate(8),24);
assert.deepEqual(candidate(10),81);
assert.deepEqual(candidate(12),274);
assert.deep... |
humaneval-HumanEval_91_is_bored.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 {
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with th... | }
return boredoms;
}
} | } | }
public static void main(String[] args) {
assert(isBored(("Hello world")) == (0l));
assert(isBored(("Is the sky blue?")) == (0l));
assert(isBored(("I love It !")) == (1l));
assert(isBored(("bIt")) == (0l));
assert(isBored(("I feel good today. I will be productive. will kill It")) == (2l));
... |
humaneval-HumanEval_74_total_match.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 {
// Write a function that accepts two array lists of strings and returns the array list that has
// total number of chars in the all s... | return lst2;
}
}
} | } else { | }
public static void main(String[] args) {
assert(totalMatch((new ArrayList<String>(Arrays.asList())), (new ArrayList<String>(Arrays.asList()))).equals((new ArrayList<String>(Arrays.asList()))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<Stri... |
humaneval-HumanEval_8_sum_product.json-L12 | 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){
if(numbers.length... | for(let i = 0; i < numbers.length; i++){
sum += numbers[i];
product *= numbers[i];
}
return [sum, product];
}
| let product = 1; | 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_91_is_bored.json-L23 | 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'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with th... | }
}
return boredoms;
}
} | boredoms++; | }
public static void main(String[] args) {
assert(isBored(("Hello world")) == (0l));
assert(isBored(("Is the sky blue?")) == (0l));
assert(isBored(("I love It !")) == (1l));
assert(isBored(("bIt")) == (0l));
assert(isBored(("I feel good today. I will be productive. will kill It")) == (2l));
... |
humaneval-HumanEval_59_largest_prime_factor.json-L11 | js | //Return the largest prime factor of n. Assume n > 1 and is not a prime.
// >>> largest_prime_factor(13195)
// 29
// >>> largest_prime_factor(2048)
// 2
function largest_prime_factor(n){
var result = 2;
while(n > result){
if(n % result == 0){
n = n / result; | else{
result = result + 1;
}
}
return result;
} | } | const assert = require('node:assert');
function test() {
let candidate = largest_prime_factor;
assert.deepEqual(candidate(15),5);
assert.deepEqual(candidate(27),3);
assert.deepEqual(candidate(63),7);
assert.deepEqual(candidate(330),11);
assert.deepEqual(candidate(13195),29);
}
test(); |
humaneval-HumanEval_87_get_row.json-L29 | js | //You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of arrays, [(x1, y1), (x2, y2) ...] such that
// each array is a coordi... | } | const assert = require('node:assert');
function test() {
let candidate = get_row;
assert.deepEqual(candidate([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1),[[0, 0], [1, 4], [1, 0], [2, 5], [2, 0]]);
assert.deepEqual(candidate([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, ... | |
humaneval-HumanEval_94_skjkasdkd.json-L58 | 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 an array array list of integers.
// You need to find the largest prime value and return the sum of its digits.
//... | return output;
}
}
} | } | }
public static void main(String[] args) {
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l, (long)2l, (long)1l, (long)3l, (long)5l, (long)7l, (long)4l, (long)5l, (long)5l, (long)5l, (long)2l, (long)181l, (long)32l, (long)4l, (long)32l, (long)3l, (long)2l, (long)32l, (long)324l, (long)... |
humaneval-HumanEval_109_move_one_ball.json-L41 | 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 {
// We have an array array list 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array array list will be randomly... | }
} | return false; | }
public static void main(String[] args) {
assert(moveOneBall((new ArrayList<Long>(Arrays.asList((long)3l, (long)4l, (long)5l, (long)1l, (long)2l)))) == (true));
assert(moveOneBall((new ArrayList<Long>(Arrays.asList((long)3l, (long)5l, (long)10l, (long)1l, (long)2l)))) == (true));
assert(moveOneBall... |
humaneval-HumanEval_156_int_to_mini_roman.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 {
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <=... | return "";
while (num >= 1000) {
res += "m";
num -= 1000;
}
if (num >= 900) {
res += "cm";
num -= 900;
}
if (num >= 500) {
res += "d";
num -= 500;
}
if (num >= 400) {
r... | if (num == 0) | }
public static void main(String[] args) {
assert(intToMiniRoman((19l)).equals(("xix")));
assert(intToMiniRoman((152l)).equals(("clii")));
assert(intToMiniRoman((251l)).equals(("ccli")));
assert(intToMiniRoman((426l)).equals(("cdxxvi")));
assert(intToMiniRoman((500l)).equals(("d")));
ass... |
humaneval-HumanEval_20_find_closest_elements.json-L14 | py | from typing import List, Tuple
def find_closest_elements(numbers: List[float]) -> Tuple[float, float]:
""" From a supplied list 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... | temp_index, temp2_index = temp2_index, temp_index
for i in range(len(numbers)):
for j in range(i+1, len(numbers)):
if abs(numbers[i] - numbers[j]) < temp:
temp = abs(numbers[i] - numbers[j])
temp_index = i
temp2_index = j
elif a... | temp, temp2 = temp2, temp | def check(candidate):
assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2]) == (3.9, 4.0)
assert candidate([1.0, 2.0, 5.9, 4.0, 5.0]) == (5.0, 5.9)
assert candidate([1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
assert candidate([1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
assert candidate([1.1, 2.2, 3.1... |
humaneval-HumanEval_160_do_algebra.json-L58 | 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 ( - )
... | case '-':
answer -= operand[0];
break;
}
operand.splice(0, 1);
operator.splice(0, 1);
}
return answer;
}
| break; | 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_155_even_odd_count.json-L18 | py | from typing import Tuple
def even_odd_count(num: int) -> Tuple[int, int]:
"""Given an integer. return a tuple that has the number of even and odd digits respectively.
Example:
>>> even_odd_count(-12)
(1, 1)
>>> even_odd_count(123)
(1, 2)
"""
num_str = str(abs(num))
even_count = 0
... | else:
odd_count += 1
return even_count, odd_count
| even_count += 1 | def check(candidate):
assert candidate(7) == (0, 1)
assert candidate(-78) == (1, 1)
assert candidate(3452) == (2, 2)
assert candidate(346211) == (3, 3)
assert candidate(-345821) == (3, 3)
assert candidate(-2) == (1, 0)
assert candidate(-45347) == (2, 3)
assert candidate(0) == (1, 0)
def... |
humaneval-HumanEval_55_fib.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 {
// Return n-th Fibonacci number.
// >>> fib((10l))
// (55l)
// >>> fib((1l))
// (1l)
// >>> fib((8l))
// (21l)
... | }
}
} | return Problem.fib((n - 1)) + Problem.fib((n - 2)); | }
public static void main(String[] args) {
assert(fib((10l)) == (55l));
assert(fib((1l)) == (1l));
assert(fib((8l)) == (21l));
assert(fib((11l)) == (89l));
assert(fib((12l)) == (144l));
}
}
|
humaneval-HumanEval_111_histogram.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 a string representing a space separated lowercase letters, return a hash map
// of the letter with the most repetition and co... | for (String key : hm.keySet()) {
if (hm.get(key) == max) {
s.put(key, hm.get(key));
}
}
}
return s;
}
} | } | }
public static void main(String[] args) {
assert(histogram(("a b b a")).equals((new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))));
assert(histogram(("a b c a b")).equals((new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))));
assert(histogram(("a b c d g")).equals((new HashMap<String,Long>(Map.... |
humaneval-HumanEval_68_pluck.json-L32 | js | //"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 same smallest even value are found return the node that has smallest index.
//... | }
}
}
return result;
}
| result = [arr[i], i]; | const assert = require('node:assert');
function test() {
let candidate = pluck;
assert.deepEqual(candidate([4, 2, 3]),[2, 1]);
assert.deepEqual(candidate([1, 2, 3]),[2, 1]);
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([5, 0, 3, 0, 4, 2]),[0, 1]);
assert.deepEqual(candidate([1, 2, 3, 0, ... |
humaneval-HumanEval_73_smallest_change.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 {
// Given an array array list arr of integers, find the minimum number of elements that
// need to be changed to make the array array l... | int last = arr.size() - 1;
int count = 0;
while (first < last) {
if (arr.get(first) != arr.get(last)) {
count++;
}
first++;
last--;
}
return count;
}
} | int first = 0; | }
public static void main(String[] args) {
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)5l, (long)4l, (long)7l, (long)9l, (long)6l)))) == (4l));
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)3l, (lon... |
humaneval-HumanEval_109_move_one_ball.json-L39 | py | from typing import List
def move_one_ball(arr: List[int]) -> bool:
"""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 followi... | return True
| flag = False | def check(candidate):
assert candidate([3, 4, 5, 1, 2]) == True
assert candidate([3, 5, 10, 1, 2]) == True
assert candidate([4, 3, 1, 2]) == False
assert candidate([3, 5, 4, 1, 2]) == False
assert candidate([]) == True
def test_check():
check(move_one_ball)
test_check()
|
humaneval-HumanEval_136_largest_smallest_integers.json-L20 | py | from typing import List, Tuple, Optional
def largest_smallest_integers(lst: List[int]) -> Tuple[Optional[int], Optional[int]]:
"""
Create a function that returns a tuple (a, b), where 'a' is
the largest of negative integers, and 'b' is the smallest
of positive integers in a list.
If there is no neg... | if num > 0:
if smallest_positive is None or num < smallest_positive:
smallest_positive = num
elif num < 0:
if largest_negative is None or num > largest_negative:
largest_negative = num
return (largest_negative, smallest_positive)
| for num in lst: | def check(candidate):
assert candidate([2, 4, 1, 3, 5, 7]) == (None, 1)
assert candidate([2, 4, 1, 3, 5, 7, 0]) == (None, 1)
assert candidate([1, 3, 2, 4, 5, 6, -2]) == (-2, 1)
assert candidate([4, 5, 3, 6, 2, 7, -7]) == (-7, 2)
assert candidate([7, 3, 8, 4, 9, 2, 5, -9]) == (-9, 2)
assert candi... |
humaneval-HumanEval_147_get_max_triples.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 {
// You are given a positive integer n. You have to create an integer array array list a of length n.
// For each i (1 ≤ i ≤ n), the va... | }
} | return count; | }
public static void main(String[] args) {
assert(getMaxTriples((5l)) == (1l));
assert(getMaxTriples((6l)) == (4l));
assert(getMaxTriples((10l)) == (36l));
assert(getMaxTriples((100l)) == (53361l));
}
}
|
humaneval-HumanEval_64_vowels_count.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 {
// 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; | }
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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.