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_1_separate_paren_groups.json-L8 | js | //Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// >>> separate_paren_groups("( ) (( )) (( )( ))")
// ["()", "(())", "(()())"]
function separate_paren_groups(paren_string){
| var group = '';
var groups = [];
for (var i = 0; i < paren_string.length; i++){
if (paren_string[i] === '('){
count++;
group += paren_string[i];
} else if (paren_string[i] === ')'){
count--;
group += paren_string[i];
}
if (count === 0 && group){
groups.push(group);
group = '';
}
}
return groups;
}
| var count = 0; | const assert = require('node:assert');
function test() {
let candidate = separate_paren_groups;
assert.deepEqual(candidate("(()()) ((())) () ((())()())"),["(()())", "((()))", "()", "((())()())"]);
assert.deepEqual(candidate("() (()) ((())) (((())))"),["()", "(())", "((()))", "(((())))"]);
assert.deepEqual(candidate("(()(())((())))"),["(()(())((())))"]);
assert.deepEqual(candidate("( ) (( )) (( )( ))"),["()", "(())", "(()())"]);
}
test(); |
humaneval-HumanEval_21_rescale_to_unit.json-L16 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given array list of numbers (of at least two elements), apply a linear transform to that array list,
// such that the smallest number will become 0 and the largest will become 1
// >>> rescaleToUnit((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f, (float)4.0f, (float)5.0f))))
// (new ArrayList<Float>(Arrays.asList((float)0.0f, (float)0.25f, (float)0.5f, (float)0.75f, (float)1.0f)))
public static ArrayList<Float> rescaleToUnit(ArrayList<Float> numbers) {
float min = numbers.stream().min(Float::compare).get();
float max = numbers.stream().max(Float::compare).get(); | }
} | return numbers.stream().map(e -> (e - min) / (max - min)).collect(Collectors.toCollection(ArrayList::new)); | }
public static void main(String[] args) {
assert(rescaleToUnit((new ArrayList<Float>(Arrays.asList((float)2.0f, (float)49.9f)))).equals((new ArrayList<Float>(Arrays.asList((float)0.0f, (float)1.0f)))));
assert(rescaleToUnit((new ArrayList<Float>(Arrays.asList((float)100.0f, (float)49.9f)))).equals((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)0.0f)))));
assert(rescaleToUnit((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f, (float)4.0f, (float)5.0f)))).equals((new ArrayList<Float>(Arrays.asList((float)0.0f, (float)0.25f, (float)0.5f, (float)0.75f, (float)1.0f)))));
assert(rescaleToUnit((new ArrayList<Float>(Arrays.asList((float)2.0f, (float)1.0f, (float)5.0f, (float)3.0f, (float)4.0f)))).equals((new ArrayList<Float>(Arrays.asList((float)0.25f, (float)0.0f, (float)1.0f, (float)0.5f, (float)0.75f)))));
assert(rescaleToUnit((new ArrayList<Float>(Arrays.asList((float)12.0f, (float)11.0f, (float)15.0f, (float)13.0f, (float)14.0f)))).equals((new ArrayList<Float>(Arrays.asList((float)0.25f, (float)0.0f, (float)1.0f, (float)0.5f, (float)0.75f)))));
}
}
|
humaneval-HumanEval_116_sort_array.json-L29 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// In this Kata, you have to sort an array array list of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)2l, (long)3l, (long)4l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)-2l, (long)-3l, (long)-4l, (long)-5l, (long)-6l))))
// (new ArrayList<Long>(Arrays.asList((long)-6l, (long)-5l, (long)-4l, (long)-3l, (long)-2l)))
// >>> sortArray((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)2l, (long)3l, (long)4l))))
// (new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)2l, (long)3l, (long)4l)))
public static ArrayList<Long> sortArray(ArrayList<Long> arr) {
Collections.sort(arr, (a, b) -> {
long a1 = a, b1 = b;
if (a1 < 0) {
a1 = -a1;
}
if (b1 < 0) {
b1 = -b1;
}
return Long.bitCount(a1) == Long.bitCount(b1) ? Long.compare(a, b) : Integer.compare(Long.bitCount(a1), Long.bitCount(b1)); | return arr;
}
} | }); | }
public static void main(String[] args) {
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)3l, (long)5l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)-2l, (long)-3l, (long)-4l, (long)-5l, (long)-6l)))).equals((new ArrayList<Long>(Arrays.asList((long)-4l, (long)-2l, (long)-6l, (long)-5l, (long)-3l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)2l, (long)4l, (long)3l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)5l, (long)77l, (long)4l, (long)5l, (long)3l, (long)5l, (long)7l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)2l, (long)4l, (long)4l, (long)3l, (long)3l, (long)5l, (long)5l, (long)5l, (long)7l, (long)77l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)3l, (long)6l, (long)44l, (long)12l, (long)32l, (long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)32l, (long)3l, (long)5l, (long)6l, (long)12l, (long)44l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)8l, (long)16l, (long)32l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)8l, (long)16l, (long)32l)))));
assert(sortArray((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)8l, (long)16l, (long)32l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)4l, (long)8l, (long)16l, (long)32l)))));
}
}
|
humaneval-HumanEval_41_car_race_collision.json-L13 | js | //Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
function car_race_collision(n){
let num_collisions = 0;
let left_to_right = Array(n).fill(1);
let right_to_left = Array(n).fill(1); | for (let j = 0; j < right_to_left.length; j++) {
if (left_to_right[i] == right_to_left[j]) {
num_collisions++;
}
}
}
return num_collisions;
}
| for (let i = 0; i < left_to_right.length; i++) { | const assert = require('node:assert');
function test() {
let candidate = car_race_collision;
assert.deepEqual(candidate(2),4);
assert.deepEqual(candidate(3),9);
assert.deepEqual(candidate(4),16);
assert.deepEqual(candidate(8),64);
assert.deepEqual(candidate(10),100);
}
test(); |
humaneval-HumanEval_106_f.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 {
// Implement the function f that takes n as a parameter,
// and returns an array array list of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// >>> f((5l))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l)))
public static ArrayList<Long> f(long n) {
ArrayList<Long> ret = new ArrayList<Long>();
for (long i = 1l; i <= n; i++) { | if (i % 2 == 0) {
v = 1l;
for (long j = 2l; j <= i; j++) {
v *= j;
}
} else {
v = (i * (i + 1l)) / 2l;
}
ret.add(v);
}
return ret;
}
} | long v = 0l; | }
public static void main(String[] args) {
assert(f((5l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l)))));
assert(f((7l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l, (long)720l, (long)28l)))));
assert(f((1l)).equals((new ArrayList<Long>(Arrays.asList((long)1l)))));
assert(f((3l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l)))));
}
}
|
humaneval-HumanEval_111_histogram.json-L38 | js | //Given a string representing a space separated lowercase letters, return an object
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// >>> histogram("a b c")
// {"a": 1, "b": 1, "c": 1}
// >>> histogram("a b b a")
// {"a": 2, "b": 2}
// >>> histogram("a b c a b")
// {"a": 2, "b": 2}
// >>> histogram("b b b b a")
// {"b": 4}
// >>> histogram("")
// {}
function histogram(test){
if (test.length === 0){
return {};
}
var lst = test.split(" ");
var count = {};
for (var i = 0; i < lst.length; i++){
if (count[lst[i]]){
count[lst[i]] += 1;
}
else{
count[lst[i]] = 1;
}
}
console.log(count);
var max = 0;
var result = {};
for (var key in count){
if (count[key] > max){
max = count[key];
result = {};
result[key] = max;
} | result[key] = max;
}
}
return result;
}
| else 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_90_next_smallest.json-L20 | js | //You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return undefined if there is no such element.
// >>> next_smallest([1, 2, 3, 4, 5])
// 2
// >>> next_smallest([5, 1, 4, 3, 2])
// 2
// >>> next_smallest([])
// undefined
// >>> next_smallest([1, 1])
// undefined
function next_smallest(lst){
if(lst.length<=1){
return undefined;
}
var smallest=Math.min(...lst);
var second_smallest=Number.MAX_VALUE;
for(var i in lst){
if(lst[i]>smallest&&lst[i]<second_smallest){ | }
}
if(second_smallest==Number.MAX_VALUE){
return undefined;
}
return second_smallest;
} | second_smallest=lst[i]; | const assert = require('node:assert');
function test() {
let candidate = next_smallest;
assert.deepEqual(candidate([1, 2, 3, 4, 5]),2);
assert.deepEqual(candidate([5, 1, 4, 3, 2]),2);
assert.deepEqual(candidate([]),undefined);
assert.deepEqual(candidate([1, 1]),undefined);
assert.deepEqual(candidate([1, 1, 1, 1, 0]),1);
assert.deepEqual(candidate([1, 1]),undefined);
assert.deepEqual(candidate([-35, 34, 12, -45]),-35);
}
test(); |
humaneval-HumanEval_105_by_length.json-L20 | 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_13_greatest_common_divisor.json-L21 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return a greatest common divisor of two integers a and b
// >>> greatestCommonDivisor((3l), (5l))
// (1l)
// >>> greatestCommonDivisor((25l), (15l))
// (5l)
public static long greatestCommonDivisor(long a, long b) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
} | }
} | return greatestCommonDivisor(b, a % b); | }
public static void main(String[] args) {
assert(greatestCommonDivisor((3l), (7l)) == (1l));
assert(greatestCommonDivisor((10l), (15l)) == (5l));
assert(greatestCommonDivisor((49l), (14l)) == (7l));
assert(greatestCommonDivisor((144l), (60l)) == (12l));
}
}
|
humaneval-HumanEval_95_check_dict_case.json-L22 | 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;
for (let key in dict){
if (typeof key == "string"){ | 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;
} | if (case_type == -1){ | 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_117_select_words.json-L21 | 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){ | }else{
return [];
}
}
| return selected.filter(e => e.match(/[bcdfghjklmnpqrstvwxyz]/gi).length == n); | 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_40_triples_sum_to_zero.json-L19 | 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) { | return true;
}
}
}
}
}
return false;
}
| if (l[i] + l[j] + l[k] === 0) { | 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_31_is_prime.json-L23 | py | def is_prime(n: int) -> bool:
"""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
"""
if n <= 1:
return False
for i in range(2, n//2 + 1):
if n % i == 0:
return False | return True | def check(candidate):
assert candidate(6) == False
assert candidate(101) == True
assert candidate(11) == True
assert candidate(13441) == True
assert candidate(61) == True
assert candidate(4) == False
assert candidate(1) == False
assert candidate(5) == True
assert candidate(11) == True
assert candidate(17) == True
assert candidate(85) == False
assert candidate(77) == False
assert candidate(255379) == False
def test_check():
check(is_prime)
test_check()
|
|
humaneval-HumanEval_142_sum_squares.json-L22 | 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_11_string_xor.json-L19 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// >>> stringXor(("010"), ("110"))
// ("100")
public static String stringXor(String a, String b) {
StringBuilder c = new StringBuilder();
for (int i = 0; i < a.length(); i++) {
c.append(a.charAt(i) ^ b.charAt(i));
}
return c.toString(); | } | } | }
public static void main(String[] args) {
assert(stringXor(("111000"), ("101010")).equals(("010010")));
assert(stringXor(("1"), ("1")).equals(("0")));
assert(stringXor(("0101"), ("0000")).equals(("0101")));
}
}
|
humaneval-HumanEval_70_strange_sort_list.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 array list of integers, return array list in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// >>> strangeSortList((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)2l, (long)3l)))
// >>> strangeSortList((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)5l, (long)5l))))
// (new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)5l, (long)5l)))
// >>> strangeSortList((new ArrayList<Long>(Arrays.asList())))
// (new ArrayList<Long>(Arrays.asList()))
public static ArrayList<Long> strangeSortList(ArrayList<Long> lst) {
if (lst.size() <= 1) { | }
ArrayList<Long> result = new ArrayList<Long>();
ArrayList<Long> sorted = new ArrayList<Long>(lst);
Collections.sort(sorted);
int min = 0;
int max = sorted.size() - 1;
while (min <= max) {
result.add(sorted.get(min));
min++;
if (min <= max) {
result.add(sorted.get(max));
max--;
}
}
return result;
}
} | return lst; | }
public static void main(String[] args) {
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)2l, (long)3l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)7l, (long)8l, (long)9l)))).equals((new ArrayList<Long>(Arrays.asList((long)5l, (long)9l, (long)6l, (long)8l, (long)7l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)2l, (long)4l, (long)3l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)7l, (long)8l, (long)9l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)9l, (long)5l, (long)8l, (long)6l, (long)7l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)5l, (long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)5l, (long)5l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l, (long)8l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)8l, (long)2l, (long)7l, (long)3l, (long)6l, (long)4l, (long)5l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)0l, (long)2l, (long)2l, (long)2l, (long)5l, (long)5l, (long)-5l, (long)-5l)))).equals((new ArrayList<Long>(Arrays.asList((long)-5l, (long)5l, (long)-5l, (long)5l, (long)0l, (long)2l, (long)2l, (long)2l)))));
assert(strangeSortList((new ArrayList<Long>(Arrays.asList((long)111111l)))).equals((new ArrayList<Long>(Arrays.asList((long)111111l)))));
}
}
|
humaneval-HumanEval_147_get_max_triples.json-L16 | py | def get_max_triples(n: int) -> int:
"""
You are given a positive integer n. You have to create an integer array a of length n.
For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
and a[i] + a[j] + a[k] is a multiple of 3.
Example :
>>> get_max_triples(5)
1
Explanation:
a = [1, 3, 7, 13, 21]
The only valid triple is (1, 7, 13).
"""
a = [i * i - i + 1 for i in range(1, n + 1)] | j = 1
k = 2
count = 0
while (i < n - 2):
while (j < n - 1):
while (k < n):
if (a[i] + a[j] + a[k]) % 3 == 0:
count += 1
k += 1
j += 1
k = j + 1
i += 1
j = i + 1
k = j + 1
return count
| i = 0 | def check(candidate):
assert candidate(5) == 1
assert candidate(6) == 4
assert candidate(10) == 36
assert candidate(100) == 53361
def test_check():
check(get_max_triples)
test_check()
|
humaneval-HumanEval_81_numerical_letter_grade.json-L35 | 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-");
} | 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;
} | else if (grades[i] > 3.0){ | const assert = require('node:assert');
function test() {
let candidate = numerical_letter_grade;
assert.deepEqual(candidate([4.0, 3, 1.7, 2, 3.5]),["A+", "B", "C-", "C", "A-"]);
assert.deepEqual(candidate([1.2]),["D+"]);
assert.deepEqual(candidate([0.5]),["D-"]);
assert.deepEqual(candidate([0.0]),["E"]);
assert.deepEqual(candidate([1.0, 0.3, 1.5, 2.8, 3.3]),["D", "D-", "C-", "B", "B+"]);
assert.deepEqual(candidate([0.0, 0.7]),["E", "D-"]);
}
test(); |
humaneval-HumanEval_142_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 {
// "
// 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++) {
if (i % 3 == 0) { | } 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;
}
} | lst.set(i, lst.get(i) * lst.get(i)); | }
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_119_match_parens.json-L41 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given an array array list of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// >>> matchParens((new ArrayList<String>(Arrays.asList((String)"()(", (String)")"))))
// ("Yes")
// >>> matchParens((new ArrayList<String>(Arrays.asList((String)")", (String)")"))))
// ("No")
public static String matchParens(ArrayList<String> lst) {
String s1 = lst.get(0);
String s2 = lst.get(1);
String s3 = s1+s2;
String s4 = s2+s1;
int c1 = 0;
int c2 = 0;
for (int i = 0; i < s3.length(); i++) {
if (s3.charAt(i) == '(') c1 += 1;
else c1 -= 1;
if (c1 < 0) break;
}
for (int i = 0; i < s4.length(); i++) {
if (s4.charAt(i) == '(') c2 += 1;
else c2 -= 1;
if (c2 < 0) break;
}
if (c1 == 0 || c2 == 0) return "Yes";
else return "No"; | } | } | }
public static void main(String[] args) {
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"()(", (String)")")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")", (String)")")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"(()(())", (String)"())())")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")())", (String)"(()()(")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"(())))", (String)"(()())((")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"()", (String)"())")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"(()(", (String)"()))()")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"((((", (String)"((())")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")(()", (String)"(()(")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")(", (String)")(")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"(", (String)")")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")", (String)"(")))).equals(("Yes")));
}
}
|
humaneval-HumanEval_135_can_arrange.json-L21 | js | //Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// >>> can_arrange([1, 2, 4, 3, 5])
// 3
// >>> can_arrange([1, 2, 3])
// -1
function can_arrange(arr){
var max = arr[0];
var res = -1;
for(var i = 1; i < arr.length; i++){
if(arr[i] < max){
res = i;
}else{
max = arr[i];
}
}
return res; | } | const assert = require('node:assert');
function test() {
let candidate = can_arrange;
assert.deepEqual(candidate([1, 2, 4, 3, 5]),3);
assert.deepEqual(candidate([1, 2, 4, 5]),-1);
assert.deepEqual(candidate([1, 4, 2, 5, 6, 7, 8, 9, 10]),2);
assert.deepEqual(candidate([4, 8, 5, 7, 3]),4);
assert.deepEqual(candidate([]),-1);
}
test(); |
|
humaneval-HumanEval_75_is_multiply_prime.json-L19 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that 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) {
while (a % i == 0) {
arr.add(i);
a /= i;
}
}
if (a > 2) {
arr.add(a);
}
return arr.size() == 3;
}
} | } | }
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_113_odd_count.json-L17 | js | //Given an array of strings, where each string consists of only digits, return an array.
// 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.
// >>> odd_count(["1234567"])
// ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// >>> odd_count(["3", "11111111"])
// ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
function odd_count(lst){
var new_lst = [];
for (var i = 0; i < lst.length; i++){
var word = lst[i];
var odd_sum = 0;
for (var j = 0; j < word.length; j++){
if (word[j] % 2 == 1){
odd_sum += 1; | }
var odd_word = "the number of odd elements " + odd_sum + "n the str" + odd_sum + "ng " + odd_sum + " of the " + odd_sum + "nput.";
new_lst.push(odd_word);
}
return new_lst;
} | } | const assert = require('node:assert');
function test() {
let candidate = odd_count;
assert.deepEqual(candidate(["1234567"]),["the number of odd elements 4n the str4ng 4 of the 4nput."]);
assert.deepEqual(candidate(["3", "11111111"]),["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]);
assert.deepEqual(candidate(["271", "137", "314"]),["the number of odd elements 2n the str2ng 2 of the 2nput.", "the number of odd elements 3n the str3ng 3 of the 3nput.", "the number of odd elements 2n the str2ng 2 of the 2nput."]);
}
test(); |
humaneval-HumanEval_154_cycpattern_check.json-L17 | py | def cycpattern_check(a: str, b: str) -> bool:
"""You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word
>>> cycpattern_check('abcd', 'abd')
False
>>> cycpattern_check('hello', 'ell')
True
>>> cycpattern_check('whassup', 'psus')
False
>>> cycpattern_check('abab', 'baa')
True
>>> cycpattern_check('efef', 'eeff')
False
>>> cycpattern_check('himenss', 'simen')
True
"""
| if a.find(b) != -1:
return True
b = b[1:] + b[0]
return False
| for i in range(len(b)): | def check(candidate):
assert candidate('xyzw', 'xyw') == False
assert candidate('yello', 'ell') == True
assert candidate('whattup', 'ptut') == False
assert candidate('efef', 'fee') == True
assert candidate('abab', 'aabb') == False
assert candidate('winemtt', 'tinem') == True
def test_check():
check(cycpattern_check)
test_check()
|
humaneval-HumanEval_108_count_nums.json-L23 | py | from typing import List
def count_nums(arr: List[int]) -> int:
"""
Write a function count_nums which takes an array of integers and returns
the number of elements which has a sum of digits > 0.
If a number is negative, then its first signed digit will be negative:
e.g. -123 has signed digits -1, 2, and 3.
>>> count_nums([])
0
>>> count_nums([-1, 11, -11])
1
>>> count_nums([1, 1, 2])
3
"""
n = 0
for i in arr:
if i < 0:
i = abs(i)
s = -1 * int(str(i)[0])
for j in str(i)[1:]:
s += int(j) | s = 0
for j in str(i):
s += int(j)
if s > 0:
n += 1
return n
| else: | def check(candidate):
assert candidate([]) == 0
assert candidate([-1, -2, 0]) == 0
assert candidate([1, 1, 2, -2, 3, 4, 5]) == 6
assert candidate([1, 6, 9, -6, 0, 1, 5]) == 5
assert candidate([1, 100, 98, -7, 1, -1]) == 4
assert candidate([12, 23, 34, -45, -56, 0]) == 5
assert candidate([0, 1]) == 1
assert candidate([1]) == 1
def test_check():
check(count_nums)
test_check()
|
humaneval-HumanEval_98_count_upper.json-L12 | js | //Given a string s, count the number of uppercase vowels in even indices.
// For example:
// >>> count_upper("aBCdEf")
// 1
// >>> count_upper("abcdefg")
// 0
// >>> count_upper("dBBE")
// 0
function count_upper(s){
var index;
var result = 0; | for (index = 0; index < s.length; index += 2){
if (vowel.indexOf(s[index]) > -1){
result += 1;
}
}
return result;
} | var vowel = ['A', 'E', 'I', 'O', 'U']; | const assert = require('node:assert');
function test() {
let candidate = count_upper;
assert.deepEqual(candidate("aBCdEf"),1);
assert.deepEqual(candidate("abcdefg"),0);
assert.deepEqual(candidate("dBBE"),0);
assert.deepEqual(candidate("B"),0);
assert.deepEqual(candidate("U"),1);
assert.deepEqual(candidate(""),0);
assert.deepEqual(candidate("EEEE"),2);
}
test(); |
humaneval-HumanEval_160_do_algebra.json-L22 | 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 answer;
while(count < operator.length){
switch(operator[count]){
case '*':
operand[count] = operand[count] * operand[count + 1];
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
case '//':
operand[count] = Math.floor(operand[count] / operand[count + 1]);
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
case '**':
operand[count] = Math.pow(operand[count], operand[count + 1]);
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
default:
count++;
do_again = false;
}
}
answer = operand[0];
operand.splice(0, 1);
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;
}
| let temp; | 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_86_anti_shuffle.json-L26 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// >>> antiShuffle(("Hi"))
// ("Hi")
// >>> antiShuffle(("hello"))
// ("ehllo")
// >>> antiShuffle(("Hello World!!!"))
// ("Hello !!!Wdlor")
public static String antiShuffle(String s) {
StringBuilder sb = new StringBuilder();
String[] words = s.split(" ");
for (String word : words) {
char[] chars = word.toCharArray(); | sb.append(new String(chars));
sb.append(" ");
}
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
} | Arrays.sort(chars); | }
public static void main(String[] args) {
assert(antiShuffle(("Hi")).equals(("Hi")));
assert(antiShuffle(("hello")).equals(("ehllo")));
assert(antiShuffle(("number")).equals(("bemnru")));
assert(antiShuffle(("abcd")).equals(("abcd")));
assert(antiShuffle(("Hello World!!!")).equals(("Hello !!!Wdlor")));
assert(antiShuffle(("")).equals(("")));
assert(antiShuffle(("Hi. My name is Mister Robot. How are you?")).equals((".Hi My aemn is Meirst .Rboot How aer ?ouy")));
}
}
|
humaneval-HumanEval_112_reverse_delete.json-L14 | js | //Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return an array containing the result string and true/false for the check.
// Example
// >>> reverse_delete("abcde", "ae")
// ["bcd", false]
// >>> reverse_delete("abcdef", "b")
// ["acdef", false]
// >>> reverse_delete("abcdedcba", "ab")
// ["cdedc", true]
function reverse_delete(s, c){
| const filterString = filter.join('');
const filterStringReverse = filter.reverse().join('');
const result = [];
if (filterString === filterStringReverse) {
result.push(filterString, true);
} else {
result.push(filterString, false);
}
return result;
} | const filter = s.split('').filter(x => c.includes(x) === false); | const assert = require('node:assert');
function test() {
let candidate = reverse_delete;
assert.deepEqual(candidate("abcde", "ae"),["bcd", false]);
assert.deepEqual(candidate("abcdef", "b"),["acdef", false]);
assert.deepEqual(candidate("abcdedcba", "ab"),["cdedc", true]);
assert.deepEqual(candidate("dwik", "w"),["dik", false]);
assert.deepEqual(candidate("a", "a"),["", true]);
assert.deepEqual(candidate("abcdedcba", ""),["abcdedcba", true]);
assert.deepEqual(candidate("abcdedcba", "v"),["abcdedcba", true]);
assert.deepEqual(candidate("vabba", "v"),["abba", true]);
assert.deepEqual(candidate("mamma", "mia"),["", true]);
}
test(); |
humaneval-HumanEval_149_sorted_list_sum.json-L29 | js | //Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// >>> list_sort(["aa", "a", "aaa"])
// ["aa"]
// >>> list_sort(["ab", "a", "aaa", "cd"])
// ["ab", "cd"]
function sorted_list_sum(lst){
var result = [];
for(var i = 0; i < lst.length; i++){
if(lst[i].length % 2 == 0){
result.push(lst[i]);
}
}
return result.sort(function(a, b){
if(a.length < b.length){
return -1;
}
else if(a.length > b.length){
return 1; | else{
if(a < b){
return -1;
}
else if(a > b){
return 1;
}
else{
return 0;
}
}
});
}
var a = ["aa", "a", "aaa"];
var b = ["ab", "a", "aaa", "cd"]; | } | const assert = require('node:assert');
function test() {
let candidate = sorted_list_sum;
assert.deepEqual(candidate(["aa", "a", "aaa"]),["aa"]);
assert.deepEqual(candidate(["school", "AI", "asdf", "b"]),["AI", "asdf", "school"]);
assert.deepEqual(candidate(["d", "b", "c", "a"]),[]);
assert.deepEqual(candidate(["d", "dcba", "abcd", "a"]),["abcd", "dcba"]);
assert.deepEqual(candidate(["AI", "ai", "au"]),["AI", "ai", "au"]);
assert.deepEqual(candidate(["a", "b", "b", "c", "c", "a"]),[]);
assert.deepEqual(candidate(["aaaa", "bbbb", "dd", "cc"]),["cc", "dd", "aaaa", "bbbb"]);
}
test(); |
humaneval-HumanEval_83_starts_one_ends.json-L9 | py | def starts_one_ends(n: int) -> int:
"""
Given a positive integer n, return the count of the numbers of n-digit
positive integers that start or end with 1.
"""
count = 0
for i in range(10**(n-1), 10**n):
if i // 10**(n-1) == 1 or i % 10 == 1: | return count
| count += 1 | def check(candidate):
assert candidate(1) == 1
assert candidate(2) == 18
assert candidate(3) == 180
assert candidate(4) == 1800
assert candidate(5) == 18000
def test_check():
check(starts_one_ends)
test_check()
|
humaneval-HumanEval_147_get_max_triples.json-L25 | 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_47_median.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 {
// Return median of elements in the array list l.
// >>> median((new ArrayList<Long>(Arrays.asList((long)3l, (long)1l, (long)2l, (long)4l, (long)5l))))
// (float)3l
// >>> median((new ArrayList<Long>(Arrays.asList((long)-10l, (long)4l, (long)6l, (long)1000l, (long)10l, (long)20l))))
// (15.0f)
public static float median(ArrayList<Long> l) {
| Collections.sort(l);
int size = l.size();
if (size % 2 == 0) {
ret = (l.get(size / 2) + l.get(size / 2 - 1)) / 2f;
} else {
ret = l.get(size / 2);
}
return ret;
}
} | float ret = 0; | }
public static void main(String[] args) {
assert(median((new ArrayList<Long>(Arrays.asList((long)3l, (long)1l, (long)2l, (long)4l, (long)5l)))) == (float)3l);
assert(median((new ArrayList<Long>(Arrays.asList((long)-10l, (long)4l, (long)6l, (long)1000l, (long)10l, (long)20l)))) == (8.0f));
assert(median((new ArrayList<Long>(Arrays.asList((long)5l)))) == (float)5l);
assert(median((new ArrayList<Long>(Arrays.asList((long)6l, (long)5l)))) == (5.5f));
assert(median((new ArrayList<Long>(Arrays.asList((long)8l, (long)1l, (long)3l, (long)9l, (long)9l, (long)2l, (long)7l)))) == (float)7l);
}
}
|
humaneval-HumanEval_7_filter_by_substring.json-L10 | js | //Filter an input array of strings only for ones that contain given substring
// >>> filter_by_substring([], "a")
// []
// >>> filter_by_substring(["abc", "bacd", "cde", "array"], "a")
// ["abc", "bacd", "array"]
function filter_by_substring(strings, substring){
var filtered = [];
for(var i = 0; i < strings.length; i++){
if(strings[i].includes(substring)){ | }
}
return filtered;
} | filtered.push(strings[i]); | const assert = require('node:assert');
function test() {
let candidate = filter_by_substring;
assert.deepEqual(candidate([], "john"),[]);
assert.deepEqual(candidate(["xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"], "xxx"),["xxx", "xxxAAA", "xxx"]);
assert.deepEqual(candidate(["xxx", "asd", "aaaxxy", "john doe", "xxxAAA", "xxx"], "xx"),["xxx", "aaaxxy", "xxxAAA", "xxx"]);
assert.deepEqual(candidate(["grunt", "trumpet", "prune", "gruesome"], "run"),["grunt", "prune"]);
}
test(); |
humaneval-HumanEval_14_all_prefixes.json-L8 | js | //Return array of all prefixes from shortest to longest of the input string
// >>> all_prefixes("abc")
// ["a", "ab", "abc"]
function all_prefixes(string){
var result = [];
for (var i = 1; i <= string.length; i++){
result.push(string.slice(0, i)); | return result;
}
| } | const assert = require('node:assert');
function test() {
let candidate = all_prefixes;
assert.deepEqual(candidate(""),[]);
assert.deepEqual(candidate("asdfgh"),["a", "as", "asd", "asdf", "asdfg", "asdfgh"]);
assert.deepEqual(candidate("WWW"),["W", "WW", "WWW"]);
}
test(); |
humaneval-HumanEval_75_is_multiply_prime.json-L40 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that 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) {
while (a % i == 0) {
arr.add(i);
a /= i;
}
}
if (a > 2) {
arr.add(a);
}
return arr.size() == 3;
} | } | }
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_100_make_a_pile.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 {
// 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>();
for (long i = 0; i < n; i++) {
levels.add(n + 2 * i);
}
return levels;
} | } | }
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_17_parse_music.json-L11 | js | //Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// >>> parse_music("o o| .| o| o| .| .| .| .| o o")
// [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
function parse_music(music_string){
| let song = [];
songs.forEach(s => {
if(s === 'o'){
song.push(4);
}else if(s === 'o|'){
song.push(2);
}else if(s === '.|'){
song.push(1);
}
});
return song;
}
| let songs = music_string.split(' '); | const assert = require('node:assert');
function test() {
let candidate = parse_music;
assert.deepEqual(candidate(""),[]);
assert.deepEqual(candidate("o o o o"),[4, 4, 4, 4]);
assert.deepEqual(candidate(".| .| .| .|"),[1, 1, 1, 1]);
assert.deepEqual(candidate("o| o| .| .| o o o o"),[2, 2, 1, 1, 4, 4, 4, 4]);
assert.deepEqual(candidate("o| .| o| .| o o| o o|"),[2, 1, 2, 1, 4, 2, 4, 2]);
}
test(); |
humaneval-HumanEval_106_f.json-L19 | py | from typing import List
def f(n: int) -> List[int]:
""" Implement the function f that takes n as a parameter,
and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even
or the sum of numbers from 1 to i otherwise.
i starts from 1.
the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
Example:
>>> f(5)
[1, 2, 6, 24, 15]
"""
import math
a=[]
for i in range(n):
i=i+1
if i%2==0:
a.append(math.factorial(i)) | a.append(sum(range(1,i+1)))
return a
pass | else: | def check(candidate):
assert candidate(5) == [1, 2, 6, 24, 15]
assert candidate(7) == [1, 2, 6, 24, 15, 720, 28]
assert candidate(1) == [1]
assert candidate(3) == [1, 2, 6]
def test_check():
check(f)
test_check()
|
humaneval-HumanEval_95_check_dict_case.json-L27 | py | from typing import Dict
def check_dict_case(dict: Dict[str, str]) -> bool:
"""
Given a dictionary, 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 dictionary 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
"""
if len(dict) == 0:
return False
if any(not isinstance(x, str) for x in dict.keys()):
return False
if any(not x.islower() for x in dict.keys()):
if any(not x.isupper() for x in dict.keys()):
return False | return True | def check(candidate):
assert candidate({ 'p': 'pineapple', 'b': 'banana' }) == True
assert candidate({ 'p': 'pineapple', 'A': 'banana', 'B': 'banana' }) == False
assert candidate({ 'p': 'pineapple', '5': 'banana', 'a': 'apple' }) == False
assert candidate({ 'Name': 'John', 'Age': '36', 'City': 'Houston' }) == False
assert candidate({ 'STATE': 'NC', 'ZIP': '12345' }) == True
assert candidate({ 'fruit': 'Orange', 'taste': 'Sweet' }) == True
assert candidate({ }) == False
def test_check():
check(check_dict_case)
test_check()
|
|
humaneval-HumanEval_143_words_in_sentence.json-L16 | 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){
| 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(' ');
} | return sentence.split(' ').filter(word => { | 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_1_separate_paren_groups.json-L16 | py | from typing import List
def separate_paren_groups(paren_string: str) -> List[str]:
""" Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
separate those group into separate strings and return the list of those.
Separate groups are balanced (each open brace is properly closed) and not nested within each other
Ignore any spaces in the input string.
>>> separate_paren_groups('( ) (( )) (( )( ))')
['()', '(())', '(()())']
"""
paren_string = paren_string.replace(' ', '')
groups = []
group = ''
open_count = 0
for c in paren_string: | open_count += 1
elif c == ')':
open_count -= 1
group += c
if open_count == 0:
groups.append(group)
group = ''
return groups
| if c == '(': | def check(candidate):
assert candidate('(()()) ((())) () ((())()())') == ['(()())', '((()))', '()', '((())()())']
assert candidate('() (()) ((())) (((())))') == ['()', '(())', '((()))', '(((())))']
assert candidate('(()(())((())))') == ['(()(())((())))']
assert candidate('( ) (( )) (( )( ))') == ['()', '(())', '(()())']
def test_check():
check(separate_paren_groups)
test_check()
|
humaneval-HumanEval_141_file_name_check.json-L37 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// >>> fileNameCheck(("example.txt"))
// ("Yes")
// >>> fileNameCheck(("1example.dll"))
// ("No")
public static String fileNameCheck(String file_name) {
String result = "No";
String[] tokens = file_name.split("\\.");
if (tokens.length != 2) {
return result;
}
String extension = tokens[1];
if (!(extension.equals("txt") || extension.equals("exe") || extension.equals("dll"))) {
return result;
}
String name = tokens[0];
int count = 0;
for (int i = 0; i < name.length(); i++) {
if (Character.isDigit(name.charAt(i))) { | }
}
if (count > 3) {
return result;
}
if (name.length() == 0) {
return result;
}
if (!Character.isLetter(name.charAt(0))) {
return result;
}
return "Yes";
}
} | count++; | }
public static void main(String[] args) {
assert(fileNameCheck(("example.txt")).equals(("Yes")));
assert(fileNameCheck(("1example.dll")).equals(("No")));
assert(fileNameCheck(("s1sdf3.asd")).equals(("No")));
assert(fileNameCheck(("K.dll")).equals(("Yes")));
assert(fileNameCheck(("MY16FILE3.exe")).equals(("Yes")));
assert(fileNameCheck(("His12FILE94.exe")).equals(("No")));
assert(fileNameCheck(("_Y.txt")).equals(("No")));
assert(fileNameCheck(("?aREYA.exe")).equals(("No")));
assert(fileNameCheck(("/this_is_valid.dll")).equals(("No")));
assert(fileNameCheck(("this_is_valid.wow")).equals(("No")));
assert(fileNameCheck(("this_is_valid.txt")).equals(("Yes")));
assert(fileNameCheck(("this_is_valid.txtexe")).equals(("No")));
assert(fileNameCheck(("#this2_i4s_5valid.ten")).equals(("No")));
assert(fileNameCheck(("@this1_is6_valid.exe")).equals(("No")));
assert(fileNameCheck(("this_is_12valid.6exe4.txt")).equals(("No")));
assert(fileNameCheck(("all.exe.txt")).equals(("No")));
assert(fileNameCheck(("I563_No.exe")).equals(("Yes")));
assert(fileNameCheck(("Is3youfault.txt")).equals(("Yes")));
assert(fileNameCheck(("no_one#knows.dll")).equals(("Yes")));
assert(fileNameCheck(("1I563_Yes3.exe")).equals(("No")));
assert(fileNameCheck(("I563_Yes3.txtt")).equals(("No")));
assert(fileNameCheck(("final..txt")).equals(("No")));
assert(fileNameCheck(("final132")).equals(("No")));
assert(fileNameCheck(("_f4indsartal132.")).equals(("No")));
assert(fileNameCheck((".txt")).equals(("No")));
assert(fileNameCheck(("s.")).equals(("No")));
}
}
|
humaneval-HumanEval_142_sum_squares.json-L30 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// "
// This function 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++) {
if (i % 3 == 0) {
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; | ans += lst.get(i);
}
return ans;
}
} | for (int i = 0; i < sz; i++) { | }
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_34_unique.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 {
// Return sorted unique elements in an array array list
// >>> unique((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)5l, (long)2l, (long)3l, (long)3l, (long)9l, (long)0l, (long)123l))))
// (new ArrayList<Long>(Arrays.asList((long)0l, (long)2l, (long)3l, (long)5l, (long)9l, (long)123l)))
public static ArrayList<Long> unique(ArrayList<Long> l) {
TreeSet<Long> tree = new TreeSet<Long>(l);
return new ArrayList<Long>(tree); | } | } | }
public static void main(String[] args) {
assert(unique((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)5l, (long)2l, (long)3l, (long)3l, (long)9l, (long)0l, (long)123l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)2l, (long)3l, (long)5l, (long)9l, (long)123l)))));
}
}
|
humaneval-HumanEval_9_rolling_max.json-L15 | js | //From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// >>> rolling_max([1, 2, 3, 2, 3, 4, 2])
// [1, 2, 3, 3, 3, 4, 4]
function rolling_max(numbers){
let max = [];
let tempMax = 0;
for(let i = 0; i < numbers.length; i++){
if(tempMax < numbers[i]){
tempMax = numbers[i];
}
max.push(tempMax);
}
return max; | } | const assert = require('node:assert');
function test() {
let candidate = rolling_max;
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([1, 2, 3, 4]),[1, 2, 3, 4]);
assert.deepEqual(candidate([4, 3, 2, 1]),[4, 4, 4, 4]);
assert.deepEqual(candidate([3, 2, 3, 100, 3]),[3, 3, 3, 100, 100]);
}
test(); |
|
humaneval-HumanEval_81_numerical_letter_grade.json-L60 | 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){ | }
else if (grades[i] == 0.0){
grades_array.push("E");
}
}
return grades_array;
} | grades_array.push("D-"); | 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_106_f.json-L32 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Implement the function f that takes n as a parameter,
// and returns an array array list of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// >>> f((5l))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l)))
public static ArrayList<Long> f(long n) {
ArrayList<Long> ret = new ArrayList<Long>();
for (long i = 1l; i <= n; i++) {
long v = 0l;
if (i % 2 == 0) {
v = 1l;
for (long j = 2l; j <= i; j++) {
v *= j;
}
} else {
v = (i * (i + 1l)) / 2l;
}
ret.add(v);
}
return ret; | } | } | }
public static void main(String[] args) {
assert(f((5l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l)))));
assert(f((7l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l, (long)720l, (long)28l)))));
assert(f((1l)).equals((new ArrayList<Long>(Arrays.asList((long)1l)))));
assert(f((3l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l)))));
}
}
|
humaneval-HumanEval_71_triangle_area.json-L18 | py | def triangle_area(a: int, b: int, c: int) -> float:
"""
Given the lengths of the three sides of a triangle. Return the area of
the triangle rounded to 2 decimal points if the three sides form a valid triangle.
Otherwise return -1
Three sides make a valid triangle when the sum of any two sides is greater
than the third side.
Example:
>>> triangle_area(3, 4, 5)
6.0
>>> triangle_area(1, 2, 10)
-1
"""
if a + b > c and a + c > b and b + c > a:
perimeter = (a + b + c) / 2
area = (perimeter * (perimeter - a) * (perimeter - b) * (perimeter - c)) ** 0.5
return round(area, 2) | return -1
| else: | def check(candidate):
assert candidate(3, 4, 5) == 6.0
assert candidate(1, 2, 10) == -1
assert candidate(4, 8, 5) == 8.18
assert candidate(2, 2, 2) == 1.73
assert candidate(1, 2, 3) == -1
assert candidate(10, 5, 7) == 16.25
assert candidate(2, 6, 3) == -1
assert candidate(1, 1, 1) == 0.43
assert candidate(2, 2, 10) == -1
def test_check():
check(triangle_area)
test_check()
|
humaneval-HumanEval_147_get_max_triples.json-L26 | py | def get_max_triples(n: int) -> int:
"""
You are given a positive integer n. You have to create an integer array a of length n.
For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
and a[i] + a[j] + a[k] is a multiple of 3.
Example :
>>> get_max_triples(5)
1
Explanation:
a = [1, 3, 7, 13, 21]
The only valid triple is (1, 7, 13).
"""
a = [i * i - i + 1 for i in range(1, n + 1)]
i = 0
j = 1
k = 2
count = 0
while (i < n - 2):
while (j < n - 1):
while (k < n):
if (a[i] + a[j] + a[k]) % 3 == 0:
count += 1
k += 1 | k = j + 1
i += 1
j = i + 1
k = j + 1
return count
| j += 1 | def check(candidate):
assert candidate(5) == 1
assert candidate(6) == 4
assert candidate(10) == 36
assert candidate(100) == 53361
def test_check():
check(get_max_triples)
test_check()
|
humaneval-HumanEval_149_sorted_list_sum.json-L28 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that 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) { | }
}
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;
}
} | result.add(s); | }
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_56_correct_bracketing.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 {
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correctBracketing(("<"))
// (false)
// >>> correctBracketing(("<>"))
// (true)
// >>> correctBracketing(("<<><>>"))
// (true)
// >>> correctBracketing(("><<>"))
// (false)
public static boolean correctBracketing(String brackets) {
int open = 0;
for (int i = 0; i < brackets.length(); i++) {
char c = brackets.charAt(i); | open++;
} else {
open--;
}
if (open < 0) {
return false;
}
}
return open == 0;
}
} | if (c == '<') { | }
public static void main(String[] args) {
assert(correctBracketing(("<>")) == (true));
assert(correctBracketing(("<<><>>")) == (true));
assert(correctBracketing(("<><><<><>><>")) == (true));
assert(correctBracketing(("<><><<<><><>><>><<><><<>>>")) == (true));
assert(correctBracketing(("<<<><>>>>")) == (false));
assert(correctBracketing(("><<>")) == (false));
assert(correctBracketing(("<")) == (false));
assert(correctBracketing(("<<<<")) == (false));
assert(correctBracketing((">")) == (false));
assert(correctBracketing(("<<>")) == (false));
assert(correctBracketing(("<><><<><>><>><<>")) == (false));
assert(correctBracketing(("<><><<><>><>>><>")) == (false));
}
}
|
humaneval-HumanEval_52_below_threshold.json-L20 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return true if all numbers in the array list l are below threshold t.
// >>> belowThreshold((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)10l))), (100l))
// (true)
// >>> belowThreshold((new ArrayList<Long>(Arrays.asList((long)1l, (long)20l, (long)4l, (long)10l))), (5l))
// (false)
public static boolean belowThreshold(ArrayList<Long> l, long t) {
Long[] a = l.toArray(new Long[l.size()]);
for (int i = 0; i < a.length; i++) {
if (a[i] >= t) {
return false;
} | return true;
}
} | } | }
public static void main(String[] args) {
assert(belowThreshold((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)10l))), (100l)) == (true));
assert(belowThreshold((new ArrayList<Long>(Arrays.asList((long)1l, (long)20l, (long)4l, (long)10l))), (5l)) == (false));
assert(belowThreshold((new ArrayList<Long>(Arrays.asList((long)1l, (long)20l, (long)4l, (long)10l))), (21l)) == (true));
assert(belowThreshold((new ArrayList<Long>(Arrays.asList((long)1l, (long)20l, (long)4l, (long)10l))), (22l)) == (true));
assert(belowThreshold((new ArrayList<Long>(Arrays.asList((long)1l, (long)8l, (long)4l, (long)10l))), (11l)) == (true));
assert(belowThreshold((new ArrayList<Long>(Arrays.asList((long)1l, (long)8l, (long)4l, (long)10l))), (10l)) == (false));
}
}
|
humaneval-HumanEval_146_specialFilter.json-L12 | js | //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
function specialFilter(nums){
let count = 0;
for(let i = 0; i < nums.length; i++){ | let firstDigit = nums[i].toString()[0];
let lastDigit = nums[i].toString()[nums[i].toString().length - 1];
if(num > 10 && firstDigit % 2 !== 0 && lastDigit % 2 !== 0){
count++;
}
}
return count;
}
| let num = nums[i]; | const assert = require('node:assert');
function test() {
let candidate = specialFilter;
assert.deepEqual(candidate([5, -2, 1, -5]),0);
assert.deepEqual(candidate([15, -73, 14, -15]),1);
assert.deepEqual(candidate([33, -2, -3, 45, 21, 109]),2);
assert.deepEqual(candidate([43, -12, 93, 125, 121, 109]),4);
assert.deepEqual(candidate([71, -2, -33, 75, 21, 19]),3);
assert.deepEqual(candidate([1]),0);
assert.deepEqual(candidate([]),0);
}
test(); |
humaneval-HumanEval_64_vowels_count.json-L14 | py | def vowels_count(s: str) -> int:
"""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
"""
s = s.lower() | count = 0
while i < len(s):
if (s[i] == 'a' or s[i] == 'e' or s[i] == 'i' or s[i] == 'o' or s[i] == 'u'):
count += 1
if (s[i] == 'y' and i == len(s) - 1):
count += 1
i += 1
return count
| i = 0 | def check(candidate):
assert candidate('abcde') == 2
assert candidate('Alone') == 3
assert candidate('key') == 2
assert candidate('bye') == 1
assert candidate('keY') == 2
assert candidate('bYe') == 1
assert candidate('ACEDY') == 3
def test_check():
check(vowels_count)
test_check()
|
humaneval-HumanEval_131_digits.json-L12 | py | def digits(n: int) -> int:
"""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
"""
| return n if n % 2 == 1 else 0
d, m = divmod(n, 10)
return digits(d) * (m if m % 2 == 1 else 1)
| if n < 10: | def check(candidate):
assert candidate(5) == 5
assert candidate(54) == 5
assert candidate(120) == 1
assert candidate(5014) == 5
assert candidate(98765) == 315
assert candidate(5576543) == 2625
assert candidate(2468) == 0
def test_check():
check(digits)
test_check()
|
humaneval-HumanEval_37_sort_even.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 {
// This function takes an array array list l and returns an array array list l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// >>> sortEven((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))
// >>> sortEven((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l))))
// (new ArrayList<Long>(Arrays.asList((long)3l, (long)6l, (long)5l, (long)4l)))
public static ArrayList<Long> sortEven(ArrayList<Long> l) {
ArrayList<Long> res = new ArrayList<Long>();
ArrayList<Long> evenIndexed = new ArrayList<Long>();
int index = 0;
for (Long num : l) {
if (index % 2 == 0) {
evenIndexed.add(num);
} | }
Collections.sort(evenIndexed);
index = 0;
for (Long num : l) {
if (index % 2 == 0) {
res.add(evenIndexed.get(0));
evenIndexed.remove(0);
} else {
res.add(num);
}
index++;
}
return res;
}
} | index++; | }
public static void main(String[] args) {
assert(sortEven((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))));
assert(sortEven((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)-5l, (long)2l, (long)-3l, (long)3l, (long)9l, (long)0l, (long)123l, (long)1l, (long)-10l)))).equals((new ArrayList<Long>(Arrays.asList((long)-10l, (long)3l, (long)-5l, (long)2l, (long)-3l, (long)3l, (long)5l, (long)0l, (long)9l, (long)1l, (long)123l)))));
assert(sortEven((new ArrayList<Long>(Arrays.asList((long)5l, (long)8l, (long)-12l, (long)4l, (long)23l, (long)2l, (long)3l, (long)11l, (long)12l, (long)-10l)))).equals((new ArrayList<Long>(Arrays.asList((long)-12l, (long)8l, (long)3l, (long)4l, (long)5l, (long)2l, (long)12l, (long)11l, (long)23l, (long)-10l)))));
}
}
|
humaneval-HumanEval_158_find_max.json-L37 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that accepts an array array list of strings.
// The array 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.
// >>> findMax((new ArrayList<String>(Arrays.asList((String)"name", (String)"of", (String)"string"))))
// ("string")
// >>> findMax((new ArrayList<String>(Arrays.asList((String)"name", (String)"enam", (String)"game"))))
// ("enam")
// >>> findMax((new ArrayList<String>(Arrays.asList((String)"aaaaaaa", (String)"bb", (String)"cc"))))
// ("aaaaaaa")
public static String findMax(ArrayList<String> words) {
Map<String, Integer> wordsToUniqueCharacters = new HashMap<String, Integer>();
for (String word : words) {
Set<Character> uniqueCharacters = new HashSet<Character>();
for (char c : word.toCharArray()) {
uniqueCharacters.add(c);
}
wordsToUniqueCharacters.put(word, uniqueCharacters.size());
}
words.sort(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
int compareResult = wordsToUniqueCharacters.get(o2).compareTo(wordsToUniqueCharacters.get(o1));
if (compareResult == 0) {
return o1.compareTo(o2);
}
return compareResult;
} | return words.get(0);
}
} | }); | }
public static void main(String[] args) {
assert(findMax((new ArrayList<String>(Arrays.asList((String)"name", (String)"of", (String)"string")))).equals(("string")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"name", (String)"enam", (String)"game")))).equals(("enam")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"aaaaaaa", (String)"bb", (String)"cc")))).equals(("aaaaaaa")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"abc", (String)"cba")))).equals(("abc")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"play", (String)"this", (String)"game", (String)"of", (String)"footbott")))).equals(("footbott")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"we", (String)"are", (String)"gonna", (String)"rock")))).equals(("gonna")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"we", (String)"are", (String)"a", (String)"mad", (String)"nation")))).equals(("nation")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"this", (String)"is", (String)"a", (String)"prrk")))).equals(("this")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"b")))).equals(("b")));
assert(findMax((new ArrayList<String>(Arrays.asList((String)"play", (String)"play", (String)"play")))).equals(("play")));
}
}
|
humaneval-HumanEval_61_correct_bracketing.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correctBracketing(("("))
// (false)
// >>> correctBracketing(("()"))
// (true)
// >>> correctBracketing(("(()())"))
// (true)
// >>> correctBracketing((")(()"))
// (false)
public static boolean correctBracketing(String brackets) {
int balance = 0;
for (int i = 0; i < brackets.length(); i++) {
if (brackets.charAt(i) == '(') {
balance++; | balance--;
}
if (balance < 0) {
return false;
}
}
return balance == 0;
}
} | } else { | }
public static void main(String[] args) {
assert(correctBracketing(("()")) == (true));
assert(correctBracketing(("(()())")) == (true));
assert(correctBracketing(("()()(()())()")) == (true));
assert(correctBracketing(("()()((()()())())(()()(()))")) == (true));
assert(correctBracketing(("((()())))")) == (false));
assert(correctBracketing((")(()")) == (false));
assert(correctBracketing(("(")) == (false));
assert(correctBracketing(("((((")) == (false));
assert(correctBracketing((")")) == (false));
assert(correctBracketing(("(()")) == (false));
assert(correctBracketing(("()()(()())())(()")) == (false));
assert(correctBracketing(("()()(()())()))()")) == (false));
}
}
|
humaneval-HumanEval_156_int_to_mini_roman.json-L38 | 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_99_closest_integer.json-L19 | js | //Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// >>> closest_integer("10")
// 10
// >>> closest_integer("15.3")
// 15
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
function closest_integer(value){
value = parseFloat(value);
if(value > 0){
if(value - Math.floor(value) < 0.5){
return Math.floor(value); | return Math.ceil(value);
}
}else{
if(value - Math.floor(value) > -0.5){
return Math.floor(value);
}else{
return Math.ceil(value);
}
}
}
| }else{ | const assert = require('node:assert');
function test() {
let candidate = closest_integer;
assert.deepEqual(candidate("10"),10);
assert.deepEqual(candidate("14.5"),15);
assert.deepEqual(candidate("-15.5"),-16);
assert.deepEqual(candidate("15.3"),15);
assert.deepEqual(candidate("0"),0);
}
test(); |
humaneval-HumanEval_141_file_name_check.json-L27 | 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():
s_count += 1
if i == '.':
e_count += 1
if s_count > 3 or e_count != 1: | 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'
| return 'No' | def check(candidate):
assert candidate('example.txt') == 'Yes'
assert candidate('1example.dll') == 'No'
assert candidate('s1sdf3.asd') == 'No'
assert candidate('K.dll') == 'Yes'
assert candidate('MY16FILE3.exe') == 'Yes'
assert candidate('His12FILE94.exe') == 'No'
assert candidate('_Y.txt') == '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_109_move_one_ball.json-L34 | 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++){
if(arr[i] > arr[i + 1]){
diff_count += 1;
}
}
if(diff_count > 1){
return false;
} | return true;
}
} | else{ | 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_126_is_sorted.json-L37 | js | //Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> is_sorted([5])
// true
// >>> is_sorted([1, 2, 3, 4, 5])
// true
// >>> is_sorted([1, 3, 2, 4, 5])
// false
// >>> is_sorted([1, 2, 3, 4, 5, 6])
// true
// >>> is_sorted([1, 2, 3, 4, 5, 6, 7])
// true
// >>> is_sorted([1, 3, 2, 4, 5, 6, 7])
// false
// >>> is_sorted([1, 2, 2, 3, 3, 4])
// true
// >>> is_sorted([1, 2, 2, 2, 3, 4])
// false
function is_sorted(lst){
var last = null;
var dupe_found = false;
for (var x of lst){
if (last == null){
last = x;
} else if (x < last){
return false;
} else if (x == last){
if (dupe_found){
return false;
} else {
dupe_found = true;
}
} else {
last = x; | }
}
return true;
}
| dupe_found = false; | const assert = require('node:assert');
function test() {
let candidate = is_sorted;
assert.deepEqual(candidate([5]),true);
assert.deepEqual(candidate([1, 2, 3, 4, 5]),true);
assert.deepEqual(candidate([1, 3, 2, 4, 5]),false);
assert.deepEqual(candidate([1, 2, 3, 4, 5, 6]),true);
assert.deepEqual(candidate([1, 2, 3, 4, 5, 6, 7]),true);
assert.deepEqual(candidate([1, 3, 2, 4, 5, 6, 7]),false);
assert.deepEqual(candidate([]),true);
assert.deepEqual(candidate([1]),true);
assert.deepEqual(candidate([3, 2, 1]),false);
assert.deepEqual(candidate([1, 2, 2, 2, 3, 4]),false);
assert.deepEqual(candidate([1, 2, 3, 3, 3, 4]),false);
assert.deepEqual(candidate([1, 2, 2, 3, 3, 4]),true);
assert.deepEqual(candidate([1, 2, 3, 4]),true);
}
test(); |
humaneval-HumanEval_26_remove_duplicates.json-L18 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// From an array array list of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// >>> removeDuplicates((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)2l, (long)4l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)4l)))
public static ArrayList<Long> removeDuplicates(ArrayList<Long> numbers) {
HashMap<Long, Long> hashmap = new HashMap<Long, Long>();
for (int i = 0; i < numbers.size(); i++) {
Long key = numbers.get(i);
if (hashmap.containsKey(key)) { | } else {
hashmap.put(key, 1L);
}
}
ArrayList<Long> out = new ArrayList<Long>();
for (int i = 0; i < numbers.size(); i++) {
Long key = numbers.get(i);
if (hashmap.get(key) == 1) {
out.add(key);
}
}
return out;
}
} | hashmap.put(key, hashmap.get(key) + 1); | }
public static void main(String[] args) {
assert(removeDuplicates((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(removeDuplicates((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))));
assert(removeDuplicates((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)2l, (long)4l, (long)3l, (long)5l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)5l)))));
}
}
|
humaneval-HumanEval_16_count_distinct_characters.json-L11 | py | def count_distinct_characters(string: str) -> int:
""" Given a string, find out how many distinct characters (regardless of case) does it consist of
>>> count_distinct_characters('xyzXYZ')
3
>>> count_distinct_characters('Jerry')
4
"""
assert isinstance(string, str)
s = set()
for l in string: | return len(s)
| s.add(l.lower()) | def check(candidate):
assert candidate('') == 0
assert candidate('abcde') == 5
assert candidate('abcdecadeCADE') == 5
assert candidate('aaaaAAAAaaaa') == 1
assert candidate('Jerry jERRY JeRRRY') == 5
def test_check():
check(count_distinct_characters)
test_check()
|
humaneval-HumanEval_133_sum_squares.json-L23 | py | from typing import List
def sum_squares(lst: List[float]) -> int:
"""You are given a list of numbers.
You need to return the sum of squared numbers in the given list,
round each element in the list to the upper int(Ceiling) first.
Examples:
>>> lst([1.0, 2.0, 3.0])
14
>>> lst([1.0, 4.0, 9.0])
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
"""
import math
for i in range(len(lst)): | total = 0
for i in lst:
total += i**2
return total | lst[i] = math.ceil(lst[i]) | def check(candidate):
assert candidate([1.0, 2.0, 3.0]) == 14
assert candidate([1.0, 2.0, 3.0]) == 14
assert candidate([1.0, 3.0, 5.0, 7.0]) == 84
assert candidate([1.4, 4.2, 0.0]) == 29
assert candidate([-2.4, 1.0, 1.0]) == 6
assert candidate([100.0, 1.0, 15.0, 2.0]) == 10230
assert candidate([10000.0, 10000.0]) == 200000000
assert candidate([-1.4, 4.6, 6.3]) == 75
assert candidate([-1.4, 17.9, 18.9, 19.9]) == 1086
assert candidate([0.0]) == 0
assert candidate([-1.0]) == 1
assert candidate([-1.0, 1.0, 0.0]) == 2
def test_check():
check(sum_squares)
test_check()
|
humaneval-HumanEval_57_monotonic.json-L19 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return true is array list elements are monotonically increasing or decreasing.
// >>> monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)20l))))
// (true)
// >>> monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)20l, (long)4l, (long)10l))))
// (false)
// >>> monotonic((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)0l, (long)-10l))))
// (true)
public static boolean monotonic(ArrayList<Long> l) {
long a = l.get(0);
boolean inc = true; | for (int i = 1; i < l.size(); i++) {
if (l.get(i) < a) {
inc = false;
}
if (l.get(i) > a) {
dec = false;
}
a = l.get(i);
}
return inc || dec;
}
} | boolean dec = true; | }
public static void main(String[] args) {
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)10l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)4l, (long)20l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)20l, (long)4l, (long)10l)))) == (false));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)0l, (long)-10l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)1l, (long)0l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)2l, (long)5l, (long)60l)))) == (false));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)60l)))) == (true));
assert(monotonic((new ArrayList<Long>(Arrays.asList((long)9l, (long)9l, (long)9l, (long)9l)))) == (true));
}
}
|
humaneval-HumanEval_98_count_upper.json-L16 | js | //Given a string s, count the number of uppercase vowels in even indices.
// For example:
// >>> count_upper("aBCdEf")
// 1
// >>> count_upper("abcdefg")
// 0
// >>> count_upper("dBBE")
// 0
function count_upper(s){
var index;
var result = 0;
var vowel = ['A', 'E', 'I', 'O', 'U'];
for (index = 0; index < s.length; index += 2){
if (vowel.indexOf(s[index]) > -1){
result += 1; | }
return result;
} | } | const assert = require('node:assert');
function test() {
let candidate = count_upper;
assert.deepEqual(candidate("aBCdEf"),1);
assert.deepEqual(candidate("abcdefg"),0);
assert.deepEqual(candidate("dBBE"),0);
assert.deepEqual(candidate("B"),0);
assert.deepEqual(candidate("U"),1);
assert.deepEqual(candidate(""),0);
assert.deepEqual(candidate("EEEE"),2);
}
test(); |
humaneval-HumanEval_143_words_in_sentence.json-L32 | py | def words_in_sentence(sentence: str) -> str:
"""
You are given a string representing a sentence,
the sentence contains some words separated by a space,
and you have to return a string that contains the words from the original sentence,
whose lengths are prime numbers,
the order of the words in 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
"""
def is_prime(n: int) -> bool:
if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False
return True
words = sentence.split()
prime_words = []
for word in words: | prime_words.append(word)
return ' '.join(prime_words) | if is_prime(len(word)): | def check(candidate):
assert candidate('This is a test') == 'is'
assert candidate('lets go for swimming') == 'go for'
assert candidate('there is no place available here') == 'there is no place'
assert candidate('Hi I am Hussein') == 'Hi am Hussein'
assert candidate('go for it') == 'go for it'
assert candidate('here') == ''
assert candidate('here is') == 'is'
def test_check():
check(words_in_sentence)
test_check()
|
humaneval-HumanEval_119_match_parens.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 {
// You are given an array array list of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// >>> matchParens((new ArrayList<String>(Arrays.asList((String)"()(", (String)")"))))
// ("Yes")
// >>> matchParens((new ArrayList<String>(Arrays.asList((String)")", (String)")"))))
// ("No")
public static String matchParens(ArrayList<String> lst) {
String s1 = lst.get(0);
String s2 = lst.get(1);
String s3 = s1+s2; | int c1 = 0;
int c2 = 0;
for (int i = 0; i < s3.length(); i++) {
if (s3.charAt(i) == '(') c1 += 1;
else c1 -= 1;
if (c1 < 0) break;
}
for (int i = 0; i < s4.length(); i++) {
if (s4.charAt(i) == '(') c2 += 1;
else c2 -= 1;
if (c2 < 0) break;
}
if (c1 == 0 || c2 == 0) return "Yes";
else return "No";
}
} | String s4 = s2+s1; | }
public static void main(String[] args) {
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"()(", (String)")")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")", (String)")")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"(()(())", (String)"())())")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")())", (String)"(()()(")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"(())))", (String)"(()())((")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"()", (String)"())")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"(()(", (String)"()))()")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"((((", (String)"((())")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")(()", (String)"(()(")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")(", (String)")(")))).equals(("No")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)"(", (String)")")))).equals(("Yes")));
assert(matchParens((new ArrayList<String>(Arrays.asList((String)")", (String)"(")))).equals(("Yes")));
}
}
|
humaneval-HumanEval_46_fib4.json-L27 | js | //The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// >>> fib4(5)
// 4
// >>> fib4(6)
// 8
// >>> fib4(7)
// 14
function fib4(n){
var prev = [0,0,2,0];
if(n<prev.length){
return prev[n];
}
for(var i=4;i<=n;i++){
var curr = prev[0]+prev[1]+prev[2]+prev[3];
prev[0] = prev[1];
prev[1] = prev[2];
prev[2] = prev[3];
prev[3] = curr;
}
return prev[3]; | } | const assert = require('node:assert');
function test() {
let candidate = fib4;
assert.deepEqual(candidate(5),4);
assert.deepEqual(candidate(8),28);
assert.deepEqual(candidate(10),104);
assert.deepEqual(candidate(12),386);
}
test(); |
|
humaneval-HumanEval_126_is_sorted.json-L34 | js | //Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> is_sorted([5])
// true
// >>> is_sorted([1, 2, 3, 4, 5])
// true
// >>> is_sorted([1, 3, 2, 4, 5])
// false
// >>> is_sorted([1, 2, 3, 4, 5, 6])
// true
// >>> is_sorted([1, 2, 3, 4, 5, 6, 7])
// true
// >>> is_sorted([1, 3, 2, 4, 5, 6, 7])
// false
// >>> is_sorted([1, 2, 2, 3, 3, 4])
// true
// >>> is_sorted([1, 2, 2, 2, 3, 4])
// false
function is_sorted(lst){
var last = null;
var dupe_found = false;
for (var x of lst){
if (last == null){
last = x;
} else if (x < last){
return false;
} else if (x == last){
if (dupe_found){
return false;
} else {
dupe_found = true; | } else {
last = x;
dupe_found = false;
}
}
return true;
}
| } | const assert = require('node:assert');
function test() {
let candidate = is_sorted;
assert.deepEqual(candidate([5]),true);
assert.deepEqual(candidate([1, 2, 3, 4, 5]),true);
assert.deepEqual(candidate([1, 3, 2, 4, 5]),false);
assert.deepEqual(candidate([1, 2, 3, 4, 5, 6]),true);
assert.deepEqual(candidate([1, 2, 3, 4, 5, 6, 7]),true);
assert.deepEqual(candidate([1, 3, 2, 4, 5, 6, 7]),false);
assert.deepEqual(candidate([]),true);
assert.deepEqual(candidate([1]),true);
assert.deepEqual(candidate([3, 2, 1]),false);
assert.deepEqual(candidate([1, 2, 2, 2, 3, 4]),false);
assert.deepEqual(candidate([1, 2, 3, 3, 3, 4]),false);
assert.deepEqual(candidate([1, 2, 2, 3, 3, 4]),true);
assert.deepEqual(candidate([1, 2, 3, 4]),true);
}
test(); |
humaneval-HumanEval_89_encrypt.json-L23 | 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 = "";
var shiftBy = 2 * 2;
for(var i = 0; i < s.length; i++){
var index = alphabet.indexOf(s[i]);
newString += alphabet[(index + shiftBy) % 26];
}
return newString; | } | 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_153_Strongest_Extension.json-L34 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// 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(); | if (diff > strength) {
strength = diff;
strongest = s;
}
}
return class_name + "." + strongest;
}
} | int diff = cap - sm; | }
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_6_parse_nested_parens.json-L16 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// >>> parseNestedParens(("(()()) ((())) () ((())()())"))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)1l, (long)3l)))
public static ArrayList<Long> parseNestedParens(String paren_string) {
ArrayList<Long> result = new ArrayList<Long>(); | for (String paren : paren_strings) {
long max_depth = 0;
long current_depth = 0;
for (char c : paren.toCharArray()) {
if (c == '(') {
current_depth += 1;
max_depth = Math.max(max_depth, current_depth);
} else if (c == ')') {
current_depth -= 1;
}
}
result.add(max_depth);
}
return result;
}
} | String[] paren_strings = paren_string.split(" "); | }
public static void main(String[] args) {
assert(parseNestedParens(("(()()) ((())) () ((())()())")).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)1l, (long)3l)))));
assert(parseNestedParens(("() (()) ((())) (((())))")).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))));
assert(parseNestedParens(("(()(())((())))")).equals((new ArrayList<Long>(Arrays.asList((long)4l)))));
}
}
|
humaneval-HumanEval_91_is_bored.json-L16 | 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_80_is_happy.json-L22 | py | def is_happy(s: str) -> bool:
"""You are given a string s.
Your task is to check if the string is happy or not.
A string is happy if its length is at least 3 and every 3 consecutive letters are distinct
For example:
>>> is_happy(a)
False
>>> is_happy(aa)
False
>>> is_happy(abcd)
True
>>> is_happy(aabb)
False
>>> is_happy(adb)
True
>>> is_happy(xyy)
False
"""
n = len(s)
if n < 3:
return False | for i in range(n - 2):
if s[i] == s[i + 1] or s[i] == s[i + 2] or s[i + 1] == s[i + 2]:
return False
return True
| else: | def check(candidate):
assert candidate('a') == False
assert candidate('aa') == False
assert candidate('abcd') == True
assert candidate('aabb') == False
assert candidate('adb') == True
assert candidate('xyy') == False
assert candidate('iopaxpoi') == True
assert candidate('iopaxioi') == False
def test_check():
check(is_happy)
test_check()
|
humaneval-HumanEval_76_is_simple_power.json-L26 | py | def is_simple_power(x: int, n: int) -> bool:
"""Your task is to write a function that returns true if a number x is a simple
power of n and false in other cases.
x is a simple power of n if n**int=x
For example:
>>> is_simple_power(1, 4)
true
>>> is_simple_power(2, 2)
true
>>> is_simple_power(8, 2)
true
>>> is_simple_power(3, 2)
false
>>> is_simple_power(3, 1)
false
>>> is_simple_power(5, 3)
false
"""
if x == 0:
return False
else:
while x > 1:
if x % n != 0:
return False
x /= n | return True | def check(candidate):
assert candidate(16, 2) == True
assert candidate(143214, 16) == False
assert candidate(4, 2) == True
assert candidate(9, 3) == True
assert candidate(16, 4) == True
assert candidate(24, 2) == False
assert candidate(128, 4) == False
assert candidate(12, 6) == False
assert candidate(1, 1) == True
assert candidate(1, 12) == True
def test_check():
check(is_simple_power)
test_check()
|
|
humaneval-HumanEval_118_get_closest_vowel.json-L22 | py | def get_closest_vowel(word: str) -> str:
"""You are given a word. Your task is to find the closest vowel that stands between
two consonants from the right side of the word (case sensitive).
Vowels in the beginning and ending doesn't count. Return empty string if you didn't
find any vowel met the above condition.
You may assume that the given string contains English letter only.
Example:
>>> get_closest_vowel('yogurt')
'u'
>>> get_closest_vowel('FULL')
'U'
>>> get_closest_vowel('quick')
''
>>> get_closest_vowel('ab')
''
"""
if len(word) < 3:
return '' | if word[i] in 'aeiouAEIOU' and word[i-1] not in 'aeiouAEIOU' and word[i+1] not in 'aeiouAEIOU':
return word[i]
return ''
| for i in range(len(word) - 2, 0, -1): | def check(candidate):
assert candidate('yogurt') == 'u'
assert candidate('full') == 'u'
assert candidate('easy') == ''
assert candidate('eAsy') == ''
assert candidate('ali') == ''
assert candidate('bad') == 'a'
assert candidate('most') == 'o'
assert candidate('ab') == ''
assert candidate('ba') == ''
assert candidate('quick') == ''
assert candidate('anime') == 'i'
assert candidate('Asia') == ''
assert candidate('Above') == 'o'
def test_check():
check(get_closest_vowel)
test_check()
|
humaneval-HumanEval_81_numerical_letter_grade.json-L55 | 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) {
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+"); | letterGrades.add("D");
} else if (currentGrade > 0.0f) {
letterGrades.add("D-");
} else {
letterGrades.add("E");
}
}
return letterGrades;
}
} | } else if (currentGrade > 0.7f) { | }
public static void main(String[] args) {
assert(numericalLetterGrade((new ArrayList<Float>(Arrays.asList((float)4.0f, (float)3l, (float)1.7f, (float)2l, (float)3.5f)))).equals((new ArrayList<String>(Arrays.asList((String)"A+", (String)"B", (String)"C-", (String)"C", (String)"A-")))));
assert(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_106_f.json-L18 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Implement the function f that takes n as a parameter,
// and returns an array array list of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// >>> f((5l))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l)))
public static ArrayList<Long> f(long n) {
| for (long i = 1l; i <= n; i++) {
long v = 0l;
if (i % 2 == 0) {
v = 1l;
for (long j = 2l; j <= i; j++) {
v *= j;
}
} else {
v = (i * (i + 1l)) / 2l;
}
ret.add(v);
}
return ret;
}
} | ArrayList<Long> ret = new ArrayList<Long>(); | }
public static void main(String[] args) {
assert(f((5l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l)))));
assert(f((7l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l, (long)720l, (long)28l)))));
assert(f((1l)).equals((new ArrayList<Long>(Arrays.asList((long)1l)))));
assert(f((3l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l)))));
}
}
|
humaneval-HumanEval_144_simplify.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 {
// 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[] 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);
}
} | String[] nums = x.split("/"); | }
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_141_file_name_check.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 {
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// >>> fileNameCheck(("example.txt"))
// ("Yes")
// >>> fileNameCheck(("1example.dll"))
// ("No")
public static String fileNameCheck(String file_name) {
String result = "No";
String[] tokens = file_name.split("\\.");
if (tokens.length != 2) {
return result;
}
String extension = tokens[1];
if (!(extension.equals("txt") || extension.equals("exe") || extension.equals("dll"))) {
return result;
} | int count = 0;
for (int i = 0; i < name.length(); i++) {
if (Character.isDigit(name.charAt(i))) {
count++;
}
}
if (count > 3) {
return result;
}
if (name.length() == 0) {
return result;
}
if (!Character.isLetter(name.charAt(0))) {
return result;
}
return "Yes";
}
} | String name = tokens[0]; | }
public static void main(String[] args) {
assert(fileNameCheck(("example.txt")).equals(("Yes")));
assert(fileNameCheck(("1example.dll")).equals(("No")));
assert(fileNameCheck(("s1sdf3.asd")).equals(("No")));
assert(fileNameCheck(("K.dll")).equals(("Yes")));
assert(fileNameCheck(("MY16FILE3.exe")).equals(("Yes")));
assert(fileNameCheck(("His12FILE94.exe")).equals(("No")));
assert(fileNameCheck(("_Y.txt")).equals(("No")));
assert(fileNameCheck(("?aREYA.exe")).equals(("No")));
assert(fileNameCheck(("/this_is_valid.dll")).equals(("No")));
assert(fileNameCheck(("this_is_valid.wow")).equals(("No")));
assert(fileNameCheck(("this_is_valid.txt")).equals(("Yes")));
assert(fileNameCheck(("this_is_valid.txtexe")).equals(("No")));
assert(fileNameCheck(("#this2_i4s_5valid.ten")).equals(("No")));
assert(fileNameCheck(("@this1_is6_valid.exe")).equals(("No")));
assert(fileNameCheck(("this_is_12valid.6exe4.txt")).equals(("No")));
assert(fileNameCheck(("all.exe.txt")).equals(("No")));
assert(fileNameCheck(("I563_No.exe")).equals(("Yes")));
assert(fileNameCheck(("Is3youfault.txt")).equals(("Yes")));
assert(fileNameCheck(("no_one#knows.dll")).equals(("Yes")));
assert(fileNameCheck(("1I563_Yes3.exe")).equals(("No")));
assert(fileNameCheck(("I563_Yes3.txtt")).equals(("No")));
assert(fileNameCheck(("final..txt")).equals(("No")));
assert(fileNameCheck(("final132")).equals(("No")));
assert(fileNameCheck(("_f4indsartal132.")).equals(("No")));
assert(fileNameCheck((".txt")).equals(("No")));
assert(fileNameCheck(("s.")).equals(("No")));
}
}
|
humaneval-HumanEval_107_even_odd_palindrome.json-L28 | js | //Given a positive integer n, return an array that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// >>> even_odd_palindrome(3)
// [1, 2]
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// >>> even_odd_palindrome(12)
// [4, 6]
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned array has the number of even and odd integer palindromes respectively.
function even_odd_palindrome(n){
var pal = [];
var isPalindrome = function(x){
var y = x.toString().split('').reverse().join('');
return y == x;
}
for(var i = 1; i <= n; i++){
if(isPalindrome(i)){
pal.push(i);
}
}
var odd = 0; | for(var i = 0; i < pal.length; i++){
if(pal[i] % 2 == 0){
even++;
}
else{
odd++;
}
}
return [even, odd];
} | var even = 0; | const assert = require('node:assert');
function test() {
let candidate = even_odd_palindrome;
assert.deepEqual(candidate(123),[8, 13]);
assert.deepEqual(candidate(12),[4, 6]);
assert.deepEqual(candidate(3),[1, 2]);
assert.deepEqual(candidate(63),[6, 8]);
assert.deepEqual(candidate(25),[5, 6]);
assert.deepEqual(candidate(19),[4, 6]);
assert.deepEqual(candidate(9),[4, 5]);
assert.deepEqual(candidate(1),[0, 1]);
}
test(); |
humaneval-HumanEval_91_is_bored.json-L15 | py | def is_bored(S: str) -> int:
"""
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
"""
boredoms = 0
sentences = S.split('.') | words = sentence.split()
if words and words[0] == 'I':
boredoms += 1
return boredoms
| for sentence in sentences: | def check(candidate):
assert candidate('Hello world') == 0
assert candidate('Is the sky blue?') == 0
assert candidate('I love It !') == 1
assert candidate('bIt') == 0
assert candidate('I feel good today. I will be productive. will kill It') == 2
assert candidate('You and I are going for a walk') == 0
def test_check():
check(is_bored)
test_check()
|
humaneval-HumanEval_139_special_factorial.json-L13 | py | def special_factorial(n: int) -> int:
"""The Brazilian factorial is defined as:
brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
where n > 0
For example:
>>> special_factorial(4)
288
The function will receive an integer as input and should return the special
factorial of this integer.
"""
| if n <= 1:
return 1
else:
return n * factorial(n-1)
if n <= 1:
return 1
else:
return n * special_factorial(n-1) * factorial(n-1)
| def factorial(n): | def check(candidate):
assert candidate(4) == 288
assert candidate(5) == 34560
assert candidate(7) == 125411328000
assert candidate(1) == 1
def test_check():
check(special_factorial)
test_check()
|
humaneval-HumanEval_115_max_fill.json-L36 | js | //You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// >>> max_fill([[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], 1)
// 6
// Example 2:
// >>> max_fill([[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], 2)
// 5
// Example 3:
// >>> max_fill([[0, 0, 0], [0, 0, 0]], 5)
// 0
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
function max_fill(grid, capacity){
var maxFill = 0;
var sum = 0;
var c = 1;
var r = grid.length;
var c = grid[0].length;
for(var i = 0; i < r; i++){
sum = 0;
for(var j = 0; j < c; j++){
sum += grid[i][j];
}
maxFill += Math.ceil(sum/capacity);
}
return maxFill; | } | const assert = require('node:assert');
function test() {
let candidate = max_fill;
assert.deepEqual(candidate([[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], 1),6);
assert.deepEqual(candidate([[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], 2),5);
assert.deepEqual(candidate([[0, 0, 0], [0, 0, 0]], 5),0);
assert.deepEqual(candidate([[1, 1, 1, 1], [1, 1, 1, 1]], 2),4);
assert.deepEqual(candidate([[1, 1, 1, 1], [1, 1, 1, 1]], 9),2);
}
test(); |
|
humaneval-HumanEval_151_double_the_difference.json-L16 | js | //Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// >>> double_the_difference([1, 3, 2, 0])
// 10
// >>> double_the_difference([-1, -2, 0])
// 0
// >>> double_the_difference([9, -2])
// 81
// >>> double_the_difference([0])
// 0
// If the input array is empty, return 0.
function double_the_difference(lst){
sum = 0;
for (var i = 0; i < lst.length; i++){
if(lst[i] % 2 == 1 && lst[i] > 0){ | }
}
return sum;
}
| sum += lst[i] ** 2; | const assert = require('node:assert');
function test() {
let candidate = double_the_difference;
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([5.0, 4.0]),25);
assert.deepEqual(candidate([0.1, 0.2, 0.3]),0);
assert.deepEqual(candidate([-10.0, -20.0, -30.0]),0);
assert.deepEqual(candidate([-1.0, -2.0, 8.0]),0);
assert.deepEqual(candidate([0.2, 3.0, 5.0]),34);
assert.deepEqual(candidate([-9.0, -7.0, -5.0, -3.0, -1.0, 1.0, 3.0, 5.0, 7.0, 9.0]),165);
}
test(); |
humaneval-HumanEval_160_do_algebra.json-L67 | js | //Given two arrays operator, and operand. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
function do_algebra(operator, operand){
let do_again;
let count = 0;
let temp;
let answer;
while(count < operator.length){
switch(operator[count]){
case '*':
operand[count] = operand[count] * operand[count + 1];
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
case '//':
operand[count] = Math.floor(operand[count] / operand[count + 1]);
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
case '**':
operand[count] = Math.pow(operand[count], operand[count + 1]);
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
default:
count++;
do_again = false;
}
}
answer = operand[0];
operand.splice(0, 1);
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; | } | 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_115_max_fill.json-L47 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// >>> maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)1l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)0l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l))))), (1l))
// (6l)
// Example 2:
// >>> maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)1l, (long)1l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)1l, (long)1l))))), (2l))
// (5l)
// Example 3:
// >>> maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l))))), (5l))
// (0l)
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
public static long maxFill(ArrayList<ArrayList<Long>> grid, long capacity) {
long count = 0l;
for (ArrayList<Long> well : grid) {
long level = 0l;
for (Long unit : well) {
if (unit == 1l) {
level += 1l;
}
}
long units = level / capacity;
if (level % capacity != 0l) {
units += 1l;
}
count += units;
}
return count;
} | } | }
public static void main(String[] args) {
assert(maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)1l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)0l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l))))), (1l)) == (6l));
assert(maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)1l, (long)1l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)1l, (long)1l, (long)1l))))), (2l)) == (5l));
assert(maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)0l, (long)0l, (long)0l))))), (5l)) == (0l));
assert(maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l))))), (2l)) == (4l));
assert(maxFill((new ArrayList<ArrayList<Long>>(Arrays.asList((ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l)), (ArrayList<Long>)new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)1l, (long)1l))))), (9l)) == (2l));
}
}
|
|
humaneval-HumanEval_119_match_parens.json-L25 | 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_42_incr_list.json-L12 | py | from typing import List
def incr_list(l: List[int]) -> List[int]:
"""Return list with elements incremented by 1.
>>> incr_list([1, 2, 3])
[2, 3, 4]
>>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123])
[6, 4, 6, 3, 4, 4, 10, 1, 124]
"""
res = []
for i in l: | return res
| res.append(i + 1) | def check(candidate):
assert candidate([]) == []
assert candidate([3, 2, 1]) == [4, 3, 2]
assert candidate([5, 2, 5, 2, 3, 3, 9, 0, 123]) == [6, 3, 6, 3, 4, 4, 10, 1, 124]
def test_check():
check(incr_list)
test_check()
|
humaneval-HumanEval_94_skjkasdkd.json-L57 | 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; | }
return output;
}
}
} | largestPrime /= 10; | }
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_49_modp.json-L13 | js | //Return 2^n modulo p (be aware of numerics).
// >>> modp(3, 5)
// 3
// >>> modp(1101, 101)
// 2
// >>> modp(0, 101)
// 1
// >>> modp(3, 11)
// 8
// >>> modp(100, 101)
// 1
function modp(n, p){
| while(n>0){
result = (result*2)%p;
n--;
}
return result;
}
| var result = 1; | const assert = require('node:assert');
function test() {
let candidate = modp;
assert.deepEqual(candidate(3, 5),3);
assert.deepEqual(candidate(1101, 101),2);
assert.deepEqual(candidate(0, 101),1);
assert.deepEqual(candidate(3, 11),8);
assert.deepEqual(candidate(100, 101),1);
assert.deepEqual(candidate(30, 5),4);
assert.deepEqual(candidate(31, 5),3);
}
test(); |
humaneval-HumanEval_161_solve.json-L31 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given a 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 { | }
} else {
sb.append(s.charAt(i));
}
}
if (letterNotFound) {
return sb.reverse().toString();
}
return sb.toString();
}
} | sb.append(Character.toUpperCase(s.charAt(i))); | }
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_13_greatest_common_divisor.json-L10 | py | def greatest_common_divisor(a: int, b: int) -> int:
""" Return a greatest common divisor of two integers a and b
>>> greatest_common_divisor(3, 5)
1
>>> greatest_common_divisor(25, 15)
5
"""
if a > b:
a, b = b, a | return b
return greatest_common_divisor(b % a, a)
| if a == 0: | def check(candidate):
assert candidate(3, 7) == 1
assert candidate(10, 15) == 5
assert candidate(49, 14) == 7
assert candidate(144, 60) == 12
def test_check():
check(greatest_common_divisor)
test_check()
|
humaneval-HumanEval_143_words_in_sentence.json-L31 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given a 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:
// >>> wordsInSentence(("This is a test"))
// ("is")
// Example 2:
// >>> wordsInSentence(("lets go for swimming"))
// ("go for")
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
public static String wordsInSentence(String sentence) {
StringBuilder ans = new StringBuilder();
String[] words = sentence.split(" ");
int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
boolean isPrime;
for (String word : words) {
isPrime = false;
for (int prime : primes) { | isPrime = true;
break;
}
}
if (isPrime) {
ans.append(word + " ");
}
}
if (ans.length() > 0) {
ans.deleteCharAt(ans.length() - 1);
}
return ans.toString();
}
} | if (word.length() == prime) { | }
public static void main(String[] args) {
assert(wordsInSentence(("This is a test")).equals(("is")));
assert(wordsInSentence(("lets go for swimming")).equals(("go for")));
assert(wordsInSentence(("there is no place available here")).equals(("there is no place")));
assert(wordsInSentence(("Hi I am Hussein")).equals(("Hi am Hussein")));
assert(wordsInSentence(("go for it")).equals(("go for it")));
assert(wordsInSentence(("here")).equals(("")));
assert(wordsInSentence(("here is")).equals(("is")));
}
}
|
humaneval-HumanEval_107_even_odd_palindrome.json-L25 | js | //Given a positive integer n, return an array that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// >>> even_odd_palindrome(3)
// [1, 2]
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// >>> even_odd_palindrome(12)
// [4, 6]
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned array has the number of even and odd integer palindromes respectively.
function even_odd_palindrome(n){
var pal = [];
var isPalindrome = function(x){
var y = x.toString().split('').reverse().join('');
return y == x;
}
for(var i = 1; i <= n; i++){
if(isPalindrome(i)){
pal.push(i); | }
var odd = 0;
var even = 0;
for(var i = 0; i < pal.length; i++){
if(pal[i] % 2 == 0){
even++;
}
else{
odd++;
}
}
return [even, odd];
} | } | const assert = require('node:assert');
function test() {
let candidate = even_odd_palindrome;
assert.deepEqual(candidate(123),[8, 13]);
assert.deepEqual(candidate(12),[4, 6]);
assert.deepEqual(candidate(3),[1, 2]);
assert.deepEqual(candidate(63),[6, 8]);
assert.deepEqual(candidate(25),[5, 6]);
assert.deepEqual(candidate(19),[4, 6]);
assert.deepEqual(candidate(9),[4, 5]);
assert.deepEqual(candidate(1),[0, 1]);
}
test(); |
humaneval-HumanEval_123_get_odd_collatz.json-L15 | js | //Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// >>> get_odd_collatz(5)
// [1, 5]
function get_odd_collatz(n){
| var odd_numbers = []
var odd_count = 0
collatz_sequence.push(n)
for(var i = 0; i < collatz_sequence.length; i++){
if(collatz_sequence[i]%2 == 0){
collatz_sequence.push(collatz_sequence[i]/2)
}
else if(collatz_sequence[i]%2 == 1){
collatz_sequence.push(collatz_sequence[i]*3+1)
}
if(collatz_sequence[i]%2 == 1){
odd_numbers.push(collatz_sequence[i])
odd_count += 1
}
if(collatz_sequence[i] == 1){
break
}
}
if(odd_count != 0){
odd_numbers.sort(function(a, b){return a-b})
return odd_numbers
}
else{
odd_numbers.push(1)
return odd_numbers
}
}
| var collatz_sequence = [] | const assert = require('node:assert');
function test() {
let candidate = get_odd_collatz;
assert.deepEqual(candidate(14),[1, 5, 7, 11, 13, 17]);
assert.deepEqual(candidate(5),[1, 5]);
assert.deepEqual(candidate(12),[1, 3, 5]);
assert.deepEqual(candidate(1),[1]);
}
test(); |