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_137_compare_one.json-L40 | py | from typing import Union
def compare_one(a: Union[int, float, str], b: Union[int, float, str]) -> Union[int, float, str, None]:
"""
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values ... | return None
elif isinstance(a, int) and isinstance(b, float):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, float) and isinstance(b, int):
if a > b:
return a
elif a < b:
... | else: | def check(candidate):
assert candidate(1, 2) == 2
assert candidate(1, 2.5) == 2.5
assert candidate(2, 3) == 3
assert candidate(5, 6) == 6
assert candidate(1, '2,3') == '2,3'
assert candidate('5,1', '6') == '6'
assert candidate('1', '2') == '2'
assert candidate('1', 1) == None
def test_c... |
humaneval-HumanEval_20_find_closest_elements.json-L20 | js | //From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])
// [2.0, 2.2]
// >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])
// [2.... | }
| return a > b ? [b, a] : [a, b]; | const assert = require('node:assert');
function test() {
let candidate = find_closest_elements;
assert.deepEqual(candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2]),[3.9, 4.0]);
assert.deepEqual(candidate([1.0, 2.0, 5.9, 4.0, 5.0]),[5.0, 5.9]);
assert.deepEqual(candidate([1.0, 2.0, 3.0, 4.0, 5.0, 2.2]),[2.0, 2.2]);
a... |
humaneval-HumanEval_98_count_upper.json-L18 | py | def count_upper(s: str) -> int:
"""
Given a string s, count the number of uppercase vowels in even indices.
For example:
>>> count_upper('aBCdEf')
1
>>> count_upper('abcdefg')
0
>>> count_upper('dBBE')
0
"""
vowel_set = set('AEIOU')
count = 0
for i in range(0, le... |
"""
D.1 Recursion
Given a positive integer n, write a recursive function that returns the sum of the squares of the
positive odd integers smaller than n. Assume n is greater than or equal to 3.
""" | return count | def check(candidate):
assert candidate('aBCdEf') == 1
assert candidate('abcdefg') == 0
assert candidate('dBBE') == 0
assert candidate('B') == 0
assert candidate('U') == 1
assert candidate('') == 0
assert candidate('EEEE') == 2
def test_check():
check(count_upper)
test_check()
|
humaneval-HumanEval_135_can_arrange.json-L16 | 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,... | max = arr[i];
}
}
return res;
}
| }else{ | const assert = require('node:assert');
function test() {
let candidate = can_arrange;
assert.deepEqual(candidate([1, 2, 4, 3, 5]),3);
assert.deepEqual(candidate([1, 2, 4, 5]),-1);
assert.deepEqual(candidate([1, 4, 2, 5, 6, 7, 8, 9, 10]),2);
assert.deepEqual(candidate([4, 8, 5, 7, 3]),4);
assert.deepEqual(... |
humaneval-HumanEval_129_minPath.json-L33 | 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 currCell = startCell;
for(let l = 0; l < k; l++){
path.push(currCell);
let neighbours = [];
let x = null;
let y = null;
for(let i = 0; i < n; i++){
for(let j = 0; j < n; j++){
if(grid[i][j] === currCell){
... | } | 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_146_specialFilter.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 {
// Write a function that takes an array array list of numbers as input and returns
// the number of elements in the array array list ... | digits.add(n % 10);
n /= 10;
}
Collections.reverse(digits);
return digits.stream().mapToLong(i -> i).toArray();
}
}
helper h = new helper();
return nums.stream().filter(x -> x > 10).filter(x -> {
... | while (n != 0) { | }
public static void main(String[] args) {
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)5l, (long)-2l, (long)1l, (long)-5l)))) == (0l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)15l, (long)-73l, (long)14l, (long)-15l)))) == (1l));
assert(specialFilter((new Array... |
humaneval-HumanEval_14_all_prefixes.json-L9 | py | from typing import List
def all_prefixes(string: str) -> List[str]:
""" Return list of all prefixes from shortest to longest of the input string
>>> all_prefixes('abc')
['a', 'ab', 'abc']
"""
prefixes = [] | prefixes.append(string[:i+1])
return prefixes
| for i in range(len(string)): | def check(candidate):
assert candidate('') == []
assert candidate('asdfgh') == ['a', 'as', 'asd', 'asdf', 'asdfg', 'asdfgh']
assert candidate('WWW') == ['W', 'WW', 'WWW']
def test_check():
check(all_prefixes)
test_check()
|
humaneval-HumanEval_31_is_prime.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 if a given number is prime, and false otherwise.
// >>> isPrime((6l))
// (false)
// >>> isPrime((101l))
// ... | if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
long i = 5;
while (i * i <= n) {
if (n % i == 0 || n % (i + 2) == 0) return false;
i += 6;
}
return true;
}
} | if (n <= 1) 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_57_monotonic.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 {
// Return true is array list elements are monotonically increasing or decreasing.
// >>> monotonic((new ArrayList<Long>(Arrays.asList(... | inc = false;
}
if (l.get(i) > a) {
dec = false;
}
a = l.get(i);
}
return inc || dec;
}
} | if (l.get(i) < a) { | }
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_95_check_dict_case.json-L44 | 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": "bana... | return false;
}
}
return true;
} | else{ | const assert = require('node:assert');
function test() {
let candidate = check_dict_case;
assert.deepEqual(candidate({"p": "pineapple", "b": "banana"}),true);
assert.deepEqual(candidate({"p": "pineapple", "A": "banana", "B": "banana"}),false);
assert.deepEqual(candidate({"p": "pineapple", "5": "banana", "a": ... |
humaneval-HumanEval_65_circular_shift.json-L9 | js | //Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// >>> circular_shift(12, 1)
// "21"
// >>> circular_shift(12, 2)
// "12"
function circular_shift(x, shift){
| var len = str.length;
var res = '';
if(len < shift){
for(var i = len-1; i >= 0; i--){
res += str[i];
}
}else{
res = str.substring(len-shift) + str.substring(0, len-shift);
}
return res;
}
| var str = x.toString(); | const assert = require('node:assert');
function test() {
let candidate = circular_shift;
assert.deepEqual(candidate(100, 2),"001");
assert.deepEqual(candidate(12, 2),"12");
assert.deepEqual(candidate(97, 8),"79");
assert.deepEqual(candidate(12, 1),"21");
assert.deepEqual(candidate(11, 101),"11");
}
test(... |
humaneval-HumanEval_141_file_name_check.json-L17 | 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_3 = file_name.split('');
if (file_name.includes('.') && /[a-zA-Z]/.test(str_1[0]) &&
(str_2 == 'txt' || str_2 == 'exe' || str_2 == 'dll') && str_1.length != 0 &&
str_3.filter(item => /[0-9]/.test(item)).length < 4) {
return 'Yes';
}
return 'No';
}
| let str_2 = file_name.slice(file_name.indexOf('.')+1); | 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_39_prime_fib.json-L32 | 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;
... | 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);
} | while (num >= 0){ | const assert = require('node:assert');
function test() {
let candidate = prime_fib;
assert.deepEqual(candidate(1),2);
assert.deepEqual(candidate(2),3);
assert.deepEqual(candidate(3),5);
assert.deepEqual(candidate(4),13);
assert.deepEqual(candidate(5),89);
assert.deepEqual(candidate(6),233);
assert.dee... |
humaneval-HumanEval_141_file_name_check.json-L46 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and return... | return result;
}
return "Yes";
}
} | if (!Character.isLetter(name.charAt(0))) { | }
public static void main(String[] args) {
assert(fileNameCheck(("example.txt")).equals(("Yes")));
assert(fileNameCheck(("1example.dll")).equals(("No")));
assert(fileNameCheck(("s1sdf3.asd")).equals(("No")));
assert(fileNameCheck(("K.dll")).equals(("Yes")));
assert(fileNameCheck(("MY16FILE3.... |
humaneval-HumanEval_147_get_max_triples.json-L21 | py | def get_max_triples(n: int) -> int:
"""
You are given a positive integer n. You have to create an integer array a of length n.
For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
and a[i] + a[j] + a[k] is a multipl... | while (k < n):
if (a[i] + a[j] + a[k]) % 3 == 0:
count += 1
k += 1
j += 1
k = j + 1
i += 1
j = i + 1
k = j + 1
return count
| while (j < n - 1): | def check(candidate):
assert candidate(5) == 1
assert candidate(6) == 4
assert candidate(10) == 36
assert candidate(100) == 53361
def test_check():
check(get_max_triples)
test_check()
|
humaneval-HumanEval_126_is_sorted.json-L38 | js | //Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> is_sorted([5])
// true
// >>> is_sorted([1, 2, 3, 4, 5])
// true
// >>> is_sorted([1, 3, 2, 4... | }
return true;
}
| } | const assert = require('node:assert');
function test() {
let candidate = is_sorted;
assert.deepEqual(candidate([5]),true);
assert.deepEqual(candidate([1, 2, 3, 4, 5]),true);
assert.deepEqual(candidate([1, 3, 2, 4, 5]),false);
assert.deepEqual(candidate([1, 2, 3, 4, 5, 6]),true);
assert.deepEqual(candidate... |
humaneval-HumanEval_81_numerical_letter_grade.json-L28 | 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... | 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");
... | } | 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_156_int_to_mini_roman.json-L41 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <=... | num -= 100;
}
if (num >= 90) {
res += "xc";
num -= 90;
}
if (num >= 50) {
res += "l";
num -= 50;
}
if (num >= 40) {
res += "xl";
num -= 40;
}
while (num >= 10) {
... | res += "c"; | }
public static void main(String[] args) {
assert(intToMiniRoman((19l)).equals(("xix")));
assert(intToMiniRoman((152l)).equals(("clii")));
assert(intToMiniRoman((251l)).equals(("ccli")));
assert(intToMiniRoman((426l)).equals(("cdxxvi")));
assert(intToMiniRoman((500l)).equals(("d")));
ass... |
humaneval-HumanEval_7_filter_by_substring.json-L13 | js | //Filter an input array of strings only for ones that contain given substring
// >>> filter_by_substring([], "a")
// []
// >>> filter_by_substring(["abc", "bacd", "cde", "array"], "a")
// ["abc", "bacd", "array"]
function filter_by_substring(strings, substring){
var filtered = [];
for(var i = 0; i < strings.len... | } | return filtered; | const assert = require('node:assert');
function test() {
let candidate = filter_by_substring;
assert.deepEqual(candidate([], "john"),[]);
assert.deepEqual(candidate(["xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"], "xxx"),["xxx", "xxxAAA", "xxx"]);
assert.deepEqual(candidate(["xxx", "asd", "aaaxxy", "john d... |
humaneval-HumanEval_25_factorize.json-L18 | js | //Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed 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(2... | }
}
return arr;
}
| factor++; | const assert = require('node:assert');
function test() {
let candidate = factorize;
assert.deepEqual(candidate(2),[2]);
assert.deepEqual(candidate(4),[2, 2]);
assert.deepEqual(candidate(8),[2, 2, 2]);
assert.deepEqual(candidate(57),[3, 19]);
assert.deepEqual(candidate(3249),[3, 3, 19, 19]);
assert.deepE... |
humaneval-HumanEval_148_bf.json-L22 | 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 p... | if planet1 not in planets or planet2 not in planets:
return ()
start = planets.index(planet1)
end = planets.index(planet2)
if start < end:
planets = planets[start+1:end]
else:
planets = planets[end+1:start]
return tuple(planets) | planets = ('Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune') | 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', ... |
humaneval-HumanEval_153_Strongest_Extension.json-L35 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You will be given the name of a class (a string) and an array array list of extensions.
// The extensions are to be used to load ad... | strength = diff;
strongest = s;
}
}
return class_name + "." + strongest;
}
} | if (diff > strength) { | }
public static void main(String[] args) {
assert(StrongestExtension(("Watashi"), (new ArrayList<String>(Arrays.asList((String)"tEN", (String)"niNE", (String)"eIGHt8OKe")))).equals(("Watashi.eIGHt8OKe")));
assert(StrongestExtension(("Boku123"), (new ArrayList<String>(Arrays.asList((String)"nani", (Strin... |
humaneval-HumanEval_26_remove_duplicates.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 {
// From an array array list of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in ... | ArrayList<Long> out = new ArrayList<Long>();
for (int i = 0; i < numbers.size(); i++) {
Long key = numbers.get(i);
if (hashmap.get(key) == 1) {
out.add(key);
}
}
return out;
}
} | } | }
public static void main(String[] args) {
assert(removeDuplicates((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(removeDuplicates((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((lon... |
humaneval-HumanEval_81_numerical_letter_grade.json-L59 | 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("E");
}
}
return letterGrades;
}
} | } else { | }
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_18_how_many_times.json-L10 | 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; | while(string.indexOf(substring, i) !== -1){
count++;
i = string.indexOf(substring, i) + 1;
}
return count;
} | var count = 0; | 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_75_is_multiply_prime.json-L14 | 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... | a = a / prime[i];
check.push(prime[i]);
}else{
i++;
}
}
if(check.length == 3){
return true;
}else{
return false;
}
} | if(a % prime[i] == 0){ | const assert = require('node:assert');
function test() {
let candidate = is_multiply_prime;
assert.deepEqual(candidate(5),false);
assert.deepEqual(candidate(30),true);
assert.deepEqual(candidate(8),true);
assert.deepEqual(candidate(10),false);
assert.deepEqual(candidate(125),true);
assert.deepEqual(cand... |
humaneval-HumanEval_156_int_to_mini_roman.json-L30 | 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... | for (var i = 0; i < key_list.length; i++){
if (key_list[i] <= number){
output += roman_conversion[key_list[i]];
number -= key_list[i];
break;
}
}
}
return output;
}
| key_list.sort(function(a, b){return b-a}); | 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_116_sort_array.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 {
// In this Kata, you have to sort an array array list of non-negative integers according to
// number of ones in their binary represen... | 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;
}
} | long a1 = a, b1 = 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)-... |
humaneval-HumanEval_63_fibfib.json-L40 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fib... | } | }
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_81_numerical_letter_grade.json-L53 | py | from typing import List
def numerical_letter_grade(grades: List[float]) -> List[str]:
"""It is the last week of the semester and the teacher has to give the grades
to students. The teacher has been making her own algorithm for grading.
The only problem is, she has lost the code she used for grading.
Sh... | final.append('D-')
else:
final.append('E')
return final
| elif x > 0.0: | def check(candidate):
assert candidate([4.0, 3, 1.7, 2, 3.5]) == ['A+', 'B', 'C-', 'C', 'A-']
assert candidate([1.2]) == ['D+']
assert candidate([0.5]) == ['D-']
assert candidate([0.0]) == ['E']
assert candidate([1.0, 0.3, 1.5, 2.8, 3.3]) == ['D', 'D-', 'C-', 'B', 'B+']
assert candidate([0.0, 0.... |
humaneval-HumanEval_155_even_odd_count.json-L20 | py | from typing import Tuple
def even_odd_count(num: int) -> Tuple[int, int]:
"""Given an integer. return a tuple that has the number of even and odd digits respectively.
Example:
>>> even_odd_count(-12)
(1, 1)
>>> even_odd_count(123)
(1, 2)
"""
num_str = str(abs(num))
even_count = 0
... | return even_count, odd_count
| odd_count += 1 | def check(candidate):
assert candidate(7) == (0, 1)
assert candidate(-78) == (1, 1)
assert candidate(3452) == (2, 2)
assert candidate(346211) == (3, 3)
assert candidate(-345821) == (3, 3)
assert candidate(-2) == (1, 0)
assert candidate(-45347) == (2, 3)
assert candidate(0) == (1, 0)
def... |
humaneval-HumanEval_101_words_string.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 {
// 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 arr... | }
return al;
}
} | al.add(st.nextToken()); | }
public static void main(String[] args) {
assert(wordsString(("Hi, my name is John")).equals((new ArrayList<String>(Arrays.asList((String)"Hi", (String)"my", (String)"name", (String)"is", (String)"John")))));
assert(wordsString(("One, two, three, four, five, six")).equals((new ArrayList<String>(Arrays.... |
humaneval-HumanEval_86_anti_shuffle.json-L20 | js | //Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank sp... | return result.join(" ");
} | }); | const assert = require('node:assert');
function test() {
let candidate = anti_shuffle;
assert.deepEqual(candidate("Hi"),"Hi");
assert.deepEqual(candidate("hello"),"ehllo");
assert.deepEqual(candidate("number"),"bemnru");
assert.deepEqual(candidate("abcd"),"abcd");
assert.deepEqual(candidate("Hello World!!... |
humaneval-HumanEval_91_is_bored.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 {
// 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... | if (words.length > 0 && words[0].equals("I")) {
boredoms++;
}
}
return boredoms;
}
} | String[] words = sentence.split("\\s"); | }
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_126_is_sorted.json-L54 | 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 du... | }
}
else {
seen_2_in_a_row = false;
}
previous_number = number.intValue();
running_max = number.intValue();
}
... | seen_2_in_a_row = true; | }
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, (lon... |
humaneval-HumanEval_61_correct_bracketing.json-L20 | py | def correct_bracketing(brackets: str) -> bool:
""" brackets is a string of "(" and ")".
return True if every opening bracket has a corresponding closing bracket.
>>> correct_bracketing('(')
False
>>> correct_bracketing('()')
True
>>> correct_bracketing('(()())')
True
>>> correct_bra... | return False
return count == 0
| if count < 0: | def check(candidate):
assert candidate('()') == True
assert candidate('(()())') == True
assert candidate('()()(()())()') == True
assert candidate('()()((()()())())(()()(()))') == True
assert candidate('((()())))') == False
assert candidate(')(()') == False
assert candidate('(') == False
... |
humaneval-HumanEval_100_make_a_pile.json-L14 | js | //Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i ... | }
return arr;
} | arr.push(n + (i * 2)); | const assert = require('node:assert');
function test() {
let candidate = make_a_pile;
assert.deepEqual(candidate(3),[3, 5, 7]);
assert.deepEqual(candidate(4),[4, 6, 8, 10]);
assert.deepEqual(candidate(5),[5, 7, 9, 11, 13]);
assert.deepEqual(candidate(6),[6, 8, 10, 12, 14, 16]);
assert.deepEqual(candidate(... |
humaneval-HumanEval_147_get_max_triples.json-L24 | py | def get_max_triples(n: int) -> int:
"""
You are given a positive integer n. You have to create an integer array a of length n.
For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
and a[i] + a[j] + a[k] is a multipl... | k += 1
j += 1
k = j + 1
i += 1
j = i + 1
k = j + 1
return count
| count += 1 | def check(candidate):
assert candidate(5) == 1
assert candidate(6) == 4
assert candidate(10) == 36
assert candidate(100) == 53361
def test_check():
check(get_max_triples)
test_check()
|
humaneval-HumanEval_33_sort_third.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 {
// 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... | for (int i = 0; i < l.size(); i++) {
if (i % 3 == 0) {
l_e.add(l.get(i));
} else {
l_r.add(l.get(i));
}
}
for (int i = 0; i < l_e.size(); i++) {
long min = l_e.get(i);
for (int j = i; j < l_e.size(); j++)... | ArrayList<Long> l_s = new ArrayList<Long>(); | }
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_99_closest_integer.json-L20 | js | //Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// >>> closest_integer("10")
// 10
// >>> closest_integer("15.3")
// 15
// Note:
// Rounding away from zero means that i... | }
}else{
if(value - Math.floor(value) > -0.5){
return Math.floor(value);
}else{
return Math.ceil(value);
}
}
}
| return Math.ceil(value); | const assert = require('node:assert');
function test() {
let candidate = closest_integer;
assert.deepEqual(candidate("10"),10);
assert.deepEqual(candidate("14.5"),15);
assert.deepEqual(candidate("-15.5"),-16);
assert.deepEqual(candidate("15.3"),15);
assert.deepEqual(candidate("0"),0);
}
test(); |
humaneval-HumanEval_54_same_chars.json-L17 | js | //Check if two words have the same characters.
// >>> same_chars("eabcdzzzz", "dddzzzzzzzddeddabc")
// true
// >>> same_chars("abcd", "dddddddabc")
// true
// >>> same_chars("dddddddabc", "abcd")
// true
// >>> same_chars("eabcd", "dddddddabc")
// false
// >>> same_chars("abcd", "dddddddabce")
// false
// >>> same_char... | res = false;
break;
}
}
for(let i = 0; i < s1.length; i++){
if(s0.indexOf(s1[i]) === -1){
res = false;
break;
}
}
return res;
}
| if(s1.indexOf(s0[i]) === -1){ | const assert = require('node:assert');
function test() {
let candidate = same_chars;
assert.deepEqual(candidate("eabcdzzzz", "dddzzzzzzzddeddabc"),true);
assert.deepEqual(candidate("abcd", "dddddddabc"),true);
assert.deepEqual(candidate("dddddddabc", "abcd"),true);
assert.deepEqual(candidate("eabcd", "ddddd... |
humaneval-HumanEval_128_prod_signs.json-L13 | js | //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 undefined for empty arr.
// Example:
// >>> prod_signs([1, 2, 2, -4])
// 9
// >>> prod_signs([0, 1])
// 0
// >>> ... | var len = arr.length;
var pro = 1;
if(len == 0){
return undefined;
}
else{
for(var i = 0; i < len; i++){
total += Math.abs(arr[i]);
if(arr[i] < 0){
pro *= -1;
}
else if(arr[i] == 0){
pro *= 0;
}
}
... | var total = 0; | const assert = require('node:assert');
function test() {
let candidate = prod_signs;
assert.deepEqual(candidate([1, 2, 2, -4]),-9);
assert.deepEqual(candidate([0, 1]),0);
assert.deepEqual(candidate([1, 1, 1, 2, 3, -1, 1]),-10);
assert.deepEqual(candidate([]),undefined);
assert.deepEqual(candidate([2, 4, 1... |
humaneval-HumanEval_33_sort_third.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 {
// 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... | 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++;
... | if (l_e.get(j) < min) { | }
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_10_make_palindrome.json-L16 | 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_pa... | while(i > 0){
if(is_palindrome(string.substring(0, i))){
return string + string.substring(0, string_length - i).split("").reverse().join("");
}
i--;
}
return string;
}
| var i = string_length; | 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");
}
tes... |
humaneval-HumanEval_81_numerical_letter_grade.json-L62 | 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... | return letterGrades;
}
} | } | }
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_133_sum_squares.json-L26 | py | from typing import List
def sum_squares(lst: List[float]) -> int:
"""You are given a list of numbers.
You need to return the sum of squared numbers in the given list,
round each element in the list to the upper int(Ceiling) first.
Examples:
>>> lst([1.0, 2.0, 3.0])
14
>>> lst([1.0, 4.0, 9.0... | return total | total += i**2 | def check(candidate):
assert candidate([1.0, 2.0, 3.0]) == 14
assert candidate([1.0, 2.0, 3.0]) == 14
assert candidate([1.0, 3.0, 5.0, 7.0]) == 84
assert candidate([1.4, 4.2, 0.0]) == 29
assert candidate([-2.4, 1.0, 1.0]) == 6
assert candidate([100.0, 1.0, 15.0, 2.0]) == 10230
assert candida... |
humaneval-HumanEval_76_is_simple_power.json-L21 | js | //Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// >>> is_simple_power(1, 4)
// true
// >>> is_simple_power(2, 2)
// true
// >>> is_simple_power(8, 2)
// true
// >>> is_simple_power(3, 2)
// fa... | return false;
}
if(x % n !== 0){
return false;
}
return is_simple_power(x/n, n);
}
| if(x < n){ | const assert = require('node:assert');
function test() {
let candidate = is_simple_power;
assert.deepEqual(candidate(16, 2),true);
assert.deepEqual(candidate(143214, 16),false);
assert.deepEqual(candidate(4, 2),true);
assert.deepEqual(candidate(9, 3),true);
assert.deepEqual(candidate(16, 4),true);
asser... |
humaneval-HumanEval_91_is_bored.json-L13 | js | //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")
... | boredoms++;
}
}
return boredoms;
}
| if(line.match(/^\s*I /)){ | const assert = require('node:assert');
function test() {
let candidate = is_bored;
assert.deepEqual(candidate("Hello world"),0);
assert.deepEqual(candidate("Is the sky blue?"),0);
assert.deepEqual(candidate("I love It !"),1);
assert.deepEqual(candidate("bIt"),0);
assert.deepEqual(candidate("I feel good to... |
humaneval-HumanEval_86_anti_shuffle.json-L14 | js | //Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank sp... | var strings = s.split(" ");
strings.forEach(function(str){
var temp = str.split("");
temp.sort();
result.push(temp.join(""));
});
return result.join(" ");
} | var result = []; | const assert = require('node:assert');
function test() {
let candidate = anti_shuffle;
assert.deepEqual(candidate("Hi"),"Hi");
assert.deepEqual(candidate("hello"),"ehllo");
assert.deepEqual(candidate("number"),"bemnru");
assert.deepEqual(candidate("abcd"),"abcd");
assert.deepEqual(candidate("Hello World!!... |
humaneval-HumanEval_74_total_match.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 accepts two array lists of strings and returns the array list that has
// total number of chars in the all s... | } | } | }
public static void main(String[] args) {
assert(totalMatch((new ArrayList<String>(Arrays.asList())), (new ArrayList<String>(Arrays.asList()))).equals((new ArrayList<String>(Arrays.asList()))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<Stri... |
humaneval-HumanEval_155_even_odd_count.json-L18 | 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_137_compare_one.json-L64 | py | from typing import Union
def compare_one(a: Union[int, float, str], b: Union[int, float, str]) -> Union[int, float, str, None]:
"""
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values ... | b_tmp = b.replace(',', '.')
if a > float(b_tmp):
return a
elif a < float(b_tmp):
return b
else:
return None
elif isinstance(a, str) and isinstance(b, float):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
... | elif isinstance(a, int) and isinstance(b, str): | def check(candidate):
assert candidate(1, 2) == 2
assert candidate(1, 2.5) == 2.5
assert candidate(2, 3) == 3
assert candidate(5, 6) == 6
assert candidate(1, '2,3') == '2,3'
assert candidate('5,1', '6') == '6'
assert candidate('1', '2') == '2'
assert candidate('1', 1) == None
def test_c... |
humaneval-HumanEval_99_closest_integer.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 {
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equi... | }
} | return bd.longValue(); | }
public static void main(String[] args) {
assert(closestInteger(("10")) == (10l));
assert(closestInteger(("14.5")) == (15l));
assert(closestInteger(("-15.5")) == (-16l));
assert(closestInteger(("15.3")) == (15l));
assert(closestInteger(("0")) == (0l));
}
}
|
humaneval-HumanEval_36_fizz_buzz.json-L13 | py | def fizz_buzz(n: int) -> int:
"""Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
>>> fizz_buzz(50)
0
>>> fizz_buzz(78)
2
>>> fizz_buzz(79)
3
"""
x = 0
for i in range(n):
if i % 11 == 0 or i % 13 == 0: | return x
| x += str(i).count('7') | def check(candidate):
assert candidate(50) == 0
assert candidate(78) == 2
assert candidate(79) == 3
assert candidate(100) == 3
assert candidate(200) == 6
assert candidate(4000) == 192
assert candidate(10000) == 639
assert candidate(100000) == 8026
def test_check():
check(fizz_buzz)
... |
humaneval-HumanEval_43_pairs_sum_to_zero.json-L27 | 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
// >>>... | } | const assert = require('node:assert');
function test() {
let candidate = pairs_sum_to_zero;
assert.deepEqual(candidate([1, 3, 5, 0]),false);
assert.deepEqual(candidate([1, 3, -2, 1]),false);
assert.deepEqual(candidate([1, 2, 3, 7]),false);
assert.deepEqual(candidate([2, 4, -5, 3, 5, 7]),true);
assert.deep... | |
humaneval-HumanEval_158_find_max.json-L21 | py | from typing import List
def find_max(words: List[str]) -> str:
"""Write a function that accepts a list of strings.
The list contains different words. Return the word with maximum number
of unique characters. If multiple strings have maximum number of unique
characters, return the one which comes first ... | max_word = word
elif unique_num == max_num:
if word < max_word:
max_word = word
return max_word
| max_num = unique_num | def check(candidate):
assert candidate(['name', 'of', 'string']) == 'string'
assert candidate(['name', 'enam', 'game']) == 'enam'
assert candidate(['aaaaaaa', 'bb', 'cc']) == 'aaaaaaa'
assert candidate(['abc', 'cba']) == 'abc'
assert candidate(['play', 'this', 'game', 'of', 'footbott']) == 'footbott... |
humaneval-HumanEval_11_string_xor.json-L18 | js | //Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// >>> string_xor("010", "110")
// "100"
function string_xor(a, b){
var arrayA = [];
var arrayB = [];
var arrayXOR = [];
var result = '';
for (var i = 0; i < a.length; i++) {... | }
else {
arrayXOR.push(0);
}
}
result = arrayXOR.join('');
return result;
} | arrayXOR.push(1); | const assert = require('node:assert');
function test() {
let candidate = string_xor;
assert.deepEqual(candidate("111000", "101010"),"010010");
assert.deepEqual(candidate("1", "1"),"0");
assert.deepEqual(candidate("0101", "0000"),"0101");
}
test(); |
humaneval-HumanEval_27_flip_case.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 {
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// >>> flipCase(("Hello"))
// ("hELLO")
... | } | } | }
public static void main(String[] args) {
assert(flipCase(("")).equals(("")));
assert(flipCase(("Hello!")).equals(("hELLO!")));
assert(flipCase(("These violent delights have violent ends")).equals(("tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS")));
}
}
|
humaneval-HumanEval_137_compare_one.json-L76 | py | from typing import Union
def compare_one(a: Union[int, float, str], b: Union[int, float, str]) -> Union[int, float, str, None]:
"""
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values ... | return b | elif float(a_tmp) < b: | def check(candidate):
assert candidate(1, 2) == 2
assert candidate(1, 2.5) == 2.5
assert candidate(2, 3) == 3
assert candidate(5, 6) == 6
assert candidate(1, '2,3') == '2,3'
assert candidate('5,1', '6') == '6'
assert candidate('1', '2') == '2'
assert candidate('1', 1) == None
def test_c... |
humaneval-HumanEval_63_fibfib.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 {
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fib... | } | } | }
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_118_get_closest_vowel.json-L20 | py | def get_closest_vowel(word: str) -> str:
"""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 a... | return ''
for i in range(len(word) - 2, 0, -1):
if word[i] in 'aeiouAEIOU' and word[i-1] not in 'aeiouAEIOU' and word[i+1] not in 'aeiouAEIOU':
return word[i]
return ''
| if len(word) < 3: | def check(candidate):
assert candidate('yogurt') == 'u'
assert candidate('full') == 'u'
assert candidate('easy') == ''
assert candidate('eAsy') == ''
assert candidate('ali') == ''
assert candidate('bad') == 'a'
assert candidate('most') == 'o'
assert candidate('ab') == ''
assert candi... |
humaneval-HumanEval_49_modp.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 2^n modulo p (be aware of numerics).
// >>> modp((3l), (5l))
// (3l)
// >>> modp((1101l), (101l))
// (2l)
//... | } | }
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_56_correct_bracketing.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 {
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correc... | } else {
open--;
}
if (open < 0) {
return false;
}
}
return open == 0;
}
} | open++; | }
public static void main(String[] args) {
assert(correctBracketing(("<>")) == (true));
assert(correctBracketing(("<<><>>")) == (true));
assert(correctBracketing(("<><><<><>><>")) == (true));
assert(correctBracketing(("<><><<<><><>><>><<><><<>>>")) == (true));
assert(correctBracketing(("<<<>... |
humaneval-HumanEval_119_match_parens.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 an array array list of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
... | }
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";
else return "No";
}
} | if (c1 < 0) break; | }
public static void main(String[] args) {
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"()(", (String)")")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")", (String)")")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.a... |
humaneval-HumanEval_147_get_max_triples.json-L27 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given a positive integer n. You have to create an integer array array list a of length n.
// For each i (1 ≤ i ≤ n), the va... | if ((arrayList.get(i) + arrayList.get(j) + arrayList.get(k)) % 3 == 0) {
count++;
}
}
}
}
return count;
}
} | for (int k = j + 1; k < arrayList.size(); k++) { | }
public static void main(String[] args) {
assert(getMaxTriples((5l)) == (1l));
assert(getMaxTriples((6l)) == (4l));
assert(getMaxTriples((10l)) == (36l));
assert(getMaxTriples((100l)) == (53361l));
}
}
|
humaneval-HumanEval_1_separate_paren_groups.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 {
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into s... | temp.append(c);
} else if (c == ')') {
open_paren--;
temp.append(c);
if (open_paren == 0) {
output.add(temp.toString());
}
}
}
return output;
}
} | open_paren++; | }
public static void main(String[] args) {
assert(separateParenGroups(("(()()) ((())) () ((())()())")).equals((new ArrayList<String>(Arrays.asList((String)"(()())", (String)"((()))", (String)"()", (String)"((())()())")))));
assert(separateParenGroups(("() (()) ((())) (((())))")).equals((new ArrayList<St... |
humaneval-HumanEval_68_pluck.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 an array array list representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the ... | newArr.add((long)minIndex);
return newArr;
}
} | newArr.add(minValue); | }
public static void main(String[] args) {
assert(pluck((new ArrayList<Long>(Arrays.asList((long)4l, (long)2l, (long)3l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)1l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))).equals((new ArrayList<Long>(Arra... |
humaneval-HumanEval_135_can_arrange.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 {
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately pr... | }
return p;
}
} | } | }
public static void main(String[] args) {
assert(canArrange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)3l, (long)5l)))) == (3l));
assert(canArrange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)5l)))) == (-1l));
assert(canArrange((new ArrayList<L... |
humaneval-HumanEval_17_parse_music.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and r... | i += 1;
} else {
res.add((long)4l);
}
} else if (chars[i] == '.') {
if (i + 1 < chars.length && chars[i + 1] == '|') {
res.add((long)1l);
i += 1;
}
}
... | res.add((long)2l); | }
public static void main(String[] args) {
assert(parseMusic(("")).equals((new ArrayList<Long>(Arrays.asList()))));
assert(parseMusic(("o o o o")).equals((new ArrayList<Long>(Arrays.asList((long)4l, (long)4l, (long)4l, (long)4l)))));
assert(parseMusic((".| .| .| .|")).equals((new ArrayList<Long>(Arr... |
humaneval-HumanEval_121_solution.json-L23 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a non-empty array list of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// ... | return sum;
}
} | } | }
public static void main(String[] args) {
assert(solution((new ArrayList<Long>(Arrays.asList((long)5l, (long)8l, (long)7l, (long)1l)))) == (12l));
assert(solution((new ArrayList<Long>(Arrays.asList((long)3l, (long)3l, (long)3l, (long)3l, (long)3l)))) == (9l));
assert(solution((new ArrayList<Long>(A... |
humaneval-HumanEval_131_digits.json-L28 | js | //Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// >>> digits(1)
// 1
// >>> digits(4)
// 0
// >>> digits(235)
// 15
function digits(n){
if(!n){
return "error";
}
if(n < 0){
return "error";
}
var temp = 0;
va... | }
return prod;
}
| return 0; | const assert = require('node:assert');
function test() {
let candidate = digits;
assert.deepEqual(candidate(5),5);
assert.deepEqual(candidate(54),5);
assert.deepEqual(candidate(120),1);
assert.deepEqual(candidate(5014),5);
assert.deepEqual(candidate(98765),315);
assert.deepEqual(candidate(5576543),2625)... |
humaneval-HumanEval_75_is_multiply_prime.json-L21 | 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... | return true;
}else{
return false;
}
} | if(check.length == 3){ | 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_99_closest_integer.json-L21 | py | def closest_integer(value: str) -> int:
"""
Create a function that takes a value (string) representing a number
and returns the closest integer to it. If the number is equidistant
from two integers, round it away from zero.
Examples
>>> closest_integer('10')
10
>>> closest_integer('15.3... | return integer_val if abs(value - integer_val) < 0.5 else (integer_val + 1) if value > 0 else (integer_val - 1) | def check(candidate):
assert candidate('10') == 10
assert candidate('14.5') == 15
assert candidate('-15.5') == -16
assert candidate('15.3') == 15
assert candidate('0') == 0
def test_check():
check(closest_integer)
test_check()
| |
humaneval-HumanEval_124_valid_date.json-L32 | 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;
}
return true;
}
return false;
}
| }else if((month == 4 || month == 6 || month == 9 || month == 11) && (day < 1 || day > 30)){ | 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_152_compare.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 {
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you ... | }
} | return result; | }
public static void main(String[] args) {
assert(compare((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)1l))), (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)2l, (long)-2l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (... |
humaneval-HumanEval_116_sort_array.json-L14 | js | //In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// >>> sort_array([1, 5, 2, 3, 4])
// [1, 2, 3, 4, 5]
// >>> sort_array([-... | if (aBinary === bBinary) {
return a - b;
} else {
return aBinary - bBinary;
}
});
} | let bBinary = b.toString(2).split('').filter(el => el === '1').length; | const assert = require('node:assert');
function test() {
let candidate = sort_array;
assert.deepEqual(candidate([1, 5, 2, 3, 4]),[1, 2, 4, 3, 5]);
assert.deepEqual(candidate([-2, -3, -4, -5, -6]),[-4, -2, -6, -5, -3]);
assert.deepEqual(candidate([1, 0, 2, 3, 4]),[0, 1, 2, 4, 3]);
assert.deepEqual(candidate(... |
humaneval-HumanEval_55_fib.json-L22 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return n-th Fibonacci number.
// >>> fib((10l))
// (55l)
// >>> fib((1l))
// (1l)
// >>> fib((8l))
// (21l)
... | else {
return Problem.fib((n - 1)) + Problem.fib((n - 2));
}
}
} | } | }
public static void main(String[] args) {
assert(fib((10l)) == (55l));
assert(fib((1l)) == (1l));
assert(fib((8l)) == (21l));
assert(fib((11l)) == (89l));
assert(fib((12l)) == (144l));
}
}
|
humaneval-HumanEval_67_fruit_distribution.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 {
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fru... | } | }
public static void main(String[] args) {
assert(fruitDistribution(("5 apples and 6 oranges"), (19l)) == (8l));
assert(fruitDistribution(("5 apples and 6 oranges"), (21l)) == (10l));
assert(fruitDistribution(("0 apples and 1 oranges"), (3l)) == (2l));
assert(fruitDistribution(("1 apples and 0 o... | |
humaneval-HumanEval_94_skjkasdkd.json-L17 | js | //You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// >>> skjkasdkd([0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3])
// 10
// >>> skjkasdkd([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1])
// 25
// >>> skj... | if (n<2) return false;
for (let i=2; i<=Math.sqrt(n); i++){
if (n%i==0) return false;
}
return true;
}
let max = Math.max(...lst.filter(x=>prime(x)));
let digits = String(max).split('');
let sum = 0;
for (let i=0; i<digits.length; i++){
sum += Numb... | function prime(n){ | const assert = require('node:assert');
function test() {
let candidate = skjkasdkd;
assert.deepEqual(candidate([0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]),10);
assert.deepEqual(candidate([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]),25);
assert.deepEqual(candidate(... |
humaneval-HumanEval_17_parse_music.json-L35 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and r... | return res;
}
} | } | }
public static void main(String[] args) {
assert(parseMusic(("")).equals((new ArrayList<Long>(Arrays.asList()))));
assert(parseMusic(("o o o o")).equals((new ArrayList<Long>(Arrays.asList((long)4l, (long)4l, (long)4l, (long)4l)))));
assert(parseMusic((".| .| .| .|")).equals((new ArrayList<Long>(Arr... |
humaneval-HumanEval_99_closest_integer.json-L21 | js | //Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// >>> closest_integer("10")
// 10
// >>> closest_integer("15.3")
// 15
// Note:
// Rounding away from zero means that i... | }else{
if(value - Math.floor(value) > -0.5){
return Math.floor(value);
}else{
return Math.ceil(value);
}
}
}
| } | const assert = require('node:assert');
function test() {
let candidate = closest_integer;
assert.deepEqual(candidate("10"),10);
assert.deepEqual(candidate("14.5"),15);
assert.deepEqual(candidate("-15.5"),-16);
assert.deepEqual(candidate("15.3"),15);
assert.deepEqual(candidate("0"),0);
}
test(); |
humaneval-HumanEval_135_can_arrange.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 {
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately pr... | } | } | }
public static void main(String[] args) {
assert(canArrange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)3l, (long)5l)))) == (3l));
assert(canArrange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)5l)))) == (-1l));
assert(canArrange((new ArrayList<L... |
humaneval-HumanEval_43_pairs_sum_to_zero.json-L21 | py | from typing import List
def pairs_sum_to_zero(l: List[int]) -> bool:
"""
pairs_sum_to_zero takes a list of integers as an input.
it returns True if there are two distinct elements in the list that
sum to zero, and False otherwise.
>>> pairs_sum_to_zero([1, 3, 5, 0])
False
>>> pairs_sum_to_z... | return True
return False
| if x+y == 0 and x != y: | def check(candidate):
assert candidate([1, 3, 5, 0]) == False
assert candidate([1, 3, -2, 1]) == False
assert candidate([1, 2, 3, 7]) == False
assert candidate([2, 4, -5, 3, 5, 7]) == True
assert candidate([1]) == False
assert candidate([-3, 9, -1, 3, 2, 30]) == True
assert candidate([-3, 9,... |
humaneval-HumanEval_51_remove_vowels.json-L15 | py | def remove_vowels(text: str) -> str:
"""
remove_vowels is a function that takes string and returns string without vowels.
>>> remove_vowels('')
''
>>> remove_vowels('abcdef')
'bcdf'
>>> remove_vowels('aaaaa')
''
>>> remove_vowels('aaBAA')
'B'
>>> remove_vowels('zbcd')
'zb... | return ''.join(filter(lambda x: x not in vowels, text))
| vowels = 'aeiouAEIOU' | def check(candidate):
assert candidate('') == ''
assert candidate('abcdef\nghijklm') == 'bcdf\nghjklm'
assert candidate('fedcba') == 'fdcb'
assert candidate('eeeee') == ''
assert candidate('acBAA') == 'cB'
assert candidate('EcBOO') == 'cB'
assert candidate('ybcd') == 'ybcd'
def test_check()... |
humaneval-HumanEval_162_string_to_md5.json-L7 | js | //Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return undefined.
// >>> string_to_md5("Hello world")
// "3e25960a79dbc69b674cd4ec67a72c62"
function string_to_md5(text){
if(text === ''){ | }
return require('crypto').createHash('md5').update(text).digest('hex');
}
| return undefined; | const assert = require('node:assert');
function test() {
let candidate = string_to_md5;
assert.deepEqual(candidate("Hello world"),"3e25960a79dbc69b674cd4ec67a72c62");
assert.deepEqual(candidate(""),undefined);
assert.deepEqual(candidate("A B C"),"0ef78513b0cb8cef12743f5aeb35f888");
assert.deepEqual(candidat... |
humaneval-HumanEval_158_find_max.json-L17 | py | from typing import List
def find_max(words: List[str]) -> str:
"""Write a function that accepts a list of strings.
The list contains different words. Return the word with maximum number
of unique characters. If multiple strings have maximum number of unique
characters, return the one which comes first ... | for word in words:
unique_num = len(set(word))
if unique_num > max_num:
max_num = unique_num
max_word = word
elif unique_num == max_num:
if word < max_word:
max_word = word
return max_word
| max_word = "" | def check(candidate):
assert candidate(['name', 'of', 'string']) == 'string'
assert candidate(['name', 'enam', 'game']) == 'enam'
assert candidate(['aaaaaaa', 'bb', 'cc']) == 'aaaaaaa'
assert candidate(['abc', 'cba']) == 'abc'
assert candidate(['play', 'this', 'game', 'of', 'footbott']) == 'footbott... |
humaneval-HumanEval_67_fruit_distribution.json-L22 | py | def fruit_distribution(s: str, n: int) -> int:
"""
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 ora... | pass
return n - sum(fruits)
| except: | def check(candidate):
assert candidate('5 apples and 6 oranges', 19) == 8
assert candidate('5 apples and 6 oranges', 21) == 10
assert candidate('0 apples and 1 oranges', 3) == 2
assert candidate('1 apples and 0 oranges', 3) == 2
assert candidate('2 apples and 3 oranges', 100) == 95
assert candid... |
humaneval-HumanEval_124_valid_date.json-L28 | 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... | }
}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)){
return false;
}
... | return false; | 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_7_filter_by_substring.json-L8 | js | //Filter an input array of strings only for ones that contain given substring
// >>> filter_by_substring([], "a")
// []
// >>> filter_by_substring(["abc", "bacd", "cde", "array"], "a")
// ["abc", "bacd", "array"]
function filter_by_substring(strings, substring){
var filtered = []; | if(strings[i].includes(substring)){
filtered.push(strings[i]);
}
}
return filtered;
} | for(var i = 0; i < strings.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = filter_by_substring;
assert.deepEqual(candidate([], "john"),[]);
assert.deepEqual(candidate(["xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"], "xxx"),["xxx", "xxxAAA", "xxx"]);
assert.deepEqual(candidate(["xxx", "asd", "aaaxxy", "john d... |
humaneval-HumanEval_154_cycpattern_check.json-L16 | js | //You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// >>> cycpattern_check("abcd", "abd")
// false
// >>> cycpattern_check("hello", "ell")
// true
// >>> cycpattern_check("whassup", "psus")
// false
// >>> cycpattern_check("abab", "baa")
// true
... | result = result || a.includes(b);
b = b.slice(1) + b[0];
}
return result;
}
| for(var i = 0; i < b.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = cycpattern_check;
assert.deepEqual(candidate("xyzw", "xyw"),false);
assert.deepEqual(candidate("yello", "ell"),true);
assert.deepEqual(candidate("whattup", "ptut"),false);
assert.deepEqual(candidate("efef", "fee"),true);
assert.deepE... |
humaneval-HumanEval_43_pairs_sum_to_zero.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 {
// pairs_sum_to_zero takes an array array list of integers as an input.
// it returns true if there are two distinct elements in the a... | for (int j = i + 1; j < l.size(); j++) {
if (l.get(i) + l.get(j) == 0) {
return true;
}
}
}
return false;
}
} | for (int i = 0; i < l.size(); i++) { | }
public static void main(String[] args) {
assert(pairsSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)0l)))) == (false));
assert(pairsSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)-2l, (long)1l)))) == (false));
assert(pairsSumToZero((new Arr... |
humaneval-HumanEval_6_parse_nested_parens.json-L18 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group... | long current_depth = 0;
for (char c : paren.toCharArray()) {
if (c == '(') {
current_depth += 1;
max_depth = Math.max(max_depth, current_depth);
} else if (c == ')') {
current_depth -= 1;
... | long max_depth = 0; | }
public static void main(String[] args) {
assert(parseNestedParens(("(()()) ((())) () ((())()())")).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)1l, (long)3l)))));
assert(parseNestedParens(("() (()) ((())) (((())))")).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, ... |
humaneval-HumanEval_23_strlen.json-L10 | py | def strlen(string: str) -> int:
""" Return length of given string
>>> strlen('')
0
>>> strlen('abc')
3
"""
length = 0
for char in string: | return length
| length += 1 | def check(candidate):
assert candidate('') == 0
assert candidate('x') == 1
assert candidate('asdasnakj') == 9
def test_check():
check(strlen)
test_check()
|
humaneval-HumanEval_137_compare_one.json-L71 | py | from typing import Union
def compare_one(a: Union[int, float, str], b: Union[int, float, str]) -> Union[int, float, str, None]:
"""
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values ... | elif isinstance(a, str) and isinstance(b, float):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b | return None | def check(candidate):
assert candidate(1, 2) == 2
assert candidate(1, 2.5) == 2.5
assert candidate(2, 3) == 3
assert candidate(5, 6) == 6
assert candidate(1, '2,3') == '2,3'
assert candidate('5,1', '6') == '6'
assert candidate('1', '2') == '2'
assert candidate('1', 1) == None
def test_c... |
humaneval-HumanEval_141_file_name_check.json-L31 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and return... | }
String name = tokens[0];
int count = 0;
for (int i = 0; i < name.length(); i++) {
if (Character.isDigit(name.charAt(i))) {
count++;
}
}
if (count > 3) {
return result;
}
if (name.length() == 0) {
... | return result; | }
public static void main(String[] args) {
assert(fileNameCheck(("example.txt")).equals(("Yes")));
assert(fileNameCheck(("1example.dll")).equals(("No")));
assert(fileNameCheck(("s1sdf3.asd")).equals(("No")));
assert(fileNameCheck(("K.dll")).equals(("Yes")));
assert(fileNameCheck(("MY16FILE3.... |
humaneval-HumanEval_112_reverse_delete.json-L24 | js | //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 an array containing the result string and true/fa... | } | const assert = require('node:assert');
function test() {
let candidate = reverse_delete;
assert.deepEqual(candidate("abcde", "ae"),["bcd", false]);
assert.deepEqual(candidate("abcdef", "b"),["acdef", false]);
assert.deepEqual(candidate("abcdedcba", "ab"),["cdedc", true]);
assert.deepEqual(candidate("dwik", ... | |
humaneval-HumanEval_141_file_name_check.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 {
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and return... | if (!Character.isLetter(name.charAt(0))) {
return result;
}
return "Yes";
}
} | } | }
public static void main(String[] args) {
assert(fileNameCheck(("example.txt")).equals(("Yes")));
assert(fileNameCheck(("1example.dll")).equals(("No")));
assert(fileNameCheck(("s1sdf3.asd")).equals(("No")));
assert(fileNameCheck(("K.dll")).equals(("Yes")));
assert(fileNameCheck(("MY16FILE3.... |
humaneval-HumanEval_142_sum_squares.json-L20 | py | from typing import List
def sum_squares(lst: List[int]) -> int:
""""
This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a
multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3.... | lst[index] = lst[index] ** 3
return sum(lst) | elif index % 4 == 0: | def check(candidate):
assert candidate([1, 2, 3]) == 6
assert candidate([1, 4, 9]) == 14
assert candidate([]) == 0
assert candidate([1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9
assert candidate([-1, -1, -1, -1, -1, -1, -1, -1, -1]) == -3
assert candidate([0]) == 0
assert candidate([-1, -5, 2, -1, -5]) ... |
humaneval-HumanEval_74_total_match.json-L20 | js | //Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// >>> total_match([], [])
// []
// >>> total_match(["hi", "ad... | for(let item of lst2){
sum_lst2 += item.length;
}
if(sum_lst1 > sum_lst2){
return lst2;
}
else{
return lst1;
}
}
| } | const assert = require('node:assert');
function test() {
let candidate = total_match;
assert.deepEqual(candidate([], []),[]);
assert.deepEqual(candidate(["hi", "admin"], ["hi", "hi"]),["hi", "hi"]);
assert.deepEqual(candidate(["hi", "admin"], ["hi", "hi", "admin", "project"]),["hi", "admin"]);
assert.deepEq... |
humaneval-HumanEval_115_max_fill.json-L36 | py | from typing import List
def max_fill(grid: List[List[int]], capacity: int) -> int:
"""
You are given a rectangular grid of wells. Each row represents a single well,
and each 1 in a row represents a single unit of water.
Each well has a corresponding bucket that can be used to extract water from it,
... | return times | def check(candidate):
assert candidate([[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], 1) == 6
assert candidate([[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], 2) == 5
assert candidate([[0, 0, 0], [0, 0, 0]], 5) == 0
assert candidate([[1, 1, 1, 1], [1, 1, 1, 1]], 2) == 4
assert candidate([[1, ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.