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_123_get_odd_collatz.json-L27 | js | //Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// >>> get_odd_collatz(5)
// [1, 5]
function get_odd_collatz(n){
var collatz_sequence = []
var odd_numbers = []
var odd_count = 0
collatz_sequence.push(n)
for(var i = 0; i < collatz_sequence.length; i++){
if(collatz_sequence[i]%2 == 0){
collatz_sequence.push(collatz_sequence[i]/2)
}
else if(collatz_sequence[i]%2 == 1){
collatz_sequence.push(collatz_sequence[i]*3+1)
}
if(collatz_sequence[i]%2 == 1){ | odd_count += 1
}
if(collatz_sequence[i] == 1){
break
}
}
if(odd_count != 0){
odd_numbers.sort(function(a, b){return a-b})
return odd_numbers
}
else{
odd_numbers.push(1)
return odd_numbers
}
}
| odd_numbers.push(collatz_sequence[i]) | 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_87_get_row.json-L25 | js | //You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of arrays, [(x1, y1), (x2, y2) ...] such that
// each array is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// >>> get_row([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1)
// [[0, 0], [1, 4], [1, 0], [2, 5], [2, 0]]
// >>> get_row([], 1)
// []
// >>> get_row([[], [1], [1, 2, 3]], 3)
// [[2, 2]]
function get_row(lst, x){
let coordinates = [];
for (let i = 0; i < lst.length; i++){
let array = lst[i];
for (let j = 0; j < array.length; j++){
if (lst[i][j] === x){
coordinates.push([i, j]);
}
} | return coordinates.sort(function(a, b){
return a[0] - b[0] || b[1] - a[1];
});
}
| } | const assert = require('node:assert');
function test() {
let candidate = get_row;
assert.deepEqual(candidate([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1),[[0, 0], [1, 4], [1, 0], [2, 5], [2, 0]]);
assert.deepEqual(candidate([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6]], 2),[[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1]]);
assert.deepEqual(candidate([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 1, 3, 4, 5, 6], [1, 2, 1, 4, 5, 6], [1, 2, 3, 1, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1),[[0, 0], [1, 0], [2, 1], [2, 0], [3, 2], [3, 0], [4, 3], [4, 0], [5, 4], [5, 0], [6, 5], [6, 0]]);
assert.deepEqual(candidate([], 1),[]);
assert.deepEqual(candidate([[1]], 2),[]);
assert.deepEqual(candidate([[], [1], [1, 2, 3]], 3),[[2, 2]]);
}
test(); |
humaneval-HumanEval_69_search.json-L21 | js | //You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// >>> search([4, 1, 2, 2, 3, 1])
// 2
// >>> search([1, 2, 2, 3, 3, 3, 4, 4, 4])
// 3
// >>> search([5, 5, 4, 4, 4])
// -1
function search(lst){
var h = {};
for (var i=0; i<lst.length; i++){
var x = lst[i];
if (x in h){
h[x] += 1;
}
else{
h[x] = 1; | }
var keys = Object.keys(h);
var max = 0;
for (var i=0; i<keys.length; i++){
if (keys[i] > max && h[keys[i]] >= keys[i]){
max = keys[i];
}
}
if (max == 0){
return -1;
}
return max;
}
| } | const assert = require('node:assert');
function test() {
let candidate = search;
assert.deepEqual(candidate([5, 5, 5, 5, 1]),1);
assert.deepEqual(candidate([4, 1, 4, 1, 4, 4]),4);
assert.deepEqual(candidate([3, 3]),-1);
assert.deepEqual(candidate([8, 8, 8, 8, 8, 8, 8, 8]),8);
assert.deepEqual(candidate([2, 3, 3, 2, 2]),2);
assert.deepEqual(candidate([2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1]),1);
assert.deepEqual(candidate([3, 2, 8, 2]),2);
assert.deepEqual(candidate([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]),1);
assert.deepEqual(candidate([8, 8, 3, 6, 5, 6, 4]),-1);
assert.deepEqual(candidate([6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9]),1);
assert.deepEqual(candidate([1, 9, 10, 1, 3]),1);
assert.deepEqual(candidate([6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10]),5);
assert.deepEqual(candidate([1]),1);
assert.deepEqual(candidate([8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5]),4);
assert.deepEqual(candidate([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]),2);
assert.deepEqual(candidate([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]),1);
assert.deepEqual(candidate([9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4]),4);
assert.deepEqual(candidate([2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7]),4);
assert.deepEqual(candidate([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]),2);
assert.deepEqual(candidate([5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8]),-1);
assert.deepEqual(candidate([10]),-1);
assert.deepEqual(candidate([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]),2);
assert.deepEqual(candidate([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]),1);
assert.deepEqual(candidate([7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6]),1);
assert.deepEqual(candidate([3, 10, 10, 9, 2]),-1);
}
test(); |
humaneval-HumanEval_150_x_or_y.json-L17 | js | //A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// >>> x_or_y(7, 34, 12)
// 34
// >>> x_or_y(15, 8, 5)
// 5
function x_or_y(n, x, y){
if(n<2){
return y;
}
for(var i=2; i<n; i++){
if(n%i==0){
return y;
}
} | } | return x; | const assert = require('node:assert');
function test() {
let candidate = x_or_y;
assert.deepEqual(candidate(7, 34, 12),34);
assert.deepEqual(candidate(15, 8, 5),5);
assert.deepEqual(candidate(3, 33, 5212),33);
assert.deepEqual(candidate(1259, 3, 52),3);
assert.deepEqual(candidate(7919, -1, 12),-1);
assert.deepEqual(candidate(3609, 1245, 583),583);
assert.deepEqual(candidate(91, 56, 129),129);
assert.deepEqual(candidate(6, 34, 1234),1234);
assert.deepEqual(candidate(1, 2, 0),0);
assert.deepEqual(candidate(2, 2, 0),2);
}
test(); |
humaneval-HumanEval_10_make_palindrome.json-L20 | py | def make_palindrome(string: str) -> str:
""" Find the shortest palindrome that begins with a supplied string.
Algorithm idea is simple:
- Find the longest postfix of supplied string that is a palindrome.
- Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
>>> make_palindrome('')
''
>>> make_palindrome('cat')
'catac'
>>> make_palindrome('cata')
'catac'
"""
if not string:
return string
prefix = string[::-1]
for i in range(len(string)):
if string[i:] == prefix[:len(string) - i]: |
return string
| return string + prefix[len(string) - i:] | def check(candidate):
assert candidate('') == ''
assert candidate('x') == 'x'
assert candidate('xyz') == 'xyzyx'
assert candidate('xyx') == 'xyx'
assert candidate('jerry') == 'jerryrrej'
def test_check():
check(make_palindrome)
test_check()
|
humaneval-HumanEval_118_get_closest_vowel.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 a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// >>> getClosestVowel(("yogurt"))
// ("u")
// >>> getClosestVowel(("FULL"))
// ("U")
// >>> getClosestVowel(("quick"))
// ("")
// >>> getClosestVowel(("ab"))
// ("")
public static String getClosestVowel(String word) {
final String vowels = "aeiou";
final String consonants = "bcdfghjklmnpqrstvwxyz";
List<Integer> idx = new ArrayList<>();
word = word.toLowerCase();
for (int i = 0; i < word.length(); i++) {
if (vowels.indexOf(word.charAt(i)) != -1) {
idx.add(i); | }
for (int i = idx.size() - 1; i >= 0; i--) {
int j = idx.get(i);
if (j == 0 || j == word.length() - 1) continue;
char left = word.charAt(j - 1);
char right = word.charAt(j + 1);
if (consonants.indexOf(left) != -1 && consonants.indexOf(right) != -1) {
return String.valueOf(word.charAt(j));
}
}
return "";
}
} | } | }
public static void main(String[] args) {
assert(getClosestVowel(("yogurt")).equals(("u")));
assert(getClosestVowel(("full")).equals(("u")));
assert(getClosestVowel(("easy")).equals(("")));
assert(getClosestVowel(("eAsy")).equals(("")));
assert(getClosestVowel(("ali")).equals(("")));
assert(getClosestVowel(("bad")).equals(("a")));
assert(getClosestVowel(("most")).equals(("o")));
assert(getClosestVowel(("ab")).equals(("")));
assert(getClosestVowel(("ba")).equals(("")));
assert(getClosestVowel(("quick")).equals(("")));
assert(getClosestVowel(("anime")).equals(("i")));
assert(getClosestVowel(("Asia")).equals(("")));
assert(getClosestVowel(("Above")).equals(("o")));
}
}
|
humaneval-HumanEval_131_digits.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 positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// >>> digits((1l))
// (1l)
// >>> digits((4l))
// (0l)
// >>> digits((235l))
// (15l)
public static long digits(long n) {
if (n < 10) {
return n % 2 == 1 ? n : 0;
}
return digits(n / 10) * (n % 2 == 1 ? n % 10 : 1); | } | } | }
public static void main(String[] args) {
assert(digits((5l)) == (5l));
assert(digits((54l)) == (5l));
assert(digits((120l)) == (1l));
assert(digits((5014l)) == (5l));
assert(digits((98765l)) == (315l));
assert(digits((5576543l)) == (2625l));
assert(digits((2468l)) == (0l));
}
}
|
humaneval-HumanEval_137_compare_one.json-L68 | py | from typing import Union
def compare_one(a: Union[int, float, str], b: Union[int, float, str]) -> Union[int, float, str, None]:
"""
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values are equal.
Note: If a real number is represented as a string, the floating point might be . or ,
>>> compare_one(1, 2.5)
2.5
>>> compare_one(1, '2,3')
'2,3'
>>> compare_one('5,1', '6')
'6'
>>> compare_one('1', 1)
None
"""
if isinstance(a, int) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, float) and isinstance(b, float):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, str) and isinstance(b, str):
a_tmp = a.replace(',', '.')
b_tmp = b.replace(',', '.')
if float(a_tmp) > float(b_tmp):
return a
elif float(a_tmp) < float(b_tmp):
return b
else:
return None
elif isinstance(a, int) and isinstance(b, float):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, float) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, str) and isinstance(b, int):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b
else:
return None
elif isinstance(a, int) and isinstance(b, str):
b_tmp = b.replace(',', '.')
if a > float(b_tmp):
return a | return b
else:
return None
elif isinstance(a, str) and isinstance(b, float):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b | elif a < float(b_tmp): | def check(candidate):
assert candidate(1, 2) == 2
assert candidate(1, 2.5) == 2.5
assert candidate(2, 3) == 3
assert candidate(5, 6) == 6
assert candidate(1, '2,3') == '2,3'
assert candidate('5,1', '6') == '6'
assert candidate('1', '2') == '2'
assert candidate('1', 1) == None
def test_check():
check(compare_one)
test_check()
|
humaneval-HumanEval_56_correct_bracketing.json-L20 | js | //brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correct_bracketing("<")
// false
// >>> correct_bracketing("<>")
// true
// >>> correct_bracketing("<<><>>")
// true
// >>> correct_bracketing("><<>")
// false
function correct_bracketing(brackets){
var opens = 0;
for (var i = 0; i < brackets.length; i++) {
if (brackets[i] === "<") {
opens++;
}
else if (brackets[i] === ">") {
opens--;
} | return false;
}
}
return opens === 0;
}
| if (opens < 0) { | const assert = require('node:assert');
function test() {
let candidate = correct_bracketing;
assert.deepEqual(candidate("<>"),true);
assert.deepEqual(candidate("<<><>>"),true);
assert.deepEqual(candidate("<><><<><>><>"),true);
assert.deepEqual(candidate("<><><<<><><>><>><<><><<>>>"),true);
assert.deepEqual(candidate("<<<><>>>>"),false);
assert.deepEqual(candidate("><<>"),false);
assert.deepEqual(candidate("<"),false);
assert.deepEqual(candidate("<<<<"),false);
assert.deepEqual(candidate(">"),false);
assert.deepEqual(candidate("<<>"),false);
assert.deepEqual(candidate("<><><<><>><>><<>"),false);
assert.deepEqual(candidate("<><><<><>><>>><>"),false);
}
test(); |
humaneval-HumanEval_124_valid_date.json-L20 | 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. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// >>> valid_date("03-11-2000")
// true
// >>> valid_date("15-01-2012")
// false
// >>> valid_date("04-0-2040")
// false
// >>> valid_date("06-04-2020")
// true
// >>> valid_date("06/04/2020")
// false
function valid_date(date){
var date_arr = date.split("-"); | var month = parseInt(date_arr[0]);
var day = parseInt(date_arr[1]);
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 || 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 true;
}
return false;
}
| if(date_arr.length == 3){ | 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("01-01-2007"),true);
assert.deepEqual(candidate("03-32-2011"),false);
assert.deepEqual(candidate(""),false);
assert.deepEqual(candidate("04-31-3000"),false);
assert.deepEqual(candidate("06-06-2005"),true);
assert.deepEqual(candidate("21-31-2000"),false);
assert.deepEqual(candidate("04-12-2003"),true);
assert.deepEqual(candidate("04122003"),false);
assert.deepEqual(candidate("20030412"),false);
assert.deepEqual(candidate("2003-04"),false);
assert.deepEqual(candidate("2003-04-12"),false);
assert.deepEqual(candidate("04-2003"),false);
}
test(); |
humaneval-HumanEval_157_right_angle_triangle.json-L11 | js | //Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// >>> right_angle_triangle(3, 4, 5)
// true
// >>> right_angle_triangle(1, 2, 3)
// false
function right_angle_triangle(a, b, c){
| return true;
} else {
return false;
}
}
| if(a**2 + b**2 == c**2 || b**2 + c**2 == a**2 || a**2 + c**2 == b**2) { | const assert = require('node:assert');
function test() {
let candidate = right_angle_triangle;
assert.deepEqual(candidate(3, 4, 5),true);
assert.deepEqual(candidate(1, 2, 3),false);
assert.deepEqual(candidate(10, 6, 8),true);
assert.deepEqual(candidate(2, 2, 2),false);
assert.deepEqual(candidate(7, 24, 25),true);
assert.deepEqual(candidate(10, 5, 7),false);
assert.deepEqual(candidate(5, 12, 13),true);
assert.deepEqual(candidate(15, 8, 17),true);
assert.deepEqual(candidate(48, 55, 73),true);
assert.deepEqual(candidate(1, 1, 1),false);
assert.deepEqual(candidate(2, 2, 10),false);
}
test(); |
humaneval-HumanEval_110_exchange.json-L26 | py | from typing import List
def exchange(lst1: List[int], lst2: List[int]) -> str:
"""In this problem, you will implement a function that takes two lists of numbers,
and determines whether it is possible to perform an exchange of elements
between them to make lst1 a list of only even numbers.
There is no limit on the number of exchanged elements between lst1 and lst2.
If it is possible to exchange elements between the lst1 and lst2 to make
all the elements of lst1 to be even, return "YES".
Otherwise, return "NO".
For example:
>>> exchange([1, 2, 3, 4], [1, 2, 3, 4])
'YES'
>>> exchange([1, 2, 3, 4], [1, 5, 3, 4])
'NO'
It is assumed that the input lists will be non-empty.
"""
count = 0
for x in lst1:
if x % 2 == 1:
count += 1
for y in lst2:
if y % 2 == 0:
count -= 1
if count > 0: | else:
return "YES" | return "NO" | def check(candidate):
assert candidate([1, 2, 3, 4], [1, 2, 3, 4]) == 'YES'
assert candidate([1, 2, 3, 4], [1, 5, 3, 4]) == 'NO'
assert candidate([1, 2, 3, 4], [2, 1, 4, 3]) == 'YES'
assert candidate([5, 7, 3], [2, 6, 4]) == 'YES'
assert candidate([5, 7, 3], [2, 6, 3]) == 'NO'
assert candidate([3, 2, 6, 1, 8, 9], [3, 5, 5, 1, 1, 1]) == 'NO'
assert candidate([100, 200], [200, 200]) == 'YES'
def test_check():
check(exchange)
test_check()
|
humaneval-HumanEval_157_right_angle_triangle.json-L15 | js | //Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// >>> right_angle_triangle(3, 4, 5)
// true
// >>> right_angle_triangle(1, 2, 3)
// false
function right_angle_triangle(a, b, c){
if(a**2 + b**2 == c**2 || b**2 + c**2 == a**2 || a**2 + c**2 == b**2) {
return true;
} else {
return false; | }
| } | const assert = require('node:assert');
function test() {
let candidate = right_angle_triangle;
assert.deepEqual(candidate(3, 4, 5),true);
assert.deepEqual(candidate(1, 2, 3),false);
assert.deepEqual(candidate(10, 6, 8),true);
assert.deepEqual(candidate(2, 2, 2),false);
assert.deepEqual(candidate(7, 24, 25),true);
assert.deepEqual(candidate(10, 5, 7),false);
assert.deepEqual(candidate(5, 12, 13),true);
assert.deepEqual(candidate(15, 8, 17),true);
assert.deepEqual(candidate(48, 55, 73),true);
assert.deepEqual(candidate(1, 1, 1),false);
assert.deepEqual(candidate(2, 2, 10),false);
}
test(); |
humaneval-HumanEval_78_hex_key.json-L33 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// >>> hexKey(("AB"))
// (1l)
// >>> hexKey(("1077E"))
// (2l)
// >>> hexKey(("ABED1A33"))
// (4l)
// >>> hexKey(("123456789ABCDEF0"))
// (6l)
// >>> hexKey(("2020"))
// (2l)
public static long hexKey(String num) {
long result = 0;
for (int i = 0; i < num.length(); i++) { | result++;
}
}
return result;
}
} | if (num.charAt(i) == '2' || num.charAt(i) == '3' || num.charAt(i) == '5' || num.charAt(i) == '7' || num.charAt(i) == 'B' || num.charAt(i) == 'D') { | }
public static void main(String[] args) {
assert(hexKey(("AB")) == (1l));
assert(hexKey(("1077E")) == (2l));
assert(hexKey(("ABED1A33")) == (4l));
assert(hexKey(("2020")) == (2l));
assert(hexKey(("123456789ABCDEF0")) == (6l));
assert(hexKey(("112233445566778899AABBCCDDEEFF00")) == (12l));
}
}
|
humaneval-HumanEval_81_numerical_letter_grade.json-L53 | js | //It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// >>> grade_equation([4.0, 3, 1.7, 2, 3.5])
// ["A+", "B", "C-", "C", "A-"]
function numerical_letter_grade(grades){
var grades_array = [];
for (var i = 0; i < grades.length; i++){
if (grades[i] >= 4.0){
grades_array.push("A+");
}
else if (grades[i] > 3.7){
grades_array.push("A");
}
else if (grades[i] > 3.3){
grades_array.push("A-");
}
else if (grades[i] > 3.0){
grades_array.push("B+");
}
else if (grades[i] > 2.7){
grades_array.push("B");
}
else if (grades[i] > 2.3){
grades_array.push("B-");
}
else if (grades[i] > 2.0){
grades_array.push("C+");
}
else if (grades[i] > 1.7){
grades_array.push("C");
}
else if (grades[i] > 1.3){
grades_array.push("C-");
} | grades_array.push("D+");
}
else if (grades[i] > 0.7){
grades_array.push("D");
}
else if (grades[i] > 0.0){
grades_array.push("D-");
}
else if (grades[i] == 0.0){
grades_array.push("E");
}
}
return grades_array;
} | else if (grades[i] > 1.0){ | const assert = require('node:assert');
function test() {
let candidate = numerical_letter_grade;
assert.deepEqual(candidate([4.0, 3, 1.7, 2, 3.5]),["A+", "B", "C-", "C", "A-"]);
assert.deepEqual(candidate([1.2]),["D+"]);
assert.deepEqual(candidate([0.5]),["D-"]);
assert.deepEqual(candidate([0.0]),["E"]);
assert.deepEqual(candidate([1.0, 0.3, 1.5, 2.8, 3.3]),["D", "D-", "C-", "B", "B+"]);
assert.deepEqual(candidate([0.0, 0.7]),["E", "D-"]);
}
test(); |
humaneval-HumanEval_146_specialFilter.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 {
// Write a function that takes an array array list of numbers as input and returns
// the number of elements in the array array list that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// >>> specialFilter((new ArrayList<Long>(Arrays.asList((long)15l, (long)-73l, (long)14l, (long)-15l))))
// (1l)
// >>> specialFilter((new ArrayList<Long>(Arrays.asList((long)33l, (long)-2l, (long)-3l, (long)45l, (long)21l, (long)109l))))
// (2l)
public static long specialFilter(ArrayList<Long> nums) {
class helper {
public long getFirstDigit(long n) {
long[] digits = getDigits(n);
return digits[0];
}
public long getLastDigit(long n) {
long[] digits = getDigits(n);
return digits[digits.length - 1];
}
public long[] getDigits(long n) {
ArrayList<Long> digits = new ArrayList<Long>();
while (n != 0) {
digits.add(n % 10);
n /= 10;
}
Collections.reverse(digits);
return digits.stream().mapToLong(i -> i).toArray();
}
}
helper h = new helper();
return nums.stream().filter(x -> x > 10).filter(x -> {
long firstDigit = h.getFirstDigit(x);
long lastDigit = h.getLastDigit(x); | }).count();
}
} | return firstDigit % 2 != 0 && lastDigit % 2 != 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 ArrayList<Long>(Arrays.asList((long)33l, (long)-2l, (long)-3l, (long)45l, (long)21l, (long)109l)))) == (2l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)43l, (long)-12l, (long)93l, (long)125l, (long)121l, (long)109l)))) == (4l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)71l, (long)-2l, (long)-33l, (long)75l, (long)21l, (long)19l)))) == (3l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)1l)))) == (0l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList()))) == (0l));
}
}
|
humaneval-HumanEval_160_do_algebra.json-L28 | py | from typing import List
def do_algebra(operator: List[str], operand: List[int]) -> int:
"""
Given two lists operator, and operand. The first list has basic algebra operations, and
the second list is a list of integers. Use the two given lists to build the algebric
expression and return the evaluation of this expression.
The basic algebra operations:
Addition ( + )
Subtraction ( - )
Multiplication ( * )
Floor division ( // )
Exponentiation ( ** )
Example:
operator['+', '*', '-']
array = [2, 3, 4, 5]
result = 2 + 3 * 4 - 5
=> result = 9
Note:
The length of operator list is equal to the length of operand list minus one.
Operand is a list of of non-negative integers.
Operator list has at least one operator, and operand list has at least two operands.
"""
| raise ValueError("Invalid number of operators")
expr = [str(operand[0])]
for idx, op in enumerate(operator):
expr.append(op)
expr.append(str(operand[idx + 1]))
return eval("".join(expr)) | if len(operator) != len(operand) - 1: | def check(candidate):
assert candidate(['**', '*', '+'], [2, 3, 4, 5]) == 37
assert candidate(['+', '*', '-'], [2, 3, 4, 5]) == 9
assert candidate(['//', '*'], [7, 3, 4]) == 8
def test_check():
check(do_algebra)
test_check()
|
humaneval-HumanEval_69_search.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 are given a non-empty array list of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array list.
// If no such a value exist, return -1.
// Examples:
// >>> search((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)2l, (long)2l, (long)3l, (long)1l))))
// (2l)
// >>> search((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)3l, (long)4l, (long)4l, (long)4l))))
// (3l)
// >>> search((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)4l, (long)4l, (long)4l))))
// (-1l)
public static long search(ArrayList<Long> lst) {
| Long max = (long)-1;
for (int i = 0; i < lst.size(); i++) {
long val = lst.get(i);
if (map.containsKey(val)) {
map.put(val, map.get(val) + 1);
} else {
map.put(val, (long)1);
}
if (map.get(val) >= val && val > max) {
max = val;
}
}
return max;
}
} | HashMap<Long, Long> map = new HashMap<Long, Long>(); | }
public static void main(String[] args) {
assert(search((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)5l, (long)5l, (long)1l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)4l, (long)1l, (long)4l, (long)4l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)3l, (long)3l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)8l, (long)8l, (long)8l, (long)8l, (long)8l, (long)8l, (long)8l, (long)8l)))) == (8l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)3l, (long)2l, (long)2l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)7l, (long)8l, (long)8l, (long)4l, (long)8l, (long)7l, (long)3l, (long)9l, (long)6l, (long)5l, (long)10l, (long)4l, (long)3l, (long)6l, (long)7l, (long)1l, (long)7l, (long)4l, (long)10l, (long)8l, (long)1l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)8l, (long)2l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)6l, (long)7l, (long)1l, (long)8l, (long)8l, (long)10l, (long)5l, (long)8l, (long)5l, (long)3l, (long)10l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)8l, (long)8l, (long)3l, (long)6l, (long)5l, (long)6l, (long)4l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)6l, (long)9l, (long)6l, (long)7l, (long)1l, (long)4l, (long)7l, (long)1l, (long)8l, (long)8l, (long)9l, (long)8l, (long)10l, (long)10l, (long)8l, (long)4l, (long)10l, (long)4l, (long)10l, (long)1l, (long)2l, (long)9l, (long)5l, (long)7l, (long)9l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)1l, (long)9l, (long)10l, (long)1l, (long)3l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)6l, (long)9l, (long)7l, (long)5l, (long)8l, (long)7l, (long)5l, (long)3l, (long)7l, (long)5l, (long)10l, (long)10l, (long)3l, (long)6l, (long)10l, (long)2l, (long)8l, (long)6l, (long)5l, (long)4l, (long)9l, (long)5l, (long)3l, (long)10l)))) == (5l));
assert(search((new ArrayList<Long>(Arrays.asList((long)1l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)8l, (long)8l, (long)10l, (long)6l, (long)4l, (long)3l, (long)5l, (long)8l, (long)2l, (long)4l, (long)2l, (long)8l, (long)4l, (long)6l, (long)10l, (long)4l, (long)2l, (long)1l, (long)10l, (long)2l, (long)1l, (long)1l, (long)5l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)10l, (long)4l, (long)8l, (long)2l, (long)10l, (long)5l, (long)1l, (long)2l, (long)9l, (long)5l, (long)5l, (long)6l, (long)3l, (long)8l, (long)6l, (long)4l, (long)10l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)1l, (long)6l, (long)10l, (long)1l, (long)6l, (long)9l, (long)10l, (long)8l, (long)6l, (long)8l, (long)7l, (long)3l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)9l, (long)2l, (long)4l, (long)1l, (long)5l, (long)1l, (long)5l, (long)2l, (long)5l, (long)7l, (long)7l, (long)7l, (long)3l, (long)10l, (long)1l, (long)5l, (long)4l, (long)2l, (long)8l, (long)4l, (long)1l, (long)9l, (long)10l, (long)7l, (long)10l, (long)2l, (long)8l, (long)10l, (long)9l, (long)4l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)4l, (long)2l, (long)8l, (long)7l, (long)5l, (long)6l, (long)4l, (long)10l, (long)4l, (long)6l, (long)3l, (long)7l, (long)8l, (long)8l, (long)3l, (long)1l, (long)4l, (long)2l, (long)2l, (long)10l, (long)7l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)9l, (long)8l, (long)6l, (long)10l, (long)2l, (long)6l, (long)10l, (long)2l, (long)7l, (long)8l, (long)10l, (long)3l, (long)8l, (long)2l, (long)6l, (long)2l, (long)3l, (long)1l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)3l, (long)9l, (long)5l, (long)6l, (long)3l, (long)2l, (long)8l, (long)5l, (long)6l, (long)10l, (long)10l, (long)6l, (long)8l, (long)4l, (long)10l, (long)7l, (long)7l, (long)10l, (long)8l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)10l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)9l, (long)7l, (long)7l, (long)2l, (long)4l, (long)7l, (long)2l, (long)10l, (long)9l, (long)7l, (long)5l, (long)7l, (long)2l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)5l, (long)4l, (long)10l, (long)2l, (long)1l, (long)1l, (long)10l, (long)3l, (long)6l, (long)1l, (long)8l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)7l, (long)9l, (long)9l, (long)9l, (long)3l, (long)4l, (long)1l, (long)5l, (long)9l, (long)1l, (long)2l, (long)1l, (long)1l, (long)10l, (long)7l, (long)5l, (long)6l, (long)7l, (long)6l, (long)7l, (long)7l, (long)6l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)3l, (long)10l, (long)10l, (long)9l, (long)2l)))) == (-1l));
}
}
|
humaneval-HumanEval_59_largest_prime_factor.json-L15 | js | //Return the largest prime factor of n. Assume n > 1 and is not a prime.
// >>> largest_prime_factor(13195)
// 29
// >>> largest_prime_factor(2048)
// 2
function largest_prime_factor(n){
var result = 2;
while(n > result){
if(n % result == 0){
n = n / result;
}
else{
result = result + 1;
} | return result;
} | } | const assert = require('node:assert');
function test() {
let candidate = largest_prime_factor;
assert.deepEqual(candidate(15),5);
assert.deepEqual(candidate(27),3);
assert.deepEqual(candidate(63),7);
assert.deepEqual(candidate(330),11);
assert.deepEqual(candidate(13195),29);
}
test(); |
humaneval-HumanEval_156_int_to_mini_roman.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 {
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// >>> intToMiniRoman((19l))
// ("xix")
// >>> intToMiniRoman((152l))
// ("clii")
// >>> intToMiniRoman((426l))
// ("cdxxvi")
public static String intToMiniRoman(long number) {
int num = (int) number;
String res = "";
if (num == 0)
return "";
while (num >= 1000) {
res += "m";
num -= 1000;
}
if (num >= 900) {
res += "cm";
num -= 900;
}
if (num >= 500) {
res += "d";
num -= 500;
}
if (num >= 400) {
res += "cd";
num -= 400; | while (num >= 100) {
res += "c";
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 += "x";
num -= 10;
}
if (num >= 9) {
res += "ix";
num -= 9;
}
if (num >= 5) {
res += "v";
num -= 5;
}
if (num >= 4) {
res += "iv";
num -= 4;
}
while (num >= 1) {
res += "i";
num -= 1;
}
return res;
}
} | } | }
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")));
assert(intToMiniRoman((1l)).equals(("i")));
assert(intToMiniRoman((4l)).equals(("iv")));
assert(intToMiniRoman((43l)).equals(("xliii")));
assert(intToMiniRoman((90l)).equals(("xc")));
assert(intToMiniRoman((94l)).equals(("xciv")));
assert(intToMiniRoman((532l)).equals(("dxxxii")));
assert(intToMiniRoman((900l)).equals(("cm")));
assert(intToMiniRoman((994l)).equals(("cmxciv")));
assert(intToMiniRoman((1000l)).equals(("m")));
}
}
|
humaneval-HumanEval_149_sorted_list_sum.json-L40 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that accepts an array array list of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array list with a sorted order,
// The array list is always an array array list of strings and never an array array list of numbers,
// and it may contain duplicates.
// The order of the array list should be ascending by length of each word, and you
// should return the array list sorted by that rule.
// If two words have the same length, sort the array list alphabetically.
// The function should return an array array list of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// >>> listSort((new ArrayList<String>(Arrays.asList((String)"aa", (String)"a", (String)"aaa"))))
// (new ArrayList<String>(Arrays.asList((String)"aa")))
// >>> listSort((new ArrayList<String>(Arrays.asList((String)"ab", (String)"a", (String)"aaa", (String)"cd"))))
// (new ArrayList<String>(Arrays.asList((String)"ab", (String)"cd")))
public static ArrayList<String> sortedListSum(ArrayList<String> lst) {
ArrayList<String> result = new ArrayList<String>();
for (String s : lst) {
if (s.length() % 2 == 0) {
result.add(s);
}
}
Collections.sort(result, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
if (s1.length() == s2.length()) {
return s1.compareTo(s2);
}
return s1.length() - s2.length();
}
}); | }
} | return result; | }
public static void main(String[] args) {
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"aa", (String)"a", (String)"aaa")))).equals((new ArrayList<String>(Arrays.asList((String)"aa")))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"school", (String)"AI", (String)"asdf", (String)"b")))).equals((new ArrayList<String>(Arrays.asList((String)"AI", (String)"asdf", (String)"school")))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"d", (String)"b", (String)"c", (String)"a")))).equals((new ArrayList<String>(Arrays.asList()))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"d", (String)"dcba", (String)"abcd", (String)"a")))).equals((new ArrayList<String>(Arrays.asList((String)"abcd", (String)"dcba")))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"AI", (String)"ai", (String)"au")))).equals((new ArrayList<String>(Arrays.asList((String)"AI", (String)"ai", (String)"au")))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"a", (String)"b", (String)"b", (String)"c", (String)"c", (String)"a")))).equals((new ArrayList<String>(Arrays.asList()))));
assert(sortedListSum((new ArrayList<String>(Arrays.asList((String)"aaaa", (String)"bbbb", (String)"dd", (String)"cc")))).equals((new ArrayList<String>(Arrays.asList((String)"cc", (String)"dd", (String)"aaaa", (String)"bbbb")))));
}
}
|
humaneval-HumanEval_149_sorted_list_sum.json-L35 | js | //Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// >>> list_sort(["aa", "a", "aaa"])
// ["aa"]
// >>> list_sort(["ab", "a", "aaa", "cd"])
// ["ab", "cd"]
function sorted_list_sum(lst){
var result = [];
for(var i = 0; i < lst.length; i++){
if(lst[i].length % 2 == 0){
result.push(lst[i]);
}
}
return result.sort(function(a, b){
if(a.length < b.length){
return -1;
}
else if(a.length > b.length){
return 1;
}
else{
if(a < b){
return -1;
}
else if(a > b){ | }
else{
return 0;
}
}
});
}
var a = ["aa", "a", "aaa"];
var b = ["ab", "a", "aaa", "cd"]; | return 1; | const assert = require('node:assert');
function test() {
let candidate = sorted_list_sum;
assert.deepEqual(candidate(["aa", "a", "aaa"]),["aa"]);
assert.deepEqual(candidate(["school", "AI", "asdf", "b"]),["AI", "asdf", "school"]);
assert.deepEqual(candidate(["d", "b", "c", "a"]),[]);
assert.deepEqual(candidate(["d", "dcba", "abcd", "a"]),["abcd", "dcba"]);
assert.deepEqual(candidate(["AI", "ai", "au"]),["AI", "ai", "au"]);
assert.deepEqual(candidate(["a", "b", "b", "c", "c", "a"]),[]);
assert.deepEqual(candidate(["aaaa", "bbbb", "dd", "cc"]),["cc", "dd", "aaaa", "bbbb"]);
}
test(); |
humaneval-HumanEval_49_modp.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 {
// Return 2^n modulo p (be aware of numerics).
// >>> modp((3l), (5l))
// (3l)
// >>> modp((1101l), (101l))
// (2l)
// >>> modp((0l), (101l))
// (1l)
// >>> modp((3l), (11l))
// (8l)
// >>> modp((100l), (101l))
// (1l)
public static long modp(long n, long p) {
if (n == 0) return 1;
long sqrt = modp(n / 2, p);
sqrt = (sqrt * sqrt) % p;
if (n % 2 == 0) {
return sqrt;
} | }
} | return (sqrt * 2) % p; | }
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)) == (3l));
}
}
|
humaneval-HumanEval_6_parse_nested_parens.json-L17 | js | //Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// >>> parse_nested_parens("(()()) ((())) () ((())()())")
// [2, 3, 1, 3]
function parse_nested_parens(paren_string){
var level = 0;
var maxlevel = 0;
var result = [];
for (var i = 0; i < paren_string.length; i++){
if (paren_string[i] == "("){
level += 1;
if (level > maxlevel){
maxlevel = level;
}
} | level -= 1;
}
else if (paren_string[i] == " "){
result.push(maxlevel);
maxlevel = 0;
level = 0;
}
}
result.push(maxlevel);
return result;
}
| else if (paren_string[i] == ")"){ | const assert = require('node:assert');
function test() {
let candidate = parse_nested_parens;
assert.deepEqual(candidate("(()()) ((())) () ((())()())"),[2, 3, 1, 3]);
assert.deepEqual(candidate("() (()) ((())) (((())))"),[1, 2, 3, 4]);
assert.deepEqual(candidate("(()(())((())))"),[4]);
}
test(); |
humaneval-HumanEval_134_check_if_last_char_is_a_letter.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 {
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// >>> checkIfLastCharIsALetter(("apple pie"))
// (false)
// >>> checkIfLastCharIsALetter(("apple pi e"))
// (true)
// >>> checkIfLastCharIsALetter(("apple pi e "))
// (false)
// >>> checkIfLastCharIsALetter((""))
// (false)
public static boolean checkIfLastCharIsALetter(String txt) {
if (txt.length() == 0) {
return false;
}
int len = txt.length();
if (txt.substring(len - 1, len).matches("[A-Z]") || txt.substring(len - 1, len).matches("[a-z]")) {
if (len == 1) { | }
if (txt.substring(len - 2, len - 1).matches(" ")) {
return true;
}
}
return false;
}
} | return true; | }
public static void main(String[] args) {
assert(checkIfLastCharIsALetter(("apple")) == (false));
assert(checkIfLastCharIsALetter(("apple pi e")) == (true));
assert(checkIfLastCharIsALetter(("eeeee")) == (false));
assert(checkIfLastCharIsALetter(("A")) == (true));
assert(checkIfLastCharIsALetter(("Pumpkin pie ")) == (false));
assert(checkIfLastCharIsALetter(("Pumpkin pie 1")) == (false));
assert(checkIfLastCharIsALetter(("")) == (false));
assert(checkIfLastCharIsALetter(("eeeee e ")) == (false));
assert(checkIfLastCharIsALetter(("apple pie")) == (false));
assert(checkIfLastCharIsALetter(("apple pi e ")) == (false));
}
}
|
humaneval-HumanEval_81_numerical_letter_grade.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 {
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array array list of GPAs for some students and you have to write
// a function that can output an array array list of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// >>> gradeEquation((new ArrayList<Float>(Arrays.asList((float)4.0f, (float)3l, (float)1.7f, (float)2l, (float)3.5f))))
// (new ArrayList<String>(Arrays.asList((String)"A+", (String)"B", (String)"C-", (String)"C", (String)"A-")))
public static ArrayList<String> numericalLetterGrade(ArrayList<Float> grades) {
ArrayList<String> letterGrades = new ArrayList<String>();
for (int i = 0; i < grades.size(); i++) {
float currentGrade = grades.get(i);
if (currentGrade == 4.0f) {
letterGrades.add("A+");
} else if (currentGrade > 3.7f) {
letterGrades.add("A");
} else if (currentGrade > 3.3f) { | } else if (currentGrade > 3.0f) {
letterGrades.add("B+");
} else if (currentGrade > 2.7f) {
letterGrades.add("B");
} else if (currentGrade > 2.3f) {
letterGrades.add("B-");
} else if (currentGrade > 2.0f) {
letterGrades.add("C+");
} else if (currentGrade > 1.7f) {
letterGrades.add("C");
} else if (currentGrade > 1.3f) {
letterGrades.add("C-");
} else if (currentGrade > 1.0f) {
letterGrades.add("D+");
} else if (currentGrade > 0.7f) {
letterGrades.add("D");
} else if (currentGrade > 0.0f) {
letterGrades.add("D-");
} else {
letterGrades.add("E");
}
}
return letterGrades;
}
} | letterGrades.add("A-"); | }
public static void main(String[] args) {
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)4.0f, (float)3l, (float)1.7f, (float)2l, (float)3.5f)))).equals((new ArrayList<String>(Arrays.asList((String)"A+", (String)"B", (String)"C-", (String)"C", (String)"A-")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)1.2f)))).equals((new ArrayList<String>(Arrays.asList((String)"D+")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)0.5f)))).equals((new ArrayList<String>(Arrays.asList((String)"D-")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)0.0f)))).equals((new ArrayList<String>(Arrays.asList((String)"E")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)0.3f, (float)1.5f, (float)2.8f, (float)3.3f)))).equals((new ArrayList<String>(Arrays.asList((String)"D", (String)"D-", (String)"C-", (String)"B", (String)"B+")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)0.0f, (float)0.7f)))).equals((new ArrayList<String>(Arrays.asList((String)"E", (String)"D-")))));
}
}
|
humaneval-HumanEval_105_by_length.json-L21 | py | from typing import List
def by_length(arr: List[int]) -> List[str]:
"""
Given an array of integers, sort the integers that are between 1 and 9 inclusive,
reverse the resulting array, and then replace each digit by its corresponding name from
"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
For example:
>>> by_length([2, 1, 1, 4, 5, 8, 2, 3])
['Eight', 'Five', 'Four', 'Three', 'Two', 'Two', 'One', 'One']
If the array is empty, return an empty array:
>>> by_length([])
[]
If the array has any strange number ignore it:
>>> by_length([1, -1, 55])
['One']
"""
| digits.sort()
digits.reverse()
for i in range(len(digits)):
digits[i] = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'][digits[i] - 1]
return digits
| digits = [x for x in arr if 1 <= x <= 9] | def check(candidate):
assert candidate([2, 1, 1, 4, 5, 8, 2, 3]) == ['Eight', 'Five', 'Four', 'Three', 'Two', 'Two', 'One', 'One']
assert candidate([]) == []
assert candidate([1, -1, 55]) == ['One']
assert candidate([1, -1, 3, 2]) == ['Three', 'Two', 'One']
assert candidate([9, 4, 8]) == ['Nine', 'Eight', 'Four']
def test_check():
check(by_length)
test_check()
|
humaneval-HumanEval_125_split_words.json-L12 | js | //Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// >>> split_words("Hello world!")
// ["Hello", "world!"]
// >>> split_words("Hello,world!")
// ["Hello", "world!"]
// >>> split_words("abcdef")
// 3
function split_words(txt){
| return txt.split(' ');
}
else if(txt.includes(',')){
return txt.split(',');
}
else{
let count = 0;
for(let i = 0; i < txt.length; i++){
if(i % 2 != 0){
if(txt[i] == txt[i].toLowerCase()){
count++;
}
}
}
return count;
}
} | if(txt.includes(' ')){ | const assert = require('node:assert');
function test() {
let candidate = split_words;
assert.deepEqual(candidate("Hello world!"),["Hello", "world!"]);
assert.deepEqual(candidate("Hello,world!"),["Hello", "world!"]);
assert.deepEqual(candidate("Hello world,!"),["Hello", "world,!"]);
assert.deepEqual(candidate("Hello,Hello,world !"),["Hello,Hello,world", "!"]);
assert.deepEqual(candidate("abcdef"),3);
assert.deepEqual(candidate("aaabb"),2);
assert.deepEqual(candidate("aaaBb"),1);
assert.deepEqual(candidate(""),0);
}
test(); |
humaneval-HumanEval_65_circular_shift.json-L16 | 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.length;
var res = '';
if(len < shift){
for(var i = len-1; i >= 0; i--){
res += str[i];
} | res = str.substring(len-shift) + str.substring(0, len-shift);
}
return res;
}
| }else{ | 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_10_make_palindrome.json-L13 | js | //Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// >>> make_palindrome("")
// ""
// >>> make_palindrome("cat")
// "catac"
// >>> make_palindrome("cata")
// "catac"
function make_palindrome(string){
var string_length = string.length; | return s == s.split("").reverse().join("");
};
var i = string_length;
while(i > 0){
if(is_palindrome(string.substring(0, i))){
return string + string.substring(0, string_length - i).split("").reverse().join("");
}
i--;
}
return string;
}
| var is_palindrome = function(s){ | const assert = require('node:assert');
function test() {
let candidate = make_palindrome;
assert.deepEqual(candidate(""),"");
assert.deepEqual(candidate("x"),"x");
assert.deepEqual(candidate("xyz"),"xyzyx");
assert.deepEqual(candidate("xyx"),"xyx");
assert.deepEqual(candidate("jerry"),"jerryrrej");
}
test(); |
humaneval-HumanEval_124_valid_date.json-L35 | 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. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// >>> valid_date("03-11-2000")
// true
// >>> valid_date("15-01-2012")
// false
// >>> valid_date("04-0-2040")
// false
// >>> valid_date("06-04-2020")
// true
// >>> valid_date("06/04/2020")
// false
function valid_date(date){
var date_arr = date.split("-");
if(date_arr.length == 3){
var month = parseInt(date_arr[0]);
var day = parseInt(date_arr[1]);
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 || 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;
}
| return true; | 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("01-01-2007"),true);
assert.deepEqual(candidate("03-32-2011"),false);
assert.deepEqual(candidate(""),false);
assert.deepEqual(candidate("04-31-3000"),false);
assert.deepEqual(candidate("06-06-2005"),true);
assert.deepEqual(candidate("21-31-2000"),false);
assert.deepEqual(candidate("04-12-2003"),true);
assert.deepEqual(candidate("04122003"),false);
assert.deepEqual(candidate("20030412"),false);
assert.deepEqual(candidate("2003-04"),false);
assert.deepEqual(candidate("2003-04-12"),false);
assert.deepEqual(candidate("04-2003"),false);
}
test(); |
humaneval-HumanEval_124_valid_date.json-L26 | py | def valid_date(date: str) -> bool:
"""You have to write a function which validates a given date string and
returns True if the date is valid otherwise False.
The date is valid if all of the following rules are satisfied:
1. The date string is not empty.
2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
3. The months should not be less than 1 or higher than 12.
4. The date should be in the format: mm-dd-yyyy
>>> valid_date('03-11-2000')
True
>>> valid_date('15-01-2012')
False
>>> valid_date('04-0-2040')
False
>>> valid_date('06-04-2020')
True
>>> valid_date('06/04/2020')
False
"""
if not date: | days_per_month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
date_list = [int(d) for d in date.split('-')]
if len(date_list) != 3:
return False
if date_list[0] < 1 or date_list[0] > 12:
return False
if date_list[1] < 1 or date_list[1] > days_per_month[date_list[0] - 1]:
return False
if len(str(date_list[2])) != 4:
return False
return True | return False | def check(candidate):
assert candidate('03-11-2000') == True
assert candidate('15-01-2012') == False
assert candidate('04-0-2040') == False
assert candidate('06-04-2020') == True
assert candidate('01-01-2007') == True
assert candidate('03-32-2011') == False
assert candidate('') == False
assert candidate('04-31-3000') == False
assert candidate('06-06-2005') == True
assert candidate('21-31-2000') == False
assert candidate('04-12-2003') == True
assert candidate('04122003') == False
assert candidate('20030412') == False
assert candidate('2003-04') == False
assert candidate('2003-04-12') == False
assert candidate('04-2003') == False
def test_check():
check(valid_date)
test_check()
|
humaneval-HumanEval_93_encode.json-L21 | js | //Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// >>> encode("test")
// "TGST"
// >>> encode("This is a message")
// "tHKS KS C MGSSCGG"
function encode(message){
const vowels = "aeiou";
let result = "";
for(let i = 0; i < message.length; i++){
let letter = message[i];
if(vowels.includes(letter.toLowerCase())){
let newIndex = (letter.charCodeAt(0) + 2 - (letter.toLowerCase() === letter ? 'a'.charCodeAt(0) : 'A'.charCodeAt(0))) % 26;
letter = String.fromCharCode(newIndex + (letter.toLowerCase() === letter ? 'a'.charCodeAt(0) : 'A'.charCodeAt(0)));
}
result += letter.toUpperCase() === letter ? letter.toLowerCase() : letter.toUpperCase(); | return result;
} | } | const assert = require('node:assert');
function test() {
let candidate = encode;
assert.deepEqual(candidate("TEST"),"tgst");
assert.deepEqual(candidate("Mudasir"),"mWDCSKR");
assert.deepEqual(candidate("YES"),"ygs");
assert.deepEqual(candidate("This is a message"),"tHKS KS C MGSSCGG");
assert.deepEqual(candidate("I DoNt KnOw WhAt tO WrItE"),"k dQnT kNqW wHcT Tq wRkTg");
}
test(); |
humaneval-HumanEval_159_eat.json-L36 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array array list of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// >>> eat((5l), (6l), (10l))
// (new ArrayList<Long>(Arrays.asList((long)11l, (long)4l)))
// >>> eat((4l), (8l), (9l))
// (new ArrayList<Long>(Arrays.asList((long)12l, (long)1l)))
// >>> eat((1l), (10l), (10l))
// (new ArrayList<Long>(Arrays.asList((long)11l, (long)0l)))
// >>> eat((2l), (11l), (5l))
// (new ArrayList<Long>(Arrays.asList((long)7l, (long)0l)))
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
public static ArrayList<Long> eat(long number, long need, long remaining) {
| long left = Math.max(0, remaining - need);
return new ArrayList<Long>(Arrays.asList(total, left));
}
} | long total = number + Math.min(need, remaining); | }
public static void main(String[] args) {
assert(eat((5l), (6l), (10l)).equals((new ArrayList<Long>(Arrays.asList((long)11l, (long)4l)))));
assert(eat((4l), (8l), (9l)).equals((new ArrayList<Long>(Arrays.asList((long)12l, (long)1l)))));
assert(eat((1l), (10l), (10l)).equals((new ArrayList<Long>(Arrays.asList((long)11l, (long)0l)))));
assert(eat((2l), (11l), (5l)).equals((new ArrayList<Long>(Arrays.asList((long)7l, (long)0l)))));
assert(eat((4l), (5l), (7l)).equals((new ArrayList<Long>(Arrays.asList((long)9l, (long)2l)))));
assert(eat((4l), (5l), (1l)).equals((new ArrayList<Long>(Arrays.asList((long)5l, (long)0l)))));
}
}
|
humaneval-HumanEval_67_fruit_distribution.json-L20 | js | //In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// >>> fruit_distribution("5 apples and 6 oranges", 19)
// 8
// >>> fruit_distribution("0 apples and 1 oranges", 3)
// 2
// >>> fruit_distribution("2 apples and 3 oranges", 100)
// 95
// >>> fruit_distribution("100 apples and 1 oranges", 120)
// 19
function fruit_distribution(s, n){
let split_s = s.split(" ");
let num_of_apples = parseInt(split_s[0]);
let num_of_oranges = parseInt(split_s[3]);
let sum = num_of_apples + num_of_oranges; | } | return n - sum; | const assert = require('node:assert');
function test() {
let candidate = fruit_distribution;
assert.deepEqual(candidate("5 apples and 6 oranges", 19),8);
assert.deepEqual(candidate("5 apples and 6 oranges", 21),10);
assert.deepEqual(candidate("0 apples and 1 oranges", 3),2);
assert.deepEqual(candidate("1 apples and 0 oranges", 3),2);
assert.deepEqual(candidate("2 apples and 3 oranges", 100),95);
assert.deepEqual(candidate("2 apples and 3 oranges", 5),0);
assert.deepEqual(candidate("1 apples and 100 oranges", 120),19);
}
test(); |
humaneval-HumanEval_153_Strongest_Extension.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 {
// 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 additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array list.
// For example, if you are given "Slices" as the class and an array array list of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// >>> StrongestExtension(("my_class"), (new ArrayList<String>(Arrays.asList((String)"AA", (String)"Be", (String)"CC"))))
// ("my_class.AA")
public static String StrongestExtension(String class_name, ArrayList<String> extensions) {
if (extensions.size() == 0) {
return class_name;
}
int strength = Integer.MIN_VALUE;
String strongest = "";
for (String s : extensions) {
int cap = (int)s.chars().filter(c -> Character.isUpperCase(c)).count();
int sm = (int)s.chars().filter(c -> Character.isLowerCase(c)).count();
int diff = cap - sm;
if (diff > strength) {
strength = diff;
strongest = s;
}
} | }
} | return class_name + "." + strongest; | }
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", (String)"NazeDa", (String)"YEs.WeCaNe", (String)"32145tggg")))).equals(("Boku123.YEs.WeCaNe")));
assert(StrongestExtension(("__YESIMHERE"), (new ArrayList<String>(Arrays.asList((String)"t", (String)"eMptY", (String)"nothing", (String)"zeR00", (String)"NuLl__", (String)"123NoooneB321")))).equals(("__YESIMHERE.NuLl__")));
assert(StrongestExtension(("K"), (new ArrayList<String>(Arrays.asList((String)"Ta", (String)"TAR", (String)"t234An", (String)"cosSo")))).equals(("K.TAR")));
assert(StrongestExtension(("__HAHA"), (new ArrayList<String>(Arrays.asList((String)"Tab", (String)"123", (String)"781345", (String)"-_-")))).equals(("__HAHA.123")));
assert(StrongestExtension(("YameRore"), (new ArrayList<String>(Arrays.asList((String)"HhAas", (String)"okIWILL123", (String)"WorkOut", (String)"Fails", (String)"-_-")))).equals(("YameRore.okIWILL123")));
assert(StrongestExtension(("finNNalLLly"), (new ArrayList<String>(Arrays.asList((String)"Die", (String)"NowW", (String)"Wow", (String)"WoW")))).equals(("finNNalLLly.WoW")));
assert(StrongestExtension(("_"), (new ArrayList<String>(Arrays.asList((String)"Bb", (String)"91245")))).equals(("_.Bb")));
assert(StrongestExtension(("Sp"), (new ArrayList<String>(Arrays.asList((String)"671235", (String)"Bb")))).equals(("Sp.671235")));
}
}
|
humaneval-HumanEval_105_by_length.json-L27 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array array list, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// >>> byLength((new ArrayList<Long>(Arrays.asList((long)2l, (long)1l, (long)1l, (long)4l, (long)5l, (long)8l, (long)2l, (long)3l))))
// (new ArrayList<String>(Arrays.asList((String)"Eight", (String)"Five", (String)"Four", (String)"Three", (String)"Two", (String)"Two", (String)"One", (String)"One")))
// If the array array list is empty, return an empty array array list:
// >>> byLength((new ArrayList<Long>(Arrays.asList())))
// (new ArrayList<String>(Arrays.asList()))
// If the array array list has any strange number ignore it:
// >>> byLength((new ArrayList<Long>(Arrays.asList((long)1l, (long)-1l, (long)55l))))
// (new ArrayList<String>(Arrays.asList((String)"One")))
public static ArrayList<String> byLength(ArrayList<Long> arr) {
String[] a = new String[] {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
ArrayList<String> res = new ArrayList<String>();
ArrayList<Long> good = new ArrayList<Long>();
for (Long i : arr) {
if (i >= 1 && i <= 9) { | }
}
good.sort(new Comparator<Long>() {
public int compare(Long i1, Long i2) {
return i1.compareTo(i2);
}
});
Collections.reverse(good);
for (Long i : good) {
res.add(a[i.intValue() - 1]);
}
return res;
}
} | good.add(i); | }
public static void main(String[] args) {
assert(byLength((new ArrayList<Long>(Arrays.asList((long)2l, (long)1l, (long)1l, (long)4l, (long)5l, (long)8l, (long)2l, (long)3l)))).equals((new ArrayList<String>(Arrays.asList((String)"Eight", (String)"Five", (String)"Four", (String)"Three", (String)"Two", (String)"Two", (String)"One", (String)"One")))));
assert(byLength((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<String>(Arrays.asList()))));
assert(byLength((new ArrayList<Long>(Arrays.asList((long)1l, (long)-1l, (long)55l)))).equals((new ArrayList<String>(Arrays.asList((String)"One")))));
assert(byLength((new ArrayList<Long>(Arrays.asList((long)1l, (long)-1l, (long)3l, (long)2l)))).equals((new ArrayList<String>(Arrays.asList((String)"Three", (String)"Two", (String)"One")))));
assert(byLength((new ArrayList<Long>(Arrays.asList((long)9l, (long)4l, (long)8l)))).equals((new ArrayList<String>(Arrays.asList((String)"Nine", (String)"Eight", (String)"Four")))));
}
}
|
humaneval-HumanEval_124_valid_date.json-L31 | 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. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// >>> valid_date("03-11-2000")
// true
// >>> valid_date("15-01-2012")
// false
// >>> valid_date("04-0-2040")
// false
// >>> valid_date("06-04-2020")
// true
// >>> valid_date("06/04/2020")
// false
function valid_date(date){
var date_arr = date.split("-");
if(date_arr.length == 3){
var month = parseInt(date_arr[0]);
var day = parseInt(date_arr[1]);
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 || month == 12) && (day < 1 || day > 31)){ | }else if((month == 4 || month == 6 || month == 9 || month == 11) && (day < 1 || day > 30)){
return false;
}
return true;
}
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("01-01-2007"),true);
assert.deepEqual(candidate("03-32-2011"),false);
assert.deepEqual(candidate(""),false);
assert.deepEqual(candidate("04-31-3000"),false);
assert.deepEqual(candidate("06-06-2005"),true);
assert.deepEqual(candidate("21-31-2000"),false);
assert.deepEqual(candidate("04-12-2003"),true);
assert.deepEqual(candidate("04122003"),false);
assert.deepEqual(candidate("20030412"),false);
assert.deepEqual(candidate("2003-04"),false);
assert.deepEqual(candidate("2003-04-12"),false);
assert.deepEqual(candidate("04-2003"),false);
}
test(); |
humaneval-HumanEval_139_special_factorial.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 {
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// >>> specialFactorial((4l))
// (288l)
// The function will receive an integer as input and should return the special
// factorial of this integer.
public static long specialFactorial(long n) {
long result = 1;
while (n > 0) {
long local_result = 1;
long temp = n;
while (temp > 0) {
local_result *= temp;
temp--;
}
result *= local_result; | }
return result;
}
} | n--; | }
public static void main(String[] args) {
assert(specialFactorial((4l)) == (288l));
assert(specialFactorial((5l)) == (34560l));
assert(specialFactorial((7l)) == (125411328000l));
assert(specialFactorial((1l)) == (1l));
}
}
|
humaneval-HumanEval_88_sort_array.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 {
// Given an array array list of non-negative integers, return a cojava of the given array array list after sorting,
// you will sort the given array array list in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array array list.
// Examples:
// >>> sortArray((new ArrayList<Long>(Arrays.asList())))
// (new ArrayList<Long>(Arrays.asList()))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)5l))))
// (new ArrayList<Long>(Arrays.asList((long)5l)))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)3l, (long)0l, (long)1l, (long)5l))))
// (new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)3l, (long)0l, (long)1l, (long)5l, (long)6l))))
// (new ArrayList<Long>(Arrays.asList((long)6l, (long)5l, (long)4l, (long)3l, (long)2l, (long)1l, (long)0l)))
public static ArrayList<Long> sortArray(ArrayList<Long> array) {
if(array.size()==0) {
return array;
}
if(array.size()==1) {
return array;
}
if(array.size()>1) {
if((array.get(0)+array.get(array.size()-1))%2==0) {
Collections.sort(array, Collections.reverseOrder());
}
else {
Collections.sort(array);
}
}
return array;
} | } | }
public static void main(String[] args) {
assert(sortArray((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)5l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)3l, (long)0l, (long)1l, (long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)3l, (long)0l, (long)1l, (long)5l, (long)6l)))).equals((new ArrayList<Long>(Arrays.asList((long)6l, (long)5l, (long)4l, (long)3l, (long)2l, (long)1l, (long)0l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)15l, (long)42l, (long)87l, (long)32l, (long)11l, (long)0l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)11l, (long)15l, (long)32l, (long)42l, (long)87l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)21l, (long)14l, (long)23l, (long)11l)))).equals((new ArrayList<Long>(Arrays.asList((long)23l, (long)21l, (long)14l, (long)11l)))));
}
}
|
|
humaneval-HumanEval_115_max_fill.json-L36 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// >>> maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)1l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)0l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l))))), (1l))
// (6l)
// Example 2:
// >>> maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)1l, (long)1l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)1l, (long)1l))))), (2l))
// (5l)
// Example 3:
// >>> maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l))))), (5l))
// (0l)
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
public static long maxFill(ArrayList<ArrayList<Long>> grid, long capacity) {
long count = 0l;
for (ArrayList<Long> well : grid) {
long level = 0l;
for (Long unit : well) {
if (unit == 1l) { | }
}
long units = level / capacity;
if (level % capacity != 0l) {
units += 1l;
}
count += units;
}
return count;
}
} | level += 1l; | }
public static void main(String[] args) {
assert(maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)1l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)0l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l))))), (1l)) == (6l));
assert(maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)1l, (long)1l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)1l, (long)1l))))), (2l)) == (5l));
assert(maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l))))), (5l)) == (0l));
assert(maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l))))), (2l)) == (4l));
assert(maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l))))), (9l)) == (2l));
}
}
|
humaneval-HumanEval_102_choose_num.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 {
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// >>> chooseNum((12l), (15l))
// (14l)
// >>> chooseNum((13l), (12l))
// (-1l)
public static long chooseNum(long x, long y) {
long chosen = -1;
for (long i = x; i <= y; i++) {
if (i % 2 == 0) {
chosen = i;
} | return chosen;
}
} | } | }
public static void main(String[] args) {
assert(chooseNum((12l), (15l)) == (14l));
assert(chooseNum((13l), (12l)) == (-1l));
assert(chooseNum((33l), (12354l)) == (12354l));
assert(chooseNum((5234l), (5233l)) == (-1l));
assert(chooseNum((6l), (29l)) == (28l));
assert(chooseNum((27l), (10l)) == (-1l));
assert(chooseNum((7l), (7l)) == (-1l));
assert(chooseNum((546l), (546l)) == (546l));
}
}
|
humaneval-HumanEval_75_is_multiply_prime.json-L16 | py | def is_multiply_prime(a: int) -> bool:
"""Write a function that returns true if the given number is the multiplication of 3 prime numbers
and false otherwise.
Knowing that (a) is less then 100.
Example:
>>> is_multiply_prime(30)
True
30 = 2 * 3 * 5
"""
n = a
d = 2
prime_factors = []
while d * d <= n:
if n % d == 0:
prime_factors.append(d) | else:
d += 1
if n > 1:
prime_factors.append(n)
if len(prime_factors) == 3:
return True
else:
return False
| n //= d | def check(candidate):
assert candidate(5) == False
assert candidate(30) == True
assert candidate(8) == True
assert candidate(10) == False
assert candidate(125) == True
assert candidate(105) == True
assert candidate(126) == False
assert candidate(729) == False
assert candidate(891) == False
assert candidate(1001) == True
def test_check():
check(is_multiply_prime)
test_check()
|
humaneval-HumanEval_123_get_odd_collatz.json-L21 | js | //Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// >>> get_odd_collatz(5)
// [1, 5]
function get_odd_collatz(n){
var collatz_sequence = []
var odd_numbers = []
var odd_count = 0
collatz_sequence.push(n)
for(var i = 0; i < collatz_sequence.length; i++){
if(collatz_sequence[i]%2 == 0){ | }
else if(collatz_sequence[i]%2 == 1){
collatz_sequence.push(collatz_sequence[i]*3+1)
}
if(collatz_sequence[i]%2 == 1){
odd_numbers.push(collatz_sequence[i])
odd_count += 1
}
if(collatz_sequence[i] == 1){
break
}
}
if(odd_count != 0){
odd_numbers.sort(function(a, b){return a-b})
return odd_numbers
}
else{
odd_numbers.push(1)
return odd_numbers
}
}
| collatz_sequence.push(collatz_sequence[i]/2) | 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_19_sort_numbers.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 {
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// >>> sortNumbers(("three one five"))
// ("one three five")
public static String sortNumbers(String numbers) {
String [] nums = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
HashMap<String, Integer> indexMap = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
indexMap.put(nums[i], i);
}
String [] split = numbers.split(" ");
Arrays.sort(split, new Comparator<String>() {
@Override | return indexMap.get(s1) - indexMap.get(s2);
}
});
return String.join(" ", split);
}
} | public int compare(String s1, String s2) { | }
public static void main(String[] args) {
assert(sortNumbers(("")).equals(("")));
assert(sortNumbers(("three")).equals(("three")));
assert(sortNumbers(("three five nine")).equals(("three five nine")));
assert(sortNumbers(("five zero four seven nine eight")).equals(("zero four five seven eight nine")));
assert(sortNumbers(("six five four three two one zero")).equals(("zero one two three four five six")));
}
}
|
humaneval-HumanEval_123_get_odd_collatz.json-L32 | js | //Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// >>> get_odd_collatz(5)
// [1, 5]
function get_odd_collatz(n){
var collatz_sequence = []
var odd_numbers = []
var odd_count = 0
collatz_sequence.push(n)
for(var i = 0; i < collatz_sequence.length; i++){
if(collatz_sequence[i]%2 == 0){
collatz_sequence.push(collatz_sequence[i]/2)
}
else if(collatz_sequence[i]%2 == 1){
collatz_sequence.push(collatz_sequence[i]*3+1)
}
if(collatz_sequence[i]%2 == 1){
odd_numbers.push(collatz_sequence[i])
odd_count += 1
}
if(collatz_sequence[i] == 1){
break | }
if(odd_count != 0){
odd_numbers.sort(function(a, b){return a-b})
return odd_numbers
}
else{
odd_numbers.push(1)
return odd_numbers
}
}
| } | 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_16_count_distinct_characters.json-L22 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// >>> countDistinctCharacters(("xyzXYZ"))
// (3l)
// >>> countDistinctCharacters(("Jerry"))
// (4l)
public static long countDistinctCharacters(String string) {
long result = 0;
string = string.toLowerCase();
Set<Character> set = new HashSet<Character>();
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
set.add(c);
} | return result;
}
} | result = set.size(); | }
public static void main(String[] args) {
assert(countDistinctCharacters(("")) == (0l));
assert(countDistinctCharacters(("abcde")) == (5l));
assert(countDistinctCharacters(("abcdecadeCADE")) == (5l));
assert(countDistinctCharacters(("aaaaAAAAaaaa")) == (1l));
assert(countDistinctCharacters(("Jerry jERRY JeRRRY")) == (5l));
}
}
|
humaneval-HumanEval_39_prime_fib.json-L20 | js | //prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// >>> prime_fib(1)
// 2
// >>> prime_fib(2)
// 3
// >>> prime_fib(3)
// 5
// >>> prime_fib(4)
// 13
// >>> prime_fib(5)
// 89
function prime_fib(n){
function isPrime(number){
if(number <= 3){
return number > 1;
}
else if(number % 2 == 0 || number % 3 == 0){
return false;
} | for(var i = 5; i * i <= number; i += 6){
if(number % i == 0 || number % (i + 2) == 0){
return false;
}
}
return true;
}
}
function fib(num){
var a = 1, b = 0, temp;
while (num >= 0){
temp = a;
a = a + b;
b = temp;
num--;
}
return b;
}
var res = 0;
var fibNum = 0;
while(res < n){
if(isPrime(fib(fibNum))){
res++;
}
fibNum++;
}
return fib(fibNum - 1);
} | else{ | const assert = require('node:assert');
function test() {
let candidate = prime_fib;
assert.deepEqual(candidate(1),2);
assert.deepEqual(candidate(2),3);
assert.deepEqual(candidate(3),5);
assert.deepEqual(candidate(4),13);
assert.deepEqual(candidate(5),89);
assert.deepEqual(candidate(6),233);
assert.deepEqual(candidate(7),1597);
assert.deepEqual(candidate(8),28657);
assert.deepEqual(candidate(9),514229);
assert.deepEqual(candidate(10),433494437);
}
test(); |
humaneval-HumanEval_81_numerical_letter_grade.json-L30 | py | from typing import List
def numerical_letter_grade(grades: List[float]) -> List[str]:
"""It is the last week of the semester and the teacher has to give the grades
to students. The teacher has been making her own algorithm for grading.
The only problem is, she has lost the code she used for grading.
She has given you a list of GPAs for some students and you have to write
a function that can output a list of letter grades using the following table:
GPA | Letter grade
4.0 A+
> 3.7 A
> 3.3 A-
> 3.0 B+
> 2.7 B
> 2.3 B-
> 2.0 C+
> 1.7 C
> 1.3 C-
> 1.0 D+
> 0.7 D
> 0.0 D-
0.0 E
Example:
>>> grade_equation([4.0, 3, 1.7, 2, 3.5])
['A+', 'B', 'C-', 'C', 'A-']
"""
final = [] | if x == 4.0:
final.append('A+')
elif x > 3.7:
final.append('A')
elif x > 3.3:
final.append('A-')
elif x > 3.0:
final.append('B+')
elif x > 2.7:
final.append('B')
elif x > 2.3:
final.append('B-')
elif x > 2.0:
final.append('C+')
elif x > 1.7:
final.append('C')
elif x > 1.3:
final.append('C-')
elif x > 1.0:
final.append('D+')
elif x > 0.7:
final.append('D')
elif x > 0.0:
final.append('D-')
else:
final.append('E')
return final
| for x in grades: | def check(candidate):
assert candidate([4.0, 3, 1.7, 2, 3.5]) == ['A+', 'B', 'C-', 'C', 'A-']
assert candidate([1.2]) == ['D+']
assert candidate([0.5]) == ['D-']
assert candidate([0.0]) == ['E']
assert candidate([1.0, 0.3, 1.5, 2.8, 3.3]) == ['D', 'D-', 'C-', 'B', 'B+']
assert candidate([0.0, 0.7]) == ['E', 'D-']
def test_check():
check(numerical_letter_grade)
test_check()
|
humaneval-HumanEval_98_count_upper.json-L18 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// >>> countUpper(("aBCdEf"))
// (1l)
// >>> countUpper(("abcdefg"))
// (0l)
// >>> countUpper(("dBBE"))
// (0l)
public static long countUpper(String s) {
| .filter(i -> i % 2 == 0)
.filter(i -> s.charAt(i) == 'A' || s.charAt(i) == 'E' || s.charAt(i) == 'I' || s.charAt(i) == 'O' || s.charAt(i) == 'U')
.count();
}
} | return (long) IntStream.range(0, s.length()) | }
public static void main(String[] args) {
assert(countUpper(("aBCdEf")) == (1l));
assert(countUpper(("abcdefg")) == (0l));
assert(countUpper(("dBBE")) == (0l));
assert(countUpper(("B")) == (0l));
assert(countUpper(("U")) == (1l));
assert(countUpper(("")) == (0l));
assert(countUpper(("EEEE")) == (2l));
}
}
|
humaneval-HumanEval_61_correct_bracketing.json-L21 | 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_bracketing(')(()')
False
"""
count = 0
for char in brackets:
if char == '(':
count += 1
elif char == ')':
count -= 1
if count < 0: | return count == 0
| return False | def check(candidate):
assert candidate('()') == True
assert candidate('(()())') == True
assert candidate('()()(()())()') == True
assert candidate('()()((()()())())(()()(()))') == True
assert candidate('((()())))') == False
assert candidate(')(()') == False
assert candidate('(') == False
assert candidate('((((') == False
assert candidate(')') == False
assert candidate('(()') == False
assert candidate('()()(()())())(()') == False
assert candidate('()()(()())()))()') == False
def test_check():
check(correct_bracketing)
test_check()
|
humaneval-HumanEval_104_unique_digits.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 {
// Given an array array list of positive integers x. return a sorted array list of all
// elements that hasn't any even digit.
// Note: Returned array list should be sorted in increasing order.
// For example:
// >>> uniqueDigits((new ArrayList<Long>(Arrays.asList((long)15l, (long)33l, (long)1422l, (long)1l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)15l, (long)33l)))
// >>> uniqueDigits((new ArrayList<Long>(Arrays.asList((long)152l, (long)323l, (long)1422l, (long)10l))))
// (new ArrayList<Long>(Arrays.asList()))
public static ArrayList<Long> uniqueDigits(ArrayList<Long> x) {
ArrayList<Long> b = new ArrayList<Long>();
for (int i = 0; i < x.size(); i++) {
if (x.get(i) < 0) {
x.set(i, x.get(i)*(long)-1);
}
boolean unique = true;
long z = x.get(i);
while (z > 0) {
long y = z % 10;
if (y % 2 == 0) {
unique = false;
break;
} | }
if (unique) {
b.add(x.get(i));
}
}
Collections.sort(b);
return b;
}
} | z = z / 10; | }
public static void main(String[] args) {
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)15l, (long)33l, (long)1422l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)15l, (long)33l)))));
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)152l, (long)323l, (long)1422l, (long)10l)))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)12345l, (long)2033l, (long)111l, (long)151l)))).equals((new ArrayList<Long>(Arrays.asList((long)111l, (long)151l)))));
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)135l, (long)103l, (long)31l)))).equals((new ArrayList<Long>(Arrays.asList((long)31l, (long)135l)))));
}
}
|
humaneval-HumanEval_108_count_nums.json-L15 | js | //Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// >>> count_nums([])
// 0
// >>> count_nums([-1, 11, -11])
// 1
// >>> count_nums([1, 1, 2])
// 3
function count_nums(arr){
if(!arr.length) {
return 0;
} | for(var i = 0; i < arr.length; i++) {
var sum = 0;
var str = arr[i].toString();
if(str[0] === '-') {
sum += Number(str[0] + str[1]);
for(var j = 2; j < str.length; j++) {
sum += Number(str[j]);
}
} else {
for(var k = 0; k < str.length; k++) {
sum += Number(str[k]);
}
}
if(sum > 0) {
count++;
}
}
return count;
} | var count = 0; | const assert = require('node:assert');
function test() {
let candidate = count_nums;
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([-1, -2, 0]),0);
assert.deepEqual(candidate([1, 1, 2, -2, 3, 4, 5]),6);
assert.deepEqual(candidate([1, 6, 9, -6, 0, 1, 5]),5);
assert.deepEqual(candidate([1, 100, 98, -7, 1, -1]),4);
assert.deepEqual(candidate([12, 23, 34, -45, -56, 0]),5);
assert.deepEqual(candidate([0, 1]),1);
assert.deepEqual(candidate([1]),1);
}
test(); |
humaneval-HumanEval_114_minSubArraySum.json-L19 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of integers nums, find the minimum sum of any non-empty sub-array array list
// of nums.
// Example
// >>> minSubArraySum((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l, (long)1l, (long)2l, (long)4l))))
// (1l)
// >>> minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l))))
// (-6l)
public static long minSubArraySum(ArrayList<Long> nums) {
long minSum = Long.MAX_VALUE;
long prevMinSum = Long.MAX_VALUE; | long currSum = nums.get(i);
if (currSum < prevMinSum) {
prevMinSum = currSum;
}
if (currSum < minSum) {
minSum = currSum;
}
for (int j = i + 1; j < nums.size(); j++) {
currSum += nums.get(j);
if (currSum < prevMinSum) {
prevMinSum = currSum;
}
if (currSum < minSum) {
minSum = currSum;
}
}
}
return minSum;
}
} | for (int i = 0; i < nums.size(); i++) { | }
public static void main(String[] args) {
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l, (long)1l, (long)2l, (long)4l)))) == (1l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l)))) == (-6l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l, (long)2l, (long)-10l)))) == (-14l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-9999999999999999l)))) == (-9999999999999999l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)0l, (long)10l, (long)20l, (long)1000000l)))) == (0l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l, (long)10l, (long)-5l)))) == (-6l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)100l, (long)-1l, (long)-2l, (long)-3l, (long)10l, (long)-5l)))) == (-6l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)10l, (long)11l, (long)13l, (long)8l, (long)3l, (long)4l)))) == (3l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)100l, (long)-33l, (long)32l, (long)-1l, (long)0l, (long)-2l)))) == (-33l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-10l)))) == (-10l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)7l)))) == (7l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)1l, (long)-1l)))) == (-1l));
}
}
|
humaneval-HumanEval_117_select_words.json-L48 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array array list of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array list.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// >>> selectWords(("Mary had a little lamb"), (4l))
// (new ArrayList<String>(Arrays.asList((String)"little")))
// >>> selectWords(("Mary had a little lamb"), (3l))
// (new ArrayList<String>(Arrays.asList((String)"Mary", (String)"lamb")))
// >>> selectWords(("simple white space"), (2l))
// (new ArrayList<String>(Arrays.asList()))
// >>> selectWords(("Hello world"), (4l))
// (new ArrayList<String>(Arrays.asList((String)"world")))
// >>> selectWords(("Uncle sam"), (3l))
// (new ArrayList<String>(Arrays.asList((String)"Uncle")))
public static ArrayList<String> selectWords(String s, long n) {
ArrayList<String> ret = new ArrayList<String>();
String[] words = s.split(" ");
for (String word : words) {
String wordInLowerCase = word.toLowerCase();
long consonants = 0l;
for (char c : wordInLowerCase.toCharArray()) {
switch (c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
break;
default:
consonants++;
break;
}
}
if (consonants == n) {
ret.add(word);
}
} | }
} | return ret; | }
public static void main(String[] args) {
assert(selectWords(("Mary had a little lamb"), (4l)).equals((new ArrayList<String>(Arrays.asList((String)"little")))));
assert(selectWords(("Mary had a little lamb"), (3l)).equals((new ArrayList<String>(Arrays.asList((String)"Mary", (String)"lamb")))));
assert(selectWords(("simple white space"), (2l)).equals((new ArrayList<String>(Arrays.asList()))));
assert(selectWords(("Hello world"), (4l)).equals((new ArrayList<String>(Arrays.asList((String)"world")))));
assert(selectWords(("Uncle sam"), (3l)).equals((new ArrayList<String>(Arrays.asList((String)"Uncle")))));
assert(selectWords((""), (4l)).equals((new ArrayList<String>(Arrays.asList()))));
assert(selectWords(("a b c d e f"), (1l)).equals((new ArrayList<String>(Arrays.asList((String)"b", (String)"c", (String)"d", (String)"f")))));
}
}
|
humaneval-HumanEval_71_triangle_area.json-L17 | js | //Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// >>> triangle_area(3, 4, 5)
// 6.0
// >>> triangle_area(1, 2, 10)
// -1
function triangle_area(a, b, c){
if(a+b>c && a+c>b && b+c>a){
var s = (a+b+c)/2;
return Math.sqrt(s*(s-a)*(s-b)*(s-c)).toFixed(2);
}else{
return -1; | }
| } | const assert = require('node:assert');
function test() {
let candidate = triangle_area;
assert.deepEqual(candidate(3, 4, 5),6.0);
assert.deepEqual(candidate(1, 2, 10),-1);
assert.deepEqual(candidate(4, 8, 5),8.18);
assert.deepEqual(candidate(2, 2, 2),1.73);
assert.deepEqual(candidate(1, 2, 3),-1);
assert.deepEqual(candidate(10, 5, 7),16.25);
assert.deepEqual(candidate(2, 6, 3),-1);
assert.deepEqual(candidate(1, 1, 1),0.43);
assert.deepEqual(candidate(2, 2, 10),-1);
}
test(); |
humaneval-HumanEval_35_max_element.json-L17 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return maximum element in the array list.
// >>> maxElement((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (3l)
// >>> maxElement((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)-5l, (long)2l, (long)-3l, (long)3l, (long)9l, (long)0l, (long)123l, (long)1l, (long)-10l))))
// (123l)
public static long maxElement(ArrayList<Long> l) {
Long max = Long.MIN_VALUE;
for (int i = 0; i < l.size(); i += 1) { | max = l.get(i);
}
}
return max;
}
} | if (l.get(i) > max) { | }
public static void main(String[] args) {
assert(maxElement((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))) == (3l));
assert(maxElement((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)-5l, (long)2l, (long)-3l, (long)3l, (long)9l, (long)0l, (long)124l, (long)1l, (long)-10l)))) == (124l));
}
}
|
humaneval-HumanEval_70_strange_sort_list.json-L18 | py | from typing import List
def strange_sort_list(lst: List[int]) -> List[int]:
"""
Given list of integers, return list in strange order.
Strange sorting, is when you start with the minimum value,
then maximum of the remaining integers, then minimum and so on.
Examples:
>>> strange_sort_list([1, 2, 3, 4])
[1, 4, 2, 3]
>>> strange_sort_list([5, 5, 5, 5])
[5, 5, 5, 5]
>>> strange_sort_list([])
[]
"""
lst = sorted(lst) | while lst:
out.append(lst.pop(0))
if not lst:
break
out.append(lst.pop())
return out | out = [] | def check(candidate):
assert candidate([1, 2, 3, 4]) == [1, 4, 2, 3]
assert candidate([5, 6, 7, 8, 9]) == [5, 9, 6, 8, 7]
assert candidate([1, 2, 3, 4, 5]) == [1, 5, 2, 4, 3]
assert candidate([5, 6, 7, 8, 9, 1]) == [1, 9, 5, 8, 6, 7]
assert candidate([5, 5, 5, 5]) == [5, 5, 5, 5]
assert candidate([]) == []
assert candidate([1, 2, 3, 4, 5, 6, 7, 8]) == [1, 8, 2, 7, 3, 6, 4, 5]
assert candidate([0, 2, 2, 2, 5, 5, -5, -5]) == [-5, 5, -5, 5, 0, 2, 2, 2]
assert candidate([111111]) == [111111]
def test_check():
check(strange_sort_list)
test_check()
|
humaneval-HumanEval_126_is_sorted.json-L56 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of numbers, return whether or not they are sorted
// in ascending order. If array list has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l))))
// (false)
public static boolean isSorted(ArrayList<Long> lst) {
if (lst.size() == 0) {
return true;
}
else {
int running_max = 0;
int previous_number = 0;
boolean first_time = true;
boolean seen_2_in_a_row = false;
for (Long number : lst) {
if (first_time) {
first_time = false;
previous_number = number.intValue();
running_max = number.intValue();
}
else {
if (running_max > number.intValue()) {
return false;
}
else {
if (previous_number == number.intValue()) {
if (seen_2_in_a_row) {
return false;
}
else {
seen_2_in_a_row = true;
} | else {
seen_2_in_a_row = false;
}
previous_number = number.intValue();
running_max = number.intValue();
}
}
}
return true;
}
}
} | } | }
public static void main(String[] args) {
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)5l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList()))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)1l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)3l, (long)3l, (long)4l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))) == (true));
}
}
|
humaneval-HumanEval_10_make_palindrome.json-L17 | js | //Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// >>> make_palindrome("")
// ""
// >>> make_palindrome("cat")
// "catac"
// >>> make_palindrome("cata")
// "catac"
function make_palindrome(string){
var string_length = string.length;
var is_palindrome = function(s){
return s == s.split("").reverse().join("");
};
var i = string_length; | if(is_palindrome(string.substring(0, i))){
return string + string.substring(0, string_length - i).split("").reverse().join("");
}
i--;
}
return string;
}
| while(i > 0){ | const assert = require('node:assert');
function test() {
let candidate = make_palindrome;
assert.deepEqual(candidate(""),"");
assert.deepEqual(candidate("x"),"x");
assert.deepEqual(candidate("xyz"),"xyzyx");
assert.deepEqual(candidate("xyx"),"xyx");
assert.deepEqual(candidate("jerry"),"jerryrrej");
}
test(); |
humaneval-HumanEval_56_correct_bracketing.json-L27 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correctBracketing(("<"))
// (false)
// >>> correctBracketing(("<>"))
// (true)
// >>> correctBracketing(("<<><>>"))
// (true)
// >>> correctBracketing(("><<>"))
// (false)
public static boolean correctBracketing(String brackets) {
int open = 0;
for (int i = 0; i < brackets.length(); i++) {
char c = brackets.charAt(i);
if (c == '<') {
open++;
} else {
open--; | if (open < 0) {
return false;
}
}
return open == 0;
}
} | } | }
public static void main(String[] args) {
assert(correctBracketing(("<>")) == (true));
assert(correctBracketing(("<<><>>")) == (true));
assert(correctBracketing(("<><><<><>><>")) == (true));
assert(correctBracketing(("<><><<<><><>><>><<><><<>>>")) == (true));
assert(correctBracketing(("<<<><>>>>")) == (false));
assert(correctBracketing(("><<>")) == (false));
assert(correctBracketing(("<")) == (false));
assert(correctBracketing(("<<<<")) == (false));
assert(correctBracketing((">")) == (false));
assert(correctBracketing(("<<>")) == (false));
assert(correctBracketing(("<><><<><>><>><<>")) == (false));
assert(correctBracketing(("<><><<><>><>>><>")) == (false));
}
}
|
humaneval-HumanEval_160_do_algebra.json-L54 | js | //Given two arrays operator, and operand. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
function do_algebra(operator, operand){
let do_again;
let count = 0;
let temp;
let answer;
while(count < operator.length){
switch(operator[count]){
case '*':
operand[count] = operand[count] * operand[count + 1];
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
case '//':
operand[count] = Math.floor(operand[count] / operand[count + 1]);
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
case '**':
operand[count] = Math.pow(operand[count], operand[count + 1]);
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
default:
count++;
do_again = false;
}
}
answer = operand[0];
operand.splice(0, 1); | switch(operator[0]){
case '+':
answer += operand[0];
break;
case '-':
answer -= operand[0];
break;
}
operand.splice(0, 1);
operator.splice(0, 1);
}
return answer;
}
| while(operand.length > 0){ | const assert = require('node:assert');
function test() {
let candidate = do_algebra;
assert.deepEqual(candidate(["**", "*", "+"], [2, 3, 4, 5]),37);
assert.deepEqual(candidate(["+", "*", "-"], [2, 3, 4, 5]),9);
assert.deepEqual(candidate(["//", "*"], [7, 3, 4]),8);
}
test(); |
humaneval-HumanEval_47_median.json-L9 | 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); | return (sorted[middle - 1] + sorted[middle]) / 2;
} else {
return sorted[middle];
}
}
| if (l.length % 2 === 0) { | const assert = require('node:assert');
function test() {
let candidate = median;
assert.deepEqual(candidate([3, 1, 2, 4, 5]),3);
assert.deepEqual(candidate([-10, 4, 6, 1000, 10, 20]),8.0);
assert.deepEqual(candidate([5]),5);
assert.deepEqual(candidate([6, 5]),5.5);
assert.deepEqual(candidate([8, 1, 3, 9, 9, 2, 7]),7);
}
test(); |
humaneval-HumanEval_149_sorted_list_sum.json-L42 | js | //Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// >>> list_sort(["aa", "a", "aaa"])
// ["aa"]
// >>> list_sort(["ab", "a", "aaa", "cd"])
// ["ab", "cd"]
function sorted_list_sum(lst){
var result = [];
for(var i = 0; i < lst.length; i++){
if(lst[i].length % 2 == 0){
result.push(lst[i]);
}
}
return result.sort(function(a, b){
if(a.length < b.length){
return -1;
}
else if(a.length > b.length){
return 1;
}
else{
if(a < b){
return -1;
}
else if(a > b){
return 1;
}
else{
return 0;
}
}
}); | var a = ["aa", "a", "aaa"];
var b = ["ab", "a", "aaa", "cd"]; | } | const assert = require('node:assert');
function test() {
let candidate = sorted_list_sum;
assert.deepEqual(candidate(["aa", "a", "aaa"]),["aa"]);
assert.deepEqual(candidate(["school", "AI", "asdf", "b"]),["AI", "asdf", "school"]);
assert.deepEqual(candidate(["d", "b", "c", "a"]),[]);
assert.deepEqual(candidate(["d", "dcba", "abcd", "a"]),["abcd", "dcba"]);
assert.deepEqual(candidate(["AI", "ai", "au"]),["AI", "ai", "au"]);
assert.deepEqual(candidate(["a", "b", "b", "c", "c", "a"]),[]);
assert.deepEqual(candidate(["aaaa", "bbbb", "dd", "cc"]),["cc", "dd", "aaaa", "bbbb"]);
}
test(); |
humaneval-HumanEval_138_is_equal_to_sum_even.json-L28 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// >>> isEqualToSumEven((4l))
// (false)
// >>> isEqualToSumEven((6l))
// (false)
// >>> isEqualToSumEven((8l))
// (true)
public static boolean isEqualToSumEven(long n) {
if (n < 4) {
return false;
}
long d = 2;
if (n % 2 == 1) {
d = 1;
}
long minX = d;
long maxX = n / 4;
while (minX <= maxX) { | long y = n - 2 * x;
if (y % 2 == 1) {
y--;
}
if (2 * x + y < n) {
minX = x + 1;
} else if (2 * x + y > n) {
maxX = x - 1;
} else {
return true;
}
}
return false;
}
} | long x = (minX + maxX) / 2; | }
public static void main(String[] args) {
assert(isEqualToSumEven((4l)) == (false));
assert(isEqualToSumEven((6l)) == (false));
assert(isEqualToSumEven((8l)) == (true));
assert(isEqualToSumEven((10l)) == (true));
assert(isEqualToSumEven((11l)) == (false));
assert(isEqualToSumEven((12l)) == (true));
assert(isEqualToSumEven((13l)) == (false));
assert(isEqualToSumEven((16l)) == (true));
}
}
|
humaneval-HumanEval_119_match_parens.json-L21 | py | from typing import List
def match_parens(lst: List[str]) -> str:
"""
You are given a list of two strings, both strings consist of open
parentheses '(' or close parentheses ')' only.
Your job is to check if it is possible to concatenate the two strings in
some order, that the resulting string will be good.
A string S is considered to be good if and only if all parentheses in S
are balanced. For example: the string '(())()' is good, while the string
'())' is not.
Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
Examples:
>>> match_parens(['()(', ')'])
'Yes'
>>> match_parens([')', ')'])
'No'
"""
s1, s2 = lst | for s in strings:
open_parens = 0
close_parens = 0
for c in s:
if c == '(':
open_parens += 1
elif c == ')':
if open_parens:
open_parens -= 1
else:
close_parens += 1
if open_parens == 0 and close_parens == 0:
return 'Yes'
return 'No'
| strings = [s1 + s2, s2 + s1] | def check(candidate):
assert candidate(['()(', ')']) == 'Yes'
assert candidate([')', ')']) == 'No'
assert candidate(['(()(())', '())())']) == 'No'
assert candidate([')())', '(()()(']) == 'Yes'
assert candidate(['(())))', '(()())((']) == 'Yes'
assert candidate(['()', '())']) == 'No'
assert candidate(['(()(', '()))()']) == 'Yes'
assert candidate(['((((', '((())']) == 'No'
assert candidate([')(()', '(()(']) == 'No'
assert candidate([')(', ')(']) == 'No'
assert candidate(['(', ')']) == 'Yes'
assert candidate([')', '(']) == 'Yes'
def test_check():
check(match_parens)
test_check()
|
humaneval-HumanEval_111_histogram.json-L43 | js | //Given a string representing a space separated lowercase letters, return an object
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// >>> histogram("a b c")
// {"a": 1, "b": 1, "c": 1}
// >>> histogram("a b b a")
// {"a": 2, "b": 2}
// >>> histogram("a b c a b")
// {"a": 2, "b": 2}
// >>> histogram("b b b b a")
// {"b": 4}
// >>> histogram("")
// {}
function histogram(test){
if (test.length === 0){
return {};
}
var lst = test.split(" ");
var count = {};
for (var i = 0; i < lst.length; i++){
if (count[lst[i]]){
count[lst[i]] += 1;
}
else{
count[lst[i]] = 1;
}
}
console.log(count);
var max = 0;
var result = {};
for (var key in count){
if (count[key] > max){
max = count[key];
result = {};
result[key] = max;
}
else if (count[key] === max){
result[key] = max;
}
}
return result; | } | const assert = require('node:assert');
function test() {
let candidate = histogram;
assert.deepEqual(candidate("a b b a"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c a b"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c d g"),{"a": 1, "b": 1, "c": 1, "d": 1, "g": 1});
assert.deepEqual(candidate("r t g"),{"r": 1, "t": 1, "g": 1});
assert.deepEqual(candidate("b b b b a"),{"b": 4});
assert.deepEqual(candidate("r t g"),{"r": 1, "t": 1, "g": 1});
assert.deepEqual(candidate(""),{});
assert.deepEqual(candidate("a"),{"a": 1});
}
test(); |
|
humaneval-HumanEval_118_get_closest_vowel.json-L30 | js | //You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// >>> get_closest_vowel("yogurt")
// "u"
// >>> get_closest_vowel("FULL")
// "U"
// >>> get_closest_vowel("quick")
// ""
// >>> get_closest_vowel("ab")
// ""
function get_closest_vowel(word){
let vowels = ["a", "e", "i", "o", "u"];
let i = word.length - 1;
let result = [];
if (word.length === 1) {
return ""
} else {
while (i >= 0) {
if (vowels.includes(word[i])) {
if (i > 0 && i < word.length - 1) {
if (!vowels.includes(word[i-1]) && !vowels.includes(word[i+1])) {
result.push(word[i]);
}
}
} | }
if (result.length === 0) {
return ""
} else {
return result[0];
}
}
} | i--; | const assert = require('node:assert');
function test() {
let candidate = get_closest_vowel;
assert.deepEqual(candidate("yogurt"),"u");
assert.deepEqual(candidate("full"),"u");
assert.deepEqual(candidate("easy"),"");
assert.deepEqual(candidate("eAsy"),"");
assert.deepEqual(candidate("ali"),"");
assert.deepEqual(candidate("bad"),"a");
assert.deepEqual(candidate("most"),"o");
assert.deepEqual(candidate("ab"),"");
assert.deepEqual(candidate("ba"),"");
assert.deepEqual(candidate("quick"),"");
assert.deepEqual(candidate("anime"),"i");
assert.deepEqual(candidate("Asia"),"");
assert.deepEqual(candidate("Above"),"o");
}
test(); |
humaneval-HumanEval_108_count_nums.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 {
// Write a function count_nums which takes an array array list of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// >>> countNums((new ArrayList<Long>(Arrays.asList())))
// (0l)
// >>> countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)11l, (long)-11l))))
// (1l)
// >>> countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l))))
// (3l)
public static long countNums(ArrayList<Long> arr) {
| for (long i : arr) {
String str = String.valueOf(i);
int sum = 0;
if (str.startsWith("-")) {
sum = sum - (int) Character.getNumericValue(str.charAt(1));
for (int j = 2; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j));
}
} else {
for (int j = 0; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j));
}
}
if (sum > 0) {
result++;
}
}
return result;
}
} | long result = 0l; | }
public static void main(String[] args) {
assert(countNums((new ArrayList<Long>(Arrays.asList()))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)0l)))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l, (long)-2l, (long)3l, (long)4l, (long)5l)))) == (6l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)6l, (long)9l, (long)-6l, (long)0l, (long)1l, (long)5l)))) == (5l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)100l, (long)98l, (long)-7l, (long)1l, (long)-1l)))) == (4l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)12l, (long)23l, (long)34l, (long)-45l, (long)-56l, (long)0l)))) == (5l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l)))) == (1l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l)))) == (1l));
}
}
|
humaneval-HumanEval_81_numerical_letter_grade.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 {
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array array list of GPAs for some students and you have to write
// a function that can output an array array list of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// >>> gradeEquation((new ArrayList<Float>(Arrays.asList((float)4.0f, (float)3l, (float)1.7f, (float)2l, (float)3.5f))))
// (new ArrayList<String>(Arrays.asList((String)"A+", (String)"B", (String)"C-", (String)"C", (String)"A-")))
public static ArrayList<String> numericalLetterGrade(ArrayList<Float> grades) {
ArrayList<String> letterGrades = new ArrayList<String>();
for (int i = 0; i < grades.size(); i++) {
float currentGrade = grades.get(i); | letterGrades.add("A+");
} else if (currentGrade > 3.7f) {
letterGrades.add("A");
} else if (currentGrade > 3.3f) {
letterGrades.add("A-");
} else if (currentGrade > 3.0f) {
letterGrades.add("B+");
} else if (currentGrade > 2.7f) {
letterGrades.add("B");
} else if (currentGrade > 2.3f) {
letterGrades.add("B-");
} else if (currentGrade > 2.0f) {
letterGrades.add("C+");
} else if (currentGrade > 1.7f) {
letterGrades.add("C");
} else if (currentGrade > 1.3f) {
letterGrades.add("C-");
} else if (currentGrade > 1.0f) {
letterGrades.add("D+");
} else if (currentGrade > 0.7f) {
letterGrades.add("D");
} else if (currentGrade > 0.0f) {
letterGrades.add("D-");
} else {
letterGrades.add("E");
}
}
return letterGrades;
}
} | if (currentGrade == 4.0f) { | }
public static void main(String[] args) {
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)4.0f, (float)3l, (float)1.7f, (float)2l, (float)3.5f)))).equals((new ArrayList<String>(Arrays.asList((String)"A+", (String)"B", (String)"C-", (String)"C", (String)"A-")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)1.2f)))).equals((new ArrayList<String>(Arrays.asList((String)"D+")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)0.5f)))).equals((new ArrayList<String>(Arrays.asList((String)"D-")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)0.0f)))).equals((new ArrayList<String>(Arrays.asList((String)"E")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)0.3f, (float)1.5f, (float)2.8f, (float)3.3f)))).equals((new ArrayList<String>(Arrays.asList((String)"D", (String)"D-", (String)"C-", (String)"B", (String)"B+")))));
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)0.0f, (float)0.7f)))).equals((new ArrayList<String>(Arrays.asList((String)"E", (String)"D-")))));
}
}
|
humaneval-HumanEval_22_filter_integers.json-L7 | js | //Filter given array of any jsthon values only for integers
// >>> filter_integers(["a", 3.14, 5])
// [5]
// >>> filter_integers([1, 2, 3, "abc", {}, []])
// [1, 2, 3]
function filter_integers(values){
| values.forEach(function(value){
if(typeof value === "number" && value % 1 === 0){
result.push(value);
}
});
return result;
}
| var result = []; | const assert = require('node:assert');
function test() {
let candidate = filter_integers;
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([4, {}, [], 23.2, 9, "adasd"]),[4, 9]);
assert.deepEqual(candidate([3, "c", 3, 3, "a", "b"]),[3, 3, 3]);
}
test(); |
humaneval-HumanEval_155_even_odd_count.json-L19 | 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
odd_count = 0
for ch in num_str:
digit = int(ch)
if digit % 2 == 0:
even_count += 1 | odd_count += 1
return even_count, odd_count
| else: | 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 test_check():
check(even_odd_count)
test_check()
|
humaneval-HumanEval_160_do_algebra.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 two array lists operator, and operand. The first array list has basic algebra operations, and
// the second array list is an array array list of integers. Use the two given array lists to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array array list = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array list is equal to the length of operand array list minus one.
// Operand is an array array list of of non-negative integers.
// Operator array list has at least one operator, and operand array list has at least two operands.
public static long doAlgebra(ArrayList<String> op, ArrayList<Long> operand) {
ArrayList<Long> list = new ArrayList<>();
list.add(operand.get(0));
for (int i = 0; i < op.size(); i++) {
if (op.get(i).equals("+"))
list.add(operand.get(i + 1));
else if (op.get(i).equals("-"))
list.add(-operand.get(i + 1));
else if (op.get(i).equals("*"))
list.set(list.size() - 1, list.get(list.size() - 1) * operand.get(i + 1));
else if (op.get(i).equals("//"))
list.set(list.size() - 1, list.get(list.size() - 1) / operand.get(i + 1));
else if (op.get(i).equals("**"))
list.set(list.size() - 1, (long) Math.pow(list.get(list.size() - 1), operand.get(i + 1))); | return list.stream().mapToLong(x -> x).sum();
}
} | } | }
public static void main(String[] args) {
assert(doAlgebra((new ArrayList<String>(Arrays.asList((String)"**", (String)"*", (String)"+"))), (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l, (long)5l)))) == (37l));
assert(doAlgebra((new ArrayList<String>(Arrays.asList((String)"+", (String)"*", (String)"-"))), (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l, (long)5l)))) == (9l));
assert(doAlgebra((new ArrayList<String>(Arrays.asList((String)"//", (String)"*"))), (new ArrayList<Long>(Arrays.asList((long)7l, (long)3l, (long)4l)))) == (8l));
}
}
|
humaneval-HumanEval_149_sorted_list_sum.json-L21 | js | //Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// >>> list_sort(["aa", "a", "aaa"])
// ["aa"]
// >>> list_sort(["ab", "a", "aaa", "cd"])
// ["ab", "cd"]
function sorted_list_sum(lst){
var result = [];
for(var i = 0; i < lst.length; i++){
if(lst[i].length % 2 == 0){
result.push(lst[i]); | }
return result.sort(function(a, b){
if(a.length < b.length){
return -1;
}
else if(a.length > b.length){
return 1;
}
else{
if(a < b){
return -1;
}
else if(a > b){
return 1;
}
else{
return 0;
}
}
});
}
var a = ["aa", "a", "aaa"];
var b = ["ab", "a", "aaa", "cd"]; | } | const assert = require('node:assert');
function test() {
let candidate = sorted_list_sum;
assert.deepEqual(candidate(["aa", "a", "aaa"]),["aa"]);
assert.deepEqual(candidate(["school", "AI", "asdf", "b"]),["AI", "asdf", "school"]);
assert.deepEqual(candidate(["d", "b", "c", "a"]),[]);
assert.deepEqual(candidate(["d", "dcba", "abcd", "a"]),["abcd", "dcba"]);
assert.deepEqual(candidate(["AI", "ai", "au"]),["AI", "ai", "au"]);
assert.deepEqual(candidate(["a", "b", "b", "c", "c", "a"]),[]);
assert.deepEqual(candidate(["aaaa", "bbbb", "dd", "cc"]),["cc", "dd", "aaaa", "bbbb"]);
}
test(); |
humaneval-HumanEval_152_compare.json-L15 | js | //I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// >>> compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])
// [0, 0, 0, 0, 3, 3]
// >>> compare([0, 5, 0, 0, 0, 4], [4, 1, 1, 0, 0, -2])
// [4, 4, 1, 0, 0, 6]
function compare(game, guess){
let result = []; | if(game[i] === guess[i]){
result.push(0);
} else {
result.push(Math.abs(game[i] - guess[i]));
}
}
return result;
}
| for(let i = 0; i < game.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = compare;
assert.deepEqual(candidate([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2]),[0, 0, 0, 0, 3, 3]);
assert.deepEqual(candidate([0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]),[0, 0, 0, 0, 0, 0]);
assert.deepEqual(candidate([1, 2, 3], [-1, -2, -3]),[2, 4, 6]);
assert.deepEqual(candidate([1, 2, 3, 5], [-1, 2, 3, 4]),[2, 0, 0, 1]);
}
test(); |
humaneval-HumanEval_71_triangle_area.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 the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// >>> triangleArea((3l), (4l), (5l))
// (6.0f)
// >>> triangleArea((1l), (2l), (10l))
// (float)-1l
public static float triangleArea(long a, long b, long c) {
if(a + b > c && a + c > b && b + c > a) {
float s = (a + b + c) / 2.0f;
float area = (float)Math.sqrt(s * (s - a) * (s - b) * (s - c));
return (float)Math.round(area * 100) / 100;
} | }
} | return -1; | }
public static void main(String[] args) {
assert(triangleArea((3l), (4l), (5l)) == (6.0f));
assert(triangleArea((1l), (2l), (10l)) == (float)-1l);
assert(triangleArea((4l), (8l), (5l)) == (8.18f));
assert(triangleArea((2l), (2l), (2l)) == (1.73f));
assert(triangleArea((1l), (2l), (3l)) == (float)-1l);
assert(triangleArea((10l), (5l), (7l)) == (16.25f));
assert(triangleArea((2l), (6l), (3l)) == (float)-1l);
assert(triangleArea((1l), (1l), (1l)) == (0.43f));
assert(triangleArea((2l), (2l), (10l)) == (float)-1l);
}
}
|
humaneval-HumanEval_41_car_race_collision.json-L20 | js | //Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
function car_race_collision(n){
let num_collisions = 0;
let left_to_right = Array(n).fill(1);
let right_to_left = Array(n).fill(1);
for (let i = 0; i < left_to_right.length; i++) {
for (let j = 0; j < right_to_left.length; j++) {
if (left_to_right[i] == right_to_left[j]) {
num_collisions++;
}
}
} | }
| return num_collisions; | const assert = require('node:assert');
function test() {
let candidate = car_race_collision;
assert.deepEqual(candidate(2),4);
assert.deepEqual(candidate(3),9);
assert.deepEqual(candidate(4),16);
assert.deepEqual(candidate(8),64);
assert.deepEqual(candidate(10),100);
}
test(); |
humaneval-HumanEval_69_search.json-L17 | js | //You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// >>> search([4, 1, 2, 2, 3, 1])
// 2
// >>> search([1, 2, 2, 3, 3, 3, 4, 4, 4])
// 3
// >>> search([5, 5, 4, 4, 4])
// -1
function search(lst){
var h = {};
for (var i=0; i<lst.length; i++){
var x = lst[i];
if (x in h){ | }
else{
h[x] = 1;
}
}
var keys = Object.keys(h);
var max = 0;
for (var i=0; i<keys.length; i++){
if (keys[i] > max && h[keys[i]] >= keys[i]){
max = keys[i];
}
}
if (max == 0){
return -1;
}
return max;
}
| h[x] += 1; | const assert = require('node:assert');
function test() {
let candidate = search;
assert.deepEqual(candidate([5, 5, 5, 5, 1]),1);
assert.deepEqual(candidate([4, 1, 4, 1, 4, 4]),4);
assert.deepEqual(candidate([3, 3]),-1);
assert.deepEqual(candidate([8, 8, 8, 8, 8, 8, 8, 8]),8);
assert.deepEqual(candidate([2, 3, 3, 2, 2]),2);
assert.deepEqual(candidate([2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1]),1);
assert.deepEqual(candidate([3, 2, 8, 2]),2);
assert.deepEqual(candidate([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]),1);
assert.deepEqual(candidate([8, 8, 3, 6, 5, 6, 4]),-1);
assert.deepEqual(candidate([6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9]),1);
assert.deepEqual(candidate([1, 9, 10, 1, 3]),1);
assert.deepEqual(candidate([6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10]),5);
assert.deepEqual(candidate([1]),1);
assert.deepEqual(candidate([8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5]),4);
assert.deepEqual(candidate([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]),2);
assert.deepEqual(candidate([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]),1);
assert.deepEqual(candidate([9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4]),4);
assert.deepEqual(candidate([2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7]),4);
assert.deepEqual(candidate([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]),2);
assert.deepEqual(candidate([5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8]),-1);
assert.deepEqual(candidate([10]),-1);
assert.deepEqual(candidate([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]),2);
assert.deepEqual(candidate([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]),1);
assert.deepEqual(candidate([7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6]),1);
assert.deepEqual(candidate([3, 10, 10, 9, 2]),-1);
}
test(); |
humaneval-HumanEval_58_common.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 sorted unique common elements for two array lists.
// >>> common((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)3l, (long)34l, (long)653l, (long)2l, (long)5l))), (new ArrayList<Long>(Arrays.asList((long)5l, (long)7l, (long)1l, (long)5l, (long)9l, (long)653l, (long)121l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)653l)))
// >>> common((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)2l, (long)8l))), (new ArrayList<Long>(Arrays.asList((long)3l, (long)2l))))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l)))
public static ArrayList<Long> common(ArrayList<Long> l1, ArrayList<Long> l2) {
return new ArrayList<Long>(
l1.stream()
.filter(l2::contains)
.collect(Collectors.toSet())
); | } | } | }
public static void main(String[] args) {
assert(common((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)3l, (long)34l, (long)653l, (long)2l, (long)5l))), (new ArrayList<Long>(Arrays.asList((long)5l, (long)7l, (long)1l, (long)5l, (long)9l, (long)653l, (long)121l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)653l)))));
assert(common((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)2l, (long)8l))), (new ArrayList<Long>(Arrays.asList((long)3l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l)))));
assert(common((new ArrayList<Long>(Arrays.asList((long)4l, (long)3l, (long)2l, (long)8l))), (new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l)))));
assert(common((new ArrayList<Long>(Arrays.asList((long)4l, (long)3l, (long)2l, (long)8l))), (new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
}
}
|
humaneval-HumanEval_37_sort_even.json-L18 | py | from typing import List
def sort_even(l: List[int]) -> List[int]:
"""This function takes a list l and returns a list l' such that
l' is identical to l in the odd indicies, while its values at the even indicies are equal
to the values of the even indicies of l, but sorted.
>>> sort_even([1, 2, 3])
[1, 2, 3]
>>> sort_even([5, 6, 3, 4])
[3, 6, 5, 4]
"""
if l:
temp: List[int] = []
for i in range(0, len(l), 2):
temp.append(l[i])
temp.sort()
for i in range(0, len(l), 2): | return l | l[i] = temp[i // 2] | def check(candidate):
assert candidate([1, 2, 3]) == [1, 2, 3]
assert candidate([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123]
assert candidate([5, 8, -12, 4, 23, 2, 3, 11, 12, -10]) == [-12, 8, 3, 4, 5, 2, 12, 11, 23, -10]
def test_check():
check(sort_even)
test_check()
|
humaneval-HumanEval_119_match_parens.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 an array array list of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// >>> matchParens((new ArrayList<String>(Arrays.asList((String)"()(", (String)")"))))
// ("Yes")
// >>> matchParens((new ArrayList<String>(Arrays.asList((String)")", (String)")"))))
// ("No")
public static String matchParens(ArrayList<String> lst) {
String s1 = lst.get(0);
String s2 = lst.get(1);
String s3 = s1+s2;
String s4 = s2+s1;
int c1 = 0;
int c2 = 0;
for (int i = 0; i < s3.length(); i++) {
if (s3.charAt(i) == '(') c1 += 1;
else c1 -= 1;
if (c1 < 0) break;
}
for (int i = 0; i < s4.length(); i++) {
if (s4.charAt(i) == '(') c2 += 1;
else c2 -= 1;
if (c2 < 0) break;
} | else return "No";
}
} | if (c1 == 0 || c2 == 0) return "Yes"; | }
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.asList((String)"(()(())", (String)"())())")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")())", (String)"(()()(")))).equals(("Yes")));
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.asList((String)"(()(", (String)"()))()")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"((((", (String)"((())")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")(()", (String)"(()(")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")(", (String)")(")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"(", (String)")")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")", (String)"(")))).equals(("Yes")));
}
}
|
humaneval-HumanEval_94_skjkasdkd.json-L18 | 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
// >>> skjkasdkd([1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3])
// 13
// >>> skjkasdkd([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6])
// 11
// >>> skjkasdkd([0, 81, 12, 3, 1, 21])
// 3
// >>> skjkasdkd([0, 8, 1, 2, 1, 7])
// 7
function skjkasdkd(lst){
function prime(n){ | 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 += Number(digits[i]);
}
return sum;
} | if (n<2) return false; | 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([1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]),13);
assert.deepEqual(candidate([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]),11);
assert.deepEqual(candidate([0, 81, 12, 3, 1, 21]),3);
assert.deepEqual(candidate([0, 8, 1, 2, 1, 7]),7);
assert.deepEqual(candidate([8191]),19);
assert.deepEqual(candidate([8191, 123456, 127, 7]),19);
assert.deepEqual(candidate([127, 97, 8192]),10);
}
test(); |
humaneval-HumanEval_78_hex_key.json-L29 | js | //You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// >>> hex_key("AB")
// 1
// >>> hex_key("1077E")
// 2
// >>> hex_key("ABED1A33")
// 4
// >>> hex_key("123456789ABCDEF0")
// 6
// >>> hex_key("2020")
// 2
function hex_key(num){
let result = 0;
let hexadecimals = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
let primes = ['2', '3', '5', '7', 'B', 'D'];
for(let x = 0; x < num.length; x++){
if(primes.includes(num[x])){
result += 1; | }
return result;
} | } | const assert = require('node:assert');
function test() {
let candidate = hex_key;
assert.deepEqual(candidate("AB"),1);
assert.deepEqual(candidate("1077E"),2);
assert.deepEqual(candidate("ABED1A33"),4);
assert.deepEqual(candidate("2020"),2);
assert.deepEqual(candidate("123456789ABCDEF0"),6);
assert.deepEqual(candidate("112233445566778899AABBCCDDEEFF00"),12);
}
test(); |
humaneval-HumanEval_161_solve.json-L15 | 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"
// >>> solve("#a@C")
// "#A@c"
function solve(s){
let letters = s.match(/[a-z]/ig); | const swapped = s.split('').map(char => {
if(/[a-z]/i.test(char)) {
return char === char.toLowerCase()
? char.toUpperCase()
: char.toLowerCase();
}
return char;
});
return swapped.join('');
}
return s.split('').reverse().join('');
}
| if(letters) { | 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");
assert.deepEqual(candidate("#6@2"),"2@6#");
assert.deepEqual(candidate("#$a^D"),"#$A^d");
assert.deepEqual(candidate("#ccc"),"#CCC");
}
test(); |
humaneval-HumanEval_108_count_nums.json-L28 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function count_nums which takes an array array list of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// >>> countNums((new ArrayList<Long>(Arrays.asList())))
// (0l)
// >>> countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)11l, (long)-11l))))
// (1l)
// >>> countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l))))
// (3l)
public static long countNums(ArrayList<Long> arr) {
long result = 0l;
for (long i : arr) {
String str = String.valueOf(i);
int sum = 0;
if (str.startsWith("-")) {
sum = sum - (int) Character.getNumericValue(str.charAt(1));
for (int j = 2; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j)); | } else {
for (int j = 0; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j));
}
}
if (sum > 0) {
result++;
}
}
return result;
}
} | } | }
public static void main(String[] args) {
assert(countNums((new ArrayList<Long>(Arrays.asList()))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)0l)))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l, (long)-2l, (long)3l, (long)4l, (long)5l)))) == (6l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)6l, (long)9l, (long)-6l, (long)0l, (long)1l, (long)5l)))) == (5l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)100l, (long)98l, (long)-7l, (long)1l, (long)-1l)))) == (4l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)12l, (long)23l, (long)34l, (long)-45l, (long)-56l, (long)0l)))) == (5l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l)))) == (1l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l)))) == (1l));
}
}
|
humaneval-HumanEval_83_starts_one_ends.json-L17 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
public static long startsOneEnds(long n) {
long lower = (long) Math.pow(10, n - 1);
long upper = (long) Math.pow(10, n) - 1;
long count = 0;
for (long i = lower; i <= upper; i++) {
String s = "" + i; | count++;
}
return count;
}
} | if (s.startsWith("1") || s.endsWith("1")) | }
public static void main(String[] args) {
assert(startsOneEnds((1l)) == (1l));
assert(startsOneEnds((2l)) == (18l));
assert(startsOneEnds((3l)) == (180l));
assert(startsOneEnds((4l)) == (1800l));
assert(startsOneEnds((5l)) == (18000l));
}
}
|
humaneval-HumanEval_146_specialFilter.json-L28 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that takes an array array list of numbers as input and returns
// the number of elements in the array array list that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// >>> specialFilter((new ArrayList<Long>(Arrays.asList((long)15l, (long)-73l, (long)14l, (long)-15l))))
// (1l)
// >>> specialFilter((new ArrayList<Long>(Arrays.asList((long)33l, (long)-2l, (long)-3l, (long)45l, (long)21l, (long)109l))))
// (2l)
public static long specialFilter(ArrayList<Long> nums) {
class helper {
public long getFirstDigit(long n) {
long[] digits = getDigits(n);
return digits[0];
}
public long getLastDigit(long n) {
long[] digits = getDigits(n);
return digits[digits.length - 1];
}
public long[] getDigits(long n) { | while (n != 0) {
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 -> {
long firstDigit = h.getFirstDigit(x);
long lastDigit = h.getLastDigit(x);
return firstDigit % 2 != 0 && lastDigit % 2 != 0;
}).count();
}
} | ArrayList<Long> digits = new ArrayList<Long>(); | }
public static void main(String[] args) {
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)5l, (long)-2l, (long)1l, (long)-5l)))) == (0l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)15l, (long)-73l, (long)14l, (long)-15l)))) == (1l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)33l, (long)-2l, (long)-3l, (long)45l, (long)21l, (long)109l)))) == (2l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)43l, (long)-12l, (long)93l, (long)125l, (long)121l, (long)109l)))) == (4l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)71l, (long)-2l, (long)-33l, (long)75l, (long)21l, (long)19l)))) == (3l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)1l)))) == (0l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList()))) == (0l));
}
}
|
humaneval-HumanEval_102_choose_num.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 {
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// >>> chooseNum((12l), (15l))
// (14l)
// >>> chooseNum((13l), (12l))
// (-1l)
public static long chooseNum(long x, long y) {
long chosen = -1;
for (long i = x; i <= y; i++) {
if (i % 2 == 0) {
chosen = i;
}
}
return chosen;
} | } | }
public static void main(String[] args) {
assert(chooseNum((12l), (15l)) == (14l));
assert(chooseNum((13l), (12l)) == (-1l));
assert(chooseNum((33l), (12354l)) == (12354l));
assert(chooseNum((5234l), (5233l)) == (-1l));
assert(chooseNum((6l), (29l)) == (28l));
assert(chooseNum((27l), (10l)) == (-1l));
assert(chooseNum((7l), (7l)) == (-1l));
assert(chooseNum((546l), (546l)) == (546l));
}
}
|
|
humaneval-HumanEval_108_count_nums.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function count_nums which takes an array array list of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// >>> countNums((new ArrayList<Long>(Arrays.asList())))
// (0l)
// >>> countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)11l, (long)-11l))))
// (1l)
// >>> countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l))))
// (3l)
public static long countNums(ArrayList<Long> arr) {
long result = 0l;
for (long i : arr) {
String str = String.valueOf(i);
int sum = 0; | sum = sum - (int) Character.getNumericValue(str.charAt(1));
for (int j = 2; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j));
}
} else {
for (int j = 0; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j));
}
}
if (sum > 0) {
result++;
}
}
return result;
}
} | if (str.startsWith("-")) { | }
public static void main(String[] args) {
assert(countNums((new ArrayList<Long>(Arrays.asList()))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)0l)))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l, (long)-2l, (long)3l, (long)4l, (long)5l)))) == (6l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)6l, (long)9l, (long)-6l, (long)0l, (long)1l, (long)5l)))) == (5l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)100l, (long)98l, (long)-7l, (long)1l, (long)-1l)))) == (4l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)12l, (long)23l, (long)34l, (long)-45l, (long)-56l, (long)0l)))) == (5l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l)))) == (1l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l)))) == (1l));
}
}
|
humaneval-HumanEval_141_file_name_check.json-L36 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// >>> fileNameCheck(("example.txt"))
// ("Yes")
// >>> fileNameCheck(("1example.dll"))
// ("No")
public static String fileNameCheck(String file_name) {
String result = "No";
String[] tokens = file_name.split("\\.");
if (tokens.length != 2) {
return result;
}
String extension = tokens[1];
if (!(extension.equals("txt") || extension.equals("exe") || extension.equals("dll"))) {
return result;
}
String name = tokens[0];
int count = 0;
for (int i = 0; i < name.length(); i++) { | count++;
}
}
if (count > 3) {
return result;
}
if (name.length() == 0) {
return result;
}
if (!Character.isLetter(name.charAt(0))) {
return result;
}
return "Yes";
}
} | if (Character.isDigit(name.charAt(i))) { | }
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.exe")).equals(("Yes")));
assert(fileNameCheck(("His12FILE94.exe")).equals(("No")));
assert(fileNameCheck(("_Y.txt")).equals(("No")));
assert(fileNameCheck(("?aREYA.exe")).equals(("No")));
assert(fileNameCheck(("/this_is_valid.dll")).equals(("No")));
assert(fileNameCheck(("this_is_valid.wow")).equals(("No")));
assert(fileNameCheck(("this_is_valid.txt")).equals(("Yes")));
assert(fileNameCheck(("this_is_valid.txtexe")).equals(("No")));
assert(fileNameCheck(("#this2_i4s_5valid.ten")).equals(("No")));
assert(fileNameCheck(("@this1_is6_valid.exe")).equals(("No")));
assert(fileNameCheck(("this_is_12valid.6exe4.txt")).equals(("No")));
assert(fileNameCheck(("all.exe.txt")).equals(("No")));
assert(fileNameCheck(("I563_No.exe")).equals(("Yes")));
assert(fileNameCheck(("Is3youfault.txt")).equals(("Yes")));
assert(fileNameCheck(("no_one#knows.dll")).equals(("Yes")));
assert(fileNameCheck(("1I563_Yes3.exe")).equals(("No")));
assert(fileNameCheck(("I563_Yes3.txtt")).equals(("No")));
assert(fileNameCheck(("final..txt")).equals(("No")));
assert(fileNameCheck(("final132")).equals(("No")));
assert(fileNameCheck(("_f4indsartal132.")).equals(("No")));
assert(fileNameCheck((".txt")).equals(("No")));
assert(fileNameCheck(("s.")).equals(("No")));
}
}
|
humaneval-HumanEval_109_move_one_ball.json-L32 | py | from typing import List
def move_one_ball(arr: List[int]) -> bool:
"""We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
numbers in the array will be randomly ordered. Your task is to determine if
it is possible to get an array sorted in non-decreasing order by performing
the following operation on the given array:
You are allowed to perform right shift operation any number of times.
One right shift operation means shifting all elements of the array by one
position in the right direction. The last element of the array will be moved to
the starting position in the array i.e. 0th index.
If it is possible to obtain the sorted array by performing the above operation
then return True else return False.
If the given array is empty then return True.
Note: The given list is guaranteed to have unique elements.
For Example:
>>> move_one_ball([3, 4, 5, 1, 2])
True
Explanation: By performin 2 right shift operations, non-decreasing order can
be achieved for the given array.
>>> move_one_ball([3, 5, 4, 1, 2])
False
Explanation:It is not possible to get non-decreasing order for the given
array by performing any number of right shift operations.
"""
| for i in range(1, len(arr)):
if arr[i-1] > arr[i]:
if flag == True:
return False
flag = True
elif arr[i-1] < arr[i]:
flag = False
return True
| flag = False | def check(candidate):
assert candidate([3, 4, 5, 1, 2]) == True
assert candidate([3, 5, 10, 1, 2]) == True
assert candidate([4, 3, 1, 2]) == False
assert candidate([3, 5, 4, 1, 2]) == False
assert candidate([]) == True
def test_check():
check(move_one_ball)
test_check()
|
humaneval-HumanEval_154_cycpattern_check.json-L21 | py | def cycpattern_check(a: str, b: str) -> bool:
"""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
>>> cycpattern_check('efef', 'eeff')
False
>>> cycpattern_check('himenss', 'simen')
True
"""
for i in range(len(b)):
if a.find(b) != -1:
return True
b = b[1:] + b[0] | return False | def check(candidate):
assert candidate('xyzw', 'xyw') == False
assert candidate('yello', 'ell') == True
assert candidate('whattup', 'ptut') == False
assert candidate('efef', 'fee') == True
assert candidate('abab', 'aabb') == False
assert candidate('winemtt', 'tinem') == True
def test_check():
check(cycpattern_check)
test_check()
|
|
humaneval-HumanEval_61_correct_bracketing.json-L12 | js | //brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correct_bracketing("(")
// false
// >>> correct_bracketing("()")
// true
// >>> correct_bracketing("(()())")
// true
// >>> correct_bracketing(")(()")
// false
function correct_bracketing(brackets){
| for (var i = 0; i < brackets.length; i++){
if (brackets[i] == "("){
opens.push(brackets[i]);
}
else if (brackets[i] == ")"){
if (opens.length > 0){
opens.pop();
}
else {
return false;
}
}
}
if (opens.length == 0){
return true;
}
else {
return false;
}
} | var opens = []; | const assert = require('node:assert');
function test() {
let candidate = correct_bracketing;
assert.deepEqual(candidate("()"),true);
assert.deepEqual(candidate("(()())"),true);
assert.deepEqual(candidate("()()(()())()"),true);
assert.deepEqual(candidate("()()((()()())())(()()(()))"),true);
assert.deepEqual(candidate("((()())))"),false);
assert.deepEqual(candidate(")(()"),false);
assert.deepEqual(candidate("("),false);
assert.deepEqual(candidate("(((("),false);
assert.deepEqual(candidate(")"),false);
assert.deepEqual(candidate("(()"),false);
assert.deepEqual(candidate("()()(()())())(()"),false);
assert.deepEqual(candidate("()()(()())()))()"),false);
}
test(); |
humaneval-HumanEval_40_triples_sum_to_zero.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 {
// triples_sum_to_zero takes an array array list of integers as an input.
// it returns true if there are three distinct elements in the array list that
// sum to zero, and false otherwise.
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)0l))))
// (false)
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)-2l, (long)1l))))
// (true)
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)7l))))
// (false)
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)-5l, (long)3l, (long)9l, (long)7l))))
// (true)
// >>> triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l))))
// (false)
public static boolean triplesSumToZero(ArrayList<Long> l) {
if (l.size() < 3) {
return false;
}
ArrayList<Long> sortedList = new ArrayList<Long>(l);
Collections.sort(sortedList);
for (int i = 0; i < sortedList.size() - 2; i++) {
int j = i + 1;
int k = sortedList.size() - 1;
while (j < k) { | if (currSum == 0) {
return true;
} else if (currSum < 0) {
j++;
} else {
k--;
}
}
}
return false;
}
} | long currSum = sortedList.get(i) + sortedList.get(j) + sortedList.get(k); | }
public static void main(String[] args) {
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)0l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)-1l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)-2l, (long)1l)))) == (true));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)7l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)5l, (long)7l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)-5l, (long)3l, (long)9l, (long)7l)))) == (true));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l, (long)-100l)))) == (false));
assert(triplesSumToZero((new ArrayList<Long>(Arrays.asList((long)100l, (long)3l, (long)5l, (long)-100l)))) == (false));
}
}
|
humaneval-HumanEval_156_int_to_mini_roman.json-L65 | 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 <= 1000
// Examples:
// >>> intToMiniRoman((19l))
// ("xix")
// >>> intToMiniRoman((152l))
// ("clii")
// >>> intToMiniRoman((426l))
// ("cdxxvi")
public static String intToMiniRoman(long number) {
int num = (int) number;
String res = "";
if (num == 0)
return "";
while (num >= 1000) {
res += "m";
num -= 1000;
}
if (num >= 900) {
res += "cm";
num -= 900;
}
if (num >= 500) {
res += "d";
num -= 500;
}
if (num >= 400) {
res += "cd";
num -= 400;
}
while (num >= 100) {
res += "c";
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 += "x";
num -= 10;
}
if (num >= 9) {
res += "ix";
num -= 9;
}
if (num >= 5) { | num -= 5;
}
if (num >= 4) {
res += "iv";
num -= 4;
}
while (num >= 1) {
res += "i";
num -= 1;
}
return res;
}
} | res += "v"; | }
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")));
assert(intToMiniRoman((1l)).equals(("i")));
assert(intToMiniRoman((4l)).equals(("iv")));
assert(intToMiniRoman((43l)).equals(("xliii")));
assert(intToMiniRoman((90l)).equals(("xc")));
assert(intToMiniRoman((94l)).equals(("xciv")));
assert(intToMiniRoman((532l)).equals(("dxxxii")));
assert(intToMiniRoman((900l)).equals(("cm")));
assert(intToMiniRoman((994l)).equals(("cmxciv")));
assert(intToMiniRoman((1000l)).equals(("m")));
}
}
|
humaneval-HumanEval_148_bf.json-L33 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// There are eight planets in our solar system: the closerst to the Sun
// is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
// Uranus, Neptune.
// Write a function that takes two planet names as strings planet1 and planet2.
// The function should return a pair containing all planets whose orbits are
// located between the orbit of planet1 and the orbit of planet2, sorted by
// the proximity to the sun.
// The function should return an empty pair if planet1 or planet2
// are not correct planet names.
// Examples
// >>> bf(("Jupiter"), ("Neptune"))
// (new ArrayList<String>(Arrays.asList((String)"Saturn", (String)"Uranus")))
// >>> bf(("Earth"), ("Mercury"))
// (ArrayList<String>("Venus"))
// >>> bf(("Mercury"), ("Uranus"))
// (new ArrayList<String>(Arrays.asList((String)"Venus", (String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn")))
public static ArrayList<String> bf(String planet1, String planet2) {
ArrayList<String> planets = new ArrayList<String>(Arrays.asList((String)"Mercury", (String)"Venus", (String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn", (String)"Uranus", (String)"Neptune"));
int indexPlanet1 = planets.indexOf(planet1);
int indexPlanet2 = planets.indexOf(planet2);
int indexMin = 0;
int indexMax = 0;
if (indexPlanet1 >= 0 && indexPlanet2 >= 0) {
if (indexPlanet1 < indexPlanet2) { | indexMax = indexPlanet2;
} else {
indexMin = indexPlanet2;
indexMax = indexPlanet1;
}
ArrayList<String> planetsInBetween = new ArrayList<String>();
for (int i = indexMin + 1; i < indexMax; i++) {
planetsInBetween.add(planets.get(i));
}
return planetsInBetween;
} else {
return new ArrayList<String>();
}
}
} | indexMin = indexPlanet1; | }
public static void main(String[] args) {
assert(bf(("Jupiter"), ("Neptune")).equals((new ArrayList<String>(Arrays.asList((String)"Saturn", (String)"Uranus")))));
assert(bf(("Earth"), ("Mercury")).equals((new ArrayList<String>(Arrays.asList((String)"Venus")))));
assert(bf(("Mercury"), ("Uranus")).equals((new ArrayList<String>(Arrays.asList((String)"Venus", (String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn")))));
assert(bf(("Neptune"), ("Venus")).equals((new ArrayList<String>(Arrays.asList((String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn", (String)"Uranus")))));
assert(bf(("Earth"), ("Earth")).equals((new ArrayList<String>(Arrays.asList()))));
assert(bf(("Mars"), ("Earth")).equals((new ArrayList<String>(Arrays.asList()))));
assert(bf(("Jupiter"), ("Makemake")).equals((new ArrayList<String>(Arrays.asList()))));
}
}
|
humaneval-HumanEval_82_prime_length.json-L17 | js | //Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// >>> prime_length("Hello")
// true
// >>> prime_length("abcdcba")
// true
// >>> prime_length("kittens")
// true
// >>> prime_length("orange")
// false
function prime_length(string){
let length = string.length;
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199];
if (primes.includes(length)){
return true; | return false;
}
} | } else { | const assert = require('node:assert');
function test() {
let candidate = prime_length;
assert.deepEqual(candidate("Hello"),true);
assert.deepEqual(candidate("abcdcba"),true);
assert.deepEqual(candidate("kittens"),true);
assert.deepEqual(candidate("orange"),false);
assert.deepEqual(candidate("wow"),true);
assert.deepEqual(candidate("world"),true);
assert.deepEqual(candidate("MadaM"),true);
assert.deepEqual(candidate("Wow"),true);
assert.deepEqual(candidate(""),false);
assert.deepEqual(candidate("HI"),true);
assert.deepEqual(candidate("go"),true);
assert.deepEqual(candidate("gogo"),false);
assert.deepEqual(candidate("aaaaaaaaaaaaaaa"),false);
assert.deepEqual(candidate("Madam"),true);
assert.deepEqual(candidate("M"),false);
assert.deepEqual(candidate("0"),false);
}
test(); |
humaneval-HumanEval_90_next_smallest.json-L16 | js | //You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return undefined if there is no such element.
// >>> next_smallest([1, 2, 3, 4, 5])
// 2
// >>> next_smallest([5, 1, 4, 3, 2])
// 2
// >>> next_smallest([])
// undefined
// >>> next_smallest([1, 1])
// undefined
function next_smallest(lst){
if(lst.length<=1){
return undefined;
} | var second_smallest=Number.MAX_VALUE;
for(var i in lst){
if(lst[i]>smallest&&lst[i]<second_smallest){
second_smallest=lst[i];
}
}
if(second_smallest==Number.MAX_VALUE){
return undefined;
}
return second_smallest;
} | var smallest=Math.min(...lst); | const assert = require('node:assert');
function test() {
let candidate = next_smallest;
assert.deepEqual(candidate([1, 2, 3, 4, 5]),2);
assert.deepEqual(candidate([5, 1, 4, 3, 2]),2);
assert.deepEqual(candidate([]),undefined);
assert.deepEqual(candidate([1, 1]),undefined);
assert.deepEqual(candidate([1, 1, 1, 1, 0]),1);
assert.deepEqual(candidate([1, 1]),undefined);
assert.deepEqual(candidate([-35, 34, 12, -45]),-35);
}
test(); |
humaneval-HumanEval_5_intersperse.json-L8 | js | //Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// >>> intersperse([], 4)
// []
// >>> intersperse([1, 2, 3], 4)
// [1, 4, 2, 4, 3]
function intersperse(numbers, delimeter){
var result = []; | result.push(numbers[i]);
if(i !== numbers.length - 1){
result.push(delimeter);
}
}
return result;
}
| for(var i = 0; i < numbers.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = intersperse;
assert.deepEqual(candidate([], 7),[]);
assert.deepEqual(candidate([5, 6, 3, 2], 8),[5, 8, 6, 8, 3, 8, 2]);
assert.deepEqual(candidate([2, 2, 2], 2),[2, 2, 2, 2, 2]);
}
test(); |
humaneval-HumanEval_150_x_or_y.json-L18 | js | //A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// >>> x_or_y(7, 34, 12)
// 34
// >>> x_or_y(15, 8, 5)
// 5
function x_or_y(n, x, y){
if(n<2){
return y;
}
for(var i=2; i<n; i++){
if(n%i==0){
return y;
}
}
return x; | } | const assert = require('node:assert');
function test() {
let candidate = x_or_y;
assert.deepEqual(candidate(7, 34, 12),34);
assert.deepEqual(candidate(15, 8, 5),5);
assert.deepEqual(candidate(3, 33, 5212),33);
assert.deepEqual(candidate(1259, 3, 52),3);
assert.deepEqual(candidate(7919, -1, 12),-1);
assert.deepEqual(candidate(3609, 1245, 583),583);
assert.deepEqual(candidate(91, 56, 129),129);
assert.deepEqual(candidate(6, 34, 1234),1234);
assert.deepEqual(candidate(1, 2, 0),0);
assert.deepEqual(candidate(2, 2, 0),2);
}
test(); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.