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_59_largest_prime_factor.json-L26 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// >>> largestPrimeFactor((13195l))
// (29l)
// >>> ... | 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_93_encode.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 {
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
... | }
} | return new String(arr); | }
public static void main(String[] args) {
assert(encode(("TEST")).equals(("tgst")));
assert(encode(("Mudasir")).equals(("mWDCSKR")));
assert(encode(("YES")).equals(("ygs")));
assert(encode(("This is a message")).equals(("tHKS KS C MGSSCGG")));
assert(encode(("I DoNt KnOw WhAt tO WrItE")).eq... |
humaneval-HumanEval_91_is_bored.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'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with th... | return boredoms;
}
} | } | }
public static void main(String[] args) {
assert(isBored(("Hello world")) == (0l));
assert(isBored(("Is the sky blue?")) == (0l));
assert(isBored(("I love It !")) == (1l));
assert(isBored(("bIt")) == (0l));
assert(isBored(("I feel good today. I will be productive. will kill It")) == (2l));
... |
humaneval-HumanEval_75_is_multiply_prime.json-L24 | py | def is_multiply_prime(a: int) -> bool:
"""Write a function that returns true if the given number is the multiplication of 3 prime numbers
and false otherwise.
Knowing that (a) is less then 100.
Example:
>>> is_multiply_prime(30)
True
30 = 2 * 3 * 5
"""
n = a
d = 2
prime_fact... | return False | def check(candidate):
assert candidate(5) == False
assert candidate(30) == True
assert candidate(8) == True
assert candidate(10) == False
assert candidate(125) == True
assert candidate(105) == True
assert candidate(126) == False
assert candidate(729) == False
assert candidate(891) ==... | |
humaneval-HumanEval_108_count_nums.json-L23 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function count_nums which takes an array array list of integers and returns
// the number of elements which has a sum of di... | if (str.startsWith("-")) {
sum = sum - (int) Character.getNumericValue(str.charAt(1));
for (int j = 2; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j));
}
} else {
for (int j = ... | int sum = 0; | }
public static void main(String[] args) {
assert(countNums((new ArrayList<Long>(Arrays.asList()))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)0l)))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l, (long)-2l, ... |
humaneval-HumanEval_109_move_one_ball.json-L36 | js | //We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift o... | } | } | const assert = require('node:assert');
function test() {
let candidate = move_one_ball;
assert.deepEqual(candidate([3, 4, 5, 1, 2]),true);
assert.deepEqual(candidate([3, 5, 10, 1, 2]),true);
assert.deepEqual(candidate([4, 3, 1, 2]),false);
assert.deepEqual(candidate([3, 5, 4, 1, 2]),false);
assert.deepEqu... |
humaneval-HumanEval_81_numerical_letter_grade.json-L47 | js | //It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that ca... | 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] > ... | else if (grades[i] > 1.7){ | const assert = require('node:assert');
function test() {
let candidate = numerical_letter_grade;
assert.deepEqual(candidate([4.0, 3, 1.7, 2, 3.5]),["A+", "B", "C-", "C", "A-"]);
assert.deepEqual(candidate([1.2]),["D+"]);
assert.deepEqual(candidate([0.5]),["D-"]);
assert.deepEqual(candidate([0.0]),["E"]);
... |
humaneval-HumanEval_148_bf.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 {
// There are eight planets in our solar system: the closerst to the Sun
// is Mercury, the next one is Venus, then Earth, Mars, Jupit... | return new ArrayList<String>();
}
}
} | } else { | }
public static void main(String[] args) {
assert(bf(("Jupiter"), ("Neptune")).equals((new ArrayList<String>(Arrays.asList((String)"Saturn", (String)"Uranus")))));
assert(bf(("Earth"), ("Mercury")).equals((new ArrayList<String>(Arrays.asList((String)"Venus")))));
assert(bf(("Mercury"), ("Uranus")).e... |
humaneval-HumanEval_86_anti_shuffle.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 {
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all word... | char[] chars = word.toCharArray();
Arrays.sort(chars);
sb.append(new String(chars));
sb.append(" ");
}
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
} | for (String word : words) { | }
public static void main(String[] args) {
assert(antiShuffle(("Hi")).equals(("Hi")));
assert(antiShuffle(("hello")).equals(("ehllo")));
assert(antiShuffle(("number")).equals(("bemnru")));
assert(antiShuffle(("abcd")).equals(("abcd")));
assert(antiShuffle(("Hello World!!!")).equals(("Hello !... |
humaneval-HumanEval_37_sort_even.json-L39 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// This function takes an array array list l and returns an array array list l' such that
// l' is identical to l in the odd indicies,... | } | }
public static void main(String[] args) {
assert(sortEven((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))));
assert(sortEven((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)-5l, (long)2l, (long)-3... | |
humaneval-HumanEval_137_compare_one.json-L35 | js | //Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return undefined if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// >>> compare_one(1, 2.5)
// 2.5
//... | return b;
} else {
return undefined;
}
}
}
| } else if (a < b[0]){ | const assert = require('node:assert');
function test() {
let candidate = compare_one;
assert.deepEqual(candidate(1, 2),2);
assert.deepEqual(candidate(1, 2.5),2.5);
assert.deepEqual(candidate(2, 3),3);
assert.deepEqual(candidate(5, 6),6);
assert.deepEqual(candidate(1, "2,3"),"2,3");
assert.deepEqual(cand... |
humaneval-HumanEval_160_do_algebra.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 {
// Given two array lists operator, and operand. The first array list has basic algebra operations, and
// the second array list is an... | 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(lis... | list.add(operand.get(0)); | }
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)... |
humaneval-HumanEval_81_numerical_letter_grade.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 {
// 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 algo... | 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 (c... | } else if (currentGrade > 3.7f) { | }
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(numerical... |
humaneval-HumanEval_63_fibfib.json-L17 | py | def fibfib(n: int) -> int:
"""The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
fibfib(0) == 0
fibfib(1) == 0
fibfib(2) == 1
fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
Please write a function to efficiently compute the n-th element ... | n -= 1
return a
| a, b, c = b, c, a + b + c | def check(candidate):
assert candidate(2) == 1
assert candidate(1) == 0
assert candidate(5) == 4
assert candidate(8) == 24
assert candidate(10) == 81
assert candidate(12) == 274
assert candidate(14) == 927
def test_check():
check(fibfib)
test_check()
|
humaneval-HumanEval_119_match_parens.json-L28 | py | from typing import List
def match_parens(lst: List[str]) -> str:
"""
You are given a list 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 b... | if open_parens:
open_parens -= 1
else:
close_parens += 1
if open_parens == 0 and close_parens == 0:
return 'Yes'
return 'No'
| elif c == ')': | def check(candidate):
assert candidate(['()(', ')']) == 'Yes'
assert candidate([')', ')']) == 'No'
assert candidate(['(()(())', '())())']) == 'No'
assert candidate([')())', '(()()(']) == 'Yes'
assert candidate(['(())))', '(()())((']) == 'Yes'
assert candidate(['()', '())']) == 'No'
assert ca... |
humaneval-HumanEval_151_double_the_difference.json-L22 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of numbers, return the sum of squares of the numbers
// in the array list that are odd. Ignore numbers th... | } | } | }
public static void main(String[] args) {
assert(doubleTheDifference((new ArrayList<Float>(Arrays.asList()))) == (0l));
assert(doubleTheDifference((new ArrayList<Float>(Arrays.asList((float)5.0f, (float)4.0f)))) == (25l));
assert(doubleTheDifference((new ArrayList<Float>(Arrays.asList((float)0.1f, ... |
humaneval-HumanEval_42_incr_list.json-L19 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return array list with elements incremented by 1.
// >>> incrList((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))... | } | } | }
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))... |
humaneval-HumanEval_59_largest_prime_factor.json-L9 | js | //Return the largest prime factor of n. Assume n > 1 and is not a prime.
// >>> largest_prime_factor(13195)
// 29
// >>> largest_prime_factor(2048)
// 2
function largest_prime_factor(n){
var result = 2;
while(n > result){ | n = n / result;
}
else{
result = result + 1;
}
}
return result;
} | if(n % result == 0){ | const assert = require('node:assert');
function test() {
let candidate = largest_prime_factor;
assert.deepEqual(candidate(15),5);
assert.deepEqual(candidate(27),3);
assert.deepEqual(candidate(63),7);
assert.deepEqual(candidate(330),11);
assert.deepEqual(candidate(13195),29);
}
test(); |
humaneval-HumanEval_36_fizz_buzz.json-L18 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// >>> fizzBuzz((50l))
... | if (i % 11 == 0 || i % 13 == 0) {
String s = String.valueOf(i);
for (int j = 0; j < s.length(); j++) {
if (s.charAt(j) == '7') {
res++;
}
}
}
}
return res;
}
} | for (long i = 0; i < n; i++) { | }
public static void main(String[] args) {
assert(fizzBuzz((50l)) == (0l));
assert(fizzBuzz((78l)) == (2l));
assert(fizzBuzz((79l)) == (3l));
assert(fizzBuzz((100l)) == (3l));
assert(fizzBuzz((200l)) == (6l));
assert(fizzBuzz((4000l)) == (192l));
assert(fizzBuzz((10000l)) == (639l));... |
humaneval-HumanEval_156_int_to_mini_roman.json-L33 | 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(... | return roman_numeral
| number = number % key | def check(candidate):
assert candidate(19) == 'xix'
assert candidate(152) == 'clii'
assert candidate(251) == 'ccli'
assert candidate(426) == 'cdxxvi'
assert candidate(500) == 'd'
assert candidate(1) == 'i'
assert candidate(4) == 'iv'
assert candidate(43) == 'xliii'
assert candidate(9... |
humaneval-HumanEval_104_unique_digits.json-L30 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of positive integers x. return a sorted array list of all
// elements that hasn't any even digit.
//... | z = z / 10;
}
if (unique) {
b.add(x.get(i));
}
}
Collections.sort(b);
return b;
}
} | } | }
public static void main(String[] args) {
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)15l, (long)33l, (long)1422l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)15l, (long)33l)))));
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)152l, (long)323l, ... |
humaneval-HumanEval_128_prod_signs.json-L18 | py | from typing import List, Optional
def prod_signs(arr: List[int]) -> Optional[int]:
"""
You are given an array arr of integers and you need to return
sum of magnitudes of integers multiplied by product of all signs
of each number in the array, represented by 1, -1 or 0.
Note: return None for empty a... | out = 1
for item in lst:
out *= item
return out
if len(arr) == 0:
return None
else:
sign_arr = []
for num in arr:
if num > 0:
sign_arr.append(1)
elif num < 0:
sign_arr.append(-1)
else... | def product(lst: List[int]) -> int: | def check(candidate):
assert candidate([1, 2, 2, -4]) == -9
assert candidate([0, 1]) == 0
assert candidate([1, 1, 1, 2, 3, -1, 1]) == -10
assert candidate([]) == None
assert candidate([2, 4, 1, 2, -1, -1, 9]) == 20
assert candidate([-1, 1, -1, 1]) == 4
assert candidate([-1, 1, 1, 1]) == -4
... |
humaneval-HumanEval_117_select_words.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 s and a natural number n, you have been tasked to implement
// a function that returns an array array list of all w... | if (consonants == n) {
ret.add(word);
}
}
return ret;
}
} | } | }
public static void main(String[] args) {
assert(selectWords(("Mary had a little lamb"), (4l)).equals((new ArrayList<String>(Arrays.asList((String)"little")))));
assert(selectWords(("Mary had a little lamb"), (3l)).equals((new ArrayList<String>(Arrays.asList((String)"Mary", (String)"lamb")))));
ass... |
humaneval-HumanEval_64_vowels_count.json-L14 | js | //Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// >>> vowels_count("abcde")
// 2
// >>> vo... | if(vowels.indexOf(s[i])!=-1){
count++;
}
}
if(s[s.length-1]=='y'){
count++;
}
return count;
}
| for(var i=0; i<s.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = vowels_count;
assert.deepEqual(candidate("abcde"),2);
assert.deepEqual(candidate("Alone"),3);
assert.deepEqual(candidate("key"),2);
assert.deepEqual(candidate("bye"),1);
assert.deepEqual(candidate("keY"),2);
assert.deepEqual(candid... |
humaneval-HumanEval_56_correct_bracketing.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 {
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correc... | open--;
}
if (open < 0) {
return false;
}
}
return open == 0;
}
} | } else { | }
public static void main(String[] args) {
assert(correctBracketing(("<>")) == (true));
assert(correctBracketing(("<<><>>")) == (true));
assert(correctBracketing(("<><><<><>><>")) == (true));
assert(correctBracketing(("<><><<<><><>><>><<><><<>>>")) == (true));
assert(correctBracketing(("<<<>... |
humaneval-HumanEval_96_count_up_to.json-L39 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Implement a function that takes an non-negative integer and returns an array array list of the first n
// integers that are prime n... | } | } | }
public static void main(String[] args) {
assert(countUpTo((5l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l)))));
assert(countUpTo((6l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)5l)))));
assert(countUpTo((7l)).equals((new ArrayList<Long>(Arrays.asList((l... |
humaneval-HumanEval_119_match_parens.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 {
// You are given an array array list of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
... | if (s3.charAt(i) == '(') c1 += 1;
else c1 -= 1;
if (c1 < 0) break;
}
for (int i = 0; i < s4.length(); i++) {
if (s4.charAt(i) == '(') c2 += 1;
else c2 -= 1;
if (c2 < 0) break;
}
if (c1 == 0 || c2 == 0) return "Yes";
... | for (int i = 0; i < s3.length(); i++) { | }
public static void main(String[] args) {
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"()(", (String)")")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")", (String)")")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.a... |
humaneval-HumanEval_96_count_up_to.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 {
// Implement a function that takes an non-negative integer and returns an array array list of the first n
// integers that are prime n... | for (long j = 2l; j < i; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
arrayList.add(i);
}
}
return arrayList;
}
} | boolean isPrime = true; | }
public static void main(String[] args) {
assert(countUpTo((5l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l)))));
assert(countUpTo((6l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)5l)))));
assert(countUpTo((7l)).equals((new ArrayList<Long>(Arrays.asList((l... |
humaneval-HumanEval_115_max_fill.json-L31 | js | //You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
... | }
maxFill += Math.ceil(sum/capacity);
}
return maxFill;
}
| sum += grid[i][j]; | const assert = require('node:assert');
function test() {
let candidate = max_fill;
assert.deepEqual(candidate([[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], 1),6);
assert.deepEqual(candidate([[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], 2),5);
assert.deepEqual(candidate([[0, 0, 0], [0, 0, 0]], 5),0);... |
humaneval-HumanEval_82_prime_length.json-L19 | js | //Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// >>> prime_length("Hello")
// true
// >>> prime_length("abcdcba")
// true
// >>> prime_length("kittens")
// true
// >>> prime_length("orange")
// false
function prime_length(string){
le... | } | } | const assert = require('node:assert');
function test() {
let candidate = prime_length;
assert.deepEqual(candidate("Hello"),true);
assert.deepEqual(candidate("abcdcba"),true);
assert.deepEqual(candidate("kittens"),true);
assert.deepEqual(candidate("orange"),false);
assert.deepEqual(candidate("wow"),true);
... |
humaneval-HumanEval_19_sort_numbers.json-L10 | js | //Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// >>> sort_numbers("three one five")
// "one three five"
function sort_number... | "two": 2,
"three": 3,
"four": 4,
"five": 5,
"six": 6,
"seven": 7,
"eight": 8,
"nine": 9
};
numString.sort(function(a, b){
return numMap[a] - numMap[b];
});
numString = numString.join(" ");
return numString;
} | "one": 1, | const assert = require('node:assert');
function test() {
let candidate = sort_numbers;
assert.deepEqual(candidate(""),"");
assert.deepEqual(candidate("three"),"three");
assert.deepEqual(candidate("three five nine"),"three five nine");
assert.deepEqual(candidate("five zero four seven nine eight"),"zero four ... |
humaneval-HumanEval_111_histogram.json-L48 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a string representing a space separated lowercase letters, return a hash map
// of the letter with the most repetition and co... | } | } | }
public static void main(String[] args) {
assert(histogram(("a b b a")).equals((new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))));
assert(histogram(("a b c a b")).equals((new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))));
assert(histogram(("a b c d g")).equals((new HashMap<String,Long>(Map.... |
humaneval-HumanEval_6_parse_nested_parens.json-L22 | 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 ne... | return result | 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_156_int_to_mini_roman.json-L27 | js | //Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// >>> int_to_mini_roman(19)
// "xix"
// >>> int_to_mini_roman(152)
// "clii"
// >>> int_to_mini_roman(426)
// "cdxxvi"
function int_to_mini_roman(number){
var r... | while (number > 0){
var key_list = Object.keys(roman_conversion).map(Number);
key_list.sort(function(a, b){return b-a});
for (var i = 0; i < key_list.length; i++){
if (key_list[i] <= number){
output += roman_conversion[key_list[i]];
number -= key_l... | var output = ""; | const assert = require('node:assert');
function test() {
let candidate = int_to_mini_roman;
assert.deepEqual(candidate(19),"xix");
assert.deepEqual(candidate(152),"clii");
assert.deepEqual(candidate(251),"ccli");
assert.deepEqual(candidate(426),"cdxxvi");
assert.deepEqual(candidate(500),"d");
assert.dee... |
humaneval-HumanEval_105_by_length.json-L40 | js | //Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// >>> by_length([2, 1, 1, 4, 5, 8, 2, 3])
// ["Eight"... | else if(num == 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(can... |
humaneval-HumanEval_160_do_algebra.json-L29 | 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 ( - )
... | 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... | operator.splice(count, 1); | const assert = require('node:assert');
function test() {
let candidate = do_algebra;
assert.deepEqual(candidate(["**", "*", "+"], [2, 3, 4, 5]),37);
assert.deepEqual(candidate(["+", "*", "-"], [2, 3, 4, 5]),9);
assert.deepEqual(candidate(["//", "*"], [7, 3, 4]),8);
}
test(); |
humaneval-HumanEval_108_count_nums.json-L33 | js | //Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// >>> count_nums([])
// 0
// >>> count_nums([-1, 11, -11])
// 1
// >... | } | return count; | const assert = require('node:assert');
function test() {
let candidate = count_nums;
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([-1, -2, 0]),0);
assert.deepEqual(candidate([1, 1, 2, -2, 3, 4, 5]),6);
assert.deepEqual(candidate([1, 6, 9, -6, 0, 1, 5]),5);
assert.deepEqual(candidate([1, 1... |
humaneval-HumanEval_81_numerical_letter_grade.json-L63 | js | //It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that ca... | }
}
return grades_array;
} | grades_array.push("E"); | const assert = require('node:assert');
function test() {
let candidate = numerical_letter_grade;
assert.deepEqual(candidate([4.0, 3, 1.7, 2, 3.5]),["A+", "B", "C-", "C", "A-"]);
assert.deepEqual(candidate([1.2]),["D+"]);
assert.deepEqual(candidate([0.5]),["D-"]);
assert.deepEqual(candidate([0.0]),["E"]);
... |
humaneval-HumanEval_124_valid_date.json-L27 | js | //You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12... | return false;
}
}else if((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && (day < 1 || day > 31)){
return false;
}else if((month == 4 || month == 6 || month == 9 || month == 11) && (day < 1 || day > 30)){
... | if(day < 1 || day > 29){ | const assert = require('node:assert');
function test() {
let candidate = valid_date;
assert.deepEqual(candidate("03-11-2000"),true);
assert.deepEqual(candidate("15-01-2012"),false);
assert.deepEqual(candidate("04-0-2040"),false);
assert.deepEqual(candidate("06-04-2020"),true);
assert.deepEqual(candidate("... |
humaneval-HumanEval_129_minPath.json-L54 | js | //Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in e... | }
if(y > 0){
neighbours.push(grid[x][y - 1]);
}
if(y < n - 1){
neighbours.push(grid[x][y + 1]);
}
let nextCell = neighbours[0];
for(let i = 0; i < neighbours.length; i++){
let curr = neighbours[i];
if(curr < nextCell... | neighbours.push(grid[x + 1][y]); | const assert = require('node:assert');
function test() {
let candidate = minPath;
assert.deepEqual(candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3),[1, 2, 1]);
assert.deepEqual(candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1),[1]);
assert.deepEqual(candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14... |
humaneval-HumanEval_115_max_fill.json-L24 | js | //You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
... | var c = 1;
var r = grid.length;
var c = grid[0].length;
for(var i = 0; i < r; i++){
sum = 0;
for(var j = 0; j < c; j++){
sum += grid[i][j];
}
maxFill += Math.ceil(sum/capacity);
}
return maxFill;
}
| var sum = 0; | const assert = require('node:assert');
function test() {
let candidate = max_fill;
assert.deepEqual(candidate([[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], 1),6);
assert.deepEqual(candidate([[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], 2),5);
assert.deepEqual(candidate([[0, 0, 0], [0, 0, 0]], 5),0);... |
humaneval-HumanEval_148_bf.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 {
// There are eight planets in our solar system: the closerst to the Sun
// is Mercury, the next one is Venus, then Earth, Mars, Jupit... | indexMin = indexPlanet1;
indexMax = indexPlanet2;
} else {
indexMin = indexPlanet2;
indexMax = indexPlanet1;
}
ArrayList<String> planetsInBetween = new ArrayList<String>();
for (int i = indexMin + 1; i < inde... | if (indexPlanet1 < indexPlanet2) { | }
public static void main(String[] args) {
assert(bf(("Jupiter"), ("Neptune")).equals((new ArrayList<String>(Arrays.asList((String)"Saturn", (String)"Uranus")))));
assert(bf(("Earth"), ("Mercury")).equals((new ArrayList<String>(Arrays.asList((String)"Venus")))));
assert(bf(("Mercury"), ("Uranus")).e... |
humaneval-HumanEval_111_histogram.json-L37 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a string representing a space separated lowercase letters, return a hash map
// of the letter with the most repetition and co... | max = hm.get(key);
}
}
for (String key : hm.keySet()) {
if (hm.get(key) == max) {
s.put(key, hm.get(key));
}
}
}
return s;
}
} | if (hm.get(key) > max) { | }
public static void main(String[] args) {
assert(histogram(("a b b a")).equals((new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))));
assert(histogram(("a b c a b")).equals((new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))));
assert(histogram(("a b c d g")).equals((new HashMap<String,Long>(Map.... |
humaneval-HumanEval_49_modp.json-L14 | js | //Return 2^n modulo p (be aware of numerics).
// >>> modp(3, 5)
// 3
// >>> modp(1101, 101)
// 2
// >>> modp(0, 101)
// 1
// >>> modp(3, 11)
// 8
// >>> modp(100, 101)
// 1
function modp(n, p){
var result = 1; | result = (result*2)%p;
n--;
}
return result;
}
| while(n>0){ | const assert = require('node:assert');
function test() {
let candidate = modp;
assert.deepEqual(candidate(3, 5),3);
assert.deepEqual(candidate(1101, 101),2);
assert.deepEqual(candidate(0, 101),1);
assert.deepEqual(candidate(3, 11),8);
assert.deepEqual(candidate(100, 101),1);
assert.deepEqual(candidate(3... |
humaneval-HumanEval_94_skjkasdkd.json-L42 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given an array array list of integers.
// You need to find the largest prime value and return the sum of its digits.
//... | }
if (counter == 2) {
if (number > largestPrime) {
largestPrime = number;
}
}
}
if (largestPrime == 0) {
return 0l;
}
else {
long output = 0l;
while (largestPrime >... | } | }
public static void main(String[] args) {
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l, (long)2l, (long)1l, (long)3l, (long)5l, (long)7l, (long)4l, (long)5l, (long)5l, (long)5l, (long)2l, (long)181l, (long)32l, (long)4l, (long)32l, (long)3l, (long)2l, (long)32l, (long)324l, (long)... |
humaneval-HumanEval_158_find_max.json-L39 | js | //Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// >>> find_max(["name", "of", "string"])
/... | } | const assert = require('node:assert');
function test() {
let candidate = find_max;
assert.deepEqual(candidate(["name", "of", "string"]),"string");
assert.deepEqual(candidate(["name", "enam", "game"]),"enam");
assert.deepEqual(candidate(["aaaaaaa", "bb", "cc"]),"aaaaaaa");
assert.deepEqual(candidate(["abc", ... | |
humaneval-HumanEval_39_prime_fib.json-L21 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// >>> primeFib((1l))
// (2l)
// >>> primeFib... | long prev = 0;
long count = 0;
while (count != n) {
long tmp = fib;
fib += prev;
prev = tmp;
if (BigInteger.valueOf(fib).isProbablePrime(1)) {
count++;
}
}
return fib;
}
} | long fib = 1; | }
public static void main(String[] args) {
assert(primeFib((1l)) == (2l));
assert(primeFib((2l)) == (3l));
assert(primeFib((3l)) == (5l));
assert(primeFib((4l)) == (13l));
assert(primeFib((5l)) == (89l));
assert(primeFib((6l)) == (233l));
assert(primeFib((7l)) == (1597l));
assert... |
humaneval-HumanEval_123_get_odd_collatz.json-L27 | 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. The... | 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])))
| current_num = current_num // 2 | 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_54_same_chars.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 {
// Check if two words have the same characters.
// >>> sameChars(("eabcdzzzz"), ("dddzzzzzzzddeddabc"))
// (true)
// >>> sameC... | } | }
public static void main(String[] args) {
assert(sameChars(("eabcdzzzz"), ("dddzzzzzzzddeddabc")) == (true));
assert(sameChars(("abcd"), ("dddddddabc")) == (true));
assert(sameChars(("dddddddabc"), ("abcd")) == (true));
assert(sameChars(("eabcd"), ("dddddddabc")) == (false));
assert(sameCha... | |
humaneval-HumanEval_64_vowels_count.json-L16 | js | //Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// >>> vowels_count("abcde")
// 2
// >>> vo... | }
}
if(s[s.length-1]=='y'){
count++;
}
return count;
}
| count++; | const assert = require('node:assert');
function test() {
let candidate = vowels_count;
assert.deepEqual(candidate("abcde"),2);
assert.deepEqual(candidate("Alone"),3);
assert.deepEqual(candidate("key"),2);
assert.deepEqual(candidate("bye"),1);
assert.deepEqual(candidate("keY"),2);
assert.deepEqual(candid... |
humaneval-HumanEval_150_x_or_y.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 {
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// E... | } else {
return y;
}
}
} | return x; | }
public static void main(String[] args) {
assert(xOrY((7l), (34l), (12l)) == (34l));
assert(xOrY((15l), (8l), (5l)) == (5l));
assert(xOrY((3l), (33l), (5212l)) == (33l));
assert(xOrY((1259l), (3l), (52l)) == (3l));
assert(xOrY((7919l), (-1l), (12l)) == (-1l));
assert(xOrY((3609l), (1245... |
humaneval-HumanEval_63_fibfib.json-L23 | js | //The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// >>>... | }
| return fibfib(n-1) + fibfib(n-2) + fibfib(n-3); | const assert = require('node:assert');
function test() {
let candidate = fibfib;
assert.deepEqual(candidate(2),1);
assert.deepEqual(candidate(1),0);
assert.deepEqual(candidate(5),4);
assert.deepEqual(candidate(8),24);
assert.deepEqual(candidate(10),81);
assert.deepEqual(candidate(12),274);
assert.deep... |
humaneval-HumanEval_17_parse_music.json-L12 | js | //Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - qu... | songs.forEach(s => {
if(s === 'o'){
song.push(4);
}else if(s === 'o|'){
song.push(2);
}else if(s === '.|'){
song.push(1);
}
});
return song;
}
| let song = []; | const assert = require('node:assert');
function test() {
let candidate = parse_music;
assert.deepEqual(candidate(""),[]);
assert.deepEqual(candidate("o o o o"),[4, 4, 4, 4]);
assert.deepEqual(candidate(".| .| .| .|"),[1, 1, 1, 1]);
assert.deepEqual(candidate("o| o| .| .| o o o o"),[2, 2, 1, 1, 4, 4, 4, 4]);... |
humaneval-HumanEval_62_derivative.json-L21 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in... | }
} | return ans; | }
public static void main(String[] args) {
assert(derivative((new ArrayList<Long>(Arrays.asList((long)3l, (long)1l, (long)2l, (long)4l, (long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)12l, (long)20l)))));
assert(derivative((new ArrayList<Long>(Arrays.asList((long)1l, (lo... |
humaneval-HumanEval_40_triples_sum_to_zero.json-L16 | js | //triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// >>> triples_sum_to_zero([1, 3, 5, 0])
// false
// >>> triples_sum_to_zero([1, 3, -2, 1])
// true
// >>> triples_sum_to_zero([1, 2, 3, 7])
// fal... | for (var k = 0; k < l.length; k++) {
if (i !== j && i !== k && j !== k) {
if (l[i] + l[j] + l[k] === 0) {
return true;
}
}
}
}
}
return false;
}
| for (var j = 0; j < l.length; j++) { | const assert = require('node:assert');
function test() {
let candidate = triples_sum_to_zero;
assert.deepEqual(candidate([1, 3, 5, 0]),false);
assert.deepEqual(candidate([1, 3, 5, -1]),false);
assert.deepEqual(candidate([1, 3, -2, 1]),true);
assert.deepEqual(candidate([1, 2, 3, 7]),false);
assert.deepEqua... |
humaneval-HumanEval_122_add_elements.json-L11 | js | //Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// >>> add_elements([111, 21, 3, 4000, 5, 6, 7, 8, 9], 4)
// 24
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
function add_elements(ar... | if(arr[i] < 100){
sum += arr[i];
}
}
return sum;
}
| for(var i = 0; i < k; i++){ | const assert = require('node:assert');
function test() {
let candidate = add_elements;
assert.deepEqual(candidate([1, -2, -3, 41, 57, 76, 87, 88, 99], 3),-4);
assert.deepEqual(candidate([111, 121, 3, 4000, 5, 6], 2),0);
assert.deepEqual(candidate([11, 21, 3, 90, 5, 6, 7, 8, 9], 4),125);
assert.deepEqual(can... |
humaneval-HumanEval_1_separate_paren_groups.json-L25 | js | //Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input stri... | } | const assert = require('node:assert');
function test() {
let candidate = separate_paren_groups;
assert.deepEqual(candidate("(()()) ((())) () ((())()())"),["(()())", "((()))", "()", "((())()())"]);
assert.deepEqual(candidate("() (()) ((())) (((())))"),["()", "(())", "((()))", "(((())))"]);
assert.deepEqual(can... | |
humaneval-HumanEval_117_select_words.json-L49 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array array list of all w... | } | } | }
public static void main(String[] args) {
assert(selectWords(("Mary had a little lamb"), (4l)).equals((new ArrayList<String>(Arrays.asList((String)"little")))));
assert(selectWords(("Mary had a little lamb"), (3l)).equals((new ArrayList<String>(Arrays.asList((String)"Mary", (String)"lamb")))));
ass... |
humaneval-HumanEval_141_file_name_check.json-L16 | js | //Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file... | let str_2 = file_name.slice(file_name.indexOf('.')+1);
let str_3 = file_name.split('');
if (file_name.includes('.') && /[a-zA-Z]/.test(str_1[0]) &&
(str_2 == 'txt' || str_2 == 'exe' || str_2 == 'dll') && str_1.length != 0 &&
str_3.filter(item => /[0-9]/.test(item)).length < 4) {
return 'Ye... | let str_1 = file_name.slice(0,file_name.indexOf('.')); | const assert = require('node:assert');
function test() {
let candidate = file_name_check;
assert.deepEqual(candidate("example.txt"),"Yes");
assert.deepEqual(candidate("1example.dll"),"No");
assert.deepEqual(candidate("s1sdf3.asd"),"No");
assert.deepEqual(candidate("K.dll"),"Yes");
assert.deepEqual(candida... |
humaneval-HumanEval_113_odd_count.json-L30 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of strings, where each string consists of only digits, return an array array list.
// Each element i of t... | } | }
public static void main(String[] args) {
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"1234567")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 4n the str4ng 4 of the 4nput.")))));
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"3", (St... | |
humaneval-HumanEval_143_words_in_sentence.json-L31 | 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 t... | if is_prime(len(word)):
prime_words.append(word)
return ' '.join(prime_words) | for word in 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'
as... |
humaneval-HumanEval_115_max_fill.json-L30 | js | //You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
... | sum += grid[i][j];
}
maxFill += Math.ceil(sum/capacity);
}
return maxFill;
}
| for(var j = 0; j < c; j++){ | const assert = require('node:assert');
function test() {
let candidate = max_fill;
assert.deepEqual(candidate([[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], 1),6);
assert.deepEqual(candidate([[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], 2),5);
assert.deepEqual(candidate([[0, 0, 0], [0, 0, 0]], 5),0);... |
humaneval-HumanEval_40_triples_sum_to_zero.json-L42 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// triples_sum_to_zero takes an array array list of integers as an input.
// it returns true if there are three distinct elements in t... | }
} | 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((n... |
humaneval-HumanEval_104_unique_digits.json-L18 | js | //Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// >>> unique_digits([15, 33, 1422, 1])
// [1, 15, 33]
// >>> unique_digits([152, 323, 1422, 10])
// []
function unique_digits(x){
... | } | const assert = require('node:assert');
function test() {
let candidate = unique_digits;
assert.deepEqual(candidate([15, 33, 1422, 1]),[1, 15, 33]);
assert.deepEqual(candidate([152, 323, 1422, 10]),[]);
assert.deepEqual(candidate([12345, 2033, 111, 151]),[111, 151]);
assert.deepEqual(candidate([135, 103, 31]... | |
humaneval-HumanEval_56_correct_bracketing.json-L21 | js | //brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correct_bracketing("<")
// false
// >>> correct_bracketing("<>")
// true
// >>> correct_bracketing("<<><>>")
// true
// >>> correct_bracketing("><<>")
// false
function correct_bracketing(brackets)... | }
}
return opens === 0;
}
| return false; | const assert = require('node:assert');
function test() {
let candidate = correct_bracketing;
assert.deepEqual(candidate("<>"),true);
assert.deepEqual(candidate("<<><>>"),true);
assert.deepEqual(candidate("<><><<><>><>"),true);
assert.deepEqual(candidate("<><><<<><><>><>><<><><<>>>"),true);
assert.deepEqua... |
humaneval-HumanEval_31_is_prime.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 {
// Return true if a given number is prime, and false otherwise.
// >>> isPrime((6l))
// (false)
// >>> isPrime((101l))
// ... | i += 6;
}
return true;
}
} | if (n % i == 0 || n % (i + 2) == 0) return false; | }
public static void main(String[] args) {
assert(isPrime((6l)) == (false));
assert(isPrime((101l)) == (true));
assert(isPrime((11l)) == (true));
assert(isPrime((13441l)) == (true));
assert(isPrime((61l)) == (true));
assert(isPrime((4l)) == (false));
assert(isPrime((1l)) == (false));... |
humaneval-HumanEval_49_modp.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return 2^n modulo p (be aware of numerics).
// >>> modp((3l), (5l))
// (3l)
// >>> modp((1101l), (101l))
// (2l)
//... | return sqrt;
}
return (sqrt * 2) % p;
}
} | if (n % 2 == 0) { | }
public static void main(String[] args) {
assert(modp((3l), (5l)) == (3l));
assert(modp((1101l), (101l)) == (2l));
assert(modp((0l), (101l)) == (1l));
assert(modp((3l), (11l)) == (8l));
assert(modp((100l), (101l)) == (1l));
assert(modp((30l), (5l)) == (4l));
assert(modp((31l), (5l))... |
humaneval-HumanEval_129_minPath.json-L63 | js | //Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in e... | let curr = neighbours[i];
if(curr < nextCell){
nextCell = curr;
}
}
currCell = nextCell;
}
return path;
} | for(let i = 0; i < neighbours.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = minPath;
assert.deepEqual(candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3),[1, 2, 1]);
assert.deepEqual(candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1),[1]);
assert.deepEqual(candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14... |
humaneval-HumanEval_8_sum_product.json-L13 | py | from typing import List, Tuple
def sum_product(numbers: List[int]) -> Tuple[int, int]:
""" For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.
Empty sum should be equal to 0 and empty product should be equal to 1.
>>> sum_product([])
(0, 1)
... | sum += i
product *= i
return (sum, product)
| for i in numbers: | def check(candidate):
assert candidate([]) == (0, 1)
assert candidate([1, 1, 1]) == (3, 1)
assert candidate([100, 0]) == (100, 0)
assert candidate([3, 5, 7]) == (15, 105)
assert candidate([10]) == (10, 10)
def test_check():
check(sum_product)
test_check()
|
humaneval-HumanEval_57_monotonic.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 true is array list elements are monotonically increasing or decreasing.
// >>> monotonic((new ArrayList<Long>(Arrays.asList(... | 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>(Arr... |
humaneval-HumanEval_107_even_odd_palindrome.json-L26 | js | //Given a positive integer n, return an array that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// >>> even_odd_palindrome(3)
// [1, 2]
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// >>... | var odd = 0;
var even = 0;
for(var i = 0; i < pal.length; i++){
if(pal[i] % 2 == 0){
even++;
}
else{
odd++;
}
}
return [even, odd];
} | } | const assert = require('node:assert');
function test() {
let candidate = even_odd_palindrome;
assert.deepEqual(candidate(123),[8, 13]);
assert.deepEqual(candidate(12),[4, 6]);
assert.deepEqual(candidate(3),[1, 2]);
assert.deepEqual(candidate(63),[6, 8]);
assert.deepEqual(candidate(25),[5, 6]);
assert.de... |
humaneval-HumanEval_104_unique_digits.json-L17 | js | //Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// >>> unique_digits([15, 33, 1422, 1])
// [1, 15, 33]
// >>> unique_digits([152, 323, 1422, 10])
// []
function unique_digits(x){
... | }
| return result.sort(function(a, b){return a-b}) | const assert = require('node:assert');
function test() {
let candidate = unique_digits;
assert.deepEqual(candidate([15, 33, 1422, 1]),[1, 15, 33]);
assert.deepEqual(candidate([152, 323, 1422, 10]),[]);
assert.deepEqual(candidate([12345, 2033, 111, 151]),[111, 151]);
assert.deepEqual(candidate([135, 103, 31]... |
humaneval-HumanEval_8_sum_product.json-L15 | py | from typing import List, Tuple
def sum_product(numbers: List[int]) -> Tuple[int, int]:
""" For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.
Empty sum should be equal to 0 and empty product should be equal to 1.
>>> sum_product([])
(0, 1)
... | return (sum, product)
| product *= i | def check(candidate):
assert candidate([]) == (0, 1)
assert candidate([1, 1, 1]) == (3, 1)
assert candidate([100, 0]) == (100, 0)
assert candidate([3, 5, 7]) == (15, 105)
assert candidate([10]) == (10, 10)
def test_check():
check(sum_product)
test_check()
|
humaneval-HumanEval_75_is_multiply_prime.json-L14 | py | def is_multiply_prime(a: int) -> bool:
"""Write a function that returns true if the given number is the multiplication of 3 prime numbers
and false otherwise.
Knowing that (a) is less then 100.
Example:
>>> is_multiply_prime(30)
True
30 = 2 * 3 * 5
"""
n = a
d = 2
prime_fact... | prime_factors.append(d)
n //= d
else:
d += 1
if n > 1:
prime_factors.append(n)
if len(prime_factors) == 3:
return True
else:
return False
| if n % d == 0: | def check(candidate):
assert candidate(5) == False
assert candidate(30) == True
assert candidate(8) == True
assert candidate(10) == False
assert candidate(125) == True
assert candidate(105) == True
assert candidate(126) == False
assert candidate(729) == False
assert candidate(891) ==... |
humaneval-HumanEval_104_unique_digits.json-L16 | py | from typing import List
def unique_digits(x: List[int]) -> List[int]:
"""Given a list of positive integers x. return a sorted list of all
elements that hasn't any even digit.
Note: Returned list should be sorted in increasing order.
For example:
>>> unique_digits([15, 33, 1422, 1])
[1, 1... | temp=i
while temp:
if temp%2==0:
s.append(i)
break
temp=temp//10
for i in s:
x.remove(i)
return sorted(x)
| for i in x: | def check(candidate):
assert candidate([15, 33, 1422, 1]) == [1, 15, 33]
assert candidate([152, 323, 1422, 10]) == []
assert candidate([12345, 2033, 111, 151]) == [111, 151]
assert candidate([135, 103, 31]) == [31, 135]
def test_check():
check(unique_digits)
test_check()
|
humaneval-HumanEval_75_is_multiply_prime.json-L16 | js | //Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// >>> is_multiply_prime(30)
// true
// 30 = 2 * 3 * 5
function is_multiply_prime(a){
a = Math.abs(a);
const prime = [2, 3, 5, 7, 11, 13, 1... | }else{
i++;
}
}
if(check.length == 3){
return true;
}else{
return false;
}
} | check.push(prime[i]); | const assert = require('node:assert');
function test() {
let candidate = is_multiply_prime;
assert.deepEqual(candidate(5),false);
assert.deepEqual(candidate(30),true);
assert.deepEqual(candidate(8),true);
assert.deepEqual(candidate(10),false);
assert.deepEqual(candidate(125),true);
assert.deepEqual(cand... |
humaneval-HumanEval_39_prime_fib.json-L27 | 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;
... | }
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))){
... | } | const assert = require('node:assert');
function test() {
let candidate = prime_fib;
assert.deepEqual(candidate(1),2);
assert.deepEqual(candidate(2),3);
assert.deepEqual(candidate(3),5);
assert.deepEqual(candidate(4),13);
assert.deepEqual(candidate(5),89);
assert.deepEqual(candidate(6),233);
assert.dee... |
humaneval-HumanEval_129_minPath.json-L42 | js | //Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in e... | for(let j = 0; j < n; j++){
if(grid[i][j] === currCell){
x = i;
y = j;
}
}
}
if(x > 0){
neighbours.push(grid[x - 1][y]);
}
if(x < n - 1){
neighbours.push(grid[x + 1][y]... | for(let i = 0; i < n; i++){ | const assert = require('node:assert');
function test() {
let candidate = minPath;
assert.deepEqual(candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3),[1, 2, 1]);
assert.deepEqual(candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1),[1]);
assert.deepEqual(candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14... |
humaneval-HumanEval_4_mean_absolute_deviation.json-L17 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// For a given array list of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute... | return (float)numbers.stream().mapToDouble(n -> Math.abs(n - mean)).average().getAsDouble();
}
} | float mean = (float)numbers.stream().mapToDouble(Float::floatValue).average().getAsDouble(); | }
public static void main(String[] args) {
assert(meanAbsoluteDeviation((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f)))) == (0.5f));
assert(meanAbsoluteDeviation((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f, (float)4.0f)))) == (1.0f));
assert(meanAbsolute... |
humaneval-HumanEval_41_car_race_collision.json-L15 | js | //Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a c... | num_collisions++;
}
}
}
return num_collisions;
}
| if (left_to_right[i] == right_to_left[j]) { | const assert = require('node:assert');
function test() {
let candidate = car_race_collision;
assert.deepEqual(candidate(2),4);
assert.deepEqual(candidate(3),9);
assert.deepEqual(candidate(4),16);
assert.deepEqual(candidate(8),64);
assert.deepEqual(candidate(10),100);
}
test(); |
humaneval-HumanEval_77_iscube.json-L25 | 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)... | return True
return False
pass
| if i**3 == a: | 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(... |
humaneval-HumanEval_70_strange_sort_list.json-L26 | js | //Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// >>> strange_sort_list([1, 2, 3, 4])
// [1, 4, 2, 3]
// >>> strange_sort_list([5, 5, 5, 5])
// [5, 5, 5, 5]
// >>> str... | } | return output; | const assert = require('node:assert');
function test() {
let candidate = strange_sort_list;
assert.deepEqual(candidate([1, 2, 3, 4]),[1, 4, 2, 3]);
assert.deepEqual(candidate([5, 6, 7, 8, 9]),[5, 9, 6, 8, 7]);
assert.deepEqual(candidate([1, 2, 3, 4, 5]),[1, 5, 2, 4, 3]);
assert.deepEqual(candidate([5, 6, 7,... |
humaneval-HumanEval_117_select_words.json-L36 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array array list of all w... | case 'u':
break;
default:
consonants++;
break;
}
}
if (consonants == n) {
ret.add(word);
}
}
return ret;
}
} | case 'o': | }
public static void main(String[] args) {
assert(selectWords(("Mary had a little lamb"), (4l)).equals((new ArrayList<String>(Arrays.asList((String)"little")))));
assert(selectWords(("Mary had a little lamb"), (3l)).equals((new ArrayList<String>(Arrays.asList((String)"Mary", (String)"lamb")))));
ass... |
humaneval-HumanEval_104_unique_digits.json-L34 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of positive integers x. return a sorted array list of all
// elements that hasn't any even digit.
//... | }
}
Collections.sort(b);
return b;
}
} | b.add(x.get(i)); | }
public static void main(String[] args) {
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)15l, (long)33l, (long)1422l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)15l, (long)33l)))));
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)152l, (long)323l, ... |
humaneval-HumanEval_78_hex_key.json-L24 | js | //You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, ... | let primes = ['2', '3', '5', '7', 'B', 'D'];
for(let x = 0; x < num.length; x++){
if(primes.includes(num[x])){
result += 1;
}
}
return result;
} | let hexadecimals = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']; | const assert = require('node:assert');
function test() {
let candidate = hex_key;
assert.deepEqual(candidate("AB"),1);
assert.deepEqual(candidate("1077E"),2);
assert.deepEqual(candidate("ABED1A33"),4);
assert.deepEqual(candidate("2020"),2);
assert.deepEqual(candidate("123456789ABCDEF0"),6);
assert.deepE... |
humaneval-HumanEval_143_words_in_sentence.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 {
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to re... | } | }
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 ... | |
humaneval-HumanEval_33_sort_third.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 {
// 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... | 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 i = 0; i < l.size(); i++) { | }
public static void main(String[] args) {
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)5l)))));
assert(sortThird((n... |
humaneval-HumanEval_98_count_upper.json-L17 | js | //Given a string s, count the number of uppercase vowels in even indices.
// For example:
// >>> count_upper("aBCdEf")
// 1
// >>> count_upper("abcdefg")
// 0
// >>> count_upper("dBBE")
// 0
function count_upper(s){
var index;
var result = 0;
var vowel = ['A', 'E', 'I', 'O', 'U'];
for (index = 0; index ... | return result;
} | } | const assert = require('node:assert');
function test() {
let candidate = count_upper;
assert.deepEqual(candidate("aBCdEf"),1);
assert.deepEqual(candidate("abcdefg"),0);
assert.deepEqual(candidate("dBBE"),0);
assert.deepEqual(candidate("B"),0);
assert.deepEqual(candidate("U"),1);
assert.deepEqual(candida... |
humaneval-HumanEval_28_concatenate.json-L10 | js | //Concatenate array of strings into a single string
// >>> concatenate([])
// ""
// >>> concatenate(["a", "b", "c"])
// "abc"
function concatenate(strings){
if(strings.length === 0){
return "";
} | return string;
}
| var string = strings.join(""); | 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_17_parse_music.json-L17 | js | //Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - qu... | }else if(s === '.|'){
song.push(1);
}
});
return song;
}
| song.push(2); | const assert = require('node:assert');
function test() {
let candidate = parse_music;
assert.deepEqual(candidate(""),[]);
assert.deepEqual(candidate("o o o o"),[4, 4, 4, 4]);
assert.deepEqual(candidate(".| .| .| .|"),[1, 1, 1, 1]);
assert.deepEqual(candidate("o| o| .| .| o o o o"),[2, 2, 1, 1, 4, 4, 4, 4]);... |
humaneval-HumanEval_124_valid_date.json-L37 | py | def valid_date(date: str) -> bool:
"""You have to write a function which validates a given date string and
returns True if the date is valid otherwise False.
The date is valid if all of the following rules are satisfied:
1. The date string is not empty.
2. The number of days is not less than 1 or hi... | return True | def check(candidate):
assert candidate('03-11-2000') == True
assert candidate('15-01-2012') == False
assert candidate('04-0-2040') == False
assert candidate('06-04-2020') == True
assert candidate('01-01-2007') == True
assert candidate('03-32-2011') == False
assert candidate('') == False
... | |
humaneval-HumanEval_124_valid_date.json-L32 | py | def valid_date(date: str) -> bool:
"""You have to write a function which validates a given date string and
returns True if the date is valid otherwise False.
The date is valid if all of the following rules are satisfied:
1. The date string is not empty.
2. The number of days is not less than 1 or hi... | if date_list[1] < 1 or date_list[1] > days_per_month[date_list[0] - 1]:
return False
if len(str(date_list[2])) != 4:
return False
return True | return False | def check(candidate):
assert candidate('03-11-2000') == True
assert candidate('15-01-2012') == False
assert candidate('04-0-2040') == False
assert candidate('06-04-2020') == True
assert candidate('01-01-2007') == True
assert candidate('03-32-2011') == False
assert candidate('') == False
... |
humaneval-HumanEval_139_special_factorial.json-L11 | 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... | for (let i = 1; i <= n; i++) {
fact *= i;
}
return fact * special_factorial(n - 1);
} else {
return 1;
}
}
| let fact = 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_46_fib4.json-L23 | js | //The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequen... | prev[3] = curr;
}
return prev[3];
}
| prev[2] = prev[3]; | const assert = require('node:assert');
function test() {
let candidate = fib4;
assert.deepEqual(candidate(5),4);
assert.deepEqual(candidate(8),28);
assert.deepEqual(candidate(10),104);
assert.deepEqual(candidate(12),386);
}
test(); |
humaneval-HumanEval_24_largest_divisor.json-L10 | 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_0_has_close_elements.json-L8 | js | //Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// >>> has_close_elements([1.0, 2.0, 3.0], 0.5)
// false
// >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)
// true
function has_close_elements(numbers, threshold){
| for(var j = i + 1; j < numbers.length; j++){
if(Math.abs(numbers[i] - numbers[j]) < threshold){
return true;
}
}
}
return false;
}
| for(var i = 0; i < numbers.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = has_close_elements;
assert.deepEqual(candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.3),true);
assert.deepEqual(candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.05),false);
assert.deepEqual(candidate([1.0, 2.0, 5.9, 4.0, 5.0], 0.95),true);
asse... |
humaneval-HumanEval_160_do_algebra.json-L36 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given two array lists operator, and operand. The first array list has basic algebra operations, and
// the second array list is an... | 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.st... | list.set(list.size() - 1, list.get(list.size() - 1) * operand.get(i + 1)); | }
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)... |
humaneval-HumanEval_81_numerical_letter_grade.json-L41 | js | //It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that ca... | 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] >... | else if (grades[i] > 2.3){ | const assert = require('node:assert');
function test() {
let candidate = numerical_letter_grade;
assert.deepEqual(candidate([4.0, 3, 1.7, 2, 3.5]),["A+", "B", "C-", "C", "A-"]);
assert.deepEqual(candidate([1.2]),["D+"]);
assert.deepEqual(candidate([0.5]),["D-"]);
assert.deepEqual(candidate([0.0]),["E"]);
... |
humaneval-HumanEval_155_even_odd_count.json-L19 | 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.... | }
| 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]);
asse... |
humaneval-HumanEval_40_triples_sum_to_zero.json-L24 | js | //triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// >>> triples_sum_to_zero([1, 3, 5, 0])
// false
// >>> triples_sum_to_zero([1, 3, -2, 1])
// true
// >>> triples_sum_to_zero([1, 2, 3, 7])
// fal... | }
return false;
}
| } | const assert = require('node:assert');
function test() {
let candidate = triples_sum_to_zero;
assert.deepEqual(candidate([1, 3, 5, 0]),false);
assert.deepEqual(candidate([1, 3, 5, -1]),false);
assert.deepEqual(candidate([1, 3, -2, 1]),true);
assert.deepEqual(candidate([1, 2, 3, 7]),false);
assert.deepEqua... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.