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_63_fibfib.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 {
// 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) {
return 0;
}
if (n == 1) { | }
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_93_encode.json-L17 | py | def encode(message: str) -> str:
"""
Write a function that takes a message, and encodes in such a
way that it swaps case of all letters, replaces all vowels in
the message with the letter that appears 2 places ahead of that
vowel in the english alphabet.
Assume only letters.
Examples:
>>> encode('test')
'TGST'
>>> encode('This is a message')
'tHKS KS C MGSSCGG'
"""
def swap_case(ch: str) -> str:
if ch.isupper(): | else:
return ch.upper()
def encode_vowel(ch: str) -> str:
if ch.lower() in 'aeiou':
if ch.lower() in 'wxyz':
return ch.lower()
return chr(ord(ch) + 2)
return ch
return ''.join(map(lambda ch: encode_vowel(swap_case(ch)), message))
| return ch.lower() | def check(candidate):
assert candidate('TEST') == 'tgst'
assert candidate('Mudasir') == 'mWDCSKR'
assert candidate('YES') == 'ygs'
assert candidate('This is a message') == 'tHKS KS C MGSSCGG'
assert candidate('I DoNt KnOw WhAt tO WrItE') == 'k dQnT kNqW wHcT Tq wRkTg'
def test_check():
check(encode)
test_check()
|
humaneval-HumanEval_78_hex_key.json-L25 | py | def hex_key(num: str) -> int:
"""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
"""
primes = '2357BDB' | return len([i for i in num if i in primes]) | def check(candidate):
assert candidate('AB') == 1
assert candidate('1077E') == 2
assert candidate('ABED1A33') == 4
assert candidate('2020') == 2
assert candidate('123456789ABCDEF0') == 6
assert candidate('112233445566778899AABBCCDDEEFF00') == 12
def test_check():
check(hex_key)
test_check()
|
|
humaneval-HumanEval_137_compare_one.json-L21 | 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: | 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
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_82_prime_length.json-L21 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// >>> primeLength(("Hello"))
// (true)
// >>> primeLength(("abcdcba"))
// (true)
// >>> primeLength(("kittens"))
// (true)
// >>> primeLength(("orange"))
// (false)
public static boolean primeLength(String string) {
| }
} | return new java.math.BigInteger(String.valueOf(string.length())).isProbablePrime(100); | }
public static void main(String[] args) {
assert(primeLength(("Hello")) == (true));
assert(primeLength(("abcdcba")) == (true));
assert(primeLength(("kittens")) == (true));
assert(primeLength(("orange")) == (false));
assert(primeLength(("wow")) == (true));
assert(primeLength(("world")) == (true));
assert(primeLength(("MadaM")) == (true));
assert(primeLength(("Wow")) == (true));
assert(primeLength(("")) == (false));
assert(primeLength(("HI")) == (true));
assert(primeLength(("go")) == (true));
assert(primeLength(("gogo")) == (false));
assert(primeLength(("aaaaaaaaaaaaaaa")) == (false));
assert(primeLength(("Madam")) == (true));
assert(primeLength(("M")) == (false));
assert(primeLength(("0")) == (false));
}
}
|
humaneval-HumanEval_123_get_odd_collatz.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 {
// Given a positive integer n, return a sorted array list that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array list sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// >>> getOddCollatz((5l))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)5l)))
public static ArrayList<Long> getOddCollatz(long n) {
if (n <= 0) return new ArrayList<Long>();
HashSet<Long> odds = new HashSet<Long>();
long n1 = n;
while (n1 > 1) { | n1 = n1 % 2 == 0 ? n1 / 2 : 3 * n1 + 1;
}
odds.add(1l);
Long[] odds_arr = odds.toArray(new Long[odds.size()]);
ArrayList<Long> ans = new ArrayList<Long>(Arrays.asList(odds_arr));
Collections.sort(ans);
return ans;
}
} | if (n1 % 2 == 1) odds.add(n1); | }
public static void main(String[] args) {
assert(getOddCollatz((14l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)7l, (long)11l, (long)13l, (long)17l)))));
assert(getOddCollatz((5l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l)))));
assert(getOddCollatz((12l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l)))));
assert(getOddCollatz((1l)).equals((new ArrayList<Long>(Arrays.asList((long)1l)))));
}
}
|
humaneval-HumanEval_118_get_closest_vowel.json-L31 | js | //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:
// >>> get_closest_vowel("yogurt")
// "u"
// >>> get_closest_vowel("FULL")
// "U"
// >>> get_closest_vowel("quick")
// ""
// >>> get_closest_vowel("ab")
// ""
function get_closest_vowel(word){
let vowels = ["a", "e", "i", "o", "u"];
let i = word.length - 1;
let result = [];
if (word.length === 1) {
return ""
} else {
while (i >= 0) {
if (vowels.includes(word[i])) {
if (i > 0 && i < word.length - 1) {
if (!vowels.includes(word[i-1]) && !vowels.includes(word[i+1])) {
result.push(word[i]);
}
}
}
i--; | if (result.length === 0) {
return ""
} else {
return result[0];
}
}
} | } | const assert = require('node:assert');
function test() {
let candidate = get_closest_vowel;
assert.deepEqual(candidate("yogurt"),"u");
assert.deepEqual(candidate("full"),"u");
assert.deepEqual(candidate("easy"),"");
assert.deepEqual(candidate("eAsy"),"");
assert.deepEqual(candidate("ali"),"");
assert.deepEqual(candidate("bad"),"a");
assert.deepEqual(candidate("most"),"o");
assert.deepEqual(candidate("ab"),"");
assert.deepEqual(candidate("ba"),"");
assert.deepEqual(candidate("quick"),"");
assert.deepEqual(candidate("anime"),"i");
assert.deepEqual(candidate("Asia"),"");
assert.deepEqual(candidate("Above"),"o");
}
test(); |
humaneval-HumanEval_146_specialFilter.json-L20 | py | from typing import List
def specialFilter(nums: List[int]) -> int:
"""Write a function that takes an array of numbers as input and returns
the number of elements in the array that are greater than 10 and both
first and last digits of a number are odd (1, 3, 5, 7, 9).
For example:
>>> specialFilter([15, -73, 14, -15])
1
>>> specialFilter([33, -2, -3, 45, 21, 109])
2
"""
count = 0
for num in nums:
if num < 10:
continue
else:
rev = int(str(num)[::-1])
if num % 2 != 0 and rev % 2 != 0: | return count
| count += 1 | def check(candidate):
assert candidate([5, -2, 1, -5]) == 0
assert candidate([15, -73, 14, -15]) == 1
assert candidate([33, -2, -3, 45, 21, 109]) == 2
assert candidate([43, -12, 93, 125, 121, 109]) == 4
assert candidate([71, -2, -33, 75, 21, 19]) == 3
assert candidate([1]) == 0
assert candidate([]) == 0
def test_check():
check(specialFilter)
test_check()
|
humaneval-HumanEval_148_bf.json-L40 | 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 position1 = keys.indexOf(planet1);
var position2 = keys.indexOf(planet2);
if(position1 > position2){
var temp = position1;
position1 = position2;
position2 = temp;
}
var res = []; | res.push(keys[i]);
}
return res;
} | for(var i = position1 + 1; i < position2; i++){ | 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_78_hex_key.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 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:
// >>> hexKey(("AB"))
// (1l)
// >>> hexKey(("1077E"))
// (2l)
// >>> hexKey(("ABED1A33"))
// (4l)
// >>> hexKey(("123456789ABCDEF0"))
// (6l)
// >>> hexKey(("2020"))
// (2l)
public static long hexKey(String num) {
long result = 0;
for (int i = 0; i < num.length(); i++) {
if (num.charAt(i) == '2' || num.charAt(i) == '3' || num.charAt(i) == '5' || num.charAt(i) == '7' || num.charAt(i) == 'B' || num.charAt(i) == 'D') {
result++; | }
return result;
}
} | } | }
public static void main(String[] args) {
assert(hexKey(("AB")) == (1l));
assert(hexKey(("1077E")) == (2l));
assert(hexKey(("ABED1A33")) == (4l));
assert(hexKey(("2020")) == (2l));
assert(hexKey(("123456789ABCDEF0")) == (6l));
assert(hexKey(("112233445566778899AABBCCDDEEFF00")) == (12l));
}
}
|
humaneval-HumanEval_60_sum_to_n.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 {
// sum_to_n is a function that sums numbers from 1 to n.
// >>> sumToN((30l))
// (465l)
// >>> sumToN((100l))
// (5050l)
// >>> sumToN((5l))
// (15l)
// >>> sumToN((10l))
// (55l)
// >>> sumToN((1l))
// (1l)
public static long sumToN(long n) {
return (n * (n + 1)) / 2;
} | } | }
public static void main(String[] args) {
assert(sumToN((1l)) == (1l));
assert(sumToN((6l)) == (21l));
assert(sumToN((11l)) == (66l));
assert(sumToN((30l)) == (465l));
assert(sumToN((100l)) == (5050l));
}
}
|
|
humaneval-HumanEval_9_rolling_max.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 {
// From a given array list of integers, generate an array array list of rolling maximum element found until given moment
// in the sequence.
// >>> rollingMax((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)2l, (long)3l, (long)4l, (long)2l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)3l, (long)3l, (long)4l, (long)4l)))
public static ArrayList<Long> rollingMax(ArrayList<Long> numbers) {
ArrayList<Long> results = new ArrayList<Long>(); | results.add(numbers.subList(0, i + 1).stream().max(Long::compare).get());
}
return results;
}
} | for (int i = 0; i < numbers.size(); i++) { | }
public static void main(String[] args) {
assert(rollingMax((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(rollingMax((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))));
assert(rollingMax((new ArrayList<Long>(Arrays.asList((long)4l, (long)3l, (long)2l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)4l, (long)4l, (long)4l, (long)4l)))));
assert(rollingMax((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)3l, (long)100l, (long)3l)))).equals((new ArrayList<Long>(Arrays.asList((long)3l, (long)3l, (long)3l, (long)100l, (long)100l)))));
}
}
|
humaneval-HumanEval_70_strange_sort_list.json-L38 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given array list of integers, return array 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:
// >>> strangeSortList((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)2l, (long)3l)))
// >>> strangeSortList((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)5l, (long)5l))))
// (new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)5l, (long)5l)))
// >>> strangeSortList((new ArrayList<Long>(Arrays.asList())))
// (new ArrayList<Long>(Arrays.asList()))
public static ArrayList<Long> strangeSortList(ArrayList<Long> lst) {
if (lst.size() <= 1) {
return lst;
}
ArrayList<Long> result = new ArrayList<Long>();
ArrayList<Long> sorted = new ArrayList<Long>(lst);
Collections.sort(sorted);
int min = 0;
int max = sorted.size() - 1;
while (min <= max) {
result.add(sorted.get(min));
min++;
if (min <= max) {
result.add(sorted.get(max));
max--;
}
}
return result;
} | } | }
public static void main(String[] args) {
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)2l, (long)3l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)7l, (long)8l, (long)9l)))).equals((new ArrayList<Long>(Arrays.asList((long)5l, (long)9l, (long)6l, (long)8l, (long)7l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)2l, (long)4l, (long)3l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)7l, (long)8l, (long)9l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)9l, (long)5l, (long)8l, (long)6l, (long)7l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)5l, (long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)5l, (long)5l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l, (long)8l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)8l, (long)2l, (long)7l, (long)3l, (long)6l, (long)4l, (long)5l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)0l, (long)2l, (long)2l, (long)2l, (long)5l, (long)5l, (long)-5l, (long)-5l)))).equals((new ArrayList<Long>(Arrays.asList((long)-5l, (long)5l, (long)-5l, (long)5l, (long)0l, (long)2l, (long)2l, (long)2l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)111111l)))).equals((new ArrayList<Long>(Arrays.asList((long)111111l)))));
}
}
|
|
humaneval-HumanEval_103_rounded_avg.json-L22 | py | from typing import Union
def rounded_avg(n: int, m: int) -> Union[str, int]:
"""You are given two positive integers n and m, and your task is to compute the
average of the integers from n through m (including n and m).
Round the answer to the nearest integer and convert that to binary.
If n is greater than m, return -1.
Example:
>>> rounded_avg(1, 5)
'0b11'
>>> rounded_avg(7, 5)
-1
>>> rounded_avg(10, 20)
'0b1111'
>>> rounded_avg(20, 33)
'0b11010'
"""
if n <= m:
rounded_avg = round(((n + m) / 2))
return(bin(rounded_avg))
else: | return(-1) | def check(candidate):
assert candidate(1, 5) == '0b11'
assert candidate(7, 13) == '0b1010'
assert candidate(964, 977) == '0b1111001010'
assert candidate(996, 997) == '0b1111100100'
assert candidate(560, 851) == '0b1011000010'
assert candidate(185, 546) == '0b101101110'
assert candidate(362, 496) == '0b110101101'
assert candidate(350, 902) == '0b1001110010'
assert candidate(197, 233) == '0b11010111'
assert candidate(7, 5) == -1
assert candidate(5, 1) == -1
assert candidate(5, 5) == '0b101'
def test_check():
check(rounded_avg)
test_check()
|
|
humaneval-HumanEval_109_move_one_ball.json-L33 | py | from typing import List
def move_one_ball(arr: List[int]) -> bool:
"""We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
numbers in the array will be randomly ordered. Your task is to determine if
it is possible to get an array sorted in non-decreasing order by performing
the following operation on the given array:
You are allowed to perform right shift operation any number of times.
One right shift operation means shifting all elements of the array by one
position in the right direction. The last element of the array will be moved to
the starting position in the array i.e. 0th index.
If it is possible to obtain the sorted array by performing the above operation
then return True else return False.
If the given array is empty then return True.
Note: The given list is guaranteed to have unique elements.
For Example:
>>> move_one_ball([3, 4, 5, 1, 2])
True
Explanation: By performin 2 right shift operations, non-decreasing order can
be achieved for the given array.
>>> move_one_ball([3, 5, 4, 1, 2])
False
Explanation:It is not possible to get non-decreasing order for the given
array by performing any number of right shift operations.
"""
flag = False | if arr[i-1] > arr[i]:
if flag == True:
return False
flag = True
elif arr[i-1] < arr[i]:
flag = False
return True
| for i in range(1, len(arr)): | def check(candidate):
assert candidate([3, 4, 5, 1, 2]) == True
assert candidate([3, 5, 10, 1, 2]) == True
assert candidate([4, 3, 1, 2]) == False
assert candidate([3, 5, 4, 1, 2]) == False
assert candidate([]) == True
def test_check():
check(move_one_ball)
test_check()
|
humaneval-HumanEval_8_sum_product.json-L13 | 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; | sum += numbers[i];
product *= numbers[i];
}
return [sum, product];
}
| for(let i = 0; i < numbers.length; 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_10_make_palindrome.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 {
// 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.
// >>> makePalindrome((""))
// ("")
// >>> makePalindrome(("cat"))
// ("catac")
// >>> makePalindrome(("cata"))
// ("catac")
public static String makePalindrome(String string) {
StringBuilder newString = new StringBuilder(string);
String reverse = new StringBuilder(string).reverse().toString();
for (int index = 0; index < string.length(); index++) {
if (string.substring(index).equals(reverse.substring(0, string.length() - index))) {
newString.append(reverse.substring(string.length() - index));
break;
} | return newString.toString();
}
} | } | }
public static void main(String[] args) {
assert(makePalindrome(("")).equals(("")));
assert(makePalindrome(("x")).equals(("x")));
assert(makePalindrome(("xyz")).equals(("xyzyx")));
assert(makePalindrome(("xyx")).equals(("xyx")));
assert(makePalindrome(("jerry")).equals(("jerryrrej")));
}
}
|
humaneval-HumanEval_148_bf.json-L37 | 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 position1 = keys.indexOf(planet1);
var position2 = keys.indexOf(planet2);
if(position1 > position2){
var temp = position1;
position1 = position2; | }
var res = [];
for(var i = position1 + 1; i < position2; i++){
res.push(keys[i]);
}
return res;
} | position2 = temp; | 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_81_numerical_letter_grade.json-L49 | py | from typing import List
def numerical_letter_grade(grades: List[float]) -> List[str]:
"""It is the last week of the semester and the teacher has to give the grades
to students. The teacher has been making her own algorithm for grading.
The only problem is, she has lost the code she used for grading.
She has given you a list of GPAs for some students and you have to write
a function that can output a list 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-']
"""
final = []
for x in grades:
if x == 4.0:
final.append('A+')
elif x > 3.7:
final.append('A')
elif x > 3.3:
final.append('A-')
elif x > 3.0:
final.append('B+')
elif x > 2.7:
final.append('B')
elif x > 2.3:
final.append('B-')
elif x > 2.0:
final.append('C+')
elif x > 1.7:
final.append('C')
elif x > 1.3:
final.append('C-') | final.append('D+')
elif x > 0.7:
final.append('D')
elif x > 0.0:
final.append('D-')
else:
final.append('E')
return final
| elif x > 1.0: | def check(candidate):
assert candidate([4.0, 3, 1.7, 2, 3.5]) == ['A+', 'B', 'C-', 'C', 'A-']
assert candidate([1.2]) == ['D+']
assert candidate([0.5]) == ['D-']
assert candidate([0.0]) == ['E']
assert candidate([1.0, 0.3, 1.5, 2.8, 3.3]) == ['D', 'D-', 'C-', 'B', 'B+']
assert candidate([0.0, 0.7]) == ['E', 'D-']
def test_check():
check(numerical_letter_grade)
test_check()
|
humaneval-HumanEval_33_sort_third.json-L47 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// 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_70_strange_sort_list.json-L24 | 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:
out.append(lst.pop(0))
if not lst:
break
out.append(lst.pop()) | return out | 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_118_get_closest_vowel.json-L35 | js | //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:
// >>> get_closest_vowel("yogurt")
// "u"
// >>> get_closest_vowel("FULL")
// "U"
// >>> get_closest_vowel("quick")
// ""
// >>> get_closest_vowel("ab")
// ""
function get_closest_vowel(word){
let vowels = ["a", "e", "i", "o", "u"];
let i = word.length - 1;
let result = [];
if (word.length === 1) {
return ""
} else {
while (i >= 0) {
if (vowels.includes(word[i])) {
if (i > 0 && i < word.length - 1) {
if (!vowels.includes(word[i-1]) && !vowels.includes(word[i+1])) {
result.push(word[i]);
}
}
}
i--;
}
if (result.length === 0) {
return ""
} else { | }
}
} | return result[0]; | const assert = require('node:assert');
function test() {
let candidate = get_closest_vowel;
assert.deepEqual(candidate("yogurt"),"u");
assert.deepEqual(candidate("full"),"u");
assert.deepEqual(candidate("easy"),"");
assert.deepEqual(candidate("eAsy"),"");
assert.deepEqual(candidate("ali"),"");
assert.deepEqual(candidate("bad"),"a");
assert.deepEqual(candidate("most"),"o");
assert.deepEqual(candidate("ab"),"");
assert.deepEqual(candidate("ba"),"");
assert.deepEqual(candidate("quick"),"");
assert.deepEqual(candidate("anime"),"i");
assert.deepEqual(candidate("Asia"),"");
assert.deepEqual(candidate("Above"),"o");
}
test(); |
humaneval-HumanEval_71_triangle_area.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 {
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// >>> triangleArea((3l), (4l), (5l))
// (6.0f)
// >>> triangleArea((1l), (2l), (10l))
// (float)-1l
public static float triangleArea(long a, long b, long c) {
if(a + b > c && a + c > b && b + c > a) {
float s = (a + b + c) / 2.0f;
float area = (float)Math.sqrt(s * (s - a) * (s - b) * (s - c));
return (float)Math.round(area * 100) / 100;
}
return -1;
} | } | }
public static void main(String[] args) {
assert(triangleArea((3l), (4l), (5l)) == (6.0f));
assert(triangleArea((1l), (2l), (10l)) == (float)-1l);
assert(triangleArea((4l), (8l), (5l)) == (8.18f));
assert(triangleArea((2l), (2l), (2l)) == (1.73f));
assert(triangleArea((1l), (2l), (3l)) == (float)-1l);
assert(triangleArea((10l), (5l), (7l)) == (16.25f));
assert(triangleArea((2l), (6l), (3l)) == (float)-1l);
assert(triangleArea((1l), (1l), (1l)) == (0.43f));
assert(triangleArea((2l), (2l), (10l)) == (float)-1l);
}
}
|
|
humaneval-HumanEval_88_sort_array.json-L34 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given 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());
} | Collections.sort(array);
}
}
return array;
}
} | else { | }
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_48_is_palindrome.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 {
// Checks if given string is a palindrome
// >>> isPalindrome((""))
// (true)
// >>> isPalindrome(("aba"))
// (true)
// >>> isPalindrome(("aaaaa"))
// (true)
// >>> isPalindrome(("zbcd"))
// (false)
public static boolean isPalindrome(String text) {
boolean isPalindrome = true;
int left = 0;
int right = text.length() - 1;
while (left < right) {
if (text.charAt(left) != text.charAt(right)) {
isPalindrome = false; | }
left++;
right--;
}
return isPalindrome;
}
} | break; | }
public static void main(String[] args) {
assert(isPalindrome(("")) == (true));
assert(isPalindrome(("aba")) == (true));
assert(isPalindrome(("aaaaa")) == (true));
assert(isPalindrome(("zbcd")) == (false));
assert(isPalindrome(("xywyx")) == (true));
assert(isPalindrome(("xywyz")) == (false));
assert(isPalindrome(("xywzx")) == (false));
}
}
|
humaneval-HumanEval_66_digitSum.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 {
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// >>> digitSum((""))
// (0l)
// >>> digitSum(("abAB"))
// (131l)
// >>> digitSum(("abcCd"))
// (67l)
// >>> digitSum(("helloE"))
// (69l)
// >>> digitSum(("woArBld"))
// (131l)
// >>> digitSum(("aAaaaXa"))
// (153l)
public static long digitSum(String s) {
return s.chars().filter(i -> i >= 65 && i <= 90).sum();
} | } | }
public static void main(String[] args) {
assert(digitSum(("")) == (0l));
assert(digitSum(("abAB")) == (131l));
assert(digitSum(("abcCd")) == (67l));
assert(digitSum(("helloE")) == (69l));
assert(digitSum(("woArBld")) == (131l));
assert(digitSum(("aAaaaXa")) == (153l));
assert(digitSum((" How are yOu?")) == (151l));
assert(digitSum(("You arE Very Smart")) == (327l));
}
}
|
|
humaneval-HumanEval_70_strange_sort_list.json-L18 | 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++){ | output.push(Math.min.apply(null, tmp));
}
else{
output.push(Math.max.apply(null, tmp));
}
tmp.splice(tmp.indexOf(output[i]), 1);
}
return output;
} | if(i % 2 === 0){ | 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_89_encrypt.json-L20 | js | //Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// >>> encrypt("hi")
// "lm"
// >>> encrypt("asdfghjkl")
// "ewhjklnop"
// >>> encrypt("gf")
// "kj"
// >>> encrypt("et")
// "ix"
function encrypt(s){
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var newString = "";
var shiftBy = 2 * 2;
for(var i = 0; i < s.length; i++){
var index = alphabet.indexOf(s[i]); | }
return newString;
}
| newString += alphabet[(index + shiftBy) % 26]; | const assert = require('node:assert');
function test() {
let candidate = encrypt;
assert.deepEqual(candidate("hi"),"lm");
assert.deepEqual(candidate("asdfghjkl"),"ewhjklnop");
assert.deepEqual(candidate("gf"),"kj");
assert.deepEqual(candidate("et"),"ix");
assert.deepEqual(candidate("faewfawefaewg"),"jeiajeaijeiak");
assert.deepEqual(candidate("hellomyfriend"),"lippsqcjvmirh");
assert.deepEqual(candidate("dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh"),"hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl");
assert.deepEqual(candidate("a"),"e");
}
test(); |
humaneval-HumanEval_37_sort_even.json-L16 | 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_59_largest_prime_factor.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 the largest prime factor of n. Assume n > 1 and is not a prime.
// >>> largestPrimeFactor((13195l))
// (29l)
// >>> largestPrimeFactor((2048l))
// (2l)
public static long largestPrimeFactor(long n) {
List<Long> primes = new ArrayList<>();
long x = n;
for (long i = 2; i * i <= x; i++) {
if (x % i == 0) {
primes.add(i);
x /= i;
i--; | }
if (x > 1) {
primes.add(x);
}
return primes.get(primes.size() - 1);
}
} | } | }
public static void main(String[] args) {
assert(largestPrimeFactor((15l)) == (5l));
assert(largestPrimeFactor((27l)) == (3l));
assert(largestPrimeFactor((63l)) == (7l));
assert(largestPrimeFactor((330l)) == (11l));
assert(largestPrimeFactor((13195l)) == (29l));
}
}
|
humaneval-HumanEval_141_file_name_check.json-L23 | js | //Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// >>> file_name_check("example.txt")
// "Yes"
// >>> file_name_check("1example.dll")
// "No"
function file_name_check(file_name){
let str_1 = file_name.slice(0,file_name.indexOf('.'));
let str_2 = file_name.slice(file_name.indexOf('.')+1);
let str_3 = file_name.split('');
if (file_name.includes('.') && /[a-zA-Z]/.test(str_1[0]) &&
(str_2 == 'txt' || str_2 == 'exe' || str_2 == 'dll') && str_1.length != 0 &&
str_3.filter(item => /[0-9]/.test(item)).length < 4) {
return 'Yes'; | return 'No';
}
| } | const assert = require('node:assert');
function test() {
let candidate = file_name_check;
assert.deepEqual(candidate("example.txt"),"Yes");
assert.deepEqual(candidate("1example.dll"),"No");
assert.deepEqual(candidate("s1sdf3.asd"),"No");
assert.deepEqual(candidate("K.dll"),"Yes");
assert.deepEqual(candidate("MY16FILE3.exe"),"Yes");
assert.deepEqual(candidate("His12FILE94.exe"),"No");
assert.deepEqual(candidate("_Y.txt"),"No");
assert.deepEqual(candidate("?aREYA.exe"),"No");
assert.deepEqual(candidate("/this_is_valid.dll"),"No");
assert.deepEqual(candidate("this_is_valid.wow"),"No");
assert.deepEqual(candidate("this_is_valid.txt"),"Yes");
assert.deepEqual(candidate("this_is_valid.txtexe"),"No");
assert.deepEqual(candidate("#this2_i4s_5valid.ten"),"No");
assert.deepEqual(candidate("@this1_is6_valid.exe"),"No");
assert.deepEqual(candidate("this_is_12valid.6exe4.txt"),"No");
assert.deepEqual(candidate("all.exe.txt"),"No");
assert.deepEqual(candidate("I563_No.exe"),"Yes");
assert.deepEqual(candidate("Is3youfault.txt"),"Yes");
assert.deepEqual(candidate("no_one#knows.dll"),"Yes");
assert.deepEqual(candidate("1I563_Yes3.exe"),"No");
assert.deepEqual(candidate("I563_Yes3.txtt"),"No");
assert.deepEqual(candidate("final..txt"),"No");
assert.deepEqual(candidate("final132"),"No");
assert.deepEqual(candidate("_f4indsartal132."),"No");
assert.deepEqual(candidate(".txt"),"No");
assert.deepEqual(candidate("s."),"No");
}
test(); |
humaneval-HumanEval_156_int_to_mini_roman.json-L14 | 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", | 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++){
if (key_list[i] <= number){
output += roman_conversion[key_list[i]];
number -= key_list[i];
break;
}
}
}
return output;
}
| 900: "cm", | 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_160_do_algebra.json-L32 | 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){
switch(operator[count]){
case '*':
operand[count] = operand[count] * operand[count + 1];
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true; | 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;
}
| break; | const assert = require('node:assert');
function test() {
let candidate = do_algebra;
assert.deepEqual(candidate(["**", "*", "+"], [2, 3, 4, 5]),37);
assert.deepEqual(candidate(["+", "*", "-"], [2, 3, 4, 5]),9);
assert.deepEqual(candidate(["//", "*"], [7, 3, 4]),8);
}
test(); |
humaneval-HumanEval_85_add.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 {
// 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++) {
if (i % 2 == 1 && lst.get(i) % 2 == 0) {
sum += lst.get(i);
}
}
return sum; | } | } | }
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_143_words_in_sentence.json-L23 | js | //You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// >>> words_in_sentence("This is a test")
// "is"
// Example 2:
// >>> words_in_sentence("lets go for swimming")
// "go for"
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
function words_in_sentence(sentence){
return sentence.split(' ').filter(word => {
var number = word.length;
var isPrime = true;
if(number === 1 || number === 0){
return false;
}
for(var i = 2; i < number; i++){ | isPrime = false;
break;
}
}
return isPrime;
}).join(' ');
} | if(number % i === 0){ | const assert = require('node:assert');
function test() {
let candidate = words_in_sentence;
assert.deepEqual(candidate("This is a test"),"is");
assert.deepEqual(candidate("lets go for swimming"),"go for");
assert.deepEqual(candidate("there is no place available here"),"there is no place");
assert.deepEqual(candidate("Hi I am Hussein"),"Hi am Hussein");
assert.deepEqual(candidate("go for it"),"go for it");
assert.deepEqual(candidate("here"),"");
assert.deepEqual(candidate("here is"),"is");
}
test(); |
humaneval-HumanEval_0_has_close_elements.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 {
// Check if in given array list of numbers, are any two numbers closer to each other than
// given threshold.
// >>> hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f))), (0.5f))
// (false)
// >>> hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.8f, (float)3.0f, (float)4.0f, (float)5.0f, (float)2.0f))), (0.3f))
// (true)
public static boolean hasCloseElements(ArrayList<Float> numbers, float threshold) {
Collections.sort(numbers);
for (int i = 0; i < numbers.size() - 1; i++) {
if (numbers.get(i+1) - numbers.get(i) < threshold) {
return true;
}
} | }
} | return false; | }
public static void main(String[] args) {
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.9f, (float)4.0f, (float)5.0f, (float)2.2f))), (0.3f)) == (true));
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.9f, (float)4.0f, (float)5.0f, (float)2.2f))), (0.05f)) == (false));
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)5.9f, (float)4.0f, (float)5.0f))), (0.95f)) == (true));
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)5.9f, (float)4.0f, (float)5.0f))), (0.8f)) == (false));
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f, (float)4.0f, (float)5.0f, (float)2.0f))), (0.1f)) == (true));
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.1f, (float)2.2f, (float)3.1f, (float)4.1f, (float)5.1f))), (1.0f)) == (true));
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.1f, (float)2.2f, (float)3.1f, (float)4.1f, (float)5.1f))), (0.5f)) == (false));
}
}
|
humaneval-HumanEval_14_all_prefixes.json-L14 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return array list of all prefixes from shortest to longest of the input string
// >>> allPrefixes(("abc"))
// (new ArrayList<String>(Arrays.asList((String)"a", (String)"ab", (String)"abc")))
public static ArrayList<String> allPrefixes(String string) {
ArrayList<String> result = new ArrayList<String>(); | result.add(string.substring(0, i + 1));
}
return result;
}
} | for (int i = 0; i < string.length(); i++) { | }
public static void main(String[] args) {
assert(allPrefixes(("")).equals((new ArrayList<String>(Arrays.asList()))));
assert(allPrefixes(("asdfgh")).equals((new ArrayList<String>(Arrays.asList((String)"a", (String)"as", (String)"asd", (String)"asdf", (String)"asdfg", (String)"asdfgh")))));
assert(allPrefixes(("WWW")).equals((new ArrayList<String>(Arrays.asList((String)"W", (String)"WW", (String)"WWW")))));
}
}
|
humaneval-HumanEval_141_file_name_check.json-L30 | py | def file_name_check(file_name: str) -> str:
"""Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is valid, and returns 'No' otherwise.
A file's name is considered to be valid if and only if all the following conditions
are met:
- There should not be more than three digits ('0'-'9') in the file's name.
- The file's name contains exactly one dot '.'
- The substring before the dot should not be empty, and it starts with a letter from
the latin alphapet ('a'-'z' and 'A'-'Z').
- The substring after the dot should be one of these: ['txt', 'exe', 'dll']
Examples:
>>> file_name_check('example.txt')
'Yes'
>>> file_name_check('1example.dll')
'No'
"""
if not file_name:
return 'No'
s_count = 0
e_count = 0
for i in file_name:
if i.isdigit():
s_count += 1
if i == '.':
e_count += 1
if s_count > 3 or e_count != 1:
return 'No'
s_name = file_name.split('.')[0]
e_name = file_name.split('.')[1] | return 'No'
if e_name not in ['txt', 'exe', 'dll']:
return 'No'
return 'Yes'
| if not s_name or not e_name or not s_name[0].isalpha(): | def check(candidate):
assert candidate('example.txt') == 'Yes'
assert candidate('1example.dll') == 'No'
assert candidate('s1sdf3.asd') == 'No'
assert candidate('K.dll') == 'Yes'
assert candidate('MY16FILE3.exe') == 'Yes'
assert candidate('His12FILE94.exe') == 'No'
assert candidate('_Y.txt') == 'No'
assert candidate('?aREYA.exe') == 'No'
assert candidate('/this_is_valid.dll') == 'No'
assert candidate('this_is_valid.wow') == 'No'
assert candidate('this_is_valid.txt') == 'Yes'
assert candidate('this_is_valid.txtexe') == 'No'
assert candidate('#this2_i4s_5valid.ten') == 'No'
assert candidate('@this1_is6_valid.exe') == 'No'
assert candidate('this_is_12valid.6exe4.txt') == 'No'
assert candidate('all.exe.txt') == 'No'
assert candidate('I563_No.exe') == 'Yes'
assert candidate('Is3youfault.txt') == 'Yes'
assert candidate('no_one#knows.dll') == 'Yes'
assert candidate('1I563_Yes3.exe') == 'No'
assert candidate('I563_Yes3.txtt') == 'No'
assert candidate('final..txt') == 'No'
assert candidate('final132') == 'No'
assert candidate('_f4indsartal132.') == 'No'
assert candidate('.txt') == 'No'
assert candidate('s.') == 'No'
def test_check():
check(file_name_check)
test_check()
|
humaneval-HumanEval_16_count_distinct_characters.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 {
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// >>> countDistinctCharacters(("xyzXYZ"))
// (3l)
// >>> countDistinctCharacters(("Jerry"))
// (4l)
public static long countDistinctCharacters(String string) {
long result = 0;
string = string.toLowerCase();
Set<Character> set = new HashSet<Character>(); | char c = string.charAt(i);
set.add(c);
}
result = set.size();
return result;
}
} | for (int i = 0; i < string.length(); i++) { | }
public static void main(String[] args) {
assert(countDistinctCharacters(("")) == (0l));
assert(countDistinctCharacters(("abcde")) == (5l));
assert(countDistinctCharacters(("abcdecadeCADE")) == (5l));
assert(countDistinctCharacters(("aaaaAAAAaaaa")) == (1l));
assert(countDistinctCharacters(("Jerry jERRY JeRRRY")) == (5l));
}
}
|
humaneval-HumanEval_146_specialFilter.json-L19 | py | from typing import List
def specialFilter(nums: List[int]) -> int:
"""Write a function that takes an array of numbers as input and returns
the number of elements in the array that are greater than 10 and both
first and last digits of a number are odd (1, 3, 5, 7, 9).
For example:
>>> specialFilter([15, -73, 14, -15])
1
>>> specialFilter([33, -2, -3, 45, 21, 109])
2
"""
count = 0
for num in nums:
if num < 10:
continue
else:
rev = int(str(num)[::-1]) | count += 1
return count
| if num % 2 != 0 and rev % 2 != 0: | def check(candidate):
assert candidate([5, -2, 1, -5]) == 0
assert candidate([15, -73, 14, -15]) == 1
assert candidate([33, -2, -3, 45, 21, 109]) == 2
assert candidate([43, -12, 93, 125, 121, 109]) == 4
assert candidate([71, -2, -33, 75, 21, 19]) == 3
assert candidate([1]) == 0
assert candidate([]) == 0
def test_check():
check(specialFilter)
test_check()
|
humaneval-HumanEval_88_sort_array.json-L20 | js | //Given an array of non-negative integers, return a cojs of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// >>> sort_array([])
// []
// >>> sort_array([5])
// [5]
// >>> sort_array([2, 4, 3, 0, 1, 5])
// [0, 1, 2, 3, 4, 5]
// >>> sort_array([2, 4, 3, 0, 1, 5, 6])
// [6, 5, 4, 3, 2, 1, 0]
function sort_array(array){
let sum = array[0] + array[array.length - 1];
let newArr = [];
if(sum % 2 === 0){
newArr = array.sort(function(a, b){return b - a;}); | newArr = array.sort(function(a, b){return a - b;});
}
return newArr;
} | }else{ | const assert = require('node:assert');
function test() {
let candidate = sort_array;
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([5]),[5]);
assert.deepEqual(candidate([2, 4, 3, 0, 1, 5]),[0, 1, 2, 3, 4, 5]);
assert.deepEqual(candidate([2, 4, 3, 0, 1, 5, 6]),[6, 5, 4, 3, 2, 1, 0]);
assert.deepEqual(candidate([2, 1]),[1, 2]);
assert.deepEqual(candidate([15, 42, 87, 32, 11, 0]),[0, 11, 15, 32, 42, 87]);
assert.deepEqual(candidate([21, 14, 23, 11]),[23, 21, 14, 11]);
}
test(); |
humaneval-HumanEval_88_sort_array.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 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) { | }
else {
Collections.sort(array);
}
}
return array;
}
} | Collections.sort(array, Collections.reverseOrder()); | }
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_19_sort_numbers.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 {
// 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"};
HashMap<String, Integer> indexMap = new HashMap<>();
for (int i = 0; i < nums.length; 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);
}
} | indexMap.put(nums[i], i); | }
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_87_get_row.json-L23 | js | //You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of arrays, [(x1, y1), (x2, y2) ...] such that
// each array is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// >>> get_row([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1)
// [[0, 0], [1, 4], [1, 0], [2, 5], [2, 0]]
// >>> get_row([], 1)
// []
// >>> get_row([[], [1], [1, 2, 3]], 3)
// [[2, 2]]
function get_row(lst, x){
let coordinates = [];
for (let i = 0; i < lst.length; i++){
let array = lst[i];
for (let j = 0; j < array.length; j++){
if (lst[i][j] === x){
coordinates.push([i, j]); | }
}
return coordinates.sort(function(a, b){
return a[0] - b[0] || b[1] - a[1];
});
}
| } | const assert = require('node:assert');
function test() {
let candidate = get_row;
assert.deepEqual(candidate([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1),[[0, 0], [1, 4], [1, 0], [2, 5], [2, 0]]);
assert.deepEqual(candidate([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6]], 2),[[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1]]);
assert.deepEqual(candidate([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 1, 3, 4, 5, 6], [1, 2, 1, 4, 5, 6], [1, 2, 3, 1, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1),[[0, 0], [1, 0], [2, 1], [2, 0], [3, 2], [3, 0], [4, 3], [4, 0], [5, 4], [5, 0], [6, 5], [6, 0]]);
assert.deepEqual(candidate([], 1),[]);
assert.deepEqual(candidate([[1]], 2),[]);
assert.deepEqual(candidate([[], [1], [1, 2, 3]], 3),[[2, 2]]);
}
test(); |
humaneval-HumanEval_61_correct_bracketing.json-L18 | 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 = [];
for (var i = 0; i < brackets.length; i++){
if (brackets[i] == "("){
opens.push(brackets[i]);
}
else if (brackets[i] == ")"){ | opens.pop();
}
else {
return false;
}
}
}
if (opens.length == 0){
return true;
}
else {
return false;
}
} | if (opens.length > 0){ | 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_18_how_many_times.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 {
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// >>> howManyTimes((""), ("a"))
// (0l)
// >>> howManyTimes(("aaa"), ("a"))
// (3l)
// >>> howManyTimes(("aaaa"), ("aa"))
// (3l)
public static long howManyTimes(String string, String substring) {
long count = 0; | while (index != -1) {
index = string.indexOf(substring, index);
if (index != -1) {
index++;
count++;
}
}
return count;
}
} | int index = 0; | }
public static void main(String[] args) {
assert(howManyTimes((""), ("x")) == (0l));
assert(howManyTimes(("xyxyxyx"), ("x")) == (4l));
assert(howManyTimes(("cacacacac"), ("cac")) == (4l));
assert(howManyTimes(("john doe"), ("john")) == (1l));
}
}
|
humaneval-HumanEval_111_histogram.json-L40 | js | //Given a string representing a space separated lowercase letters, return an object
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// >>> histogram("a b c")
// {"a": 1, "b": 1, "c": 1}
// >>> histogram("a b b a")
// {"a": 2, "b": 2}
// >>> histogram("a b c a b")
// {"a": 2, "b": 2}
// >>> histogram("b b b b a")
// {"b": 4}
// >>> histogram("")
// {}
function histogram(test){
if (test.length === 0){
return {};
}
var lst = test.split(" ");
var count = {};
for (var i = 0; i < lst.length; i++){
if (count[lst[i]]){
count[lst[i]] += 1;
}
else{
count[lst[i]] = 1;
}
}
console.log(count);
var max = 0;
var result = {};
for (var key in count){
if (count[key] > max){
max = count[key];
result = {};
result[key] = max;
}
else if (count[key] === max){
result[key] = max; | }
return result;
}
| } | const assert = require('node:assert');
function test() {
let candidate = histogram;
assert.deepEqual(candidate("a b b a"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c a b"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c d g"),{"a": 1, "b": 1, "c": 1, "d": 1, "g": 1});
assert.deepEqual(candidate("r t g"),{"r": 1, "t": 1, "g": 1});
assert.deepEqual(candidate("b b b b a"),{"b": 4});
assert.deepEqual(candidate("r t g"),{"r": 1, "t": 1, "g": 1});
assert.deepEqual(candidate(""),{});
assert.deepEqual(candidate("a"),{"a": 1});
}
test(); |
humaneval-HumanEval_36_fizz_buzz.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 {
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// >>> fizzBuzz((50l))
// (0l)
// >>> fizzBuzz((78l))
// (2l)
// >>> fizzBuzz((79l))
// (3l)
public static long fizzBuzz(long n) {
long res = 0;
for (long i = 0; i < n; i++) {
if (i % 11 == 0 || i % 13 == 0) {
String s = String.valueOf(i);
for (int j = 0; j < s.length(); j++) {
if (s.charAt(j) == '7') { | }
}
}
}
return res;
}
} | res++; | }
public static void main(String[] args) {
assert(fizzBuzz((50l)) == (0l));
assert(fizzBuzz((78l)) == (2l));
assert(fizzBuzz((79l)) == (3l));
assert(fizzBuzz((100l)) == (3l));
assert(fizzBuzz((200l)) == (6l));
assert(fizzBuzz((4000l)) == (192l));
assert(fizzBuzz((10000l)) == (639l));
assert(fizzBuzz((100000l)) == (8026l));
}
}
|
humaneval-HumanEval_95_check_dict_case.json-L18 | 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;
}
else{
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;
} | } | 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_82_prime_length.json-L18 | js | //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
function prime_length(string){
let length = string.length;
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, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199];
if (primes.includes(length)){
return true;
} else { | }
} | return false; | const assert = require('node:assert');
function test() {
let candidate = prime_length;
assert.deepEqual(candidate("Hello"),true);
assert.deepEqual(candidate("abcdcba"),true);
assert.deepEqual(candidate("kittens"),true);
assert.deepEqual(candidate("orange"),false);
assert.deepEqual(candidate("wow"),true);
assert.deepEqual(candidate("world"),true);
assert.deepEqual(candidate("MadaM"),true);
assert.deepEqual(candidate("Wow"),true);
assert.deepEqual(candidate(""),false);
assert.deepEqual(candidate("HI"),true);
assert.deepEqual(candidate("go"),true);
assert.deepEqual(candidate("gogo"),false);
assert.deepEqual(candidate("aaaaaaaaaaaaaaa"),false);
assert.deepEqual(candidate("Madam"),true);
assert.deepEqual(candidate("M"),false);
assert.deepEqual(candidate("0"),false);
}
test(); |
humaneval-HumanEval_46_fib4.json-L20 | js | //The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// >>> fib4(5)
// 4
// >>> fib4(6)
// 8
// >>> fib4(7)
// 14
function fib4(n){
var prev = [0,0,2,0];
if(n<prev.length){
return prev[n];
}
for(var i=4;i<=n;i++){ | prev[0] = prev[1];
prev[1] = prev[2];
prev[2] = prev[3];
prev[3] = curr;
}
return prev[3];
}
| var curr = prev[0]+prev[1]+prev[2]+prev[3]; | const assert = require('node:assert');
function test() {
let candidate = fib4;
assert.deepEqual(candidate(5),4);
assert.deepEqual(candidate(8),28);
assert.deepEqual(candidate(10),104);
assert.deepEqual(candidate(12),386);
}
test(); |
humaneval-HumanEval_106_f.json-L13 | 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; | 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;
} | for(var i = 1; i <= n; i++){ | 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_42_incr_list.json-L10 | js | //Return array with elements incremented by 1.
// >>> incr_list([1, 2, 3])
// [2, 3, 4]
// >>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123])
// [6, 4, 6, 3, 4, 4, 10, 1, 124]
function incr_list(l){
var new_list = [];
for(var i = 0; i < l.length; i++){
new_list.push(l[i] + 1); | return new_list;
}
| } | const assert = require('node:assert');
function test() {
let candidate = incr_list;
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([3, 2, 1]),[4, 3, 2]);
assert.deepEqual(candidate([5, 2, 5, 2, 3, 3, 9, 0, 123]),[6, 3, 6, 3, 4, 4, 10, 1, 124]);
}
test(); |
humaneval-HumanEval_3_below_zero.json-L15 | py | from typing import List
def below_zero(operations: List[int]) -> bool:
""" You're given a list of deposit and withdrawal operations on a bank account that starts with
zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
at that point function should return True. Otherwise it should return False.
>>> below_zero([1, 2, 3])
False
>>> below_zero([1, 2, -4, 5])
True
"""
balance = 0
for operation in operations:
balance += operation | return True
return False
print(below_zero([1, 2, 3]))
print(below_zero([1, 2, -4, 5])) | if balance < 0: | def check(candidate):
assert candidate([]) == False
assert candidate([1, 2, -3, 1, 2, -3]) == False
assert candidate([1, 2, -4, 5, 6]) == True
assert candidate([1, -1, 2, -2, 5, -5, 4, -4]) == False
assert candidate([1, -1, 2, -2, 5, -5, 4, -5]) == True
assert candidate([1, -2, 2, -2, 5, -5, 4, -4]) == True
def test_check():
check(below_zero)
test_check()
|
humaneval-HumanEval_114_minSubArraySum.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 {
// Given an array array list of integers nums, find the minimum sum of any non-empty sub-array array list
// of nums.
// Example
// >>> minSubArraySum((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l, (long)1l, (long)2l, (long)4l))))
// (1l)
// >>> minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l))))
// (-6l)
public static long minSubArraySum(ArrayList<Long> nums) {
| long prevMinSum = Long.MAX_VALUE;
for (int i = 0; i < nums.size(); i++) {
long currSum = nums.get(i);
if (currSum < prevMinSum) {
prevMinSum = currSum;
}
if (currSum < minSum) {
minSum = currSum;
}
for (int j = i + 1; j < nums.size(); j++) {
currSum += nums.get(j);
if (currSum < prevMinSum) {
prevMinSum = currSum;
}
if (currSum < minSum) {
minSum = currSum;
}
}
}
return minSum;
}
} | long minSum = Long.MAX_VALUE; | }
public static void main(String[] args) {
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l, (long)1l, (long)2l, (long)4l)))) == (1l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l)))) == (-6l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l, (long)2l, (long)-10l)))) == (-14l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-9999999999999999l)))) == (-9999999999999999l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)0l, (long)10l, (long)20l, (long)1000000l)))) == (0l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l, (long)10l, (long)-5l)))) == (-6l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)100l, (long)-1l, (long)-2l, (long)-3l, (long)10l, (long)-5l)))) == (-6l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)10l, (long)11l, (long)13l, (long)8l, (long)3l, (long)4l)))) == (3l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)100l, (long)-33l, (long)32l, (long)-1l, (long)0l, (long)-2l)))) == (-33l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-10l)))) == (-10l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)7l)))) == (7l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)1l, (long)-1l)))) == (-1l));
}
}
|
humaneval-HumanEval_149_sorted_list_sum.json-L37 | js | //Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// >>> list_sort(["aa", "a", "aaa"])
// ["aa"]
// >>> list_sort(["ab", "a", "aaa", "cd"])
// ["ab", "cd"]
function sorted_list_sum(lst){
var result = [];
for(var i = 0; i < lst.length; i++){
if(lst[i].length % 2 == 0){
result.push(lst[i]);
}
}
return result.sort(function(a, b){
if(a.length < b.length){
return -1;
}
else if(a.length > b.length){
return 1;
}
else{
if(a < b){
return -1;
}
else if(a > b){
return 1;
} | return 0;
}
}
});
}
var a = ["aa", "a", "aaa"];
var b = ["ab", "a", "aaa", "cd"]; | else{ | const assert = require('node:assert');
function test() {
let candidate = sorted_list_sum;
assert.deepEqual(candidate(["aa", "a", "aaa"]),["aa"]);
assert.deepEqual(candidate(["school", "AI", "asdf", "b"]),["AI", "asdf", "school"]);
assert.deepEqual(candidate(["d", "b", "c", "a"]),[]);
assert.deepEqual(candidate(["d", "dcba", "abcd", "a"]),["abcd", "dcba"]);
assert.deepEqual(candidate(["AI", "ai", "au"]),["AI", "ai", "au"]);
assert.deepEqual(candidate(["a", "b", "b", "c", "c", "a"]),[]);
assert.deepEqual(candidate(["aaaa", "bbbb", "dd", "cc"]),["cc", "dd", "aaaa", "bbbb"]);
}
test(); |
humaneval-HumanEval_95_check_dict_case.json-L27 | 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()){ | }
else{
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;
} | case_type = 0; | 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_81_numerical_letter_grade.json-L31 | 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_95_check_dict_case.json-L43 | 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;
}
else{
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;
} | } | 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_143_words_in_sentence.json-L29 | py | def words_in_sentence(sentence: str) -> str:
"""
You are given a string representing a sentence,
the sentence contains some words separated by a space,
and you have to return a string that contains the words from the original sentence,
whose lengths are prime numbers,
the order of the words in the new string should be the same as the original one.
Example 1:
>>> words_in_sentence('This is a test')
'is'
Example 2:
>>> words_in_sentence('lets go for swimming')
'go for'
Constraints:
* 1 <= len(sentence) <= 100
* sentence contains only letters
"""
def is_prime(n: int) -> bool:
if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False
return True
| prime_words = []
for word in words:
if is_prime(len(word)):
prime_words.append(word)
return ' '.join(prime_words) | words = sentence.split() | def check(candidate):
assert candidate('This is a test') == 'is'
assert candidate('lets go for swimming') == 'go for'
assert candidate('there is no place available here') == 'there is no place'
assert candidate('Hi I am Hussein') == 'Hi am Hussein'
assert candidate('go for it') == 'go for it'
assert candidate('here') == ''
assert candidate('here is') == 'is'
def test_check():
check(words_in_sentence)
test_check()
|
humaneval-HumanEval_61_correct_bracketing.json-L17 | 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 = [];
for (var i = 0; i < brackets.length; i++){
if (brackets[i] == "("){
opens.push(brackets[i]);
} | if (opens.length > 0){
opens.pop();
}
else {
return false;
}
}
}
if (opens.length == 0){
return true;
}
else {
return false;
}
} | else if (brackets[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_17_parse_music.json-L30 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Input to this function is a string 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] == '.') { | res.add((long)1l);
i += 1;
}
}
}
return res;
}
} | if (i + 1 < chars.length && chars[i + 1] == '|') { | }
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_118_get_closest_vowel.json-L23 | js | //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:
// >>> get_closest_vowel("yogurt")
// "u"
// >>> get_closest_vowel("FULL")
// "U"
// >>> get_closest_vowel("quick")
// ""
// >>> get_closest_vowel("ab")
// ""
function get_closest_vowel(word){
let vowels = ["a", "e", "i", "o", "u"];
let i = word.length - 1;
let result = [];
if (word.length === 1) {
return ""
} else {
while (i >= 0) { | if (i > 0 && i < word.length - 1) {
if (!vowels.includes(word[i-1]) && !vowels.includes(word[i+1])) {
result.push(word[i]);
}
}
}
i--;
}
if (result.length === 0) {
return ""
} else {
return result[0];
}
}
} | if (vowels.includes(word[i])) { | const assert = require('node:assert');
function test() {
let candidate = get_closest_vowel;
assert.deepEqual(candidate("yogurt"),"u");
assert.deepEqual(candidate("full"),"u");
assert.deepEqual(candidate("easy"),"");
assert.deepEqual(candidate("eAsy"),"");
assert.deepEqual(candidate("ali"),"");
assert.deepEqual(candidate("bad"),"a");
assert.deepEqual(candidate("most"),"o");
assert.deepEqual(candidate("ab"),"");
assert.deepEqual(candidate("ba"),"");
assert.deepEqual(candidate("quick"),"");
assert.deepEqual(candidate("anime"),"i");
assert.deepEqual(candidate("Asia"),"");
assert.deepEqual(candidate("Above"),"o");
}
test(); |
humaneval-HumanEval_90_next_smallest.json-L21 | js | //You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return undefined if there is no such element.
// >>> next_smallest([1, 2, 3, 4, 5])
// 2
// >>> next_smallest([5, 1, 4, 3, 2])
// 2
// >>> next_smallest([])
// undefined
// >>> next_smallest([1, 1])
// undefined
function next_smallest(lst){
if(lst.length<=1){
return undefined;
}
var smallest=Math.min(...lst);
var second_smallest=Number.MAX_VALUE;
for(var i in lst){
if(lst[i]>smallest&&lst[i]<second_smallest){
second_smallest=lst[i]; | }
if(second_smallest==Number.MAX_VALUE){
return undefined;
}
return second_smallest;
} | } | const assert = require('node:assert');
function test() {
let candidate = next_smallest;
assert.deepEqual(candidate([1, 2, 3, 4, 5]),2);
assert.deepEqual(candidate([5, 1, 4, 3, 2]),2);
assert.deepEqual(candidate([]),undefined);
assert.deepEqual(candidate([1, 1]),undefined);
assert.deepEqual(candidate([1, 1, 1, 1, 0]),1);
assert.deepEqual(candidate([1, 1]),undefined);
assert.deepEqual(candidate([-35, 34, 12, -45]),-35);
}
test(); |
humaneval-HumanEval_138_is_equal_to_sum_even.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 {
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// >>> isEqualToSumEven((4l))
// (false)
// >>> isEqualToSumEven((6l))
// (false)
// >>> isEqualToSumEven((8l))
// (true)
public static boolean isEqualToSumEven(long n) {
if (n < 4) {
return false;
}
long d = 2;
if (n % 2 == 1) {
d = 1;
}
long minX = d;
long maxX = n / 4; | long x = (minX + maxX) / 2;
long y = n - 2 * x;
if (y % 2 == 1) {
y--;
}
if (2 * x + y < n) {
minX = x + 1;
} else if (2 * x + y > n) {
maxX = x - 1;
} else {
return true;
}
}
return false;
}
} | while (minX <= maxX) { | }
public static void main(String[] args) {
assert(isEqualToSumEven((4l)) == (false));
assert(isEqualToSumEven((6l)) == (false));
assert(isEqualToSumEven((8l)) == (true));
assert(isEqualToSumEven((10l)) == (true));
assert(isEqualToSumEven((11l)) == (false));
assert(isEqualToSumEven((12l)) == (true));
assert(isEqualToSumEven((13l)) == (false));
assert(isEqualToSumEven((16l)) == (true));
}
}
|
humaneval-HumanEval_108_count_nums.json-L40 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function count_nums which takes an array array list of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// >>> countNums((new ArrayList<Long>(Arrays.asList())))
// (0l)
// >>> countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)11l, (long)-11l))))
// (1l)
// >>> countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l))))
// (3l)
public static long countNums(ArrayList<Long> arr) {
long result = 0l;
for (long i : arr) {
String str = String.valueOf(i);
int sum = 0;
if (str.startsWith("-")) {
sum = sum - (int) Character.getNumericValue(str.charAt(1));
for (int j = 2; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j));
}
} else {
for (int j = 0; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j));
}
}
if (sum > 0) {
result++;
}
}
return result;
} | } | }
public static void main(String[] args) {
assert(countNums((new ArrayList<Long>(Arrays.asList()))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)0l)))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l, (long)-2l, (long)3l, (long)4l, (long)5l)))) == (6l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)6l, (long)9l, (long)-6l, (long)0l, (long)1l, (long)5l)))) == (5l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)100l, (long)98l, (long)-7l, (long)1l, (long)-1l)))) == (4l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)12l, (long)23l, (long)34l, (long)-45l, (long)-56l, (long)0l)))) == (5l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l)))) == (1l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l)))) == (1l));
}
}
|
|
humaneval-HumanEval_63_fibfib.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 {
// 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) {
return 0;
} | 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 == 1) { | }
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_98_count_upper.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 {
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// >>> countUpper(("aBCdEf"))
// (1l)
// >>> countUpper(("abcdefg"))
// (0l)
// >>> countUpper(("dBBE"))
// (0l)
public static long countUpper(String s) {
return (long) IntStream.range(0, s.length())
.filter(i -> i % 2 == 0)
.filter(i -> s.charAt(i) == 'A' || s.charAt(i) == 'E' || s.charAt(i) == 'I' || s.charAt(i) == 'O' || s.charAt(i) == 'U') | }
} | .count(); | }
public static void main(String[] args) {
assert(countUpper(("aBCdEf")) == (1l));
assert(countUpper(("abcdefg")) == (0l));
assert(countUpper(("dBBE")) == (0l));
assert(countUpper(("B")) == (0l));
assert(countUpper(("U")) == (1l));
assert(countUpper(("")) == (0l));
assert(countUpper(("EEEE")) == (2l));
}
}
|
humaneval-HumanEval_6_parse_nested_parens.json-L20 | py | from typing import List
def parse_nested_parens(paren_string: str) -> List[int]:
""" Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
For each of the group, output the deepest level of nesting of parentheses.
E.g. (()()) has maximum two levels of nesting while ((())) has three.
>>> parse_nested_parens('(()()) ((())) () ((())()())')
[2, 3, 1, 3]
"""
result = []
for parens in paren_string.split(' '):
max_depth = 0
current_depth = 0
for paren in parens:
if paren == '(':
current_depth += 1
max_depth = max(max_depth, current_depth)
elif paren == ')': | result.append(max_depth)
return result
| current_depth -= 1 | def check(candidate):
assert candidate('(()()) ((())) () ((())()())') == [2, 3, 1, 3]
assert candidate('() (()) ((())) (((())))') == [1, 2, 3, 4]
assert candidate('(()(())((())))') == [4]
def test_check():
check(parse_nested_parens)
test_check()
|
humaneval-HumanEval_160_do_algebra.json-L62 | 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){
switch(operator[count]){
case '*':
operand[count] = operand[count] * operand[count + 1];
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
case '//':
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;
}
| } | 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_158_find_max.json-L27 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that accepts an array array list of strings.
// The array list contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// >>> findMax((new ArrayList<String>(Arrays.asList((String)"name", (String)"of", (String)"string"))))
// ("string")
// >>> findMax((new ArrayList<String>(Arrays.asList((String)"name", (String)"enam", (String)"game"))))
// ("enam")
// >>> findMax((new ArrayList<String>(Arrays.asList((String)"aaaaaaa", (String)"bb", (String)"cc"))))
// ("aaaaaaa")
public static String findMax(ArrayList<String> words) {
Map<String, Integer> wordsToUniqueCharacters = new HashMap<String, Integer>();
for (String word : words) {
Set<Character> uniqueCharacters = new HashSet<Character>();
for (char c : word.toCharArray()) {
uniqueCharacters.add(c);
}
wordsToUniqueCharacters.put(word, uniqueCharacters.size()); | words.sort(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
int compareResult = wordsToUniqueCharacters.get(o2).compareTo(wordsToUniqueCharacters.get(o1));
if (compareResult == 0) {
return o1.compareTo(o2);
}
return compareResult;
}
});
return words.get(0);
}
} | } | }
public static void main(String[] args) {
assert(findMax((new ArrayList<String>(Arrays.asList((String)"name", (String)"of", (String)"string")))).equals(("string")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"name", (String)"enam", (String)"game")))).equals(("enam")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"aaaaaaa", (String)"bb", (String)"cc")))).equals(("aaaaaaa")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"abc", (String)"cba")))).equals(("abc")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"play", (String)"this", (String)"game", (String)"of", (String)"footbott")))).equals(("footbott")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"we", (String)"are", (String)"gonna", (String)"rock")))).equals(("gonna")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"we", (String)"are", (String)"a", (String)"mad", (String)"nation")))).equals(("nation")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"this", (String)"is", (String)"a", (String)"prrk")))).equals(("this")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"b")))).equals(("b")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"play", (String)"play", (String)"play")))).equals(("play")));
}
}
|
humaneval-HumanEval_94_skjkasdkd.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 {
// You are given an array array list of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l, (long)2l, (long)1l, (long)3l, (long)5l, (long)7l, (long)4l, (long)5l, (long)5l, (long)5l, (long)2l, (long)181l, (long)32l, (long)4l, (long)32l, (long)3l, (long)2l, (long)32l, (long)324l, (long)4l, (long)3l))))
// (10l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)1l, (long)8l, (long)2l, (long)4597l, (long)2l, (long)1l, (long)3l, (long)40l, (long)1l, (long)2l, (long)1l, (long)2l, (long)4l, (long)2l, (long)5l, (long)1l))))
// (25l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)1l, (long)32l, (long)5107l, (long)34l, (long)83278l, (long)109l, (long)163l, (long)23l, (long)2323l, (long)32l, (long)30l, (long)1l, (long)9l, (long)3l))))
// (13l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)724l, (long)32l, (long)71l, (long)99l, (long)32l, (long)6l, (long)0l, (long)5l, (long)91l, (long)83l, (long)0l, (long)5l, (long)6l))))
// (11l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)81l, (long)12l, (long)3l, (long)1l, (long)21l))))
// (3l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)8l, (long)1l, (long)2l, (long)1l, (long)7l))))
// (7l)
public static long skjkasdkd(ArrayList<Long> lst) {
long largestPrime = 0l;
for (Long item : lst) {
long number = item;
int counter = 0;
if (item == 1) {
continue;
}
if (item == 2) { | }
else {
int l = 1;
while (l <= (int) number) {
if (number % l == 0) {
counter++;
}
l++;
}
}
if (counter == 2) {
if (number > largestPrime) {
largestPrime = number;
}
}
}
if (largestPrime == 0) {
return 0l;
}
else {
long output = 0l;
while (largestPrime > 0) {
output += largestPrime % 10;
largestPrime /= 10;
}
return output;
}
}
} | counter = 1; | }
public static void main(String[] args) {
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l, (long)2l, (long)1l, (long)3l, (long)5l, (long)7l, (long)4l, (long)5l, (long)5l, (long)5l, (long)2l, (long)181l, (long)32l, (long)4l, (long)32l, (long)3l, (long)2l, (long)32l, (long)324l, (long)4l, (long)3l)))) == (10l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)1l, (long)8l, (long)2l, (long)4597l, (long)2l, (long)1l, (long)3l, (long)40l, (long)1l, (long)2l, (long)1l, (long)2l, (long)4l, (long)2l, (long)5l, (long)1l)))) == (25l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)1l, (long)32l, (long)5107l, (long)34l, (long)83278l, (long)109l, (long)163l, (long)23l, (long)2323l, (long)32l, (long)30l, (long)1l, (long)9l, (long)3l)))) == (13l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)724l, (long)32l, (long)71l, (long)99l, (long)32l, (long)6l, (long)0l, (long)5l, (long)91l, (long)83l, (long)0l, (long)5l, (long)6l)))) == (11l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)81l, (long)12l, (long)3l, (long)1l, (long)21l)))) == (3l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)8l, (long)1l, (long)2l, (long)1l, (long)7l)))) == (7l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)8191l)))) == (19l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)8191l, (long)123456l, (long)127l, (long)7l)))) == (19l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)127l, (long)97l, (long)8192l)))) == (10l));
}
}
|
humaneval-HumanEval_137_compare_one.json-L31 | 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 | 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
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 | 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_68_pluck.json-L38 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// "Given an array array list representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array array list, [ smalest_value, its index ],
// If there are no even values or the given array array list is empty, return [].
// Example 1:
// >>> pluck((new ArrayList<Long>(Arrays.asList((long)4l, (long)2l, (long)3l))))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)1l)))
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// >>> pluck((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)1l)))
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// >>> pluck((new ArrayList<Long>(Arrays.asList())))
// (new ArrayList<Long>(Arrays.asList()))
// Example 4:
// >>> pluck((new ArrayList<Long>(Arrays.asList((long)5l, (long)0l, (long)3l, (long)0l, (long)4l, (long)2l))))
// (new ArrayList<Long>(Arrays.asList((long)0l, (long)1l)))
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
public static ArrayList<Long> pluck(ArrayList<Long> arr) {
int minIndex = -1;
long minValue = -1;
for (int i = 0; i < arr.size(); i++) { | if (minIndex == -1 || arr.get(i) < minValue) {
minIndex = i;
minValue = arr.get(i);
}
}
}
ArrayList<Long> newArr = new ArrayList<Long>();
if (minIndex == -1) {
return newArr;
}
newArr.add(minValue);
newArr.add((long)minIndex);
return newArr;
}
} | if (arr.get(i) % 2 == 0) { | }
public static void main(String[] args) {
assert(pluck((new ArrayList<Long>(Arrays.asList((long)4l, (long)2l, (long)3l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)1l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)1l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)5l, (long)0l, (long)3l, (long)0l, (long)4l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)0l, (long)5l, (long)3l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)5l, (long)4l, (long)8l, (long)4l, (long)8l)))).equals((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)7l, (long)6l, (long)7l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)6l, (long)1l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)7l, (long)9l, (long)7l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList()))));
}
}
|
humaneval-HumanEval_148_bf.json-L45 | 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++) {
planetsInBetween.add(planets.get(i));
}
return planetsInBetween;
} else { | }
}
} | return new ArrayList<String>(); | }
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_149_sorted_list_sum.json-L30 | js | //Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// >>> list_sort(["aa", "a", "aaa"])
// ["aa"]
// >>> list_sort(["ab", "a", "aaa", "cd"])
// ["ab", "cd"]
function sorted_list_sum(lst){
var result = [];
for(var i = 0; i < lst.length; i++){
if(lst[i].length % 2 == 0){
result.push(lst[i]);
}
}
return result.sort(function(a, b){
if(a.length < b.length){
return -1;
}
else if(a.length > b.length){
return 1;
} | if(a < b){
return -1;
}
else if(a > b){
return 1;
}
else{
return 0;
}
}
});
}
var a = ["aa", "a", "aaa"];
var b = ["ab", "a", "aaa", "cd"]; | else{ | const assert = require('node:assert');
function test() {
let candidate = sorted_list_sum;
assert.deepEqual(candidate(["aa", "a", "aaa"]),["aa"]);
assert.deepEqual(candidate(["school", "AI", "asdf", "b"]),["AI", "asdf", "school"]);
assert.deepEqual(candidate(["d", "b", "c", "a"]),[]);
assert.deepEqual(candidate(["d", "dcba", "abcd", "a"]),["abcd", "dcba"]);
assert.deepEqual(candidate(["AI", "ai", "au"]),["AI", "ai", "au"]);
assert.deepEqual(candidate(["a", "b", "b", "c", "c", "a"]),[]);
assert.deepEqual(candidate(["aaaa", "bbbb", "dd", "cc"]),["cc", "dd", "aaaa", "bbbb"]);
}
test(); |
humaneval-HumanEval_77_iscube.json-L22 | py | def iscube(a: int) -> bool:
"""
Write a function that takes an integer a and returns True
if this ingeger is a cube of some integer number.
Note: you may assume the input is always valid.
Examples:
>>> iscube(1)
True
>>> iscube(2)
False
>>> iscube(-1)
True
>>> iscube(64)
True
>>> iscube(0)
True
>>> iscube(180)
False
"""
import math
a = abs(a) | return True
for i in range(1,int(math.sqrt(a))+1):
if i**3 == a:
return True
return False
pass
| if a == 0: | def check(candidate):
assert candidate(1) == True
assert candidate(2) == False
assert candidate(-1) == True
assert candidate(64) == True
assert candidate(180) == False
assert candidate(1000) == True
assert candidate(0) == True
assert candidate(1729) == False
def test_check():
check(iscube)
test_check()
|
humaneval-HumanEval_149_sorted_list_sum.json-L42 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that accepts an array array list of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array list with a sorted order,
// The array list is always an array array list of strings and never an array array list of numbers,
// and it may contain duplicates.
// The order of the array list should be ascending by length of each word, and you
// should return the array list sorted by that rule.
// If two words have the same length, sort the array list alphabetically.
// The function should return an array array list of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// >>> listSort((new ArrayList<String>(Arrays.asList((String)"aa", (String)"a", (String)"aaa"))))
// (new ArrayList<String>(Arrays.asList((String)"aa")))
// >>> listSort((new ArrayList<String>(Arrays.asList((String)"ab", (String)"a", (String)"aaa", (String)"cd"))))
// (new ArrayList<String>(Arrays.asList((String)"ab", (String)"cd")))
public static ArrayList<String> sortedListSum(ArrayList<String> lst) {
ArrayList<String> result = new ArrayList<String>();
for (String s : lst) {
if (s.length() % 2 == 0) {
result.add(s);
}
}
Collections.sort(result, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
if (s1.length() == s2.length()) {
return s1.compareTo(s2);
}
return s1.length() - s2.length();
}
});
return result;
} | } | }
public static void main(String[] args) {
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"aa", (String)"a", (String)"aaa")))).equals((new ArrayList<String>(Arrays.asList((String)"aa")))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"school", (String)"AI", (String)"asdf", (String)"b")))).equals((new ArrayList<String>(Arrays.asList((String)"AI", (String)"asdf", (String)"school")))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"d", (String)"b", (String)"c", (String)"a")))).equals((new ArrayList<String>(Arrays.asList()))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"d", (String)"dcba", (String)"abcd", (String)"a")))).equals((new ArrayList<String>(Arrays.asList((String)"abcd", (String)"dcba")))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"AI", (String)"ai", (String)"au")))).equals((new ArrayList<String>(Arrays.asList((String)"AI", (String)"ai", (String)"au")))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"a", (String)"b", (String)"b", (String)"c", (String)"c", (String)"a")))).equals((new ArrayList<String>(Arrays.asList()))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"aaaa", (String)"bbbb", (String)"dd", (String)"cc")))).equals((new ArrayList<String>(Arrays.asList((String)"cc", (String)"dd", (String)"aaaa", (String)"bbbb")))));
}
}
|
|
humaneval-HumanEval_106_f.json-L14 | py | from typing import List
def f(n: int) -> List[int]:
""" Implement the function f that takes n as a parameter,
and returns a list 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]
"""
import math | for i in range(n):
i=i+1
if i%2==0:
a.append(math.factorial(i))
else:
a.append(sum(range(1,i+1)))
return a
pass | a=[] | def check(candidate):
assert candidate(5) == [1, 2, 6, 24, 15]
assert candidate(7) == [1, 2, 6, 24, 15, 720, 28]
assert candidate(1) == [1]
assert candidate(3) == [1, 2, 6]
def test_check():
check(f)
test_check()
|
humaneval-HumanEval_95_check_dict_case.json-L24 | 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()){ | }
else if (key == key.toLowerCase()){
case_type = 0;
}
else{
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;
} | case_type = 1; | 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_19_sort_numbers.json-L11 | js | //Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// >>> sort_numbers("three one five")
// "one three five"
function sort_numbers(numbers){
var numString = numbers.split(" ");
var numMap = {
"zero": 0,
"one": 1, | "three": 3,
"four": 4,
"five": 5,
"six": 6,
"seven": 7,
"eight": 8,
"nine": 9
};
numString.sort(function(a, b){
return numMap[a] - numMap[b];
});
numString = numString.join(" ");
return numString;
} | "two": 2, | const assert = require('node:assert');
function test() {
let candidate = sort_numbers;
assert.deepEqual(candidate(""),"");
assert.deepEqual(candidate("three"),"three");
assert.deepEqual(candidate("three five nine"),"three five nine");
assert.deepEqual(candidate("five zero four seven nine eight"),"zero four five seven eight nine");
assert.deepEqual(candidate("six five four three two one zero"),"zero one two three four five six");
}
test(); |
humaneval-HumanEval_113_odd_count.json-L20 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of strings, where each string consists of only digits, return an array array 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.
// >>> oddCount((new ArrayList<String>(Arrays.asList((String)"1234567"))))
// (new ArrayList<String>(Arrays.asList((String)"the number of odd elements 4n the str4ng 4 of the 4nput.")))
// >>> oddCount((new ArrayList<String>(Arrays.asList((String)"3", (String)"11111111"))))
// (new ArrayList<String>(Arrays.asList((String)"the number of odd elements 1n the str1ng 1 of the 1nput.", (String)"the number of odd elements 8n the str8ng 8 of the 8nput.")))
public static ArrayList<String> oddCount(ArrayList<String> lst) {
ArrayList<String> res = new ArrayList<String>();
for (int i = 0; i < lst.size(); i++) { | for (int j = 0; j < lst.get(i).length(); j++) {
if (Integer.parseInt(lst.get(i).substring(j, j + 1)) % 2 == 1) {
count++;
}
}
res.add("the number of odd elements " + count + "n the str" + count + "ng " + count + " of the " + count + "nput.");
}
return res;
}
} | int count = 0; | }
public static void main(String[] args) {
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"1234567")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 4n the str4ng 4 of the 4nput.")))));
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"3", (String)"11111111")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 1n the str1ng 1 of the 1nput.", (String)"the number of odd elements 8n the str8ng 8 of the 8nput.")))));
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"271", (String)"137", (String)"314")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 2n the str2ng 2 of the 2nput.", (String)"the number of odd elements 3n the str3ng 3 of the 3nput.", (String)"the number of odd elements 2n the str2ng 2 of the 2nput.")))));
}
}
|
humaneval-HumanEval_80_is_happy.json-L20 | py | def is_happy(s: str) -> bool:
"""You are given a string s.
Your task is to check if the string is happy or not.
A string is happy if its length is at least 3 and every 3 consecutive letters are distinct
For example:
>>> is_happy(a)
False
>>> is_happy(aa)
False
>>> is_happy(abcd)
True
>>> is_happy(aabb)
False
>>> is_happy(adb)
True
>>> is_happy(xyy)
False
"""
n = len(s) | return False
else:
for i in range(n - 2):
if s[i] == s[i + 1] or s[i] == s[i + 2] or s[i + 1] == s[i + 2]:
return False
return True
| if n < 3: | def check(candidate):
assert candidate('a') == False
assert candidate('aa') == False
assert candidate('abcd') == True
assert candidate('aabb') == False
assert candidate('adb') == True
assert candidate('xyy') == False
assert candidate('iopaxpoi') == True
assert candidate('iopaxioi') == False
def test_check():
check(is_happy)
test_check()
|
humaneval-HumanEval_63_fibfib.json-L18 | py | def fibfib(n: int) -> int:
"""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(1)
0
>>> fibfib(5)
4
>>> fibfib(8)
24
"""
a, b, c = 0, 0, 1
while n > 0:
a, b, c = b, c, a + b + c | return a
| n -= 1 | def check(candidate):
assert candidate(2) == 1
assert candidate(1) == 0
assert candidate(5) == 4
assert candidate(8) == 24
assert candidate(10) == 81
assert candidate(12) == 274
assert candidate(14) == 927
def test_check():
check(fibfib)
test_check()
|
humaneval-HumanEval_61_correct_bracketing.json-L14 | 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 = [];
for (var i = 0; i < brackets.length; i++){ | opens.push(brackets[i]);
}
else if (brackets[i] == ")"){
if (opens.length > 0){
opens.pop();
}
else {
return false;
}
}
}
if (opens.length == 0){
return true;
}
else {
return false;
}
} | if (brackets[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_162_string_to_md5.json-L9 | js | //Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return undefined.
// >>> string_to_md5("Hello world")
// "3e25960a79dbc69b674cd4ec67a72c62"
function string_to_md5(text){
if(text === ''){
return undefined;
} | }
| return require('crypto').createHash('md5').update(text).digest('hex'); | const assert = require('node:assert');
function test() {
let candidate = string_to_md5;
assert.deepEqual(candidate("Hello world"),"3e25960a79dbc69b674cd4ec67a72c62");
assert.deepEqual(candidate(""),undefined);
assert.deepEqual(candidate("A B C"),"0ef78513b0cb8cef12743f5aeb35f888");
assert.deepEqual(candidate("password"),"5f4dcc3b5aa765d61d8327deb882cf99");
}
test(); |
humaneval-HumanEval_137_compare_one.json-L30 | 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: | 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
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 b | 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_137_compare_one.json-L50 | 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
else:
return None
elif isinstance(a, float) and isinstance(b, int): | 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 | if a > b: | 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_137_compare_one.json-L62 | 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
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 | 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_108_count_nums.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 count_nums which takes an array array list of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// >>> countNums((new ArrayList<Long>(Arrays.asList())))
// (0l)
// >>> countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)11l, (long)-11l))))
// (1l)
// >>> countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l))))
// (3l)
public static long countNums(ArrayList<Long> arr) {
long result = 0l;
for (long i : arr) {
String str = String.valueOf(i);
int sum = 0;
if (str.startsWith("-")) {
sum = sum - (int) Character.getNumericValue(str.charAt(1));
for (int j = 2; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j));
}
} else {
for (int j = 0; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j));
}
}
if (sum > 0) {
result++;
}
} | }
} | return result; | }
public static void main(String[] args) {
assert(countNums((new ArrayList<Long>(Arrays.asList()))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)0l)))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l, (long)-2l, (long)3l, (long)4l, (long)5l)))) == (6l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)6l, (long)9l, (long)-6l, (long)0l, (long)1l, (long)5l)))) == (5l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)100l, (long)98l, (long)-7l, (long)1l, (long)-1l)))) == (4l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)12l, (long)23l, (long)34l, (long)-45l, (long)-56l, (long)0l)))) == (5l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l)))) == (1l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l)))) == (1l));
}
}
|
humaneval-HumanEval_88_sort_array.json-L21 | js | //Given an array of non-negative integers, return a cojs of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// >>> sort_array([])
// []
// >>> sort_array([5])
// [5]
// >>> sort_array([2, 4, 3, 0, 1, 5])
// [0, 1, 2, 3, 4, 5]
// >>> sort_array([2, 4, 3, 0, 1, 5, 6])
// [6, 5, 4, 3, 2, 1, 0]
function sort_array(array){
let sum = array[0] + array[array.length - 1];
let newArr = [];
if(sum % 2 === 0){
newArr = array.sort(function(a, b){return b - a;});
}else{ | }
return newArr;
} | newArr = array.sort(function(a, b){return a - b;}); | const assert = require('node:assert');
function test() {
let candidate = sort_array;
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([5]),[5]);
assert.deepEqual(candidate([2, 4, 3, 0, 1, 5]),[0, 1, 2, 3, 4, 5]);
assert.deepEqual(candidate([2, 4, 3, 0, 1, 5, 6]),[6, 5, 4, 3, 2, 1, 0]);
assert.deepEqual(candidate([2, 1]),[1, 2]);
assert.deepEqual(candidate([15, 42, 87, 32, 11, 0]),[0, 11, 15, 32, 42, 87]);
assert.deepEqual(candidate([21, 14, 23, 11]),[23, 21, 14, 11]);
}
test(); |
humaneval-HumanEval_137_compare_one.json-L41 | 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;
} else if (a < b) {
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;
}
} | } | 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_31_is_prime.json-L22 | py | def is_prime(n: int) -> bool:
"""Return true if a given number is prime, and false otherwise.
>>> is_prime(6)
False
>>> is_prime(101)
True
>>> is_prime(11)
True
>>> is_prime(13441)
True
>>> is_prime(61)
True
>>> is_prime(4)
False
>>> is_prime(1)
False
"""
if n <= 1:
return False
for i in range(2, n//2 + 1):
if n % i == 0: | return True
| return False | def check(candidate):
assert candidate(6) == False
assert candidate(101) == True
assert candidate(11) == True
assert candidate(13441) == True
assert candidate(61) == True
assert candidate(4) == False
assert candidate(1) == False
assert candidate(5) == True
assert candidate(11) == True
assert candidate(17) == True
assert candidate(85) == False
assert candidate(77) == False
assert candidate(255379) == False
def test_check():
check(is_prime)
test_check()
|
humaneval-HumanEval_19_sort_numbers.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 {
// 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"};
HashMap<String, Integer> indexMap = new HashMap<>();
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 String.join(" ", split);
}
} | return indexMap.get(s1) - indexMap.get(s2); | }
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_5_intersperse.json-L13 | 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_148_bf.json-L29 | py | from typing import Tuple
def bf(planet1: str, planet2: str) -> Tuple[str, ...]:
"""
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 tuple 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 tuple 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')
"""
planets = ('Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune')
if planet1 not in planets or planet2 not in planets:
return ()
start = planets.index(planet1)
end = planets.index(planet2)
if start < end:
planets = planets[start+1:end] | planets = planets[end+1:start]
return tuple(planets) | else: | def check(candidate):
assert candidate('Jupiter', 'Neptune') == ('Saturn', 'Uranus')
assert candidate('Earth', 'Mercury') == ('Venus',)
assert candidate('Mercury', 'Uranus') == ('Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn')
assert candidate('Neptune', 'Venus') == ('Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus')
assert candidate('Earth', 'Earth') == ()
assert candidate('Mars', 'Earth') == ()
assert candidate('Jupiter', 'Makemake') == ()
def test_check():
check(bf)
test_check()
|
humaneval-HumanEval_81_numerical_letter_grade.json-L60 | 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 {
// 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 array list of GPAs for some students and you have to write
// a function that can output an array array list 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:
// >>> gradeEquation((new ArrayList<Float>(Arrays.asList((float)4.0f, (float)3l, (float)1.7f, (float)2l, (float)3.5f))))
// (new ArrayList<String>(Arrays.asList((String)"A+", (String)"B", (String)"C-", (String)"C", (String)"A-")))
public static ArrayList<String> numericalLetterGrade(ArrayList<Float> grades) {
ArrayList<String> letterGrades = new ArrayList<String>();
for (int i = 0; i < grades.size(); i++) {
float currentGrade = grades.get(i);
if (currentGrade == 4.0f) {
letterGrades.add("A+");
} else if (currentGrade > 3.7f) {
letterGrades.add("A");
} else if (currentGrade > 3.3f) {
letterGrades.add("A-");
} else if (currentGrade > 3.0f) {
letterGrades.add("B+");
} else if (currentGrade > 2.7f) {
letterGrades.add("B");
} else if (currentGrade > 2.3f) {
letterGrades.add("B-");
} else if (currentGrade > 2.0f) {
letterGrades.add("C+");
} else if (currentGrade > 1.7f) {
letterGrades.add("C");
} else if (currentGrade > 1.3f) {
letterGrades.add("C-");
} else if (currentGrade > 1.0f) {
letterGrades.add("D+");
} else if (currentGrade > 0.7f) {
letterGrades.add("D");
} else if (currentGrade > 0.0f) {
letterGrades.add("D-");
} else { | }
}
return letterGrades;
}
} | letterGrades.add("E"); | }
public static void main(String[] args) {
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)4.0f, (float)3l, (float)1.7f, (float)2l, (float)3.5f)))).equals((new ArrayList<String>(Arrays.asList((String)"A+", (String)"B", (String)"C-", (String)"C", (String)"A-")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)1.2f)))).equals((new ArrayList<String>(Arrays.asList((String)"D+")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)0.5f)))).equals((new ArrayList<String>(Arrays.asList((String)"D-")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)0.0f)))).equals((new ArrayList<String>(Arrays.asList((String)"E")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)0.3f, (float)1.5f, (float)2.8f, (float)3.3f)))).equals((new ArrayList<String>(Arrays.asList((String)"D", (String)"D-", (String)"C-", (String)"B", (String)"B+")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)0.0f, (float)0.7f)))).equals((new ArrayList<String>(Arrays.asList((String)"E", (String)"D-")))));
}
}
|
humaneval-HumanEval_42_incr_list.json-L9 | js | //Return array with elements incremented by 1.
// >>> incr_list([1, 2, 3])
// [2, 3, 4]
// >>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123])
// [6, 4, 6, 3, 4, 4, 10, 1, 124]
function incr_list(l){
var new_list = [];
for(var i = 0; i < l.length; i++){ | }
return new_list;
}
| new_list.push(l[i] + 1); | const assert = require('node:assert');
function test() {
let candidate = incr_list;
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([3, 2, 1]),[4, 3, 2]);
assert.deepEqual(candidate([5, 2, 5, 2, 3, 3, 9, 0, 123]),[6, 3, 6, 3, 4, 4, 10, 1, 124]);
}
test(); |
humaneval-HumanEval_120_maximum.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 {
// Given an array array list arr of integers and a positive integer k, return a sorted array list
// of length k with the maximum k numbers in arr.
// Example 1:
// >>> maximum((new ArrayList<Long>(Arrays.asList((long)-3l, (long)-4l, (long)5l))), (3l))
// (new ArrayList<Long>(Arrays.asList((long)-4l, (long)-3l, (long)5l)))
// Example 2:
// >>> maximum((new ArrayList<Long>(Arrays.asList((long)4l, (long)-4l, (long)4l))), (2l))
// (new ArrayList<Long>(Arrays.asList((long)4l, (long)4l)))
// Example 3:
// >>> maximum((new ArrayList<Long>(Arrays.asList((long)-3l, (long)2l, (long)1l, (long)2l, (long)-1l, (long)-2l, (long)1l))), (1l))
// (new ArrayList<Long>(Arrays.asList((long)2l)))
// Note:
// 1. The length of the array array list will be in the range of [1, 1000].
// 2. The elements in the array array list will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
public static ArrayList<Long> maximum(ArrayList<Long> arr, long k) {
Collections.sort(arr);
return new ArrayList<Long>(arr.subList((int)(arr.size() - k), (int)(arr.size())));
} | } | }
public static void main(String[] args) {
assert(maximum((new ArrayList<Long>(Arrays.asList((long)-3l, (long)-4l, (long)5l))), (3l)).equals((new ArrayList<Long>(Arrays.asList((long)-4l, (long)-3l, (long)5l)))));
assert(maximum((new ArrayList<Long>(Arrays.asList((long)4l, (long)-4l, (long)4l))), (2l)).equals((new ArrayList<Long>(Arrays.asList((long)4l, (long)4l)))));
assert(maximum((new ArrayList<Long>(Arrays.asList((long)-3l, (long)2l, (long)1l, (long)2l, (long)-1l, (long)-2l, (long)1l))), (1l)).equals((new ArrayList<Long>(Arrays.asList((long)2l)))));
assert(maximum((new ArrayList<Long>(Arrays.asList((long)123l, (long)-123l, (long)20l, (long)0l, (long)1l, (long)2l, (long)-3l))), (3l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)20l, (long)123l)))));
assert(maximum((new ArrayList<Long>(Arrays.asList((long)-123l, (long)20l, (long)0l, (long)1l, (long)2l, (long)-3l))), (4l)).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)2l, (long)20l)))));
assert(maximum((new ArrayList<Long>(Arrays.asList((long)5l, (long)15l, (long)0l, (long)3l, (long)-13l, (long)-8l, (long)0l))), (7l)).equals((new ArrayList<Long>(Arrays.asList((long)-13l, (long)-8l, (long)0l, (long)0l, (long)3l, (long)5l, (long)15l)))));
assert(maximum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)0l, (long)2l, (long)5l, (long)3l, (long)-10l))), (2l)).equals((new ArrayList<Long>(Arrays.asList((long)3l, (long)5l)))));
assert(maximum((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)5l, (long)-7l))), (1l)).equals((new ArrayList<Long>(Arrays.asList((long)5l)))));
assert(maximum((new ArrayList<Long>(Arrays.asList((long)4l, (long)-4l))), (2l)).equals((new ArrayList<Long>(Arrays.asList((long)-4l, (long)4l)))));
assert(maximum((new ArrayList<Long>(Arrays.asList((long)-10l, (long)10l))), (2l)).equals((new ArrayList<Long>(Arrays.asList((long)-10l, (long)10l)))));
assert(maximum((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)-23l, (long)243l, (long)-400l, (long)0l))), (0l)).equals((new ArrayList<Long>(Arrays.asList()))));
}
}
|
|
humaneval-HumanEval_74_total_match.json-L16 | js | //Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// >>> total_match([], [])
// []
// >>> total_match(["hi", "admin"], ["hI", "Hi"])
// ["hI", "Hi"]
// >>> total_match(["hi", "admin"], ["hi", "hi", "admin", "project"])
// ["hi", "admin"]
// >>> total_match(["hi", "admin"], ["hI", "hi", "hi"])
// ["hI", "hi", "hi"]
// >>> total_match(["4"], ["1", "2", "3", "4", "5"])
// ["4"]
function total_match(lst1, lst2){
| let sum_lst2 = 0;
for(let item of lst1){
sum_lst1 += item.length;
}
for(let item of lst2){
sum_lst2 += item.length;
}
if(sum_lst1 > sum_lst2){
return lst2;
}
else{
return lst1;
}
}
| let sum_lst1 = 0; | const assert = require('node:assert');
function test() {
let candidate = total_match;
assert.deepEqual(candidate([], []),[]);
assert.deepEqual(candidate(["hi", "admin"], ["hi", "hi"]),["hi", "hi"]);
assert.deepEqual(candidate(["hi", "admin"], ["hi", "hi", "admin", "project"]),["hi", "admin"]);
assert.deepEqual(candidate(["4"], ["1", "2", "3", "4", "5"]),["4"]);
assert.deepEqual(candidate(["hi", "admin"], ["hI", "Hi"]),["hI", "Hi"]);
assert.deepEqual(candidate(["hi", "admin"], ["hI", "hi", "hi"]),["hI", "hi", "hi"]);
assert.deepEqual(candidate(["hi", "admin"], ["hI", "hi", "hii"]),["hi", "admin"]);
assert.deepEqual(candidate([], ["this"]),[]);
assert.deepEqual(candidate(["this"], []),[]);
}
test(); |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.