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_98_count_upper.json-L24 | py | def count_upper(s: str) -> int:
"""
Given a string s, count the number of uppercase vowels in even indices.
For example:
>>> count_upper('aBCdEf')
1
>>> count_upper('abcdefg')
0
>>> count_upper('dBBE')
0
"""
vowel_set = set('AEIOU')
count = 0
for i in range(0, len(s), 2):
if s[i] in vowel_set:
count += 1
return count
"""
D.1 Recursion
Given a positive integer n, write a recursive function that returns the sum of the squares of the
positive odd integers smaller than n. Assume n is greater than or equal to 3. | """ | def check(candidate):
assert candidate('aBCdEf') == 1
assert candidate('abcdefg') == 0
assert candidate('dBBE') == 0
assert candidate('B') == 0
assert candidate('U') == 1
assert candidate('') == 0
assert candidate('EEEE') == 2
def test_check():
check(count_upper)
test_check()
|
|
humaneval-HumanEval_110_exchange.json-L32 | js | //In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array 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 arrays will be non-empty.
function exchange(lst1, lst2){
var num1 = 0;
var num2 = 0;
var exchange = true;
while(num1 < lst1.length && exchange){
if(lst1[num1] % 2 !== 0){
exchange = false;
if(num2 < lst2.length){
while(num2 < lst2.length && exchange == false){
if(lst2[num2] % 2 == 0){
lst1[num1] = lst2[num2];
exchange = true;
}
num2++;
}
}
}
num1++; | if(exchange){
return "YES";
}else{
return "NO";
}
}
| } | const assert = require('node:assert');
function test() {
let candidate = exchange;
assert.deepEqual(candidate([1, 2, 3, 4], [1, 2, 3, 4]),"YES");
assert.deepEqual(candidate([1, 2, 3, 4], [1, 5, 3, 4]),"NO");
assert.deepEqual(candidate([1, 2, 3, 4], [2, 1, 4, 3]),"YES");
assert.deepEqual(candidate([5, 7, 3], [2, 6, 4]),"YES");
assert.deepEqual(candidate([5, 7, 3], [2, 6, 3]),"NO");
assert.deepEqual(candidate([3, 2, 6, 1, 8, 9], [3, 5, 5, 1, 1, 1]),"NO");
assert.deepEqual(candidate([100, 200], [200, 200]),"YES");
}
test(); |
humaneval-HumanEval_158_find_max.json-L35 | js | //Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// >>> find_max(["name", "of", "string"])
// "string"
// >>> find_max(["name", "enam", "game"])
// "enam"
// >>> find_max(["aaaaaaa", "bb", "cc"])
// "aaaaaaa"
function find_max(words){
var max_unique = {};
var max_unique_word = "";
for(var i = 0; i < words.length; i++){
var unique_word = {};
var word = words[i];
for(var j = 0; j < word.length; j++){
var char = word[j];
if(unique_word[char] === undefined){
unique_word[char] = 1;
}
}
if(max_unique_word === ""){
max_unique_word = word;
max_unique = unique_word;
}
else if(Object.keys(unique_word).length > Object.keys(max_unique).length){
max_unique_word = word;
max_unique = unique_word;
}
else if(Object.keys(unique_word).length === Object.keys(max_unique).length){
if(word < max_unique_word){
max_unique_word = word;
max_unique = unique_word; | }
}
return max_unique_word;
} | } | const assert = require('node:assert');
function test() {
let candidate = find_max;
assert.deepEqual(candidate(["name", "of", "string"]),"string");
assert.deepEqual(candidate(["name", "enam", "game"]),"enam");
assert.deepEqual(candidate(["aaaaaaa", "bb", "cc"]),"aaaaaaa");
assert.deepEqual(candidate(["abc", "cba"]),"abc");
assert.deepEqual(candidate(["play", "this", "game", "of", "footbott"]),"footbott");
assert.deepEqual(candidate(["we", "are", "gonna", "rock"]),"gonna");
assert.deepEqual(candidate(["we", "are", "a", "mad", "nation"]),"nation");
assert.deepEqual(candidate(["this", "is", "a", "prrk"]),"this");
assert.deepEqual(candidate(["b"]),"b");
assert.deepEqual(candidate(["play", "play", "play"]),"play");
}
test(); |
humaneval-HumanEval_7_filter_by_substring.json-L15 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Filter an input array list of strings only for ones that contain given substring
// >>> filterBySubstring((new ArrayList<String>(Arrays.asList())), ("a"))
// (new ArrayList<String>(Arrays.asList()))
// >>> filterBySubstring((new ArrayList<String>(Arrays.asList((String)"abc", (String)"bacd", (String)"cde", (String)"array"))), ("a"))
// (new ArrayList<String>(Arrays.asList((String)"abc", (String)"bacd", (String)"array")))
public static ArrayList<String> filterBySubstring(ArrayList<String> strings, String substring) {
| }
} | return new ArrayList<String>(strings.stream().filter(s -> s.contains(substring)).collect(Collectors.toList())); | }
public static void main(String[] args) {
assert(filterBySubstring((new ArrayList<String>(Arrays.asList())), ("john")).equals((new ArrayList<String>(Arrays.asList()))));
assert(filterBySubstring((new ArrayList<String>(Arrays.asList((String)"xxx", (String)"asd", (String)"xxy", (String)"john doe", (String)"xxxAAA", (String)"xxx"))), ("xxx")).equals((new ArrayList<String>(Arrays.asList((String)"xxx", (String)"xxxAAA", (String)"xxx")))));
assert(filterBySubstring((new ArrayList<String>(Arrays.asList((String)"xxx", (String)"asd", (String)"aaaxxy", (String)"john doe", (String)"xxxAAA", (String)"xxx"))), ("xx")).equals((new ArrayList<String>(Arrays.asList((String)"xxx", (String)"aaaxxy", (String)"xxxAAA", (String)"xxx")))));
assert(filterBySubstring((new ArrayList<String>(Arrays.asList((String)"grunt", (String)"trumpet", (String)"prune", (String)"gruesome"))), ("run")).equals((new ArrayList<String>(Arrays.asList((String)"grunt", (String)"prune")))));
}
}
|
humaneval-HumanEval_141_file_name_check.json-L23 | py | def file_name_check(file_name: str) -> str:
"""Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is valid, and returns 'No' otherwise.
A file's name is considered to be valid if and only if all the following conditions
are met:
- There 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:
>>> file_name_check('example.txt')
'Yes'
>>> file_name_check('1example.dll')
'No'
"""
if not file_name:
return 'No'
s_count = 0
e_count = 0
for i in file_name:
if i.isdigit(): | if i == '.':
e_count += 1
if s_count > 3 or e_count != 1:
return 'No'
s_name = file_name.split('.')[0]
e_name = file_name.split('.')[1]
if not s_name or not e_name or not s_name[0].isalpha():
return 'No'
if e_name not in ['txt', 'exe', 'dll']:
return 'No'
return 'Yes'
| s_count += 1 | def check(candidate):
assert candidate('example.txt') == 'Yes'
assert candidate('1example.dll') == 'No'
assert candidate('s1sdf3.asd') == 'No'
assert candidate('K.dll') == 'Yes'
assert candidate('MY16FILE3.exe') == 'Yes'
assert candidate('His12FILE94.exe') == 'No'
assert candidate('_Y.txt') == 'No'
assert candidate('?aREYA.exe') == 'No'
assert candidate('/this_is_valid.dll') == 'No'
assert candidate('this_is_valid.wow') == 'No'
assert candidate('this_is_valid.txt') == 'Yes'
assert candidate('this_is_valid.txtexe') == 'No'
assert candidate('#this2_i4s_5valid.ten') == 'No'
assert candidate('@this1_is6_valid.exe') == 'No'
assert candidate('this_is_12valid.6exe4.txt') == 'No'
assert candidate('all.exe.txt') == 'No'
assert candidate('I563_No.exe') == 'Yes'
assert candidate('Is3youfault.txt') == 'Yes'
assert candidate('no_one#knows.dll') == 'Yes'
assert candidate('1I563_Yes3.exe') == 'No'
assert candidate('I563_Yes3.txtt') == 'No'
assert candidate('final..txt') == 'No'
assert candidate('final132') == 'No'
assert candidate('_f4indsartal132.') == 'No'
assert candidate('.txt') == 'No'
assert candidate('s.') == 'No'
def test_check():
check(file_name_check)
test_check()
|
humaneval-HumanEval_69_search.json-L27 | 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]){ | }
}
if (max == 0){
return -1;
}
return max;
}
| max = keys[i]; | 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_70_strange_sort_list.json-L14 | js | //Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// >>> strange_sort_list([1, 2, 3, 4])
// [1, 4, 2, 3]
// >>> strange_sort_list([5, 5, 5, 5])
// [5, 5, 5, 5]
// >>> strange_sort_list([])
// []
function strange_sort_list(lst){
if(lst.length === 0){
return []; | var output = [];
var tmp = lst.slice();
for(var i = 0; i < lst.length; i++){
if(i % 2 === 0){
output.push(Math.min.apply(null, tmp));
}
else{
output.push(Math.max.apply(null, tmp));
}
tmp.splice(tmp.indexOf(output[i]), 1);
}
return output;
} | } | const assert = require('node:assert');
function test() {
let candidate = strange_sort_list;
assert.deepEqual(candidate([1, 2, 3, 4]),[1, 4, 2, 3]);
assert.deepEqual(candidate([5, 6, 7, 8, 9]),[5, 9, 6, 8, 7]);
assert.deepEqual(candidate([1, 2, 3, 4, 5]),[1, 5, 2, 4, 3]);
assert.deepEqual(candidate([5, 6, 7, 8, 9, 1]),[1, 9, 5, 8, 6, 7]);
assert.deepEqual(candidate([5, 5, 5, 5]),[5, 5, 5, 5]);
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([1, 2, 3, 4, 5, 6, 7, 8]),[1, 8, 2, 7, 3, 6, 4, 5]);
assert.deepEqual(candidate([0, 2, 2, 2, 5, 5, -5, -5]),[-5, 5, -5, 5, 0, 2, 2, 2]);
assert.deepEqual(candidate([111111]),[111111]);
}
test(); |
humaneval-HumanEval_37_sort_even.json-L13 | js | //This function takes an array l and returns an array 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]
function sort_even(l){
var l2 = []
for(var i = 0; i < l.length; i += 2){
l2.push(l[i])
} | for(var i = 0; i < l2.length; i++){
l[i * 2] = l2[i]
}
return l
}
| l2.sort(function(a, b){return a - b}) | const assert = require('node:assert');
function test() {
let candidate = sort_even;
assert.deepEqual(candidate([1, 2, 3]),[1, 2, 3]);
assert.deepEqual(candidate([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]),[-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123]);
assert.deepEqual(candidate([5, 8, -12, 4, 23, 2, 3, 11, 12, -10]),[-12, 8, 3, 4, 5, 2, 12, 11, 23, -10]);
}
test(); |
humaneval-HumanEval_23_strlen.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 length of given string
// >>> stringLength((""))
// (0l)
// >>> stringLength(("abc"))
// (3l)
public static long strlen(String string) {
return string.length();
} | } | }
public static void main(String[] args) {
assert(strlen(("")) == (0l));
assert(strlen(("x")) == (1l));
assert(strlen(("asdasnakj")) == (9l));
}
}
|
|
humaneval-HumanEval_160_do_algebra.json-L40 | 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; | operand[count] = Math.pow(operand[count], operand[count + 1]);
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
default:
count++;
do_again = false;
}
}
answer = operand[0];
operand.splice(0, 1);
while(operand.length > 0){
switch(operator[0]){
case '+':
answer += operand[0];
break;
case '-':
answer -= operand[0];
break;
}
operand.splice(0, 1);
operator.splice(0, 1);
}
return answer;
}
| case '**': | 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_57_monotonic.json-L14 | js | //Return true is array elements are monotonically increasing or decreasing.
// >>> monotonic([1, 2, 4, 20])
// true
// >>> monotonic([1, 20, 4, 10])
// false
// >>> monotonic([4, 1, 0, -10])
// true
function monotonic(l){
if(l.length <= 1){
return true;
}
if(l[0] < l[1]){
for(var i = 1; i < l.length - 1; i++){ | return false;
}
}
}
else{
for(var i = 1; i < l.length - 1; i++){
if(l[i] < l[i + 1]){
return false;
}
}
}
return true;
}
| if(l[i] > l[i + 1]){ | const assert = require('node:assert');
function test() {
let candidate = monotonic;
assert.deepEqual(candidate([1, 2, 4, 10]),true);
assert.deepEqual(candidate([1, 2, 4, 20]),true);
assert.deepEqual(candidate([1, 20, 4, 10]),false);
assert.deepEqual(candidate([4, 1, 0, -10]),true);
assert.deepEqual(candidate([4, 1, 1, 0]),true);
assert.deepEqual(candidate([1, 2, 3, 2, 5, 60]),false);
assert.deepEqual(candidate([1, 2, 3, 4, 5, 60]),true);
assert.deepEqual(candidate([9, 9, 9, 9]),true);
}
test(); |
humaneval-HumanEval_144_simplify.json-L30 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// >>> simplify(("1/5"), ("5/1"))
// (true)
// >>> simplify(("1/6"), ("2/1"))
// (false)
// >>> simplify(("7/10"), ("10/2"))
// (false)
public static boolean simplify(String x, String n) {
String[] nums = x.split("/");
String[] n_nums = n.split("/");
int x_num = Integer.parseInt(nums[0]);
int n_num = Integer.parseInt(n_nums[0]);
int x_denom = Integer.parseInt(nums[1]);
int n_denom = Integer.parseInt(n_nums[1]);
int res_num = x_num * n_num;
int res_denom = x_denom * n_denom;
return (res_num % res_denom == 0); | } | } | }
public static void main(String[] args) {
assert(simplify(("1/5"), ("5/1")) == (true));
assert(simplify(("1/6"), ("2/1")) == (false));
assert(simplify(("5/1"), ("3/1")) == (true));
assert(simplify(("7/10"), ("10/2")) == (false));
assert(simplify(("2/10"), ("50/10")) == (true));
assert(simplify(("7/2"), ("4/2")) == (true));
assert(simplify(("11/6"), ("6/1")) == (true));
assert(simplify(("2/3"), ("5/2")) == (false));
assert(simplify(("5/2"), ("3/5")) == (false));
assert(simplify(("2/4"), ("8/4")) == (true));
assert(simplify(("2/4"), ("4/2")) == (true));
assert(simplify(("1/5"), ("5/1")) == (true));
assert(simplify(("1/5"), ("1/5")) == (false));
}
}
|
humaneval-HumanEval_157_right_angle_triangle.json-L14 | py | def right_angle_triangle(a: int, b: int, c: int) -> bool:
"""
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
"""
a, b, c = sorted([a, b, c]) | return a ** 2 + b ** 2 == c ** 2 | def check(candidate):
assert candidate(3, 4, 5) == True
assert candidate(1, 2, 3) == False
assert candidate(10, 6, 8) == True
assert candidate(2, 2, 2) == False
assert candidate(7, 24, 25) == True
assert candidate(10, 5, 7) == False
assert candidate(5, 12, 13) == True
assert candidate(15, 8, 17) == True
assert candidate(48, 55, 73) == True
assert candidate(1, 1, 1) == False
assert candidate(2, 2, 10) == False
def test_check():
check(right_angle_triangle)
test_check()
|
|
humaneval-HumanEval_150_x_or_y.json-L13 | 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++){ | return y;
}
}
return x;
} | if(n%i==0){ | 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_31_is_prime.json-L37 | js | //Return true if a given number is prime, and false otherwise.
// >>> is_prime(6)
// false
// >>> is_prime(101)
// true
// >>> is_prime(11)
// true
// >>> is_prime(13441)
// true
// >>> is_prime(61)
// true
// >>> is_prime(4)
// false
// >>> is_prime(1)
// false
function is_prime(n){
if (n==1) {
return false;
}
if (n==2) {
return true;
}
if (n%2==0) {
return false;
}
var limit = Math.sqrt(n);
for (var i = 3; i <= limit; i += 2) {
if (n%i==0) {
return false;
}
}
return true; | } | const assert = require('node:assert');
function test() {
let candidate = is_prime;
assert.deepEqual(candidate(6),false);
assert.deepEqual(candidate(101),true);
assert.deepEqual(candidate(11),true);
assert.deepEqual(candidate(13441),true);
assert.deepEqual(candidate(61),true);
assert.deepEqual(candidate(4),false);
assert.deepEqual(candidate(1),false);
assert.deepEqual(candidate(5),true);
assert.deepEqual(candidate(11),true);
assert.deepEqual(candidate(17),true);
assert.deepEqual(candidate(85),false);
assert.deepEqual(candidate(77),false);
assert.deepEqual(candidate(255379),false);
}
test(); |
|
humaneval-HumanEval_158_find_max.json-L20 | py | from typing import List
def find_max(words: List[str]) -> str:
"""Write a function that accepts a list of strings.
The list contains different words. Return the word with maximum number
of unique characters. If multiple strings have maximum number of unique
characters, return the one which comes first in lexicographical order.
>>> find_max(['name', 'of', 'string'])
'string'
>>> find_max(['name', 'enam', 'game'])
'enam'
>>> find_max(['aaaaaaa', 'bb', 'cc'])
'aaaaaaa'
"""
max_num = 0
max_word = ""
for word in words:
unique_num = len(set(word)) | max_num = unique_num
max_word = word
elif unique_num == max_num:
if word < max_word:
max_word = word
return max_word
| if unique_num > max_num: | def check(candidate):
assert candidate(['name', 'of', 'string']) == 'string'
assert candidate(['name', 'enam', 'game']) == 'enam'
assert candidate(['aaaaaaa', 'bb', 'cc']) == 'aaaaaaa'
assert candidate(['abc', 'cba']) == 'abc'
assert candidate(['play', 'this', 'game', 'of', 'footbott']) == 'footbott'
assert candidate(['we', 'are', 'gonna', 'rock']) == 'gonna'
assert candidate(['we', 'are', 'a', 'mad', 'nation']) == 'nation'
assert candidate(['this', 'is', 'a', 'prrk']) == 'this'
assert candidate(['b']) == 'b'
assert candidate(['play', 'play', 'play']) == 'play'
def test_check():
check(find_max)
test_check()
|
humaneval-HumanEval_57_monotonic.json-L14 | py | from typing import List
def monotonic(l: List[int]) -> bool:
"""Return True is list elements are monotonically increasing or decreasing.
>>> monotonic([1, 2, 4, 20])
True
>>> monotonic([1, 20, 4, 10])
False
>>> monotonic([4, 1, 0, -10])
True
"""
if l == sorted(l) or l == sorted(l, reverse=True):
return True | return False | def check(candidate):
assert candidate([1, 2, 4, 10]) == True
assert candidate([1, 2, 4, 20]) == True
assert candidate([1, 20, 4, 10]) == False
assert candidate([4, 1, 0, -10]) == True
assert candidate([4, 1, 1, 0]) == True
assert candidate([1, 2, 3, 2, 5, 60]) == False
assert candidate([1, 2, 3, 4, 5, 60]) == True
assert candidate([9, 9, 9, 9]) == True
def test_check():
check(monotonic)
test_check()
|
|
humaneval-HumanEval_67_fruit_distribution.json-L19 | 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]); | return n - sum;
} | let sum = num_of_apples + num_of_oranges; | 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_78_hex_key.json-L28 | 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])){ | }
}
return result;
} | result += 1; | 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_127_intersection.json-L30 | py | from typing import Tuple
def intersection(interval1: Tuple[int, int], interval2: Tuple[int, int]) -> str:
"""You are given two intervals,
where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
The given intervals are closed which means that the interval (start, end)
includes both start and end.
For each given interval, it is assumed that its start is less or equal its end.
Your task is to determine whether the length of intersection of these two
intervals is a prime number.
Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
which its length is 1, which not a prime number.
If the length of the intersection is a prime number, return "YES",
otherwise, return "NO".
If the two intervals don't intersect, return "NO".
[input/output] samples:
>>> intersection((1, 2), (2, 3))
'NO'
>>> intersection((-1, 1), (0, 4))
'NO'
>>> intersection((-3, -1), (-5, 5))
'YES'
"""
start = max(interval1[0], interval2[0])
end = min(interval1[1], interval2[1])
if start > end:
return "NO" | return "YES" if end - start == 2 else "NO" | def check(candidate):
assert candidate((1, 2), (2, 3)) == 'NO'
assert candidate((-1, 1), (0, 4)) == 'NO'
assert candidate((-3, -1), (-5, 5)) == 'YES'
assert candidate((-2, 2), (-4, 0)) == 'YES'
assert candidate((-11, 2), (-1, -1)) == 'NO'
assert candidate((1, 2), (3, 5)) == 'NO'
assert candidate((1, 2), (1, 2)) == 'NO'
assert candidate((-2, -2), (-3, -2)) == 'NO'
def test_check():
check(intersection)
test_check()
|
|
humaneval-HumanEval_94_skjkasdkd.json-L25 | 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){
if (n<2) return false;
for (let i=2; i<=Math.sqrt(n); i++){
if (n%i==0) return false;
}
return true;
}
let max = Math.max(...lst.filter(x=>prime(x))); | let sum = 0;
for (let i=0; i<digits.length; i++){
sum += Number(digits[i]);
}
return sum;
} | let digits = String(max).split(''); | 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_40_triples_sum_to_zero.json-L26 | js | //triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// >>> triples_sum_to_zero([1, 3, 5, 0])
// false
// >>> triples_sum_to_zero([1, 3, -2, 1])
// true
// >>> triples_sum_to_zero([1, 2, 3, 7])
// false
// >>> triples_sum_to_zero([2, 4, -5, 3, 9, 7])
// true
// >>> triples_sum_to_zero([1])
// false
function triples_sum_to_zero(l){
for (var i = 0; i < l.length; i++) {
for (var j = 0; j < l.length; j++) {
for (var k = 0; k < l.length; k++) {
if (i !== j && i !== k && j !== k) {
if (l[i] + l[j] + l[k] === 0) {
return true;
}
}
}
}
} | }
| return false; | const assert = require('node:assert');
function test() {
let candidate = triples_sum_to_zero;
assert.deepEqual(candidate([1, 3, 5, 0]),false);
assert.deepEqual(candidate([1, 3, 5, -1]),false);
assert.deepEqual(candidate([1, 3, -2, 1]),true);
assert.deepEqual(candidate([1, 2, 3, 7]),false);
assert.deepEqual(candidate([1, 2, 5, 7]),false);
assert.deepEqual(candidate([2, 4, -5, 3, 9, 7]),true);
assert.deepEqual(candidate([1]),false);
assert.deepEqual(candidate([1, 3, 5, -100]),false);
assert.deepEqual(candidate([100, 3, 5, -100]),false);
}
test(); |
humaneval-HumanEval_146_specialFilter.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 {
// 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];
} | 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);
return firstDigit % 2 != 0 && lastDigit % 2 != 0;
}).count();
}
} | public long[] getDigits(long n) { | }
public static void main(String[] args) {
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)5l, (long)-2l, (long)1l, (long)-5l)))) == (0l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)15l, (long)-73l, (long)14l, (long)-15l)))) == (1l));
assert(specialFilter((new 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_100_make_a_pile.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 {
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array array list, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// >>> makeAPile((3l))
// (new ArrayList<Long>(Arrays.asList((long)3l, (long)5l, (long)7l)))
public static ArrayList<Long> makeAPile(long n) {
ArrayList<Long> levels = new ArrayList<Long>(); | levels.add(n + 2 * i);
}
return levels;
}
} | for (long i = 0; i < n; i++) { | }
public static void main(String[] args) {
assert(makeAPile((3l)).equals((new ArrayList<Long>(Arrays.asList((long)3l, (long)5l, (long)7l)))));
assert(makeAPile((4l)).equals((new ArrayList<Long>(Arrays.asList((long)4l, (long)6l, (long)8l, (long)10l)))));
assert(makeAPile((5l)).equals((new ArrayList<Long>(Arrays.asList((long)5l, (long)7l, (long)9l, (long)11l, (long)13l)))));
assert(makeAPile((6l)).equals((new ArrayList<Long>(Arrays.asList((long)6l, (long)8l, (long)10l, (long)12l, (long)14l, (long)16l)))));
assert(makeAPile((8l)).equals((new ArrayList<Long>(Arrays.asList((long)8l, (long)10l, (long)12l, (long)14l, (long)16l, (long)18l, (long)20l, (long)22l)))));
}
}
|
humaneval-HumanEval_156_int_to_mini_roman.json-L26 | js | //Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// >>> int_to_mini_roman(19)
// "xix"
// >>> int_to_mini_roman(152)
// "clii"
// >>> int_to_mini_roman(426)
// "cdxxvi"
function int_to_mini_roman(number){
var roman_conversion = {
1000: "m",
900: "cm",
500: "d",
400: "cd",
100: "c",
90: "xc",
50: "l",
40: "xl",
10: "x",
9: "ix",
5: "v",
4: "iv",
1: "i" | var output = "";
while (number > 0){
var key_list = Object.keys(roman_conversion).map(Number);
key_list.sort(function(a, b){return b-a});
for (var i = 0; i < key_list.length; i++){
if (key_list[i] <= number){
output += roman_conversion[key_list[i]];
number -= key_list[i];
break;
}
}
}
return output;
}
| }; | const assert = require('node:assert');
function test() {
let candidate = int_to_mini_roman;
assert.deepEqual(candidate(19),"xix");
assert.deepEqual(candidate(152),"clii");
assert.deepEqual(candidate(251),"ccli");
assert.deepEqual(candidate(426),"cdxxvi");
assert.deepEqual(candidate(500),"d");
assert.deepEqual(candidate(1),"i");
assert.deepEqual(candidate(4),"iv");
assert.deepEqual(candidate(43),"xliii");
assert.deepEqual(candidate(90),"xc");
assert.deepEqual(candidate(94),"xciv");
assert.deepEqual(candidate(532),"dxxxii");
assert.deepEqual(candidate(900),"cm");
assert.deepEqual(candidate(994),"cmxciv");
assert.deepEqual(candidate(1000),"m");
}
test(); |
humaneval-HumanEval_62_derivative.json-L11 | js | //xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// >>> derivative([3, 1, 2, 4, 5])
// [1, 4, 12, 20]
// >>> derivative([1, 2, 3])
// [2, 6]
function derivative(xs){
let coeff = [];
for(let i = 1; i < xs.length; i++){ | }
return coeff;
}
| coeff.push(xs[i] * i); | const assert = require('node:assert');
function test() {
let candidate = derivative;
assert.deepEqual(candidate([3, 1, 2, 4, 5]),[1, 4, 12, 20]);
assert.deepEqual(candidate([1, 2, 3]),[2, 6]);
assert.deepEqual(candidate([3, 2, 1]),[2, 2]);
assert.deepEqual(candidate([3, 2, 1, 0, 4]),[2, 2, 0, 16]);
assert.deepEqual(candidate([1]),[]);
}
test(); |
humaneval-HumanEval_133_sum_squares.json-L16 | js | //You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// >>> lst([1.0, 2.0, 3.0])
// 14
// >>> lst([1.0, 4.0, 9.0])
// 98
// >>> lst([1.0, 3.0, 5.0, 7.0])
// 84
// >>> lst([1.4, 4.2, 0.0])
// 29
// >>> lst([-2.4, 1.0, 1.0])
// 6
function sum_squares(lst){
| } | return lst.map(num => Math.ceil(num)).reduce((sum, num) => sum + num ** 2, 0); | const assert = require('node:assert');
function test() {
let candidate = sum_squares;
assert.deepEqual(candidate([1.0, 2.0, 3.0]),14);
assert.deepEqual(candidate([1.0, 2.0, 3.0]),14);
assert.deepEqual(candidate([1.0, 3.0, 5.0, 7.0]),84);
assert.deepEqual(candidate([1.4, 4.2, 0.0]),29);
assert.deepEqual(candidate([-2.4, 1.0, 1.0]),6);
assert.deepEqual(candidate([100.0, 1.0, 15.0, 2.0]),10230);
assert.deepEqual(candidate([10000.0, 10000.0]),200000000);
assert.deepEqual(candidate([-1.4, 4.6, 6.3]),75);
assert.deepEqual(candidate([-1.4, 17.9, 18.9, 19.9]),1086);
assert.deepEqual(candidate([0.0]),0);
assert.deepEqual(candidate([-1.0]),1);
assert.deepEqual(candidate([-1.0, 1.0, 0.0]),2);
}
test(); |
humaneval-HumanEval_112_reverse_delete.json-L17 | py | from typing import Tuple
def reverse_delete(s: str, c: str) -> Tuple[str, bool]:
"""Task
We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
then check if the result string is palindrome.
A string is called palindrome if it reads the same backward as forward.
You should return a tuple containing the result string and True/False for the check.
Example
>>> reverse_delete('abcde', 'ae')
('bcd', False)
>>> reverse_delete('abcdef', 'b')
('acdef', False)
>>> reverse_delete('abcdedcba', 'ab')
('cdedc', True)
"""
| for i in s:
if i not in c:
new_str += i
new_str_reverse = new_str[::-1]
return (new_str, new_str == new_str_reverse)
| new_str = '' | def check(candidate):
assert candidate('abcde', 'ae') == ('bcd', False)
assert candidate('abcdef', 'b') == ('acdef', False)
assert candidate('abcdedcba', 'ab') == ('cdedc', True)
assert candidate('dwik', 'w') == ('dik', False)
assert candidate('a', 'a') == ('', True)
assert candidate('abcdedcba', '') == ('abcdedcba', True)
assert candidate('abcdedcba', 'v') == ('abcdedcba', True)
assert candidate('vabba', 'v') == ('abba', True)
assert candidate('mamma', 'mia') == ('', True)
def test_check():
check(reverse_delete)
test_check()
|
humaneval-HumanEval_105_by_length.json-L46 | js | //Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// >>> by_length([2, 1, 1, 4, 5, 8, 2, 3])
// ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// If the array is empty, return an empty array:
// >>> by_length([])
// []
// If the array has any strange number ignore it:
// >>> by_length([1, -1, 55])
// ["One"]
function by_length(arr){
var arr2 = [];
for(var i = 0; i < arr.length; i++){
var num = arr[i];
if(num > 0 && num < 10){
arr2.push(num);
}
}
arr2.sort();
arr2.reverse();
var arr3 = [];
for(var i = 0; i < arr2.length; i++){
var num = arr2[i];
if(num == 1){
arr3.push("One");
}
else if(num == 2){
arr3.push("Two");
}
else if(num == 3){
arr3.push("Three");
}
else if(num == 4){
arr3.push("Four");
}
else if(num == 5){
arr3.push("Five");
}
else if(num == 6){
arr3.push("Six");
}
else if(num == 7){
arr3.push("Seven"); | else if(num == 8){
arr3.push("Eight");
}
else if(num == 9){
arr3.push("Nine");
}
}
return arr3;
} | } | const assert = require('node:assert');
function test() {
let candidate = by_length;
assert.deepEqual(candidate([2, 1, 1, 4, 5, 8, 2, 3]),["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]);
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([1, -1, 55]),["One"]);
assert.deepEqual(candidate([1, -1, 3, 2]),["Three", "Two", "One"]);
assert.deepEqual(candidate([9, 4, 8]),["Nine", "Eight", "Four"]);
}
test(); |
humaneval-HumanEval_133_sum_squares.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given an array array list of numbers.
// You need to return the sum of squared numbers in the given array list,
// round each element in the array list to the upper int(Ceiling) first.
// Examples:
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f))))
// (14l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)4.0f, (float)9.0f))))
// (98l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)3.0f, (float)5.0f, (float)7.0f))))
// (84l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.4f, (float)4.2f, (float)0.0f))))
// (29l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)-2.4f, (float)1.0f, (float)1.0f))))
// (6l)
public static long sumSquares(ArrayList<Float> lst) {
| return 0;
}
long sum = 0;
for (int i = 0; i < lst.size(); i++) {
sum += (long)Math.ceil(lst.get(i)) * (long)Math.ceil(lst.get(i));
}
return sum;
}
} | if (lst.size() == 0) { | }
public static void main(String[] args) {
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f)))) == (14l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f)))) == (14l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)3.0f, (float)5.0f, (float)7.0f)))) == (84l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.4f, (float)4.2f, (float)0.0f)))) == (29l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-2.4f, (float)1.0f, (float)1.0f)))) == (6l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)100.0f, (float)1.0f, (float)15.0f, (float)2.0f)))) == (10230l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)10000.0f, (float)10000.0f)))) == (200000000l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.4f, (float)4.6f, (float)6.3f)))) == (75l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.4f, (float)17.9f, (float)18.9f, (float)19.9f)))) == (1086l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)0.0f)))) == (0l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.0f)))) == (1l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.0f, (float)1.0f, (float)0.0f)))) == (2l));
}
}
|
humaneval-HumanEval_10_make_palindrome.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 {
// 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.
// >>> makePalindrome((""))
// ("")
// >>> makePalindrome(("cat"))
// ("catac")
// >>> makePalindrome(("cata"))
// ("catac")
public static String makePalindrome(String string) {
| String reverse = new StringBuilder(string).reverse().toString();
for (int index = 0; index < string.length(); index++) {
if (string.substring(index).equals(reverse.substring(0, string.length() - index))) {
newString.append(reverse.substring(string.length() - index));
break;
}
}
return newString.toString();
}
} | StringBuilder newString = new StringBuilder(string); | }
public static void main(String[] args) {
assert(makePalindrome(("")).equals(("")));
assert(makePalindrome(("x")).equals(("x")));
assert(makePalindrome(("xyz")).equals(("xyzyx")));
assert(makePalindrome(("xyx")).equals(("xyx")));
assert(makePalindrome(("jerry")).equals(("jerryrrej")));
}
}
|
humaneval-HumanEval_64_vowels_count.json-L11 | js | //Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// >>> vowels_count("abcde")
// 2
// >>> vowels_count("ACEDY")
// 3
function vowels_count(s){
| var vowels = ['a','e','i','o','u'];
var count = 0;
for(var i=0; i<s.length; i++){
if(vowels.indexOf(s[i])!=-1){
count++;
}
}
if(s[s.length-1]=='y'){
count++;
}
return count;
}
| s=s.toLowerCase(); | const assert = require('node:assert');
function test() {
let candidate = vowels_count;
assert.deepEqual(candidate("abcde"),2);
assert.deepEqual(candidate("Alone"),3);
assert.deepEqual(candidate("key"),2);
assert.deepEqual(candidate("bye"),1);
assert.deepEqual(candidate("keY"),2);
assert.deepEqual(candidate("bYe"),1);
assert.deepEqual(candidate("ACEDY"),3);
}
test(); |
humaneval-HumanEval_161_solve.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 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")
public static String solve(String s) {
boolean letterNotFound = true;
StringBuilder sb = new StringBuilder();
if (s.length() == 0) return s;
for (int i = 0; i < s.length(); i++) {
if (Character.isLetter(s.charAt(i))) {
letterNotFound = false;
if (Character.isUpperCase(s.charAt(i))) {
sb.append(Character.toLowerCase(s.charAt(i)));
} else {
sb.append(Character.toUpperCase(s.charAt(i)));
} | sb.append(s.charAt(i));
}
}
if (letterNotFound) {
return sb.reverse().toString();
}
return sb.toString();
}
} | } else { | }
public static void main(String[] args) {
assert(solve(("AsDf")).equals(("aSdF")));
assert(solve(("1234")).equals(("4321")));
assert(solve(("ab")).equals(("AB")));
assert(solve(("#a@C")).equals(("#A@c")));
assert(solve(("#AsdfW^45")).equals(("#aSDFw^45")));
assert(solve(("#6@2")).equals(("2@6#")));
assert(solve(("#$a^D")).equals(("#$A^d")));
assert(solve(("#ccc")).equals(("#CCC")));
}
}
|
humaneval-HumanEval_143_words_in_sentence.json-L29 | js | //You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// >>> words_in_sentence("This is a test")
// "is"
// Example 2:
// >>> words_in_sentence("lets go for swimming")
// "go for"
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
function words_in_sentence(sentence){
return sentence.split(' ').filter(word => {
var number = word.length;
var isPrime = true;
if(number === 1 || number === 0){
return false;
}
for(var i = 2; i < number; i++){
if(number % i === 0){
isPrime = false;
break;
}
}
return isPrime; | } | }).join(' '); | const assert = require('node:assert');
function test() {
let candidate = words_in_sentence;
assert.deepEqual(candidate("This is a test"),"is");
assert.deepEqual(candidate("lets go for swimming"),"go for");
assert.deepEqual(candidate("there is no place available here"),"there is no place");
assert.deepEqual(candidate("Hi I am Hussein"),"Hi am Hussein");
assert.deepEqual(candidate("go for it"),"go for it");
assert.deepEqual(candidate("here"),"");
assert.deepEqual(candidate("here is"),"is");
}
test(); |
humaneval-HumanEval_149_sorted_list_sum.json-L29 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that 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_81_numerical_letter_grade.json-L31 | 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 = []
for x in grades: | 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
| if x == 4.0: | def check(candidate):
assert candidate([4.0, 3, 1.7, 2, 3.5]) == ['A+', 'B', 'C-', 'C', 'A-']
assert candidate([1.2]) == ['D+']
assert candidate([0.5]) == ['D-']
assert candidate([0.0]) == ['E']
assert candidate([1.0, 0.3, 1.5, 2.8, 3.3]) == ['D', 'D-', 'C-', 'B', 'B+']
assert candidate([0.0, 0.7]) == ['E', 'D-']
def test_check():
check(numerical_letter_grade)
test_check()
|
humaneval-HumanEval_18_how_many_times.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 {
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// >>> howManyTimes((""), ("a"))
// (0l)
// >>> howManyTimes(("aaa"), ("a"))
// (3l)
// >>> howManyTimes(("aaaa"), ("aa"))
// (3l)
public static long howManyTimes(String string, String substring) {
long count = 0;
int index = 0;
while (index != -1) {
index = string.indexOf(substring, index);
if (index != -1) {
index++;
count++;
}
}
return count; | } | } | }
public static void main(String[] args) {
assert(howManyTimes((""), ("x")) == (0l));
assert(howManyTimes(("xyxyxyx"), ("x")) == (4l));
assert(howManyTimes(("cacacacac"), ("cac")) == (4l));
assert(howManyTimes(("john doe"), ("john")) == (1l));
}
}
|
humaneval-HumanEval_151_double_the_difference.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 an array array list of numbers, return the sum of squares of the numbers
// in the array list that are odd. Ignore numbers that are negative or not integers.
// >>> doubleTheDifference((new ArrayList<Float>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)0l))))
// (10l)
// >>> doubleTheDifference((new ArrayList<Float>(Arrays.asList((long)-1l, (long)-2l, (long)0l))))
// (0l)
// >>> doubleTheDifference((new ArrayList<Float>(Arrays.asList((long)9l, (long)-2l))))
// (81l)
// >>> doubleTheDifference((new ArrayList<Float>(Arrays.asList((long)0l))))
// (0l)
// If the input array list is empty, return 0.
public static long doubleTheDifference(ArrayList<Float> lst) {
return lst.stream().filter(x -> x%2 == 1).mapToLong(Math::round).map(x -> x*x).sum();
} | } | }
public static void main(String[] args) {
assert(doubleTheDifference((new ArrayList<Float>(Arrays.asList()))) == (0l));
assert(doubleTheDifference((new ArrayList<Float>(Arrays.asList((float)5.0f, (float)4.0f)))) == (25l));
assert(doubleTheDifference((new ArrayList<Float>(Arrays.asList((float)0.1f, (float)0.2f, (float)0.3f)))) == (0l));
assert(doubleTheDifference((new ArrayList<Float>(Arrays.asList((float)-10.0f, (float)-20.0f, (float)-30.0f)))) == (0l));
assert(doubleTheDifference((new ArrayList<Float>(Arrays.asList((float)-1.0f, (float)-2.0f, (float)8.0f)))) == (0l));
assert(doubleTheDifference((new ArrayList<Float>(Arrays.asList((float)0.2f, (float)3.0f, (float)5.0f)))) == (34l));
assert(doubleTheDifference((new ArrayList<Float>(Arrays.asList((float)-9.0f, (float)-7.0f, (float)-5.0f, (float)-3.0f, (float)-1.0f, (float)1.0f, (float)3.0f, (float)5.0f, (float)7.0f, (float)9.0f)))) == (165l));
}
}
|
|
humaneval-HumanEval_94_skjkasdkd.json-L60 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given an array array list of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l, (long)2l, (long)1l, (long)3l, (long)5l, (long)7l, (long)4l, (long)5l, (long)5l, (long)5l, (long)2l, (long)181l, (long)32l, (long)4l, (long)32l, (long)3l, (long)2l, (long)32l, (long)324l, (long)4l, (long)3l))))
// (10l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)1l, (long)8l, (long)2l, (long)4597l, (long)2l, (long)1l, (long)3l, (long)40l, (long)1l, (long)2l, (long)1l, (long)2l, (long)4l, (long)2l, (long)5l, (long)1l))))
// (25l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)1l, (long)32l, (long)5107l, (long)34l, (long)83278l, (long)109l, (long)163l, (long)23l, (long)2323l, (long)32l, (long)30l, (long)1l, (long)9l, (long)3l))))
// (13l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)724l, (long)32l, (long)71l, (long)99l, (long)32l, (long)6l, (long)0l, (long)5l, (long)91l, (long)83l, (long)0l, (long)5l, (long)6l))))
// (11l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)81l, (long)12l, (long)3l, (long)1l, (long)21l))))
// (3l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)8l, (long)1l, (long)2l, (long)1l, (long)7l))))
// (7l)
public static long skjkasdkd(ArrayList<Long> lst) {
long largestPrime = 0l;
for (Long item : lst) {
long number = item;
int counter = 0;
if (item == 1) {
continue;
}
if (item == 2) {
counter = 1;
}
else {
int l = 1;
while (l <= (int) number) {
if (number % l == 0) {
counter++;
}
l++;
}
}
if (counter == 2) {
if (number > largestPrime) {
largestPrime = number;
}
}
}
if (largestPrime == 0) {
return 0l;
}
else {
long output = 0l;
while (largestPrime > 0) {
output += largestPrime % 10;
largestPrime /= 10;
}
return output; | }
} | } | }
public static void main(String[] args) {
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l, (long)2l, (long)1l, (long)3l, (long)5l, (long)7l, (long)4l, (long)5l, (long)5l, (long)5l, (long)2l, (long)181l, (long)32l, (long)4l, (long)32l, (long)3l, (long)2l, (long)32l, (long)324l, (long)4l, (long)3l)))) == (10l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)1l, (long)8l, (long)2l, (long)4597l, (long)2l, (long)1l, (long)3l, (long)40l, (long)1l, (long)2l, (long)1l, (long)2l, (long)4l, (long)2l, (long)5l, (long)1l)))) == (25l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)1l, (long)32l, (long)5107l, (long)34l, (long)83278l, (long)109l, (long)163l, (long)23l, (long)2323l, (long)32l, (long)30l, (long)1l, (long)9l, (long)3l)))) == (13l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)724l, (long)32l, (long)71l, (long)99l, (long)32l, (long)6l, (long)0l, (long)5l, (long)91l, (long)83l, (long)0l, (long)5l, (long)6l)))) == (11l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)81l, (long)12l, (long)3l, (long)1l, (long)21l)))) == (3l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)8l, (long)1l, (long)2l, (long)1l, (long)7l)))) == (7l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)8191l)))) == (19l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)8191l, (long)123456l, (long)127l, (long)7l)))) == (19l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)127l, (long)97l, (long)8192l)))) == (10l));
}
}
|
humaneval-HumanEval_137_compare_one.json-L65 | 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): | if a > float(b_tmp):
return a
elif a < float(b_tmp):
return b
else:
return None
elif isinstance(a, str) and isinstance(b, float):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b | b_tmp = b.replace(',', '.') | 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_49_modp.json-L22 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return 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; | sqrt = (sqrt * sqrt) % p;
if (n % 2 == 0) {
return sqrt;
}
return (sqrt * 2) % p;
}
} | long sqrt = modp(n / 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_162_string_to_md5.json-L11 | py | from typing import Optional
def string_to_md5(text: str) -> Optional[str]:
"""
Given a string 'text', return its md5 hash equivalent string.
If 'text' is an empty string, return None.
>>> string_to_md5('Hello world')
'3e25960a79dbc69b674cd4ec67a72c62'
"""
| if not text:
return None
else:
return hashlib.md5(text.encode('utf-8')).hexdigest()
| import hashlib | def check(candidate):
assert candidate('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'
assert candidate('') == None
assert candidate('A B C') == '0ef78513b0cb8cef12743f5aeb35f888'
assert candidate('password') == '5f4dcc3b5aa765d61d8327deb882cf99'
def test_check():
check(string_to_md5)
test_check()
|
humaneval-HumanEval_89_encrypt.json-L17 | js | //Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// >>> encrypt("hi")
// "lm"
// >>> encrypt("asdfghjkl")
// "ewhjklnop"
// >>> encrypt("gf")
// "kj"
// >>> encrypt("et")
// "ix"
function encrypt(s){
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var newString = ""; | for(var i = 0; i < s.length; i++){
var index = alphabet.indexOf(s[i]);
newString += alphabet[(index + shiftBy) % 26];
}
return newString;
}
| var shiftBy = 2 * 2; | const assert = require('node:assert');
function test() {
let candidate = encrypt;
assert.deepEqual(candidate("hi"),"lm");
assert.deepEqual(candidate("asdfghjkl"),"ewhjklnop");
assert.deepEqual(candidate("gf"),"kj");
assert.deepEqual(candidate("et"),"ix");
assert.deepEqual(candidate("faewfawefaewg"),"jeiajeaijeiak");
assert.deepEqual(candidate("hellomyfriend"),"lippsqcjvmirh");
assert.deepEqual(candidate("dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh"),"hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl");
assert.deepEqual(candidate("a"),"e");
}
test(); |
humaneval-HumanEval_91_is_bored.json-L15 | js | //You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// >>> is_bored("Hello world")
// 0
// >>> is_bored("The sky is blue. The sun is shining. I love this weather")
// 1
function is_bored(S){
let lines = S.split(/[.?!]/);
let boredoms = 0;
for (let line of lines){
if(line.match(/^\s*I /)){
boredoms++; | }
return boredoms;
}
| } | const assert = require('node:assert');
function test() {
let candidate = is_bored;
assert.deepEqual(candidate("Hello world"),0);
assert.deepEqual(candidate("Is the sky blue?"),0);
assert.deepEqual(candidate("I love It !"),1);
assert.deepEqual(candidate("bIt"),0);
assert.deepEqual(candidate("I feel good today. I will be productive. will kill It"),2);
assert.deepEqual(candidate("You and I are going for a walk"),0);
}
test(); |
humaneval-HumanEval_28_concatenate.json-L10 | py | from typing import List
def concatenate(strings: List[str]) -> str:
""" Concatenate list of strings into a single string
>>> concatenate([])
''
>>> concatenate(['a', 'b', 'c'])
'abc'
"""
| return "".join(strings) | def check(candidate):
assert candidate([]) == ''
assert candidate(['x', 'y', 'z']) == 'xyz'
assert candidate(['x', 'y', 'z', 'w', 'k']) == 'xyzwk'
def test_check():
check(concatenate)
test_check()
|
|
humaneval-HumanEval_153_Strongest_Extension.json-L27 | py | from typing import List
def Strongest_Extension(class_name: str, extensions: List[str]) -> str:
"""You will be given the name of a class (a string) and a 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 list.
For example, if you are given "Slices" as the class and a list of the
extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
(its strength is -1).
Example:
>>> Strongest_Extension('my_class', ['AA', 'Be', 'CC'])
'my_class.AA'
"""
best_strength, best_extension = -1, ''
for extension in extensions:
n_uppercase = sum(1 for c in extension if c.isupper())
n_lowercase = sum(1 for c in extension if c.islower())
if n_uppercase - n_lowercase > best_strength:
best_strength = n_uppercase - n_lowercase | return class_name + '.' + best_extension | best_extension = extension | def check(candidate):
assert candidate('Watashi', ['tEN', 'niNE', 'eIGHt8OKe']) == 'Watashi.eIGHt8OKe'
assert candidate('Boku123', ['nani', 'NazeDa', 'YEs.WeCaNe', '32145tggg']) == 'Boku123.YEs.WeCaNe'
assert candidate('__YESIMHERE', ['t', 'eMptY', 'nothing', 'zeR00', 'NuLl__', '123NoooneB321']) == '__YESIMHERE.NuLl__'
assert candidate('K', ['Ta', 'TAR', 't234An', 'cosSo']) == 'K.TAR'
assert candidate('__HAHA', ['Tab', '123', '781345', '-_-']) == '__HAHA.123'
assert candidate('YameRore', ['HhAas', 'okIWILL123', 'WorkOut', 'Fails', '-_-']) == 'YameRore.okIWILL123'
assert candidate('finNNalLLly', ['Die', 'NowW', 'Wow', 'WoW']) == 'finNNalLLly.WoW'
assert candidate('_', ['Bb', '91245']) == '_.Bb'
assert candidate('Sp', ['671235', 'Bb']) == 'Sp.671235'
def test_check():
check(Strongest_Extension)
test_check()
|
humaneval-HumanEval_103_rounded_avg.json-L21 | py | from typing import Union
def rounded_avg(n: int, m: int) -> Union[str, int]:
"""You are given two positive integers n and m, and your task is to compute the
average of the integers from n through m (including n and m).
Round the answer to the nearest integer and convert that to binary.
If n is greater than m, return -1.
Example:
>>> rounded_avg(1, 5)
'0b11'
>>> rounded_avg(7, 5)
-1
>>> rounded_avg(10, 20)
'0b1111'
>>> rounded_avg(20, 33)
'0b11010'
"""
if n <= m:
rounded_avg = round(((n + m) / 2))
return(bin(rounded_avg)) | return(-1) | else: | def check(candidate):
assert candidate(1, 5) == '0b11'
assert candidate(7, 13) == '0b1010'
assert candidate(964, 977) == '0b1111001010'
assert candidate(996, 997) == '0b1111100100'
assert candidate(560, 851) == '0b1011000010'
assert candidate(185, 546) == '0b101101110'
assert candidate(362, 496) == '0b110101101'
assert candidate(350, 902) == '0b1001110010'
assert candidate(197, 233) == '0b11010111'
assert candidate(7, 5) == -1
assert candidate(5, 1) == -1
assert candidate(5, 5) == '0b101'
def test_check():
check(rounded_avg)
test_check()
|
humaneval-HumanEval_81_numerical_letter_grade.json-L38 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// 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) { | } 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;
}
} | 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_154_cycpattern_check.json-L21 | js | //You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// >>> cycpattern_check("abcd", "abd")
// false
// >>> cycpattern_check("hello", "ell")
// true
// >>> cycpattern_check("whassup", "psus")
// false
// >>> cycpattern_check("abab", "baa")
// true
// >>> cycpattern_check("efef", "eeff")
// false
// >>> cycpattern_check("himenss", "simen")
// true
function cycpattern_check(a, b){
var result = false;
for(var i = 0; i < b.length; i++){
result = result || a.includes(b);
b = b.slice(1) + b[0];
}
return result; | } | const assert = require('node:assert');
function test() {
let candidate = cycpattern_check;
assert.deepEqual(candidate("xyzw", "xyw"),false);
assert.deepEqual(candidate("yello", "ell"),true);
assert.deepEqual(candidate("whattup", "ptut"),false);
assert.deepEqual(candidate("efef", "fee"),true);
assert.deepEqual(candidate("abab", "aabb"),false);
assert.deepEqual(candidate("winemtt", "tinem"),true);
}
test(); |
|
humaneval-HumanEval_155_even_odd_count.json-L15 | 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 | digit = int(ch)
if digit % 2 == 0:
even_count += 1
else:
odd_count += 1
return even_count, odd_count
| for ch in num_str: | 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_67_fruit_distribution.json-L24 | py | def fruit_distribution(s: str, n: int) -> int:
"""
In this task, you will be given a string that represents a number of apples and oranges
that are distributed in a basket of fruit this basket contains
apples, oranges, and mango fruits. Given the string that represents the total number of
the 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
"""
fruits = []
for fruit in s.split(' '):
try:
fruits.append(int(fruit))
except:
pass | return n - sum(fruits) | def check(candidate):
assert candidate('5 apples and 6 oranges', 19) == 8
assert candidate('5 apples and 6 oranges', 21) == 10
assert candidate('0 apples and 1 oranges', 3) == 2
assert candidate('1 apples and 0 oranges', 3) == 2
assert candidate('2 apples and 3 oranges', 100) == 95
assert candidate('2 apples and 3 oranges', 5) == 0
assert candidate('1 apples and 100 oranges', 120) == 19
def test_check():
check(fruit_distribution)
test_check()
|
|
humaneval-HumanEval_121_solution.json-L12 | js | //Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// >>> solution([5, 8, 7, 1])
// 12
// >>> solution([3, 3, 3, 3, 3])
// 9
// >>> solution([30, 13, 24, 321])
// 0
function solution(lst){
let result = 0;
for (let i = 0; i < lst.length; i++){ | if (lst[i] % 2 === 1){
result += lst[i];
}
}
}
return result;
} | if (i % 2 === 0){ | const assert = require('node:assert');
function test() {
let candidate = solution;
assert.deepEqual(candidate([5, 8, 7, 1]),12);
assert.deepEqual(candidate([3, 3, 3, 3, 3]),9);
assert.deepEqual(candidate([30, 13, 24, 321]),0);
assert.deepEqual(candidate([5, 9]),5);
assert.deepEqual(candidate([2, 4, 8]),0);
assert.deepEqual(candidate([30, 13, 23, 32]),23);
assert.deepEqual(candidate([3, 13, 2, 9]),3);
}
test(); |
humaneval-HumanEval_129_minPath.json-L41 | js | //Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// >>> minPath([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3)
// [1, 2, 1]
// >>> minPath([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1)
// [1]
function minPath(grid, k){
let n = grid.length;
let path = [];
let startCell = grid[0][0];
for(let i = 0; i < n; i++){
for(let j = 0; j < n; j++){
let curr = grid[i][j];
if(curr < startCell){
startCell = curr;
}
}
}
let currCell = startCell;
for(let l = 0; l < k; l++){
path.push(currCell);
let neighbours = [];
let x = null; | for(let i = 0; i < n; i++){
for(let j = 0; j < n; j++){
if(grid[i][j] === currCell){
x = i;
y = j;
}
}
}
if(x > 0){
neighbours.push(grid[x - 1][y]);
}
if(x < n - 1){
neighbours.push(grid[x + 1][y]);
}
if(y > 0){
neighbours.push(grid[x][y - 1]);
}
if(y < n - 1){
neighbours.push(grid[x][y + 1]);
}
let nextCell = neighbours[0];
for(let i = 0; i < neighbours.length; i++){
let curr = neighbours[i];
if(curr < nextCell){
nextCell = curr;
}
}
currCell = nextCell;
}
return path;
} | let y = null; | const assert = require('node:assert');
function test() {
let candidate = minPath;
assert.deepEqual(candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3),[1, 2, 1]);
assert.deepEqual(candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1),[1]);
assert.deepEqual(candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], 4),[1, 2, 1, 2]);
assert.deepEqual(candidate([[6, 4, 13, 10], [5, 7, 12, 1], [3, 16, 11, 15], [8, 14, 9, 2]], 7),[1, 10, 1, 10, 1, 10, 1]);
assert.deepEqual(candidate([[8, 14, 9, 2], [6, 4, 13, 15], [5, 7, 1, 12], [3, 10, 11, 16]], 5),[1, 7, 1, 7, 1]);
assert.deepEqual(candidate([[11, 8, 7, 2], [5, 16, 14, 4], [9, 3, 15, 6], [12, 13, 10, 1]], 9),[1, 6, 1, 6, 1, 6, 1, 6, 1]);
assert.deepEqual(candidate([[12, 13, 10, 1], [9, 3, 15, 6], [5, 16, 14, 4], [11, 8, 7, 2]], 12),[1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6]);
assert.deepEqual(candidate([[2, 7, 4], [3, 1, 5], [6, 8, 9]], 8),[1, 3, 1, 3, 1, 3, 1, 3]);
assert.deepEqual(candidate([[6, 1, 5], [3, 8, 9], [2, 7, 4]], 8),[1, 5, 1, 5, 1, 5, 1, 5]);
assert.deepEqual(candidate([[1, 2], [3, 4]], 10),[1, 2, 1, 2, 1, 2, 1, 2, 1, 2]);
assert.deepEqual(candidate([[1, 3], [3, 2]], 10),[1, 3, 1, 3, 1, 3, 1, 3, 1, 3]);
}
test(); |
humaneval-HumanEval_137_compare_one.json-L25 | 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: | 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
elif a < float(b_tmp):
return b
else:
return None
elif isinstance(a, str) and isinstance(b, float):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b | return None | def check(candidate):
assert candidate(1, 2) == 2
assert candidate(1, 2.5) == 2.5
assert candidate(2, 3) == 3
assert candidate(5, 6) == 6
assert candidate(1, '2,3') == '2,3'
assert candidate('5,1', '6') == '6'
assert candidate('1', '2') == '2'
assert candidate('1', 1) == None
def test_check():
check(compare_one)
test_check()
|
humaneval-HumanEval_90_next_smallest.json-L22 | py | from typing import List, Optional
def next_smallest(lst: List[int]) -> Optional[int]:
"""
You are given a list of integers.
Write a function next_smallest() that returns the 2nd smallest element of the list.
Return None if there is no such element.
>>> next_smallest([1, 2, 3, 4, 5])
2
>>> next_smallest([5, 1, 4, 3, 2])
2
>>> next_smallest([])
None
>>> next_smallest([1, 1])
None
"""
if len(lst) < 2:
return None
min1 = min(lst[0], lst[1])
min2 = max(lst[0], lst[1])
for i in range(2, len(lst)): | min2 = min1
min1 = lst[i]
elif lst[i] < min2:
min2 = lst[i]
return min2 if min1 != min2 else None
| if lst[i] < min1: | def check(candidate):
assert candidate([1, 2, 3, 4, 5]) == 2
assert candidate([5, 1, 4, 3, 2]) == 2
assert candidate([]) == None
assert candidate([1, 1]) == None
assert candidate([1, 1, 1, 1, 0]) == 1
assert candidate([1, 1]) == None
assert candidate([-35, 34, 12, -45]) == -35
def test_check():
check(next_smallest)
test_check()
|
humaneval-HumanEval_160_do_algebra.json-L43 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given 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_146_specialFilter.json-L15 | py | from typing import List
def specialFilter(nums: List[int]) -> int:
"""Write a function that takes an array of numbers as input and returns
the number of elements in the array that are greater than 10 and both
first and last digits of a number are odd (1, 3, 5, 7, 9).
For example:
>>> specialFilter([15, -73, 14, -15])
1
>>> specialFilter([33, -2, -3, 45, 21, 109])
2
"""
count = 0
for num in nums: | continue
else:
rev = int(str(num)[::-1])
if num % 2 != 0 and rev % 2 != 0:
count += 1
return count
| if num < 10: | def check(candidate):
assert candidate([5, -2, 1, -5]) == 0
assert candidate([15, -73, 14, -15]) == 1
assert candidate([33, -2, -3, 45, 21, 109]) == 2
assert candidate([43, -12, 93, 125, 121, 109]) == 4
assert candidate([71, -2, -33, 75, 21, 19]) == 3
assert candidate([1]) == 0
assert candidate([]) == 0
def test_check():
check(specialFilter)
test_check()
|
humaneval-HumanEval_105_by_length.json-L44 | js | //Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// >>> by_length([2, 1, 1, 4, 5, 8, 2, 3])
// ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// If the array is empty, return an empty array:
// >>> by_length([])
// []
// If the array has any strange number ignore it:
// >>> by_length([1, -1, 55])
// ["One"]
function by_length(arr){
var arr2 = [];
for(var i = 0; i < arr.length; i++){
var num = arr[i];
if(num > 0 && num < 10){
arr2.push(num);
}
}
arr2.sort();
arr2.reverse();
var arr3 = [];
for(var i = 0; i < arr2.length; i++){
var num = arr2[i];
if(num == 1){
arr3.push("One");
}
else if(num == 2){
arr3.push("Two");
}
else if(num == 3){
arr3.push("Three");
}
else if(num == 4){
arr3.push("Four");
}
else if(num == 5){
arr3.push("Five");
}
else if(num == 6){
arr3.push("Six");
} | arr3.push("Seven");
}
else if(num == 8){
arr3.push("Eight");
}
else if(num == 9){
arr3.push("Nine");
}
}
return arr3;
} | else if(num == 7){ | const assert = require('node:assert');
function test() {
let candidate = by_length;
assert.deepEqual(candidate([2, 1, 1, 4, 5, 8, 2, 3]),["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]);
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([1, -1, 55]),["One"]);
assert.deepEqual(candidate([1, -1, 3, 2]),["Three", "Two", "One"]);
assert.deepEqual(candidate([9, 4, 8]),["Nine", "Eight", "Four"]);
}
test(); |
humaneval-HumanEval_69_search.json-L23 | py | from typing import List
def search(lst: List[int]) -> int:
"""
You are given a non-empty list of positive integers. Return the greatest integer that is greater than
zero, and has a frequency greater than or equal to the value of the integer itself.
The frequency of an integer is the number of times it appears in the list.
If no such a value exist, return -1.
Examples:
>>> search([4, 1, 2, 2, 3, 1])
2
>>> search([1, 2, 2, 3, 3, 3, 4, 4, 4])
3
>>> search([5, 5, 4, 4, 4])
-1
"""
dic = dict()
for i in lst:
if i in dic:
dic[i] += 1
else:
dic[i] = 1 | for key, value in dic.items():
if value >= key and key > maxValue:
maxValue = key
return maxValue
| maxValue = -1 | def check(candidate):
assert candidate([5, 5, 5, 5, 1]) == 1
assert candidate([4, 1, 4, 1, 4, 4]) == 4
assert candidate([3, 3]) == -1
assert candidate([8, 8, 8, 8, 8, 8, 8, 8]) == 8
assert candidate([2, 3, 3, 2, 2]) == 2
assert candidate([2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1]) == 1
assert candidate([3, 2, 8, 2]) == 2
assert candidate([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]) == 1
assert candidate([8, 8, 3, 6, 5, 6, 4]) == -1
assert candidate([6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9]) == 1
assert candidate([1, 9, 10, 1, 3]) == 1
assert candidate([6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10]) == 5
assert candidate([1]) == 1
assert candidate([8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5]) == 4
assert candidate([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]) == 2
assert candidate([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]) == 1
assert candidate([9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4]) == 4
assert candidate([2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7]) == 4
assert candidate([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]) == 2
assert candidate([5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8]) == -1
assert candidate([10]) == -1
assert candidate([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]) == 2
assert candidate([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]) == 1
assert candidate([7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6]) == 1
assert candidate([3, 10, 10, 9, 2]) == -1
def test_check():
check(search)
test_check()
|
humaneval-HumanEval_155_even_odd_count.json-L20 | js | //Given an integer. return an array that has the number of even and odd digits respectively.
// Example:
// >>> even_odd_count(-12)
// [1, 1]
// >>> even_odd_count(123)
// [1, 2]
function even_odd_count(num){
num = Math.abs(num);
var evens = 0;
var odds = 0;
for(var i = 0; i < num.toString().length; i++){
if(num.toString()[i] % 2 == 0){
evens ++;
}
else{
odds ++;
}
}
return [evens, odds]; | } | const assert = require('node:assert');
function test() {
let candidate = even_odd_count;
assert.deepEqual(candidate(7),[0, 1]);
assert.deepEqual(candidate(-78),[1, 1]);
assert.deepEqual(candidate(3452),[2, 2]);
assert.deepEqual(candidate(346211),[3, 3]);
assert.deepEqual(candidate(-345821),[3, 3]);
assert.deepEqual(candidate(-2),[1, 0]);
assert.deepEqual(candidate(-45347),[2, 3]);
assert.deepEqual(candidate(0),[1, 0]);
}
test(); |
|
humaneval-HumanEval_89_encrypt.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// >>> encrypt(("hi"))
// ("lm")
// >>> encrypt(("asdfghjkl"))
// ("ewhjklnop")
// >>> encrypt(("gf"))
// ("kj")
// >>> encrypt(("et"))
// ("ix")
public static String encrypt(String s) {
StringBuffer b = new StringBuffer(); | b.append((char)((c+4) > 'z' ? (((c+4)%'z')+'a'-1) : c+4));
}
return b.toString();
}
} | for (char c : s.toCharArray()) { | }
public static void main(String[] args) {
assert(encrypt(("hi")).equals(("lm")));
assert(encrypt(("asdfghjkl")).equals(("ewhjklnop")));
assert(encrypt(("gf")).equals(("kj")));
assert(encrypt(("et")).equals(("ix")));
assert(encrypt(("faewfawefaewg")).equals(("jeiajeaijeiak")));
assert(encrypt(("hellomyfriend")).equals(("lippsqcjvmirh")));
assert(encrypt(("dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh")).equals(("hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl")));
assert(encrypt(("a")).equals(("e")));
}
}
|
humaneval-HumanEval_81_numerical_letter_grade.json-L46 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array array list of GPAs for some students and you have to write
// a function that can output an array array list of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// >>> gradeEquation((new ArrayList<Float>(Arrays.asList((float)4.0f, (float)3l, (float)1.7f, (float)2l, (float)3.5f))))
// (new ArrayList<String>(Arrays.asList((String)"A+", (String)"B", (String)"C-", (String)"C", (String)"A-")))
public static ArrayList<String> numericalLetterGrade(ArrayList<Float> grades) {
ArrayList<String> letterGrades = new ArrayList<String>();
for (int i = 0; i < grades.size(); i++) {
float currentGrade = grades.get(i);
if (currentGrade == 4.0f) {
letterGrades.add("A+");
} else if (currentGrade > 3.7f) {
letterGrades.add("A");
} else if (currentGrade > 3.3f) {
letterGrades.add("A-");
} else if (currentGrade > 3.0f) {
letterGrades.add("B+");
} else if (currentGrade > 2.7f) {
letterGrades.add("B");
} else if (currentGrade > 2.3f) { | } 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("B-"); | }
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_142_sum_squares.json-L23 | js | //"
// This function will take an array of integers. For all entries in the array, the function shall square the integer entry if its index is a
// multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not
// change the entries in the array whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries.
// Examples:
// >>> lst
// [1, 2, 3]
// >>> lst
// []
// >>> lst
// [-1, -5, 2, -1, -5]
function sum_squares(lst){
var sum = 0;
var len = lst.length;
for (var i = 0; i < len; i++){
if (i % 3 == 0){
sum += lst[i]*lst[i];
} else if (i % 4 == 0){
sum += lst[i]*lst[i]*lst[i];
} else {
sum += lst[i];
} | return sum;
} | } | const assert = require('node:assert');
function test() {
let candidate = sum_squares;
assert.deepEqual(candidate([1, 2, 3]),6);
assert.deepEqual(candidate([1, 4, 9]),14);
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([1, 1, 1, 1, 1, 1, 1, 1, 1]),9);
assert.deepEqual(candidate([-1, -1, -1, -1, -1, -1, -1, -1, -1]),-3);
assert.deepEqual(candidate([0]),0);
assert.deepEqual(candidate([-1, -5, 2, -1, -5]),-126);
assert.deepEqual(candidate([-56, -99, 1, 0, -2]),3030);
assert.deepEqual(candidate([-1, 0, 0, 0, 0, 0, 0, 0, -1]),0);
assert.deepEqual(candidate([-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37]),-14196);
assert.deepEqual(candidate([-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10]),-1448);
}
test(); |
humaneval-HumanEval_119_match_parens.json-L39 | js | //You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// >>> match_parens(["()(", ")"])
// "Yes"
// >>> match_parens([")", ")"])
// "No"
function match_parens(lst){
const open = '(';
const close = ')';
const is_good = (s) => {
let stack = [];
for (let p of s){
if (p === open){
stack.push(p);
} else if (p === close){
if (stack.length === 0){
return false;
}
stack.pop();
}
}
return stack.length === 0;
};
const str1 = lst[0];
const str2 = lst[1];
if (is_good(str1 + str2)){
return 'Yes';
}
if (is_good(str2 + str1)){
return 'Yes';
} | } | return 'No'; | const assert = require('node:assert');
function test() {
let candidate = match_parens;
assert.deepEqual(candidate(["()(", ")"]),"Yes");
assert.deepEqual(candidate([")", ")"]),"No");
assert.deepEqual(candidate(["(()(())", "())())"]),"No");
assert.deepEqual(candidate([")())", "(()()("]),"Yes");
assert.deepEqual(candidate(["(())))", "(()())(("]),"Yes");
assert.deepEqual(candidate(["()", "())"]),"No");
assert.deepEqual(candidate(["(()(", "()))()"]),"Yes");
assert.deepEqual(candidate(["((((", "((())"]),"No");
assert.deepEqual(candidate([")(()", "(()("]),"No");
assert.deepEqual(candidate([")(", ")("]),"No");
assert.deepEqual(candidate(["(", ")"]),"Yes");
assert.deepEqual(candidate([")", "("]),"Yes");
}
test(); |
humaneval-HumanEval_111_histogram.json-L33 | 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){ | max = count[key];
result = {};
result[key] = max;
}
else if (count[key] === max){
result[key] = max;
}
}
return result;
}
| if (count[key] > max){ | 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_19_sort_numbers.json-L15 | js | //Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// >>> sort_numbers("three one five")
// "one three five"
function sort_numbers(numbers){
var numString = numbers.split(" ");
var numMap = {
"zero": 0,
"one": 1,
"two": 2,
"three": 3,
"four": 4,
"five": 5, | "seven": 7,
"eight": 8,
"nine": 9
};
numString.sort(function(a, b){
return numMap[a] - numMap[b];
});
numString = numString.join(" ");
return numString;
} | "six": 6, | const assert = require('node:assert');
function test() {
let candidate = sort_numbers;
assert.deepEqual(candidate(""),"");
assert.deepEqual(candidate("three"),"three");
assert.deepEqual(candidate("three five nine"),"three five nine");
assert.deepEqual(candidate("five zero four seven nine eight"),"zero four five seven eight nine");
assert.deepEqual(candidate("six five four three two one zero"),"zero one two three four five six");
}
test(); |
humaneval-HumanEval_88_sort_array.json-L36 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given 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_94_skjkasdkd.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 {
// You are given an array array list of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l, (long)2l, (long)1l, (long)3l, (long)5l, (long)7l, (long)4l, (long)5l, (long)5l, (long)5l, (long)2l, (long)181l, (long)32l, (long)4l, (long)32l, (long)3l, (long)2l, (long)32l, (long)324l, (long)4l, (long)3l))))
// (10l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)1l, (long)8l, (long)2l, (long)4597l, (long)2l, (long)1l, (long)3l, (long)40l, (long)1l, (long)2l, (long)1l, (long)2l, (long)4l, (long)2l, (long)5l, (long)1l))))
// (25l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)1l, (long)32l, (long)5107l, (long)34l, (long)83278l, (long)109l, (long)163l, (long)23l, (long)2323l, (long)32l, (long)30l, (long)1l, (long)9l, (long)3l))))
// (13l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)724l, (long)32l, (long)71l, (long)99l, (long)32l, (long)6l, (long)0l, (long)5l, (long)91l, (long)83l, (long)0l, (long)5l, (long)6l))))
// (11l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)81l, (long)12l, (long)3l, (long)1l, (long)21l))))
// (3l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)8l, (long)1l, (long)2l, (long)1l, (long)7l))))
// (7l)
public static long skjkasdkd(ArrayList<Long> lst) {
long largestPrime = 0l;
for (Long item : lst) {
long number = item;
int counter = 0;
if (item == 1) {
continue;
}
if (item == 2) {
counter = 1;
}
else {
int l = 1;
while (l <= (int) number) {
if (number % l == 0) {
counter++;
}
l++;
}
}
if (counter == 2) {
if (number > largestPrime) {
largestPrime = number;
} | }
if (largestPrime == 0) {
return 0l;
}
else {
long output = 0l;
while (largestPrime > 0) {
output += largestPrime % 10;
largestPrime /= 10;
}
return output;
}
}
} | } | }
public static void main(String[] args) {
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l, (long)2l, (long)1l, (long)3l, (long)5l, (long)7l, (long)4l, (long)5l, (long)5l, (long)5l, (long)2l, (long)181l, (long)32l, (long)4l, (long)32l, (long)3l, (long)2l, (long)32l, (long)324l, (long)4l, (long)3l)))) == (10l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)1l, (long)8l, (long)2l, (long)4597l, (long)2l, (long)1l, (long)3l, (long)40l, (long)1l, (long)2l, (long)1l, (long)2l, (long)4l, (long)2l, (long)5l, (long)1l)))) == (25l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)1l, (long)32l, (long)5107l, (long)34l, (long)83278l, (long)109l, (long)163l, (long)23l, (long)2323l, (long)32l, (long)30l, (long)1l, (long)9l, (long)3l)))) == (13l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)724l, (long)32l, (long)71l, (long)99l, (long)32l, (long)6l, (long)0l, (long)5l, (long)91l, (long)83l, (long)0l, (long)5l, (long)6l)))) == (11l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)81l, (long)12l, (long)3l, (long)1l, (long)21l)))) == (3l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)8l, (long)1l, (long)2l, (long)1l, (long)7l)))) == (7l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)8191l)))) == (19l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)8191l, (long)123456l, (long)127l, (long)7l)))) == (19l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)127l, (long)97l, (long)8192l)))) == (10l));
}
}
|
humaneval-HumanEval_25_factorize.json-L15 | js | //Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// >>> factorize(8)
// [2, 2, 2]
// >>> factorize(25)
// [5, 5]
// >>> factorize(70)
// [2, 5, 7]
function factorize(n){
let factor = 2;
let arr = [];
while (n > 1) {
if (n % factor == 0) { | n = n / factor;
} else {
factor++;
}
}
return arr;
}
| arr.push(factor); | const assert = require('node:assert');
function test() {
let candidate = factorize;
assert.deepEqual(candidate(2),[2]);
assert.deepEqual(candidate(4),[2, 2]);
assert.deepEqual(candidate(8),[2, 2, 2]);
assert.deepEqual(candidate(57),[3, 19]);
assert.deepEqual(candidate(3249),[3, 3, 19, 19]);
assert.deepEqual(candidate(185193),[3, 3, 3, 19, 19, 19]);
assert.deepEqual(candidate(20577),[3, 19, 19, 19]);
assert.deepEqual(candidate(18),[2, 3, 3]);
}
test(); |
humaneval-HumanEval_117_select_words.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 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>(); | 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;
}
} | String[] words = s.split(" "); | }
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_131_digits.json-L22 | js | //Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// >>> digits(1)
// 1
// >>> digits(4)
// 0
// >>> digits(235)
// 15
function digits(n){
if(!n){
return "error";
}
if(n < 0){
return "error";
}
var temp = 0;
var prod = 1;
var odd = true;
for(n; n > 0; n = Math.floor(n/10)){
temp = n % 10; | prod *= temp;
odd = false;
}
}
if(odd){
return 0;
}
return prod;
}
| if(temp % 2 != 0){ | const assert = require('node:assert');
function test() {
let candidate = digits;
assert.deepEqual(candidate(5),5);
assert.deepEqual(candidate(54),5);
assert.deepEqual(candidate(120),1);
assert.deepEqual(candidate(5014),5);
assert.deepEqual(candidate(98765),315);
assert.deepEqual(candidate(5576543),2625);
assert.deepEqual(candidate(2468),0);
}
test(); |
humaneval-HumanEval_104_unique_digits.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 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;
}
z = z / 10;
}
if (unique) {
b.add(x.get(i));
}
}
Collections.sort(b);
return b; | } | } | }
public static void main(String[] args) {
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)15l, (long)33l, (long)1422l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)15l, (long)33l)))));
assert(uniqueDigits((new ArrayList<Long>(Arrays.asList((long)152l, (long)323l, (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_142_sum_squares.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 will take an array array list of integers. For all entries in the array list, the function shall square the integer entry if its index is a
// multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not
// change the entries in the array list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries.
// Examples:
// >>> lst
// (long)new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))
// >>> lst
// (long)new ArrayList<Long>(Arrays.asList())
// >>> lst
// (long)new ArrayList<Long>(Arrays.asList((long)-1l, (long)-5l, (long)2l, (long)-1l, (long)-5l))
public static long sumSquares(ArrayList<Long> lst) {
int sz = lst.size();
for (int i = 0; i < sz; i++) { | lst.set(i, lst.get(i) * lst.get(i));
} else if (i % 4 == 0) {
lst.set(i, lst.get(i) * lst.get(i) * lst.get(i));
}
}
long ans = 0;
for (int i = 0; i < sz; i++) {
ans += lst.get(i);
}
return ans;
}
} | if (i % 3 == 0) { | }
public static void main(String[] args) {
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))) == (6l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)9l)))) == (14l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList()))) == (0l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l, (long)1l, (long)1l, (long)1l, (long)1l, (long)1l)))) == (9l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-1l, (long)-1l, (long)-1l, (long)-1l, (long)-1l, (long)-1l, (long)-1l, (long)-1l)))) == (-3l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)0l)))) == (0l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-5l, (long)2l, (long)-1l, (long)-5l)))) == (-126l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)-56l, (long)-99l, (long)1l, (long)0l, (long)-2l)))) == (3030l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)-1l, (long)0l, (long)0l, (long)0l, (long)0l, (long)0l, (long)0l, (long)0l, (long)-1l)))) == (0l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)-16l, (long)-9l, (long)-2l, (long)36l, (long)36l, (long)26l, (long)-20l, (long)25l, (long)-40l, (long)20l, (long)-4l, (long)12l, (long)-26l, (long)35l, (long)37l)))) == (-14196l));
assert(sumSquares((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-3l, (long)17l, (long)-1l, (long)-15l, (long)13l, (long)-1l, (long)14l, (long)-14l, (long)-12l, (long)-5l, (long)14l, (long)-14l, (long)6l, (long)13l, (long)11l, (long)16l, (long)16l, (long)4l, (long)10l)))) == (-1448l));
}
}
|
humaneval-HumanEval_75_is_multiply_prime.json-L30 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// 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:
// >>> isMultiplyPrime((30l))
// (true)
// 30 = 2 * 3 * 5
public static boolean isMultiplyPrime(long a) {
if (a == 1) {
return false;
}
if (a == 2) {
return true;
}
long copyOfInput = a;
ArrayList<Long> arr = new ArrayList<Long>();
while (a % 2 == 0) {
arr.add(2l);
a /= 2;
}
for (long i = 3; i <= Math.sqrt(a); i += 2) { | arr.add(i);
a /= i;
}
}
if (a > 2) {
arr.add(a);
}
return arr.size() == 3;
}
} | while (a % i == 0) { | }
public static void main(String[] args) {
assert(isMultiplyPrime((5l)) == (false));
assert(isMultiplyPrime((30l)) == (true));
assert(isMultiplyPrime((8l)) == (true));
assert(isMultiplyPrime((10l)) == (false));
assert(isMultiplyPrime((125l)) == (true));
assert(isMultiplyPrime((105l)) == (true));
assert(isMultiplyPrime((126l)) == (false));
assert(isMultiplyPrime((729l)) == (false));
assert(isMultiplyPrime((891l)) == (false));
assert(isMultiplyPrime((1001l)) == (true));
}
}
|
humaneval-HumanEval_69_search.json-L18 | py | from typing import List
def search(lst: List[int]) -> int:
"""
You are given a non-empty list of positive integers. Return the greatest integer that is greater than
zero, and has a frequency greater than or equal to the value of the integer itself.
The frequency of an integer is the number of times it appears in the list.
If no such a value exist, return -1.
Examples:
>>> search([4, 1, 2, 2, 3, 1])
2
>>> search([1, 2, 2, 3, 3, 3, 4, 4, 4])
3
>>> search([5, 5, 4, 4, 4])
-1
"""
dic = dict() | if i in dic:
dic[i] += 1
else:
dic[i] = 1
maxValue = -1
for key, value in dic.items():
if value >= key and key > maxValue:
maxValue = key
return maxValue
| for i in lst: | def check(candidate):
assert candidate([5, 5, 5, 5, 1]) == 1
assert candidate([4, 1, 4, 1, 4, 4]) == 4
assert candidate([3, 3]) == -1
assert candidate([8, 8, 8, 8, 8, 8, 8, 8]) == 8
assert candidate([2, 3, 3, 2, 2]) == 2
assert candidate([2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1]) == 1
assert candidate([3, 2, 8, 2]) == 2
assert candidate([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]) == 1
assert candidate([8, 8, 3, 6, 5, 6, 4]) == -1
assert candidate([6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9]) == 1
assert candidate([1, 9, 10, 1, 3]) == 1
assert candidate([6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10]) == 5
assert candidate([1]) == 1
assert candidate([8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5]) == 4
assert candidate([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]) == 2
assert candidate([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]) == 1
assert candidate([9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4]) == 4
assert candidate([2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7]) == 4
assert candidate([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]) == 2
assert candidate([5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8]) == -1
assert candidate([10]) == -1
assert candidate([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]) == 2
assert candidate([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]) == 1
assert candidate([7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6]) == 1
assert candidate([3, 10, 10, 9, 2]) == -1
def test_check():
check(search)
test_check()
|
humaneval-HumanEval_143_words_in_sentence.json-L30 | js | //You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// >>> words_in_sentence("This is a test")
// "is"
// Example 2:
// >>> words_in_sentence("lets go for swimming")
// "go for"
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
function words_in_sentence(sentence){
return sentence.split(' ').filter(word => {
var number = word.length;
var isPrime = true;
if(number === 1 || number === 0){
return false;
}
for(var i = 2; i < number; i++){
if(number % i === 0){
isPrime = false;
break;
}
}
return isPrime;
}).join(' '); | } | const assert = require('node:assert');
function test() {
let candidate = words_in_sentence;
assert.deepEqual(candidate("This is a test"),"is");
assert.deepEqual(candidate("lets go for swimming"),"go for");
assert.deepEqual(candidate("there is no place available here"),"there is no place");
assert.deepEqual(candidate("Hi I am Hussein"),"Hi am Hussein");
assert.deepEqual(candidate("go for it"),"go for it");
assert.deepEqual(candidate("here"),"");
assert.deepEqual(candidate("here is"),"is");
}
test(); |
|
humaneval-HumanEval_81_numerical_letter_grade.json-L61 | js | //It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// >>> grade_equation([4.0, 3, 1.7, 2, 3.5])
// ["A+", "B", "C-", "C", "A-"]
function numerical_letter_grade(grades){
var grades_array = [];
for (var i = 0; i < grades.length; i++){
if (grades[i] >= 4.0){
grades_array.push("A+");
}
else if (grades[i] > 3.7){
grades_array.push("A");
}
else if (grades[i] > 3.3){
grades_array.push("A-");
}
else if (grades[i] > 3.0){
grades_array.push("B+");
}
else if (grades[i] > 2.7){
grades_array.push("B");
}
else if (grades[i] > 2.3){
grades_array.push("B-");
}
else if (grades[i] > 2.0){
grades_array.push("C+");
}
else if (grades[i] > 1.7){
grades_array.push("C");
}
else if (grades[i] > 1.3){
grades_array.push("C-");
}
else if (grades[i] > 1.0){
grades_array.push("D+");
}
else if (grades[i] > 0.7){
grades_array.push("D");
}
else if (grades[i] > 0.0){
grades_array.push("D-"); | else if (grades[i] == 0.0){
grades_array.push("E");
}
}
return grades_array;
} | } | const assert = require('node:assert');
function test() {
let candidate = numerical_letter_grade;
assert.deepEqual(candidate([4.0, 3, 1.7, 2, 3.5]),["A+", "B", "C-", "C", "A-"]);
assert.deepEqual(candidate([1.2]),["D+"]);
assert.deepEqual(candidate([0.5]),["D-"]);
assert.deepEqual(candidate([0.0]),["E"]);
assert.deepEqual(candidate([1.0, 0.3, 1.5, 2.8, 3.3]),["D", "D-", "C-", "B", "B+"]);
assert.deepEqual(candidate([0.0, 0.7]),["E", "D-"]);
}
test(); |
humaneval-HumanEval_33_sort_third.json-L14 | js | //This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// >>> sort_third([1, 2, 3])
// [1, 2, 3]
// >>> sort_third([5, 6, 3, 4, 8, 9, 2])
// [2, 6, 3, 4, 8, 9, 5]
function sort_third(l){
let x=[];
let y=[];
let k=0;
for(let i=0;i<l.length;i++){
if(i%3==0){ | k=k+1;
}
else{
x[i]=l[i];
}
}
y.sort();
k=0;
for(let i=0;i<l.length;i++){
if(i%3==0){
x[i]=y[k];
k=k+1;
}
}
return x;
} | y[k]=l[i]; | const assert = require('node:assert');
function test() {
let candidate = sort_third;
assert.deepEqual(candidate([5, 6, 3, 4, 8, 9, 2]),[2, 6, 3, 4, 8, 9, 5]);
assert.deepEqual(candidate([5, 8, 3, 4, 6, 9, 2]),[2, 8, 3, 4, 6, 9, 5]);
assert.deepEqual(candidate([5, 6, 9, 4, 8, 3, 2]),[2, 6, 9, 4, 8, 3, 5]);
assert.deepEqual(candidate([5, 6, 3, 4, 8, 9, 2, 1]),[2, 6, 3, 4, 8, 9, 5, 1]);
}
test(); |
humaneval-HumanEval_137_compare_one.json-L48 | 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: | 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
elif a < float(b_tmp):
return b
else:
return None
elif isinstance(a, str) and isinstance(b, float):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b | return None | def check(candidate):
assert candidate(1, 2) == 2
assert candidate(1, 2.5) == 2.5
assert candidate(2, 3) == 3
assert candidate(5, 6) == 6
assert candidate(1, '2,3') == '2,3'
assert candidate('5,1', '6') == '6'
assert candidate('1', '2') == '2'
assert candidate('1', 1) == None
def test_check():
check(compare_one)
test_check()
|
humaneval-HumanEval_117_select_words.json-L24 | js | //Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array 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.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// >>> select_words("Mary had a little lamb", 4)
// ["little"]
// >>> select_words("Mary had a little lamb", 3)
// ["Mary", "lamb"]
// >>> select_words("simple white space", 2)
// []
// >>> select_words("Hello world", 4)
// ["world"]
// >>> select_words("Uncle sam", 3)
// ["Uncle"]
function select_words(s, n){
let words = s.split(' ').filter(e => e != '');
let selected = words.filter(e => e.match(/[bcdfghjklmnpqrstvwxyz]/gi) != null);
if(n > 0){
return selected.filter(e => e.match(/[bcdfghjklmnpqrstvwxyz]/gi).length == n);
}else{
return []; | }
| } | const assert = require('node:assert');
function test() {
let candidate = select_words;
assert.deepEqual(candidate("Mary had a little lamb", 4),["little"]);
assert.deepEqual(candidate("Mary had a little lamb", 3),["Mary", "lamb"]);
assert.deepEqual(candidate("simple white space", 2),[]);
assert.deepEqual(candidate("Hello world", 4),["world"]);
assert.deepEqual(candidate("Uncle sam", 3),["Uncle"]);
assert.deepEqual(candidate("", 4),[]);
assert.deepEqual(candidate("a b c d e f", 1),["b", "c", "d", "f"]);
}
test(); |
humaneval-HumanEval_113_odd_count.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 an array array list of strings, where each string consists of only digits, return an array array list.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// >>> oddCount((new ArrayList<String>(Arrays.asList((String)"1234567"))))
// (new ArrayList<String>(Arrays.asList((String)"the number of odd elements 4n the str4ng 4 of the 4nput.")))
// >>> oddCount((new ArrayList<String>(Arrays.asList((String)"3", (String)"11111111"))))
// (new ArrayList<String>(Arrays.asList((String)"the number of odd elements 1n the str1ng 1 of the 1nput.", (String)"the number of odd elements 8n the str8ng 8 of the 8nput.")))
public static ArrayList<String> oddCount(ArrayList<String> lst) {
ArrayList<String> res = new ArrayList<String>();
for (int i = 0; i < lst.size(); i++) {
int count = 0;
for (int j = 0; j < lst.get(i).length(); j++) {
if (Integer.parseInt(lst.get(i).substring(j, j + 1)) % 2 == 1) { | }
}
res.add("the number of odd elements " + count + "n the str" + count + "ng " + count + " of the " + count + "nput.");
}
return res;
}
} | count++; | }
public static void main(String[] args) {
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"1234567")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 4n the str4ng 4 of the 4nput.")))));
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"3", (String)"11111111")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 1n the str1ng 1 of the 1nput.", (String)"the number of odd elements 8n the str8ng 8 of the 8nput.")))));
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"271", (String)"137", (String)"314")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 2n the str2ng 2 of the 2nput.", (String)"the number of odd elements 3n the str3ng 3 of the 3nput.", (String)"the number of odd elements 2n the str2ng 2 of the 2nput.")))));
}
}
|
humaneval-HumanEval_111_histogram.json-L30 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a string representing a space separated lowercase letters, return a hash map
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// >>> histogram(("a b c"))
// (new HashMap<String,Long>(Map.of("a", 1l, "b", 1l, "c", 1l)))
// >>> histogram(("a b b a"))
// (new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))
// >>> histogram(("a b c a b"))
// (new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))
// >>> histogram(("b b b b a"))
// (new HashMap<String,Long>(Map.of("b", 4l)))
// >>> histogram((""))
// (new HashMap<String,Long>())
public static HashMap<String,Long> histogram(String test) {
HashMap<String,Long> s = new HashMap<String,Long>();
if (test.length() > 0) {
HashMap<String,Long> hm = new HashMap<String,Long>();
String[] ss = test.split(" ");
for (String sss : ss) {
if (hm.containsKey(sss)) { | } else {
hm.put(sss, 1l);
}
}
long max = 0;
for (String key : hm.keySet()) {
if (hm.get(key) > max) {
max = hm.get(key);
}
}
for (String key : hm.keySet()) {
if (hm.get(key) == max) {
s.put(key, hm.get(key));
}
}
}
return s;
}
} | hm.put(sss, hm.get(sss) + 1); | }
public static void main(String[] args) {
assert(histogram(("a b b a")).equals((new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))));
assert(histogram(("a b c a b")).equals((new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))));
assert(histogram(("a b c d g")).equals((new HashMap<String,Long>(Map.of("a", 1l, "b", 1l, "c", 1l, "d", 1l, "g", 1l)))));
assert(histogram(("r t g")).equals((new HashMap<String,Long>(Map.of("r", 1l, "t", 1l, "g", 1l)))));
assert(histogram(("b b b b a")).equals((new HashMap<String,Long>(Map.of("b", 4l)))));
assert(histogram(("r t g")).equals((new HashMap<String,Long>(Map.of("r", 1l, "t", 1l, "g", 1l)))));
assert(histogram(("")).equals((new HashMap<String,Long>())));
assert(histogram(("a")).equals((new HashMap<String,Long>(Map.of("a", 1l)))));
}
}
|
humaneval-HumanEval_134_check_if_last_char_is_a_letter.json-L20 | py | def check_if_last_char_is_a_letter(txt: str) -> bool:
"""
Create a function that returns True if the last character
of a given string is an alphabetical character and is not
a part of a word, and False otherwise.
Note: "word" is a group of characters separated by space.
Examples:
>>> check_if_last_char_is_a_letter('apple pie')
False
>>> check_if_last_char_is_a_letter('apple pi e')
True
>>> check_if_last_char_is_a_letter('apple pi e ')
False
>>> check_if_last_char_is_a_letter('')
False
"""
if len(txt) == 0:
return False | return True
else:
return False
| elif txt[-1].isalpha() and (len(txt) == 1 or not txt[-2].isalpha()): | def check(candidate):
assert candidate('apple') == False
assert candidate('apple pi e') == True
assert candidate('eeeee') == False
assert candidate('A') == True
assert candidate('Pumpkin pie ') == False
assert candidate('Pumpkin pie 1') == False
assert candidate('') == False
assert candidate('eeeee e ') == False
assert candidate('apple pie') == False
assert candidate('apple pi e ') == False
def test_check():
check(check_if_last_char_is_a_letter)
test_check()
|
humaneval-HumanEval_153_Strongest_Extension.json-L28 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You 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_109_move_one_ball.json-L27 | js | //We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift 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 array 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.
function move_one_ball(arr){
var diff_count = 0;
var i = 0;
var temp = 0;
for(var i = 0; i < arr.length - 1; i++){ | diff_count += 1;
}
}
if(diff_count > 1){
return false;
}
else{
return true;
}
} | if(arr[i] > arr[i + 1]){ | const assert = require('node:assert');
function test() {
let candidate = move_one_ball;
assert.deepEqual(candidate([3, 4, 5, 1, 2]),true);
assert.deepEqual(candidate([3, 5, 10, 1, 2]),true);
assert.deepEqual(candidate([4, 3, 1, 2]),false);
assert.deepEqual(candidate([3, 5, 4, 1, 2]),false);
assert.deepEqual(candidate([]),true);
}
test(); |
humaneval-HumanEval_147_get_max_triples.json-L22 | js | //You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// >>> get_max_triples(5)
// 1
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
function get_max_triples(n){
let result = 0;
let arr = [];
for(let i = 1; i<=n; i++){
arr.push(i*i-i+1);
}
for(let i = 0; i<arr.length; i++){
for(let j = i+1; j<arr.length; j++){
for(let k = j+1; k<arr.length; k++){
if((arr[i]+arr[j]+arr[k])%3 === 0){
result++; | }
}
}
return result;
}
| } | const assert = require('node:assert');
function test() {
let candidate = get_max_triples;
assert.deepEqual(candidate(5),1);
assert.deepEqual(candidate(6),4);
assert.deepEqual(candidate(10),36);
assert.deepEqual(candidate(100),53361);
}
test(); |
humaneval-HumanEval_54_same_chars.json-L17 | py | def same_chars(s0: str, s1: str) -> bool:
"""
Check if two words have the same characters.
>>> same_chars('eabcdzzzz', 'dddzzzzzzzddeddabc')
True
>>> same_chars('abcd', 'dddddddabc')
True
>>> same_chars('dddddddabc', 'abcd')
True
>>> same_chars('eabcd', 'dddddddabc')
False
>>> same_chars('abcd', 'dddddddabce')
False
>>> same_chars('eabcdzzzz', 'dddzzzzzzzddddabc')
False
"""
| return set(s0) == set(s1) | def check(candidate):
assert candidate('eabcdzzzz', 'dddzzzzzzzddeddabc') == True
assert candidate('abcd', 'dddddddabc') == True
assert candidate('dddddddabc', 'abcd') == True
assert candidate('eabcd', 'dddddddabc') == False
assert candidate('abcd', 'dddddddabcf') == False
assert candidate('eabcdzzzz', 'dddzzzzzzzddddabc') == False
assert candidate('aabb', 'aaccc') == False
def test_check():
check(same_chars)
test_check()
|
|
humaneval-HumanEval_24_largest_divisor.json-L11 | js | //For a given number n, find the largest number that divides n evenly, smaller than n
// >>> largest_divisor(15)
// 5
function largest_divisor(n){
let ld = 0;
for(i=1; i<n; i++){
if(n%i===0){
if(i>ld){
ld = i;
} | }
return ld;
} | } | const assert = require('node:assert');
function test() {
let candidate = largest_divisor;
assert.deepEqual(candidate(3),1);
assert.deepEqual(candidate(7),1);
assert.deepEqual(candidate(10),5);
assert.deepEqual(candidate(100),50);
assert.deepEqual(candidate(49),7);
}
test(); |
humaneval-HumanEval_29_filter_by_prefix.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 {
// Filter an input array list of strings only for ones that start with a given prefix.
// >>> filterByPrefix((new ArrayList<String>(Arrays.asList())), ("a"))
// (new ArrayList<String>(Arrays.asList()))
// >>> filterByPrefix((new ArrayList<String>(Arrays.asList((String)"abc", (String)"bcd", (String)"cde", (String)"array"))), ("a"))
// (new ArrayList<String>(Arrays.asList((String)"abc", (String)"array")))
public static ArrayList<String> filterByPrefix(ArrayList<String> strings, String prefix) {
return (ArrayList<String>)strings.stream().filter(s -> s.startsWith(prefix)).collect(Collectors.toList());
} | } | }
public static void main(String[] args) {
assert(filterByPrefix((new ArrayList<String>(Arrays.asList())), ("john")).equals((new ArrayList<String>(Arrays.asList()))));
assert(filterByPrefix((new ArrayList<String>(Arrays.asList((String)"xxx", (String)"asd", (String)"xxy", (String)"john doe", (String)"xxxAAA", (String)"xxx"))), ("xxx")).equals((new ArrayList<String>(Arrays.asList((String)"xxx", (String)"xxxAAA", (String)"xxx")))));
}
}
|
|
humaneval-HumanEval_144_simplify.json-L18 | py | def simplify(x: str, n: str) -> bool:
"""Your task is to implement a function that will simplify the expression
x * n. The function returns True if x * n evaluates to a whole number and False
otherwise. Both x and n, are string representation of a fraction, and have the following format,
<numerator>/<denominator> where both numerator and denominator are positive whole numbers.
You can assume that x, and n are valid fractions, and do not have zero as denominator.
>>> simplify('1/5', '5/1')
True
>>> simplify('1/6', '2/1')
False
>>> simplify('7/10', '10/2')
False
"""
x_num, x_denom = [int(i) for i in x.split('/')]
n_num, n_denom = [int(i) for i in n.split('/')] | return (x_num * n_num) % (x_denom * n_denom) == 0 | def check(candidate):
assert candidate('1/5', '5/1') == True
assert candidate('1/6', '2/1') == False
assert candidate('5/1', '3/1') == True
assert candidate('7/10', '10/2') == False
assert candidate('2/10', '50/10') == True
assert candidate('7/2', '4/2') == True
assert candidate('11/6', '6/1') == True
assert candidate('2/3', '5/2') == False
assert candidate('5/2', '3/5') == False
assert candidate('2/4', '8/4') == True
assert candidate('2/4', '4/2') == True
assert candidate('1/5', '5/1') == True
assert candidate('1/5', '1/5') == False
def test_check():
check(simplify)
test_check()
|
|
humaneval-HumanEval_95_check_dict_case.json-L20 | js | //Given an object, return true if all keys are strings in lower
// case or all keys are strings in upper case, else return false.
// The function should return false is the given object is empty.
// Examples:
// >>> check_dict_case({"a": "apple", "b": "banana"})
// true
// >>> check_dict_case({"a": "apple", "A": "banana", "B": "banana"})
// false
// >>> check_dict_case({"a": "apple", 8: "banana", "a": "apple"})
// false
// >>> check_dict_case({"Name": "John", "Age": "36", "City": "Houston"})
// false
// >>> check_dict_case({"STATE": "NC", "ZIP": "12345"})
// true
function check_dict_case(dict){
if (Object.keys(dict).length == 0){
return false;
}
var case_type = -1; | if (typeof key == "string"){
if (case_type == -1){
if (key == key.toUpperCase()){
case_type = 1;
}
else if (key == key.toLowerCase()){
case_type = 0;
}
else{
return false;
}
}
else if (case_type == 1){
if (key != key.toUpperCase()){
return false;
}
}
else if (case_type == 0){
if (key != key.toLowerCase()){
return false;
}
}
}
else{
return false;
}
}
return true;
} | for (let key in dict){ | const assert = require('node:assert');
function test() {
let candidate = check_dict_case;
assert.deepEqual(candidate({"p": "pineapple", "b": "banana"}),true);
assert.deepEqual(candidate({"p": "pineapple", "A": "banana", "B": "banana"}),false);
assert.deepEqual(candidate({"p": "pineapple", "5": "banana", "a": "apple"}),false);
assert.deepEqual(candidate({"Name": "John", "Age": "36", "City": "Houston"}),false);
assert.deepEqual(candidate({"STATE": "NC", "ZIP": "12345"}),true);
assert.deepEqual(candidate({"fruit": "Orange", "taste": "Sweet"}),true);
assert.deepEqual(candidate({}),false);
}
test(); |
humaneval-HumanEval_45_triangle_area.json-L6 | js | //Given length of a side and high return area for a triangle.
// >>> triangle_area(5, 3)
// 7.5
function triangle_area(a, h){
return a*h/2; | }; | const assert = require('node:assert');
function test() {
let candidate = triangle_area;
assert.deepEqual(candidate(5, 3),7.5);
assert.deepEqual(candidate(2, 2),2.0);
assert.deepEqual(candidate(10, 8),40.0);
}
test(); |
|
humaneval-HumanEval_114_minSubArraySum.json-L20 | js | //Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// >>> minSubArraySum([2, 3, 4, 1, 2, 4])
// 1
// >>> minSubArraySum([-1, -2, -3])
// -6
function minSubArraySum(nums){
let sum = 0;
let minSum = nums[0];
for(let i = 0; i < nums.length; i++){
sum += nums[i];
if(sum < minSum){
minSum = sum;
}
if(sum > 0){
sum = 0;
}
} | }
| return minSum; | const assert = require('node:assert');
function test() {
let candidate = minSubArraySum;
assert.deepEqual(candidate([2, 3, 4, 1, 2, 4]),1);
assert.deepEqual(candidate([-1, -2, -3]),-6);
assert.deepEqual(candidate([-1, -2, -3, 2, -10]),-14);
assert.deepEqual(candidate([-9999999999999999]),-9999999999999999);
assert.deepEqual(candidate([0, 10, 20, 1000000]),0);
assert.deepEqual(candidate([-1, -2, -3, 10, -5]),-6);
assert.deepEqual(candidate([100, -1, -2, -3, 10, -5]),-6);
assert.deepEqual(candidate([10, 11, 13, 8, 3, 4]),3);
assert.deepEqual(candidate([100, -33, 32, -1, 0, -2]),-33);
assert.deepEqual(candidate([-10]),-10);
assert.deepEqual(candidate([7]),7);
assert.deepEqual(candidate([1, -1]),-1);
}
test(); |
humaneval-HumanEval_27_flip_case.json-L8 | js | //For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// >>> flip_case("Hello")
// "hELLO"
function flip_case(string){
var result = "";
for(var i = 0; i < string.length; i++){
if(string[i] == string[i].toUpperCase()){ | }else{
result += string[i].toUpperCase();
}
}
return result;
}
| result += string[i].toLowerCase(); | const assert = require('node:assert');
function test() {
let candidate = flip_case;
assert.deepEqual(candidate(""),"");
assert.deepEqual(candidate("Hello!"),"hELLO!");
assert.deepEqual(candidate("These violent delights have violent ends"),"tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS");
}
test(); |
humaneval-HumanEval_89_encrypt.json-L26 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// >>> encrypt(("hi"))
// ("lm")
// >>> encrypt(("asdfghjkl"))
// ("ewhjklnop")
// >>> encrypt(("gf"))
// ("kj")
// >>> encrypt(("et"))
// ("ix")
public static String encrypt(String s) {
StringBuffer b = new StringBuffer();
for (char c : s.toCharArray()) {
b.append((char)((c+4) > 'z' ? (((c+4)%'z')+'a'-1) : c+4)); | return b.toString();
}
} | } | }
public static void main(String[] args) {
assert(encrypt(("hi")).equals(("lm")));
assert(encrypt(("asdfghjkl")).equals(("ewhjklnop")));
assert(encrypt(("gf")).equals(("kj")));
assert(encrypt(("et")).equals(("ix")));
assert(encrypt(("faewfawefaewg")).equals(("jeiajeaijeiak")));
assert(encrypt(("hellomyfriend")).equals(("lippsqcjvmirh")));
assert(encrypt(("dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh")).equals(("hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl")));
assert(encrypt(("a")).equals(("e")));
}
}
|
humaneval-HumanEval_33_sort_third.json-L25 | js | //This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// >>> sort_third([1, 2, 3])
// [1, 2, 3]
// >>> sort_third([5, 6, 3, 4, 8, 9, 2])
// [2, 6, 3, 4, 8, 9, 5]
function sort_third(l){
let x=[];
let y=[];
let k=0;
for(let i=0;i<l.length;i++){
if(i%3==0){
y[k]=l[i];
k=k+1;
}
else{
x[i]=l[i];
}
}
y.sort();
k=0;
for(let i=0;i<l.length;i++){
if(i%3==0){ | k=k+1;
}
}
return x;
} | x[i]=y[k]; | const assert = require('node:assert');
function test() {
let candidate = sort_third;
assert.deepEqual(candidate([5, 6, 3, 4, 8, 9, 2]),[2, 6, 3, 4, 8, 9, 5]);
assert.deepEqual(candidate([5, 8, 3, 4, 6, 9, 2]),[2, 8, 3, 4, 6, 9, 5]);
assert.deepEqual(candidate([5, 6, 9, 4, 8, 3, 2]),[2, 6, 9, 4, 8, 3, 5]);
assert.deepEqual(candidate([5, 6, 3, 4, 8, 9, 2, 1]),[2, 6, 3, 4, 8, 9, 5, 1]);
}
test(); |
humaneval-HumanEval_124_valid_date.json-L35 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You 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
// >>> validDate(("03-11-2000"))
// (true)
// >>> validDate(("15-01-2012"))
// (false)
// >>> validDate(("04-0-2040"))
// (false)
// >>> validDate(("06-04-2020"))
// (true)
// >>> validDate(("06/04/2020"))
// (false)
public static boolean validDate(String date) {
boolean valid_date = false;
if (date.equals("")) return valid_date;
String[] parts = date.split("-");
if (parts.length != 3) return valid_date;
try {
int month = Integer.parseInt(parts[0]);
int day = Integer.parseInt(parts[1]);
int year = Integer.parseInt(parts[2]); | if (month == 2) {
if (day < 1 || day > 29) return valid_date;
} else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
if (day < 1 || day > 31) return valid_date;
} else {
if (day < 1 || day > 30) return valid_date;
}
valid_date = true;
} catch (Exception e) {
valid_date = false;
}
return valid_date;
}
} | if (month < 1 || month > 12) return valid_date; | }
public static void main(String[] args) {
assert(validDate(("03-11-2000")) == (true));
assert(validDate(("15-01-2012")) == (false));
assert(validDate(("04-0-2040")) == (false));
assert(validDate(("06-04-2020")) == (true));
assert(validDate(("01-01-2007")) == (true));
assert(validDate(("03-32-2011")) == (false));
assert(validDate(("")) == (false));
assert(validDate(("04-31-3000")) == (false));
assert(validDate(("06-06-2005")) == (true));
assert(validDate(("21-31-2000")) == (false));
assert(validDate(("04-12-2003")) == (true));
assert(validDate(("04122003")) == (false));
assert(validDate(("20030412")) == (false));
assert(validDate(("2003-04")) == (false));
assert(validDate(("2003-04-12")) == (false));
assert(validDate(("04-2003")) == (false));
}
}
|
humaneval-HumanEval_31_is_prime.json-L31 | js | //Return true if a given number is prime, and false otherwise.
// >>> is_prime(6)
// false
// >>> is_prime(101)
// true
// >>> is_prime(11)
// true
// >>> is_prime(13441)
// true
// >>> is_prime(61)
// true
// >>> is_prime(4)
// false
// >>> is_prime(1)
// false
function is_prime(n){
if (n==1) {
return false;
}
if (n==2) {
return true;
}
if (n%2==0) {
return false;
}
var limit = Math.sqrt(n);
for (var i = 3; i <= limit; i += 2) { | return false;
}
}
return true;
}
| if (n%i==0) { | const assert = require('node:assert');
function test() {
let candidate = is_prime;
assert.deepEqual(candidate(6),false);
assert.deepEqual(candidate(101),true);
assert.deepEqual(candidate(11),true);
assert.deepEqual(candidate(13441),true);
assert.deepEqual(candidate(61),true);
assert.deepEqual(candidate(4),false);
assert.deepEqual(candidate(1),false);
assert.deepEqual(candidate(5),true);
assert.deepEqual(candidate(11),true);
assert.deepEqual(candidate(17),true);
assert.deepEqual(candidate(85),false);
assert.deepEqual(candidate(77),false);
assert.deepEqual(candidate(255379),false);
}
test(); |
humaneval-HumanEval_124_valid_date.json-L25 | 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){ | }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;
}
| 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_111_histogram.json-L24 | py | from typing import Dict
def histogram(test: str) -> Dict[str, int]:
"""Given a string representing a space separated lowercase letters, return a dictionary
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('')
{ }
"""
letters = {}
most_count = 0
result = {} | letters[letter] = letters.get(letter, 0) + 1
if letters[letter] >= most_count:
most_count = letters[letter]
for letter in letters:
if letters[letter] == most_count:
result[letter] = most_count
return result
| for letter in test.split(): | def check(candidate):
assert candidate('a b b a') == { 'a': 2, 'b': 2 }
assert candidate('a b c a b') == { 'a': 2, 'b': 2 }
assert candidate('a b c d g') == { 'a': 1, 'b': 1, 'c': 1, 'd': 1, 'g': 1 }
assert candidate('r t g') == { 'r': 1, 't': 1, 'g': 1 }
assert candidate('b b b b a') == { 'b': 4 }
assert candidate('r t g') == { 'r': 1, 't': 1, 'g': 1 }
assert candidate('') == { }
assert candidate('a') == { 'a': 1 }
def test_check():
check(histogram)
test_check()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.