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_26_remove_duplicates.json-L9 | js | //From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// >>> remove_duplicates([1, 2, 3, 2, 4])
// [1, 3, 4]
function remove_duplicates(numbers){
let result = [];
numbers.forEach(function(value){
if(numbers.indexOf(value) ===... | }
});
return result;
}
| result.push(value); | const assert = require('node:assert');
function test() {
let candidate = remove_duplicates;
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([1, 2, 3, 4]),[1, 2, 3, 4]);
assert.deepEqual(candidate([1, 2, 3, 2, 4, 3, 5]),[1, 4, 5]);
}
test(); |
humaneval-HumanEval_37_sort_even.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 {
// 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,... | }
return res;
}
} | index++; | }
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_131_digits.json-L26 | 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... | if(odd){
return 0;
}
return prod;
}
| } | 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_93_encode.json-L21 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
... | for (int i = 0; i < arr.length; i++) {
if (Arrays.binarySearch(vowels, arr[i]) > -1) {
arr[i] = (char) (arr[i] + 2);
}
if (Character.isUpperCase(arr[i])) {
arr[i] = Character.toLowerCase(arr[i]);
} else {
arr[i] = Ch... | char[] vowels = "AEIOUaeiou".toCharArray(); | }
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_9_rolling_max.json-L7 | js | //From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// >>> rolling_max([1, 2, 3, 2, 3, 4, 2])
// [1, 2, 3, 3, 3, 4, 4]
function rolling_max(numbers){
let max = []; | for(let i = 0; i < numbers.length; i++){
if(tempMax < numbers[i]){
tempMax = numbers[i];
}
max.push(tempMax);
}
return max;
}
| let tempMax = 0; | const assert = require('node:assert');
function test() {
let candidate = rolling_max;
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([1, 2, 3, 4]),[1, 2, 3, 4]);
assert.deepEqual(candidate([4, 3, 2, 1]),[4, 4, 4, 4]);
assert.deepEqual(candidate([3, 2, 3, 100, 3]),[3, 3, 3, 100, 100]);
}
tes... |
humaneval-HumanEval_36_fizz_buzz.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 the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// >>> fizzBuzz((50l))
... | }
}
return res;
}
} | } | }
public static void main(String[] args) {
assert(fizzBuzz((50l)) == (0l));
assert(fizzBuzz((78l)) == (2l));
assert(fizzBuzz((79l)) == (3l));
assert(fizzBuzz((100l)) == (3l));
assert(fizzBuzz((200l)) == (6l));
assert(fizzBuzz((4000l)) == (192l));
assert(fizzBuzz((10000l)) == (639l));... |
humaneval-HumanEval_59_largest_prime_factor.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 largest prime factor of n. Assume n > 1 and is not a prime.
// >>> largestPrimeFactor((13195l))
// (29l)
// >>> ... | primes.add(i);
x /= i;
i--;
}
}
if (x > 1) {
primes.add(x);
}
return primes.get(primes.size() - 1);
}
} | if (x % i == 0) { | }
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_25_factorize.json-L20 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return array list of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be array l... | while (n % d == 0) {
factors.add(d);
n /= d;
}
}
if (n > 1)
factors.add(n);
return factors;
}
} | for (long d = 2; d*d <= n; d++) { | }
public static void main(String[] args) {
assert(factorize((2l)).equals((new ArrayList<Long>(Arrays.asList((long)2l)))));
assert(factorize((4l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)2l)))));
assert(factorize((8l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)2l, (l... |
humaneval-HumanEval_146_specialFilter.json-L17 | py | from typing import List
def specialFilter(nums: List[int]) -> int:
"""Write a function that takes an array of numbers as input and returns
the number of elements in the array that are greater than 10 and both
first and last digits of a number are odd (1, 3, 5, 7, 9).
For example:
>>> specialFilte... | rev = int(str(num)[::-1])
if num % 2 != 0 and rev % 2 != 0:
count += 1
return count
| else: | def check(candidate):
assert candidate([5, -2, 1, -5]) == 0
assert candidate([15, -73, 14, -15]) == 1
assert candidate([33, -2, -3, 45, 21, 109]) == 2
assert candidate([43, -12, 93, 125, 121, 109]) == 4
assert candidate([71, -2, -33, 75, 21, 19]) == 3
assert candidate([1]) == 0
assert candid... |
humaneval-HumanEval_139_special_factorial.json-L16 | py | def special_factorial(n: int) -> int:
"""The Brazilian factorial is defined as:
brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
where n > 0
For example:
>>> special_factorial(4)
288
The function will receive an integer as input and should return the special
factorial of this i... | return n * factorial(n-1)
if n <= 1:
return 1
else:
return n * special_factorial(n-1) * factorial(n-1)
| else: | def check(candidate):
assert candidate(4) == 288
assert candidate(5) == 34560
assert candidate(7) == 125411328000
assert candidate(1) == 1
def test_check():
check(special_factorial)
test_check()
|
humaneval-HumanEval_146_specialFilter.json-L14 | py | from typing import List
def specialFilter(nums: List[int]) -> int:
"""Write a function that takes an array of numbers as input and returns
the number of elements in the array that are greater than 10 and both
first and last digits of a number are odd (1, 3, 5, 7, 9).
For example:
>>> specialFilte... | if num < 10:
continue
else:
rev = int(str(num)[::-1])
if num % 2 != 0 and rev % 2 != 0:
count += 1
return count
| for num in nums: | def check(candidate):
assert candidate([5, -2, 1, -5]) == 0
assert candidate([15, -73, 14, -15]) == 1
assert candidate([33, -2, -3, 45, 21, 109]) == 2
assert candidate([43, -12, 93, 125, 121, 109]) == 4
assert candidate([71, -2, -33, 75, 21, 19]) == 3
assert candidate([1]) == 0
assert candid... |
humaneval-HumanEval_122_add_elements.json-L17 | 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... | } | 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_13_greatest_common_divisor.json-L14 | js | //Return a greatest common divisor of two integers a and b
// >>> greatest_common_divisor(3, 5)
// 1
// >>> greatest_common_divisor(25, 15)
// 5
function greatest_common_divisor(a, b){
let max = Math.max(a, b)
let min = Math.min(a, b)
if (max % min == 0) {
return min
} else {
return greatest_common_divisor(min,... | } | const assert = require('node:assert');
function test() {
let candidate = greatest_common_divisor;
assert.deepEqual(candidate(3, 7),1);
assert.deepEqual(candidate(10, 15),5);
assert.deepEqual(candidate(49, 14),7);
assert.deepEqual(candidate(144, 60),12);
}
test(); | |
humaneval-HumanEval_95_check_dict_case.json-L34 | 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;
}
}
else if (case_type == 0){
if (key != key.toLowerCase()){
return false;
}
}
}
else{
return false;
}
}
return true;
} | if (key != key.toUpperCase()){ | 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_118_get_closest_vowel.json-L29 | js | //You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given stri... | i--;
}
if (result.length === 0) {
return ""
} else {
return result[0];
}
}
} | } | const assert = require('node:assert');
function test() {
let candidate = get_closest_vowel;
assert.deepEqual(candidate("yogurt"),"u");
assert.deepEqual(candidate("full"),"u");
assert.deepEqual(candidate("easy"),"");
assert.deepEqual(candidate("eAsy"),"");
assert.deepEqual(candidate("ali"),"");
assert.de... |
humaneval-HumanEval_124_valid_date.json-L30 | 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 == 4 || month == 6 || month == 9 || month == 11) && (day < 1 || day > 30)){
return false;
}
return true;
}
return false;
}
| }else if((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && (day < 1 || day > 31)){ | 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_141_file_name_check.json-L26 | py | def file_name_check(file_name: str) -> str:
"""Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is valid, and returns 'No' otherwise.
A file's name is considered to be valid if and only if all the following conditions
are met:
- There shoul... | return 'No'
s_name = file_name.split('.')[0]
e_name = file_name.split('.')[1]
if not s_name or not e_name or not s_name[0].isalpha():
return 'No'
if e_name not in ['txt', 'exe', 'dll']:
return 'No'
return 'Yes'
| if s_count > 3 or e_count != 1: | def check(candidate):
assert candidate('example.txt') == 'Yes'
assert candidate('1example.dll') == 'No'
assert candidate('s1sdf3.asd') == 'No'
assert candidate('K.dll') == 'Yes'
assert candidate('MY16FILE3.exe') == 'Yes'
assert candidate('His12FILE94.exe') == 'No'
assert candidate('_Y.txt') ... |
humaneval-HumanEval_37_sort_even.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 {
// 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,... | Collections.sort(evenIndexed);
index = 0;
for (Long num : l) {
if (index % 2 == 0) {
res.add(evenIndexed.get(0));
evenIndexed.remove(0);
} else {
res.add(num);
}
index++;
}
return res;... | } | }
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_96_count_up_to.json-L27 | py | from typing import List
def count_up_to(n: int) -> List[int]:
"""Implement a function that takes an non-negative integer and returns an array of the first n
integers that are prime numbers and less than n.
for example:
>>> count_up_to(5)
[2, 3]
>>> count_up_to(11)
[2, 3, 5, 7]
>>> count... | break
if is_prime:
result.append(number)
return result
| is_prime = False | def check(candidate):
assert candidate(5) == [2, 3]
assert candidate(6) == [2, 3, 5]
assert candidate(7) == [2, 3, 5]
assert candidate(10) == [2, 3, 5, 7]
assert candidate(0) == []
assert candidate(22) == [2, 3, 5, 7, 11, 13, 17, 19]
assert candidate(1) == []
assert candidate(18) == [2, ... |
humaneval-HumanEval_81_numerical_letter_grade.json-L50 | 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.0){
grades_array.push("D+");
}
else if (grades[i] > 0.7){
grades_array.push("D");
}
else if (grades[i] > 0.0){
grades_array.push("D-");
}
else if (grades[i] =... | else if (grades[i] > 1.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_124_valid_date.json-L22 | 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... | var year = parseInt(date_arr[2]);
if(month < 1 || month > 12){
return false;
}else if(month == 2){
if(day < 1 || day > 29){
return false;
}
}else if((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || m... | var day = parseInt(date_arr[1]); | 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_41_car_race_collision.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 {
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different ... | } | } | }
public static void main(String[] args) {
assert(carRaceCollision((2l)) == (4l));
assert(carRaceCollision((3l)) == (9l));
assert(carRaceCollision((4l)) == (16l));
assert(carRaceCollision((8l)) == (64l));
assert(carRaceCollision((10l)) == (100l));
}
}
|
humaneval-HumanEval_104_unique_digits.json-L22 | 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... | for i in s:
x.remove(i)
return sorted(x)
| temp=temp//10 | 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_139_special_factorial.json-L15 | py | def special_factorial(n: int) -> int:
"""The Brazilian factorial is defined as:
brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
where n > 0
For example:
>>> special_factorial(4)
288
The function will receive an integer as input and should return the special
factorial of this i... | else:
return n * factorial(n-1)
if n <= 1:
return 1
else:
return n * special_factorial(n-1) * factorial(n-1)
| return 1 | def check(candidate):
assert candidate(4) == 288
assert candidate(5) == 34560
assert candidate(7) == 125411328000
assert candidate(1) == 1
def test_check():
check(special_factorial)
test_check()
|
humaneval-HumanEval_156_int_to_mini_roman.json-L51 | 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 <=... | if (num >= 40) {
res += "xl";
num -= 40;
}
while (num >= 10) {
res += "x";
num -= 10;
}
if (num >= 9) {
res += "ix";
num -= 9;
}
if (num >= 5) {
res += "v";
num -= 5;
... | } | }
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_151_double_the_difference.json-L14 | js | //Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// >>> double_the_difference([1, 3, 2, 0])
// 10
// >>> double_the_difference([-1, -2, 0])
// 0
// >>> double_the_difference([9, -2])
// 81
// >>> double_the_difference([... | if(lst[i] % 2 == 1 && lst[i] > 0){
sum += lst[i] ** 2;
}
}
return sum;
}
| for (var i = 0; i < lst.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = double_the_difference;
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([5.0, 4.0]),25);
assert.deepEqual(candidate([0.1, 0.2, 0.3]),0);
assert.deepEqual(candidate([-10.0, -20.0, -30.0]),0);
assert.deepEqual(candidate([-... |
humaneval-HumanEval_117_select_words.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 {
// 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... | }
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_128_prod_signs.json-L30 | 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... | elif num < 0:
sign_arr.append(-1)
else:
sign_arr.append(0)
return sum(map(abs, arr)) * product(sign_arr) | sign_arr.append(1) | 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_99_closest_integer.json-L27 | 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... | }
}
| } | 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_146_specialFilter.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 {
// Write a function that takes an array array list of numbers as input and returns
// the number of elements in the array array list ... | long[] digits = getDigits(n);
return digits[0];
}
public long getLastDigit(long n) {
long[] digits = getDigits(n);
return digits[digits.length - 1];
}
public long[] getDigits(long n) {
ArrayLi... | public long getFirstDigit(long n) { | }
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_137_compare_one.json-L23 | 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
//... | if (a[0] > b){
return a;
} else if (a[0] < b){
return b;
} else {
return undefined;
}
}
else if (typeof a === "number" && typeof b === "string"){
if (a > b[0]){
return a;
} else if (a < b[0]){
return b;
} else {
return undefined;
}
}
}
| else if (typeof a === "string" && typeof b === "number"){ | 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_7_filter_by_substring.json-L16 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Filter an input array list of strings only for ones that contain given substring
// >>> filterBySubstring((new ArrayList<String>(Ar... | } | } | }
public static void main(String[] args) {
assert(filterBySubstring((new ArrayList<String>(Arrays.asList())), ("john")).equals((new ArrayList<String>(Arrays.asList()))));
assert(filterBySubstring((new ArrayList<String>(Arrays.asList((String)"xxx", (String)"asd", (String)"xxy", (String)"john doe", (Strin... |
humaneval-HumanEval_33_sort_third.json-L28 | js | //This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// >>> sort_third([1, 2, 3])
// [1, 2, 3]
//... | return x;
} | } | const assert = require('node:assert');
function test() {
let candidate = sort_third;
assert.deepEqual(candidate([5, 6, 3, 4, 8, 9, 2]),[2, 6, 3, 4, 8, 9, 5]);
assert.deepEqual(candidate([5, 8, 3, 4, 6, 9, 2]),[2, 8, 3, 4, 6, 9, 5]);
assert.deepEqual(candidate([5, 6, 9, 4, 8, 3, 2]),[2, 6, 9, 4, 8, 3, 5]);
a... |
humaneval-HumanEval_147_get_max_triples.json-L28 | 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... | j = i + 1
k = j + 1
return count
| i += 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_27_flip_case.json-L14 | js | //For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// >>> flip_case("Hello")
// "hELLO"
function flip_case(string){
var result = "";
for(var i = 0; i < string.length; i++){
if(string[i] == string[i].toUpperCase()){
result += string[i].toLowerCase();
}else{
result += str... | } | const assert = require('node:assert');
function test() {
let candidate = flip_case;
assert.deepEqual(candidate(""),"");
assert.deepEqual(candidate("Hello!"),"hELLO!");
assert.deepEqual(candidate("These violent delights have violent ends"),"tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS");
}
test(); | |
humaneval-HumanEval_17_parse_music.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 {
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and r... | if (chars[i] == 'o') {
if (i + 1 < chars.length && chars[i + 1] == '|') {
res.add((long)2l);
i += 1;
} else {
res.add((long)4l);
}
} else if (chars[i] == '.') {
if (i + 1 <... | for (int i = 0; i < chars.length; i++) { | }
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_68_pluck.json-L37 | py | from typing import List
def pluck(arr: List[int]) -> List[int]:
"""
"Given an array representing a branch of a tree that has non-negative integer nodes
your task is to pluck one of the nodes and return it.
The plucked node should be the node with the smallest even value.
If multiple nodes with the ... | return []
evens = [e for e in arr if e % 2 == 0]
if len(evens) == 0:
return []
return [min(evens), arr.index(min(evens))]
| if len(arr) == 0: | def check(candidate):
assert candidate([4, 2, 3]) == [2, 1]
assert candidate([1, 2, 3]) == [2, 1]
assert candidate([]) == []
assert candidate([5, 0, 3, 0, 4, 2]) == [0, 1]
assert candidate([1, 2, 3, 0, 5, 3]) == [0, 3]
assert candidate([5, 4, 8, 4, 8]) == [4, 1]
assert candidate([7, 6, 7, 1]... |
humaneval-HumanEval_4_mean_absolute_deviation.json-L13 | py | from typing import List
def mean_absolute_deviation(numbers: List[float]) -> float:
""" For a given list of input numbers, calculate Mean Absolute Deviation
around the mean of this dataset.
Mean Absolute Deviation is the average absolute difference between each
element and a centerpoint (mean in this c... | return sum(absolute_deviations) / len(absolute_deviations)
print(mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])) | absolute_deviations = [abs(x - mean) for x in numbers] | def check(candidate):
assert candidate([1.0, 2.0]) == 0.5
assert candidate([1.0, 2.0, 3.0, 4.0]) == 1.0
assert candidate([1.0, 2.0, 3.0, 4.0, 5.0]) == 1.2
def test_check():
check(mean_absolute_deviation)
test_check()
|
humaneval-HumanEval_1_separate_paren_groups.json-L23 | 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... | return groups;
}
| } | const assert = require('node:assert');
function test() {
let candidate = separate_paren_groups;
assert.deepEqual(candidate("(()()) ((())) () ((())()())"),["(()())", "((()))", "()", "((())()())"]);
assert.deepEqual(candidate("() (()) ((())) (((())))"),["()", "(())", "((()))", "(((())))"]);
assert.deepEqual(can... |
humaneval-HumanEval_17_parse_music.json-L15 | 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 === 'o|'){
song.push(2);
}else if(s === '.|'){
song.push(1);
}
});
return song;
}
| song.push(4); | 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_21_rescale_to_unit.json-L12 | js | //Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// >>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0])
// [0.0, 0.25, 0.5, 0.75, 1.0]
function rescale_to_unit(numbers){
var min = Math.min.apply(Math, n... | return unit;
}
| } | const assert = require('node:assert');
function test() {
let candidate = rescale_to_unit;
assert.deepEqual(candidate([2.0, 49.9]),[0.0, 1.0]);
assert.deepEqual(candidate([100.0, 49.9]),[1.0, 0.0]);
assert.deepEqual(candidate([1.0, 2.0, 3.0, 4.0, 5.0]),[0.0, 0.25, 0.5, 0.75, 1.0]);
assert.deepEqual(candidate... |
humaneval-HumanEval_161_solve.json-L25 | js | //You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// >>> solve("1234")
// "4321"
// >>> solve("ab")
// "AB"
// >>... | return s.split('').reverse().join('');
}
| } | const assert = require('node:assert');
function test() {
let candidate = solve;
assert.deepEqual(candidate("AsDf"),"aSdF");
assert.deepEqual(candidate("1234"),"4321");
assert.deepEqual(candidate("ab"),"AB");
assert.deepEqual(candidate("#a@C"),"#A@c");
assert.deepEqual(candidate("#AsdfW^45"),"#aSDFw^45");
... |
humaneval-HumanEval_19_sort_numbers.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 is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', '... | });
return String.join(" ", split);
}
} | } | }
public static void main(String[] args) {
assert(sortNumbers(("")).equals(("")));
assert(sortNumbers(("three")).equals(("three")));
assert(sortNumbers(("three five nine")).equals(("three five nine")));
assert(sortNumbers(("five zero four seven nine eight")).equals(("zero four five seven eight n... |
humaneval-HumanEval_120_maximum.json-L21 | js | //Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// >>> maximum([-3, -4, 5], 3)
// [-4, -3, 5]
// Example 2:
// >>> maximum([4, -4, 4], 2)
// [4, 4]
// Example 3:
// >>> maximum([-3, 2, 1, 2, -1, -2, 1], 1)
// [2]
// Note:
... | } | const assert = require('node:assert');
function test() {
let candidate = maximum;
assert.deepEqual(candidate([-3, -4, 5], 3),[-4, -3, 5]);
assert.deepEqual(candidate([4, -4, 4], 2),[4, 4]);
assert.deepEqual(candidate([-3, 2, 1, 2, -1, -2, 1], 1),[2]);
assert.deepEqual(candidate([123, -123, 20, 0, 1, 2, -3],... | |
humaneval-HumanEval_65_circular_shift.json-L14 | py | def circular_shift(x: int, shift: int) -> str:
"""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'
"""
temp... | return ''.join(temp[-shift:] + temp[:-shift]) | def check(candidate):
assert candidate(100, 2) == '001'
assert candidate(12, 2) == '12'
assert candidate(97, 8) == '79'
assert candidate(12, 1) == '21'
assert candidate(11, 101) == '11'
def test_check():
check(circular_shift)
test_check()
| |
humaneval-HumanEval_34_unique.json-L7 | js | //Return sorted unique elements in an array
// >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])
// [0, 2, 3, 5, 9, 123]
function unique(l){
return l.filter(function(e, i, a){
return a.indexOf(e) === i; | }
| }).sort(function(a, b){return a-b}); | const assert = require('node:assert');
function test() {
let candidate = unique;
assert.deepEqual(candidate([5, 3, 5, 2, 3, 3, 9, 0, 123]),[0, 2, 3, 5, 9, 123]);
}
test(); |
humaneval-HumanEval_1_separate_paren_groups.json-L12 | py | from typing import List
def separate_paren_groups(paren_string: str) -> List[str]:
""" 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 list of those.
Separate groups are balanced (each open brace ... | group = ''
open_count = 0
for c in paren_string:
if c == '(':
open_count += 1
elif c == ')':
open_count -= 1
group += c
if open_count == 0:
groups.append(group)
group = ''
return groups
| groups = [] | def check(candidate):
assert candidate('(()()) ((())) () ((())()())') == ['(()())', '((()))', '()', '((())()())']
assert candidate('() (()) ((())) (((())))') == ['()', '(())', '((()))', '(((())))']
assert candidate('(()(())((())))') == ['(()(())((())))']
assert candidate('( ) (( )) (( )( ))') == ['()', ... |
humaneval-HumanEval_152_compare.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 {
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you ... | for (int i = 0; i < game.size(); i++) {
if (game.get(i) != guess.get(i)) {
result.add(Math.abs(game.get(i) - guess.get(i)));
} else {
result.add((long)0);
}
}
return result;
}
} | ArrayList<Long> result = new ArrayList<Long>(); | }
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_57_monotonic.json-L9 | js | //Return true is array elements are monotonically increasing or decreasing.
// >>> monotonic([1, 2, 4, 20])
// true
// >>> monotonic([1, 20, 4, 10])
// false
// >>> monotonic([4, 1, 0, -10])
// true
function monotonic(l){
| return true;
}
if(l[0] < l[1]){
for(var i = 1; i < l.length - 1; i++){
if(l[i] > l[i + 1]){
return false;
}
}
}
else{
for(var i = 1; i < l.length - 1; i++){
if(l[i] < l[i + 1]){
return false;
... | if(l.length <= 1){ | const assert = require('node:assert');
function test() {
let candidate = monotonic;
assert.deepEqual(candidate([1, 2, 4, 10]),true);
assert.deepEqual(candidate([1, 2, 4, 20]),true);
assert.deepEqual(candidate([1, 20, 4, 10]),false);
assert.deepEqual(candidate([4, 1, 0, -10]),true);
assert.deepEqual(candid... |
humaneval-HumanEval_129_minPath.json-L44 | 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... | x = i;
y = j;
}
}
}
if(x > 0){
neighbours.push(grid[x - 1][y]);
}
if(x < n - 1){
neighbours.push(grid[x + 1][y]);
}
if(y > 0){
neighbours.push(grid[x][y - 1]);
... | if(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_99_closest_integer.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 {
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equi... | } | } | }
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_113_odd_count.json-L18 | py | from typing import List
def odd_count(lst: List[str]) -> List[str]:
"""Given a list of strings, where each string consists of only digits, return a list.
Each element i of the output should be "the number of odd elements in the
string i of the input." where all the i's should be replaced by the number
... | count += 1
output.append(f"the number of odd elements {count}n the str{count}ng {count} of the {count}nput.")
return output
| if int(lst[i][j]) % 2 != 0: | def check(candidate):
assert candidate(['1234567']) == ['the number of odd elements 4n the str4ng 4 of the 4nput.']
assert candidate(['3', '11111111']) == ['the number of odd elements 1n the str1ng 1 of the 1nput.', 'the number of odd elements 8n the str8ng 8 of the 8nput.']
assert candidate(['271', '137', ... |
humaneval-HumanEval_109_move_one_ball.json-L37 | 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_73_smallest_change.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 {
// Given an array array list arr of integers, find the minimum number of elements that
// need to be changed to make the array array l... | count++;
}
first++;
last--;
}
return count;
}
} | if (arr.get(first) != arr.get(last)) { | }
public static void main(String[] args) {
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)5l, (long)4l, (long)7l, (long)9l, (long)6l)))) == (4l));
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)3l, (lon... |
humaneval-HumanEval_90_next_smallest.json-L27 | js | //You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return undefined if there is no such element.
// >>> next_smallest([1, 2, 3, 4, 5])
// 2
// >>> next_smallest([5, 1, 4, 3, 2])
// 2
// >>> next_smallest([])
// undefined
// >>> next_smallest(... | } | const assert = require('node:assert');
function test() {
let candidate = next_smallest;
assert.deepEqual(candidate([1, 2, 3, 4, 5]),2);
assert.deepEqual(candidate([5, 1, 4, 3, 2]),2);
assert.deepEqual(candidate([]),undefined);
assert.deepEqual(candidate([1, 1]),undefined);
assert.deepEqual(candidate([1, 1... | |
humaneval-HumanEval_139_special_factorial.json-L10 | 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){
| let fact = 1;
for (let i = 1; i <= n; i++) {
fact *= i;
}
return fact * special_factorial(n - 1);
} else {
return 1;
}
}
| if (n > 0) { | 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_143_words_in_sentence.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 {
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to re... | if (ans.length() > 0) {
ans.deleteCharAt(ans.length() - 1);
}
return ans.toString();
}
} | } | }
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_111_histogram.json-L22 | js | //Given a string representing a space separated lowercase letters, return an object
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// >>> histogram("a b c")
// {"a": 1, "b": 1, "c": 1}
// >>> histogram("a ... | count[lst[i]] += 1;
}
else{
count[lst[i]] = 1;
}
}
console.log(count);
var max = 0;
var result = {};
for (var key in count){
if (count[key] > max){
max = count[key];
result = {};
result[key] = max;
}
else if (count[key] === max){
result[key] = max;
... | if (count[lst[i]]){ | const assert = require('node:assert');
function test() {
let candidate = histogram;
assert.deepEqual(candidate("a b b a"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c a b"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c d g"),{"a": 1, "b": 1, "c": 1, "d": 1, "g": 1});
assert.deepEqual(candidat... |
humaneval-HumanEval_56_correct_bracketing.json-L15 | 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... | if bracket == '<':
num_left_brackets += 1
elif bracket == '>':
num_left_brackets -= 1
if num_left_brackets < 0:
return False
return num_left_brackets == 0
| for bracket in brackets: | 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_42_incr_list.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 array list with elements incremented by 1.
// >>> incrList((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))... | }
} | return l; | }
public static void main(String[] args) {
assert(incrList((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(incrList((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)4l, (long)3l, (long)2l))... |
humaneval-HumanEval_47_median.json-L13 | js | //Return median of elements in the array l.
// >>> median([3, 1, 2, 4, 5])
// 3
// >>> median([-10, 4, 6, 1000, 10, 20])
// 15.0
function median(l){
let middle = Math.floor(l.length / 2);
let sorted = l.sort((a, b) => a - b);
if (l.length % 2 === 0) {
return (sorted[middle - 1] + sorted[middle]) / 2... | }
| } | const assert = require('node:assert');
function test() {
let candidate = median;
assert.deepEqual(candidate([3, 1, 2, 4, 5]),3);
assert.deepEqual(candidate([-10, 4, 6, 1000, 10, 20]),8.0);
assert.deepEqual(candidate([5]),5);
assert.deepEqual(candidate([6, 5]),5.5);
assert.deepEqual(candidate([8, 1, 3, 9, ... |
humaneval-HumanEval_119_match_parens.json-L17 | js | //You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses... | let stack = [];
for (let p of s){
if (p === open){
stack.push(p);
} else if (p === close){
if (stack.length === 0){
return false;
}
stack.pop();
}
}
return stack.length === 0;
};
const str1 = lst[0];
const str2 = lst[1];
if (is_good(str1 + str2)){
return 'Yes';
}
if (is_goo... | const is_good = (s) => { | const assert = require('node:assert');
function test() {
let candidate = match_parens;
assert.deepEqual(candidate(["()(", ")"]),"Yes");
assert.deepEqual(candidate([")", ")"]),"No");
assert.deepEqual(candidate(["(()(())", "())())"]),"No");
assert.deepEqual(candidate([")())", "(()()("]),"Yes");
assert.deepE... |
humaneval-HumanEval_19_sort_numbers.json-L8 | py | def sort_numbers(numbers: str) -> str:
""" 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... | res = ''
mapper = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}
for word in sorted(words, key=lambda x: mapper[x]):
res += ' ' + word
return res.strip()
| words = numbers.split() | def check(candidate):
assert candidate('') == ''
assert candidate('three') == 'three'
assert candidate('three five nine') == 'three five nine'
assert candidate('five zero four seven nine eight') == 'zero four five seven eight nine'
assert candidate('six five four three two one zero') == 'zero one tw... |
humaneval-HumanEval_26_remove_duplicates.json-L16 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// From an array array list of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in ... | if (hashmap.containsKey(key)) {
hashmap.put(key, hashmap.get(key) + 1);
} else {
hashmap.put(key, 1L);
}
}
ArrayList<Long> out = new ArrayList<Long>();
for (int i = 0; i < numbers.size(); i++) {
Long key = numbers.ge... | Long key = numbers.get(i); | }
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_119_match_parens.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 {
// You are given an array array list of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
... | 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";
else return "No";
}
} | else c1 -= 1; | }
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-L21 | js | //Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// >>> count_up_to(5)
// [2, 3]
// >>> count_up_to(11)
// [2, 3, 5, 7]
// >>> count_up_to(0)
// []
// >>> count_up_to(20)
// [2, 3, 5, 7, 11, 13, 17, 19]
// >... | if (i % j === 0){
prime = false;
break;
}
}
if (prime) output.push(i);
}
return output;
}
| for (var j = 3; j < i; j += 2){ | const assert = require('node:assert');
function test() {
let candidate = count_up_to;
assert.deepEqual(candidate(5),[2, 3]);
assert.deepEqual(candidate(6),[2, 3, 5]);
assert.deepEqual(candidate(7),[2, 3, 5]);
assert.deepEqual(candidate(10),[2, 3, 5, 7]);
assert.deepEqual(candidate(0),[]);
assert.deepEqu... |
humaneval-HumanEval_128_prod_signs.json-L28 | 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... | if num > 0:
sign_arr.append(1)
elif num < 0:
sign_arr.append(-1)
else:
sign_arr.append(0)
return sum(map(abs, arr)) * product(sign_arr) | for num in arr: | 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_124_valid_date.json-L37 | 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; | 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_147_get_max_triples.json-L23 | 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... | count += 1
k += 1
j += 1
k = j + 1
i += 1
j = i + 1
k = j + 1
return count
| if (a[i] + a[j] + a[k]) % 3 == 0: | 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_65_circular_shift.json-L13 | 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 str = x.toString();
var len = str... | res += str[i];
}
}else{
res = str.substring(len-shift) + str.substring(0, len-shift);
}
return res;
}
| for(var i = len-1; i >= 0; i--){ | 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_47_median.json-L20 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return median of elements in the array list l.
// >>> median((new ArrayList<Long>(Arrays.asList((long)3l, (long)1l, (long)2l, (long... | ret = l.get(size / 2);
}
return ret;
}
} | } else { | }
public static void main(String[] args) {
assert(median((new ArrayList<Long>(Arrays.asList((long)3l, (long)1l, (long)2l, (long)4l, (long)5l)))) == (float)3l);
assert(median((new ArrayList<Long>(Arrays.asList((long)-10l, (long)4l, (long)6l, (long)1000l, (long)10l, (long)20l)))) == (8.0f));
assert(me... |
humaneval-HumanEval_123_get_odd_collatz.json-L35 | js | //Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous ... | return odd_numbers
}
else{
odd_numbers.push(1)
return odd_numbers
}
}
| odd_numbers.sort(function(a, b){return a-b}) | const assert = require('node:assert');
function test() {
let candidate = get_odd_collatz;
assert.deepEqual(candidate(14),[1, 5, 7, 11, 13, 17]);
assert.deepEqual(candidate(5),[1, 5]);
assert.deepEqual(candidate(12),[1, 3, 5]);
assert.deepEqual(candidate(1),[1]);
}
test(); |
humaneval-HumanEval_121_solution.json-L25 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a non-empty array list of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// ... | } | } | }
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_67_fruit_distribution.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 {
// 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... | long oranges = Long.parseLong(splitted[3]);
return n - apples - oranges;
}
} | long apples = Long.parseLong(splitted[0]); | }
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_68_pluck.json-L30 | js | //"Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
//... | if(result.length === 0 || result[0] > arr[i]){
result = [arr[i], i];
}
}
}
return result;
}
| if(arr[i] % 2 === 0){ | const assert = require('node:assert');
function test() {
let candidate = pluck;
assert.deepEqual(candidate([4, 2, 3]),[2, 1]);
assert.deepEqual(candidate([1, 2, 3]),[2, 1]);
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([5, 0, 3, 0, 4, 2]),[0, 1]);
assert.deepEqual(candidate([1, 2, 3, 0, ... |
humaneval-HumanEval_12_longest.json-L17 | py | from typing import List, Optional
def longest(strings: List[str]) -> Optional[str]:
""" Out of list of strings, return the longest one. Return the first one in case of multiple
strings of the same length. Return None in case the input list is empty.
>>> longest([])
None
>>> longest(['a', 'b', 'c'])... | if len(s) > len(long):
long = s
return long
| for s in strings: | def check(candidate):
assert candidate([]) == None
assert candidate(['x', 'y', 'z']) == 'x'
assert candidate(['x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc']) == 'zzzz'
def test_check():
check(longest)
test_check()
|
humaneval-HumanEval_146_specialFilter.json-L26 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that takes an array array list of numbers as input and returns
// the number of elements in the array array list ... | public long[] getDigits(long n) {
ArrayList<Long> digits = new ArrayList<Long>();
while (n != 0) {
digits.add(n % 10);
n /= 10;
}
Collections.reverse(digits);
return digits.stream().mapToL... | } | }
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_137_compare_one.json-L74 | 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 a
elif float(a_tmp) < b:
return b | if 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_111_histogram.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 {
// Given a string representing a space separated lowercase letters, return a hash map
// of the letter with the most repetition and co... | if (test.length() > 0) {
HashMap<String,Long> hm = new HashMap<String,Long>();
String[] ss = test.split(" ");
for (String sss : ss) {
if (hm.containsKey(sss)) {
hm.put(sss, hm.get(sss) + 1);
} else {
hm.p... | HashMap<String,Long> s = new HashMap<String,Long>(); | }
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_66_digitSum.json-L24 | js | //Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// >>> digitSum("")
// 0
// >>> digitSum("abAB")
// 131
// >>> digitSum("abcCd")
// 67
// >>> digitSum("helloE")
// 69
// >>> digitSum("woArBld")
// 131
// >>> digitSum("aAaaaXa")
// 15... | } | return sum; | const assert = require('node:assert');
function test() {
let candidate = digitSum;
assert.deepEqual(candidate(""),0);
assert.deepEqual(candidate("abAB"),131);
assert.deepEqual(candidate("abcCd"),67);
assert.deepEqual(candidate("helloE"),69);
assert.deepEqual(candidate("woArBld"),131);
assert.deepEqual(c... |
humaneval-HumanEval_127_intersection.json-L24 | js | //You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Y... | }
let length = end - start;
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
return primes.includes(length) ? "YES" : "NO";
}
| return "NO"; | const assert = require('node:assert');
function test() {
let candidate = intersection;
assert.deepEqual(candidate([1, 2], [2, 3]),"NO");
assert.deepEqual(candidate([-1, 1], [0, 4]),"NO");
assert.deepEqual(candidate([-3, -1], [-5, 5]),"YES");
assert.deepEqual(candidate([-2, 2], [-4, 0]),"YES");
assert.deep... |
humaneval-HumanEval_128_prod_signs.json-L25 | 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... | else:
sign_arr = []
for num in arr:
if num > 0:
sign_arr.append(1)
elif num < 0:
sign_arr.append(-1)
else:
sign_arr.append(0)
return sum(map(abs, arr)) * product(sign_arr) | return None | 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_10_make_palindrome.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 {
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of ... | newString.append(reverse.substring(string.length() - index));
break;
}
}
return newString.toString();
}
} | if (string.substring(index).equals(reverse.substring(0, string.length() - index))) { | }
public static void main(String[] args) {
assert(makePalindrome(("")).equals(("")));
assert(makePalindrome(("x")).equals(("x")));
assert(makePalindrome(("xyz")).equals(("xyzyx")));
assert(makePalindrome(("xyx")).equals(("xyx")));
assert(makePalindrome(("jerry")).equals(("jerryrrej")));
... |
humaneval-HumanEval_61_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... | }
if (balance < 0) {
return false;
}
}
return balance == 0;
}
} | balance--; | }
public static void main(String[] args) {
assert(correctBracketing(("()")) == (true));
assert(correctBracketing(("(()())")) == (true));
assert(correctBracketing(("()()(()())()")) == (true));
assert(correctBracketing(("()()((()()())())(()()(()))")) == (true));
assert(correctBracketing(("((()... |
humaneval-HumanEval_129_minPath.json-L34 | py | from typing import List
def minPath(grid: List[List[int]], k: int) -> List[int]:
"""
Given a grid with N rows and N columns (N >= 2) and a positive integer k,
each cell of the grid contains a value. Every integer in the range [1, N * N]
inclusive appears exactly once on the cells of the grid.
You... | if grid[i][j] < min_val:
min_val = grid[i][j]
row = i
col = j
path = [min_val]
while len(path) < k:
min_val = float('inf')
for i, j in (row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1):
if 0 <= i < len(grid) and... | for j in range(len(grid[0])): | def check(candidate):
assert candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3) == [1, 2, 1]
assert candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1) == [1]
assert candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], 4) == [1, 2, 1, 2]
assert candidate([[6, 4, 13, 10], [5, 7, 12, 1], [3... |
humaneval-HumanEval_148_bf.json-L27 | 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... | planets = planets[start+1:end]
else:
planets = planets[end+1:start]
return tuple(planets) | if start < end: | 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_141_file_name_check.json-L31 | py | def file_name_check(file_name: str) -> str:
"""Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is valid, and returns 'No' otherwise.
A file's name is considered to be valid if and only if all the following conditions
are met:
- There shoul... | if e_name not in ['txt', 'exe', 'dll']:
return 'No'
return 'Yes'
| return 'No' | def check(candidate):
assert candidate('example.txt') == 'Yes'
assert candidate('1example.dll') == 'No'
assert candidate('s1sdf3.asd') == 'No'
assert candidate('K.dll') == 'Yes'
assert candidate('MY16FILE3.exe') == 'Yes'
assert candidate('His12FILE94.exe') == 'No'
assert candidate('_Y.txt') ... |
humaneval-HumanEval_123_get_odd_collatz.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 {
// Given a positive integer n, return a sorted array list that has the odd numbers in collatz sequence.
// The Collatz conjecture is a... | } | } | }
public static void main(String[] args) {
assert(getOddCollatz((14l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)7l, (long)11l, (long)13l, (long)17l)))));
assert(getOddCollatz((5l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l)))));
assert(getOddCollatz((12l... |
humaneval-HumanEval_147_get_max_triples.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 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... | }
}
}
}
return count;
}
} | count++; | }
public static void main(String[] args) {
assert(getMaxTriples((5l)) == (1l));
assert(getMaxTriples((6l)) == (4l));
assert(getMaxTriples((10l)) == (36l));
assert(getMaxTriples((100l)) == (53361l));
}
}
|
humaneval-HumanEval_72_will_it_fly.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 {
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is ... | } | }
public static void main(String[] args) {
assert(willItFly((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)3l))), (9l)) == (true));
assert(willItFly((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l))), (5l)) == (false));
assert(willItFly((new ArrayList<Long>(Arrays.asList((long)3l... | |
humaneval-HumanEval_115_max_fill.json-L34 | 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,
... | times += 1
return times
| if 1 in row[i:i+capacity]: | 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, ... |
humaneval-HumanEval_147_get_max_triples.json-L21 | js | //You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// >>> get_max_triples(5)
// 1
// Ex... | }
}
}
}
return result;
}
| result++; | const assert = require('node:assert');
function test() {
let candidate = get_max_triples;
assert.deepEqual(candidate(5),1);
assert.deepEqual(candidate(6),4);
assert.deepEqual(candidate(10),36);
assert.deepEqual(candidate(100),53361);
}
test(); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.