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_74_total_match.json-L36 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that accepts two array lists of strings and returns the array list that has
// total number of chars in the all strings of the array list less than the other array list.
// if the two array lists have the same number of chars, return the first array list.
// Examples
// >>> totalMatch((new ArrayList<String>(Arrays.asList())), (new ArrayList<String>(Arrays.asList())))
// (new ArrayList<String>(Arrays.asList()))
// >>> totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hI", (String)"Hi"))))
// (new ArrayList<String>(Arrays.asList((String)"hI", (String)"Hi")))
// >>> totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hi", (String)"hi", (String)"admin", (String)"project"))))
// (new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin")))
// >>> totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hI", (String)"hi", (String)"hi"))))
// (new ArrayList<String>(Arrays.asList((String)"hI", (String)"hi", (String)"hi")))
// >>> totalMatch((new ArrayList<String>(Arrays.asList((String)"4"))), (new ArrayList<String>(Arrays.asList((String)"1", (String)"2", (String)"3", (String)"4", (String)"5"))))
// (new ArrayList<String>(Arrays.asList((String)"4")))
public static ArrayList<String> totalMatch(ArrayList<String> lst1, ArrayList<String> lst2) {
int sum1 = 0;
int sum2 = 0;
for (String s : lst1) {
sum1 += s.length();
}
for (String s : lst2) {
sum2 += s.length();
}
if (sum1 <= sum2) {
return lst1;
} else {
return lst2; | }
} | } | }
public static void main(String[] args) {
assert(totalMatch((new ArrayList<String>(Arrays.asList())), (new ArrayList<String>(Arrays.asList()))).equals((new ArrayList<String>(Arrays.asList()))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hi", (String)"hi")))).equals((new ArrayList<String>(Arrays.asList((String)"hi", (String)"hi")))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hi", (String)"hi", (String)"admin", (String)"project")))).equals((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin")))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"4"))), (new ArrayList<String>(Arrays.asList((String)"1", (String)"2", (String)"3", (String)"4", (String)"5")))).equals((new ArrayList<String>(Arrays.asList((String)"4")))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hI", (String)"Hi")))).equals((new ArrayList<String>(Arrays.asList((String)"hI", (String)"Hi")))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hI", (String)"hi", (String)"hi")))).equals((new ArrayList<String>(Arrays.asList((String)"hI", (String)"hi", (String)"hi")))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hI", (String)"hi", (String)"hii")))).equals((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin")))));
assert(totalMatch((new ArrayList<String>(Arrays.asList())), (new ArrayList<String>(Arrays.asList((String)"this")))).equals((new ArrayList<String>(Arrays.asList()))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"this"))), (new ArrayList<String>(Arrays.asList()))).equals((new ArrayList<String>(Arrays.asList()))));
}
}
|
humaneval-HumanEval_26_remove_duplicates.json-L14 | 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) {
| for (int i = 0; i < numbers.size(); i++) {
Long key = numbers.get(i);
if (hashmap.containsKey(key)) {
hashmap.put(key, hashmap.get(key) + 1);
} else {
hashmap.put(key, 1L);
}
}
ArrayList<Long> out = new ArrayList<Long>();
for (int i = 0; i < numbers.size(); i++) {
Long key = numbers.get(i);
if (hashmap.get(key) == 1) {
out.add(key);
}
}
return out;
}
} | HashMap<Long, Long> hashmap = new HashMap<Long, Long>(); | }
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_117_select_words.json-L21 | py | from typing import List
def select_words(s: str, n: int) -> List[str]:
"""Given a string s and a natural number n, you have been tasked to implement
a function that returns a list of all words from string s that contain exactly
n consonants, in order these words appear in the string s.
If the string s is empty then the function should return an empty list.
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']
"""
| words = s.split()
result = []
for word in words:
count = 0
for char in word:
if char.lower() in CONSONANTS:
count += 1
if count == n:
result.append(word)
return result
| CONSONANTS = 'bcdfghjklmnpqrstvwxyz' | def check(candidate):
assert candidate('Mary had a little lamb', 4) == ['little']
assert candidate('Mary had a little lamb', 3) == ['Mary', 'lamb']
assert candidate('simple white space', 2) == []
assert candidate('Hello world', 4) == ['world']
assert candidate('Uncle sam', 3) == ['Uncle']
assert candidate('', 4) == []
assert candidate('a b c d e f', 1) == ['b', 'c', 'd', 'f']
def test_check():
check(select_words)
test_check()
|
humaneval-HumanEval_128_prod_signs.json-L14 | js | //You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return undefined for empty arr.
// Example:
// >>> prod_signs([1, 2, 2, -4])
// 9
// >>> prod_signs([0, 1])
// 0
// >>> prod_signs([])
// undefined
function prod_signs(arr){
var total = 0; | var pro = 1;
if(len == 0){
return undefined;
}
else{
for(var i = 0; i < len; i++){
total += Math.abs(arr[i]);
if(arr[i] < 0){
pro *= -1;
}
else if(arr[i] == 0){
pro *= 0;
}
}
total *= pro;
return total;
}
}
| var len = arr.length; | const assert = require('node:assert');
function test() {
let candidate = prod_signs;
assert.deepEqual(candidate([1, 2, 2, -4]),-9);
assert.deepEqual(candidate([0, 1]),0);
assert.deepEqual(candidate([1, 1, 1, 2, 3, -1, 1]),-10);
assert.deepEqual(candidate([]),undefined);
assert.deepEqual(candidate([2, 4, 1, 2, -1, -1, 9]),20);
assert.deepEqual(candidate([-1, 1, -1, 1]),4);
assert.deepEqual(candidate([-1, 1, 1, 1]),-4);
assert.deepEqual(candidate([-1, 1, 1, 0]),0);
}
test(); |
humaneval-HumanEval_0_has_close_elements.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 {
// Check if in given array list of numbers, are any two numbers closer to each other than
// given threshold.
// >>> hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f))), (0.5f))
// (false)
// >>> hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.8f, (float)3.0f, (float)4.0f, (float)5.0f, (float)2.0f))), (0.3f))
// (true)
public static boolean hasCloseElements(ArrayList<Float> numbers, float threshold) {
| for (int i = 0; i < numbers.size() - 1; i++) {
if (numbers.get(i+1) - numbers.get(i) < threshold) {
return true;
}
}
return false;
}
} | Collections.sort(numbers); | }
public static void main(String[] args) {
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.9f, (float)4.0f, (float)5.0f, (float)2.2f))), (0.3f)) == (true));
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.9f, (float)4.0f, (float)5.0f, (float)2.2f))), (0.05f)) == (false));
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)5.9f, (float)4.0f, (float)5.0f))), (0.95f)) == (true));
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)5.9f, (float)4.0f, (float)5.0f))), (0.8f)) == (false));
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f, (float)4.0f, (float)5.0f, (float)2.0f))), (0.1f)) == (true));
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.1f, (float)2.2f, (float)3.1f, (float)4.1f, (float)5.1f))), (1.0f)) == (true));
assert(hasCloseElements((new ArrayList<Float>(Arrays.asList((float)1.1f, (float)2.2f, (float)3.1f, (float)4.1f, (float)5.1f))), (0.5f)) == (false));
}
}
|
humaneval-HumanEval_126_is_sorted.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 {
// Given an array array list of numbers, return whether or not they are sorted
// in ascending order. If array list has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l))))
// (false)
public static boolean isSorted(ArrayList<Long> lst) {
if (lst.size() == 0) {
return true;
} | int running_max = 0;
int previous_number = 0;
boolean first_time = true;
boolean seen_2_in_a_row = false;
for (Long number : lst) {
if (first_time) {
first_time = false;
previous_number = number.intValue();
running_max = number.intValue();
}
else {
if (running_max > number.intValue()) {
return false;
}
else {
if (previous_number == number.intValue()) {
if (seen_2_in_a_row) {
return false;
}
else {
seen_2_in_a_row = true;
}
}
else {
seen_2_in_a_row = false;
}
previous_number = number.intValue();
running_max = number.intValue();
}
}
}
return true;
}
}
} | else { | }
public static void main(String[] args) {
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)5l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList()))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)1l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)3l, (long)3l, (long)4l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))) == (true));
}
}
|
humaneval-HumanEval_5_intersperse.json-L10 | py | from typing import List
def intersperse(numbers: List[int], delimeter: int) -> List[int]:
""" Insert a number 'delimeter' between every two consecutive elements of input list `numbers'
>>> intersperse([], 4)
[]
>>> intersperse([1, 2, 3], 4)
[1, 4, 2, 4, 3]
"""
| if len(numbers) == 0:
return result
result.append(numbers[0])
for num in numbers[1:]:
result.append(delimeter)
result.append(num)
return result
| result = [] | def check(candidate):
assert candidate([], 7) == []
assert candidate([5, 6, 3, 2], 8) == [5, 8, 6, 8, 3, 8, 2]
assert candidate([2, 2, 2], 2) == [2, 2, 2, 2, 2]
def test_check():
check(intersperse)
test_check()
|
humaneval-HumanEval_119_match_parens.json-L38 | 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_43_pairs_sum_to_zero.json-L19 | js | //pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// >>> pairs_sum_to_zero([1, 3, 5, 0])
// false
// >>> pairs_sum_to_zero([1, 3, -2, 1])
// false
// >>> pairs_sum_to_zero([1, 2, 3, 7])
// false
// >>> pairs_sum_to_zero([2, 4, -5, 3, 5, 7])
// true
// >>> pairs_sum_to_zero([1])
// false
function pairs_sum_to_zero(l){
var i = 0
while (i < l.length){
var j = i+1
while (j < l.length){ | return true
}
j = j + 1
}
i = i + 1
}
return false
}
| if ((l[i] + l[j]) === 0){ | const assert = require('node:assert');
function test() {
let candidate = pairs_sum_to_zero;
assert.deepEqual(candidate([1, 3, 5, 0]),false);
assert.deepEqual(candidate([1, 3, -2, 1]),false);
assert.deepEqual(candidate([1, 2, 3, 7]),false);
assert.deepEqual(candidate([2, 4, -5, 3, 5, 7]),true);
assert.deepEqual(candidate([1]),false);
assert.deepEqual(candidate([-3, 9, -1, 3, 2, 30]),true);
assert.deepEqual(candidate([-3, 9, -1, 3, 2, 31]),true);
assert.deepEqual(candidate([-3, 9, -1, 4, 2, 30]),false);
assert.deepEqual(candidate([-3, 9, -1, 4, 2, 31]),false);
}
test(); |
humaneval-HumanEval_139_special_factorial.json-L18 | js | //The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// >>> special_factorial(4)
// 288
// The function will receive an integer as input and should return the special
// factorial of this integer.
function special_factorial(n){
if (n > 0) {
let fact = 1;
for (let i = 1; i <= n; i++) {
fact *= i;
}
return fact * special_factorial(n - 1);
} else {
return 1; | }
| } | const assert = require('node:assert');
function test() {
let candidate = special_factorial;
assert.deepEqual(candidate(4),288);
assert.deepEqual(candidate(5),34560);
assert.deepEqual(candidate(7),125411328000);
assert.deepEqual(candidate(1),1);
}
test(); |
humaneval-HumanEval_59_largest_prime_factor.json-L25 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// >>> largestPrimeFactor((13195l))
// (29l)
// >>> largestPrimeFactor((2048l))
// (2l)
public static long largestPrimeFactor(long n) {
List<Long> primes = new ArrayList<>();
long x = n;
for (long i = 2; i * i <= x; i++) {
if (x % i == 0) {
primes.add(i);
x /= i;
i--;
}
}
if (x > 1) { | }
return primes.get(primes.size() - 1);
}
} | primes.add(x); | }
public static void main(String[] args) {
assert(largestPrimeFactor((15l)) == (5l));
assert(largestPrimeFactor((27l)) == (3l));
assert(largestPrimeFactor((63l)) == (7l));
assert(largestPrimeFactor((330l)) == (11l));
assert(largestPrimeFactor((13195l)) == (29l));
}
}
|
humaneval-HumanEval_113_odd_count.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 {
// Given an array array list of strings, where each string consists of only digits, return an array array list.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// >>> oddCount((new ArrayList<String>(Arrays.asList((String)"1234567"))))
// (new ArrayList<String>(Arrays.asList((String)"the number of odd elements 4n the str4ng 4 of the 4nput.")))
// >>> oddCount((new ArrayList<String>(Arrays.asList((String)"3", (String)"11111111"))))
// (new ArrayList<String>(Arrays.asList((String)"the number of odd elements 1n the str1ng 1 of the 1nput.", (String)"the number of odd elements 8n the str8ng 8 of the 8nput.")))
public static ArrayList<String> oddCount(ArrayList<String> lst) {
ArrayList<String> res = new ArrayList<String>();
for (int i = 0; i < lst.size(); i++) {
int count = 0;
for (int j = 0; j < lst.get(i).length(); j++) {
if (Integer.parseInt(lst.get(i).substring(j, j + 1)) % 2 == 1) {
count++;
}
}
res.add("the number of odd elements " + count + "n the str" + count + "ng " + count + " of the " + count + "nput.");
}
return res; | } | } | }
public static void main(String[] args) {
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"1234567")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 4n the str4ng 4 of the 4nput.")))));
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"3", (String)"11111111")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 1n the str1ng 1 of the 1nput.", (String)"the number of odd elements 8n the str8ng 8 of the 8nput.")))));
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"271", (String)"137", (String)"314")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 2n the str2ng 2 of the 2nput.", (String)"the number of odd elements 3n the str3ng 3 of the 3nput.", (String)"the number of odd elements 2n the str2ng 2 of the 2nput.")))));
}
}
|
humaneval-HumanEval_65_circular_shift.json-L19 | js | //Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// >>> circular_shift(12, 1)
// "21"
// >>> circular_shift(12, 2)
// "12"
function circular_shift(x, shift){
var str = x.toString();
var len = str.length;
var res = '';
if(len < shift){
for(var i = len-1; i >= 0; i--){
res += str[i];
}
}else{
res = str.substring(len-shift) + str.substring(0, len-shift);
} | }
| return res; | const assert = require('node:assert');
function test() {
let candidate = circular_shift;
assert.deepEqual(candidate(100, 2),"001");
assert.deepEqual(candidate(12, 2),"12");
assert.deepEqual(candidate(97, 8),"79");
assert.deepEqual(candidate(12, 1),"21");
assert.deepEqual(candidate(11, 101),"11");
}
test(); |
humaneval-HumanEval_61_correct_bracketing.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 {
// 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++;
} else {
balance--;
}
if (balance < 0) { | }
}
return balance == 0;
}
} | return false; | }
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_69_search.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 are given a non-empty array list of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array list.
// If no such a value exist, return -1.
// Examples:
// >>> search((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)2l, (long)2l, (long)3l, (long)1l))))
// (2l)
// >>> search((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)3l, (long)4l, (long)4l, (long)4l))))
// (3l)
// >>> search((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)4l, (long)4l, (long)4l))))
// (-1l)
public static long search(ArrayList<Long> lst) {
HashMap<Long, Long> map = new HashMap<Long, Long>();
Long max = (long)-1;
for (int i = 0; i < lst.size(); i++) {
long val = lst.get(i);
if (map.containsKey(val)) {
map.put(val, map.get(val) + 1);
} else {
map.put(val, (long)1);
}
if (map.get(val) >= val && val > max) {
max = val;
}
} | }
} | return max; | }
public static void main(String[] args) {
assert(search((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)5l, (long)5l, (long)1l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)4l, (long)1l, (long)4l, (long)4l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)3l, (long)3l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)8l, (long)8l, (long)8l, (long)8l, (long)8l, (long)8l, (long)8l, (long)8l)))) == (8l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)3l, (long)2l, (long)2l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)7l, (long)8l, (long)8l, (long)4l, (long)8l, (long)7l, (long)3l, (long)9l, (long)6l, (long)5l, (long)10l, (long)4l, (long)3l, (long)6l, (long)7l, (long)1l, (long)7l, (long)4l, (long)10l, (long)8l, (long)1l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)8l, (long)2l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)6l, (long)7l, (long)1l, (long)8l, (long)8l, (long)10l, (long)5l, (long)8l, (long)5l, (long)3l, (long)10l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)8l, (long)8l, (long)3l, (long)6l, (long)5l, (long)6l, (long)4l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)6l, (long)9l, (long)6l, (long)7l, (long)1l, (long)4l, (long)7l, (long)1l, (long)8l, (long)8l, (long)9l, (long)8l, (long)10l, (long)10l, (long)8l, (long)4l, (long)10l, (long)4l, (long)10l, (long)1l, (long)2l, (long)9l, (long)5l, (long)7l, (long)9l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)1l, (long)9l, (long)10l, (long)1l, (long)3l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)6l, (long)9l, (long)7l, (long)5l, (long)8l, (long)7l, (long)5l, (long)3l, (long)7l, (long)5l, (long)10l, (long)10l, (long)3l, (long)6l, (long)10l, (long)2l, (long)8l, (long)6l, (long)5l, (long)4l, (long)9l, (long)5l, (long)3l, (long)10l)))) == (5l));
assert(search((new ArrayList<Long>(Arrays.asList((long)1l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)8l, (long)8l, (long)10l, (long)6l, (long)4l, (long)3l, (long)5l, (long)8l, (long)2l, (long)4l, (long)2l, (long)8l, (long)4l, (long)6l, (long)10l, (long)4l, (long)2l, (long)1l, (long)10l, (long)2l, (long)1l, (long)1l, (long)5l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)10l, (long)4l, (long)8l, (long)2l, (long)10l, (long)5l, (long)1l, (long)2l, (long)9l, (long)5l, (long)5l, (long)6l, (long)3l, (long)8l, (long)6l, (long)4l, (long)10l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)1l, (long)6l, (long)10l, (long)1l, (long)6l, (long)9l, (long)10l, (long)8l, (long)6l, (long)8l, (long)7l, (long)3l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)9l, (long)2l, (long)4l, (long)1l, (long)5l, (long)1l, (long)5l, (long)2l, (long)5l, (long)7l, (long)7l, (long)7l, (long)3l, (long)10l, (long)1l, (long)5l, (long)4l, (long)2l, (long)8l, (long)4l, (long)1l, (long)9l, (long)10l, (long)7l, (long)10l, (long)2l, (long)8l, (long)10l, (long)9l, (long)4l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)4l, (long)2l, (long)8l, (long)7l, (long)5l, (long)6l, (long)4l, (long)10l, (long)4l, (long)6l, (long)3l, (long)7l, (long)8l, (long)8l, (long)3l, (long)1l, (long)4l, (long)2l, (long)2l, (long)10l, (long)7l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)9l, (long)8l, (long)6l, (long)10l, (long)2l, (long)6l, (long)10l, (long)2l, (long)7l, (long)8l, (long)10l, (long)3l, (long)8l, (long)2l, (long)6l, (long)2l, (long)3l, (long)1l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)3l, (long)9l, (long)5l, (long)6l, (long)3l, (long)2l, (long)8l, (long)5l, (long)6l, (long)10l, (long)10l, (long)6l, (long)8l, (long)4l, (long)10l, (long)7l, (long)7l, (long)10l, (long)8l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)10l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)9l, (long)7l, (long)7l, (long)2l, (long)4l, (long)7l, (long)2l, (long)10l, (long)9l, (long)7l, (long)5l, (long)7l, (long)2l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)5l, (long)4l, (long)10l, (long)2l, (long)1l, (long)1l, (long)10l, (long)3l, (long)6l, (long)1l, (long)8l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)7l, (long)9l, (long)9l, (long)9l, (long)3l, (long)4l, (long)1l, (long)5l, (long)9l, (long)1l, (long)2l, (long)1l, (long)1l, (long)10l, (long)7l, (long)5l, (long)6l, (long)7l, (long)6l, (long)7l, (long)7l, (long)6l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)3l, (long)10l, (long)10l, (long)9l, (long)2l)))) == (-1l));
}
}
|
humaneval-HumanEval_11_string_xor.json-L11 | js | //Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// >>> string_xor("010", "110")
// "100"
function string_xor(a, b){
var arrayA = [];
var arrayB = [];
var arrayXOR = [];
var result = '';
for (var i = 0; i < a.length; i++) { | }
for (var j = 0; j < b.length; j++) {
arrayB.push(parseInt(b[j]));
}
for (var k = 0; k < arrayA.length; k++) {
if (arrayA[k] !== arrayB[k]) {
arrayXOR.push(1);
}
else {
arrayXOR.push(0);
}
}
result = arrayXOR.join('');
return result;
} | arrayA.push(parseInt(a[i])); | const assert = require('node:assert');
function test() {
let candidate = string_xor;
assert.deepEqual(candidate("111000", "101010"),"010010");
assert.deepEqual(candidate("1", "1"),"0");
assert.deepEqual(candidate("0101", "0000"),"0101");
}
test(); |
humaneval-HumanEval_123_get_odd_collatz.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 {
// Given a positive integer n, return a sorted array list 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 list 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.
// >>> getOddCollatz((5l))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)5l)))
public static ArrayList<Long> getOddCollatz(long n) {
if (n <= 0) return new ArrayList<Long>();
HashSet<Long> odds = new HashSet<Long>();
long n1 = n;
while (n1 > 1) {
if (n1 % 2 == 1) odds.add(n1);
n1 = n1 % 2 == 0 ? n1 / 2 : 3 * n1 + 1;
}
odds.add(1l);
Long[] odds_arr = odds.toArray(new Long[odds.size()]);
ArrayList<Long> ans = new ArrayList<Long>(Arrays.asList(odds_arr));
Collections.sort(ans); | }
} | return ans; | }
public static void main(String[] args) {
assert(getOddCollatz((14l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)7l, (long)11l, (long)13l, (long)17l)))));
assert(getOddCollatz((5l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l)))));
assert(getOddCollatz((12l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l)))));
assert(getOddCollatz((1l)).equals((new ArrayList<Long>(Arrays.asList((long)1l)))));
}
}
|
humaneval-HumanEval_141_file_name_check.json-L35 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// 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; | 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";
}
} | for (int i = 0; i < name.length(); i++) { | }
public static void main(String[] args) {
assert(fileNameCheck(("example.txt")).equals(("Yes")));
assert(fileNameCheck(("1example.dll")).equals(("No")));
assert(fileNameCheck(("s1sdf3.asd")).equals(("No")));
assert(fileNameCheck(("K.dll")).equals(("Yes")));
assert(fileNameCheck(("MY16FILE3.exe")).equals(("Yes")));
assert(fileNameCheck(("His12FILE94.exe")).equals(("No")));
assert(fileNameCheck(("_Y.txt")).equals(("No")));
assert(fileNameCheck(("?aREYA.exe")).equals(("No")));
assert(fileNameCheck(("/this_is_valid.dll")).equals(("No")));
assert(fileNameCheck(("this_is_valid.wow")).equals(("No")));
assert(fileNameCheck(("this_is_valid.txt")).equals(("Yes")));
assert(fileNameCheck(("this_is_valid.txtexe")).equals(("No")));
assert(fileNameCheck(("#this2_i4s_5valid.ten")).equals(("No")));
assert(fileNameCheck(("@this1_is6_valid.exe")).equals(("No")));
assert(fileNameCheck(("this_is_12valid.6exe4.txt")).equals(("No")));
assert(fileNameCheck(("all.exe.txt")).equals(("No")));
assert(fileNameCheck(("I563_No.exe")).equals(("Yes")));
assert(fileNameCheck(("Is3youfault.txt")).equals(("Yes")));
assert(fileNameCheck(("no_one#knows.dll")).equals(("Yes")));
assert(fileNameCheck(("1I563_Yes3.exe")).equals(("No")));
assert(fileNameCheck(("I563_Yes3.txtt")).equals(("No")));
assert(fileNameCheck(("final..txt")).equals(("No")));
assert(fileNameCheck(("final132")).equals(("No")));
assert(fileNameCheck(("_f4indsartal132.")).equals(("No")));
assert(fileNameCheck((".txt")).equals(("No")));
assert(fileNameCheck(("s.")).equals(("No")));
}
}
|
humaneval-HumanEval_73_smallest_change.json-L24 | py | from typing import List
def smallest_change(arr: List[int]) -> int:
"""
Given an array arr of integers, find the minimum number of elements that
need to be changed to make the array palindromic. A palindromic array is an array that
is read the same backwards and forwards. In one change, you can change one element to any other element.
For example:
>>> smallest_change([1, 2, 3, 5, 4, 7, 9, 6])
4
>>> smallest_change([1, 2, 3, 4, 3, 2, 2])
1
>>> smallest_change([1, 2, 3, 2, 1])
0
"""
start = 0
end = len(arr) - 1
count = 0
while start < end:
if arr[start] != arr[end]:
count += 1
start += 1 | return count
| end -= 1 | def check(candidate):
assert candidate([1, 2, 3, 5, 4, 7, 9, 6]) == 4
assert candidate([1, 2, 3, 4, 3, 2, 2]) == 1
assert candidate([1, 4, 2]) == 1
assert candidate([1, 4, 4, 2]) == 1
assert candidate([1, 2, 3, 2, 1]) == 0
assert candidate([3, 1, 1, 3]) == 0
assert candidate([1]) == 0
assert candidate([0, 1]) == 1
def test_check():
check(smallest_change)
test_check()
|
humaneval-HumanEval_156_int_to_mini_roman.json-L33 | 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){ | number -= key_list[i];
break;
}
}
}
return output;
}
| output += roman_conversion[key_list[i]]; | 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_91_is_bored.json-L17 | 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_64_vowels_count.json-L17 | js | //Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// >>> vowels_count("abcde")
// 2
// >>> vowels_count("ACEDY")
// 3
function vowels_count(s){
s=s.toLowerCase();
var vowels = ['a','e','i','o','u'];
var count = 0;
for(var i=0; i<s.length; i++){
if(vowels.indexOf(s[i])!=-1){
count++; | }
if(s[s.length-1]=='y'){
count++;
}
return count;
}
| } | const assert = require('node:assert');
function test() {
let candidate = vowels_count;
assert.deepEqual(candidate("abcde"),2);
assert.deepEqual(candidate("Alone"),3);
assert.deepEqual(candidate("key"),2);
assert.deepEqual(candidate("bye"),1);
assert.deepEqual(candidate("keY"),2);
assert.deepEqual(candidate("bYe"),1);
assert.deepEqual(candidate("ACEDY"),3);
}
test(); |
humaneval-HumanEval_133_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 {
// You are given an array array list of numbers.
// You need to return the sum of squared numbers in the given array list,
// round each element in the array list to the upper int(Ceiling) first.
// Examples:
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f))))
// (14l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)4.0f, (float)9.0f))))
// (98l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)3.0f, (float)5.0f, (float)7.0f))))
// (84l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.4f, (float)4.2f, (float)0.0f))))
// (29l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)-2.4f, (float)1.0f, (float)1.0f))))
// (6l)
public static long sumSquares(ArrayList<Float> lst) {
if (lst.size() == 0) {
return 0;
}
long sum = 0;
for (int i = 0; i < lst.size(); i++) {
sum += (long)Math.ceil(lst.get(i)) * (long)Math.ceil(lst.get(i)); | return sum;
}
} | } | }
public static void main(String[] args) {
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f)))) == (14l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f)))) == (14l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)3.0f, (float)5.0f, (float)7.0f)))) == (84l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.4f, (float)4.2f, (float)0.0f)))) == (29l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-2.4f, (float)1.0f, (float)1.0f)))) == (6l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)100.0f, (float)1.0f, (float)15.0f, (float)2.0f)))) == (10230l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)10000.0f, (float)10000.0f)))) == (200000000l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.4f, (float)4.6f, (float)6.3f)))) == (75l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.4f, (float)17.9f, (float)18.9f, (float)19.9f)))) == (1086l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)0.0f)))) == (0l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.0f)))) == (1l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.0f, (float)1.0f, (float)0.0f)))) == (2l));
}
}
|
humaneval-HumanEval_123_get_odd_collatz.json-L29 | py | from typing import List
def get_odd_collatz(n: int) -> List[int]:
"""
Given a positive integer n, return a sorted list 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 list 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]
"""
collatz_list = []
current_num = n
while (current_num > 1):
collatz_list.append(current_num)
if (current_num % 2 == 0):
current_num = current_num // 2
else: | collatz_list.append(1)
return sorted(list(set([x for x in collatz_list if x % 2 != 0])))
| current_num = current_num * 3 + 1 | def check(candidate):
assert candidate(14) == [1, 5, 7, 11, 13, 17]
assert candidate(5) == [1, 5]
assert candidate(12) == [1, 3, 5]
assert candidate(1) == [1]
def test_check():
check(get_odd_collatz)
test_check()
|
humaneval-HumanEval_157_right_angle_triangle.json-L19 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// >>> rightAngleTriangle((3l), (4l), (5l))
// (true)
// >>> rightAngleTriangle((1l), (2l), (3l))
// (false)
public static boolean rightAngleTriangle(long a, long b, long c) {
| }
} | return a*a + b*b == c*c || b*b + c*c == a*a || c*c + a*a == b*b; | }
public static void main(String[] args) {
assert(rightAngleTriangle((3l), (4l), (5l)) == (true));
assert(rightAngleTriangle((1l), (2l), (3l)) == (false));
assert(rightAngleTriangle((10l), (6l), (8l)) == (true));
assert(rightAngleTriangle((2l), (2l), (2l)) == (false));
assert(rightAngleTriangle((7l), (24l), (25l)) == (true));
assert(rightAngleTriangle((10l), (5l), (7l)) == (false));
assert(rightAngleTriangle((5l), (12l), (13l)) == (true));
assert(rightAngleTriangle((15l), (8l), (17l)) == (true));
assert(rightAngleTriangle((48l), (55l), (73l)) == (true));
assert(rightAngleTriangle((1l), (1l), (1l)) == (false));
assert(rightAngleTriangle((2l), (2l), (10l)) == (false));
}
}
|
humaneval-HumanEval_128_prod_signs.json-L24 | js | //You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return undefined for empty arr.
// Example:
// >>> prod_signs([1, 2, 2, -4])
// 9
// >>> prod_signs([0, 1])
// 0
// >>> prod_signs([])
// undefined
function prod_signs(arr){
var total = 0;
var len = arr.length;
var pro = 1;
if(len == 0){
return undefined;
}
else{
for(var i = 0; i < len; i++){
total += Math.abs(arr[i]);
if(arr[i] < 0){
pro *= -1; | else if(arr[i] == 0){
pro *= 0;
}
}
total *= pro;
return total;
}
}
| } | const assert = require('node:assert');
function test() {
let candidate = prod_signs;
assert.deepEqual(candidate([1, 2, 2, -4]),-9);
assert.deepEqual(candidate([0, 1]),0);
assert.deepEqual(candidate([1, 1, 1, 2, 3, -1, 1]),-10);
assert.deepEqual(candidate([]),undefined);
assert.deepEqual(candidate([2, 4, 1, 2, -1, -1, 9]),20);
assert.deepEqual(candidate([-1, 1, -1, 1]),4);
assert.deepEqual(candidate([-1, 1, 1, 1]),-4);
assert.deepEqual(candidate([-1, 1, 1, 0]),0);
}
test(); |
humaneval-HumanEval_69_search.json-L28 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given a non-empty array list of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array list.
// If no such a value exist, return -1.
// Examples:
// >>> search((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)2l, (long)2l, (long)3l, (long)1l))))
// (2l)
// >>> search((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)3l, (long)4l, (long)4l, (long)4l))))
// (3l)
// >>> search((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)4l, (long)4l, (long)4l))))
// (-1l)
public static long search(ArrayList<Long> lst) {
HashMap<Long, Long> map = new HashMap<Long, Long>();
Long max = (long)-1;
for (int i = 0; i < lst.size(); i++) {
long val = lst.get(i);
if (map.containsKey(val)) {
map.put(val, map.get(val) + 1);
} else { | }
if (map.get(val) >= val && val > max) {
max = val;
}
}
return max;
}
} | map.put(val, (long)1); | }
public static void main(String[] args) {
assert(search((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)5l, (long)5l, (long)1l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l, (long)4l, (long)1l, (long)4l, (long)4l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)3l, (long)3l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)8l, (long)8l, (long)8l, (long)8l, (long)8l, (long)8l, (long)8l, (long)8l)))) == (8l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)3l, (long)2l, (long)2l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)7l, (long)8l, (long)8l, (long)4l, (long)8l, (long)7l, (long)3l, (long)9l, (long)6l, (long)5l, (long)10l, (long)4l, (long)3l, (long)6l, (long)7l, (long)1l, (long)7l, (long)4l, (long)10l, (long)8l, (long)1l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)8l, (long)2l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)6l, (long)7l, (long)1l, (long)8l, (long)8l, (long)10l, (long)5l, (long)8l, (long)5l, (long)3l, (long)10l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)8l, (long)8l, (long)3l, (long)6l, (long)5l, (long)6l, (long)4l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)6l, (long)9l, (long)6l, (long)7l, (long)1l, (long)4l, (long)7l, (long)1l, (long)8l, (long)8l, (long)9l, (long)8l, (long)10l, (long)10l, (long)8l, (long)4l, (long)10l, (long)4l, (long)10l, (long)1l, (long)2l, (long)9l, (long)5l, (long)7l, (long)9l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)1l, (long)9l, (long)10l, (long)1l, (long)3l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)6l, (long)9l, (long)7l, (long)5l, (long)8l, (long)7l, (long)5l, (long)3l, (long)7l, (long)5l, (long)10l, (long)10l, (long)3l, (long)6l, (long)10l, (long)2l, (long)8l, (long)6l, (long)5l, (long)4l, (long)9l, (long)5l, (long)3l, (long)10l)))) == (5l));
assert(search((new ArrayList<Long>(Arrays.asList((long)1l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)8l, (long)8l, (long)10l, (long)6l, (long)4l, (long)3l, (long)5l, (long)8l, (long)2l, (long)4l, (long)2l, (long)8l, (long)4l, (long)6l, (long)10l, (long)4l, (long)2l, (long)1l, (long)10l, (long)2l, (long)1l, (long)1l, (long)5l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)10l, (long)4l, (long)8l, (long)2l, (long)10l, (long)5l, (long)1l, (long)2l, (long)9l, (long)5l, (long)5l, (long)6l, (long)3l, (long)8l, (long)6l, (long)4l, (long)10l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)1l, (long)6l, (long)10l, (long)1l, (long)6l, (long)9l, (long)10l, (long)8l, (long)6l, (long)8l, (long)7l, (long)3l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)9l, (long)2l, (long)4l, (long)1l, (long)5l, (long)1l, (long)5l, (long)2l, (long)5l, (long)7l, (long)7l, (long)7l, (long)3l, (long)10l, (long)1l, (long)5l, (long)4l, (long)2l, (long)8l, (long)4l, (long)1l, (long)9l, (long)10l, (long)7l, (long)10l, (long)2l, (long)8l, (long)10l, (long)9l, (long)4l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)4l, (long)2l, (long)8l, (long)7l, (long)5l, (long)6l, (long)4l, (long)10l, (long)4l, (long)6l, (long)3l, (long)7l, (long)8l, (long)8l, (long)3l, (long)1l, (long)4l, (long)2l, (long)2l, (long)10l, (long)7l)))) == (4l));
assert(search((new ArrayList<Long>(Arrays.asList((long)9l, (long)8l, (long)6l, (long)10l, (long)2l, (long)6l, (long)10l, (long)2l, (long)7l, (long)8l, (long)10l, (long)3l, (long)8l, (long)2l, (long)6l, (long)2l, (long)3l, (long)1l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)5l, (long)5l, (long)3l, (long)9l, (long)5l, (long)6l, (long)3l, (long)2l, (long)8l, (long)5l, (long)6l, (long)10l, (long)10l, (long)6l, (long)8l, (long)4l, (long)10l, (long)7l, (long)7l, (long)10l, (long)8l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)10l)))) == (-1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)9l, (long)7l, (long)7l, (long)2l, (long)4l, (long)7l, (long)2l, (long)10l, (long)9l, (long)7l, (long)5l, (long)7l, (long)2l)))) == (2l));
assert(search((new ArrayList<Long>(Arrays.asList((long)5l, (long)4l, (long)10l, (long)2l, (long)1l, (long)1l, (long)10l, (long)3l, (long)6l, (long)1l, (long)8l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)7l, (long)9l, (long)9l, (long)9l, (long)3l, (long)4l, (long)1l, (long)5l, (long)9l, (long)1l, (long)2l, (long)1l, (long)1l, (long)10l, (long)7l, (long)5l, (long)6l, (long)7l, (long)6l, (long)7l, (long)7l, (long)6l)))) == (1l));
assert(search((new ArrayList<Long>(Arrays.asList((long)3l, (long)10l, (long)10l, (long)9l, (long)2l)))) == (-1l));
}
}
|
humaneval-HumanEval_15_string_sequence.json-L7 | js | //Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// >>> string_sequence(0)
// "0"
// >>> string_sequence(5)
// "0 1 2 3 4 5"
function string_sequence(n){
| for(let i = 0; i <= n; i++){
arr.push(i);
}
return arr.join(" ");
}
| let arr = []; | const assert = require('node:assert');
function test() {
let candidate = string_sequence;
assert.deepEqual(candidate(0),"0");
assert.deepEqual(candidate(3),"0 1 2 3");
assert.deepEqual(candidate(10),"0 1 2 3 4 5 6 7 8 9 10");
}
test(); |
humaneval-HumanEval_80_is_happy.json-L25 | 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
else:
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 True
| return False | 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_119_match_parens.json-L26 | 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;
} | }
}
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';
} | stack.pop(); | 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_141_file_name_check.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 {
// 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))) {
count++;
}
}
if (count > 3) { | }
if (name.length() == 0) {
return result;
}
if (!Character.isLetter(name.charAt(0))) {
return result;
}
return "Yes";
}
} | return result; | }
public static void main(String[] args) {
assert(fileNameCheck(("example.txt")).equals(("Yes")));
assert(fileNameCheck(("1example.dll")).equals(("No")));
assert(fileNameCheck(("s1sdf3.asd")).equals(("No")));
assert(fileNameCheck(("K.dll")).equals(("Yes")));
assert(fileNameCheck(("MY16FILE3.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_156_int_to_mini_roman.json-L77 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// >>> intToMiniRoman((19l))
// ("xix")
// >>> intToMiniRoman((152l))
// ("clii")
// >>> intToMiniRoman((426l))
// ("cdxxvi")
public static String intToMiniRoman(long number) {
int num = (int) number;
String res = "";
if (num == 0)
return "";
while (num >= 1000) {
res += "m";
num -= 1000;
}
if (num >= 900) {
res += "cm";
num -= 900;
}
if (num >= 500) {
res += "d";
num -= 500;
}
if (num >= 400) {
res += "cd";
num -= 400;
}
while (num >= 100) {
res += "c";
num -= 100;
}
if (num >= 90) {
res += "xc";
num -= 90;
}
if (num >= 50) {
res += "l";
num -= 50;
}
if (num >= 40) {
res += "xl";
num -= 40;
}
while (num >= 10) {
res += "x";
num -= 10;
}
if (num >= 9) {
res += "ix";
num -= 9;
}
if (num >= 5) {
res += "v";
num -= 5;
}
if (num >= 4) {
res += "iv";
num -= 4;
}
while (num >= 1) {
res += "i";
num -= 1;
}
return res; | } | } | }
public static void main(String[] args) {
assert(intToMiniRoman((19l)).equals(("xix")));
assert(intToMiniRoman((152l)).equals(("clii")));
assert(intToMiniRoman((251l)).equals(("ccli")));
assert(intToMiniRoman((426l)).equals(("cdxxvi")));
assert(intToMiniRoman((500l)).equals(("d")));
assert(intToMiniRoman((1l)).equals(("i")));
assert(intToMiniRoman((4l)).equals(("iv")));
assert(intToMiniRoman((43l)).equals(("xliii")));
assert(intToMiniRoman((90l)).equals(("xc")));
assert(intToMiniRoman((94l)).equals(("xciv")));
assert(intToMiniRoman((532l)).equals(("dxxxii")));
assert(intToMiniRoman((900l)).equals(("cm")));
assert(intToMiniRoman((994l)).equals(("cmxciv")));
assert(intToMiniRoman((1000l)).equals(("m")));
}
}
|
humaneval-HumanEval_30_get_positive.json-L12 | py | from typing import List
def get_positive(l: List[int]) -> List[int]:
"""Return only positive numbers in the list.
>>> get_positive([-1, 2, -4, 5, 6])
[2, 5, 6]
>>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
[5, 3, 2, 3, 9, 123, 1]
"""
p = []
for i in l: | p.append(i)
return p
| if i > 0: | def check(candidate):
assert candidate([-1, -2, 4, 5, 6]) == [4, 5, 6]
assert candidate([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 3, 9, 123, 1]
assert candidate([-1, -2]) == []
assert candidate([]) == []
def test_check():
check(get_positive)
test_check()
|
humaneval-HumanEval_129_minPath.json-L72 | js | //Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// >>> minPath([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3)
// [1, 2, 1]
// >>> minPath([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1)
// [1]
function minPath(grid, k){
let n = grid.length;
let path = [];
let startCell = grid[0][0];
for(let i = 0; i < n; i++){
for(let j = 0; j < n; j++){
let curr = grid[i][j];
if(curr < startCell){
startCell = curr;
}
}
}
let currCell = startCell;
for(let l = 0; l < k; l++){
path.push(currCell);
let neighbours = [];
let x = null;
let y = null;
for(let i = 0; i < n; i++){
for(let j = 0; j < n; j++){
if(grid[i][j] === currCell){
x = i;
y = j;
}
}
}
if(x > 0){
neighbours.push(grid[x - 1][y]);
}
if(x < n - 1){
neighbours.push(grid[x + 1][y]);
}
if(y > 0){
neighbours.push(grid[x][y - 1]);
}
if(y < n - 1){
neighbours.push(grid[x][y + 1]);
}
let nextCell = neighbours[0];
for(let i = 0; i < neighbours.length; i++){
let curr = neighbours[i];
if(curr < nextCell){
nextCell = curr;
}
}
currCell = nextCell;
}
return path; | } | const assert = require('node:assert');
function test() {
let candidate = minPath;
assert.deepEqual(candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3),[1, 2, 1]);
assert.deepEqual(candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1),[1]);
assert.deepEqual(candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], 4),[1, 2, 1, 2]);
assert.deepEqual(candidate([[6, 4, 13, 10], [5, 7, 12, 1], [3, 16, 11, 15], [8, 14, 9, 2]], 7),[1, 10, 1, 10, 1, 10, 1]);
assert.deepEqual(candidate([[8, 14, 9, 2], [6, 4, 13, 15], [5, 7, 1, 12], [3, 10, 11, 16]], 5),[1, 7, 1, 7, 1]);
assert.deepEqual(candidate([[11, 8, 7, 2], [5, 16, 14, 4], [9, 3, 15, 6], [12, 13, 10, 1]], 9),[1, 6, 1, 6, 1, 6, 1, 6, 1]);
assert.deepEqual(candidate([[12, 13, 10, 1], [9, 3, 15, 6], [5, 16, 14, 4], [11, 8, 7, 2]], 12),[1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6]);
assert.deepEqual(candidate([[2, 7, 4], [3, 1, 5], [6, 8, 9]], 8),[1, 3, 1, 3, 1, 3, 1, 3]);
assert.deepEqual(candidate([[6, 1, 5], [3, 8, 9], [2, 7, 4]], 8),[1, 5, 1, 5, 1, 5, 1, 5]);
assert.deepEqual(candidate([[1, 2], [3, 4]], 10),[1, 2, 1, 2, 1, 2, 1, 2, 1, 2]);
assert.deepEqual(candidate([[1, 3], [3, 2]], 10),[1, 3, 1, 3, 1, 3, 1, 3, 1, 3]);
}
test(); |
|
humaneval-HumanEval_65_circular_shift.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 {
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// >>> circularShift((12l), (1l))
// ("21")
// >>> circularShift((12l), (2l))
// ("12")
public static String circularShift(long x, long shift) {
String digits = String.valueOf(x);
if (shift > digits.length()) {
return new StringBuilder(digits).reverse().toString(); | return (digits.substring(digits.length() - (int)shift, digits.length()) + digits.substring(0, digits.length() - (int)shift));
}
} | } | }
public static void main(String[] args) {
assert(circularShift((100l), (2l)).equals(("001")));
assert(circularShift((12l), (2l)).equals(("12")));
assert(circularShift((97l), (8l)).equals(("79")));
assert(circularShift((12l), (1l)).equals(("21")));
assert(circularShift((11l), (101l)).equals(("11")));
}
}
|
humaneval-HumanEval_110_exchange.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 {
// In this problem, you will implement a function that takes two array lists of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array array list of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// >>> exchange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l))), (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l))))
// ("YES")
// >>> exchange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l))), (new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)3l, (long)4l))))
// ("NO")
// It is assumed that the input array lists will be non-empty.
public static String exchange(ArrayList<Long> lst1, ArrayList<Long> lst2) {
for (int i = 0; i < lst1.size(); i++) {
if (lst1.get(i) % 2 == 1) {
for (int j = 0; j < lst2.size(); j++) {
if (lst2.get(j) % 2 == 0) {
lst1.set(i, lst2.get(j));
lst2.set(j, (long) 1);
break;
}
}
}
} | }
} | return (lst1.stream().allMatch(x -> x % 2 == 0)) ? "YES" : "NO"; | }
public static void main(String[] args) {
assert(exchange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l))), (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))).equals(("YES")));
assert(exchange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l))), (new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)3l, (long)4l)))).equals(("NO")));
assert(exchange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l))), (new ArrayList<Long>(Arrays.asList((long)2l, (long)1l, (long)4l, (long)3l)))).equals(("YES")));
assert(exchange((new ArrayList<Long>(Arrays.asList((long)5l, (long)7l, (long)3l))), (new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)4l)))).equals(("YES")));
assert(exchange((new ArrayList<Long>(Arrays.asList((long)5l, (long)7l, (long)3l))), (new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l)))).equals(("NO")));
assert(exchange((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)6l, (long)1l, (long)8l, (long)9l))), (new ArrayList<Long>(Arrays.asList((long)3l, (long)5l, (long)5l, (long)1l, (long)1l, (long)1l)))).equals(("NO")));
assert(exchange((new ArrayList<Long>(Arrays.asList((long)100l, (long)200l))), (new ArrayList<Long>(Arrays.asList((long)200l, (long)200l)))).equals(("YES")));
}
}
|
humaneval-HumanEval_128_prod_signs.json-L16 | js | //You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return undefined for empty arr.
// Example:
// >>> prod_signs([1, 2, 2, -4])
// 9
// >>> prod_signs([0, 1])
// 0
// >>> prod_signs([])
// undefined
function prod_signs(arr){
var total = 0;
var len = arr.length;
var pro = 1; | return undefined;
}
else{
for(var i = 0; i < len; i++){
total += Math.abs(arr[i]);
if(arr[i] < 0){
pro *= -1;
}
else if(arr[i] == 0){
pro *= 0;
}
}
total *= pro;
return total;
}
}
| if(len == 0){ | const assert = require('node:assert');
function test() {
let candidate = prod_signs;
assert.deepEqual(candidate([1, 2, 2, -4]),-9);
assert.deepEqual(candidate([0, 1]),0);
assert.deepEqual(candidate([1, 1, 1, 2, 3, -1, 1]),-10);
assert.deepEqual(candidate([]),undefined);
assert.deepEqual(candidate([2, 4, 1, 2, -1, -1, 9]),20);
assert.deepEqual(candidate([-1, 1, -1, 1]),4);
assert.deepEqual(candidate([-1, 1, 1, 1]),-4);
assert.deepEqual(candidate([-1, 1, 1, 0]),0);
}
test(); |
humaneval-HumanEval_108_count_nums.json-L39 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function count_nums which takes an array array list of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// >>> countNums((new ArrayList<Long>(Arrays.asList())))
// (0l)
// >>> countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)11l, (long)-11l))))
// (1l)
// >>> countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l))))
// (3l)
public static long countNums(ArrayList<Long> arr) {
long result = 0l;
for (long i : arr) {
String str = String.valueOf(i);
int sum = 0;
if (str.startsWith("-")) {
sum = sum - (int) Character.getNumericValue(str.charAt(1));
for (int j = 2; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j));
}
} else {
for (int j = 0; j < str.length(); j++) {
sum = sum + (int) Character.getNumericValue(str.charAt(j));
}
}
if (sum > 0) {
result++;
}
}
return result; | } | } | }
public static void main(String[] args) {
assert(countNums((new ArrayList<Long>(Arrays.asList()))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)0l)))) == (0l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)1l, (long)2l, (long)-2l, (long)3l, (long)4l, (long)5l)))) == (6l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)6l, (long)9l, (long)-6l, (long)0l, (long)1l, (long)5l)))) == (5l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l, (long)100l, (long)98l, (long)-7l, (long)1l, (long)-1l)))) == (4l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)12l, (long)23l, (long)34l, (long)-45l, (long)-56l, (long)0l)))) == (5l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l)))) == (1l));
assert(countNums((new ArrayList<Long>(Arrays.asList((long)1l)))) == (1l));
}
}
|
humaneval-HumanEval_96_count_up_to.json-L29 | py | from typing import List
def count_up_to(n: int) -> List[int]:
"""Implement a function that takes an non-negative integer and returns an array of the first n
integers that are prime numbers and less than n.
for example:
>>> count_up_to(5)
[2, 3]
>>> count_up_to(11)
[2, 3, 5, 7]
>>> count_up_to(0)
[]
>>> count_up_to(20)
[2, 3, 5, 7, 11, 13, 17, 19]
>>> count_up_to(1)
[]
>>> count_up_to(18)
[2, 3, 5, 7, 11, 13, 17]
"""
if n <= 1:
return []
result = []
for number in range(2, n):
is_prime = True
for divisor in range(2, number):
if number % divisor == 0:
is_prime = False
break | result.append(number)
return result
| if is_prime: | def check(candidate):
assert candidate(5) == [2, 3]
assert candidate(6) == [2, 3, 5]
assert candidate(7) == [2, 3, 5]
assert candidate(10) == [2, 3, 5, 7]
assert candidate(0) == []
assert candidate(22) == [2, 3, 5, 7, 11, 13, 17, 19]
assert candidate(1) == []
assert candidate(18) == [2, 3, 5, 7, 11, 13, 17]
assert candidate(47) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]
assert candidate(101) == [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]
def test_check():
check(count_up_to)
test_check()
|
humaneval-HumanEval_10_make_palindrome.json-L22 | js | //Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// >>> make_palindrome("")
// ""
// >>> make_palindrome("cat")
// "catac"
// >>> make_palindrome("cata")
// "catac"
function make_palindrome(string){
var string_length = string.length;
var is_palindrome = function(s){
return s == s.split("").reverse().join("");
};
var i = string_length;
while(i > 0){
if(is_palindrome(string.substring(0, i))){
return string + string.substring(0, string_length - i).split("").reverse().join("");
}
i--; | return string;
}
| } | const assert = require('node:assert');
function test() {
let candidate = make_palindrome;
assert.deepEqual(candidate(""),"");
assert.deepEqual(candidate("x"),"x");
assert.deepEqual(candidate("xyz"),"xyzyx");
assert.deepEqual(candidate("xyx"),"xyx");
assert.deepEqual(candidate("jerry"),"jerryrrej");
}
test(); |
humaneval-HumanEval_44_change_base.json-L15 | py | def change_base(x: int, base: int) -> str:
"""Change numerical base of input number x to base.
return string representation after the conversion.
base numbers are less than 10.
>>> change_base(8, 3)
'22'
>>> change_base(8, 2)
'1000'
>>> change_base(7, 2)
'111'
"""
if x == 0:
return '0'
ans = [] | ans.append(str(x % base))
x //= base
return ''.join(ans[::-1])
| while x != 0: | def check(candidate):
assert candidate(8, 3) == '22'
assert candidate(9, 3) == '100'
assert candidate(234, 2) == '11101010'
assert candidate(16, 2) == '10000'
assert candidate(8, 2) == '1000'
assert candidate(7, 2) == '111'
assert candidate(2, 3) == '2'
assert candidate(3, 4) == '3'
assert candidate(4, 5) == '4'
assert candidate(5, 6) == '5'
assert candidate(6, 7) == '6'
assert candidate(7, 8) == '7'
def test_check():
check(change_base)
test_check()
|
humaneval-HumanEval_112_reverse_delete.json-L20 | 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 filter = s.split('').filter(x => c.includes(x) === false);
const filterString = filter.join('');
const filterStringReverse = filter.reverse().join('');
const result = [];
if (filterString === filterStringReverse) {
result.push(filterString, true); | result.push(filterString, false);
}
return result;
} | } else { | 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-L23 | 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]);
}
} | 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"]; | return result.sort(function(a, b){ | 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_113_odd_count.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of strings, where each string consists of only digits, return an array array list.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// >>> oddCount((new ArrayList<String>(Arrays.asList((String)"1234567"))))
// (new ArrayList<String>(Arrays.asList((String)"the number of odd elements 4n the str4ng 4 of the 4nput.")))
// >>> oddCount((new ArrayList<String>(Arrays.asList((String)"3", (String)"11111111"))))
// (new ArrayList<String>(Arrays.asList((String)"the number of odd elements 1n the str1ng 1 of the 1nput.", (String)"the number of odd elements 8n the str8ng 8 of the 8nput.")))
public static ArrayList<String> oddCount(ArrayList<String> lst) {
ArrayList<String> res = new ArrayList<String>();
for (int i = 0; i < lst.size(); i++) {
int count = 0;
for (int j = 0; j < lst.get(i).length(); j++) {
if (Integer.parseInt(lst.get(i).substring(j, j + 1)) % 2 == 1) {
count++; | }
res.add("the number of odd elements " + count + "n the str" + count + "ng " + count + " of the " + count + "nput.");
}
return res;
}
} | } | }
public static void main(String[] args) {
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"1234567")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 4n the str4ng 4 of the 4nput.")))));
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"3", (String)"11111111")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 1n the str1ng 1 of the 1nput.", (String)"the number of odd elements 8n the str8ng 8 of the 8nput.")))));
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"271", (String)"137", (String)"314")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 2n the str2ng 2 of the 2nput.", (String)"the number of odd elements 3n the str3ng 3 of the 3nput.", (String)"the number of odd elements 2n the str2ng 2 of the 2nput.")))));
}
}
|
humaneval-HumanEval_9_rolling_max.json-L10 | py | from typing import List
def rolling_max(numbers: List[int]) -> List[int]:
""" From a given list of integers, generate a list 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]
"""
if len(numbers) == 0: | else:
return [max(numbers[:i + 1]) for i in range(len(numbers))]
| return [] | def check(candidate):
assert candidate([]) == []
assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4]
assert candidate([4, 3, 2, 1]) == [4, 4, 4, 4]
assert candidate([3, 2, 3, 100, 3]) == [3, 3, 3, 100, 100]
def test_check():
check(rolling_max)
test_check()
|
humaneval-HumanEval_150_x_or_y.json-L9 | js | //A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// >>> x_or_y(7, 34, 12)
// 34
// >>> x_or_y(15, 8, 5)
// 5
function x_or_y(n, x, y){
| return y;
}
for(var i=2; i<n; i++){
if(n%i==0){
return y;
}
}
return x;
} | if(n<2){ | const assert = require('node:assert');
function test() {
let candidate = x_or_y;
assert.deepEqual(candidate(7, 34, 12),34);
assert.deepEqual(candidate(15, 8, 5),5);
assert.deepEqual(candidate(3, 33, 5212),33);
assert.deepEqual(candidate(1259, 3, 52),3);
assert.deepEqual(candidate(7919, -1, 12),-1);
assert.deepEqual(candidate(3609, 1245, 583),583);
assert.deepEqual(candidate(91, 56, 129),129);
assert.deepEqual(candidate(6, 34, 1234),1234);
assert.deepEqual(candidate(1, 2, 0),0);
assert.deepEqual(candidate(2, 2, 0),2);
}
test(); |
humaneval-HumanEval_108_count_nums.json-L12 | js | //Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// >>> count_nums([])
// 0
// >>> count_nums([-1, 11, -11])
// 1
// >>> count_nums([1, 1, 2])
// 3
function count_nums(arr){
| return 0;
}
var count = 0;
for(var i = 0; i < arr.length; i++) {
var sum = 0;
var str = arr[i].toString();
if(str[0] === '-') {
sum += Number(str[0] + str[1]);
for(var j = 2; j < str.length; j++) {
sum += Number(str[j]);
}
} else {
for(var k = 0; k < str.length; k++) {
sum += Number(str[k]);
}
}
if(sum > 0) {
count++;
}
}
return count;
} | if(!arr.length) { | const assert = require('node:assert');
function test() {
let candidate = count_nums;
assert.deepEqual(candidate([]),0);
assert.deepEqual(candidate([-1, -2, 0]),0);
assert.deepEqual(candidate([1, 1, 2, -2, 3, 4, 5]),6);
assert.deepEqual(candidate([1, 6, 9, -6, 0, 1, 5]),5);
assert.deepEqual(candidate([1, 100, 98, -7, 1, -1]),4);
assert.deepEqual(candidate([12, 23, 34, -45, -56, 0]),5);
assert.deepEqual(candidate([0, 1]),1);
assert.deepEqual(candidate([1]),1);
}
test(); |
humaneval-HumanEval_160_do_algebra.json-L33 | py | from typing import List
def do_algebra(operator: List[str], operand: List[int]) -> int:
"""
Given two lists operator, and operand. The first list has basic algebra operations, and
the second list is a list of integers. Use the two given lists to build the algebric
expression and return the evaluation of this expression.
The basic algebra operations:
Addition ( + )
Subtraction ( - )
Multiplication ( * )
Floor division ( // )
Exponentiation ( ** )
Example:
operator['+', '*', '-']
array = [2, 3, 4, 5]
result = 2 + 3 * 4 - 5
=> result = 9
Note:
The length of operator list is equal to the length of operand list minus one.
Operand is a list of of non-negative integers.
Operator list has at least one operator, and operand list has at least two operands.
"""
if len(operator) != len(operand) - 1:
raise ValueError("Invalid number of operators")
expr = [str(operand[0])]
for idx, op in enumerate(operator):
expr.append(op) | return eval("".join(expr)) | expr.append(str(operand[idx + 1])) | def check(candidate):
assert candidate(['**', '*', '+'], [2, 3, 4, 5]) == 37
assert candidate(['+', '*', '-'], [2, 3, 4, 5]) == 9
assert candidate(['//', '*'], [7, 3, 4]) == 8
def test_check():
check(do_algebra)
test_check()
|
humaneval-HumanEval_17_parse_music.json-L13 | 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 songs = music_string.split(' ');
let song = []; | if(s === 'o'){
song.push(4);
}else if(s === 'o|'){
song.push(2);
}else if(s === '.|'){
song.push(1);
}
});
return song;
}
| songs.forEach(s => { | 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_36_fizz_buzz.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 {
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// >>> fizzBuzz((50l))
// (0l)
// >>> fizzBuzz((78l))
// (2l)
// >>> fizzBuzz((79l))
// (3l)
public static long fizzBuzz(long n) {
long res = 0;
for (long i = 0; i < n; i++) {
if (i % 11 == 0 || i % 13 == 0) {
String s = String.valueOf(i);
for (int j = 0; j < s.length(); j++) {
if (s.charAt(j) == '7') {
res++;
}
}
}
}
return res;
} | } | }
public static void main(String[] args) {
assert(fizzBuzz((50l)) == (0l));
assert(fizzBuzz((78l)) == (2l));
assert(fizzBuzz((79l)) == (3l));
assert(fizzBuzz((100l)) == (3l));
assert(fizzBuzz((200l)) == (6l));
assert(fizzBuzz((4000l)) == (192l));
assert(fizzBuzz((10000l)) == (639l));
assert(fizzBuzz((100000l)) == (8026l));
}
}
|
|
humaneval-HumanEval_71_triangle_area.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 the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// >>> triangleArea((3l), (4l), (5l))
// (6.0f)
// >>> triangleArea((1l), (2l), (10l))
// (float)-1l
public static float triangleArea(long a, long b, long c) {
if(a + b > c && a + c > b && b + c > a) { | float area = (float)Math.sqrt(s * (s - a) * (s - b) * (s - c));
return (float)Math.round(area * 100) / 100;
}
return -1;
}
} | float s = (a + b + c) / 2.0f; | }
public static void main(String[] args) {
assert(triangleArea((3l), (4l), (5l)) == (6.0f));
assert(triangleArea((1l), (2l), (10l)) == (float)-1l);
assert(triangleArea((4l), (8l), (5l)) == (8.18f));
assert(triangleArea((2l), (2l), (2l)) == (1.73f));
assert(triangleArea((1l), (2l), (3l)) == (float)-1l);
assert(triangleArea((10l), (5l), (7l)) == (16.25f));
assert(triangleArea((2l), (6l), (3l)) == (float)-1l);
assert(triangleArea((1l), (1l), (1l)) == (0.43f));
assert(triangleArea((2l), (2l), (10l)) == (float)-1l);
}
}
|
humaneval-HumanEval_113_odd_count.json-L19 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of strings, where each string consists of only digits, return an array array list.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// >>> oddCount((new ArrayList<String>(Arrays.asList((String)"1234567"))))
// (new ArrayList<String>(Arrays.asList((String)"the number of odd elements 4n the str4ng 4 of the 4nput.")))
// >>> oddCount((new ArrayList<String>(Arrays.asList((String)"3", (String)"11111111"))))
// (new ArrayList<String>(Arrays.asList((String)"the number of odd elements 1n the str1ng 1 of the 1nput.", (String)"the number of odd elements 8n the str8ng 8 of the 8nput.")))
public static ArrayList<String> oddCount(ArrayList<String> lst) {
ArrayList<String> res = new ArrayList<String>(); | int count = 0;
for (int j = 0; j < lst.get(i).length(); j++) {
if (Integer.parseInt(lst.get(i).substring(j, j + 1)) % 2 == 1) {
count++;
}
}
res.add("the number of odd elements " + count + "n the str" + count + "ng " + count + " of the " + count + "nput.");
}
return res;
}
} | for (int i = 0; i < lst.size(); i++) { | }
public static void main(String[] args) {
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"1234567")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 4n the str4ng 4 of the 4nput.")))));
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"3", (String)"11111111")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 1n the str1ng 1 of the 1nput.", (String)"the number of odd elements 8n the str8ng 8 of the 8nput.")))));
assert(oddCount((new ArrayList<String>(Arrays.asList((String)"271", (String)"137", (String)"314")))).equals((new ArrayList<String>(Arrays.asList((String)"the number of odd elements 2n the str2ng 2 of the 2nput.", (String)"the number of odd elements 3n the str3ng 3 of the 3nput.", (String)"the number of odd elements 2n the str2ng 2 of the 2nput.")))));
}
}
|
humaneval-HumanEval_26_remove_duplicates.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 {
// 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)) {
hashmap.put(key, hashmap.get(key) + 1);
} else {
hashmap.put(key, 1L);
}
}
ArrayList<Long> out = new ArrayList<Long>();
for (int i = 0; i < numbers.size(); i++) {
Long key = numbers.get(i);
if (hashmap.get(key) == 1) {
out.add(key); | }
return out;
}
} | } | }
public static void main(String[] args) {
assert(removeDuplicates((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(removeDuplicates((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))).equals((new ArrayList<Long>(Arrays.asList((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_93_encode.json-L20 | py | def encode(message: str) -> str:
"""
Write a function that takes a message, and encodes in such a
way that it swaps case of all letters, replaces all vowels in
the message with the letter that appears 2 places ahead of that
vowel in the english alphabet.
Assume only letters.
Examples:
>>> encode('test')
'TGST'
>>> encode('This is a message')
'tHKS KS C MGSSCGG'
"""
def swap_case(ch: str) -> str:
if ch.isupper():
return ch.lower()
else:
return ch.upper() | if ch.lower() in 'aeiou':
if ch.lower() in 'wxyz':
return ch.lower()
return chr(ord(ch) + 2)
return ch
return ''.join(map(lambda ch: encode_vowel(swap_case(ch)), message))
| def encode_vowel(ch: str) -> str: | def check(candidate):
assert candidate('TEST') == 'tgst'
assert candidate('Mudasir') == 'mWDCSKR'
assert candidate('YES') == 'ygs'
assert candidate('This is a message') == 'tHKS KS C MGSSCGG'
assert candidate('I DoNt KnOw WhAt tO WrItE') == 'k dQnT kNqW wHcT Tq wRkTg'
def test_check():
check(encode)
test_check()
|
humaneval-HumanEval_83_starts_one_ends.json-L4 | js | //Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
function starts_one_ends(n){
| for(let i = Math.pow(10, n-1); i < Math.pow(10, n); i++){
if(i.toString().startsWith('1') || i.toString().endsWith('1')){
ones.push(i);
}
}
return ones.length;
} | let ones = []; | const assert = require('node:assert');
function test() {
let candidate = starts_one_ends;
assert.deepEqual(candidate(1),1);
assert.deepEqual(candidate(2),18);
assert.deepEqual(candidate(3),180);
assert.deepEqual(candidate(4),1800);
assert.deepEqual(candidate(5),18000);
}
test(); |
humaneval-HumanEval_39_prime_fib.json-L45 | js | //prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// >>> prime_fib(1)
// 2
// >>> prime_fib(2)
// 3
// >>> prime_fib(3)
// 5
// >>> prime_fib(4)
// 13
// >>> prime_fib(5)
// 89
function prime_fib(n){
function isPrime(number){
if(number <= 3){
return number > 1;
}
else if(number % 2 == 0 || number % 3 == 0){
return false;
}
else{
for(var i = 5; i * i <= number; i += 6){
if(number % i == 0 || number % (i + 2) == 0){
return false;
}
}
return true;
}
}
function fib(num){
var a = 1, b = 0, temp;
while (num >= 0){
temp = a;
a = a + b;
b = temp;
num--;
}
return b;
}
var res = 0;
var fibNum = 0;
while(res < n){
if(isPrime(fib(fibNum))){ | }
fibNum++;
}
return fib(fibNum - 1);
} | res++; | const assert = require('node:assert');
function test() {
let candidate = prime_fib;
assert.deepEqual(candidate(1),2);
assert.deepEqual(candidate(2),3);
assert.deepEqual(candidate(3),5);
assert.deepEqual(candidate(4),13);
assert.deepEqual(candidate(5),89);
assert.deepEqual(candidate(6),233);
assert.deepEqual(candidate(7),1597);
assert.deepEqual(candidate(8),28657);
assert.deepEqual(candidate(9),514229);
assert.deepEqual(candidate(10),433494437);
}
test(); |
humaneval-HumanEval_3_below_zero.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 {
// You're given an array array list of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// >>> belowZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (false)
// >>> belowZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)-4l, (long)5l))))
// (true)
public static boolean belowZero(ArrayList<Long> operations) {
long balance = 0;
for (long op : operations) { | if (balance < 0) {
return true;
}
}
return false;
}
} | balance += op; | }
public static void main(String[] args) {
assert(belowZero((new ArrayList<Long>(Arrays.asList()))) == (false));
assert(belowZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)-3l, (long)1l, (long)2l, (long)-3l)))) == (false));
assert(belowZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)-4l, (long)5l, (long)6l)))) == (true));
assert(belowZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)-1l, (long)2l, (long)-2l, (long)5l, (long)-5l, (long)4l, (long)-4l)))) == (false));
assert(belowZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)-1l, (long)2l, (long)-2l, (long)5l, (long)-5l, (long)4l, (long)-5l)))) == (true));
assert(belowZero((new ArrayList<Long>(Arrays.asList((long)1l, (long)-2l, (long)2l, (long)-2l, (long)5l, (long)-5l, (long)4l, (long)-4l)))) == (true));
}
}
|
humaneval-HumanEval_68_pluck.json-L35 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// "Given an array array list representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array array list, [ smalest_value, its index ],
// If there are no even values or the given array array list is empty, return [].
// Example 1:
// >>> pluck((new ArrayList<Long>(Arrays.asList((long)4l, (long)2l, (long)3l))))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)1l)))
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// >>> pluck((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)1l)))
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// >>> pluck((new ArrayList<Long>(Arrays.asList())))
// (new ArrayList<Long>(Arrays.asList()))
// Example 4:
// >>> pluck((new ArrayList<Long>(Arrays.asList((long)5l, (long)0l, (long)3l, (long)0l, (long)4l, (long)2l))))
// (new ArrayList<Long>(Arrays.asList((long)0l, (long)1l)))
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
public static ArrayList<Long> pluck(ArrayList<Long> arr) {
| long minValue = -1;
for (int i = 0; i < arr.size(); i++) {
if (arr.get(i) % 2 == 0) {
if (minIndex == -1 || arr.get(i) < minValue) {
minIndex = i;
minValue = arr.get(i);
}
}
}
ArrayList<Long> newArr = new ArrayList<Long>();
if (minIndex == -1) {
return newArr;
}
newArr.add(minValue);
newArr.add((long)minIndex);
return newArr;
}
} | int minIndex = -1; | }
public static void main(String[] args) {
assert(pluck((new ArrayList<Long>(Arrays.asList((long)4l, (long)2l, (long)3l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)1l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)1l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList()))).equals((new ArrayList<Long>(Arrays.asList()))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)5l, (long)0l, (long)3l, (long)0l, (long)4l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)0l, (long)5l, (long)3l)))).equals((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)5l, (long)4l, (long)8l, (long)4l, (long)8l)))).equals((new ArrayList<Long>(Arrays.asList((long)4l, (long)1l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)7l, (long)6l, (long)7l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)6l, (long)1l)))));
assert(pluck((new ArrayList<Long>(Arrays.asList((long)7l, (long)9l, (long)7l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList()))));
}
}
|
humaneval-HumanEval_141_file_name_check.json-L43 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// 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))) {
count++;
}
}
if (count > 3) {
return result;
} | return result;
}
if (!Character.isLetter(name.charAt(0))) {
return result;
}
return "Yes";
}
} | if (name.length() == 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_77_iscube.json-L26 | py | def iscube(a: int) -> bool:
"""
Write a function that takes an integer a and returns True
if this ingeger is a cube of some integer number.
Note: you may assume the input is always valid.
Examples:
>>> iscube(1)
True
>>> iscube(2)
False
>>> iscube(-1)
True
>>> iscube(64)
True
>>> iscube(0)
True
>>> iscube(180)
False
"""
import math
a = abs(a)
if a == 0:
return True
for i in range(1,int(math.sqrt(a))+1):
if i**3 == a: | return False
pass
| return True | def check(candidate):
assert candidate(1) == True
assert candidate(2) == False
assert candidate(-1) == True
assert candidate(64) == True
assert candidate(180) == False
assert candidate(1000) == True
assert candidate(0) == True
assert candidate(1729) == False
def test_check():
check(iscube)
test_check()
|
humaneval-HumanEval_54_same_chars.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 {
// Check if two words have the same characters.
// >>> sameChars(("eabcdzzzz"), ("dddzzzzzzzddeddabc"))
// (true)
// >>> sameChars(("abcd"), ("dddddddabc"))
// (true)
// >>> sameChars(("dddddddabc"), ("abcd"))
// (true)
// >>> sameChars(("eabcd"), ("dddddddabc"))
// (false)
// >>> sameChars(("abcd"), ("dddddddabce"))
// (false)
// >>> sameChars(("eabcdzzzz"), ("dddzzzzzzzddddabc"))
// (false)
public static boolean sameChars(String s0, String s1) {
| }
} | return s0.chars().distinct().sorted().boxed().collect(Collectors.toList()).equals(s1.chars().distinct().sorted().boxed().collect(Collectors.toList())); | }
public static void main(String[] args) {
assert(sameChars(("eabcdzzzz"), ("dddzzzzzzzddeddabc")) == (true));
assert(sameChars(("abcd"), ("dddddddabc")) == (true));
assert(sameChars(("dddddddabc"), ("abcd")) == (true));
assert(sameChars(("eabcd"), ("dddddddabc")) == (false));
assert(sameChars(("abcd"), ("dddddddabcf")) == (false));
assert(sameChars(("eabcdzzzz"), ("dddzzzzzzzddddabc")) == (false));
assert(sameChars(("aabb"), ("aaccc")) == (false));
}
}
|
humaneval-HumanEval_138_is_equal_to_sum_even.json-L26 | js | //Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// >>> is_equal_to_sum_even(4)
// false
// >>> is_equal_to_sum_even(6)
// false
// >>> is_equal_to_sum_even(8)
// true
function is_equal_to_sum_even(n){
let m =0;
for(let i=2;i<n;i+=2){
for(let j=2;j<n;j+=2){
for(let k=2;k<n;k+=2){
for(let l=2;l<n;l+=2){
if((i+j+k+l)==n){
m=1;
break;
}
}
}
}
}
if(m==1){
return true;
} | return false;
}
} | else{ | const assert = require('node:assert');
function test() {
let candidate = is_equal_to_sum_even;
assert.deepEqual(candidate(4),false);
assert.deepEqual(candidate(6),false);
assert.deepEqual(candidate(8),true);
assert.deepEqual(candidate(10),true);
assert.deepEqual(candidate(11),false);
assert.deepEqual(candidate(12),true);
assert.deepEqual(candidate(13),false);
assert.deepEqual(candidate(16),true);
}
test(); |
humaneval-HumanEval_162_string_to_md5.json-L12 | py | from typing import Optional
def string_to_md5(text: str) -> Optional[str]:
"""
Given a string 'text', return its md5 hash equivalent string.
If 'text' is an empty string, return None.
>>> string_to_md5('Hello world')
'3e25960a79dbc69b674cd4ec67a72c62'
"""
import hashlib | return None
else:
return hashlib.md5(text.encode('utf-8')).hexdigest()
| if not text: | def check(candidate):
assert candidate('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'
assert candidate('') == None
assert candidate('A B C') == '0ef78513b0cb8cef12743f5aeb35f888'
assert candidate('password') == '5f4dcc3b5aa765d61d8327deb882cf99'
def test_check():
check(string_to_md5)
test_check()
|
humaneval-HumanEval_78_hex_key.json-L38 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// >>> hexKey(("AB"))
// (1l)
// >>> hexKey(("1077E"))
// (2l)
// >>> hexKey(("ABED1A33"))
// (4l)
// >>> hexKey(("123456789ABCDEF0"))
// (6l)
// >>> hexKey(("2020"))
// (2l)
public static long hexKey(String num) {
long result = 0;
for (int i = 0; i < num.length(); i++) {
if (num.charAt(i) == '2' || num.charAt(i) == '3' || num.charAt(i) == '5' || num.charAt(i) == '7' || num.charAt(i) == 'B' || num.charAt(i) == 'D') {
result++;
}
}
return result; | } | } | }
public static void main(String[] args) {
assert(hexKey(("AB")) == (1l));
assert(hexKey(("1077E")) == (2l));
assert(hexKey(("ABED1A33")) == (4l));
assert(hexKey(("2020")) == (2l));
assert(hexKey(("123456789ABCDEF0")) == (6l));
assert(hexKey(("112233445566778899AABBCCDDEEFF00")) == (12l));
}
}
|
humaneval-HumanEval_122_add_elements.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 {
// Given a non-empty array array list of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// >>> addElements((new ArrayList<Long>(Arrays.asList((long)111l, (long)21l, (long)3l, (long)4000l, (long)5l, (long)6l, (long)7l, (long)8l, (long)9l))), (4l))
// (24l)
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
public static long addElements(ArrayList<Long> arr, long k) {
return arr.stream().limit(k).filter(x -> x < 100).reduce(0l, (x, y) -> x + y);
} | } | }
public static void main(String[] args) {
assert(addElements((new ArrayList<Long>(Arrays.asList((long)1l, (long)-2l, (long)-3l, (long)41l, (long)57l, (long)76l, (long)87l, (long)88l, (long)99l))), (3l)) == (-4l));
assert(addElements((new ArrayList<Long>(Arrays.asList((long)111l, (long)121l, (long)3l, (long)4000l, (long)5l, (long)6l))), (2l)) == (0l));
assert(addElements((new ArrayList<Long>(Arrays.asList((long)11l, (long)21l, (long)3l, (long)90l, (long)5l, (long)6l, (long)7l, (long)8l, (long)9l))), (4l)) == (125l));
assert(addElements((new ArrayList<Long>(Arrays.asList((long)111l, (long)21l, (long)3l, (long)4000l, (long)5l, (long)6l, (long)7l, (long)8l, (long)9l))), (4l)) == (24l));
assert(addElements((new ArrayList<Long>(Arrays.asList((long)1l))), (1l)) == (1l));
}
}
|
|
humaneval-HumanEval_82_prime_length.json-L20 | py | def prime_length(string: str) -> bool:
"""Write a function that takes a string and returns True if the string
length is a prime number or False otherwise
Examples
>>> prime_length('Hello')
True
>>> prime_length('abcdcba')
True
>>> prime_length('kittens')
True
>>> prime_length('orange')
False
"""
num = len(string)
if num > 1:
for i in range(2, num):
if (num % i) == 0:
return False
else: | else:
return False
pass
| return True | def check(candidate):
assert candidate('Hello') == True
assert candidate('abcdcba') == True
assert candidate('kittens') == True
assert candidate('orange') == False
assert candidate('wow') == True
assert candidate('world') == True
assert candidate('MadaM') == True
assert candidate('Wow') == True
assert candidate('') == False
assert candidate('HI') == True
assert candidate('go') == True
assert candidate('gogo') == False
assert candidate('aaaaaaaaaaaaaaa') == False
assert candidate('Madam') == True
assert candidate('M') == False
assert candidate('0') == False
def test_check():
check(prime_length)
test_check()
|
humaneval-HumanEval_123_get_odd_collatz.json-L31 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a positive integer n, return a sorted array list 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 list 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.
// >>> getOddCollatz((5l))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)5l)))
public static ArrayList<Long> getOddCollatz(long n) {
if (n <= 0) return new ArrayList<Long>();
HashSet<Long> odds = new HashSet<Long>();
long n1 = n;
while (n1 > 1) {
if (n1 % 2 == 1) odds.add(n1);
n1 = n1 % 2 == 0 ? n1 / 2 : 3 * n1 + 1;
}
odds.add(1l); | ArrayList<Long> ans = new ArrayList<Long>(Arrays.asList(odds_arr));
Collections.sort(ans);
return ans;
}
} | Long[] odds_arr = odds.toArray(new Long[odds.size()]); | }
public static void main(String[] args) {
assert(getOddCollatz((14l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l, (long)7l, (long)11l, (long)13l, (long)17l)))));
assert(getOddCollatz((5l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)5l)))));
assert(getOddCollatz((12l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)5l)))));
assert(getOddCollatz((1l)).equals((new ArrayList<Long>(Arrays.asList((long)1l)))));
}
}
|
humaneval-HumanEval_124_valid_date.json-L31 | py | def valid_date(date: str) -> bool:
"""You have to write a function which validates a given date string and
returns True if the date is valid otherwise False.
The date is valid if all of the following rules are satisfied:
1. The date string is not empty.
2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
3. The months should not be less than 1 or higher than 12.
4. The date should be in the format: mm-dd-yyyy
>>> valid_date('03-11-2000')
True
>>> valid_date('15-01-2012')
False
>>> valid_date('04-0-2040')
False
>>> valid_date('06-04-2020')
True
>>> valid_date('06/04/2020')
False
"""
if not date:
return False
days_per_month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
date_list = [int(d) for d in date.split('-')]
if len(date_list) != 3:
return False | return False
if date_list[1] < 1 or date_list[1] > days_per_month[date_list[0] - 1]:
return False
if len(str(date_list[2])) != 4:
return False
return True | if date_list[0] < 1 or date_list[0] > 12: | def check(candidate):
assert candidate('03-11-2000') == True
assert candidate('15-01-2012') == False
assert candidate('04-0-2040') == False
assert candidate('06-04-2020') == True
assert candidate('01-01-2007') == True
assert candidate('03-32-2011') == False
assert candidate('') == False
assert candidate('04-31-3000') == False
assert candidate('06-06-2005') == True
assert candidate('21-31-2000') == False
assert candidate('04-12-2003') == True
assert candidate('04122003') == False
assert candidate('20030412') == False
assert candidate('2003-04') == False
assert candidate('2003-04-12') == False
assert candidate('04-2003') == False
def test_check():
check(valid_date)
test_check()
|
humaneval-HumanEval_101_words_string.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array array list of the words.
// For example:
// >>> wordsString(("Hi, my name is John"))
// (new ArrayList<String>(Arrays.asList((String)"Hi", (String)"my", (String)"name", (String)"is", (String)"John")))
// >>> wordsString(("One, two, three, four, five, six"))
// (new ArrayList<String>(Arrays.asList((String)"One", (String)"two", (String)"three", (String)"four", (String)"five", (String)"six")))
public static ArrayList<String> wordsString(String s) {
ArrayList<String> al = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(s, " , ");
while (st.hasMoreTokens()) {
al.add(st.nextToken());
}
return al;
} | } | }
public static void main(String[] args) {
assert(wordsString(("Hi, my name is John")).equals((new ArrayList<String>(Arrays.asList((String)"Hi", (String)"my", (String)"name", (String)"is", (String)"John")))));
assert(wordsString(("One, two, three, four, five, six")).equals((new ArrayList<String>(Arrays.asList((String)"One", (String)"two", (String)"three", (String)"four", (String)"five", (String)"six")))));
assert(wordsString(("Hi, my name")).equals((new ArrayList<String>(Arrays.asList((String)"Hi", (String)"my", (String)"name")))));
assert(wordsString(("One,, two, three, four, five, six,")).equals((new ArrayList<String>(Arrays.asList((String)"One", (String)"two", (String)"three", (String)"four", (String)"five", (String)"six")))));
assert(wordsString(("")).equals((new ArrayList<String>(Arrays.asList()))));
assert(wordsString(("ahmed , gamal")).equals((new ArrayList<String>(Arrays.asList((String)"ahmed", (String)"gamal")))));
}
}
|
|
humaneval-HumanEval_111_histogram.json-L46 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a string representing a space separated lowercase letters, return a hash map
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// >>> histogram(("a b c"))
// (new HashMap<String,Long>(Map.of("a", 1l, "b", 1l, "c", 1l)))
// >>> histogram(("a b b a"))
// (new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))
// >>> histogram(("a b c a b"))
// (new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))
// >>> histogram(("b b b b a"))
// (new HashMap<String,Long>(Map.of("b", 4l)))
// >>> histogram((""))
// (new HashMap<String,Long>())
public static HashMap<String,Long> histogram(String test) {
HashMap<String,Long> s = new HashMap<String,Long>();
if (test.length() > 0) {
HashMap<String,Long> hm = new HashMap<String,Long>();
String[] ss = test.split(" ");
for (String sss : ss) {
if (hm.containsKey(sss)) {
hm.put(sss, hm.get(sss) + 1);
} else {
hm.put(sss, 1l);
}
}
long max = 0;
for (String key : hm.keySet()) {
if (hm.get(key) > max) {
max = hm.get(key);
}
}
for (String key : hm.keySet()) {
if (hm.get(key) == max) {
s.put(key, hm.get(key));
}
} | return s;
}
} | } | }
public static void main(String[] args) {
assert(histogram(("a b b a")).equals((new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))));
assert(histogram(("a b c a b")).equals((new HashMap<String,Long>(Map.of("a", 2l, "b", 2l)))));
assert(histogram(("a b c d g")).equals((new HashMap<String,Long>(Map.of("a", 1l, "b", 1l, "c", 1l, "d", 1l, "g", 1l)))));
assert(histogram(("r t g")).equals((new HashMap<String,Long>(Map.of("r", 1l, "t", 1l, "g", 1l)))));
assert(histogram(("b b b b a")).equals((new HashMap<String,Long>(Map.of("b", 4l)))));
assert(histogram(("r t g")).equals((new HashMap<String,Long>(Map.of("r", 1l, "t", 1l, "g", 1l)))));
assert(histogram(("")).equals((new HashMap<String,Long>())));
assert(histogram(("a")).equals((new HashMap<String,Long>(Map.of("a", 1l)))));
}
}
|
humaneval-HumanEval_153_Strongest_Extension.json-L29 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You 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;
} | String strongest = "";
for (String s : extensions) {
int cap = (int)s.chars().filter(c -> Character.isUpperCase(c)).count();
int sm = (int)s.chars().filter(c -> Character.isLowerCase(c)).count();
int diff = cap - sm;
if (diff > strength) {
strength = diff;
strongest = s;
}
}
return class_name + "." + strongest;
}
} | int strength = Integer.MIN_VALUE; | }
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_46_fib4.json-L16 | 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]; | 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];
}
| if(n<prev.length){ | 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_37_sort_even.json-L11 | js | //This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// >>> sort_even([1, 2, 3])
// [1, 2, 3]
// >>> sort_even([5, 6, 3, 4])
// [3, 6, 5, 4]
function sort_even(l){
var l2 = []
for(var i = 0; i < l.length; i += 2){ | }
l2.sort(function(a, b){return a - b})
for(var i = 0; i < l2.length; i++){
l[i * 2] = l2[i]
}
return l
}
| l2.push(l[i]) | const assert = require('node:assert');
function test() {
let candidate = sort_even;
assert.deepEqual(candidate([1, 2, 3]),[1, 2, 3]);
assert.deepEqual(candidate([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]),[-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123]);
assert.deepEqual(candidate([5, 8, -12, 4, 23, 2, 3, 11, 12, -10]),[-12, 8, 3, 4, 5, 2, 12, 11, 23, -10]);
}
test(); |
humaneval-HumanEval_57_monotonic.json-L15 | js | //Return true is array elements are monotonically increasing or decreasing.
// >>> monotonic([1, 2, 4, 20])
// true
// >>> monotonic([1, 20, 4, 10])
// false
// >>> monotonic([4, 1, 0, -10])
// true
function monotonic(l){
if(l.length <= 1){
return true;
}
if(l[0] < l[1]){
for(var i = 1; i < l.length - 1; i++){
if(l[i] > l[i + 1]){ | }
}
}
else{
for(var i = 1; i < l.length - 1; i++){
if(l[i] < l[i + 1]){
return false;
}
}
}
return true;
}
| return false; | const assert = require('node:assert');
function test() {
let candidate = monotonic;
assert.deepEqual(candidate([1, 2, 4, 10]),true);
assert.deepEqual(candidate([1, 2, 4, 20]),true);
assert.deepEqual(candidate([1, 20, 4, 10]),false);
assert.deepEqual(candidate([4, 1, 0, -10]),true);
assert.deepEqual(candidate([4, 1, 1, 0]),true);
assert.deepEqual(candidate([1, 2, 3, 2, 5, 60]),false);
assert.deepEqual(candidate([1, 2, 3, 4, 5, 60]),true);
assert.deepEqual(candidate([9, 9, 9, 9]),true);
}
test(); |
humaneval-HumanEval_120_maximum.json-L33 | py | from typing import List
def maximum(arr: List[int], k: int) -> List[int]:
"""
Given an array arr of integers and a positive integer k, return a sorted list
of length k with the maximum k numbers in arr.
Example 1:
>>> maximum([-3, -4, 5], 3)
[-4, -3, 5]
Example 2:
>>> maximum([4, -4, 4], 2)
[4, 4]
Example 3:
>>> maximum([-3, 2, 1, 2, -1, -2, 1], 1)
[2]
Note:
1. The length of the array will be in the range of [1, 1000].
2. The elements in the array will be in the range of [-1000, 1000].
3. 0 <= k <= len(arr)
"""
def get_max(arr: List[int], k: int) -> List[int]:
"""
Returns the maximum k numbers in the given array
"""
if k == 0: | elif k == 1:
return [max(arr)]
else:
max_num = max(arr)
arr.remove(max_num)
return [max_num] + get_max(arr, k - 1)
return sorted(get_max(arr, k))
| return [] | def check(candidate):
assert candidate([-3, -4, 5], 3) == [-4, -3, 5]
assert candidate([4, -4, 4], 2) == [4, 4]
assert candidate([-3, 2, 1, 2, -1, -2, 1], 1) == [2]
assert candidate([123, -123, 20, 0, 1, 2, -3], 3) == [2, 20, 123]
assert candidate([-123, 20, 0, 1, 2, -3], 4) == [0, 1, 2, 20]
assert candidate([5, 15, 0, 3, -13, -8, 0], 7) == [-13, -8, 0, 0, 3, 5, 15]
assert candidate([-1, 0, 2, 5, 3, -10], 2) == [3, 5]
assert candidate([1, 0, 5, -7], 1) == [5]
assert candidate([4, -4], 2) == [-4, 4]
assert candidate([-10, 10], 2) == [-10, 10]
assert candidate([1, 2, 3, -23, 243, -400, 0], 0) == []
def test_check():
check(maximum)
test_check()
|
humaneval-HumanEval_77_iscube.json-L23 | js | //Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// >>> iscube(1)
// true
// >>> iscube(2)
// false
// >>> iscube(-1)
// true
// >>> iscube(64)
// true
// >>> iscube(0)
// true
// >>> iscube(180)
// false
function iscube(a){
if(Math.cbrt(a)%1==0){
return true;
}else{
return false;
} | } | const assert = require('node:assert');
function test() {
let candidate = iscube;
assert.deepEqual(candidate(1),true);
assert.deepEqual(candidate(2),false);
assert.deepEqual(candidate(-1),true);
assert.deepEqual(candidate(64),true);
assert.deepEqual(candidate(180),false);
assert.deepEqual(candidate(1000),true);
assert.deepEqual(candidate(0),true);
assert.deepEqual(candidate(1729),false);
}
test(); |
|
humaneval-HumanEval_11_string_xor.json-L7 | js | //Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// >>> string_xor("010", "110")
// "100"
function string_xor(a, b){
var arrayA = []; | var arrayXOR = [];
var result = '';
for (var i = 0; i < a.length; i++) {
arrayA.push(parseInt(a[i]));
}
for (var j = 0; j < b.length; j++) {
arrayB.push(parseInt(b[j]));
}
for (var k = 0; k < arrayA.length; k++) {
if (arrayA[k] !== arrayB[k]) {
arrayXOR.push(1);
}
else {
arrayXOR.push(0);
}
}
result = arrayXOR.join('');
return result;
} | var arrayB = []; | const assert = require('node:assert');
function test() {
let candidate = string_xor;
assert.deepEqual(candidate("111000", "101010"),"010010");
assert.deepEqual(candidate("1", "1"),"0");
assert.deepEqual(candidate("0101", "0000"),"0101");
}
test(); |
humaneval-HumanEval_137_compare_one.json-L30 | js | //Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return undefined if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// >>> compare_one(1, 2.5)
// 2.5
// >>> compare_one(1, "2,3")
// "2,3"
// >>> compare_one("5,1", "6")
// "6"
// >>> compare_one("1", 1)
// undefined
function compare_one(a, b){
if (typeof a === typeof b){
if (a > b) {
return a;
} else if (a < b) {
return b;
} else {
return undefined;
}
}
else if (typeof a === "string" && typeof b === "number"){
if (a[0] > b){
return a;
} else if (a[0] < b){
return b;
} else {
return undefined; | }
else if (typeof a === "number" && typeof b === "string"){
if (a > b[0]){
return a;
} else if (a < b[0]){
return b;
} else {
return undefined;
}
}
}
| } | const assert = require('node:assert');
function test() {
let candidate = compare_one;
assert.deepEqual(candidate(1, 2),2);
assert.deepEqual(candidate(1, 2.5),2.5);
assert.deepEqual(candidate(2, 3),3);
assert.deepEqual(candidate(5, 6),6);
assert.deepEqual(candidate(1, "2,3"),"2,3");
assert.deepEqual(candidate("5,1", "6"),"6");
assert.deepEqual(candidate("1", "2"),"2");
assert.deepEqual(candidate("1", 1),undefined);
}
test(); |
humaneval-HumanEval_118_get_closest_vowel.json-L17 | js | //You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// >>> get_closest_vowel("yogurt")
// "u"
// >>> get_closest_vowel("FULL")
// "U"
// >>> get_closest_vowel("quick")
// ""
// >>> get_closest_vowel("ab")
// ""
function get_closest_vowel(word){
let vowels = ["a", "e", "i", "o", "u"]; | let result = [];
if (word.length === 1) {
return ""
} else {
while (i >= 0) {
if (vowels.includes(word[i])) {
if (i > 0 && i < word.length - 1) {
if (!vowels.includes(word[i-1]) && !vowels.includes(word[i+1])) {
result.push(word[i]);
}
}
}
i--;
}
if (result.length === 0) {
return ""
} else {
return result[0];
}
}
} | let i = word.length - 1; | const assert = require('node:assert');
function test() {
let candidate = get_closest_vowel;
assert.deepEqual(candidate("yogurt"),"u");
assert.deepEqual(candidate("full"),"u");
assert.deepEqual(candidate("easy"),"");
assert.deepEqual(candidate("eAsy"),"");
assert.deepEqual(candidate("ali"),"");
assert.deepEqual(candidate("bad"),"a");
assert.deepEqual(candidate("most"),"o");
assert.deepEqual(candidate("ab"),"");
assert.deepEqual(candidate("ba"),"");
assert.deepEqual(candidate("quick"),"");
assert.deepEqual(candidate("anime"),"i");
assert.deepEqual(candidate("Asia"),"");
assert.deepEqual(candidate("Above"),"o");
}
test(); |
humaneval-HumanEval_94_skjkasdkd.json-L40 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given an array array list of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l, (long)2l, (long)1l, (long)3l, (long)5l, (long)7l, (long)4l, (long)5l, (long)5l, (long)5l, (long)2l, (long)181l, (long)32l, (long)4l, (long)32l, (long)3l, (long)2l, (long)32l, (long)324l, (long)4l, (long)3l))))
// (10l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)1l, (long)8l, (long)2l, (long)4597l, (long)2l, (long)1l, (long)3l, (long)40l, (long)1l, (long)2l, (long)1l, (long)2l, (long)4l, (long)2l, (long)5l, (long)1l))))
// (25l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)1l, (long)32l, (long)5107l, (long)34l, (long)83278l, (long)109l, (long)163l, (long)23l, (long)2323l, (long)32l, (long)30l, (long)1l, (long)9l, (long)3l))))
// (13l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)724l, (long)32l, (long)71l, (long)99l, (long)32l, (long)6l, (long)0l, (long)5l, (long)91l, (long)83l, (long)0l, (long)5l, (long)6l))))
// (11l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)81l, (long)12l, (long)3l, (long)1l, (long)21l))))
// (3l)
// >>> skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)8l, (long)1l, (long)2l, (long)1l, (long)7l))))
// (7l)
public static long skjkasdkd(ArrayList<Long> lst) {
long largestPrime = 0l;
for (Long item : lst) {
long number = item;
int counter = 0;
if (item == 1) {
continue;
}
if (item == 2) {
counter = 1;
}
else {
int l = 1;
while (l <= (int) number) {
if (number % l == 0) {
counter++; | l++;
}
}
if (counter == 2) {
if (number > largestPrime) {
largestPrime = number;
}
}
}
if (largestPrime == 0) {
return 0l;
}
else {
long output = 0l;
while (largestPrime > 0) {
output += largestPrime % 10;
largestPrime /= 10;
}
return output;
}
}
} | } | }
public static void main(String[] args) {
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)3l, (long)2l, (long)1l, (long)3l, (long)5l, (long)7l, (long)4l, (long)5l, (long)5l, (long)5l, (long)2l, (long)181l, (long)32l, (long)4l, (long)32l, (long)3l, (long)2l, (long)32l, (long)324l, (long)4l, (long)3l)))) == (10l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)0l, (long)1l, (long)8l, (long)2l, (long)4597l, (long)2l, (long)1l, (long)3l, (long)40l, (long)1l, (long)2l, (long)1l, (long)2l, (long)4l, (long)2l, (long)5l, (long)1l)))) == (25l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)1l, (long)32l, (long)5107l, (long)34l, (long)83278l, (long)109l, (long)163l, (long)23l, (long)2323l, (long)32l, (long)30l, (long)1l, (long)9l, (long)3l)))) == (13l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)724l, (long)32l, (long)71l, (long)99l, (long)32l, (long)6l, (long)0l, (long)5l, (long)91l, (long)83l, (long)0l, (long)5l, (long)6l)))) == (11l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)81l, (long)12l, (long)3l, (long)1l, (long)21l)))) == (3l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)0l, (long)8l, (long)1l, (long)2l, (long)1l, (long)7l)))) == (7l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)8191l)))) == (19l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)8191l, (long)123456l, (long)127l, (long)7l)))) == (19l));
assert(skjkasdkd((new ArrayList<Long>(Arrays.asList((long)127l, (long)97l, (long)8192l)))) == (10l));
}
}
|
humaneval-HumanEval_36_fizz_buzz.json-L18 | js | //Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// >>> fizz_buzz(50)
// 0
// >>> fizz_buzz(78)
// 2
// >>> fizz_buzz(79)
// 3
function fizz_buzz(n){
let result = 0;
for(let i = 0; i < n; i++){
if(i % 11 === 0 || i % 13 === 0){
let arr = i.toString().split('');
for(let j = 0; j < arr.length; j++){
if(arr[j] === '7'){
result++;
}
} | }
return result;
}
| } | const assert = require('node:assert');
function test() {
let candidate = fizz_buzz;
assert.deepEqual(candidate(50),0);
assert.deepEqual(candidate(78),2);
assert.deepEqual(candidate(79),3);
assert.deepEqual(candidate(100),3);
assert.deepEqual(candidate(200),6);
assert.deepEqual(candidate(4000),192);
assert.deepEqual(candidate(10000),639);
assert.deepEqual(candidate(100000),8026);
}
test(); |
humaneval-HumanEval_83_starts_one_ends.json-L9 | js | //Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
function starts_one_ends(n){
let ones = [];
for(let i = Math.pow(10, n-1); i < Math.pow(10, n); i++){
if(i.toString().startsWith('1') || i.toString().endsWith('1')){
ones.push(i);
} | return ones.length;
} | } | const assert = require('node:assert');
function test() {
let candidate = starts_one_ends;
assert.deepEqual(candidate(1),1);
assert.deepEqual(candidate(2),18);
assert.deepEqual(candidate(3),180);
assert.deepEqual(candidate(4),1800);
assert.deepEqual(candidate(5),18000);
}
test(); |
humaneval-HumanEval_114_minSubArraySum.json-L35 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of integers nums, find the minimum sum of any non-empty sub-array array list
// of nums.
// Example
// >>> minSubArraySum((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l, (long)1l, (long)2l, (long)4l))))
// (1l)
// >>> minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l))))
// (-6l)
public static long minSubArraySum(ArrayList<Long> nums) {
long minSum = Long.MAX_VALUE;
long prevMinSum = Long.MAX_VALUE;
for (int i = 0; i < nums.size(); i++) {
long currSum = nums.get(i);
if (currSum < prevMinSum) {
prevMinSum = currSum;
}
if (currSum < minSum) {
minSum = currSum;
}
for (int j = i + 1; j < nums.size(); j++) {
currSum += nums.get(j);
if (currSum < prevMinSum) {
prevMinSum = currSum;
}
if (currSum < minSum) {
minSum = currSum;
} | }
return minSum;
}
} | } | }
public static void main(String[] args) {
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)4l, (long)1l, (long)2l, (long)4l)))) == (1l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l)))) == (-6l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l, (long)2l, (long)-10l)))) == (-14l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-9999999999999999l)))) == (-9999999999999999l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)0l, (long)10l, (long)20l, (long)1000000l)))) == (0l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-1l, (long)-2l, (long)-3l, (long)10l, (long)-5l)))) == (-6l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)100l, (long)-1l, (long)-2l, (long)-3l, (long)10l, (long)-5l)))) == (-6l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)10l, (long)11l, (long)13l, (long)8l, (long)3l, (long)4l)))) == (3l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)100l, (long)-33l, (long)32l, (long)-1l, (long)0l, (long)-2l)))) == (-33l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)-10l)))) == (-10l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)7l)))) == (7l));
assert(minSubArraySum((new ArrayList<Long>(Arrays.asList((long)1l, (long)-1l)))) == (-1l));
}
}
|
humaneval-HumanEval_1_separate_paren_groups.json-L17 | 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:
if c == '(': | elif c == ')':
open_count -= 1
group += c
if open_count == 0:
groups.append(group)
group = ''
return groups
| open_count += 1 | def check(candidate):
assert candidate('(()()) ((())) () ((())()())') == ['(()())', '((()))', '()', '((())()())']
assert candidate('() (()) ((())) (((())))') == ['()', '(())', '((()))', '(((())))']
assert candidate('(()(())((())))') == ['(()(())((())))']
assert candidate('( ) (( )) (( )( ))') == ['()', '(())', '(()())']
def test_check():
check(separate_paren_groups)
test_check()
|
humaneval-HumanEval_35_max_element.json-L18 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return maximum element in the array list.
// >>> maxElement((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (3l)
// >>> maxElement((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)-5l, (long)2l, (long)-3l, (long)3l, (long)9l, (long)0l, (long)123l, (long)1l, (long)-10l))))
// (123l)
public static long maxElement(ArrayList<Long> l) {
Long max = Long.MIN_VALUE;
for (int i = 0; i < l.size(); i += 1) {
if (l.get(i) > max) { | }
}
return max;
}
} | max = l.get(i); | }
public static void main(String[] args) {
assert(maxElement((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))) == (3l));
assert(maxElement((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)-5l, (long)2l, (long)-3l, (long)3l, (long)9l, (long)0l, (long)124l, (long)1l, (long)-10l)))) == (124l));
}
}
|
humaneval-HumanEval_5_intersperse.json-L11 | py | from typing import List
def intersperse(numbers: List[int], delimeter: int) -> List[int]:
""" Insert a number 'delimeter' between every two consecutive elements of input list `numbers'
>>> intersperse([], 4)
[]
>>> intersperse([1, 2, 3], 4)
[1, 4, 2, 4, 3]
"""
result = [] | return result
result.append(numbers[0])
for num in numbers[1:]:
result.append(delimeter)
result.append(num)
return result
| if len(numbers) == 0: | def check(candidate):
assert candidate([], 7) == []
assert candidate([5, 6, 3, 2], 8) == [5, 8, 6, 8, 3, 8, 2]
assert candidate([2, 2, 2], 2) == [2, 2, 2, 2, 2]
def test_check():
check(intersperse)
test_check()
|
humaneval-HumanEval_69_search.json-L19 | js | //You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// >>> search([4, 1, 2, 2, 3, 1])
// 2
// >>> search([1, 2, 2, 3, 3, 3, 4, 4, 4])
// 3
// >>> search([5, 5, 4, 4, 4])
// -1
function search(lst){
var h = {};
for (var i=0; i<lst.length; i++){
var x = lst[i];
if (x in h){
h[x] += 1;
} | h[x] = 1;
}
}
var keys = Object.keys(h);
var max = 0;
for (var i=0; i<keys.length; i++){
if (keys[i] > max && h[keys[i]] >= keys[i]){
max = keys[i];
}
}
if (max == 0){
return -1;
}
return max;
}
| else{ | const assert = require('node:assert');
function test() {
let candidate = search;
assert.deepEqual(candidate([5, 5, 5, 5, 1]),1);
assert.deepEqual(candidate([4, 1, 4, 1, 4, 4]),4);
assert.deepEqual(candidate([3, 3]),-1);
assert.deepEqual(candidate([8, 8, 8, 8, 8, 8, 8, 8]),8);
assert.deepEqual(candidate([2, 3, 3, 2, 2]),2);
assert.deepEqual(candidate([2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1]),1);
assert.deepEqual(candidate([3, 2, 8, 2]),2);
assert.deepEqual(candidate([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]),1);
assert.deepEqual(candidate([8, 8, 3, 6, 5, 6, 4]),-1);
assert.deepEqual(candidate([6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9]),1);
assert.deepEqual(candidate([1, 9, 10, 1, 3]),1);
assert.deepEqual(candidate([6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10]),5);
assert.deepEqual(candidate([1]),1);
assert.deepEqual(candidate([8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5]),4);
assert.deepEqual(candidate([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]),2);
assert.deepEqual(candidate([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]),1);
assert.deepEqual(candidate([9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4]),4);
assert.deepEqual(candidate([2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7]),4);
assert.deepEqual(candidate([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]),2);
assert.deepEqual(candidate([5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8]),-1);
assert.deepEqual(candidate([10]),-1);
assert.deepEqual(candidate([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]),2);
assert.deepEqual(candidate([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]),1);
assert.deepEqual(candidate([7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6]),1);
assert.deepEqual(candidate([3, 10, 10, 9, 2]),-1);
}
test(); |
humaneval-HumanEval_126_is_sorted.json-L44 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of numbers, return whether or not they are sorted
// in ascending order. If array list has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l))))
// (false)
public static boolean isSorted(ArrayList<Long> lst) {
if (lst.size() == 0) {
return true;
}
else {
int running_max = 0;
int previous_number = 0;
boolean first_time = true;
boolean seen_2_in_a_row = false;
for (Long number : lst) {
if (first_time) {
first_time = false;
previous_number = number.intValue();
running_max = number.intValue();
} | if (running_max > number.intValue()) {
return false;
}
else {
if (previous_number == number.intValue()) {
if (seen_2_in_a_row) {
return false;
}
else {
seen_2_in_a_row = true;
}
}
else {
seen_2_in_a_row = false;
}
previous_number = number.intValue();
running_max = number.intValue();
}
}
}
return true;
}
}
} | else { | }
public static void main(String[] args) {
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)5l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList()))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)1l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)3l, (long)3l, (long)4l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))) == (true));
}
}
|
humaneval-HumanEval_139_special_factorial.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 {
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// >>> specialFactorial((4l))
// (288l)
// The function will receive an integer as input and should return the special
// factorial of this integer.
public static long specialFactorial(long n) {
long result = 1;
while (n > 0) {
long local_result = 1;
long temp = n;
while (temp > 0) {
local_result *= temp; | }
result *= local_result;
n--;
}
return result;
}
} | temp--; | }
public static void main(String[] args) {
assert(specialFactorial((4l)) == (288l));
assert(specialFactorial((5l)) == (34560l));
assert(specialFactorial((7l)) == (125411328000l));
assert(specialFactorial((1l)) == (1l));
}
}
|
humaneval-HumanEval_133_sum_squares.json-L27 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given an array array list of numbers.
// You need to return the sum of squared numbers in the given array list,
// round each element in the array list to the upper int(Ceiling) first.
// Examples:
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f))))
// (14l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)4.0f, (float)9.0f))))
// (98l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)3.0f, (float)5.0f, (float)7.0f))))
// (84l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)1.4f, (float)4.2f, (float)0.0f))))
// (29l)
// >>> lst((new ArrayList<Float>(Arrays.asList((float)-2.4f, (float)1.0f, (float)1.0f))))
// (6l)
public static long sumSquares(ArrayList<Float> lst) {
if (lst.size() == 0) {
return 0;
} | for (int i = 0; i < lst.size(); i++) {
sum += (long)Math.ceil(lst.get(i)) * (long)Math.ceil(lst.get(i));
}
return sum;
}
} | long sum = 0; | }
public static void main(String[] args) {
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f)))) == (14l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)2.0f, (float)3.0f)))) == (14l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.0f, (float)3.0f, (float)5.0f, (float)7.0f)))) == (84l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)1.4f, (float)4.2f, (float)0.0f)))) == (29l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-2.4f, (float)1.0f, (float)1.0f)))) == (6l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)100.0f, (float)1.0f, (float)15.0f, (float)2.0f)))) == (10230l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)10000.0f, (float)10000.0f)))) == (200000000l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.4f, (float)4.6f, (float)6.3f)))) == (75l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.4f, (float)17.9f, (float)18.9f, (float)19.9f)))) == (1086l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)0.0f)))) == (0l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.0f)))) == (1l));
assert(sumSquares((new ArrayList<Float>(Arrays.asList((float)-1.0f, (float)1.0f, (float)0.0f)))) == (2l));
}
}
|
humaneval-HumanEval_41_car_race_collision.json-L11 | 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 right_to_left = Array(n).fill(1);
for (let i = 0; i < left_to_right.length; i++) {
for (let j = 0; j < right_to_left.length; j++) {
if (left_to_right[i] == right_to_left[j]) {
num_collisions++;
}
}
}
return num_collisions;
}
| let left_to_right = Array(n).fill(1); | 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_91_is_bored.json-L27 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You'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:
// >>> isBored(("Hello world"))
// (0l)
// >>> isBored(("The sky is blue. The sun is shining. I love this weather"))
// (1l)
public static long isBored(String S) {
long boredoms = 0;
String[] sentences = S.split("\\.\\s|\\?\\s|\\!\\s");
for (String sentence : sentences) {
String[] words = sentence.split("\\s");
if (words.length > 0 && words[0].equals("I")) {
boredoms++;
}
}
return boredoms; | } | } | }
public static void main(String[] args) {
assert(isBored(("Hello world")) == (0l));
assert(isBored(("Is the sky blue?")) == (0l));
assert(isBored(("I love It !")) == (1l));
assert(isBored(("bIt")) == (0l));
assert(isBored(("I feel good today. I will be productive. will kill It")) == (2l));
assert(isBored(("You and I are going for a walk")) == (0l));
}
}
|
humaneval-HumanEval_160_do_algebra.json-L57 | 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 '+': | break;
case '-':
answer -= operand[0];
break;
}
operand.splice(0, 1);
operator.splice(0, 1);
}
return answer;
}
| answer += operand[0]; | const assert = require('node:assert');
function test() {
let candidate = do_algebra;
assert.deepEqual(candidate(["**", "*", "+"], [2, 3, 4, 5]),37);
assert.deepEqual(candidate(["+", "*", "-"], [2, 3, 4, 5]),9);
assert.deepEqual(candidate(["//", "*"], [7, 3, 4]),8);
}
test(); |
humaneval-HumanEval_59_largest_prime_factor.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 {
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// >>> largestPrimeFactor((13195l))
// (29l)
// >>> largestPrimeFactor((2048l))
// (2l)
public static long largestPrimeFactor(long n) {
List<Long> primes = new ArrayList<>();
long x = n;
for (long i = 2; i * i <= x; i++) {
if (x % i == 0) {
primes.add(i);
x /= i;
i--;
}
} | primes.add(x);
}
return primes.get(primes.size() - 1);
}
} | if (x > 1) { | }
public static void main(String[] args) {
assert(largestPrimeFactor((15l)) == (5l));
assert(largestPrimeFactor((27l)) == (3l));
assert(largestPrimeFactor((63l)) == (7l));
assert(largestPrimeFactor((330l)) == (11l));
assert(largestPrimeFactor((13195l)) == (29l));
}
}
|
humaneval-HumanEval_26_remove_duplicates.json-L13 | js | //From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// >>> remove_duplicates([1, 2, 3, 2, 4])
// [1, 3, 4]
function remove_duplicates(numbers){
let result = [];
numbers.forEach(function(value){
if(numbers.indexOf(value) === numbers.lastIndexOf(value)){
result.push(value);
}
});
return result; | } | const assert = require('node:assert');
function test() {
let candidate = remove_duplicates;
assert.deepEqual(candidate([]),[]);
assert.deepEqual(candidate([1, 2, 3, 4]),[1, 2, 3, 4]);
assert.deepEqual(candidate([1, 2, 3, 2, 4, 3, 5]),[1, 4, 5]);
}
test(); |
|
humaneval-HumanEval_110_exchange.json-L17 | js | //In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// >>> exchange([1, 2, 3, 4], [1, 2, 3, 4])
// "YES"
// >>> exchange([1, 2, 3, 4], [1, 5, 3, 4])
// "NO"
// It is assumed that the input arrays will be non-empty.
function exchange(lst1, lst2){
var num1 = 0;
var num2 = 0; | while(num1 < lst1.length && exchange){
if(lst1[num1] % 2 !== 0){
exchange = false;
if(num2 < lst2.length){
while(num2 < lst2.length && exchange == false){
if(lst2[num2] % 2 == 0){
lst1[num1] = lst2[num2];
exchange = true;
}
num2++;
}
}
}
num1++;
}
if(exchange){
return "YES";
}else{
return "NO";
}
}
| var exchange = true; | const assert = require('node:assert');
function test() {
let candidate = exchange;
assert.deepEqual(candidate([1, 2, 3, 4], [1, 2, 3, 4]),"YES");
assert.deepEqual(candidate([1, 2, 3, 4], [1, 5, 3, 4]),"NO");
assert.deepEqual(candidate([1, 2, 3, 4], [2, 1, 4, 3]),"YES");
assert.deepEqual(candidate([5, 7, 3], [2, 6, 4]),"YES");
assert.deepEqual(candidate([5, 7, 3], [2, 6, 3]),"NO");
assert.deepEqual(candidate([3, 2, 6, 1, 8, 9], [3, 5, 5, 1, 1, 1]),"NO");
assert.deepEqual(candidate([100, 200], [200, 200]),"YES");
}
test(); |
humaneval-HumanEval_74_total_match.json-L29 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that accepts two array lists of strings and returns the array list that has
// total number of chars in the all strings of the array list less than the other array list.
// if the two array lists have the same number of chars, return the first array list.
// Examples
// >>> totalMatch((new ArrayList<String>(Arrays.asList())), (new ArrayList<String>(Arrays.asList())))
// (new ArrayList<String>(Arrays.asList()))
// >>> totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hI", (String)"Hi"))))
// (new ArrayList<String>(Arrays.asList((String)"hI", (String)"Hi")))
// >>> totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hi", (String)"hi", (String)"admin", (String)"project"))))
// (new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin")))
// >>> totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hI", (String)"hi", (String)"hi"))))
// (new ArrayList<String>(Arrays.asList((String)"hI", (String)"hi", (String)"hi")))
// >>> totalMatch((new ArrayList<String>(Arrays.asList((String)"4"))), (new ArrayList<String>(Arrays.asList((String)"1", (String)"2", (String)"3", (String)"4", (String)"5"))))
// (new ArrayList<String>(Arrays.asList((String)"4")))
public static ArrayList<String> totalMatch(ArrayList<String> lst1, ArrayList<String> lst2) {
int sum1 = 0;
int sum2 = 0;
for (String s : lst1) {
sum1 += s.length();
} | sum2 += s.length();
}
if (sum1 <= sum2) {
return lst1;
} else {
return lst2;
}
}
} | for (String s : lst2) { | }
public static void main(String[] args) {
assert(totalMatch((new ArrayList<String>(Arrays.asList())), (new ArrayList<String>(Arrays.asList()))).equals((new ArrayList<String>(Arrays.asList()))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hi", (String)"hi")))).equals((new ArrayList<String>(Arrays.asList((String)"hi", (String)"hi")))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hi", (String)"hi", (String)"admin", (String)"project")))).equals((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin")))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"4"))), (new ArrayList<String>(Arrays.asList((String)"1", (String)"2", (String)"3", (String)"4", (String)"5")))).equals((new ArrayList<String>(Arrays.asList((String)"4")))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hI", (String)"Hi")))).equals((new ArrayList<String>(Arrays.asList((String)"hI", (String)"Hi")))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hI", (String)"hi", (String)"hi")))).equals((new ArrayList<String>(Arrays.asList((String)"hI", (String)"hi", (String)"hi")))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin"))), (new ArrayList<String>(Arrays.asList((String)"hI", (String)"hi", (String)"hii")))).equals((new ArrayList<String>(Arrays.asList((String)"hi", (String)"admin")))));
assert(totalMatch((new ArrayList<String>(Arrays.asList())), (new ArrayList<String>(Arrays.asList((String)"this")))).equals((new ArrayList<String>(Arrays.asList()))));
assert(totalMatch((new ArrayList<String>(Arrays.asList((String)"this"))), (new ArrayList<String>(Arrays.asList()))).equals((new ArrayList<String>(Arrays.asList()))));
}
}
|
humaneval-HumanEval_75_is_multiply_prime.json-L15 | py | def is_multiply_prime(a: int) -> bool:
"""Write a function that returns true if the given number is the multiplication of 3 prime numbers
and false otherwise.
Knowing that (a) is less then 100.
Example:
>>> is_multiply_prime(30)
True
30 = 2 * 3 * 5
"""
n = a
d = 2
prime_factors = []
while d * d <= n:
if n % d == 0: | n //= d
else:
d += 1
if n > 1:
prime_factors.append(n)
if len(prime_factors) == 3:
return True
else:
return False
| prime_factors.append(d) | def check(candidate):
assert candidate(5) == False
assert candidate(30) == True
assert candidate(8) == True
assert candidate(10) == False
assert candidate(125) == True
assert candidate(105) == True
assert candidate(126) == False
assert candidate(729) == False
assert candidate(891) == False
assert candidate(1001) == True
def test_check():
check(is_multiply_prime)
test_check()
|
humaneval-HumanEval_133_sum_squares.json-L27 | 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)):
lst[i] = math.ceil(lst[i])
total = 0
for i in lst:
total += i**2 | return total | 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_143_words_in_sentence.json-L26 | 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 True
words = sentence.split()
prime_words = []
for word in words:
if is_prime(len(word)):
prime_words.append(word)
return ' '.join(prime_words) | return False | 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()
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.