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_121_solution.json-L15 | js | //Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// >>> solution([5, 8, 7, 1])
// 12
// >>> solution([3, 3, 3, 3, 3])
// 9
// >>> solution([30, 13, 24, 321])
// 0
function solution(lst){
let result = 0;
for (let i = 0; i < lst.length; i++){
if (i % 2 === 0){
if (lst[i] % 2 === 1){
result += lst[i]; | }
}
return result;
} | } | const assert = require('node:assert');
function test() {
let candidate = solution;
assert.deepEqual(candidate([5, 8, 7, 1]),12);
assert.deepEqual(candidate([3, 3, 3, 3, 3]),9);
assert.deepEqual(candidate([30, 13, 24, 321]),0);
assert.deepEqual(candidate([5, 9]),5);
assert.deepEqual(candidate([2, 4, 8]),0);
assert.deepEqual(candidate([30, 13, 23, 32]),23);
assert.deepEqual(candidate([3, 13, 2, 9]),3);
}
test(); |
humaneval-HumanEval_126_is_sorted.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 {
// Given an array array list of numbers, return whether or not they are sorted
// in ascending order. If array list has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l))))
// (false)
public static boolean isSorted(ArrayList<Long> lst) {
if (lst.size() == 0) {
return true;
}
else {
int running_max = 0;
int previous_number = 0;
boolean first_time = true;
boolean seen_2_in_a_row = false;
for (Long number : lst) {
if (first_time) {
first_time = false;
previous_number = number.intValue();
running_max = number.intValue();
}
else { | return false;
}
else {
if (previous_number == number.intValue()) {
if (seen_2_in_a_row) {
return false;
}
else {
seen_2_in_a_row = true;
}
}
else {
seen_2_in_a_row = false;
}
previous_number = number.intValue();
running_max = number.intValue();
}
}
}
return true;
}
}
} | if (running_max > number.intValue()) { | }
public static void main(String[] args) {
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)5l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList()))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)1l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)3l, (long)3l, (long)4l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))) == (true));
}
}
|
humaneval-HumanEval_142_sum_squares.json-L25 | js | //"
// This function will take an array of integers. For all entries in the array, the function shall square the integer entry if its index is a
// multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not
// change the entries in the array whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries.
// Examples:
// >>> lst
// [1, 2, 3]
// >>> lst
// []
// >>> lst
// [-1, -5, 2, -1, -5]
function sum_squares(lst){
var sum = 0;
var len = lst.length;
for (var i = 0; i < len; i++){
if (i % 3 == 0){
sum += lst[i]*lst[i];
} else if (i % 4 == 0){
sum += lst[i]*lst[i]*lst[i];
} else {
sum += lst[i];
}
}
return sum; | } | const assert = require('node:assert');
function test() {
let candidate = sum_squares;
assert.deepEqual(candidate([1, 2, 3]),6);
assert.deepEqual(candidate([1, 4, 9]),14);
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([1, 1, 1, 1, 1, 1, 1, 1, 1]),9);
assert.deepEqual(candidate([-1, -1, -1, -1, -1, -1, -1, -1, -1]),-3);
assert.deepEqual(candidate([0]),0);
assert.deepEqual(candidate([-1, -5, 2, -1, -5]),-126);
assert.deepEqual(candidate([-56, -99, 1, 0, -2]),3030);
assert.deepEqual(candidate([-1, 0, 0, 0, 0, 0, 0, 0, -1]),0);
assert.deepEqual(candidate([-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37]),-14196);
assert.deepEqual(candidate([-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10]),-1448);
}
test(); |
|
humaneval-HumanEval_28_concatenate.json-L12 | js | //Concatenate array of strings into a single string
// >>> concatenate([])
// ""
// >>> concatenate(["a", "b", "c"])
// "abc"
function concatenate(strings){
if(strings.length === 0){
return "";
}
var string = strings.join("");
return string; | } | const assert = require('node:assert');
function test() {
let candidate = concatenate;
assert.deepEqual(candidate([]),"");
assert.deepEqual(candidate(["x", "y", "z"]),"xyz");
assert.deepEqual(candidate(["x", "y", "z", "w", "k"]),"xyzwk");
}
test(); |
|
humaneval-HumanEval_1_separate_paren_groups.json-L37 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array list of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// >>> separateParenGroups(("( ) (( )) (( )( ))"))
// (new ArrayList<String>(Arrays.asList((String)"()", (String)"(())", (String)"(()())")))
public static ArrayList<String> separateParenGroups(String paren_string) {
ArrayList<String> output = new ArrayList<String>();
StringBuffer temp = new StringBuffer();
int open_paren = 0;
for (int i = 0; i < paren_string.length(); i++) {
char c = paren_string.charAt(i);
if (c == '(') {
if (open_paren == 0) {
temp = new StringBuffer();
}
open_paren++;
temp.append(c);
} else if (c == ')') {
open_paren--;
temp.append(c);
if (open_paren == 0) {
output.add(temp.toString());
}
}
}
return output;
} | } | }
public static void main(String[] args) {
assert(separateParenGroups(("(()()) ((())) () ((())()())")).equals((new ArrayList<String>(Arrays.asList((String)"(()())", (String)"((()))", (String)"()", (String)"((())()())")))));
assert(separateParenGroups(("() (()) ((())) (((())))")).equals((new ArrayList<String>(Arrays.asList((String)"()", (String)"(())", (String)"((()))", (String)"(((())))")))));
assert(separateParenGroups(("(()(())((())))")).equals((new ArrayList<String>(Arrays.asList((String)"(()(())((())))")))));
assert(separateParenGroups(("( ) (( )) (( )( ))")).equals((new ArrayList<String>(Arrays.asList((String)"()", (String)"(())", (String)"(()())")))));
}
}
|
|
humaneval-HumanEval_101_words_string.json-L11 | js | //You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// >>> words_string("Hi, my name is John")
// ["Hi", "my", "name", "is", "John"]
// >>> words_string("One, two, three, four, five, six")
// ["One", "two", "three", "four", "five", "six"]
function words_string(s){
let res = s.split(/[\s,]+/).filter(Boolean);
return res; | } | const assert = require('node:assert');
function test() {
let candidate = words_string;
assert.deepEqual(candidate("Hi, my name is John"),["Hi", "my", "name", "is", "John"]);
assert.deepEqual(candidate("One, two, three, four, five, six"),["One", "two", "three", "four", "five", "six"]);
assert.deepEqual(candidate("Hi, my name"),["Hi", "my", "name"]);
assert.deepEqual(candidate("One,, two, three, four, five, six,"),["One", "two", "three", "four", "five", "six"]);
assert.deepEqual(candidate(""),[]);
assert.deepEqual(candidate("ahmed , gamal"),["ahmed", "gamal"]);
}
test(); |
|
humaneval-HumanEval_139_special_factorial.json-L13 | js | //The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// >>> special_factorial(4)
// 288
// The function will receive an integer as input and should return the special
// factorial of this integer.
function special_factorial(n){
if (n > 0) {
let fact = 1;
for (let i = 1; i <= n; i++) { | }
return fact * special_factorial(n - 1);
} else {
return 1;
}
}
| fact *= i; | const assert = require('node:assert');
function test() {
let candidate = special_factorial;
assert.deepEqual(candidate(4),288);
assert.deepEqual(candidate(5),34560);
assert.deepEqual(candidate(7),125411328000);
assert.deepEqual(candidate(1),1);
}
test(); |
humaneval-HumanEval_24_largest_divisor.json-L16 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// For a given number n, find the largest number that divides n evenly, smaller than n
// >>> largestDivisor((15l))
// (5l)
public static long largestDivisor(long n) {
for (long i = 2; i <= Math.floor(Math.sqrt(n)); i++) {
if (n % i == 0) {
return n / i; | }
return 1;
}
} | } | }
public static void main(String[] args) {
assert(largestDivisor((3l)) == (1l));
assert(largestDivisor((7l)) == (1l));
assert(largestDivisor((10l)) == (5l));
assert(largestDivisor((100l)) == (50l));
assert(largestDivisor((49l)) == (7l));
}
}
|
humaneval-HumanEval_82_prime_length.json-L17 | py | def prime_length(string: str) -> bool:
"""Write a function that takes a string and returns True if the string
length is a prime number or False otherwise
Examples
>>> prime_length('Hello')
True
>>> prime_length('abcdcba')
True
>>> prime_length('kittens')
True
>>> prime_length('orange')
False
"""
num = len(string)
if num > 1:
for i in range(2, num): | return False
else:
return True
else:
return False
pass
| if (num % i) == 0: | def check(candidate):
assert candidate('Hello') == True
assert candidate('abcdcba') == True
assert candidate('kittens') == True
assert candidate('orange') == False
assert candidate('wow') == True
assert candidate('world') == True
assert candidate('MadaM') == True
assert candidate('Wow') == True
assert candidate('') == False
assert candidate('HI') == True
assert candidate('go') == True
assert candidate('gogo') == False
assert candidate('aaaaaaaaaaaaaaa') == False
assert candidate('Madam') == True
assert candidate('M') == False
assert candidate('0') == False
def test_check():
check(prime_length)
test_check()
|
humaneval-HumanEval_111_histogram.json-L43 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a string representing a space separated lowercase letters, return a hash map
// 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"))
// (new HashMap<String,Long>(Map.of("a", 1l, "b", 1l, "c", 1l)))
// >>> histogram(("a b b a"))
// (new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))
// >>> histogram(("a b c a b"))
// (new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))
// >>> histogram(("b b b b a"))
// (new HashMap<String,Long>(Map.of("b", 4l)))
// >>> histogram((""))
// (new HashMap<String,Long>())
public static HashMap<String,Long> histogram(String test) {
HashMap<String,Long> s = new HashMap<String,Long>();
if (test.length() > 0) {
HashMap<String,Long> hm = new HashMap<String,Long>();
String[] ss = test.split(" ");
for (String sss : ss) {
if (hm.containsKey(sss)) {
hm.put(sss, hm.get(sss) + 1);
} else {
hm.put(sss, 1l);
}
}
long max = 0;
for (String key : hm.keySet()) {
if (hm.get(key) > max) {
max = hm.get(key);
}
}
for (String key : hm.keySet()) {
if (hm.get(key) == max) { | }
}
}
return s;
}
} | s.put(key, hm.get(key)); | }
public static void main(String[] args) {
assert(histogram(("a b b a")).equals((new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))));
assert(histogram(("a b c a b")).equals((new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))));
assert(histogram(("a b c d g")).equals((new HashMap<String,Long>(Map.of("a", 1l, "b", 1l, "c", 1l, "d", 1l, "g", 1l)))));
assert(histogram(("r t g")).equals((new HashMap<String,Long>(Map.of("r", 1l, "t", 1l, "g", 1l)))));
assert(histogram(("b b b b a")).equals((new HashMap<String,Long>(Map.of("b", 4l)))));
assert(histogram(("r t g")).equals((new HashMap<String,Long>(Map.of("r", 1l, "t", 1l, "g", 1l)))));
assert(histogram(("")).equals((new HashMap<String,Long>())));
assert(histogram(("a")).equals((new HashMap<String,Long>(Map.of("a", 1l)))));
}
}
|
humaneval-HumanEval_95_check_dict_case.json-L40 | 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()){ | }
}
}
else{
return false;
}
}
return true;
} | return false; | 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_72_will_it_fly.json-L25 | py | from typing import List
def will_it_fly(q: List[int], w: int) -> bool:
"""
Write a function that returns True if the object q will fly, and False otherwise.
The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.
Example:
>>> will_it_fly([1, 2], 5)
False
# 1+2 is less than the maximum possible weight, but it's unbalanced.
>>> will_it_fly([3, 2, 3], 1)
False
# it's balanced, but 3+2+3 is more than the maximum possible weight.
>>> will_it_fly([3, 2, 3], 9)
True
# 3+2+3 is less than the maximum possible weight, and it's balanced.
>>> will_it_fly([3], 5)
True
# 3 is less than the maximum possible weight, and it's balanced.
"""
| return s <= w and q == q[::-1]
| s = sum(q) | def check(candidate):
assert candidate([3, 2, 3], 9) == True
assert candidate([1, 2], 5) == False
assert candidate([3], 5) == True
assert candidate([3, 2, 3], 1) == False
assert candidate([1, 2, 3], 6) == False
assert candidate([5], 5) == True
def test_check():
check(will_it_fly)
test_check()
|
humaneval-HumanEval_63_fibfib.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 {
// 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) {
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]; | }
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_59_largest_prime_factor.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 {
// 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_156_int_to_mini_roman.json-L21 | py | def int_to_mini_roman(number: int) -> str:
"""
Given a positive integer, obtain its roman numeral equivalent as a string,
and return it in lowercase.
Restrictions: 1 <= num <= 1000
Examples:
>>> int_to_mini_roman(19)
'xix'
>>> int_to_mini_roman(152)
'clii'
>>> int_to_mini_roman(426)
'cdxxvi'
"""
roman_numerals = {
1000: 'm',
900: 'cm',
500: 'd',
400: 'cd',
100: 'c', | 50: 'l',
40: 'xl',
10: 'x',
9: 'ix',
5: 'v',
4: 'iv',
1: 'i'
}
roman_numeral = ''
for key in sorted(roman_numerals.keys(), reverse=True):
roman_numeral += roman_numerals[key] * (number // key)
number = number % key
return roman_numeral
| 90: 'xc', | def check(candidate):
assert candidate(19) == 'xix'
assert candidate(152) == 'clii'
assert candidate(251) == 'ccli'
assert candidate(426) == 'cdxxvi'
assert candidate(500) == 'd'
assert candidate(1) == 'i'
assert candidate(4) == 'iv'
assert candidate(43) == 'xliii'
assert candidate(90) == 'xc'
assert candidate(94) == 'xciv'
assert candidate(532) == 'dxxxii'
assert candidate(900) == 'cm'
assert candidate(994) == 'cmxciv'
assert candidate(1000) == 'm'
def test_check():
check(int_to_mini_roman)
test_check()
|
humaneval-HumanEval_160_do_algebra.json-L49 | 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++; | }
}
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;
}
| do_again = false; | 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_146_specialFilter.json-L18 | 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: | if num % 2 != 0 and rev % 2 != 0:
count += 1
return count
| rev = int(str(num)[::-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_143_words_in_sentence.json-L21 | 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
"""
| if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False
return True
words = sentence.split()
prime_words = []
for word in words:
if is_prime(len(word)):
prime_words.append(word)
return ' '.join(prime_words) | def is_prime(n: int) -> bool: | 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_24_largest_divisor.json-L13 | js | //For a given number n, find the largest number that divides n evenly, smaller than n
// >>> largest_divisor(15)
// 5
function largest_divisor(n){
let ld = 0;
for(i=1; i<n; i++){
if(n%i===0){
if(i>ld){
ld = i;
}
}
} | } | return ld; | const assert = require('node:assert');
function test() {
let candidate = largest_divisor;
assert.deepEqual(candidate(3),1);
assert.deepEqual(candidate(7),1);
assert.deepEqual(candidate(10),5);
assert.deepEqual(candidate(100),50);
assert.deepEqual(candidate(49),7);
}
test(); |
humaneval-HumanEval_157_right_angle_triangle.json-L12 | js | //Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// >>> right_angle_triangle(3, 4, 5)
// true
// >>> right_angle_triangle(1, 2, 3)
// false
function right_angle_triangle(a, b, c){
if(a**2 + b**2 == c**2 || b**2 + c**2 == a**2 || a**2 + c**2 == b**2) { | } else {
return false;
}
}
| return true; | const assert = require('node:assert');
function test() {
let candidate = right_angle_triangle;
assert.deepEqual(candidate(3, 4, 5),true);
assert.deepEqual(candidate(1, 2, 3),false);
assert.deepEqual(candidate(10, 6, 8),true);
assert.deepEqual(candidate(2, 2, 2),false);
assert.deepEqual(candidate(7, 24, 25),true);
assert.deepEqual(candidate(10, 5, 7),false);
assert.deepEqual(candidate(5, 12, 13),true);
assert.deepEqual(candidate(15, 8, 17),true);
assert.deepEqual(candidate(48, 55, 73),true);
assert.deepEqual(candidate(1, 1, 1),false);
assert.deepEqual(candidate(2, 2, 10),false);
}
test(); |
humaneval-HumanEval_154_cycpattern_check.json-L32 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// >>> cycpatternCheck(("abcd"), ("abd"))
// (false)
// >>> cycpatternCheck(("hello"), ("ell"))
// (true)
// >>> cycpatternCheck(("whassup"), ("psus"))
// (false)
// >>> cycpatternCheck(("abab"), ("baa"))
// (true)
// >>> cycpatternCheck(("efef"), ("eeff"))
// (false)
// >>> cycpatternCheck(("himenss"), ("simen"))
// (true)
public static boolean cycpatternCheck(String a, String b) {
int len = b.length();
boolean found = false;
for (int i = 0; i < len; i++) {
b = b.substring(1) + b.charAt(0);
found = a.contains(b);
if (found) break;
}
return found;
} | } | }
public static void main(String[] args) {
assert(cycpatternCheck(("xyzw"), ("xyw")) == (false));
assert(cycpatternCheck(("yello"), ("ell")) == (true));
assert(cycpatternCheck(("whattup"), ("ptut")) == (false));
assert(cycpatternCheck(("efef"), ("fee")) == (true));
assert(cycpatternCheck(("abab"), ("aabb")) == (false));
assert(cycpatternCheck(("winemtt"), ("tinem")) == (true));
}
}
|
|
humaneval-HumanEval_144_simplify.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 {
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// >>> simplify(("1/5"), ("5/1"))
// (true)
// >>> simplify(("1/6"), ("2/1"))
// (false)
// >>> simplify(("7/10"), ("10/2"))
// (false)
public static boolean simplify(String x, String n) {
String[] nums = x.split("/"); | int x_num = Integer.parseInt(nums[0]);
int n_num = Integer.parseInt(n_nums[0]);
int x_denom = Integer.parseInt(nums[1]);
int n_denom = Integer.parseInt(n_nums[1]);
int res_num = x_num * n_num;
int res_denom = x_denom * n_denom;
return (res_num % res_denom == 0);
}
} | String[] n_nums = n.split("/"); | }
public static void main(String[] args) {
assert(simplify(("1/5"), ("5/1")) == (true));
assert(simplify(("1/6"), ("2/1")) == (false));
assert(simplify(("5/1"), ("3/1")) == (true));
assert(simplify(("7/10"), ("10/2")) == (false));
assert(simplify(("2/10"), ("50/10")) == (true));
assert(simplify(("7/2"), ("4/2")) == (true));
assert(simplify(("11/6"), ("6/1")) == (true));
assert(simplify(("2/3"), ("5/2")) == (false));
assert(simplify(("5/2"), ("3/5")) == (false));
assert(simplify(("2/4"), ("8/4")) == (true));
assert(simplify(("2/4"), ("4/2")) == (true));
assert(simplify(("1/5"), ("5/1")) == (true));
assert(simplify(("1/5"), ("1/5")) == (false));
}
}
|
humaneval-HumanEval_67_fruit_distribution.json-L21 | js | //In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// >>> fruit_distribution("5 apples and 6 oranges", 19)
// 8
// >>> fruit_distribution("0 apples and 1 oranges", 3)
// 2
// >>> fruit_distribution("2 apples and 3 oranges", 100)
// 95
// >>> fruit_distribution("100 apples and 1 oranges", 120)
// 19
function fruit_distribution(s, n){
let split_s = s.split(" ");
let num_of_apples = parseInt(split_s[0]);
let num_of_oranges = parseInt(split_s[3]);
let sum = num_of_apples + num_of_oranges;
return n - sum; | } | const assert = require('node:assert');
function test() {
let candidate = fruit_distribution;
assert.deepEqual(candidate("5 apples and 6 oranges", 19),8);
assert.deepEqual(candidate("5 apples and 6 oranges", 21),10);
assert.deepEqual(candidate("0 apples and 1 oranges", 3),2);
assert.deepEqual(candidate("1 apples and 0 oranges", 3),2);
assert.deepEqual(candidate("2 apples and 3 oranges", 100),95);
assert.deepEqual(candidate("2 apples and 3 oranges", 5),0);
assert.deepEqual(candidate("1 apples and 100 oranges", 120),19);
}
test(); |
|
humaneval-HumanEval_143_words_in_sentence.json-L24 | 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++){
if(number % i === 0){ | break;
}
}
return isPrime;
}).join(' ');
} | isPrime = false; | 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_146_specialFilter.json-L37 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that takes an array array list of numbers as input and returns
// the number of elements in the array array list that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// >>> specialFilter((new ArrayList<Long>(Arrays.asList((long)15l, (long)-73l, (long)14l, (long)-15l))))
// (1l)
// >>> specialFilter((new ArrayList<Long>(Arrays.asList((long)33l, (long)-2l, (long)-3l, (long)45l, (long)21l, (long)109l))))
// (2l)
public static long specialFilter(ArrayList<Long> nums) {
class helper {
public long getFirstDigit(long n) {
long[] digits = getDigits(n);
return digits[0];
}
public long getLastDigit(long n) {
long[] digits = getDigits(n);
return digits[digits.length - 1];
}
public long[] getDigits(long n) {
ArrayList<Long> digits = new ArrayList<Long>();
while (n != 0) {
digits.add(n % 10);
n /= 10;
}
Collections.reverse(digits);
return digits.stream().mapToLong(i -> i).toArray();
}
} | return nums.stream().filter(x -> x > 10).filter(x -> {
long firstDigit = h.getFirstDigit(x);
long lastDigit = h.getLastDigit(x);
return firstDigit % 2 != 0 && lastDigit % 2 != 0;
}).count();
}
} | helper h = new helper(); | }
public static void main(String[] args) {
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)5l, (long)-2l, (long)1l, (long)-5l)))) == (0l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)15l, (long)-73l, (long)14l, (long)-15l)))) == (1l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)33l, (long)-2l, (long)-3l, (long)45l, (long)21l, (long)109l)))) == (2l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)43l, (long)-12l, (long)93l, (long)125l, (long)121l, (long)109l)))) == (4l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)71l, (long)-2l, (long)-33l, (long)75l, (long)21l, (long)19l)))) == (3l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)1l)))) == (0l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList()))) == (0l));
}
}
|
humaneval-HumanEval_116_sort_array.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 {
// In this Kata, you have to sort an array array list of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)2l, (long)3l, (long)4l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)-2l, (long)-3l, (long)-4l, (long)-5l, (long)-6l))))
// (new ArrayList<Long>(Arrays.asList((long)-6l, (long)-5l, (long)-4l, (long)-3l, (long)-2l)))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)2l, (long)3l, (long)4l))))
// (new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)2l, (long)3l, (long)4l)))
public static ArrayList<Long> sortArray(ArrayList<Long> arr) {
| long a1 = a, b1 = b;
if (a1 < 0) {
a1 = -a1;
}
if (b1 < 0) {
b1 = -b1;
}
return Long.bitCount(a1) == Long.bitCount(b1) ? Long.compare(a, b) : Integer.compare(Long.bitCount(a1), Long.bitCount(b1));
});
return arr;
}
} | Collections.sort(arr, (a, b) -> { | }
public static void main(String[] args) {
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)3l, (long)5l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)-2l, (long)-3l, (long)-4l, (long)-5l, (long)-6l)))).equals((new ArrayList<Long>(Arrays.asList((long)-4l, (long)-2l, (long)-6l, (long)-5l, (long)-3l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)2l, (long)4l, (long)3l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)5l, (long)77l, (long)4l, (long)5l, (long)3l, (long)5l, (long)7l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)2l, (long)4l, (long)4l, (long)3l, (long)3l, (long)5l, (long)5l, (long)5l, (long)7l, (long)77l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)3l, (long)6l, (long)44l, (long)12l, (long)32l, (long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)32l, (long)3l, (long)5l, (long)6l, (long)12l, (long)44l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)8l, (long)16l, (long)32l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)8l, (long)16l, (long)32l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)8l, (long)16l, (long)32l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)8l, (long)16l, (long)32l)))));
}
}
|
humaneval-HumanEval_94_skjkasdkd.json-L55 | 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) {
counter = 1;
}
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; | output += largestPrime % 10;
largestPrime /= 10;
}
return output;
}
}
} | while (largestPrime > 0) { | }
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_94_skjkasdkd.json-L25 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given an array array list of 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) {
| for (Long item : lst) {
long number = item;
int counter = 0;
if (item == 1) {
continue;
}
if (item == 2) {
counter = 1;
}
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;
}
}
} | long largestPrime = 0l; | }
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_108_count_nums.json-L30 | js | //Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// >>> count_nums([])
// 0
// >>> count_nums([-1, 11, -11])
// 1
// >>> count_nums([1, 1, 2])
// 3
function count_nums(arr){
if(!arr.length) {
return 0;
}
var count = 0;
for(var i = 0; i < arr.length; i++) {
var sum = 0;
var str = arr[i].toString();
if(str[0] === '-') {
sum += Number(str[0] + str[1]);
for(var j = 2; j < str.length; j++) {
sum += Number(str[j]);
}
} else {
for(var k = 0; k < str.length; k++) {
sum += Number(str[k]);
}
}
if(sum > 0) { | }
}
return count;
} | count++; | const assert = require('node:assert');
function test() {
let candidate = count_nums;
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([-1, -2, 0]),0);
assert.deepEqual(candidate([1, 1, 2, -2, 3, 4, 5]),6);
assert.deepEqual(candidate([1, 6, 9, -6, 0, 1, 5]),5);
assert.deepEqual(candidate([1, 100, 98, -7, 1, -1]),4);
assert.deepEqual(candidate([12, 23, 34, -45, -56, 0]),5);
assert.deepEqual(candidate([0, 1]),1);
assert.deepEqual(candidate([1]),1);
}
test(); |
humaneval-HumanEval_3_below_zero.json-L10 | js | //You're given an array 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
function below_zero(operations){
var sum = 0; | sum += operations[i];
if (sum < 0) {
return true;
}
}
return false;
}
| for (var i = 0; i < operations.length; i++) { | const assert = require('node:assert');
function test() {
let candidate = below_zero;
assert.deepEqual(candidate([]),false);
assert.deepEqual(candidate([1, 2, -3, 1, 2, -3]),false);
assert.deepEqual(candidate([1, 2, -4, 5, 6]),true);
assert.deepEqual(candidate([1, -1, 2, -2, 5, -5, 4, -4]),false);
assert.deepEqual(candidate([1, -1, 2, -2, 5, -5, 4, -5]),true);
assert.deepEqual(candidate([1, -2, 2, -2, 5, -5, 4, -4]),true);
}
test(); |
humaneval-HumanEval_42_incr_list.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 {
// Return array list with elements incremented by 1.
// >>> incrList((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l)))
// >>> incrList((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)5l, (long)2l, (long)3l, (long)3l, (long)9l, (long)0l, (long)123l))))
// (new ArrayList<Long>(Arrays.asList((long)6l, (long)4l, (long)6l, (long)3l, (long)4l, (long)4l, (long)10l, (long)1l, (long)124l)))
public static ArrayList<Long> incrList(ArrayList<Long> l) {
for (int i = 0; i < l.size(); i++) {
l.set(i, l.get(i) + 1l);
}
return l;
} | } | }
public static void main(String[] args) {
assert(incrList((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(incrList((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)4l, (long)3l, (long)2l)))));
assert(incrList((new ArrayList<Long>(Arrays.asList((long)5l, (long)2l, (long)5l, (long)2l, (long)3l, (long)3l, (long)9l, (long)0l, (long)123l)))).equals((new ArrayList<Long>(Arrays.asList((long)6l, (long)3l, (long)6l, (long)3l, (long)4l, (long)4l, (long)10l, (long)1l, (long)124l)))));
}
}
|
|
humaneval-HumanEval_106_f.json-L20 | 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
a=[]
for i in range(n):
i=i+1
if i%2==0:
a.append(math.factorial(i))
else: | return a
pass | a.append(sum(range(1,i+1))) | 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_143_words_in_sentence.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 {
// 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:
// >>> wordsInSentence(("This is a test"))
// ("is")
// Example 2:
// >>> wordsInSentence(("lets go for swimming"))
// ("go for")
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
public static String wordsInSentence(String sentence) {
StringBuilder ans = new StringBuilder();
String[] words = sentence.split(" ");
int[] 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};
boolean isPrime; | isPrime = false;
for (int prime : primes) {
if (word.length() == prime) {
isPrime = true;
break;
}
}
if (isPrime) {
ans.append(word + " ");
}
}
if (ans.length() > 0) {
ans.deleteCharAt(ans.length() - 1);
}
return ans.toString();
}
} | for (String word : words) { | }
public static void main(String[] args) {
assert(wordsInSentence(("This is a test")).equals(("is")));
assert(wordsInSentence(("lets go for swimming")).equals(("go for")));
assert(wordsInSentence(("there is no place available here")).equals(("there is no place")));
assert(wordsInSentence(("Hi I am Hussein")).equals(("Hi am Hussein")));
assert(wordsInSentence(("go for it")).equals(("go for it")));
assert(wordsInSentence(("here")).equals(("")));
assert(wordsInSentence(("here is")).equals(("is")));
}
}
|
humaneval-HumanEval_155_even_odd_count.json-L17 | js | //Given an integer. return an array that has the number of even and odd digits respectively.
// Example:
// >>> even_odd_count(-12)
// [1, 1]
// >>> even_odd_count(123)
// [1, 2]
function even_odd_count(num){
num = Math.abs(num);
var evens = 0;
var odds = 0;
for(var i = 0; i < num.toString().length; i++){
if(num.toString()[i] % 2 == 0){
evens ++;
}
else{
odds ++; | }
return [evens, odds];
}
| } | const assert = require('node:assert');
function test() {
let candidate = even_odd_count;
assert.deepEqual(candidate(7),[0, 1]);
assert.deepEqual(candidate(-78),[1, 1]);
assert.deepEqual(candidate(3452),[2, 2]);
assert.deepEqual(candidate(346211),[3, 3]);
assert.deepEqual(candidate(-345821),[3, 3]);
assert.deepEqual(candidate(-2),[1, 0]);
assert.deepEqual(candidate(-45347),[2, 3]);
assert.deepEqual(candidate(0),[1, 0]);
}
test(); |
humaneval-HumanEval_87_get_row.json-L17 | 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){
| 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];
});
}
| let coordinates = []; | 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_121_solution.json-L15 | py | from typing import List
def solution(lst: List[int]) -> int:
"""Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions.
Examples
>>> solution([5, 8, 7, 1])
12
>>> solution([3, 3, 3, 3, 3])
9
>>> solution([30, 13, 24, 321])
0
"""
| return sum([elem for i, elem in enumerate(lst) if elem % 2 != 0 and i % 2 == 0]) | def check(candidate):
assert candidate([5, 8, 7, 1]) == 12
assert candidate([3, 3, 3, 3, 3]) == 9
assert candidate([30, 13, 24, 321]) == 0
assert candidate([5, 9]) == 5
assert candidate([2, 4, 8]) == 0
assert candidate([30, 13, 23, 32]) == 23
assert candidate([3, 13, 2, 9]) == 3
def test_check():
check(solution)
test_check()
|
|
humaneval-HumanEval_59_largest_prime_factor.json-L15 | py | def largest_prime_factor(n: int) -> int:
"""Return the largest prime factor of n. Assume n > 1 and is not a prime.
>>> largest_prime_factor(13195)
29
>>> largest_prime_factor(2048)
2
"""
largest = 1
factor = 2
while factor < n:
if n % factor == 0:
largest = factor
while n % factor == 0:
n = n // factor | return max(largest, n)
| factor += 1 | def check(candidate):
assert candidate(15) == 5
assert candidate(27) == 3
assert candidate(63) == 7
assert candidate(330) == 11
assert candidate(13195) == 29
def test_check():
check(largest_prime_factor)
test_check()
|
humaneval-HumanEval_56_correct_bracketing.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 {
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correctBracketing(("<"))
// (false)
// >>> correctBracketing(("<>"))
// (true)
// >>> correctBracketing(("<<><>>"))
// (true)
// >>> correctBracketing(("><<>"))
// (false)
public static boolean correctBracketing(String brackets) {
int open = 0;
for (int i = 0; i < brackets.length(); i++) {
char c = brackets.charAt(i);
if (c == '<') {
open++;
} else {
open--;
}
if (open < 0) {
return false;
}
}
return open == 0;
} | } | }
public static void main(String[] args) {
assert(correctBracketing(("<>")) == (true));
assert(correctBracketing(("<<><>>")) == (true));
assert(correctBracketing(("<><><<><>><>")) == (true));
assert(correctBracketing(("<><><<<><><>><>><<><><<>>>")) == (true));
assert(correctBracketing(("<<<><>>>>")) == (false));
assert(correctBracketing(("><<>")) == (false));
assert(correctBracketing(("<")) == (false));
assert(correctBracketing(("<<<<")) == (false));
assert(correctBracketing((">")) == (false));
assert(correctBracketing(("<<>")) == (false));
assert(correctBracketing(("<><><<><>><>><<>")) == (false));
assert(correctBracketing(("<><><<><>><>>><>")) == (false));
}
}
|
|
humaneval-HumanEval_127_intersection.json-L21 | js | //You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// >>> intersection([1, 2], [2, 3])
// "NO"
// >>> intersection([-1, 1], [0, 4])
// "NO"
// >>> intersection([-3, -1], [-5, 5])
// "YES"
function intersection(interval1, interval2){
| let end = Math.min(interval1[1], interval2[1]);
if (start >= end) {
return "NO";
}
let length = end - start;
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
return primes.includes(length) ? "YES" : "NO";
}
| let start = Math.max(interval1[0], interval2[0]); | const assert = require('node:assert');
function test() {
let candidate = intersection;
assert.deepEqual(candidate([1, 2], [2, 3]),"NO");
assert.deepEqual(candidate([-1, 1], [0, 4]),"NO");
assert.deepEqual(candidate([-3, -1], [-5, 5]),"YES");
assert.deepEqual(candidate([-2, 2], [-4, 0]),"YES");
assert.deepEqual(candidate([-11, 2], [-1, -1]),"NO");
assert.deepEqual(candidate([1, 2], [3, 5]),"NO");
assert.deepEqual(candidate([1, 2], [1, 2]),"NO");
assert.deepEqual(candidate([-2, -2], [-3, -2]),"NO");
}
test(); |
humaneval-HumanEval_71_triangle_area.json-L18 | js | //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:
// >>> triangle_area(3, 4, 5)
// 6.0
// >>> triangle_area(1, 2, 10)
// -1
function triangle_area(a, b, c){
if(a+b>c && a+c>b && b+c>a){
var s = (a+b+c)/2;
return Math.sqrt(s*(s-a)*(s-b)*(s-c)).toFixed(2);
}else{
return -1;
} | } | const assert = require('node:assert');
function test() {
let candidate = triangle_area;
assert.deepEqual(candidate(3, 4, 5),6.0);
assert.deepEqual(candidate(1, 2, 10),-1);
assert.deepEqual(candidate(4, 8, 5),8.18);
assert.deepEqual(candidate(2, 2, 2),1.73);
assert.deepEqual(candidate(1, 2, 3),-1);
assert.deepEqual(candidate(10, 5, 7),16.25);
assert.deepEqual(candidate(2, 6, 3),-1);
assert.deepEqual(candidate(1, 1, 1),0.43);
assert.deepEqual(candidate(2, 2, 10),-1);
}
test(); |
|
humaneval-HumanEval_123_get_odd_collatz.json-L31 | py | from typing import List
def get_odd_collatz(n: int) -> List[int]:
"""
Given a positive integer n, return a sorted 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 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.
>>> get_odd_collatz(5)
[1, 5]
"""
collatz_list = []
current_num = n
while (current_num > 1):
collatz_list.append(current_num)
if (current_num % 2 == 0):
current_num = current_num // 2
else:
current_num = current_num * 3 + 1
collatz_list.append(1) | return sorted(list(set([x for x in collatz_list if x % 2 != 0]))) | def check(candidate):
assert candidate(14) == [1, 5, 7, 11, 13, 17]
assert candidate(5) == [1, 5]
assert candidate(12) == [1, 3, 5]
assert candidate(1) == [1]
def test_check():
check(get_odd_collatz)
test_check()
|
|
humaneval-HumanEval_2_truncate_number.json-L16 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// >>> truncateNumber((3.5f))
// (0.5f)
public static float truncateNumber(float number) {
| }
} | return (number - (int)number); | }
public static void main(String[] args) {
assert(truncateNumber((3.5f)) == (0.5f));
assert(truncateNumber((1.25f)) == (0.25f));
assert(truncateNumber((123.0f)) == (0.0f));
}
}
|
humaneval-HumanEval_139_special_factorial.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 {
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// >>> specialFactorial((4l))
// (288l)
// The function will receive an integer as input and should return the special
// factorial of this integer.
public static long specialFactorial(long n) {
long result = 1;
while (n > 0) {
long local_result = 1;
long temp = n;
while (temp > 0) {
local_result *= temp;
temp--;
}
result *= local_result;
n--;
}
return result; | } | } | }
public static void main(String[] args) {
assert(specialFactorial((4l)) == (288l));
assert(specialFactorial((5l)) == (34560l));
assert(specialFactorial((7l)) == (125411328000l));
assert(specialFactorial((1l)) == (1l));
}
}
|
humaneval-HumanEval_142_sum_squares.json-L16 | js | //"
// This function will take an array of integers. For all entries in the array, the function shall square the integer entry if its index is a
// multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not
// change the entries in the array whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries.
// Examples:
// >>> lst
// [1, 2, 3]
// >>> lst
// []
// >>> lst
// [-1, -5, 2, -1, -5]
function sum_squares(lst){
var sum = 0;
var len = lst.length;
for (var i = 0; i < len; i++){ | sum += lst[i]*lst[i];
} else if (i % 4 == 0){
sum += lst[i]*lst[i]*lst[i];
} else {
sum += lst[i];
}
}
return sum;
} | if (i % 3 == 0){ | const assert = require('node:assert');
function test() {
let candidate = sum_squares;
assert.deepEqual(candidate([1, 2, 3]),6);
assert.deepEqual(candidate([1, 4, 9]),14);
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([1, 1, 1, 1, 1, 1, 1, 1, 1]),9);
assert.deepEqual(candidate([-1, -1, -1, -1, -1, -1, -1, -1, -1]),-3);
assert.deepEqual(candidate([0]),0);
assert.deepEqual(candidate([-1, -5, 2, -1, -5]),-126);
assert.deepEqual(candidate([-56, -99, 1, 0, -2]),3030);
assert.deepEqual(candidate([-1, 0, 0, 0, 0, 0, 0, 0, -1]),0);
assert.deepEqual(candidate([-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37]),-14196);
assert.deepEqual(candidate([-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10]),-1448);
}
test(); |
humaneval-HumanEval_118_get_closest_vowel.json-L43 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// >>> getClosestVowel(("yogurt"))
// ("u")
// >>> getClosestVowel(("FULL"))
// ("U")
// >>> getClosestVowel(("quick"))
// ("")
// >>> getClosestVowel(("ab"))
// ("")
public static String getClosestVowel(String word) {
final String vowels = "aeiou";
final String consonants = "bcdfghjklmnpqrstvwxyz";
List<Integer> idx = new ArrayList<>();
word = word.toLowerCase();
for (int i = 0; i < word.length(); i++) {
if (vowels.indexOf(word.charAt(i)) != -1) {
idx.add(i);
}
}
for (int i = idx.size() - 1; i >= 0; i--) {
int j = idx.get(i);
if (j == 0 || j == word.length() - 1) continue;
char left = word.charAt(j - 1);
char right = word.charAt(j + 1);
if (consonants.indexOf(left) != -1 && consonants.indexOf(right) != -1) {
return String.valueOf(word.charAt(j));
}
}
return ""; | } | } | }
public static void main(String[] args) {
assert(getClosestVowel(("yogurt")).equals(("u")));
assert(getClosestVowel(("full")).equals(("u")));
assert(getClosestVowel(("easy")).equals(("")));
assert(getClosestVowel(("eAsy")).equals(("")));
assert(getClosestVowel(("ali")).equals(("")));
assert(getClosestVowel(("bad")).equals(("a")));
assert(getClosestVowel(("most")).equals(("o")));
assert(getClosestVowel(("ab")).equals(("")));
assert(getClosestVowel(("ba")).equals(("")));
assert(getClosestVowel(("quick")).equals(("")));
assert(getClosestVowel(("anime")).equals(("i")));
assert(getClosestVowel(("Asia")).equals(("")));
assert(getClosestVowel(("Above")).equals(("o")));
}
}
|
humaneval-HumanEval_108_count_nums.json-L24 | js | //Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// >>> count_nums([])
// 0
// >>> count_nums([-1, 11, -11])
// 1
// >>> count_nums([1, 1, 2])
// 3
function count_nums(arr){
if(!arr.length) {
return 0;
}
var count = 0;
for(var i = 0; i < arr.length; i++) {
var sum = 0;
var str = arr[i].toString();
if(str[0] === '-') {
sum += Number(str[0] + str[1]);
for(var j = 2; j < str.length; j++) {
sum += Number(str[j]);
} | for(var k = 0; k < str.length; k++) {
sum += Number(str[k]);
}
}
if(sum > 0) {
count++;
}
}
return count;
} | } else { | const assert = require('node:assert');
function test() {
let candidate = count_nums;
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([-1, -2, 0]),0);
assert.deepEqual(candidate([1, 1, 2, -2, 3, 4, 5]),6);
assert.deepEqual(candidate([1, 6, 9, -6, 0, 1, 5]),5);
assert.deepEqual(candidate([1, 100, 98, -7, 1, -1]),4);
assert.deepEqual(candidate([12, 23, 34, -45, -56, 0]),5);
assert.deepEqual(candidate([0, 1]),1);
assert.deepEqual(candidate([1]),1);
}
test(); |
humaneval-HumanEval_57_monotonic.json-L25 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return true is array list elements are monotonically increasing or decreasing.
// >>> monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)20l))))
// (true)
// >>> monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)20l, (long)4l, (long)10l))))
// (false)
// >>> monotonic((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)0l, (long)-10l))))
// (true)
public static boolean monotonic(ArrayList<Long> l) {
long a = l.get(0);
boolean inc = true;
boolean dec = true;
for (int i = 1; i < l.size(); i++) {
if (l.get(i) < a) {
inc = false;
}
if (l.get(i) > a) { | }
a = l.get(i);
}
return inc || dec;
}
} | dec = false; | }
public static void main(String[] args) {
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)10l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)20l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)20l, (long)4l, (long)10l)))) == (false));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)0l, (long)-10l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)1l, (long)0l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)2l, (long)5l, (long)60l)))) == (false));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)60l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)9l, (long)9l, (long)9l, (long)9l)))) == (true));
}
}
|
humaneval-HumanEval_91_is_bored.json-L14 | py | def is_bored(S: str) -> int:
"""
You'll be given a string of words, and your task is to count the number
of boredoms. A boredom is a sentence that starts with the word "I".
Sentences are delimited by '.', '?' or '!'.
For example:
>>> is_bored('Hello world')
0
>>> is_bored('The sky is blue. The sun is shining. I love this weather')
1
"""
boredoms = 0 | for sentence in sentences:
words = sentence.split()
if words and words[0] == 'I':
boredoms += 1
return boredoms
| sentences = S.split('.') | def check(candidate):
assert candidate('Hello world') == 0
assert candidate('Is the sky blue?') == 0
assert candidate('I love It !') == 1
assert candidate('bIt') == 0
assert candidate('I feel good today. I will be productive. will kill It') == 2
assert candidate('You and I are going for a walk') == 0
def test_check():
check(is_bored)
test_check()
|
humaneval-HumanEval_156_int_to_mini_roman.json-L22 | py | def int_to_mini_roman(number: int) -> str:
"""
Given a positive integer, obtain its roman numeral equivalent as a string,
and return it in lowercase.
Restrictions: 1 <= num <= 1000
Examples:
>>> int_to_mini_roman(19)
'xix'
>>> int_to_mini_roman(152)
'clii'
>>> int_to_mini_roman(426)
'cdxxvi'
"""
roman_numerals = {
1000: 'm',
900: 'cm',
500: 'd',
400: 'cd',
100: 'c',
90: 'xc', | 40: 'xl',
10: 'x',
9: 'ix',
5: 'v',
4: 'iv',
1: 'i'
}
roman_numeral = ''
for key in sorted(roman_numerals.keys(), reverse=True):
roman_numeral += roman_numerals[key] * (number // key)
number = number % key
return roman_numeral
| 50: 'l', | def check(candidate):
assert candidate(19) == 'xix'
assert candidate(152) == 'clii'
assert candidate(251) == 'ccli'
assert candidate(426) == 'cdxxvi'
assert candidate(500) == 'd'
assert candidate(1) == 'i'
assert candidate(4) == 'iv'
assert candidate(43) == 'xliii'
assert candidate(90) == 'xc'
assert candidate(94) == 'xciv'
assert candidate(532) == 'dxxxii'
assert candidate(900) == 'cm'
assert candidate(994) == 'cmxciv'
assert candidate(1000) == 'm'
def test_check():
check(int_to_mini_roman)
test_check()
|
humaneval-HumanEval_18_how_many_times.json-L14 | js | //Find how many times a given substring can be found in the original string. Count overlaping cases.
// >>> how_many_times("", "a")
// 0
// >>> how_many_times("aaa", "a")
// 3
// >>> how_many_times("aaaa", "aa")
// 3
function how_many_times(string, substring){
var i = 0;
var count = 0;
while(string.indexOf(substring, i) !== -1){
count++;
i = string.indexOf(substring, i) + 1; | return count;
} | } | const assert = require('node:assert');
function test() {
let candidate = how_many_times;
assert.deepEqual(candidate("", "x"),0);
assert.deepEqual(candidate("xyxyxyx", "x"),4);
assert.deepEqual(candidate("cacacacac", "cac"),4);
assert.deepEqual(candidate("john doe", "john"),1);
}
test(); |
humaneval-HumanEval_70_strange_sort_list.json-L19 | 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 = [] | out.append(lst.pop(0))
if not lst:
break
out.append(lst.pop())
return out | while lst: | def check(candidate):
assert candidate([1, 2, 3, 4]) == [1, 4, 2, 3]
assert candidate([5, 6, 7, 8, 9]) == [5, 9, 6, 8, 7]
assert candidate([1, 2, 3, 4, 5]) == [1, 5, 2, 4, 3]
assert candidate([5, 6, 7, 8, 9, 1]) == [1, 9, 5, 8, 6, 7]
assert candidate([5, 5, 5, 5]) == [5, 5, 5, 5]
assert 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_43_pairs_sum_to_zero.json-L20 | js | //pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// >>> pairs_sum_to_zero([1, 3, 5, 0])
// false
// >>> pairs_sum_to_zero([1, 3, -2, 1])
// false
// >>> pairs_sum_to_zero([1, 2, 3, 7])
// false
// >>> pairs_sum_to_zero([2, 4, -5, 3, 5, 7])
// true
// >>> pairs_sum_to_zero([1])
// false
function pairs_sum_to_zero(l){
var i = 0
while (i < l.length){
var j = i+1
while (j < l.length){
if ((l[i] + l[j]) === 0){ | }
j = j + 1
}
i = i + 1
}
return false
}
| return true | const assert = require('node:assert');
function test() {
let candidate = pairs_sum_to_zero;
assert.deepEqual(candidate([1, 3, 5, 0]),false);
assert.deepEqual(candidate([1, 3, -2, 1]),false);
assert.deepEqual(candidate([1, 2, 3, 7]),false);
assert.deepEqual(candidate([2, 4, -5, 3, 5, 7]),true);
assert.deepEqual(candidate([1]),false);
assert.deepEqual(candidate([-3, 9, -1, 3, 2, 30]),true);
assert.deepEqual(candidate([-3, 9, -1, 3, 2, 31]),true);
assert.deepEqual(candidate([-3, 9, -1, 4, 2, 30]),false);
assert.deepEqual(candidate([-3, 9, -1, 4, 2, 31]),false);
}
test(); |
humaneval-HumanEval_95_check_dict_case.json-L39 | 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){ | return false;
}
}
}
else{
return false;
}
}
return true;
} | if (key != key.toLowerCase()){ | 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_40_triples_sum_to_zero.json-L43 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// triples_sum_to_zero takes an array array list of integers as an input.
// it returns true if there are three distinct elements in the array list that
// sum to zero, and false otherwise.
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)0l))))
// (false)
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)-2l, (long)1l))))
// (true)
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)7l))))
// (false)
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)-5l, (long)3l, (long)9l, (long)7l))))
// (true)
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l))))
// (false)
public static boolean triplesSumToZero(ArrayList<Long> l) {
if (l.size() < 3) {
return false;
}
ArrayList<Long> sortedList = new ArrayList<Long>(l);
Collections.sort(sortedList);
for (int i = 0; i < sortedList.size() - 2; i++) {
int j = i + 1;
int k = sortedList.size() - 1;
while (j < k) {
long currSum = sortedList.get(i) + sortedList.get(j) + sortedList.get(k);
if (currSum == 0) {
return true;
} else if (currSum < 0) {
j++;
} else {
k--;
}
}
}
return false; | } | } | }
public static void main(String[] args) {
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)0l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)-1l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)-2l, (long)1l)))) == (true));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)7l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)5l, (long)7l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)-5l, (long)3l, (long)9l, (long)7l)))) == (true));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)-100l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)100l, (long)3l, (long)5l, (long)-100l)))) == (false));
}
}
|
humaneval-HumanEval_25_factorize.json-L21 | py | from typing import List
def factorize(n: int) -> List[int]:
""" Return list of prime factors of given integer in the order from smallest to largest.
Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.
Input number should be equal to the product of all factors
>>> factorize(8)
[2, 2, 2]
>>> factorize(25)
[5, 5]
>>> factorize(70)
[2, 5, 7]
"""
factors = []
i = 2
while i <= n:
while n % i == 0:
factors.append(i)
n = n / i
i += 1 | return factors | def check(candidate):
assert candidate(2) == [2]
assert candidate(4) == [2, 2]
assert candidate(8) == [2, 2, 2]
assert candidate(57) == [3, 19]
assert candidate(3249) == [3, 3, 19, 19]
assert candidate(185193) == [3, 3, 3, 19, 19, 19]
assert candidate(20577) == [3, 19, 19, 19]
assert candidate(18) == [2, 3, 3]
def test_check():
check(factorize)
test_check()
|
|
humaneval-HumanEval_148_bf.json-L26 | 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) | if start < end:
planets = planets[start+1:end]
else:
planets = planets[end+1:start]
return tuple(planets) | end = planets.index(planet2) | 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_47_median.json-L10 | js | //Return median of elements in the array l.
// >>> median([3, 1, 2, 4, 5])
// 3
// >>> median([-10, 4, 6, 1000, 10, 20])
// 15.0
function median(l){
let middle = Math.floor(l.length / 2);
let sorted = l.sort((a, b) => a - b);
if (l.length % 2 === 0) { | } else {
return sorted[middle];
}
}
| return (sorted[middle - 1] + sorted[middle]) / 2; | const assert = require('node:assert');
function test() {
let candidate = median;
assert.deepEqual(candidate([3, 1, 2, 4, 5]),3);
assert.deepEqual(candidate([-10, 4, 6, 1000, 10, 20]),8.0);
assert.deepEqual(candidate([5]),5);
assert.deepEqual(candidate([6, 5]),5.5);
assert.deepEqual(candidate([8, 1, 3, 9, 9, 2, 7]),7);
}
test(); |
humaneval-HumanEval_18_how_many_times.json-L15 | js | //Find how many times a given substring can be found in the original string. Count overlaping cases.
// >>> how_many_times("", "a")
// 0
// >>> how_many_times("aaa", "a")
// 3
// >>> how_many_times("aaaa", "aa")
// 3
function how_many_times(string, substring){
var i = 0;
var count = 0;
while(string.indexOf(substring, i) !== -1){
count++;
i = string.indexOf(substring, i) + 1;
} | } | return count; | const assert = require('node:assert');
function test() {
let candidate = how_many_times;
assert.deepEqual(candidate("", "x"),0);
assert.deepEqual(candidate("xyxyxyx", "x"),4);
assert.deepEqual(candidate("cacacacac", "cac"),4);
assert.deepEqual(candidate("john doe", "john"),1);
}
test(); |
humaneval-HumanEval_24_largest_divisor.json-L14 | js | //For a given number n, find the largest number that divides n evenly, smaller than n
// >>> largest_divisor(15)
// 5
function largest_divisor(n){
let ld = 0;
for(i=1; i<n; i++){
if(n%i===0){
if(i>ld){
ld = i;
}
}
}
return ld; | } | const assert = require('node:assert');
function test() {
let candidate = largest_divisor;
assert.deepEqual(candidate(3),1);
assert.deepEqual(candidate(7),1);
assert.deepEqual(candidate(10),5);
assert.deepEqual(candidate(100),50);
assert.deepEqual(candidate(49),7);
}
test(); |
|
humaneval-HumanEval_160_do_algebra.json-L44 | 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 two array lists operator, and operand. The first array list has basic algebra operations, and
// the second array list is an array array list of integers. Use the two given array lists 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 array list = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array list is equal to the length of operand array list minus one.
// Operand is an array array list of of non-negative integers.
// Operator array list has at least one operator, and operand array list has at least two operands.
public static long doAlgebra(ArrayList<String> op, ArrayList<Long> operand) {
ArrayList<Long> list = new ArrayList<>();
list.add(operand.get(0));
for (int i = 0; i < op.size(); i++) {
if (op.get(i).equals("+"))
list.add(operand.get(i + 1));
else if (op.get(i).equals("-"))
list.add(-operand.get(i + 1));
else if (op.get(i).equals("*"))
list.set(list.size() - 1, list.get(list.size() - 1) * operand.get(i + 1));
else if (op.get(i).equals("//"))
list.set(list.size() - 1, list.get(list.size() - 1) / operand.get(i + 1));
else if (op.get(i).equals("**"))
list.set(list.size() - 1, (long) Math.pow(list.get(list.size() - 1), operand.get(i + 1)));
}
return list.stream().mapToLong(x -> x).sum();
} | } | }
public static void main(String[] args) {
assert(doAlgebra((new ArrayList<String>(Arrays.asList((String)"**", (String)"*", (String)"+"))), (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l, (long)5l)))) == (37l));
assert(doAlgebra((new ArrayList<String>(Arrays.asList((String)"+", (String)"*", (String)"-"))), (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l, (long)5l)))) == (9l));
assert(doAlgebra((new ArrayList<String>(Arrays.asList((String)"//", (String)"*"))), (new ArrayList<Long>(Arrays.asList((long)7l, (long)3l, (long)4l)))) == (8l));
}
}
|
|
humaneval-HumanEval_123_get_odd_collatz.json-L34 | js | //Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous 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 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.
// >>> get_odd_collatz(5)
// [1, 5]
function get_odd_collatz(n){
var collatz_sequence = []
var odd_numbers = []
var odd_count = 0
collatz_sequence.push(n)
for(var i = 0; i < collatz_sequence.length; i++){
if(collatz_sequence[i]%2 == 0){
collatz_sequence.push(collatz_sequence[i]/2)
}
else if(collatz_sequence[i]%2 == 1){
collatz_sequence.push(collatz_sequence[i]*3+1)
}
if(collatz_sequence[i]%2 == 1){
odd_numbers.push(collatz_sequence[i])
odd_count += 1
}
if(collatz_sequence[i] == 1){
break
}
} | odd_numbers.sort(function(a, b){return a-b})
return odd_numbers
}
else{
odd_numbers.push(1)
return odd_numbers
}
}
| if(odd_count != 0){ | const assert = require('node:assert');
function test() {
let candidate = get_odd_collatz;
assert.deepEqual(candidate(14),[1, 5, 7, 11, 13, 17]);
assert.deepEqual(candidate(5),[1, 5]);
assert.deepEqual(candidate(12),[1, 3, 5]);
assert.deepEqual(candidate(1),[1]);
}
test(); |
humaneval-HumanEval_44_change_base.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 {
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// >>> changeBase((8l), (3l))
// ("22")
// >>> changeBase((8l), (2l))
// ("1000")
// >>> changeBase((7l), (2l))
// ("111")
public static String changeBase(long x, long base) {
if (x<0 || base<2 || base>9) { | }
if (x==0) {
return "0";
}
StringBuilder sb = new StringBuilder();
while (x>0) {
sb.append(x%base);
x = x/base;
}
return sb.reverse().toString();
}
} | throw new IllegalArgumentException("bad input"); | }
public static void main(String[] args) {
assert(changeBase((8l), (3l)).equals(("22")));
assert(changeBase((9l), (3l)).equals(("100")));
assert(changeBase((234l), (2l)).equals(("11101010")));
assert(changeBase((16l), (2l)).equals(("10000")));
assert(changeBase((8l), (2l)).equals(("1000")));
assert(changeBase((7l), (2l)).equals(("111")));
assert(changeBase((2l), (3l)).equals(("2")));
assert(changeBase((3l), (4l)).equals(("3")));
assert(changeBase((4l), (5l)).equals(("4")));
assert(changeBase((5l), (6l)).equals(("5")));
assert(changeBase((6l), (7l)).equals(("6")));
assert(changeBase((7l), (8l)).equals(("7")));
}
}
|
humaneval-HumanEval_105_by_length.json-L31 | js | //Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// >>> by_length([2, 1, 1, 4, 5, 8, 2, 3])
// ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// If the array is empty, return an empty array:
// >>> by_length([])
// []
// If the array has any strange number ignore it:
// >>> by_length([1, -1, 55])
// ["One"]
function by_length(arr){
var arr2 = [];
for(var i = 0; i < arr.length; i++){
var num = arr[i];
if(num > 0 && num < 10){
arr2.push(num);
}
}
arr2.sort();
arr2.reverse();
var arr3 = [];
for(var i = 0; i < arr2.length; i++){
var num = arr2[i];
if(num == 1){
arr3.push("One");
}
else if(num == 2){
arr3.push("Two"); | else if(num == 3){
arr3.push("Three");
}
else if(num == 4){
arr3.push("Four");
}
else if(num == 5){
arr3.push("Five");
}
else if(num == 6){
arr3.push("Six");
}
else if(num == 7){
arr3.push("Seven");
}
else if(num == 8){
arr3.push("Eight");
}
else if(num == 9){
arr3.push("Nine");
}
}
return arr3;
} | } | const assert = require('node:assert');
function test() {
let candidate = by_length;
assert.deepEqual(candidate([2, 1, 1, 4, 5, 8, 2, 3]),["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]);
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([1, -1, 55]),["One"]);
assert.deepEqual(candidate([1, -1, 3, 2]),["Three", "Two", "One"]);
assert.deepEqual(candidate([9, 4, 8]),["Nine", "Eight", "Four"]);
}
test(); |
humaneval-HumanEval_159_eat.json-L37 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array array list of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// >>> eat((5l), (6l), (10l))
// (new ArrayList<Long>(Arrays.asList((long)11l, (long)4l)))
// >>> eat((4l), (8l), (9l))
// (new ArrayList<Long>(Arrays.asList((long)12l, (long)1l)))
// >>> eat((1l), (10l), (10l))
// (new ArrayList<Long>(Arrays.asList((long)11l, (long)0l)))
// >>> eat((2l), (11l), (5l))
// (new ArrayList<Long>(Arrays.asList((long)7l, (long)0l)))
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
public static ArrayList<Long> eat(long number, long need, long remaining) {
long total = number + Math.min(need, remaining); | return new ArrayList<Long>(Arrays.asList(total, left));
}
} | long left = Math.max(0, remaining - need); | }
public static void main(String[] args) {
assert(eat((5l), (6l), (10l)).equals((new ArrayList<Long>(Arrays.asList((long)11l, (long)4l)))));
assert(eat((4l), (8l), (9l)).equals((new ArrayList<Long>(Arrays.asList((long)12l, (long)1l)))));
assert(eat((1l), (10l), (10l)).equals((new ArrayList<Long>(Arrays.asList((long)11l, (long)0l)))));
assert(eat((2l), (11l), (5l)).equals((new ArrayList<Long>(Arrays.asList((long)7l, (long)0l)))));
assert(eat((4l), (5l), (7l)).equals((new ArrayList<Long>(Arrays.asList((long)9l, (long)2l)))));
assert(eat((4l), (5l), (1l)).equals((new ArrayList<Long>(Arrays.asList((long)5l, (long)0l)))));
}
}
|
humaneval-HumanEval_51_remove_vowels.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 {
// remove_vowels is a function that takes string and returns string without vowels.
// >>> removeVowels((""))
// ("")
// >>> removeVowels(("abcdef"))
// ("bcdf")
// >>> removeVowels(("aaaaa"))
// ("")
// >>> removeVowels(("aaBAA"))
// ("B")
// >>> removeVowels(("zbcd"))
// ("zbcd")
public static String removeVowels(String text) {
String vowels = "aeiouAEIOU";
String newText = "";
for (int i = 0; i < text.length(); i++) {
if (vowels.indexOf(text.charAt(i)) == -1) { | }
}
return newText;
}
} | newText += text.charAt(i); | }
public static void main(String[] args) {
assert(removeVowels(("")).equals(("")));
assert(removeVowels(("abcdef\nghijklm")).equals(("bcdf\nghjklm")));
assert(removeVowels(("fedcba")).equals(("fdcb")));
assert(removeVowels(("eeeee")).equals(("")));
assert(removeVowels(("acBAA")).equals(("cB")));
assert(removeVowels(("EcBOO")).equals(("cB")));
assert(removeVowels(("ybcd")).equals(("ybcd")));
}
}
|
humaneval-HumanEval_90_next_smallest.json-L24 | py | from typing import List, Optional
def next_smallest(lst: List[int]) -> Optional[int]:
"""
You are given a list of integers.
Write a function next_smallest() that returns the 2nd smallest element of the list.
Return None if there is no such element.
>>> next_smallest([1, 2, 3, 4, 5])
2
>>> next_smallest([5, 1, 4, 3, 2])
2
>>> next_smallest([])
None
>>> next_smallest([1, 1])
None
"""
if len(lst) < 2:
return None
min1 = min(lst[0], lst[1])
min2 = max(lst[0], lst[1])
for i in range(2, len(lst)):
if lst[i] < min1:
min2 = min1 | elif lst[i] < min2:
min2 = lst[i]
return min2 if min1 != min2 else None
| min1 = lst[i] | def check(candidate):
assert candidate([1, 2, 3, 4, 5]) == 2
assert candidate([5, 1, 4, 3, 2]) == 2
assert candidate([]) == None
assert candidate([1, 1]) == None
assert candidate([1, 1, 1, 1, 0]) == 1
assert candidate([1, 1]) == None
assert candidate([-35, 34, 12, -45]) == -35
def test_check():
check(next_smallest)
test_check()
|
humaneval-HumanEval_33_sort_third.json-L29 | 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); | 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;
}
} | for (int j = i; j < l_e.size(); j++) { | }
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_16_count_distinct_characters.json-L12 | js | //Given a string, find out how many distinct characters (regardless of case) does it consist of
// >>> count_distinct_characters("xyzXYZ")
// 3
// >>> count_distinct_characters("Jerry")
// 4
function count_distinct_characters(string){
var arr = string.split("");
var result = [];
for(var i = 0; i < arr.length; i++){
if(result.indexOf(arr[i].toLowerCase()) < 0){
result.push(arr[i].toLowerCase()); | }
return result.length;
}
| } | const assert = require('node:assert');
function test() {
let candidate = count_distinct_characters;
assert.deepEqual(candidate(""),0);
assert.deepEqual(candidate("abcde"),5);
assert.deepEqual(candidate("abcdecadeCADE"),5);
assert.deepEqual(candidate("aaaaAAAAaaaa"),1);
assert.deepEqual(candidate("Jerry jERRY JeRRRY"),5);
}
test(); |
humaneval-HumanEval_143_words_in_sentence.json-L30 | 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
words = sentence.split() | for word in words:
if is_prime(len(word)):
prime_words.append(word)
return ' '.join(prime_words) | prime_words = [] | 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_125_split_words.json-L25 | js | //Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// >>> split_words("Hello world!")
// ["Hello", "world!"]
// >>> split_words("Hello,world!")
// ["Hello", "world!"]
// >>> split_words("abcdef")
// 3
function split_words(txt){
if(txt.includes(' ')){
return txt.split(' ');
}
else if(txt.includes(',')){
return txt.split(',');
}
else{
let count = 0;
for(let i = 0; i < txt.length; i++){
if(i % 2 != 0){
if(txt[i] == txt[i].toLowerCase()){
count++;
} | }
return count;
}
} | } | const assert = require('node:assert');
function test() {
let candidate = split_words;
assert.deepEqual(candidate("Hello world!"),["Hello", "world!"]);
assert.deepEqual(candidate("Hello,world!"),["Hello", "world!"]);
assert.deepEqual(candidate("Hello world,!"),["Hello", "world,!"]);
assert.deepEqual(candidate("Hello,Hello,world !"),["Hello,Hello,world", "!"]);
assert.deepEqual(candidate("abcdef"),3);
assert.deepEqual(candidate("aaabb"),2);
assert.deepEqual(candidate("aaaBb"),1);
assert.deepEqual(candidate(""),0);
}
test(); |
humaneval-HumanEval_112_reverse_delete.json-L18 | py | from typing import Tuple
def reverse_delete(s: str, c: str) -> Tuple[str, bool]:
"""Task
We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
then check if the result string is palindrome.
A string is called palindrome if it reads the same backward as forward.
You should return a tuple containing the result string and True/False for the check.
Example
>>> reverse_delete('abcde', 'ae')
('bcd', False)
>>> reverse_delete('abcdef', 'b')
('acdef', False)
>>> reverse_delete('abcdedcba', 'ab')
('cdedc', True)
"""
new_str = '' | if i not in c:
new_str += i
new_str_reverse = new_str[::-1]
return (new_str, new_str == new_str_reverse)
| for i in s: | def check(candidate):
assert candidate('abcde', 'ae') == ('bcd', False)
assert candidate('abcdef', 'b') == ('acdef', False)
assert candidate('abcdedcba', 'ab') == ('cdedc', True)
assert candidate('dwik', 'w') == ('dik', False)
assert candidate('a', 'a') == ('', True)
assert candidate('abcdedcba', '') == ('abcdedcba', True)
assert candidate('abcdedcba', 'v') == ('abcdedcba', True)
assert candidate('vabba', 'v') == ('abba', True)
assert candidate('mamma', 'mia') == ('', True)
def test_check():
check(reverse_delete)
test_check()
|
humaneval-HumanEval_73_smallest_change.json-L19 | js | //Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// >>> smallest_change([1, 2, 3, 5, 4, 7, 9, 6])
// 4
// >>> smallest_change([1, 2, 3, 4, 3, 2, 2])
// 1
// >>> smallest_change([1, 2, 3, 2, 1])
// 0
function smallest_change(arr){
let changes = 0;
for(let i = 0; i < arr.length/2; i++){
if(arr[i] != arr[arr.length - 1 - i]){
changes++;
}
}
return changes; | } | const assert = require('node:assert');
function test() {
let candidate = smallest_change;
assert.deepEqual(candidate([1, 2, 3, 5, 4, 7, 9, 6]),4);
assert.deepEqual(candidate([1, 2, 3, 4, 3, 2, 2]),1);
assert.deepEqual(candidate([1, 4, 2]),1);
assert.deepEqual(candidate([1, 4, 4, 2]),1);
assert.deepEqual(candidate([1, 2, 3, 2, 1]),0);
assert.deepEqual(candidate([3, 1, 1, 3]),0);
assert.deepEqual(candidate([1]),0);
assert.deepEqual(candidate([0, 1]),1);
}
test(); |
|
humaneval-HumanEval_118_get_closest_vowel.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// >>> getClosestVowel(("yogurt"))
// ("u")
// >>> getClosestVowel(("FULL"))
// ("U")
// >>> getClosestVowel(("quick"))
// ("")
// >>> getClosestVowel(("ab"))
// ("")
public static String getClosestVowel(String word) {
| final String consonants = "bcdfghjklmnpqrstvwxyz";
List<Integer> idx = new ArrayList<>();
word = word.toLowerCase();
for (int i = 0; i < word.length(); i++) {
if (vowels.indexOf(word.charAt(i)) != -1) {
idx.add(i);
}
}
for (int i = idx.size() - 1; i >= 0; i--) {
int j = idx.get(i);
if (j == 0 || j == word.length() - 1) continue;
char left = word.charAt(j - 1);
char right = word.charAt(j + 1);
if (consonants.indexOf(left) != -1 && consonants.indexOf(right) != -1) {
return String.valueOf(word.charAt(j));
}
}
return "";
}
} | final String vowels = "aeiou"; | }
public static void main(String[] args) {
assert(getClosestVowel(("yogurt")).equals(("u")));
assert(getClosestVowel(("full")).equals(("u")));
assert(getClosestVowel(("easy")).equals(("")));
assert(getClosestVowel(("eAsy")).equals(("")));
assert(getClosestVowel(("ali")).equals(("")));
assert(getClosestVowel(("bad")).equals(("a")));
assert(getClosestVowel(("most")).equals(("o")));
assert(getClosestVowel(("ab")).equals(("")));
assert(getClosestVowel(("ba")).equals(("")));
assert(getClosestVowel(("quick")).equals(("")));
assert(getClosestVowel(("anime")).equals(("i")));
assert(getClosestVowel(("Asia")).equals(("")));
assert(getClosestVowel(("Above")).equals(("o")));
}
}
|
humaneval-HumanEval_135_can_arrange.json-L19 | js | //Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// >>> can_arrange([1, 2, 4, 3, 5])
// 3
// >>> can_arrange([1, 2, 3])
// -1
function can_arrange(arr){
var max = arr[0];
var res = -1;
for(var i = 1; i < arr.length; i++){
if(arr[i] < max){
res = i;
}else{
max = arr[i];
} | return res;
}
| } | const assert = require('node:assert');
function test() {
let candidate = can_arrange;
assert.deepEqual(candidate([1, 2, 4, 3, 5]),3);
assert.deepEqual(candidate([1, 2, 4, 5]),-1);
assert.deepEqual(candidate([1, 4, 2, 5, 6, 7, 8, 9, 10]),2);
assert.deepEqual(candidate([4, 8, 5, 7, 3]),4);
assert.deepEqual(candidate([]),-1);
}
test(); |
humaneval-HumanEval_57_monotonic.json-L29 | 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 true is array list elements are monotonically increasing or decreasing.
// >>> monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)20l))))
// (true)
// >>> monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)20l, (long)4l, (long)10l))))
// (false)
// >>> monotonic((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)0l, (long)-10l))))
// (true)
public static boolean monotonic(ArrayList<Long> l) {
long a = l.get(0);
boolean inc = true;
boolean dec = true;
for (int i = 1; i < l.size(); i++) {
if (l.get(i) < a) {
inc = false;
}
if (l.get(i) > a) {
dec = false;
}
a = l.get(i);
} | }
} | return inc || dec; | }
public static void main(String[] args) {
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)10l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)20l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)20l, (long)4l, (long)10l)))) == (false));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)0l, (long)-10l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)1l, (long)0l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)2l, (long)5l, (long)60l)))) == (false));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)60l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)9l, (long)9l, (long)9l, (long)9l)))) == (true));
}
}
|
humaneval-HumanEval_81_numerical_letter_grade.json-L56 | 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) { | } else if (currentGrade > 0.0f) {
letterGrades.add("D-");
} else {
letterGrades.add("E");
}
}
return letterGrades;
}
} | letterGrades.add("D"); | }
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_39_prime_fib.json-L46 | js | //prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// >>> prime_fib(1)
// 2
// >>> prime_fib(2)
// 3
// >>> prime_fib(3)
// 5
// >>> prime_fib(4)
// 13
// >>> prime_fib(5)
// 89
function prime_fib(n){
function isPrime(number){
if(number <= 3){
return number > 1;
}
else if(number % 2 == 0 || number % 3 == 0){
return false;
}
else{
for(var i = 5; i * i <= number; i += 6){
if(number % i == 0 || number % (i + 2) == 0){
return false;
}
}
return true;
}
}
function fib(num){
var a = 1, b = 0, temp;
while (num >= 0){
temp = a;
a = a + b;
b = temp;
num--;
}
return b;
}
var res = 0;
var fibNum = 0;
while(res < n){
if(isPrime(fib(fibNum))){
res++; | fibNum++;
}
return fib(fibNum - 1);
} | } | const assert = require('node:assert');
function test() {
let candidate = prime_fib;
assert.deepEqual(candidate(1),2);
assert.deepEqual(candidate(2),3);
assert.deepEqual(candidate(3),5);
assert.deepEqual(candidate(4),13);
assert.deepEqual(candidate(5),89);
assert.deepEqual(candidate(6),233);
assert.deepEqual(candidate(7),1597);
assert.deepEqual(candidate(8),28657);
assert.deepEqual(candidate(9),514229);
assert.deepEqual(candidate(10),433494437);
}
test(); |
humaneval-HumanEval_149_sorted_list_sum.json-L34 | 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;
} | return 1;
}
else{
return 0;
}
}
});
}
var a = ["aa", "a", "aaa"];
var b = ["ab", "a", "aaa", "cd"]; | else if(a > b){ | 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_69_search.json-L20 | py | from typing import List
def search(lst: List[int]) -> int:
"""
You are given a non-empty list of positive integers. Return the greatest integer that is greater than
zero, and has a frequency greater than or equal to the value of the integer itself.
The frequency of an integer is the number of times it appears in the list.
If no such a value exist, return -1.
Examples:
>>> search([4, 1, 2, 2, 3, 1])
2
>>> search([1, 2, 2, 3, 3, 3, 4, 4, 4])
3
>>> search([5, 5, 4, 4, 4])
-1
"""
dic = dict()
for i in lst:
if i in dic: | else:
dic[i] = 1
maxValue = -1
for key, value in dic.items():
if value >= key and key > maxValue:
maxValue = key
return maxValue
| dic[i] += 1 | def check(candidate):
assert candidate([5, 5, 5, 5, 1]) == 1
assert candidate([4, 1, 4, 1, 4, 4]) == 4
assert candidate([3, 3]) == -1
assert candidate([8, 8, 8, 8, 8, 8, 8, 8]) == 8
assert candidate([2, 3, 3, 2, 2]) == 2
assert candidate([2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1]) == 1
assert candidate([3, 2, 8, 2]) == 2
assert candidate([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]) == 1
assert candidate([8, 8, 3, 6, 5, 6, 4]) == -1
assert candidate([6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9]) == 1
assert candidate([1, 9, 10, 1, 3]) == 1
assert candidate([6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10]) == 5
assert candidate([1]) == 1
assert candidate([8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5]) == 4
assert candidate([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]) == 2
assert candidate([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]) == 1
assert candidate([9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4]) == 4
assert candidate([2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7]) == 4
assert candidate([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]) == 2
assert candidate([5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8]) == -1
assert candidate([10]) == -1
assert candidate([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]) == 2
assert candidate([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]) == 1
assert candidate([7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6]) == 1
assert candidate([3, 10, 10, 9, 2]) == -1
def test_check():
check(search)
test_check()
|
humaneval-HumanEval_139_special_factorial.json-L17 | js | //The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// >>> special_factorial(4)
// 288
// The function will receive an integer as input and should return the special
// factorial of this integer.
function special_factorial(n){
if (n > 0) {
let fact = 1;
for (let i = 1; i <= n; i++) {
fact *= i;
}
return fact * special_factorial(n - 1);
} else { | }
}
| return 1; | const assert = require('node:assert');
function test() {
let candidate = special_factorial;
assert.deepEqual(candidate(4),288);
assert.deepEqual(candidate(5),34560);
assert.deepEqual(candidate(7),125411328000);
assert.deepEqual(candidate(1),1);
}
test(); |
humaneval-HumanEval_85_add.json-L8 | js | //Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// >>> add([4, 2, 6, 7])
// 2
function add(lst){
var add = 0;
for(var i = 0; i < lst.length; i++) { | add += lst[i];
}
}
return add;
} | if(lst[i] % 2 == 0 && i % 2 != 0) { | const assert = require('node:assert');
function test() {
let candidate = add;
assert.deepEqual(candidate([4, 88]),88);
assert.deepEqual(candidate([4, 5, 6, 7, 2, 122]),122);
assert.deepEqual(candidate([4, 0, 6, 7]),0);
assert.deepEqual(candidate([4, 4, 6, 8]),12);
}
test(); |
humaneval-HumanEval_47_median.json-L10 | py | from typing import List
def median(l: List[int]) -> float:
"""Return median of elements in the list l.
>>> median([3, 1, 2, 4, 5])
3
>>> median([-10, 4, 6, 1000, 10, 20])
15.0
"""
| return (sorted_l[len(l) // 2] + sorted_l[len(l) // 2 - 1]) / 2 if len(l) % 2 == 0 else sorted_l[len(l) // 2]
| sorted_l = sorted(l) | def check(candidate):
assert candidate([3, 1, 2, 4, 5]) == 3
assert candidate([-10, 4, 6, 1000, 10, 20]) == 8.0
assert candidate([5]) == 5
assert candidate([6, 5]) == 5.5
assert candidate([8, 1, 3, 9, 9, 2, 7]) == 7
def test_check():
check(median)
test_check()
|
humaneval-HumanEval_105_by_length.json-L37 | js | //Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// >>> by_length([2, 1, 1, 4, 5, 8, 2, 3])
// ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// If the array is empty, return an empty array:
// >>> by_length([])
// []
// If the array has any strange number ignore it:
// >>> by_length([1, -1, 55])
// ["One"]
function by_length(arr){
var arr2 = [];
for(var i = 0; i < arr.length; i++){
var num = arr[i];
if(num > 0 && num < 10){
arr2.push(num);
}
}
arr2.sort();
arr2.reverse();
var arr3 = [];
for(var i = 0; i < arr2.length; i++){
var num = arr2[i];
if(num == 1){
arr3.push("One");
}
else if(num == 2){
arr3.push("Two");
}
else if(num == 3){
arr3.push("Three");
}
else if(num == 4){
arr3.push("Four"); | else if(num == 5){
arr3.push("Five");
}
else if(num == 6){
arr3.push("Six");
}
else if(num == 7){
arr3.push("Seven");
}
else if(num == 8){
arr3.push("Eight");
}
else if(num == 9){
arr3.push("Nine");
}
}
return arr3;
} | } | const assert = require('node:assert');
function test() {
let candidate = by_length;
assert.deepEqual(candidate([2, 1, 1, 4, 5, 8, 2, 3]),["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]);
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([1, -1, 55]),["One"]);
assert.deepEqual(candidate([1, -1, 3, 2]),["Three", "Two", "One"]);
assert.deepEqual(candidate([9, 4, 8]),["Nine", "Eight", "Four"]);
}
test(); |
humaneval-HumanEval_77_iscube.json-L28 | 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)
if a == 0:
return True
for i in range(1,int(math.sqrt(a))+1):
if i**3 == a:
return True
return False | pass | 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_61_correct_bracketing.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 {
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correctBracketing(("("))
// (false)
// >>> correctBracketing(("()"))
// (true)
// >>> correctBracketing(("(()())"))
// (true)
// >>> correctBracketing((")(()"))
// (false)
public static boolean correctBracketing(String brackets) {
int balance = 0;
for (int i = 0; i < brackets.length(); i++) {
if (brackets.charAt(i) == '(') {
balance++;
} else {
balance--;
} | return false;
}
}
return balance == 0;
}
} | if (balance < 0) { | }
public static void main(String[] args) {
assert(correctBracketing(("()")) == (true));
assert(correctBracketing(("(()())")) == (true));
assert(correctBracketing(("()()(()())()")) == (true));
assert(correctBracketing(("()()((()()())())(()()(()))")) == (true));
assert(correctBracketing(("((()())))")) == (false));
assert(correctBracketing((")(()")) == (false));
assert(correctBracketing(("(")) == (false));
assert(correctBracketing(("((((")) == (false));
assert(correctBracketing((")")) == (false));
assert(correctBracketing(("(()")) == (false));
assert(correctBracketing(("()()(()())())(()")) == (false));
assert(correctBracketing(("()()(()())()))()")) == (false));
}
}
|
humaneval-HumanEval_93_encode.json-L23 | 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():
return ch.lower()
else:
return ch.upper()
def encode_vowel(ch: str) -> str:
if ch.lower() in 'aeiou':
if ch.lower() in 'wxyz': | 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_119_match_parens.json-L18 | js | //You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// >>> match_parens(["()(", ")"])
// "Yes"
// >>> match_parens([")", ")"])
// "No"
function match_parens(lst){
const open = '(';
const close = ')';
const is_good = (s) => { | for (let p of s){
if (p === open){
stack.push(p);
} else if (p === close){
if (stack.length === 0){
return false;
}
stack.pop();
}
}
return stack.length === 0;
};
const str1 = lst[0];
const str2 = lst[1];
if (is_good(str1 + str2)){
return 'Yes';
}
if (is_good(str2 + str1)){
return 'Yes';
}
return 'No';
} | let stack = []; | const assert = require('node:assert');
function test() {
let candidate = match_parens;
assert.deepEqual(candidate(["()(", ")"]),"Yes");
assert.deepEqual(candidate([")", ")"]),"No");
assert.deepEqual(candidate(["(()(())", "())())"]),"No");
assert.deepEqual(candidate([")())", "(()()("]),"Yes");
assert.deepEqual(candidate(["(())))", "(()())(("]),"Yes");
assert.deepEqual(candidate(["()", "())"]),"No");
assert.deepEqual(candidate(["(()(", "()))()"]),"Yes");
assert.deepEqual(candidate(["((((", "((())"]),"No");
assert.deepEqual(candidate([")(()", "(()("]),"No");
assert.deepEqual(candidate([")(", ")("]),"No");
assert.deepEqual(candidate(["(", ")"]),"Yes");
assert.deepEqual(candidate([")", "("]),"Yes");
}
test(); |
humaneval-HumanEval_6_parse_nested_parens.json-L17 | 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 == '(': | max_depth = max(max_depth, current_depth)
elif paren == ')':
current_depth -= 1
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_134_check_if_last_char_is_a_letter.json-L17 | js | //Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// >>> check_if_last_char_is_a_letter("apple pie")
// false
// >>> check_if_last_char_is_a_letter("apple pi e")
// true
// >>> check_if_last_char_is_a_letter("apple pi e ")
// false
// >>> check_if_last_char_is_a_letter("")
// false
function check_if_last_char_is_a_letter(txt){
var result=txt.split(" ");
if(result[result.length-1].length==1 && result[result.length-1].match(/[a-z]/i)){ | }
return false;
} | return true; | const assert = require('node:assert');
function test() {
let candidate = check_if_last_char_is_a_letter;
assert.deepEqual(candidate("apple"),false);
assert.deepEqual(candidate("apple pi e"),true);
assert.deepEqual(candidate("eeeee"),false);
assert.deepEqual(candidate("A"),true);
assert.deepEqual(candidate("Pumpkin pie "),false);
assert.deepEqual(candidate("Pumpkin pie 1"),false);
assert.deepEqual(candidate(""),false);
assert.deepEqual(candidate("eeeee e "),false);
assert.deepEqual(candidate("apple pie"),false);
assert.deepEqual(candidate("apple pi e "),false);
}
test(); |
humaneval-HumanEval_138_is_equal_to_sum_even.json-L43 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// 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;
while (minX <= maxX) {
long x = (minX + maxX) / 2;
long y = n - 2 * x;
if (y % 2 == 1) {
y--;
}
if (2 * x + y < n) {
minX = x + 1;
} else if (2 * x + y > n) {
maxX = x - 1;
} else {
return true;
}
}
return false;
} | } | }
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_10_make_palindrome.json-L24 | js | //Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// >>> make_palindrome("")
// ""
// >>> make_palindrome("cat")
// "catac"
// >>> make_palindrome("cata")
// "catac"
function make_palindrome(string){
var string_length = string.length;
var is_palindrome = function(s){
return s == s.split("").reverse().join("");
};
var i = string_length;
while(i > 0){
if(is_palindrome(string.substring(0, i))){
return string + string.substring(0, string_length - i).split("").reverse().join("");
}
i--;
}
return string; | } | const assert = require('node:assert');
function test() {
let candidate = make_palindrome;
assert.deepEqual(candidate(""),"");
assert.deepEqual(candidate("x"),"x");
assert.deepEqual(candidate("xyz"),"xyzyx");
assert.deepEqual(candidate("xyx"),"xyx");
assert.deepEqual(candidate("jerry"),"jerryrrej");
}
test(); |
|
humaneval-HumanEval_148_bf.json-L28 | 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
} | 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 = [];
for(var i = position1 + 1; i < position2; i++){
res.push(keys[i]);
}
return res;
} | if(!planets[planet1] || !planets[planet2]){ | 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-L65 | 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_156_int_to_mini_roman.json-L20 | py | def int_to_mini_roman(number: int) -> str:
"""
Given a positive integer, obtain its roman numeral equivalent as a string,
and return it in lowercase.
Restrictions: 1 <= num <= 1000
Examples:
>>> int_to_mini_roman(19)
'xix'
>>> int_to_mini_roman(152)
'clii'
>>> int_to_mini_roman(426)
'cdxxvi'
"""
roman_numerals = {
1000: 'm',
900: 'cm',
500: 'd',
400: 'cd', | 90: 'xc',
50: 'l',
40: 'xl',
10: 'x',
9: 'ix',
5: 'v',
4: 'iv',
1: 'i'
}
roman_numeral = ''
for key in sorted(roman_numerals.keys(), reverse=True):
roman_numeral += roman_numerals[key] * (number // key)
number = number % key
return roman_numeral
| 100: 'c', | def check(candidate):
assert candidate(19) == 'xix'
assert candidate(152) == 'clii'
assert candidate(251) == 'ccli'
assert candidate(426) == 'cdxxvi'
assert candidate(500) == 'd'
assert candidate(1) == 'i'
assert candidate(4) == 'iv'
assert candidate(43) == 'xliii'
assert candidate(90) == 'xc'
assert candidate(94) == 'xciv'
assert candidate(532) == 'dxxxii'
assert candidate(900) == 'cm'
assert candidate(994) == 'cmxciv'
assert candidate(1000) == 'm'
def test_check():
check(int_to_mini_roman)
test_check()
|
humaneval-HumanEval_3_below_zero.json-L16 | js | //You're given an array 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
function below_zero(operations){
var sum = 0;
for (var i = 0; i < operations.length; i++) {
sum += operations[i];
if (sum < 0) {
return true;
}
} | }
| return false; | const assert = require('node:assert');
function test() {
let candidate = below_zero;
assert.deepEqual(candidate([]),false);
assert.deepEqual(candidate([1, 2, -3, 1, 2, -3]),false);
assert.deepEqual(candidate([1, 2, -4, 5, 6]),true);
assert.deepEqual(candidate([1, -1, 2, -2, 5, -5, 4, -4]),false);
assert.deepEqual(candidate([1, -1, 2, -2, 5, -5, 4, -5]),true);
assert.deepEqual(candidate([1, -2, 2, -2, 5, -5, 4, -4]),true);
}
test(); |
humaneval-HumanEval_98_count_upper.json-L19 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// 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 -> s.charAt(i) == 'A' || s.charAt(i) == 'E' || s.charAt(i) == 'I' || s.charAt(i) == 'O' || s.charAt(i) == 'U')
.count();
}
} | .filter(i -> i % 2 == 0) | }
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_12_longest.json-L15 | py | from typing import List, Optional
def longest(strings: List[str]) -> Optional[str]:
""" Out of list of strings, return the longest one. Return the first one in case of multiple
strings of the same length. Return None in case the input list is empty.
>>> longest([])
None
>>> longest(['a', 'b', 'c'])
'a'
>>> longest(['a', 'bb', 'ccc'])
'ccc'
"""
if not strings:
return None | long = strings[0]
for s in strings:
if len(s) > len(long):
long = s
return long
| else: | def check(candidate):
assert candidate([]) == None
assert candidate(['x', 'y', 'z']) == 'x'
assert candidate(['x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc']) == 'zzzz'
def test_check():
check(longest)
test_check()
|
humaneval-HumanEval_114_minSubArraySum.json-L9 | js | //Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// >>> minSubArraySum([2, 3, 4, 1, 2, 4])
// 1
// >>> minSubArraySum([-1, -2, -3])
// -6
function minSubArraySum(nums){
| let minSum = nums[0];
for(let i = 0; i < nums.length; i++){
sum += nums[i];
if(sum < minSum){
minSum = sum;
}
if(sum > 0){
sum = 0;
}
}
return minSum;
}
| let sum = 0; | const assert = require('node:assert');
function test() {
let candidate = minSubArraySum;
assert.deepEqual(candidate([2, 3, 4, 1, 2, 4]),1);
assert.deepEqual(candidate([-1, -2, -3]),-6);
assert.deepEqual(candidate([-1, -2, -3, 2, -10]),-14);
assert.deepEqual(candidate([-9999999999999999]),-9999999999999999);
assert.deepEqual(candidate([0, 10, 20, 1000000]),0);
assert.deepEqual(candidate([-1, -2, -3, 10, -5]),-6);
assert.deepEqual(candidate([100, -1, -2, -3, 10, -5]),-6);
assert.deepEqual(candidate([10, 11, 13, 8, 3, 4]),3);
assert.deepEqual(candidate([100, -33, 32, -1, 0, -2]),-33);
assert.deepEqual(candidate([-10]),-10);
assert.deepEqual(candidate([7]),7);
assert.deepEqual(candidate([1, -1]),-1);
}
test(); |
humaneval-HumanEval_134_check_if_last_char_is_a_letter.json-L15 | js | //Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// >>> check_if_last_char_is_a_letter("apple pie")
// false
// >>> check_if_last_char_is_a_letter("apple pi e")
// true
// >>> check_if_last_char_is_a_letter("apple pi e ")
// false
// >>> check_if_last_char_is_a_letter("")
// false
function check_if_last_char_is_a_letter(txt){
| if(result[result.length-1].length==1 && result[result.length-1].match(/[a-z]/i)){
return true;
}
return false;
} | var result=txt.split(" "); | const assert = require('node:assert');
function test() {
let candidate = check_if_last_char_is_a_letter;
assert.deepEqual(candidate("apple"),false);
assert.deepEqual(candidate("apple pi e"),true);
assert.deepEqual(candidate("eeeee"),false);
assert.deepEqual(candidate("A"),true);
assert.deepEqual(candidate("Pumpkin pie "),false);
assert.deepEqual(candidate("Pumpkin pie 1"),false);
assert.deepEqual(candidate(""),false);
assert.deepEqual(candidate("eeeee e "),false);
assert.deepEqual(candidate("apple pie"),false);
assert.deepEqual(candidate("apple pi e "),false);
}
test(); |
humaneval-HumanEval_160_do_algebra.json-L35 | 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]); | 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;
}
| operand.splice(count + 1, 1); | const assert = require('node:assert');
function test() {
let candidate = do_algebra;
assert.deepEqual(candidate(["**", "*", "+"], [2, 3, 4, 5]),37);
assert.deepEqual(candidate(["+", "*", "-"], [2, 3, 4, 5]),9);
assert.deepEqual(candidate(["//", "*"], [7, 3, 4]),8);
}
test(); |