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_95_check_dict_case.json-L29 | 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": "banana", "B": "banana"})
// false
// >>> check_dict_case({"a": "apple", 8: "banana", "a": "apple"})
// false
// >>> check_dict_case({"Name": "John", "Age": "36", "City": "Houston"})
// false
// >>> check_dict_case({"STATE": "NC", "ZIP": "12345"})
// true
function check_dict_case(dict){
if (Object.keys(dict).length == 0){
return false;
}
var case_type = -1;
for (let key in dict){
if (typeof key == "string"){
if (case_type == -1){
if (key == key.toUpperCase()){
case_type = 1;
}
else if (key == key.toLowerCase()){
case_type = 0;
} | return false;
}
}
else if (case_type == 1){
if (key != key.toUpperCase()){
return false;
}
}
else if (case_type == 0){
if (key != key.toLowerCase()){
return false;
}
}
}
else{
return false;
}
}
return true;
} | else{ | 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": "apple"}),false);
assert.deepEqual(candidate({"Name": "John", "Age": "36", "City": "Houston"}),false);
assert.deepEqual(candidate({"STATE": "NC", "ZIP": "12345"}),true);
assert.deepEqual(candidate({"fruit": "Orange", "taste": "Sweet"}),true);
assert.deepEqual(candidate({}),false);
}
test(); |
humaneval-HumanEval_137_compare_one.json-L17 | 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
// >>> compare_one(1, "2,3")
// "2,3"
// >>> compare_one("5,1", "6")
// "6"
// >>> compare_one("1", 1)
// undefined
function compare_one(a, b){
if (typeof a === typeof b){
if (a > b) {
return a; | return b;
} else {
return undefined;
}
}
else if (typeof a === "string" && typeof b === "number"){
if (a[0] > b){
return a;
} else if (a[0] < b){
return b;
} else {
return undefined;
}
}
else if (typeof a === "number" && typeof b === "string"){
if (a > b[0]){
return a;
} else if (a < b[0]){
return b;
} else {
return undefined;
}
}
}
| } else if (a < b) { | 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(candidate("5,1", "6"),"6");
assert.deepEqual(candidate("1", "2"),"2");
assert.deepEqual(candidate("1", 1),undefined);
}
test(); |
humaneval-HumanEval_107_even_odd_palindrome.json-L33 | 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:
// >>> even_odd_palindrome(12)
// [4, 6]
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned array has the number of even and odd integer palindromes respectively.
function even_odd_palindrome(n){
var pal = [];
var isPalindrome = function(x){
var y = x.toString().split('').reverse().join('');
return y == x;
}
for(var i = 1; i <= n; i++){
if(isPalindrome(i)){
pal.push(i);
}
}
var odd = 0;
var even = 0;
for(var i = 0; i < pal.length; i++){
if(pal[i] % 2 == 0){
even++;
} | odd++;
}
}
return [even, odd];
} | else{ | 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.deepEqual(candidate(19),[4, 6]);
assert.deepEqual(candidate(9),[4, 5]);
assert.deepEqual(candidate(1),[0, 1]);
}
test(); |
humaneval-HumanEval_37_sort_even.json-L12 | js | //This function takes an array l and returns an array 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])
// [1, 2, 3]
// >>> sort_even([5, 6, 3, 4])
// [3, 6, 5, 4]
function sort_even(l){
var l2 = []
for(var i = 0; i < l.length; i += 2){
l2.push(l[i]) | l2.sort(function(a, b){return a - b})
for(var i = 0; i < l2.length; i++){
l[i * 2] = l2[i]
}
return l
}
| } | const assert = require('node:assert');
function test() {
let candidate = sort_even;
assert.deepEqual(candidate([1, 2, 3]),[1, 2, 3]);
assert.deepEqual(candidate([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]),[-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123]);
assert.deepEqual(candidate([5, 8, -12, 4, 23, 2, 3, 11, 12, -10]),[-12, 8, 3, 4, 5, 2, 12, 11, 23, -10]);
}
test(); |
humaneval-HumanEval_33_sort_third.json-L9 | 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]
// >>> sort_third([5, 6, 3, 4, 8, 9, 2])
// [2, 6, 3, 4, 8, 9, 5]
function sort_third(l){
| let y=[];
let k=0;
for(let i=0;i<l.length;i++){
if(i%3==0){
y[k]=l[i];
k=k+1;
}
else{
x[i]=l[i];
}
}
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;
} | let 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]);
assert.deepEqual(candidate([5, 6, 3, 4, 8, 9, 2, 1]),[2, 6, 3, 4, 8, 9, 5, 1]);
}
test(); |
humaneval-HumanEval_88_sort_array.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 an array array list of non-negative integers, return a cojava of the given array array list after sorting,
// you will sort the given array array list 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 the given array array list.
// Examples:
// >>> sortArray((new ArrayList<Long>(Arrays.asList())))
// (new ArrayList<Long>(Arrays.asList()))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)5l))))
// (new ArrayList<Long>(Arrays.asList((long)5l)))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)3l, (long)0l, (long)1l, (long)5l))))
// (new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)3l, (long)0l, (long)1l, (long)5l, (long)6l))))
// (new ArrayList<Long>(Arrays.asList((long)6l, (long)5l, (long)4l, (long)3l, (long)2l, (long)1l, (long)0l)))
public static ArrayList<Long> sortArray(ArrayList<Long> array) {
if(array.size()==0) { | }
if(array.size()==1) {
return array;
}
if(array.size()>1) {
if((array.get(0)+array.get(array.size()-1))%2==0) {
Collections.sort(array, Collections.reverseOrder());
}
else {
Collections.sort(array);
}
}
return array;
}
} | return array; | }
public static void main(String[] args) {
assert(sortArray((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)5l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)3l, (long)0l, (long)1l, (long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)3l, (long)0l, (long)1l, (long)5l, (long)6l)))).equals((new ArrayList<Long>(Arrays.asList((long)6l, (long)5l, (long)4l, (long)3l, (long)2l, (long)1l, (long)0l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)15l, (long)42l, (long)87l, (long)32l, (long)11l, (long)0l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)11l, (long)15l, (long)32l, (long)42l, (long)87l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)21l, (long)14l, (long)23l, (long)11l)))).equals((new ArrayList<Long>(Arrays.asList((long)23l, (long)21l, (long)14l, (long)11l)))));
}
}
|
humaneval-HumanEval_120_maximum.json-L31 | 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, -4, 4], 2)
[4, 4]
Example 3:
>>> maximum([-3, 2, 1, 2, -1, -2, 1], 1)
[2]
Note:
1. The length of the array will be in the range of [1, 1000].
2. The elements in the array will be in the range of [-1000, 1000].
3. 0 <= k <= len(arr)
"""
def get_max(arr: List[int], k: int) -> List[int]:
"""
Returns the maximum k numbers in the given array | if k == 0:
return []
elif k == 1:
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))
| """ | 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]
assert candidate([5, 15, 0, 3, -13, -8, 0], 7) == [-13, -8, 0, 0, 3, 5, 15]
assert candidate([-1, 0, 2, 5, 3, -10], 2) == [3, 5]
assert candidate([1, 0, 5, -7], 1) == [5]
assert candidate([4, -4], 2) == [-4, 4]
assert candidate([-10, 10], 2) == [-10, 10]
assert candidate([1, 2, 3, -23, 243, -400, 0], 0) == []
def test_check():
check(maximum)
test_check()
|
humaneval-HumanEval_84_solve.json-L16 | js | //Given a positive integer N, return the total sum of its digits in binary.
// Example
// >>> solve(1000)
// "1"
// >>> solve(150)
// "110"
// >>> solve(147)
// "1100"
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
function solve(N){
let newN = N.toString(); | for(let i = 0; i < newN.length; i++){
let digit = newN[i];
total += parseInt(digit);
}
return total.toString(2);
} | let total = 0; | const assert = require('node:assert');
function test() {
let candidate = solve;
assert.deepEqual(candidate(1000),"1");
assert.deepEqual(candidate(150),"110");
assert.deepEqual(candidate(147),"1100");
assert.deepEqual(candidate(333),"1001");
assert.deepEqual(candidate(963),"10010");
}
test(); |
humaneval-HumanEval_37_sort_even.json-L14 | js | //This function takes an array l and returns an array 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])
// [1, 2, 3]
// >>> sort_even([5, 6, 3, 4])
// [3, 6, 5, 4]
function sort_even(l){
var l2 = []
for(var i = 0; i < l.length; i += 2){
l2.push(l[i])
}
l2.sort(function(a, b){return a - b}) | l[i * 2] = l2[i]
}
return l
}
| for(var i = 0; i < l2.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = sort_even;
assert.deepEqual(candidate([1, 2, 3]),[1, 2, 3]);
assert.deepEqual(candidate([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]),[-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123]);
assert.deepEqual(candidate([5, 8, -12, 4, 23, 2, 3, 11, 12, -10]),[-12, 8, 3, 4, 5, 2, 12, 11, 23, -10]);
}
test(); |
humaneval-HumanEval_156_int_to_mini_roman.json-L32 | 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 roman_conversion = {
1000: "m",
900: "cm",
500: "d",
400: "cd",
100: "c",
90: "xc",
50: "l",
40: "xl",
10: "x",
9: "ix",
5: "v",
4: "iv",
1: "i"
};
var output = "";
while (number > 0){
var key_list = Object.keys(roman_conversion).map(Number);
key_list.sort(function(a, b){return b-a});
for (var i = 0; i < key_list.length; i++){ | output += roman_conversion[key_list[i]];
number -= key_list[i];
break;
}
}
}
return output;
}
| if (key_list[i] <= number){ | 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.deepEqual(candidate(1),"i");
assert.deepEqual(candidate(4),"iv");
assert.deepEqual(candidate(43),"xliii");
assert.deepEqual(candidate(90),"xc");
assert.deepEqual(candidate(94),"xciv");
assert.deepEqual(candidate(532),"dxxxii");
assert.deepEqual(candidate(900),"cm");
assert.deepEqual(candidate(994),"cmxciv");
assert.deepEqual(candidate(1000),"m");
}
test(); |
humaneval-HumanEval_124_valid_date.json-L28 | py | def valid_date(date: str) -> bool:
"""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. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
3. The months should not be less than 1 or higher than 12.
4. The date should be in the format: mm-dd-yyyy
>>> valid_date('03-11-2000')
True
>>> valid_date('15-01-2012')
False
>>> valid_date('04-0-2040')
False
>>> valid_date('06-04-2020')
True
>>> valid_date('06/04/2020')
False
"""
if not date:
return False
days_per_month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | if len(date_list) != 3:
return False
if date_list[0] < 1 or date_list[0] > 12:
return False
if date_list[1] < 1 or date_list[1] > days_per_month[date_list[0] - 1]:
return False
if len(str(date_list[2])) != 4:
return False
return True | date_list = [int(d) for d in date.split('-')] | def check(candidate):
assert candidate('03-11-2000') == True
assert candidate('15-01-2012') == False
assert candidate('04-0-2040') == False
assert candidate('06-04-2020') == True
assert candidate('01-01-2007') == True
assert candidate('03-32-2011') == False
assert candidate('') == False
assert candidate('04-31-3000') == False
assert candidate('06-06-2005') == True
assert candidate('21-31-2000') == False
assert candidate('04-12-2003') == True
assert candidate('04122003') == False
assert candidate('20030412') == False
assert candidate('2003-04') == False
assert candidate('2003-04-12') == False
assert candidate('04-2003') == False
def test_check():
check(valid_date)
test_check()
|
humaneval-HumanEval_40_triples_sum_to_zero.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 {
// triples_sum_to_zero takes an array array list of integers as an input.
// it returns true if there are three distinct elements in the array list that
// sum to zero, and false otherwise.
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)0l))))
// (false)
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)-2l, (long)1l))))
// (true)
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)7l))))
// (false)
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)-5l, (long)3l, (long)9l, (long)7l))))
// (true)
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l))))
// (false)
public static boolean triplesSumToZero(ArrayList<Long> l) {
if (l.size() < 3) {
return false;
}
ArrayList<Long> sortedList = new ArrayList<Long>(l); | for (int i = 0; i < sortedList.size() - 2; i++) {
int j = i + 1;
int k = sortedList.size() - 1;
while (j < k) {
long currSum = sortedList.get(i) + sortedList.get(j) + sortedList.get(k);
if (currSum == 0) {
return true;
} else if (currSum < 0) {
j++;
} else {
k--;
}
}
}
return false;
}
} | Collections.sort(sortedList); | }
public static void main(String[] args) {
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)0l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)-1l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)-2l, (long)1l)))) == (true));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)7l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)5l, (long)7l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)-5l, (long)3l, (long)9l, (long)7l)))) == (true));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)-100l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)100l, (long)3l, (long)5l, (long)-100l)))) == (false));
}
}
|
humaneval-HumanEval_82_prime_length.json-L21 | 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('orange')
False
"""
num = len(string)
if num > 1:
for i in range(2, num):
if (num % i) == 0:
return False
else:
return True | return False
pass
| else: | 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') == True
assert candidate('') == False
assert candidate('HI') == True
assert candidate('go') == True
assert candidate('gogo') == False
assert candidate('aaaaaaaaaaaaaaa') == False
assert candidate('Madam') == True
assert candidate('M') == False
assert candidate('0') == False
def test_check():
check(prime_length)
test_check()
|
humaneval-HumanEval_106_f.json-L27 | 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 * ... * i).
// Example:
// >>> f(5)
// [1, 2, 6, 24, 15]
function f(n){
var result = [];
var sum = 0;
var factorial = 1;
for(var i = 1; i <= n; i++){
if(i % 2 == 0){
for(var j = 1; j <= i; j++){
factorial *= j;
}
result.push(factorial);
factorial = 1;
}else{
for(var k = 1; k <= i; k++){
sum += k;
}
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_156_int_to_mini_roman.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 {
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// >>> intToMiniRoman((19l))
// ("xix")
// >>> intToMiniRoman((152l))
// ("clii")
// >>> intToMiniRoman((426l))
// ("cdxxvi")
public static String intToMiniRoman(long number) {
int num = (int) number;
String res = "";
if (num == 0)
return "";
while (num >= 1000) {
res += "m";
num -= 1000;
}
if (num >= 900) {
res += "cm";
num -= 900;
} | res += "d";
num -= 500;
}
if (num >= 400) {
res += "cd";
num -= 400;
}
while (num >= 100) {
res += "c";
num -= 100;
}
if (num >= 90) {
res += "xc";
num -= 90;
}
if (num >= 50) {
res += "l";
num -= 50;
}
if (num >= 40) {
res += "xl";
num -= 40;
}
while (num >= 10) {
res += "x";
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 += "i";
num -= 1;
}
return res;
}
} | if (num >= 500) { | }
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")));
assert(intToMiniRoman((1l)).equals(("i")));
assert(intToMiniRoman((4l)).equals(("iv")));
assert(intToMiniRoman((43l)).equals(("xliii")));
assert(intToMiniRoman((90l)).equals(("xc")));
assert(intToMiniRoman((94l)).equals(("xciv")));
assert(intToMiniRoman((532l)).equals(("dxxxii")));
assert(intToMiniRoman((900l)).equals(("cm")));
assert(intToMiniRoman((994l)).equals(("cmxciv")));
assert(intToMiniRoman((1000l)).equals(("m")));
}
}
|
humaneval-HumanEval_12_longest.json-L16 | py | from typing import List, Optional
def longest(strings: List[str]) -> Optional[str]:
""" Out of list of strings, return the longest one. Return the first one in case of multiple
strings of the same length. Return None in case the input list is empty.
>>> longest([])
None
>>> longest(['a', 'b', 'c'])
'a'
>>> longest(['a', 'bb', 'ccc'])
'ccc'
"""
if not strings:
return None
else: | for s in strings:
if len(s) > len(long):
long = s
return long
| long = strings[0] | def check(candidate):
assert candidate([]) == None
assert candidate(['x', 'y', 'z']) == 'x'
assert candidate(['x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc']) == 'zzzz'
def test_check():
check(longest)
test_check()
|
humaneval-HumanEval_56_correct_bracketing.json-L13 | 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){
var opens = 0; | if (brackets[i] === "<") {
opens++;
}
else if (brackets[i] === ">") {
opens--;
}
if (opens < 0) {
return false;
}
}
return opens === 0;
}
| for (var i = 0; i < brackets.length; i++) { | 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.deepEqual(candidate("<<<><>>>>"),false);
assert.deepEqual(candidate("><<>"),false);
assert.deepEqual(candidate("<"),false);
assert.deepEqual(candidate("<<<<"),false);
assert.deepEqual(candidate(">"),false);
assert.deepEqual(candidate("<<>"),false);
assert.deepEqual(candidate("<><><<><>><>><<>"),false);
assert.deepEqual(candidate("<><><<><>><>>><>"),false);
}
test(); |
humaneval-HumanEval_115_max_fill.json-L34 | js | //You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// >>> max_fill([[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], 1)
// 6
// Example 2:
// >>> max_fill([[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], 2)
// 5
// Example 3:
// >>> max_fill([[0, 0, 0], [0, 0, 0]], 5)
// 0
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
function max_fill(grid, capacity){
var maxFill = 0;
var sum = 0;
var c = 1;
var r = grid.length;
var c = grid[0].length;
for(var i = 0; i < r; i++){
sum = 0;
for(var j = 0; j < c; j++){
sum += grid[i][j];
}
maxFill += Math.ceil(sum/capacity); | return maxFill;
}
| } | const assert = require('node:assert');
function test() {
let candidate = max_fill;
assert.deepEqual(candidate([[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], 1),6);
assert.deepEqual(candidate([[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], 2),5);
assert.deepEqual(candidate([[0, 0, 0], [0, 0, 0]], 5),0);
assert.deepEqual(candidate([[1, 1, 1, 1], [1, 1, 1, 1]], 2),4);
assert.deepEqual(candidate([[1, 1, 1, 1], [1, 1, 1, 1]], 9),2);
}
test(); |
humaneval-HumanEval_33_sort_third.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 {
// 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 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.
// >>> sortThird((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))
// >>> sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)2l))))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)5l)))
public static ArrayList<Long> sortThird(ArrayList<Long> l) {
ArrayList<Long> l_r = new ArrayList<Long>();
ArrayList<Long> l_e = new ArrayList<Long>();
ArrayList<Long> l_s = new ArrayList<Long>();
for (int i = 0; i < l.size(); i++) {
if (i % 3 == 0) {
l_e.add(l.get(i));
} else {
l_r.add(l.get(i));
}
}
for (int i = 0; i < l_e.size(); i++) {
long min = l_e.get(i);
for (int j = i; j < l_e.size(); j++) {
if (l_e.get(j) < min) {
min = l_e.get(j);
l_e.set(j, l_e.get(i));
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));
}
}
return l_s;
}
} | } | }
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((new ArrayList<Long>(Arrays.asList((long)5l, (long)8l, (long)3l, (long)4l, (long)6l, (long)9l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)8l, (long)3l, (long)4l, (long)6l, (long)9l, (long)5l)))));
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)9l, (long)4l, (long)8l, (long)3l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)9l, (long)4l, (long)8l, (long)3l, (long)5l)))));
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)2l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)5l, (long)1l)))));
}
}
|
humaneval-HumanEval_146_specialFilter.json-L33 | 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 that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// >>> specialFilter((new ArrayList<Long>(Arrays.asList((long)15l, (long)-73l, (long)14l, (long)-15l))))
// (1l)
// >>> specialFilter((new ArrayList<Long>(Arrays.asList((long)33l, (long)-2l, (long)-3l, (long)45l, (long)21l, (long)109l))))
// (2l)
public static long specialFilter(ArrayList<Long> nums) {
class helper {
public long getFirstDigit(long n) {
long[] digits = getDigits(n);
return digits[0];
}
public long getLastDigit(long n) {
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;
} | return digits.stream().mapToLong(i -> i).toArray();
}
}
helper h = new helper();
return nums.stream().filter(x -> x > 10).filter(x -> {
long firstDigit = h.getFirstDigit(x);
long lastDigit = h.getLastDigit(x);
return firstDigit % 2 != 0 && lastDigit % 2 != 0;
}).count();
}
} | Collections.reverse(digits); | }
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 ArrayList<Long>(Arrays.asList((long)33l, (long)-2l, (long)-3l, (long)45l, (long)21l, (long)109l)))) == (2l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)43l, (long)-12l, (long)93l, (long)125l, (long)121l, (long)109l)))) == (4l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)71l, (long)-2l, (long)-33l, (long)75l, (long)21l, (long)19l)))) == (3l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)1l)))) == (0l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList()))) == (0l));
}
}
|
humaneval-HumanEval_98_count_upper.json-L11 | js | //Given a string s, count the number of uppercase vowels in even indices.
// For example:
// >>> count_upper("aBCdEf")
// 1
// >>> count_upper("abcdefg")
// 0
// >>> count_upper("dBBE")
// 0
function count_upper(s){
var index; | var vowel = ['A', 'E', 'I', 'O', 'U'];
for (index = 0; index < s.length; index += 2){
if (vowel.indexOf(s[index]) > -1){
result += 1;
}
}
return result;
} | var result = 0; | const assert = require('node:assert');
function test() {
let candidate = count_upper;
assert.deepEqual(candidate("aBCdEf"),1);
assert.deepEqual(candidate("abcdefg"),0);
assert.deepEqual(candidate("dBBE"),0);
assert.deepEqual(candidate("B"),0);
assert.deepEqual(candidate("U"),1);
assert.deepEqual(candidate(""),0);
assert.deepEqual(candidate("EEEE"),2);
}
test(); |
humaneval-HumanEval_115_max_fill.json-L31 | py | from typing import List
def max_fill(grid: List[List[int]], capacity: int) -> int:
"""
You are given a rectangular grid of wells. Each row represents a single well,
and each 1 in a row represents a single unit of water.
Each well has a corresponding bucket that can be used to extract water from it,
and all buckets have the same capacity.
Your task is to use the buckets to empty the wells.
Output the number of times you need to lower the buckets.
Example 1:
>>> max_fill([[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], 1)
6
Example 2:
>>> max_fill([[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], 2)
5
Example 3:
>>> max_fill([[0, 0, 0], [0, 0, 0]], 5)
0
Constraints:
* all wells have the same length
* 1 <= grid.length <= 10^2
* 1 <= grid[:,1].length <= 10^2
* grid[i][j] -> 0 | 1
* 1 <= capacity <= 10
"""
| for row in grid:
for i in range(0, len(row), capacity):
if 1 in row[i:i+capacity]:
times += 1
return times
| times = 0 | def check(candidate):
assert candidate([[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], 1) == 6
assert candidate([[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], 2) == 5
assert candidate([[0, 0, 0], [0, 0, 0]], 5) == 0
assert candidate([[1, 1, 1, 1], [1, 1, 1, 1]], 2) == 4
assert candidate([[1, 1, 1, 1], [1, 1, 1, 1]], 9) == 2
def test_check():
check(max_fill)
test_check()
|
humaneval-HumanEval_81_numerical_letter_grade.json-L49 | 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 can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// >>> grade_equation([4.0, 3, 1.7, 2, 3.5])
// ["A+", "B", "C-", "C", "A-"]
function numerical_letter_grade(grades){
var grades_array = [];
for (var i = 0; i < grades.length; i++){
if (grades[i] >= 4.0){
grades_array.push("A+");
}
else if (grades[i] > 3.7){
grades_array.push("A");
}
else if (grades[i] > 3.3){
grades_array.push("A-");
}
else if (grades[i] > 3.0){
grades_array.push("B+");
}
else if (grades[i] > 2.7){
grades_array.push("B");
}
else if (grades[i] > 2.3){
grades_array.push("B-");
}
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+");
}
else if (grades[i] > 0.7){
grades_array.push("D");
}
else if (grades[i] > 0.0){
grades_array.push("D-");
}
else if (grades[i] == 0.0){
grades_array.push("E");
}
}
return grades_array;
} | } | 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"]);
assert.deepEqual(candidate([1.0, 0.3, 1.5, 2.8, 3.3]),["D", "D-", "C-", "B", "B+"]);
assert.deepEqual(candidate([0.0, 0.7]),["E", "D-"]);
}
test(); |
humaneval-HumanEval_1_separate_paren_groups.json-L28 | 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 separate strings and return the array list of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// >>> separateParenGroups(("( ) (( )) (( )( ))"))
// (new ArrayList<String>(Arrays.asList((String)"()", (String)"(())", (String)"(()())")))
public static ArrayList<String> separateParenGroups(String paren_string) {
ArrayList<String> output = new ArrayList<String>();
StringBuffer temp = new StringBuffer();
int open_paren = 0;
for (int i = 0; i < paren_string.length(); i++) {
char c = paren_string.charAt(i);
if (c == '(') {
if (open_paren == 0) {
temp = new StringBuffer();
}
open_paren++;
temp.append(c);
} else if (c == ')') { | temp.append(c);
if (open_paren == 0) {
output.add(temp.toString());
}
}
}
return output;
}
} | open_paren--; | }
public static void main(String[] args) {
assert(separateParenGroups(("(()()) ((())) () ((())()())")).equals((new ArrayList<String>(Arrays.asList((String)"(()())", (String)"((()))", (String)"()", (String)"((())()())")))));
assert(separateParenGroups(("() (()) ((())) (((())))")).equals((new ArrayList<String>(Arrays.asList((String)"()", (String)"(())", (String)"((()))", (String)"(((())))")))));
assert(separateParenGroups(("(()(())((())))")).equals((new ArrayList<String>(Arrays.asList((String)"(()(())((())))")))));
assert(separateParenGroups(("( ) (( )) (( )( ))")).equals((new ArrayList<String>(Arrays.asList((String)"()", (String)"(())", (String)"(()())")))));
}
}
|
humaneval-HumanEval_137_compare_one.json-L47 | 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 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
>>> compare_one(1, '2,3')
'2,3'
>>> compare_one('5,1', '6')
'6'
>>> compare_one('1', 1)
None
"""
if isinstance(a, int) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, float) and isinstance(b, float):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, str) and isinstance(b, str):
a_tmp = a.replace(',', '.')
b_tmp = b.replace(',', '.')
if float(a_tmp) > float(b_tmp):
return a
elif float(a_tmp) < float(b_tmp):
return b
else:
return None
elif isinstance(a, int) and isinstance(b, float):
if a > b:
return a
elif a < b:
return b | return None
elif isinstance(a, float) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
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 = b.replace(',', '.')
if a > float(b_tmp):
return a
elif a < float(b_tmp):
return b
else:
return None
elif isinstance(a, str) and isinstance(b, float):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b | 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_check():
check(compare_one)
test_check()
|
humaneval-HumanEval_128_prod_signs.json-L26 | 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 arr.
Example:
>>> prod_signs([1, 2, 2, -4])
9
>>> prod_signs([0, 1])
0
>>> prod_signs([])
None
"""
def product(lst: List[int]) -> int:
out = 1
for item in lst:
out *= item
return out
if len(arr) == 0:
return None | sign_arr = []
for num in arr:
if num > 0:
sign_arr.append(1)
elif num < 0:
sign_arr.append(-1)
else:
sign_arr.append(0)
return sum(map(abs, arr)) * product(sign_arr) | else: | 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
assert candidate([-1, 1, 1, 0]) == 0
def test_check():
check(prod_signs)
test_check()
|
humaneval-HumanEval_44_change_base.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 {
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// >>> changeBase((8l), (3l))
// ("22")
// >>> changeBase((8l), (2l))
// ("1000")
// >>> changeBase((7l), (2l))
// ("111")
public static String changeBase(long x, long base) {
if (x<0 || base<2 || base>9) {
throw new IllegalArgumentException("bad input");
}
if (x==0) {
return "0";
}
StringBuilder sb = new StringBuilder();
while (x>0) {
sb.append(x%base);
x = x/base;
} | }
} | return sb.reverse().toString(); | }
public static void main(String[] args) {
assert(changeBase((8l), (3l)).equals(("22")));
assert(changeBase((9l), (3l)).equals(("100")));
assert(changeBase((234l), (2l)).equals(("11101010")));
assert(changeBase((16l), (2l)).equals(("10000")));
assert(changeBase((8l), (2l)).equals(("1000")));
assert(changeBase((7l), (2l)).equals(("111")));
assert(changeBase((2l), (3l)).equals(("2")));
assert(changeBase((3l), (4l)).equals(("3")));
assert(changeBase((4l), (5l)).equals(("4")));
assert(changeBase((5l), (6l)).equals(("5")));
assert(changeBase((6l), (7l)).equals(("6")));
assert(changeBase((7l), (8l)).equals(("7")));
}
}
|
humaneval-HumanEval_85_add.json-L16 | 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 non-empty array list of integers lst. add the even elements that are at odd indices..
// Examples:
// >>> add((new ArrayList<Long>(Arrays.asList((long)4l, (long)2l, (long)6l, (long)7l))))
// (2l)
public static long add(ArrayList<Long> lst) {
long sum = 0;
for (int i = 0; i < lst.size(); i++) { | sum += lst.get(i);
}
}
return sum;
}
} | if (i % 2 == 1 && lst.get(i) % 2 == 0) { | }
public static void main(String[] args) {
assert(add((new ArrayList<Long>(Arrays.asList((long)4l, (long)88l)))) == (88l));
assert(add((new ArrayList<Long>(Arrays.asList((long)4l, (long)5l, (long)6l, (long)7l, (long)2l, (long)122l)))) == (122l));
assert(add((new ArrayList<Long>(Arrays.asList((long)4l, (long)0l, (long)6l, (long)7l)))) == (0l));
assert(add((new ArrayList<Long>(Arrays.asList((long)4l, (long)4l, (long)6l, (long)8l)))) == (12l));
}
}
|
humaneval-HumanEval_75_is_multiply_prime.json-L19 | py | def is_multiply_prime(a: int) -> bool:
"""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
"""
n = a
d = 2
prime_factors = []
while d * d <= n:
if n % d == 0:
prime_factors.append(d)
n //= d
else:
d += 1 | prime_factors.append(n)
if len(prime_factors) == 3:
return True
else:
return False
| if n > 1: | def check(candidate):
assert candidate(5) == False
assert candidate(30) == True
assert candidate(8) == True
assert candidate(10) == False
assert candidate(125) == True
assert candidate(105) == True
assert candidate(126) == False
assert candidate(729) == False
assert candidate(891) == False
assert candidate(1001) == True
def test_check():
check(is_multiply_prime)
test_check()
|
humaneval-HumanEval_148_bf.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 {
// 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 a pair containing all planets whose orbits are
// located between the orbit of planet1 and the orbit of planet2, sorted by
// the proximity to the sun.
// The function should return an empty pair if planet1 or planet2
// are not correct planet names.
// Examples
// >>> bf(("Jupiter"), ("Neptune"))
// (new ArrayList<String>(Arrays.asList((String)"Saturn", (String)"Uranus")))
// >>> bf(("Earth"), ("Mercury"))
// (ArrayList<String>("Venus"))
// >>> bf(("Mercury"), ("Uranus"))
// (new ArrayList<String>(Arrays.asList((String)"Venus", (String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn")))
public static ArrayList<String> bf(String planet1, String planet2) {
ArrayList<String> planets = new ArrayList<String>(Arrays.asList((String)"Mercury", (String)"Venus", (String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn", (String)"Uranus", (String)"Neptune"));
int indexPlanet1 = planets.indexOf(planet1);
int indexPlanet2 = planets.indexOf(planet2);
int indexMin = 0;
int indexMax = 0;
if (indexPlanet1 >= 0 && indexPlanet2 >= 0) {
if (indexPlanet1 < indexPlanet2) {
indexMin = indexPlanet1;
indexMax = indexPlanet2;
} else {
indexMin = indexPlanet2;
indexMax = indexPlanet1;
}
ArrayList<String> planetsInBetween = new ArrayList<String>();
for (int i = indexMin + 1; i < indexMax; i++) { | }
return planetsInBetween;
} else {
return new ArrayList<String>();
}
}
} | planetsInBetween.add(planets.get(i)); | }
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")).equals((new ArrayList<String>(Arrays.asList((String)"Venus", (String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn")))));
assert(bf(("Neptune"), ("Venus")).equals((new ArrayList<String>(Arrays.asList((String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn", (String)"Uranus")))));
assert(bf(("Earth"), ("Earth")).equals((new ArrayList<String>(Arrays.asList()))));
assert(bf(("Mars"), ("Earth")).equals((new ArrayList<String>(Arrays.asList()))));
assert(bf(("Jupiter"), ("Makemake")).equals((new ArrayList<String>(Arrays.asList()))));
}
}
|
humaneval-HumanEval_5_intersperse.json-L14 | 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 !== numbers.length - 1){
result.push(delimeter);
}
} | }
| return result; | 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_91_is_bored.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'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 the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// >>> isBored(("Hello world"))
// (0l)
// >>> isBored(("The sky is blue. The sun is shining. I love this weather"))
// (1l)
public static long isBored(String S) {
long boredoms = 0;
String[] sentences = S.split("\\.\\s|\\?\\s|\\!\\s");
for (String sentence : sentences) {
String[] words = sentence.split("\\s");
if (words.length > 0 && words[0].equals("I")) {
boredoms++;
}
} | }
} | 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));
assert(isBored(("You and I are going for a walk")) == (0l));
}
}
|
humaneval-HumanEval_78_hex_key.json-L32 | js | //You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// >>> hex_key("AB")
// 1
// >>> hex_key("1077E")
// 2
// >>> hex_key("ABED1A33")
// 4
// >>> hex_key("123456789ABCDEF0")
// 6
// >>> hex_key("2020")
// 2
function hex_key(num){
let result = 0;
let hexadecimals = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
let primes = ['2', '3', '5', '7', 'B', 'D'];
for(let x = 0; x < num.length; x++){
if(primes.includes(num[x])){
result += 1;
}
}
return result; | } | const assert = require('node:assert');
function test() {
let candidate = hex_key;
assert.deepEqual(candidate("AB"),1);
assert.deepEqual(candidate("1077E"),2);
assert.deepEqual(candidate("ABED1A33"),4);
assert.deepEqual(candidate("2020"),2);
assert.deepEqual(candidate("123456789ABCDEF0"),6);
assert.deepEqual(candidate("112233445566778899AABBCCDDEEFF00"),12);
}
test(); |
|
humaneval-HumanEval_139_special_factorial.json-L19 | py | def special_factorial(n: int) -> int:
"""The Brazilian factorial is defined as:
brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
where n > 0
For example:
>>> special_factorial(4)
288
The function will receive an integer as input and should return the special
factorial of this integer.
"""
def factorial(n):
if n <= 1:
return 1
else:
return n * factorial(n-1)
if n <= 1: | else:
return n * special_factorial(n-1) * factorial(n-1)
| return 1 | def check(candidate):
assert candidate(4) == 288
assert candidate(5) == 34560
assert candidate(7) == 125411328000
assert candidate(1) == 1
def test_check():
check(special_factorial)
test_check()
|
humaneval-HumanEval_113_odd_count.json-L16 | py | from typing import List
def odd_count(lst: List[str]) -> List[str]:
"""Given a list of strings, where each string consists of only digits, return a list.
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'])
['the number of odd elements 4n the str4ng 4 of the 4nput.']
>>> odd_count(['3', '11111111'])
['the number of odd elements 1n the str1ng 1 of the 1nput.', 'the number of odd elements 8n the str8ng 8 of the 8nput.']
"""
output = []
for i in range(len(lst)): | for j in range(len(lst[i])):
if int(lst[i][j]) % 2 != 0:
count += 1
output.append(f"the number of odd elements {count}n the str{count}ng {count} of the {count}nput.")
return output
| count = 0 | def check(candidate):
assert candidate(['1234567']) == ['the number of odd elements 4n the str4ng 4 of the 4nput.']
assert candidate(['3', '11111111']) == ['the number of odd elements 1n the str1ng 1 of the 1nput.', 'the number of odd elements 8n the str8ng 8 of the 8nput.']
assert candidate(['271', '137', '314']) == ['the number of odd elements 2n the str2ng 2 of the 2nput.', 'the number of odd elements 3n the str3ng 3 of the 3nput.', 'the number of odd elements 2n the str2ng 2 of the 2nput.']
def test_check():
check(odd_count)
test_check()
|
humaneval-HumanEval_73_smallest_change.json-L17 | py | from typing import List
def smallest_change(arr: List[int]) -> int:
"""
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, 5, 4, 7, 9, 6])
4
>>> smallest_change([1, 2, 3, 4, 3, 2, 2])
1
>>> smallest_change([1, 2, 3, 2, 1])
0
"""
| end = len(arr) - 1
count = 0
while start < end:
if arr[start] != arr[end]:
count += 1
start += 1
end -= 1
return count
| start = 0 | def check(candidate):
assert candidate([1, 2, 3, 5, 4, 7, 9, 6]) == 4
assert candidate([1, 2, 3, 4, 3, 2, 2]) == 1
assert candidate([1, 4, 2]) == 1
assert candidate([1, 4, 4, 2]) == 1
assert candidate([1, 2, 3, 2, 1]) == 0
assert candidate([3, 1, 1, 3]) == 0
assert candidate([1]) == 0
assert candidate([0, 1]) == 1
def test_check():
check(smallest_change)
test_check()
|
humaneval-HumanEval_35_max_element.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 {
// Return maximum element in the array list.
// >>> maxElement((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (3l)
// >>> maxElement((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)-5l, (long)2l, (long)-3l, (long)3l, (long)9l, (long)0l, (long)123l, (long)1l, (long)-10l))))
// (123l)
public static long maxElement(ArrayList<Long> l) {
Long max = Long.MIN_VALUE;
for (int i = 0; i < l.size(); i += 1) {
if (l.get(i) > max) {
max = l.get(i);
}
}
return max; | } | } | }
public static void main(String[] args) {
assert(maxElement((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))) == (3l));
assert(maxElement((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)-5l, (long)2l, (long)-3l, (long)3l, (long)9l, (long)0l, (long)124l, (long)1l, (long)-10l)))) == (124l));
}
}
|
humaneval-HumanEval_136_largest_smallest_integers.json-L19 | 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 negative or positive integers, return them as None.
Examples:
>>> largest_smallest_integers([2, 4, 1, 3, 5, 7])
(None, 1)
>>> largest_smallest_integers([])
(None, None)
>>> largest_smallest_integers([0])
(None, None)
"""
smallest_positive = None | for num in lst:
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)
| largest_negative = None | 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 candidate([]) == (None, None)
assert candidate([0]) == (None, None)
assert candidate([-1, -3, -5, -6]) == (-1, None)
assert candidate([-1, -3, -5, -6, 0]) == (-1, None)
assert candidate([-6, -4, -4, -3, 1]) == (-3, 1)
assert candidate([-6, -4, -4, -3, -100, 1]) == (-3, 1)
def test_check():
check(largest_smallest_integers)
test_check()
|
humaneval-HumanEval_137_compare_one.json-L37 | 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 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
>>> compare_one(1, '2,3')
'2,3'
>>> compare_one('5,1', '6')
'6'
>>> compare_one('1', 1)
None
"""
if isinstance(a, int) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, float) and isinstance(b, float):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, str) and isinstance(b, str):
a_tmp = a.replace(',', '.')
b_tmp = b.replace(',', '.')
if float(a_tmp) > float(b_tmp): | elif float(a_tmp) < float(b_tmp):
return b
else:
return None
elif isinstance(a, int) and isinstance(b, float):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, float) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
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 = b.replace(',', '.')
if a > float(b_tmp):
return a
elif a < float(b_tmp):
return b
else:
return None
elif isinstance(a, str) and isinstance(b, float):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b | return a | 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_check():
check(compare_one)
test_check()
|
humaneval-HumanEval_29_filter_by_prefix.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 {
// Filter an input array list of strings only for ones that start with a given prefix.
// >>> filterByPrefix((new ArrayList<String>(Arrays.asList())), ("a"))
// (new ArrayList<String>(Arrays.asList()))
// >>> filterByPrefix((new ArrayList<String>(Arrays.asList((String)"abc", (String)"bcd", (String)"cde", (String)"array"))), ("a"))
// (new ArrayList<String>(Arrays.asList((String)"abc", (String)"array")))
public static ArrayList<String> filterByPrefix(ArrayList<String> strings, String prefix) {
| }
} | return (ArrayList<String>)strings.stream().filter(s -> s.startsWith(prefix)).collect(Collectors.toList()); | }
public static void main(String[] args) {
assert(filterByPrefix((new ArrayList<String>(Arrays.asList())), ("john")).equals((new ArrayList<String>(Arrays.asList()))));
assert(filterByPrefix((new ArrayList<String>(Arrays.asList((String)"xxx", (String)"asd", (String)"xxy", (String)"john doe", (String)"xxxAAA", (String)"xxx"))), ("xxx")).equals((new ArrayList<String>(Arrays.asList((String)"xxx", (String)"xxxAAA", (String)"xxx")))));
}
}
|
humaneval-HumanEval_96_count_up_to.json-L17 | 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]
// >>> count_up_to(1)
// []
// >>> count_up_to(18)
// [2, 3, 5, 7, 11, 13, 17]
function count_up_to(n){
| var output = [2];
for (var i = 3; i < n; i += 2){
var prime = true;
for (var j = 3; j < i; j += 2){
if (i % j === 0){
prime = false;
break;
}
}
if (prime) output.push(i);
}
return output;
}
| if (n < 2) return []; | 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.deepEqual(candidate(22),[2, 3, 5, 7, 11, 13, 17, 19]);
assert.deepEqual(candidate(1),[]);
assert.deepEqual(candidate(18),[2, 3, 5, 7, 11, 13, 17]);
assert.deepEqual(candidate(47),[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]);
assert.deepEqual(candidate(101),[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]);
}
test(); |
humaneval-HumanEval_12_longest.json-L14 | js | //Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return undefined in case the input array is empty.
// >>> longest([])
// undefined
// >>> longest(["a", "b", "c"])
// "a"
// >>> longest(["a", "bb", "ccc"])
// "ccc"
function longest(strings){
var result;
if (strings.length === 0) {
return undefined;
} | if (!result || strings[i].length > result.length) {
result = strings[i];
}
}
return result;
}
| for (var i = 0; i < strings.length; i++) { | const assert = require('node:assert');
function test() {
let candidate = longest;
assert.deepEqual(candidate([]),undefined);
assert.deepEqual(candidate(["x", "y", "z"]),"x");
assert.deepEqual(candidate(["x", "yyy", "zzzz", "www", "kkkk", "abc"]),"zzzz");
}
test(); |
humaneval-HumanEval_142_sum_squares.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 will take an array array list of integers. For all entries in the array list, 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 list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries.
// Examples:
// >>> lst
// (long)new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))
// >>> lst
// (long)new ArrayList<Long>(Arrays.asList())
// >>> lst
// (long)new ArrayList<Long>(Arrays.asList((long)-1l, (long)-5l, (long)2l, (long)-1l, (long)-5l))
public static long sumSquares(ArrayList<Long> lst) {
int sz = lst.size();
for (int i = 0; i < sz; i++) {
if (i % 3 == 0) {
lst.set(i, lst.get(i) * lst.get(i));
} else if (i % 4 == 0) {
lst.set(i, lst.get(i) * lst.get(i) * lst.get(i));
}
}
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));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l, (long)1l, (long)1l, (long)1l, (long)1l, (long)1l)))) == (9l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-1l, (long)-1l, (long)-1l, (long)-1l, (long)-1l, (long)-1l, (long)-1l, (long)-1l)))) == (-3l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)0l)))) == (0l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-5l, (long)2l, (long)-1l, (long)-5l)))) == (-126l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)-56l, (long)-99l, (long)1l, (long)0l, (long)-2l)))) == (3030l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)-1l, (long)0l, (long)0l, (long)0l, (long)0l, (long)0l, (long)0l, (long)0l, (long)-1l)))) == (0l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)-16l, (long)-9l, (long)-2l, (long)36l, (long)36l, (long)26l, (long)-20l, (long)25l, (long)-40l, (long)20l, (long)-4l, (long)12l, (long)-26l, (long)35l, (long)37l)))) == (-14196l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-3l, (long)17l, (long)-1l, (long)-15l, (long)13l, (long)-1l, (long)14l, (long)-14l, (long)-12l, (long)-5l, (long)14l, (long)-14l, (long)6l, (long)13l, (long)11l, (long)16l, (long)16l, (long)4l, (long)10l)))) == (-1448l));
}
}
|
humaneval-HumanEval_104_unique_digits.json-L19 | py | from typing import List
def unique_digits(x: List[int]) -> List[int]:
"""Given a list of positive integers x. return a sorted list of all
elements that hasn't any even digit.
Note: Returned list should be sorted in increasing order.
For example:
>>> unique_digits([15, 33, 1422, 1])
[1, 15, 33]
>>> unique_digits([152, 323, 1422, 10])
[]
"""
s=[]
for i in x:
temp=i
while temp: | s.append(i)
break
temp=temp//10
for i in s:
x.remove(i)
return sorted(x)
| if temp%2==0: | def check(candidate):
assert candidate([15, 33, 1422, 1]) == [1, 15, 33]
assert candidate([152, 323, 1422, 10]) == []
assert candidate([12345, 2033, 111, 151]) == [111, 151]
assert candidate([135, 103, 31]) == [31, 135]
def test_check():
check(unique_digits)
test_check()
|
humaneval-HumanEval_44_change_base.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 {
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// >>> changeBase((8l), (3l))
// ("22")
// >>> changeBase((8l), (2l))
// ("1000")
// >>> changeBase((7l), (2l))
// ("111")
public static String changeBase(long x, long base) {
if (x<0 || base<2 || base>9) {
throw new IllegalArgumentException("bad input");
}
if (x==0) {
return "0"; | StringBuilder sb = new StringBuilder();
while (x>0) {
sb.append(x%base);
x = x/base;
}
return sb.reverse().toString();
}
} | } | }
public static void main(String[] args) {
assert(changeBase((8l), (3l)).equals(("22")));
assert(changeBase((9l), (3l)).equals(("100")));
assert(changeBase((234l), (2l)).equals(("11101010")));
assert(changeBase((16l), (2l)).equals(("10000")));
assert(changeBase((8l), (2l)).equals(("1000")));
assert(changeBase((7l), (2l)).equals(("111")));
assert(changeBase((2l), (3l)).equals(("2")));
assert(changeBase((3l), (4l)).equals(("3")));
assert(changeBase((4l), (5l)).equals(("4")));
assert(changeBase((5l), (6l)).equals(("5")));
assert(changeBase((6l), (7l)).equals(("6")));
assert(changeBase((7l), (8l)).equals(("7")));
}
}
|
humaneval-HumanEval_70_strange_sort_list.json-L20 | 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, 3, 4])
[1, 4, 2, 3]
>>> strange_sort_list([5, 5, 5, 5])
[5, 5, 5, 5]
>>> strange_sort_list([])
[]
"""
lst = sorted(lst)
out = []
while lst: | if not lst:
break
out.append(lst.pop())
return out | out.append(lst.pop(0)) | 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 candidate([]) == []
assert candidate([1, 2, 3, 4, 5, 6, 7, 8]) == [1, 8, 2, 7, 3, 6, 4, 5]
assert candidate([0, 2, 2, 2, 5, 5, -5, -5]) == [-5, 5, -5, 5, 0, 2, 2, 2]
assert candidate([111111]) == [111111]
def test_check():
check(strange_sort_list)
test_check()
|
humaneval-HumanEval_104_unique_digits.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 an array array list of positive integers x. return a sorted array list of all
// elements that hasn't any even digit.
// Note: Returned array list should be sorted in increasing order.
// For example:
// >>> uniqueDigits((new ArrayList<Long>(Arrays.asList((long)15l, (long)33l, (long)1422l, (long)1l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)15l, (long)33l)))
// >>> uniqueDigits((new ArrayList<Long>(Arrays.asList((long)152l, (long)323l, (long)1422l, (long)10l))))
// (new ArrayList<Long>(Arrays.asList()))
public static ArrayList<Long> uniqueDigits(ArrayList<Long> x) {
ArrayList<Long> b = new ArrayList<Long>();
for (int i = 0; i < x.size(); i++) {
if (x.get(i) < 0) {
x.set(i, x.get(i)*(long)-1);
}
boolean unique = true;
long z = x.get(i); | long y = z % 10;
if (y % 2 == 0) {
unique = false;
break;
}
z = z / 10;
}
if (unique) {
b.add(x.get(i));
}
}
Collections.sort(b);
return b;
}
} | while (z > 0) { | }
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, (long)1422l, (long)10l)))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)12345l, (long)2033l, (long)111l, (long)151l)))).equals((new ArrayList<Long>(Arrays.asList((long)111l, (long)151l)))));
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)135l, (long)103l, (long)31l)))).equals((new ArrayList<Long>(Arrays.asList((long)31l, (long)135l)))));
}
}
|
humaneval-HumanEval_134_check_if_last_char_is_a_letter.json-L35 | 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 part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// >>> checkIfLastCharIsALetter(("apple pie"))
// (false)
// >>> checkIfLastCharIsALetter(("apple pi e"))
// (true)
// >>> checkIfLastCharIsALetter(("apple pi e "))
// (false)
// >>> checkIfLastCharIsALetter((""))
// (false)
public static boolean checkIfLastCharIsALetter(String txt) {
if (txt.length() == 0) {
return false;
}
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(checkIfLastCharIsALetter(("Pumpkin pie ")) == (false));
assert(checkIfLastCharIsALetter(("Pumpkin pie 1")) == (false));
assert(checkIfLastCharIsALetter(("")) == (false));
assert(checkIfLastCharIsALetter(("eeeee e ")) == (false));
assert(checkIfLastCharIsALetter(("apple pie")) == (false));
assert(checkIfLastCharIsALetter(("apple pi e ")) == (false));
}
}
|
humaneval-HumanEval_29_filter_by_prefix.json-L9 | 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(prefix); | }
| }); | 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_33_sort_third.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 {
// 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 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.
// >>> sortThird((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))
// >>> sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)2l))))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)5l)))
public static ArrayList<Long> sortThird(ArrayList<Long> l) {
ArrayList<Long> l_r = new ArrayList<Long>();
ArrayList<Long> l_e = new ArrayList<Long>();
ArrayList<Long> l_s = new ArrayList<Long>();
for (int i = 0; i < l.size(); i++) {
if (i % 3 == 0) {
l_e.add(l.get(i));
} else {
l_r.add(l.get(i));
}
}
for (int i = 0; i < l_e.size(); i++) {
long min = l_e.get(i);
for (int j = i; j < l_e.size(); j++) {
if (l_e.get(j) < min) {
min = l_e.get(j);
l_e.set(j, l_e.get(i));
l_e.set(i, min);
}
}
} | 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));
}
}
return l_s;
}
} | int j = 0; | }
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((new ArrayList<Long>(Arrays.asList((long)5l, (long)8l, (long)3l, (long)4l, (long)6l, (long)9l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)8l, (long)3l, (long)4l, (long)6l, (long)9l, (long)5l)))));
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)9l, (long)4l, (long)8l, (long)3l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)9l, (long)4l, (long)8l, (long)3l, (long)5l)))));
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)2l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)5l, (long)1l)))));
}
}
|
humaneval-HumanEval_105_by_length.json-L19 | 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", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// If the array is empty, return an empty array:
// >>> by_length([])
// []
// If the array has any strange number ignore it:
// >>> by_length([1, -1, 55])
// ["One"]
function by_length(arr){
var arr2 = [];
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");
}
else if(num == 2){
arr3.push("Two");
}
else if(num == 3){
arr3.push("Three");
}
else if(num == 4){
arr3.push("Four");
}
else if(num == 5){
arr3.push("Five");
}
else if(num == 6){
arr3.push("Six");
}
else if(num == 7){
arr3.push("Seven");
}
else if(num == 8){
arr3.push("Eight");
}
else if(num == 9){
arr3.push("Nine");
}
}
return arr3;
} | } | 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(candidate([1, -1, 3, 2]),["Three", "Two", "One"]);
assert.deepEqual(candidate([9, 4, 8]),["Nine", "Eight", "Four"]);
}
test(); |
humaneval-HumanEval_129_minPath.json-L52 | 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 each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// >>> minPath([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3)
// [1, 2, 1]
// >>> minPath([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1)
// [1]
function minPath(grid, k){
let n = grid.length;
let path = [];
let startCell = grid[0][0];
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 x = null;
let y = null;
for(let i = 0; i < n; i++){
for(let j = 0; j < n; j++){
if(grid[i][j] === currCell){
x = i;
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){
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 = curr;
}
}
currCell = nextCell;
}
return path;
} | } | 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, 15, 16]], 4),[1, 2, 1, 2]);
assert.deepEqual(candidate([[6, 4, 13, 10], [5, 7, 12, 1], [3, 16, 11, 15], [8, 14, 9, 2]], 7),[1, 10, 1, 10, 1, 10, 1]);
assert.deepEqual(candidate([[8, 14, 9, 2], [6, 4, 13, 15], [5, 7, 1, 12], [3, 10, 11, 16]], 5),[1, 7, 1, 7, 1]);
assert.deepEqual(candidate([[11, 8, 7, 2], [5, 16, 14, 4], [9, 3, 15, 6], [12, 13, 10, 1]], 9),[1, 6, 1, 6, 1, 6, 1, 6, 1]);
assert.deepEqual(candidate([[12, 13, 10, 1], [9, 3, 15, 6], [5, 16, 14, 4], [11, 8, 7, 2]], 12),[1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6]);
assert.deepEqual(candidate([[2, 7, 4], [3, 1, 5], [6, 8, 9]], 8),[1, 3, 1, 3, 1, 3, 1, 3]);
assert.deepEqual(candidate([[6, 1, 5], [3, 8, 9], [2, 7, 4]], 8),[1, 5, 1, 5, 1, 5, 1, 5]);
assert.deepEqual(candidate([[1, 2], [3, 4]], 10),[1, 2, 1, 2, 1, 2, 1, 2, 1, 2]);
assert.deepEqual(candidate([[1, 3], [3, 2]], 10),[1, 3, 1, 3, 1, 3, 1, 3, 1, 3]);
}
test(); |
humaneval-HumanEval_53_add.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 {
// Add two numbers x and y
// >>> add((2l), (3l))
// (5l)
// >>> add((5l), (7l))
// (12l)
public static long add(long x, long y) {
return x + y;
} | } | }
public static void main(String[] args) {
assert(add((0l), (1l)) == (1l));
assert(add((1l), (0l)) == (1l));
assert(add((2l), (3l)) == (5l));
assert(add((5l), (7l)) == (12l));
assert(add((7l), (5l)) == (12l));
}
}
|
|
humaneval-HumanEval_96_count_up_to.json-L28 | 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 numbers and less than n.
// for example:
// >>> countUpTo((5l))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l)))
// >>> countUpTo((11l))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)5l, (long)7l)))
// >>> countUpTo((0l))
// (new ArrayList<Long>(Arrays.asList()))
// >>> countUpTo((20l))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)5l, (long)7l, (long)11l, (long)13l, (long)17l, (long)19l)))
// >>> countUpTo((1l))
// (new ArrayList<Long>(Arrays.asList()))
// >>> countUpTo((18l))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)5l, (long)7l, (long)11l, (long)13l, (long)17l)))
public static ArrayList<Long> countUpTo(long n) {
ArrayList<Long> arrayList = new ArrayList<Long>();
for (long i = 2l; i < n; i++) {
boolean isPrime = true; | if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
arrayList.add(i);
}
}
return arrayList;
}
} | for (long j = 2l; j < i; j++) { | }
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((long)2l, (long)3l, (long)5l)))));
assert(countUpTo((10l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)5l, (long)7l)))));
assert(countUpTo((0l)).equals((new ArrayList<Long>(Arrays.asList()))));
assert(countUpTo((22l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)5l, (long)7l, (long)11l, (long)13l, (long)17l, (long)19l)))));
assert(countUpTo((1l)).equals((new ArrayList<Long>(Arrays.asList()))));
assert(countUpTo((18l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)5l, (long)7l, (long)11l, (long)13l, (long)17l)))));
assert(countUpTo((47l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)5l, (long)7l, (long)11l, (long)13l, (long)17l, (long)19l, (long)23l, (long)29l, (long)31l, (long)37l, (long)41l, (long)43l)))));
assert(countUpTo((101l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)5l, (long)7l, (long)11l, (long)13l, (long)17l, (long)19l, (long)23l, (long)29l, (long)31l, (long)37l, (long)41l, (long)43l, (long)47l, (long)53l, (long)59l, (long)61l, (long)67l, (long)71l, (long)73l, (long)79l, (long)83l, (long)89l, (long)97l)))));
}
}
|
humaneval-HumanEval_147_get_max_triples.json-L27 | js | //You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// >>> get_max_triples(5)
// 1
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
function get_max_triples(n){
let result = 0;
let arr = [];
for(let i = 1; i<=n; i++){
arr.push(i*i-i+1);
}
for(let i = 0; i<arr.length; i++){
for(let j = i+1; j<arr.length; j++){
for(let k = j+1; k<arr.length; k++){
if((arr[i]+arr[j]+arr[k])%3 === 0){
result++;
}
}
}
}
return result; | } | const assert = require('node:assert');
function test() {
let candidate = get_max_triples;
assert.deepEqual(candidate(5),1);
assert.deepEqual(candidate(6),4);
assert.deepEqual(candidate(10),36);
assert.deepEqual(candidate(100),53361);
}
test(); |
|
humaneval-HumanEval_101_words_string.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 {
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array array list of the words.
// For example:
// >>> wordsString(("Hi, my name is John"))
// (new ArrayList<String>(Arrays.asList((String)"Hi", (String)"my", (String)"name", (String)"is", (String)"John")))
// >>> wordsString(("One, two, three, four, five, six"))
// (new ArrayList<String>(Arrays.asList((String)"One", (String)"two", (String)"three", (String)"four", (String)"five", (String)"six")))
public static ArrayList<String> wordsString(String s) {
ArrayList<String> al = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(s, " , "); | al.add(st.nextToken());
}
return al;
}
} | while (st.hasMoreTokens()) { | }
public static void main(String[] args) {
assert(wordsString(("Hi, my name is John")).equals((new ArrayList<String>(Arrays.asList((String)"Hi", (String)"my", (String)"name", (String)"is", (String)"John")))));
assert(wordsString(("One, two, three, four, five, six")).equals((new ArrayList<String>(Arrays.asList((String)"One", (String)"two", (String)"three", (String)"four", (String)"five", (String)"six")))));
assert(wordsString(("Hi, my name")).equals((new ArrayList<String>(Arrays.asList((String)"Hi", (String)"my", (String)"name")))));
assert(wordsString(("One,, two, three, four, five, six,")).equals((new ArrayList<String>(Arrays.asList((String)"One", (String)"two", (String)"three", (String)"four", (String)"five", (String)"six")))));
assert(wordsString(("")).equals((new ArrayList<String>(Arrays.asList()))));
assert(wordsString(("ahmed , gamal")).equals((new ArrayList<String>(Arrays.asList((String)"ahmed", (String)"gamal")))));
}
}
|
humaneval-HumanEval_53_add.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 {
// Add two numbers x and y
// >>> add((2l), (3l))
// (5l)
// >>> add((5l), (7l))
// (12l)
public static long add(long x, long y) {
| }
} | return x + y; | }
public static void main(String[] args) {
assert(add((0l), (1l)) == (1l));
assert(add((1l), (0l)) == (1l));
assert(add((2l), (3l)) == (5l));
assert(add((5l), (7l)) == (12l));
assert(add((7l), (5l)) == (12l));
}
}
|
humaneval-HumanEval_129_minPath.json-L46 | py | from typing import List
def minPath(grid: List[List[int]], k: int) -> List[int]:
"""
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 each step you can move to any of the neighbor cells,
in other words, you can go to cells which share an edge with you current
cell.
Please note that a path of length k means visiting exactly k cells (not
necessarily distinct).
You CANNOT go off the grid.
A path A (of length k) is considered less than a path B (of length k) if
after making the ordered lists of the values on the cells that A and B go
through (let's call them lst_A and lst_B), lst_A is lexicographically less
than lst_B, in other words, there exist an integer index i (1 <= i <= k)
such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
lst_A[j] = lst_B[j].
It is guaranteed that the answer is unique.
Return an ordered list of the values on the cells that the minimum path go through.
Examples:
>>> minPath([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3)
[1, 2, 1]
>>> minPath([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1)
[1]
"""
min_val = float('inf')
for i in range(len(grid)):
for j in range(len(grid[0])):
if grid[i][j] < min_val:
min_val = grid[i][j]
row = i
col = j
path = [min_val]
while len(path) < k:
min_val = float('inf')
for i, j in (row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1):
if 0 <= i < len(grid) and 0 <= j < len(grid[0]) and grid[i][j] < min_val:
min_val = grid[i][j]
row = i | path.append(min_val)
return path | col = j | def check(candidate):
assert candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3) == [1, 2, 1]
assert candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1) == [1]
assert candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], 4) == [1, 2, 1, 2]
assert candidate([[6, 4, 13, 10], [5, 7, 12, 1], [3, 16, 11, 15], [8, 14, 9, 2]], 7) == [1, 10, 1, 10, 1, 10, 1]
assert candidate([[8, 14, 9, 2], [6, 4, 13, 15], [5, 7, 1, 12], [3, 10, 11, 16]], 5) == [1, 7, 1, 7, 1]
assert candidate([[11, 8, 7, 2], [5, 16, 14, 4], [9, 3, 15, 6], [12, 13, 10, 1]], 9) == [1, 6, 1, 6, 1, 6, 1, 6, 1]
assert candidate([[12, 13, 10, 1], [9, 3, 15, 6], [5, 16, 14, 4], [11, 8, 7, 2]], 12) == [1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6]
assert candidate([[2, 7, 4], [3, 1, 5], [6, 8, 9]], 8) == [1, 3, 1, 3, 1, 3, 1, 3]
assert candidate([[6, 1, 5], [3, 8, 9], [2, 7, 4]], 8) == [1, 5, 1, 5, 1, 5, 1, 5]
assert candidate([[1, 2], [3, 4]], 10) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
assert candidate([[1, 3], [3, 2]], 10) == [1, 3, 1, 3, 1, 3, 1, 3, 1, 3]
def test_check():
check(minPath)
test_check()
|
humaneval-HumanEval_152_compare.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 {
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two array array lists of scores and guesses of equal length, where each index shows a match.
// Return an array array list of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// >>> compare((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)1l))), (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)2l, (long)-2l))))
// (new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l, (long)0l, (long)3l, (long)3l)))
// >>> compare((new ArrayList<Long>(Arrays.asList((long)0l, (long)5l, (long)0l, (long)0l, (long)0l, (long)4l))), (new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)1l, (long)0l, (long)0l, (long)-2l))))
// (new ArrayList<Long>(Arrays.asList((long)4l, (long)4l, (long)1l, (long)0l, (long)0l, (long)6l)))
public static ArrayList<Long> compare(ArrayList<Long> game, ArrayList<Long> guess) {
ArrayList<Long> result = new ArrayList<Long>();
for (int i = 0; i < game.size(); i++) {
if (game.get(i) != guess.get(i)) {
result.add(Math.abs(game.get(i) - guess.get(i)));
} else {
result.add((long)0);
}
}
return result; | } | } | }
public static void main(String[] args) {
assert(compare((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)1l))), (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)2l, (long)-2l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l, (long)0l, (long)3l, (long)3l)))));
assert(compare((new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l, (long)0l, (long)0l, (long)0l))), (new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l, (long)0l, (long)0l, (long)0l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l, (long)0l, (long)0l, (long)0l)))));
assert(compare((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))), (new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)6l)))));
assert(compare((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)5l))), (new ArrayList<Long>(Arrays.asList((long)-1l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)0l, (long)0l, (long)1l)))));
}
}
|
humaneval-HumanEval_118_get_closest_vowel.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 {
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// >>> getClosestVowel(("yogurt"))
// ("u")
// >>> getClosestVowel(("FULL"))
// ("U")
// >>> getClosestVowel(("quick"))
// ("")
// >>> getClosestVowel(("ab"))
// ("")
public static String getClosestVowel(String word) {
final String vowels = "aeiou";
final String consonants = "bcdfghjklmnpqrstvwxyz";
List<Integer> idx = new ArrayList<>();
word = word.toLowerCase();
for (int i = 0; i < word.length(); i++) {
if (vowels.indexOf(word.charAt(i)) != -1) {
idx.add(i);
}
}
for (int i = idx.size() - 1; i >= 0; i--) {
int j = idx.get(i);
if (j == 0 || j == word.length() - 1) continue;
char left = word.charAt(j - 1);
char right = word.charAt(j + 1); | return String.valueOf(word.charAt(j));
}
}
return "";
}
} | if (consonants.indexOf(left) != -1 && consonants.indexOf(right) != -1) { | }
public static void main(String[] args) {
assert(getClosestVowel(("yogurt")).equals(("u")));
assert(getClosestVowel(("full")).equals(("u")));
assert(getClosestVowel(("easy")).equals(("")));
assert(getClosestVowel(("eAsy")).equals(("")));
assert(getClosestVowel(("ali")).equals(("")));
assert(getClosestVowel(("bad")).equals(("a")));
assert(getClosestVowel(("most")).equals(("o")));
assert(getClosestVowel(("ab")).equals(("")));
assert(getClosestVowel(("ba")).equals(("")));
assert(getClosestVowel(("quick")).equals(("")));
assert(getClosestVowel(("anime")).equals(("i")));
assert(getClosestVowel(("Asia")).equals(("")));
assert(getClosestVowel(("Above")).equals(("o")));
}
}
|
humaneval-HumanEval_43_pairs_sum_to_zero.json-L23 | py | from typing import List
def pairs_sum_to_zero(l: List[int]) -> bool:
"""
pairs_sum_to_zero takes a list of integers as an input.
it returns True if there are two distinct elements in the list 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
>>> pairs_sum_to_zero([2, 4, -5, 3, 5, 7])
True
>>> pairs_sum_to_zero([1])
False
"""
for x in l:
for y in l:
if x+y == 0 and x != y:
return True | return False | def check(candidate):
assert candidate([1, 3, 5, 0]) == False
assert candidate([1, 3, -2, 1]) == False
assert candidate([1, 2, 3, 7]) == False
assert candidate([2, 4, -5, 3, 5, 7]) == True
assert candidate([1]) == False
assert candidate([-3, 9, -1, 3, 2, 30]) == True
assert candidate([-3, 9, -1, 3, 2, 31]) == True
assert candidate([-3, 9, -1, 4, 2, 30]) == False
assert candidate([-3, 9, -1, 4, 2, 31]) == False
def test_check():
check(pairs_sum_to_zero)
test_check()
|
|
humaneval-HumanEval_140_fix_spaces.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 string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// >>> fixSpaces((" Example"))
// ("Example")
// >>> fixSpaces((" Example 1"))
// ("Example_1")
// >>> fixSpaces((" Example 2"))
// ("_Example_2")
// >>> fixSpaces((" Example 3"))
// ("_Example-3")
public static String fixSpaces(String text) {
String result = text.replace(" ", "_");
int i = 0;
while (i < result.length() - 2) {
if (result.charAt(i) == '_' && result.charAt(i + 1) == '_' && result.charAt(i + 2) == '_') { | }
i++;
}
return result;
}
} | result = result.substring(0, i) + "-" + result.substring(i + 3); | }
public static void main(String[] args) {
assert(fixSpaces(("Example")).equals(("Example")));
assert(fixSpaces(("Mudasir Hanif ")).equals(("Mudasir_Hanif_")));
assert(fixSpaces(("Yellow Yellow Dirty Fellow")).equals(("Yellow_Yellow__Dirty__Fellow")));
assert(fixSpaces(("Exa mple")).equals(("Exa-mple")));
assert(fixSpaces((" Exa 1 2 2 mple")).equals(("-Exa_1_2_2_mple")));
}
}
|
humaneval-HumanEval_140_fix_spaces.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 {
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// >>> fixSpaces((" Example"))
// ("Example")
// >>> fixSpaces((" Example 1"))
// ("Example_1")
// >>> fixSpaces((" Example 2"))
// ("_Example_2")
// >>> fixSpaces((" Example 3"))
// ("_Example-3")
public static String fixSpaces(String text) {
String result = text.replace(" ", "_");
int i = 0;
while (i < result.length() - 2) {
if (result.charAt(i) == '_' && result.charAt(i + 1) == '_' && result.charAt(i + 2) == '_') {
result = result.substring(0, i) + "-" + result.substring(i + 3); | i++;
}
return result;
}
} | } | }
public static void main(String[] args) {
assert(fixSpaces(("Example")).equals(("Example")));
assert(fixSpaces(("Mudasir Hanif ")).equals(("Mudasir_Hanif_")));
assert(fixSpaces(("Yellow Yellow Dirty Fellow")).equals(("Yellow_Yellow__Dirty__Fellow")));
assert(fixSpaces(("Exa mple")).equals(("Exa-mple")));
assert(fixSpaces((" Exa 1 2 2 mple")).equals(("-Exa_1_2_2_mple")));
}
}
|
humaneval-HumanEval_77_iscube.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 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((1l))
// (true)
// >>> iscube((2l))
// (false)
// >>> iscube((-1l))
// (true)
// >>> iscube((64l))
// (true)
// >>> iscube((0l))
// (true)
// >>> iscube((180l))
// (false)
public static boolean iscube(long a) {
| }
} | return a==0l||(a>0l&&Math.pow(Math.round(Math.pow(a, 1.0/3.0)), 3)==a)||(a<0l&&Math.pow(Math.round(Math.pow(-a, 1.0/3.0)), 3)==-a); | }
public static void main(String[] args) {
assert(iscube((1l)) == (true));
assert(iscube((2l)) == (false));
assert(iscube((-1l)) == (true));
assert(iscube((64l)) == (true));
assert(iscube((180l)) == (false));
assert(iscube((1000l)) == (true));
assert(iscube((0l)) == (true));
assert(iscube((1729l)) == (false));
}
}
|
humaneval-HumanEval_69_search.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 {
// You are given a non-empty array list of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array list.
// If no such a value exist, return -1.
// Examples:
// >>> search((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)2l, (long)2l, (long)3l, (long)1l))))
// (2l)
// >>> search((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)3l, (long)4l, (long)4l, (long)4l))))
// (3l)
// >>> search((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)4l, (long)4l, (long)4l))))
// (-1l)
public static long search(ArrayList<Long> lst) {
HashMap<Long, Long> map = new HashMap<Long, Long>();
Long max = (long)-1;
for (int i = 0; i < lst.size(); i++) {
long val = lst.get(i);
if (map.containsKey(val)) {
map.put(val, map.get(val) + 1); | map.put(val, (long)1);
}
if (map.get(val) >= val && val > max) {
max = val;
}
}
return max;
}
} | } else { | }
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 ArrayList<Long>(Arrays.asList((long)3l, (long)3l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)8l, (long)8l, (long)8l, (long)8l, (long)8l, (long)8l, (long)8l, (long)8l)))) == (8l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)3l, (long)2l, (long)2l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)7l, (long)8l, (long)8l, (long)4l, (long)8l, (long)7l, (long)3l, (long)9l, (long)6l, (long)5l, (long)10l, (long)4l, (long)3l, (long)6l, (long)7l, (long)1l, (long)7l, (long)4l, (long)10l, (long)8l, (long)1l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)8l, (long)2l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)6l, (long)7l, (long)1l, (long)8l, (long)8l, (long)10l, (long)5l, (long)8l, (long)5l, (long)3l, (long)10l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)8l, (long)8l, (long)3l, (long)6l, (long)5l, (long)6l, (long)4l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)6l, (long)9l, (long)6l, (long)7l, (long)1l, (long)4l, (long)7l, (long)1l, (long)8l, (long)8l, (long)9l, (long)8l, (long)10l, (long)10l, (long)8l, (long)4l, (long)10l, (long)4l, (long)10l, (long)1l, (long)2l, (long)9l, (long)5l, (long)7l, (long)9l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)1l, (long)9l, (long)10l, (long)1l, (long)3l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)6l, (long)9l, (long)7l, (long)5l, (long)8l, (long)7l, (long)5l, (long)3l, (long)7l, (long)5l, (long)10l, (long)10l, (long)3l, (long)6l, (long)10l, (long)2l, (long)8l, (long)6l, (long)5l, (long)4l, (long)9l, (long)5l, (long)3l, (long)10l)))) == (5l));
assert(search((new ArrayList<Long>(Arrays.asList((long)1l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)8l, (long)8l, (long)10l, (long)6l, (long)4l, (long)3l, (long)5l, (long)8l, (long)2l, (long)4l, (long)2l, (long)8l, (long)4l, (long)6l, (long)10l, (long)4l, (long)2l, (long)1l, (long)10l, (long)2l, (long)1l, (long)1l, (long)5l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)10l, (long)4l, (long)8l, (long)2l, (long)10l, (long)5l, (long)1l, (long)2l, (long)9l, (long)5l, (long)5l, (long)6l, (long)3l, (long)8l, (long)6l, (long)4l, (long)10l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)1l, (long)6l, (long)10l, (long)1l, (long)6l, (long)9l, (long)10l, (long)8l, (long)6l, (long)8l, (long)7l, (long)3l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)9l, (long)2l, (long)4l, (long)1l, (long)5l, (long)1l, (long)5l, (long)2l, (long)5l, (long)7l, (long)7l, (long)7l, (long)3l, (long)10l, (long)1l, (long)5l, (long)4l, (long)2l, (long)8l, (long)4l, (long)1l, (long)9l, (long)10l, (long)7l, (long)10l, (long)2l, (long)8l, (long)10l, (long)9l, (long)4l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)4l, (long)2l, (long)8l, (long)7l, (long)5l, (long)6l, (long)4l, (long)10l, (long)4l, (long)6l, (long)3l, (long)7l, (long)8l, (long)8l, (long)3l, (long)1l, (long)4l, (long)2l, (long)2l, (long)10l, (long)7l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)9l, (long)8l, (long)6l, (long)10l, (long)2l, (long)6l, (long)10l, (long)2l, (long)7l, (long)8l, (long)10l, (long)3l, (long)8l, (long)2l, (long)6l, (long)2l, (long)3l, (long)1l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)3l, (long)9l, (long)5l, (long)6l, (long)3l, (long)2l, (long)8l, (long)5l, (long)6l, (long)10l, (long)10l, (long)6l, (long)8l, (long)4l, (long)10l, (long)7l, (long)7l, (long)10l, (long)8l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)10l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)9l, (long)7l, (long)7l, (long)2l, (long)4l, (long)7l, (long)2l, (long)10l, (long)9l, (long)7l, (long)5l, (long)7l, (long)2l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)5l, (long)4l, (long)10l, (long)2l, (long)1l, (long)1l, (long)10l, (long)3l, (long)6l, (long)1l, (long)8l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)7l, (long)9l, (long)9l, (long)9l, (long)3l, (long)4l, (long)1l, (long)5l, (long)9l, (long)1l, (long)2l, (long)1l, (long)1l, (long)10l, (long)7l, (long)5l, (long)6l, (long)7l, (long)6l, (long)7l, (long)7l, (long)6l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)3l, (long)10l, (long)10l, (long)9l, (long)2l)))) == (-1l));
}
}
|
humaneval-HumanEval_19_sort_numbers.json-L16 | 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 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
// >>> sortNumbers(("three one five"))
// ("one three five")
public static String sortNumbers(String numbers) {
String [] nums = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; | for (int i = 0; i < nums.length; i++) {
indexMap.put(nums[i], i);
}
String [] split = numbers.split(" ");
Arrays.sort(split, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return indexMap.get(s1) - indexMap.get(s2);
}
});
return String.join(" ", split);
}
} | HashMap<String, Integer> indexMap = new HashMap<>(); | }
public static void main(String[] args) {
assert(sortNumbers(("")).equals(("")));
assert(sortNumbers(("three")).equals(("three")));
assert(sortNumbers(("three five nine")).equals(("three five nine")));
assert(sortNumbers(("five zero four seven nine eight")).equals(("zero four five seven eight nine")));
assert(sortNumbers(("six five four three two one zero")).equals(("zero one two three four five six")));
}
}
|
humaneval-HumanEval_161_solve.json-L16 | js | //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 it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// >>> solve("1234")
// "4321"
// >>> solve("ab")
// "AB"
// >>> solve("#a@C")
// "#A@c"
function solve(s){
let letters = s.match(/[a-z]/ig);
if(letters) { | if(/[a-z]/i.test(char)) {
return char === char.toLowerCase()
? char.toUpperCase()
: char.toLowerCase();
}
return char;
});
return swapped.join('');
}
return s.split('').reverse().join('');
}
| const swapped = s.split('').map(char => { | const assert = require('node:assert');
function test() {
let candidate = solve;
assert.deepEqual(candidate("AsDf"),"aSdF");
assert.deepEqual(candidate("1234"),"4321");
assert.deepEqual(candidate("ab"),"AB");
assert.deepEqual(candidate("#a@C"),"#A@c");
assert.deepEqual(candidate("#AsdfW^45"),"#aSDFw^45");
assert.deepEqual(candidate("#6@2"),"2@6#");
assert.deepEqual(candidate("#$a^D"),"#$A^d");
assert.deepEqual(candidate("#ccc"),"#CCC");
}
test(); |
humaneval-HumanEval_17_parse_music.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 {
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array list of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// >>> parseMusic(("o o| .| o| o| .| .| .| .| o o"))
// (new ArrayList<Long>(Arrays.asList((long)4l, (long)2l, (long)1l, (long)2l, (long)2l, (long)1l, (long)1l, (long)1l, (long)1l, (long)4l, (long)4l)))
public static ArrayList<Long> parseMusic(String music_string) {
ArrayList<Long> res = new ArrayList<Long>();
char[] chars = music_string.toCharArray();
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 if (chars[i] == '.') {
if (i + 1 < chars.length && chars[i + 1] == '|') {
res.add((long)1l);
i += 1;
}
}
} | }
} | return res; | }
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>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l)))));
assert(parseMusic(("o| o| .| .| o o o o")).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)2l, (long)1l, (long)1l, (long)4l, (long)4l, (long)4l, (long)4l)))));
assert(parseMusic(("o| .| o| .| o o| o o|")).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)1l, (long)2l, (long)1l, (long)4l, (long)2l, (long)4l, (long)2l)))));
}
}
|
humaneval-HumanEval_115_max_fill.json-L29 | js | //You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// >>> max_fill([[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], 1)
// 6
// Example 2:
// >>> max_fill([[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], 2)
// 5
// Example 3:
// >>> max_fill([[0, 0, 0], [0, 0, 0]], 5)
// 0
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
function max_fill(grid, capacity){
var maxFill = 0;
var sum = 0;
var c = 1;
var r = grid.length;
var c = grid[0].length;
for(var i = 0; i < r; i++){ | for(var j = 0; j < c; j++){
sum += grid[i][j];
}
maxFill += Math.ceil(sum/capacity);
}
return maxFill;
}
| sum = 0; | const assert = require('node:assert');
function test() {
let candidate = max_fill;
assert.deepEqual(candidate([[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], 1),6);
assert.deepEqual(candidate([[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], 2),5);
assert.deepEqual(candidate([[0, 0, 0], [0, 0, 0]], 5),0);
assert.deepEqual(candidate([[1, 1, 1, 1], [1, 1, 1, 1]], 2),4);
assert.deepEqual(candidate([[1, 1, 1, 1], [1, 1, 1, 1]], 9),2);
}
test(); |
humaneval-HumanEval_133_sum_squares.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 {
// You are given an array array list of numbers.
// You need to return the sum of squared numbers in the given array list,
// round each element in the array list to the upper int(Ceiling) first.
// Examples:
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f))))
// (14l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)4.0f, (float)9.0f))))
// (98l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)3.0f, (float)5.0f, (float)7.0f))))
// (84l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.4f, (float)4.2f, (float)0.0f))))
// (29l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)-2.4f, (float)1.0f, (float)1.0f))))
// (6l)
public static long sumSquares(ArrayList<Float> lst) {
if (lst.size() == 0) { | }
long sum = 0;
for (int i = 0; i < lst.size(); i++) {
sum += (long)Math.ceil(lst.get(i)) * (long)Math.ceil(lst.get(i));
}
return sum;
}
} | return 0; | }
public static void main(String[] args) {
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f)))) == (14l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f)))) == (14l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)3.0f, (float)5.0f, (float)7.0f)))) == (84l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.4f, (float)4.2f, (float)0.0f)))) == (29l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-2.4f, (float)1.0f, (float)1.0f)))) == (6l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)100.0f, (float)1.0f, (float)15.0f, (float)2.0f)))) == (10230l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)10000.0f, (float)10000.0f)))) == (200000000l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.4f, (float)4.6f, (float)6.3f)))) == (75l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.4f, (float)17.9f, (float)18.9f, (float)19.9f)))) == (1086l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)0.0f)))) == (0l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.0f)))) == (1l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.0f, (float)1.0f, (float)0.0f)))) == (2l));
}
}
|
humaneval-HumanEval_144_simplify.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 {
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// >>> simplify(("1/5"), ("5/1"))
// (true)
// >>> simplify(("1/6"), ("2/1"))
// (false)
// >>> simplify(("7/10"), ("10/2"))
// (false)
public static boolean simplify(String x, String n) {
String[] nums = x.split("/");
String[] n_nums = n.split("/");
int x_num = Integer.parseInt(nums[0]);
int n_num = Integer.parseInt(n_nums[0]);
int x_denom = Integer.parseInt(nums[1]); | int res_num = x_num * n_num;
int res_denom = x_denom * n_denom;
return (res_num % res_denom == 0);
}
} | int n_denom = Integer.parseInt(n_nums[1]); | }
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(simplify(("7/2"), ("4/2")) == (true));
assert(simplify(("11/6"), ("6/1")) == (true));
assert(simplify(("2/3"), ("5/2")) == (false));
assert(simplify(("5/2"), ("3/5")) == (false));
assert(simplify(("2/4"), ("8/4")) == (true));
assert(simplify(("2/4"), ("4/2")) == (true));
assert(simplify(("1/5"), ("5/1")) == (true));
assert(simplify(("1/5"), ("1/5")) == (false));
}
}
|
humaneval-HumanEval_13_greatest_common_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 {
// Return a greatest common divisor of two integers a and b
// >>> greatestCommonDivisor((3l), (5l))
// (1l)
// >>> greatestCommonDivisor((25l), (15l))
// (5l)
public static long greatestCommonDivisor(long a, long b) {
if (a == 0) {
return b;
} | return a;
}
return greatestCommonDivisor(b, a % b);
}
} | if (b == 0) { | }
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_61_correct_bracketing.json-L17 | 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_bracketing(')(()')
False
"""
count = 0
for char in brackets:
if char == '(': | elif char == ')':
count -= 1
if count < 0:
return False
return count == 0
| count += 1 | def check(candidate):
assert candidate('()') == True
assert candidate('(()())') == True
assert candidate('()()(()())()') == True
assert candidate('()()((()()())())(()()(()))') == True
assert candidate('((()())))') == False
assert candidate(')(()') == False
assert candidate('(') == False
assert candidate('((((') == False
assert candidate(')') == False
assert candidate('(()') == False
assert candidate('()()(()())())(()') == False
assert candidate('()()(()())()))()') == False
def test_check():
check(correct_bracketing)
test_check()
|
humaneval-HumanEval_13_greatest_common_divisor.json-L16 | 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)
// >>> greatestCommonDivisor((25l), (15l))
// (5l)
public static long greatestCommonDivisor(long a, long b) {
if (a == 0) { | }
if (b == 0) {
return a;
}
return greatestCommonDivisor(b, a % b);
}
} | return b; | }
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_116_sort_array.json-L17 | js | //In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// >>> sort_array([1, 5, 2, 3, 4])
// [1, 2, 3, 4, 5]
// >>> sort_array([-2, -3, -4, -5, -6])
// [-6, -5, -4, -3, -2]
// >>> sort_array([1, 0, 2, 3, 4])
// [0, 1, 2, 3, 4]
function sort_array(arr){
return arr.sort((a, b) => {
let aBinary = a.toString(2).split('').filter(el => el === '1').length;
let bBinary = b.toString(2).split('').filter(el => el === '1').length;
if (aBinary === bBinary) {
return a - b; | return aBinary - bBinary;
}
});
} | } else { | const assert = require('node:assert');
function test() {
let candidate = sort_array;
assert.deepEqual(candidate([1, 5, 2, 3, 4]),[1, 2, 4, 3, 5]);
assert.deepEqual(candidate([-2, -3, -4, -5, -6]),[-4, -2, -6, -5, -3]);
assert.deepEqual(candidate([1, 0, 2, 3, 4]),[0, 1, 2, 4, 3]);
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([2, 5, 77, 4, 5, 3, 5, 7, 2, 3, 4]),[2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77]);
assert.deepEqual(candidate([3, 6, 44, 12, 32, 5]),[32, 3, 5, 6, 12, 44]);
assert.deepEqual(candidate([2, 4, 8, 16, 32]),[2, 4, 8, 16, 32]);
assert.deepEqual(candidate([2, 4, 8, 16, 32]),[2, 4, 8, 16, 32]);
}
test(); |
humaneval-HumanEval_94_skjkasdkd.json-L21 | py | from typing import List
def skjkasdkd(lst: List[int]) -> int:
"""You are given a list of integers.
You need to find the largest prime value and return the sum of its digits.
Examples:
>>> skjkasdkd([0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3])
10
>>> skjkasdkd([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1])
25
>>> skjkasdkd([1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3])
13
>>> skjkasdkd([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6])
11
>>> skjkasdkd([0, 81, 12, 3, 1, 21])
3
>>> skjkasdkd([0, 8, 1, 2, 1, 7])
7
"""
| return sum(int(j) for j in str(max(filter(lambda x: x != 1 and all(x % i for i in range(2, x // 2 + 1)), lst)))) | def check(candidate):
assert candidate([0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
assert candidate([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
assert candidate([1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
assert candidate([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
assert candidate([0, 81, 12, 3, 1, 21]) == 3
assert candidate([0, 8, 1, 2, 1, 7]) == 7
assert candidate([8191]) == 19
assert candidate([8191, 123456, 127, 7]) == 19
assert candidate([127, 97, 8192]) == 10
def test_check():
check(skjkasdkd)
test_check()
|
|
humaneval-HumanEval_41_car_race_collision.json-L10 | js | //Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
function car_race_collision(n){
| let left_to_right = Array(n).fill(1);
let right_to_left = Array(n).fill(1);
for (let i = 0; i < left_to_right.length; i++) {
for (let j = 0; j < right_to_left.length; j++) {
if (left_to_right[i] == right_to_left[j]) {
num_collisions++;
}
}
}
return num_collisions;
}
| let num_collisions = 0; | const assert = require('node:assert');
function test() {
let candidate = car_race_collision;
assert.deepEqual(candidate(2),4);
assert.deepEqual(candidate(3),9);
assert.deepEqual(candidate(4),16);
assert.deepEqual(candidate(8),64);
assert.deepEqual(candidate(10),100);
}
test(); |
humaneval-HumanEval_119_match_parens.json-L34 | 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 in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// >>> match_parens(["()(", ")"])
// "Yes"
// >>> match_parens([")", ")"])
// "No"
function match_parens(lst){
const open = '(';
const close = ')';
const is_good = (s) => {
let stack = [];
for (let p of s){
if (p === open){
stack.push(p);
} else if (p === close){
if (stack.length === 0){
return false;
}
stack.pop();
}
}
return stack.length === 0;
};
const str1 = lst[0];
const str2 = lst[1];
if (is_good(str1 + str2)){ | }
if (is_good(str2 + str1)){
return 'Yes';
}
return 'No';
} | return 'Yes'; | 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.deepEqual(candidate(["(())))", "(()())(("]),"Yes");
assert.deepEqual(candidate(["()", "())"]),"No");
assert.deepEqual(candidate(["(()(", "()))()"]),"Yes");
assert.deepEqual(candidate(["((((", "((())"]),"No");
assert.deepEqual(candidate([")(()", "(()("]),"No");
assert.deepEqual(candidate([")(", ")("]),"No");
assert.deepEqual(candidate(["(", ")"]),"Yes");
assert.deepEqual(candidate([")", "("]),"Yes");
}
test(); |
humaneval-HumanEval_139_special_factorial.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 {
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// >>> specialFactorial((4l))
// (288l)
// The function will receive an integer as input and should return the special
// factorial of this integer.
public static long specialFactorial(long n) {
long result = 1;
while (n > 0) {
long local_result = 1; | while (temp > 0) {
local_result *= temp;
temp--;
}
result *= local_result;
n--;
}
return result;
}
} | long temp = n; | }
public static void main(String[] args) {
assert(specialFactorial((4l)) == (288l));
assert(specialFactorial((5l)) == (34560l));
assert(specialFactorial((7l)) == (125411328000l));
assert(specialFactorial((1l)) == (1l));
}
}
|
humaneval-HumanEval_121_solution.json-L10 | js | //Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// >>> solution([5, 8, 7, 1])
// 12
// >>> solution([3, 3, 3, 3, 3])
// 9
// >>> solution([30, 13, 24, 321])
// 0
function solution(lst){
| for (let i = 0; i < lst.length; i++){
if (i % 2 === 0){
if (lst[i] % 2 === 1){
result += lst[i];
}
}
}
return result;
} | let result = 0; | const assert = require('node:assert');
function test() {
let candidate = solution;
assert.deepEqual(candidate([5, 8, 7, 1]),12);
assert.deepEqual(candidate([3, 3, 3, 3, 3]),9);
assert.deepEqual(candidate([30, 13, 24, 321]),0);
assert.deepEqual(candidate([5, 9]),5);
assert.deepEqual(candidate([2, 4, 8]),0);
assert.deepEqual(candidate([30, 13, 23, 32]),23);
assert.deepEqual(candidate([3, 13, 2, 9]),3);
}
test(); |
humaneval-HumanEval_75_is_multiply_prime.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 {
// 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:
// >>> isMultiplyPrime((30l))
// (true)
// 30 = 2 * 3 * 5
public static boolean isMultiplyPrime(long a) {
if (a == 1) {
return false;
}
if (a == 2) {
return true;
}
long copyOfInput = a;
ArrayList<Long> arr = new ArrayList<Long>();
while (a % 2 == 0) {
arr.add(2l);
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; | }
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)) == (true));
assert(isMultiplyPrime((126l)) == (false));
assert(isMultiplyPrime((729l)) == (false));
assert(isMultiplyPrime((891l)) == (false));
assert(isMultiplyPrime((1001l)) == (true));
}
}
|
humaneval-HumanEval_148_bf.json-L32 | 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 orbits are
// located between the orbit of planet1 and the orbit of planet2, sorted by
// the proximity to the sun.
// The function should return an empty array if planet1 or planet2
// are not correct planet names.
// Examples
// >>> bf("Jupiter", "Neptune")
// ["Saturn", "Uranus"]
// >>> bf("Earth", "Mercury")
// "Venus"
// >>> bf("Mercury", "Uranus")
// ["Venus", "Earth", "Mars", "Jupiter", "Saturn"]
function bf(planet1, planet2){
var planets = {
'Mercury':1,
'Venus':2,
'Earth':3,
'Mars':4,
'Jupiter':5,
'Saturn':6,
'Uranus':7,
'Neptune':8
}
if(!planets[planet1] || !planets[planet2]){
return [];
}
var keys = Object.keys(planets); | var position2 = keys.indexOf(planet2);
if(position1 > position2){
var temp = position1;
position1 = position2;
position2 = temp;
}
var res = [];
for(var i = position1 + 1; i < position2; i++){
res.push(keys[i]);
}
return res;
} | var position1 = keys.indexOf(planet1); | 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"]);
assert.deepEqual(candidate("Neptune", "Venus"),["Earth", "Mars", "Jupiter", "Saturn", "Uranus"]);
assert.deepEqual(candidate("Earth", "Earth"),[]);
assert.deepEqual(candidate("Mars", "Earth"),[]);
assert.deepEqual(candidate("Jupiter", "Makemake"),[]);
}
test(); |
humaneval-HumanEval_82_prime_length.json-L18 | 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('orange')
False
"""
num = len(string)
if num > 1:
for i in range(2, num):
if (num % i) == 0: | else:
return True
else:
return False
pass
| return False | 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') == True
assert candidate('') == False
assert candidate('HI') == True
assert candidate('go') == True
assert candidate('gogo') == False
assert candidate('aaaaaaaaaaaaaaa') == False
assert candidate('Madam') == True
assert candidate('M') == False
assert candidate('0') == False
def test_check():
check(prime_length)
test_check()
|
humaneval-HumanEval_127_intersection.json-L26 | 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.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// >>> intersection([1, 2], [2, 3])
// "NO"
// >>> intersection([-1, 1], [0, 4])
// "NO"
// >>> intersection([-3, -1], [-5, 5])
// "YES"
function intersection(interval1, interval2){
let start = Math.max(interval1[0], interval2[0]);
let end = Math.min(interval1[1], interval2[1]);
if (start >= end) {
return "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];
return primes.includes(length) ? "YES" : "NO";
}
| let length = end - start; | 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.deepEqual(candidate([-11, 2], [-1, -1]),"NO");
assert.deepEqual(candidate([1, 2], [3, 5]),"NO");
assert.deepEqual(candidate([1, 2], [1, 2]),"NO");
assert.deepEqual(candidate([-2, -2], [-3, -2]),"NO");
}
test(); |
humaneval-HumanEval_88_sort_array.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 {
// Given an array array list of non-negative integers, return a cojava of the given array array list after sorting,
// you will sort the given array array list 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 the given array array list.
// Examples:
// >>> sortArray((new ArrayList<Long>(Arrays.asList())))
// (new ArrayList<Long>(Arrays.asList()))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)5l))))
// (new ArrayList<Long>(Arrays.asList((long)5l)))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)3l, (long)0l, (long)1l, (long)5l))))
// (new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)3l, (long)0l, (long)1l, (long)5l, (long)6l))))
// (new ArrayList<Long>(Arrays.asList((long)6l, (long)5l, (long)4l, (long)3l, (long)2l, (long)1l, (long)0l)))
public static ArrayList<Long> sortArray(ArrayList<Long> array) {
if(array.size()==0) {
return array;
}
if(array.size()==1) {
return array;
}
if(array.size()>1) {
if((array.get(0)+array.get(array.size()-1))%2==0) {
Collections.sort(array, Collections.reverseOrder());
}
else {
Collections.sort(array);
}
}
return array; | } | } | }
public static void main(String[] args) {
assert(sortArray((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)5l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)3l, (long)0l, (long)1l, (long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)3l, (long)0l, (long)1l, (long)5l, (long)6l)))).equals((new ArrayList<Long>(Arrays.asList((long)6l, (long)5l, (long)4l, (long)3l, (long)2l, (long)1l, (long)0l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)15l, (long)42l, (long)87l, (long)32l, (long)11l, (long)0l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)11l, (long)15l, (long)32l, (long)42l, (long)87l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)21l, (long)14l, (long)23l, (long)11l)))).equals((new ArrayList<Long>(Arrays.asList((long)23l, (long)21l, (long)14l, (long)11l)))));
}
}
|
humaneval-HumanEval_118_get_closest_vowel.json-L35 | 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 word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// >>> getClosestVowel(("yogurt"))
// ("u")
// >>> getClosestVowel(("FULL"))
// ("U")
// >>> getClosestVowel(("quick"))
// ("")
// >>> getClosestVowel(("ab"))
// ("")
public static String getClosestVowel(String word) {
final String vowels = "aeiou";
final String consonants = "bcdfghjklmnpqrstvwxyz";
List<Integer> idx = new ArrayList<>();
word = word.toLowerCase();
for (int i = 0; i < word.length(); i++) {
if (vowels.indexOf(word.charAt(i)) != -1) {
idx.add(i);
}
}
for (int i = idx.size() - 1; i >= 0; i--) {
int j = idx.get(i); | char left = word.charAt(j - 1);
char right = word.charAt(j + 1);
if (consonants.indexOf(left) != -1 && consonants.indexOf(right) != -1) {
return String.valueOf(word.charAt(j));
}
}
return "";
}
} | if (j == 0 || j == word.length() - 1) continue; | }
public static void main(String[] args) {
assert(getClosestVowel(("yogurt")).equals(("u")));
assert(getClosestVowel(("full")).equals(("u")));
assert(getClosestVowel(("easy")).equals(("")));
assert(getClosestVowel(("eAsy")).equals(("")));
assert(getClosestVowel(("ali")).equals(("")));
assert(getClosestVowel(("bad")).equals(("a")));
assert(getClosestVowel(("most")).equals(("o")));
assert(getClosestVowel(("ab")).equals(("")));
assert(getClosestVowel(("ba")).equals(("")));
assert(getClosestVowel(("quick")).equals(("")));
assert(getClosestVowel(("anime")).equals(("i")));
assert(getClosestVowel(("Asia")).equals(("")));
assert(getClosestVowel(("Above")).equals(("o")));
}
}
|
humaneval-HumanEval_63_fibfib.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 {
// 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.
// >>> fibfib((1l))
// (0l)
// >>> fibfib((5l))
// (4l)
// >>> fibfib((8l))
// (24l)
public static long fibfib(long n) {
| return 0;
}
if (n == 1) {
return 0;
}
if (n == 2) {
return 1;
}
long[] memo = new long[(int) n + 1];
memo[0] = 0;
memo[1] = 0;
memo[2] = 1;
for (int i = 3; i <= n; i++) {
memo[i] = memo[i - 1] + memo[i - 2] + memo[i - 3];
}
return memo[(int) n];
}
} | if (n == 0) { | }
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_160_do_algebra.json-L25 | 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 ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
function do_algebra(operator, operand){
let do_again;
let count = 0;
let temp;
let answer;
while(count < operator.length){ | case '*':
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);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
case '**':
operand[count] = Math.pow(operand[count], operand[count + 1]);
operand.splice(count + 1, 1);
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];
break;
case '-':
answer -= operand[0];
break;
}
operand.splice(0, 1);
operator.splice(0, 1);
}
return answer;
}
| switch(operator[count]){ | 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_95_check_dict_case.json-L25 | py | from typing import Dict
def check_dict_case(dict: Dict[str, str]) -> bool:
"""
Given a dictionary, 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 dictionary is empty.
Examples:
>>> check_dict_case({ 'a': 'apple', 'b': 'banana' })
True
>>> check_dict_case({ 'a': 'apple', 'A': 'banana', 'B': 'banana' })
False
>>> check_dict_case({ 'a': 'apple', 8: 'banana', 'a': 'apple' })
False
>>> check_dict_case({ 'Name': 'John', 'Age': '36', 'City': 'Houston' })
False
>>> check_dict_case({ 'STATE': 'NC', 'ZIP': '12345' })
True
"""
if len(dict) == 0:
return False
if any(not isinstance(x, str) for x in dict.keys()):
return False
if any(not x.islower() for x in dict.keys()): | return False
return True
| if any(not x.isupper() for x in dict.keys()): | def check(candidate):
assert candidate({ 'p': 'pineapple', 'b': 'banana' }) == True
assert candidate({ 'p': 'pineapple', 'A': 'banana', 'B': 'banana' }) == False
assert candidate({ 'p': 'pineapple', '5': 'banana', 'a': 'apple' }) == False
assert candidate({ 'Name': 'John', 'Age': '36', 'City': 'Houston' }) == False
assert candidate({ 'STATE': 'NC', 'ZIP': '12345' }) == True
assert candidate({ 'fruit': 'Orange', 'taste': 'Sweet' }) == True
assert candidate({ }) == False
def test_check():
check(check_dict_case)
test_check()
|
humaneval-HumanEval_10_make_palindrome.json-L20 | js | //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 suffix.
// >>> make_palindrome("")
// ""
// >>> make_palindrome("cat")
// "catac"
// >>> make_palindrome("cata")
// "catac"
function make_palindrome(string){
var string_length = string.length;
var is_palindrome = function(s){
return s == s.split("").reverse().join("");
};
var i = string_length;
while(i > 0){
if(is_palindrome(string.substring(0, i))){
return string + string.substring(0, string_length - i).split("").reverse().join(""); | i--;
}
return string;
}
| } | const assert = require('node:assert');
function test() {
let candidate = make_palindrome;
assert.deepEqual(candidate(""),"");
assert.deepEqual(candidate("x"),"x");
assert.deepEqual(candidate("xyz"),"xyzyx");
assert.deepEqual(candidate("xyx"),"xyx");
assert.deepEqual(candidate("jerry"),"jerryrrej");
}
test(); |
humaneval-HumanEval_98_count_upper.json-L14 | py | def count_upper(s: str) -> int:
"""
Given a string s, count the number of uppercase vowels in even indices.
For example:
>>> count_upper('aBCdEf')
1
>>> count_upper('abcdefg')
0
>>> count_upper('dBBE')
0
"""
vowel_set = set('AEIOU') | for i in range(0, len(s), 2):
if s[i] in vowel_set:
count += 1
return count
"""
D.1 Recursion
Given a positive integer n, write a recursive function that returns the sum of the squares of the
positive odd integers smaller than n. Assume n is greater than or equal to 3.
""" | count = 0 | def check(candidate):
assert candidate('aBCdEf') == 1
assert candidate('abcdefg') == 0
assert candidate('dBBE') == 0
assert candidate('B') == 0
assert candidate('U') == 1
assert candidate('') == 0
assert candidate('EEEE') == 2
def test_check():
check(count_upper)
test_check()
|
humaneval-HumanEval_156_int_to_mini_roman.json-L31 | 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 roman_conversion = {
1000: "m",
900: "cm",
500: "d",
400: "cd",
100: "c",
90: "xc",
50: "l",
40: "xl",
10: "x",
9: "ix",
5: "v",
4: "iv",
1: "i"
};
var output = "";
while (number > 0){
var key_list = Object.keys(roman_conversion).map(Number);
key_list.sort(function(a, b){return b-a}); | if (key_list[i] <= number){
output += roman_conversion[key_list[i]];
number -= key_list[i];
break;
}
}
}
return output;
}
| for (var i = 0; i < key_list.length; i++){ | 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.deepEqual(candidate(1),"i");
assert.deepEqual(candidate(4),"iv");
assert.deepEqual(candidate(43),"xliii");
assert.deepEqual(candidate(90),"xc");
assert.deepEqual(candidate(94),"xciv");
assert.deepEqual(candidate(532),"dxxxii");
assert.deepEqual(candidate(900),"cm");
assert.deepEqual(candidate(994),"cmxciv");
assert.deepEqual(candidate(1000),"m");
}
test(); |
humaneval-HumanEval_24_largest_divisor.json-L13 | 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)
public static long largestDivisor(long n) {
| if (n % i == 0) {
return n / i;
}
}
return 1;
}
} | for (long i = 2; i <= Math.floor(Math.sqrt(n)); i++) { | }
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_8_sum_product.json-L14 | 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 == 0){
return [0, 1];
}
let sum = 0;
let product = 1;
for(let i = 0; i < numbers.length; i++){ | product *= numbers[i];
}
return [sum, product];
}
| sum += numbers[i]; | 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]),[10, 10]);
}
test(); |
humaneval-HumanEval_76_is_simple_power.json-L24 | 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)
// false
// >>> is_simple_power(3, 1)
// false
// >>> is_simple_power(5, 3)
// false
function is_simple_power(x, n){
if(x===1){
return true;
}
if(x < n){
return false;
} | return false;
}
return is_simple_power(x/n, n);
}
| if(x % n !== 0){ | 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);
assert.deepEqual(candidate(24, 2),false);
assert.deepEqual(candidate(128, 4),false);
assert.deepEqual(candidate(12, 6),false);
assert.deepEqual(candidate(1, 1),true);
assert.deepEqual(candidate(1, 12),true);
}
test(); |
humaneval-HumanEval_63_fibfib.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 {
// 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.
// >>> fibfib((1l))
// (0l)
// >>> fibfib((5l))
// (4l)
// >>> fibfib((8l))
// (24l)
public static long fibfib(long n) {
if (n == 0) { | }
if (n == 1) {
return 0;
}
if (n == 2) {
return 1;
}
long[] memo = new long[(int) n + 1];
memo[0] = 0;
memo[1] = 0;
memo[2] = 1;
for (int i = 3; i <= n; i++) {
memo[i] = memo[i - 1] + memo[i - 2] + memo[i - 3];
}
return memo[(int) n];
}
} | return 0; | }
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_44_change_base.json-L13 | py | def change_base(x: int, base: int) -> str:
"""Change numerical base of input number x to base.
return string representation after the conversion.
base numbers are less than 10.
>>> change_base(8, 3)
'22'
>>> change_base(8, 2)
'1000'
>>> change_base(7, 2)
'111'
"""
if x == 0: | ans = []
while x != 0:
ans.append(str(x % base))
x //= base
return ''.join(ans[::-1])
| return '0' | def check(candidate):
assert candidate(8, 3) == '22'
assert candidate(9, 3) == '100'
assert candidate(234, 2) == '11101010'
assert candidate(16, 2) == '10000'
assert candidate(8, 2) == '1000'
assert candidate(7, 2) == '111'
assert candidate(2, 3) == '2'
assert candidate(3, 4) == '3'
assert candidate(4, 5) == '4'
assert candidate(5, 6) == '5'
assert candidate(6, 7) == '6'
assert candidate(7, 8) == '7'
def test_check():
check(change_base)
test_check()
|
humaneval-HumanEval_70_strange_sort_list.json-L23 | js | //Given array of integers, return array 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, 3, 4])
// [1, 4, 2, 3]
// >>> strange_sort_list([5, 5, 5, 5])
// [5, 5, 5, 5]
// >>> strange_sort_list([])
// []
function strange_sort_list(lst){
if(lst.length === 0){
return [];
}
var output = [];
var tmp = lst.slice();
for(var i = 0; i < lst.length; i++){
if(i % 2 === 0){
output.push(Math.min.apply(null, tmp));
}
else{
output.push(Math.max.apply(null, tmp)); | tmp.splice(tmp.indexOf(output[i]), 1);
}
return output;
} | } | const assert = require('node:assert');
function test() {
let candidate = strange_sort_list;
assert.deepEqual(candidate([1, 2, 3, 4]),[1, 4, 2, 3]);
assert.deepEqual(candidate([5, 6, 7, 8, 9]),[5, 9, 6, 8, 7]);
assert.deepEqual(candidate([1, 2, 3, 4, 5]),[1, 5, 2, 4, 3]);
assert.deepEqual(candidate([5, 6, 7, 8, 9, 1]),[1, 9, 5, 8, 6, 7]);
assert.deepEqual(candidate([5, 5, 5, 5]),[5, 5, 5, 5]);
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([1, 2, 3, 4, 5, 6, 7, 8]),[1, 8, 2, 7, 3, 6, 4, 5]);
assert.deepEqual(candidate([0, 2, 2, 2, 5, 5, -5, -5]),[-5, 5, -5, 5, 0, 2, 2, 2]);
assert.deepEqual(candidate([111111]),[111111]);
}
test(); |
humaneval-HumanEval_156_int_to_mini_roman.json-L15 | 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 roman_conversion = {
1000: "m",
900: "cm", | 400: "cd",
100: "c",
90: "xc",
50: "l",
40: "xl",
10: "x",
9: "ix",
5: "v",
4: "iv",
1: "i"
};
var output = "";
while (number > 0){
var key_list = Object.keys(roman_conversion).map(Number);
key_list.sort(function(a, b){return b-a});
for (var i = 0; i < key_list.length; i++){
if (key_list[i] <= number){
output += roman_conversion[key_list[i]];
number -= key_list[i];
break;
}
}
}
return output;
}
| 500: "d", | 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.deepEqual(candidate(1),"i");
assert.deepEqual(candidate(4),"iv");
assert.deepEqual(candidate(43),"xliii");
assert.deepEqual(candidate(90),"xc");
assert.deepEqual(candidate(94),"xciv");
assert.deepEqual(candidate(532),"dxxxii");
assert.deepEqual(candidate(900),"cm");
assert.deepEqual(candidate(994),"cmxciv");
assert.deepEqual(candidate(1000),"m");
}
test(); |
humaneval-HumanEval_6_parse_nested_parens.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 {
// 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.
// >>> parseNestedParens(("(()()) ((())) () ((())()())"))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)1l, (long)3l)))
public static ArrayList<Long> parseNestedParens(String paren_string) {
ArrayList<Long> result = new ArrayList<Long>();
String[] paren_strings = paren_string.split(" ");
for (String paren : paren_strings) {
long max_depth = 0;
long current_depth = 0;
for (char c : paren.toCharArray()) {
if (c == '(') { | max_depth = Math.max(max_depth, current_depth);
} else if (c == ')') {
current_depth -= 1;
}
}
result.add(max_depth);
}
return result;
}
} | current_depth += 1; | }
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, (long)3l, (long)4l)))));
assert(parseNestedParens(("(()(())((())))")).equals((new ArrayList<Long>(Arrays.asList((long)4l)))));
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.