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_73_smallest_change.json-L20 | 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 | if arr[start] != arr[end]:
count += 1
start += 1
end -= 1
return count
| while start < end: | 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_31_is_prime.json-L32 | js | //Return true if a given number is prime, and false otherwise.
// >>> is_prime(6)
// false
// >>> is_prime(101)
// true
// >>> is_prime(11)
// true
// >>> is_prime(13441)
// true
// >>> is_prime(61)
// true
// >>> is_prime(4)
// false
// >>> is_prime(1)
// false
function is_prime(n){
if (n==1) {
return false;
}
if (n==2) {
return true;
}
if (n%2==0) {
return false;
}
var limit = Math.sqrt(n);
for (var i = 3; i <= limit; i += 2) {
if (n%i==0) { | }
}
return true;
}
| return false; | const assert = require('node:assert');
function test() {
let candidate = is_prime;
assert.deepEqual(candidate(6),false);
assert.deepEqual(candidate(101),true);
assert.deepEqual(candidate(11),true);
assert.deepEqual(candidate(13441),true);
assert.deepEqual(candidate(61),true);
assert.deepEqual(candidate(4),false);
assert.deepEqual(candidate(1),false);
assert.deepEqual(candidate(5),true);
assert.deepEqual(candidate(11),true);
assert.deepEqual(candidate(17),true);
assert.deepEqual(candidate(85),false);
assert.deepEqual(candidate(77),false);
assert.deepEqual(candidate(255379),false);
}
test(); |
humaneval-HumanEval_7_filter_by_substring.json-L11 | js | //Filter an input array of strings only for ones that contain given substring
// >>> filter_by_substring([], "a")
// []
// >>> filter_by_substring(["abc", "bacd", "cde", "array"], "a")
// ["abc", "bacd", "array"]
function filter_by_substring(strings, substring){
var filtered = [];
for(var i = 0; i < strings.length; i++){
if(strings[i].includes(substring)){
filtered.push(strings[i]); | }
return filtered;
} | } | const assert = require('node:assert');
function test() {
let candidate = filter_by_substring;
assert.deepEqual(candidate([], "john"),[]);
assert.deepEqual(candidate(["xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"], "xxx"),["xxx", "xxxAAA", "xxx"]);
assert.deepEqual(candidate(["xxx", "asd", "aaaxxy", "john doe", "xxxAAA", "xxx"], "xx"),["xxx", "aaaxxy", "xxxAAA", "xxx"]);
assert.deepEqual(candidate(["grunt", "trumpet", "prune", "gruesome"], "run"),["grunt", "prune"]);
}
test(); |
humaneval-HumanEval_37_sort_even.json-L9 | 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){
| for(var i = 0; i < l.length; i += 2){
l2.push(l[i])
}
l2.sort(function(a, b){return a - b})
for(var i = 0; i < l2.length; i++){
l[i * 2] = l2[i]
}
return l
}
| var l2 = [] | 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_131_digits.json-L22 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// >>> digits((1l))
// (1l)
// >>> digits((4l))
// (0l)
// >>> digits((235l))
// (15l)
public static long digits(long n) {
if (n < 10) {
return n % 2 == 1 ? n : 0;
} | }
} | return digits(n / 10) * (n % 2 == 1 ? n % 10 : 1); | }
public static void main(String[] args) {
assert(digits((5l)) == (5l));
assert(digits((54l)) == (5l));
assert(digits((120l)) == (1l));
assert(digits((5014l)) == (5l));
assert(digits((98765l)) == (315l));
assert(digits((5576543l)) == (2625l));
assert(digits((2468l)) == (0l));
}
}
|
humaneval-HumanEval_149_sorted_list_sum.json-L31 | js | //Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// >>> list_sort(["aa", "a", "aaa"])
// ["aa"]
// >>> list_sort(["ab", "a", "aaa", "cd"])
// ["ab", "cd"]
function sorted_list_sum(lst){
var result = [];
for(var i = 0; i < lst.length; i++){
if(lst[i].length % 2 == 0){
result.push(lst[i]);
}
}
return result.sort(function(a, b){
if(a.length < b.length){
return -1;
}
else if(a.length > b.length){
return 1;
}
else{ | return -1;
}
else if(a > b){
return 1;
}
else{
return 0;
}
}
});
}
var a = ["aa", "a", "aaa"];
var b = ["ab", "a", "aaa", "cd"]; | if(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_47_median.json-L8 | js | //Return median of elements in the array l.
// >>> median([3, 1, 2, 4, 5])
// 3
// >>> median([-10, 4, 6, 1000, 10, 20])
// 15.0
function median(l){
let middle = Math.floor(l.length / 2); | if (l.length % 2 === 0) {
return (sorted[middle - 1] + sorted[middle]) / 2;
} else {
return sorted[middle];
}
}
| let sorted = l.sort((a, b) => a - b); | const assert = require('node:assert');
function test() {
let candidate = median;
assert.deepEqual(candidate([3, 1, 2, 4, 5]),3);
assert.deepEqual(candidate([-10, 4, 6, 1000, 10, 20]),8.0);
assert.deepEqual(candidate([5]),5);
assert.deepEqual(candidate([6, 5]),5.5);
assert.deepEqual(candidate([8, 1, 3, 9, 9, 2, 7]),7);
}
test(); |
humaneval-HumanEval_103_rounded_avg.json-L18 | py | from typing import Union
def rounded_avg(n: int, m: int) -> Union[str, int]:
"""You are given two positive integers n and m, and your task is to compute the
average of the integers from n through m (including n and m).
Round the answer to the nearest integer and convert that to binary.
If n is greater than m, return -1.
Example:
>>> rounded_avg(1, 5)
'0b11'
>>> rounded_avg(7, 5)
-1
>>> rounded_avg(10, 20)
'0b1111'
>>> rounded_avg(20, 33)
'0b11010'
"""
| rounded_avg = round(((n + m) / 2))
return(bin(rounded_avg))
else:
return(-1) | if n <= m: | def check(candidate):
assert candidate(1, 5) == '0b11'
assert candidate(7, 13) == '0b1010'
assert candidate(964, 977) == '0b1111001010'
assert candidate(996, 997) == '0b1111100100'
assert candidate(560, 851) == '0b1011000010'
assert candidate(185, 546) == '0b101101110'
assert candidate(362, 496) == '0b110101101'
assert candidate(350, 902) == '0b1001110010'
assert candidate(197, 233) == '0b11010111'
assert candidate(7, 5) == -1
assert candidate(5, 1) == -1
assert candidate(5, 5) == '0b101'
def test_check():
check(rounded_avg)
test_check()
|
humaneval-HumanEval_11_string_xor.json-L21 | 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++) {
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 { | }
}
result = arrayXOR.join('');
return result;
} | arrayXOR.push(0); | 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_148_bf.json-L33 | js | //There are eight planets in our solar system: the closerst to the Sun
// is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
// Uranus, Neptune.
// Write a function that takes two planet names as strings planet1 and planet2.
// The function should return an array containing all planets whose orbits are
// located between the orbit of planet1 and the orbit of planet2, sorted by
// the proximity to the sun.
// The function should return an empty array if planet1 or planet2
// are not correct planet names.
// Examples
// >>> bf("Jupiter", "Neptune")
// ["Saturn", "Uranus"]
// >>> bf("Earth", "Mercury")
// "Venus"
// >>> bf("Mercury", "Uranus")
// ["Venus", "Earth", "Mars", "Jupiter", "Saturn"]
function bf(planet1, planet2){
var planets = {
'Mercury':1,
'Venus':2,
'Earth':3,
'Mars':4,
'Jupiter':5,
'Saturn':6,
'Uranus':7,
'Neptune':8
}
if(!planets[planet1] || !planets[planet2]){
return [];
}
var keys = Object.keys(planets);
var position1 = keys.indexOf(planet1); | if(position1 > position2){
var temp = position1;
position1 = position2;
position2 = temp;
}
var res = [];
for(var i = position1 + 1; i < position2; i++){
res.push(keys[i]);
}
return res;
} | var position2 = keys.indexOf(planet2); | const assert = require('node:assert');
function test() {
let candidate = bf;
assert.deepEqual(candidate("Jupiter", "Neptune"),["Saturn", "Uranus"]);
assert.deepEqual(candidate("Earth", "Mercury"),["Venus"]);
assert.deepEqual(candidate("Mercury", "Uranus"),["Venus", "Earth", "Mars", "Jupiter", "Saturn"]);
assert.deepEqual(candidate("Neptune", "Venus"),["Earth", "Mars", "Jupiter", "Saturn", "Uranus"]);
assert.deepEqual(candidate("Earth", "Earth"),[]);
assert.deepEqual(candidate("Mars", "Earth"),[]);
assert.deepEqual(candidate("Jupiter", "Makemake"),[]);
}
test(); |
humaneval-HumanEval_111_histogram.json-L18 | js | //Given a string representing a space separated lowercase letters, return an object
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// >>> histogram("a b c")
// {"a": 1, "b": 1, "c": 1}
// >>> histogram("a b b a")
// {"a": 2, "b": 2}
// >>> histogram("a b c a b")
// {"a": 2, "b": 2}
// >>> histogram("b b b b a")
// {"b": 4}
// >>> histogram("")
// {}
function histogram(test){
if (test.length === 0){
return {}; | var lst = test.split(" ");
var count = {};
for (var i = 0; i < lst.length; i++){
if (count[lst[i]]){
count[lst[i]] += 1;
}
else{
count[lst[i]] = 1;
}
}
console.log(count);
var max = 0;
var result = {};
for (var key in count){
if (count[key] > max){
max = count[key];
result = {};
result[key] = max;
}
else if (count[key] === max){
result[key] = max;
}
}
return result;
}
| } | const assert = require('node:assert');
function test() {
let candidate = histogram;
assert.deepEqual(candidate("a b b a"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c a b"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c d g"),{"a": 1, "b": 1, "c": 1, "d": 1, "g": 1});
assert.deepEqual(candidate("r t g"),{"r": 1, "t": 1, "g": 1});
assert.deepEqual(candidate("b b b b a"),{"b": 4});
assert.deepEqual(candidate("r t g"),{"r": 1, "t": 1, "g": 1});
assert.deepEqual(candidate(""),{});
assert.deepEqual(candidate("a"),{"a": 1});
}
test(); |
humaneval-HumanEval_86_anti_shuffle.json-L32 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// >>> antiShuffle(("Hi"))
// ("Hi")
// >>> antiShuffle(("hello"))
// ("ehllo")
// >>> antiShuffle(("Hello World!!!"))
// ("Hello !!!Wdlor")
public static String antiShuffle(String s) {
StringBuilder sb = new StringBuilder();
String[] words = s.split(" ");
for (String word : words) {
char[] chars = word.toCharArray();
Arrays.sort(chars);
sb.append(new String(chars));
sb.append(" ");
}
sb.deleteCharAt(sb.length() - 1);
return sb.toString(); | } | } | }
public static void main(String[] args) {
assert(antiShuffle(("Hi")).equals(("Hi")));
assert(antiShuffle(("hello")).equals(("ehllo")));
assert(antiShuffle(("number")).equals(("bemnru")));
assert(antiShuffle(("abcd")).equals(("abcd")));
assert(antiShuffle(("Hello World!!!")).equals(("Hello !!!Wdlor")));
assert(antiShuffle(("")).equals(("")));
assert(antiShuffle(("Hi. My name is Mister Robot. How are you?")).equals((".Hi My aemn is Meirst .Rboot How aer ?ouy")));
}
}
|
humaneval-HumanEval_96_count_up_to.json-L23 | js | //Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// >>> count_up_to(5)
// [2, 3]
// >>> count_up_to(11)
// [2, 3, 5, 7]
// >>> count_up_to(0)
// []
// >>> count_up_to(20)
// [2, 3, 5, 7, 11, 13, 17, 19]
// >>> count_up_to(1)
// []
// >>> count_up_to(18)
// [2, 3, 5, 7, 11, 13, 17]
function count_up_to(n){
if (n < 2) return [];
var output = [2];
for (var i = 3; i < n; i += 2){
var prime = true;
for (var j = 3; j < i; j += 2){
if (i % j === 0){ | break;
}
}
if (prime) output.push(i);
}
return output;
}
| prime = false; | const assert = require('node:assert');
function test() {
let candidate = count_up_to;
assert.deepEqual(candidate(5),[2, 3]);
assert.deepEqual(candidate(6),[2, 3, 5]);
assert.deepEqual(candidate(7),[2, 3, 5]);
assert.deepEqual(candidate(10),[2, 3, 5, 7]);
assert.deepEqual(candidate(0),[]);
assert.deepEqual(candidate(22),[2, 3, 5, 7, 11, 13, 17, 19]);
assert.deepEqual(candidate(1),[]);
assert.deepEqual(candidate(18),[2, 3, 5, 7, 11, 13, 17]);
assert.deepEqual(candidate(47),[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]);
assert.deepEqual(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]);
}
test(); |
humaneval-HumanEval_126_is_sorted.json-L51 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of numbers, return whether or not they are sorted
// in ascending order. If array list has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l))))
// (false)
public static boolean isSorted(ArrayList<Long> lst) {
if (lst.size() == 0) {
return true;
}
else {
int running_max = 0;
int previous_number = 0;
boolean first_time = true;
boolean seen_2_in_a_row = false;
for (Long number : lst) {
if (first_time) {
first_time = false;
previous_number = number.intValue();
running_max = number.intValue();
}
else {
if (running_max > number.intValue()) {
return false;
}
else {
if (previous_number == number.intValue()) {
if (seen_2_in_a_row) { | }
else {
seen_2_in_a_row = true;
}
}
else {
seen_2_in_a_row = false;
}
previous_number = number.intValue();
running_max = number.intValue();
}
}
}
return true;
}
}
} | return false; | }
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_35_max_element.json-L8 | js | //Return maximum element in the array.
// >>> max_element([1, 2, 3])
// 3
// >>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
// 123
function max_element(l){
return Math.max.apply(null, l); | } | const assert = require('node:assert');
function test() {
let candidate = max_element;
assert.deepEqual(candidate([1, 2, 3]),3);
assert.deepEqual(candidate([5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]),124);
}
test(); |
|
humaneval-HumanEval_137_compare_one.json-L26 | py | from typing import Union
def compare_one(a: Union[int, float, str], b: Union[int, float, str]) -> Union[int, float, str, None]:
"""
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values are equal.
Note: If a real number is represented as a string, the floating point might be . or ,
>>> compare_one(1, 2.5)
2.5
>>> compare_one(1, '2,3')
'2,3'
>>> compare_one('5,1', '6')
'6'
>>> compare_one('1', 1)
None
"""
if isinstance(a, int) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
return None | if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, str) and isinstance(b, str):
a_tmp = a.replace(',', '.')
b_tmp = b.replace(',', '.')
if float(a_tmp) > float(b_tmp):
return a
elif float(a_tmp) < float(b_tmp):
return b
else:
return None
elif isinstance(a, int) and isinstance(b, float):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, float) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, str) and isinstance(b, int):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b
else:
return None
elif isinstance(a, int) and isinstance(b, str):
b_tmp = b.replace(',', '.')
if a > float(b_tmp):
return a
elif a < float(b_tmp):
return b
else:
return None
elif isinstance(a, str) and isinstance(b, float):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b | elif isinstance(a, float) and isinstance(b, float): | def check(candidate):
assert candidate(1, 2) == 2
assert candidate(1, 2.5) == 2.5
assert candidate(2, 3) == 3
assert candidate(5, 6) == 6
assert candidate(1, '2,3') == '2,3'
assert candidate('5,1', '6') == '6'
assert candidate('1', '2') == '2'
assert candidate('1', 1) == None
def test_check():
check(compare_one)
test_check()
|
humaneval-HumanEval_112_reverse_delete.json-L23 | 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);
} else {
result.push(filterString, false);
} | } | return result; | 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_81_numerical_letter_grade.json-L47 | py | from typing import List
def numerical_letter_grade(grades: List[float]) -> List[str]:
"""It is the last week of the semester and the teacher has to give the grades
to students. The teacher has been making her own algorithm for grading.
The only problem is, she has lost the code she used for grading.
She has given you a list of GPAs for some students and you have to write
a function that can output a list of letter grades using the following table:
GPA | Letter grade
4.0 A+
> 3.7 A
> 3.3 A-
> 3.0 B+
> 2.7 B
> 2.3 B-
> 2.0 C+
> 1.7 C
> 1.3 C-
> 1.0 D+
> 0.7 D
> 0.0 D-
0.0 E
Example:
>>> grade_equation([4.0, 3, 1.7, 2, 3.5])
['A+', 'B', 'C-', 'C', 'A-']
"""
final = []
for x in grades:
if x == 4.0:
final.append('A+')
elif x > 3.7:
final.append('A')
elif x > 3.3:
final.append('A-')
elif x > 3.0:
final.append('B+')
elif x > 2.7:
final.append('B')
elif x > 2.3:
final.append('B-')
elif x > 2.0:
final.append('C+')
elif x > 1.7:
final.append('C') | final.append('C-')
elif x > 1.0:
final.append('D+')
elif x > 0.7:
final.append('D')
elif x > 0.0:
final.append('D-')
else:
final.append('E')
return final
| elif x > 1.3: | def check(candidate):
assert candidate([4.0, 3, 1.7, 2, 3.5]) == ['A+', 'B', 'C-', 'C', 'A-']
assert candidate([1.2]) == ['D+']
assert candidate([0.5]) == ['D-']
assert candidate([0.0]) == ['E']
assert candidate([1.0, 0.3, 1.5, 2.8, 3.3]) == ['D', 'D-', 'C-', 'B', 'B+']
assert candidate([0.0, 0.7]) == ['E', 'D-']
def test_check():
check(numerical_letter_grade)
test_check()
|
humaneval-HumanEval_118_get_closest_vowel.json-L23 | py | def get_closest_vowel(word: str) -> str:
"""You are given a word. Your task is to find the closest vowel that stands between
two consonants from the right side of the word (case sensitive).
Vowels in the beginning and ending doesn't count. Return empty string if you didn't
find any vowel met the above condition.
You may assume that the given string contains English letter only.
Example:
>>> get_closest_vowel('yogurt')
'u'
>>> get_closest_vowel('FULL')
'U'
>>> get_closest_vowel('quick')
''
>>> get_closest_vowel('ab')
''
"""
if len(word) < 3:
return ''
for i in range(len(word) - 2, 0, -1): | return word[i]
return ''
| if word[i] in 'aeiouAEIOU' and word[i-1] not in 'aeiouAEIOU' and word[i+1] not in 'aeiouAEIOU': | def check(candidate):
assert candidate('yogurt') == 'u'
assert candidate('full') == 'u'
assert candidate('easy') == ''
assert candidate('eAsy') == ''
assert candidate('ali') == ''
assert candidate('bad') == 'a'
assert candidate('most') == 'o'
assert candidate('ab') == ''
assert candidate('ba') == ''
assert candidate('quick') == ''
assert candidate('anime') == 'i'
assert candidate('Asia') == ''
assert candidate('Above') == 'o'
def test_check():
check(get_closest_vowel)
test_check()
|
humaneval-HumanEval_153_Strongest_Extension.json-L18 | js | //You will be given the name of a class (a string) and an array 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.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// >>> Strongest_Extension("my_class", ["AA", "Be", "CC"])
// "my_class.AA"
function Strongest_Extension(class_name, extensions){
| var min_strength = 1;
for (var i = 0; i < extensions.length; i++) {
var strength = -1*(extensions[i].replace(/[^A-Z]/g, "").length - extensions[i].replace(/[^a-z]/g, "").length);
if (strength < min_strength) {
min_strength = strength;
output = class_name + "." + extensions[i];
}
}
return output;
}
| var output = class_name + "."; | const assert = require('node:assert');
function test() {
let candidate = Strongest_Extension;
assert.deepEqual(candidate("Watashi", ["tEN", "niNE", "eIGHt8OKe"]),"Watashi.eIGHt8OKe");
assert.deepEqual(candidate("Boku123", ["nani", "NazeDa", "YEs.WeCaNe", "32145tggg"]),"Boku123.YEs.WeCaNe");
assert.deepEqual(candidate("__YESIMHERE", ["t", "eMptY", "nothing", "zeR00", "NuLl__", "123NoooneB321"]),"__YESIMHERE.NuLl__");
assert.deepEqual(candidate("K", ["Ta", "TAR", "t234An", "cosSo"]),"K.TAR");
assert.deepEqual(candidate("__HAHA", ["Tab", "123", "781345", "-_-"]),"__HAHA.123");
assert.deepEqual(candidate("YameRore", ["HhAas", "okIWILL123", "WorkOut", "Fails", "-_-"]),"YameRore.okIWILL123");
assert.deepEqual(candidate("finNNalLLly", ["Die", "NowW", "Wow", "WoW"]),"finNNalLLly.WoW");
assert.deepEqual(candidate("_", ["Bb", "91245"]),"_.Bb");
assert.deepEqual(candidate("Sp", ["671235", "Bb"]),"Sp.671235");
}
test(); |
humaneval-HumanEval_111_histogram.json-L24 | js | //Given a string representing a space separated lowercase letters, return an object
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// >>> histogram("a b c")
// {"a": 1, "b": 1, "c": 1}
// >>> histogram("a b b a")
// {"a": 2, "b": 2}
// >>> histogram("a b c a b")
// {"a": 2, "b": 2}
// >>> histogram("b b b b a")
// {"b": 4}
// >>> histogram("")
// {}
function histogram(test){
if (test.length === 0){
return {};
}
var lst = test.split(" ");
var count = {};
for (var i = 0; i < lst.length; i++){
if (count[lst[i]]){
count[lst[i]] += 1; | else{
count[lst[i]] = 1;
}
}
console.log(count);
var max = 0;
var result = {};
for (var key in count){
if (count[key] > max){
max = count[key];
result = {};
result[key] = max;
}
else if (count[key] === max){
result[key] = max;
}
}
return result;
}
| } | const assert = require('node:assert');
function test() {
let candidate = histogram;
assert.deepEqual(candidate("a b b a"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c a b"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c d g"),{"a": 1, "b": 1, "c": 1, "d": 1, "g": 1});
assert.deepEqual(candidate("r t g"),{"r": 1, "t": 1, "g": 1});
assert.deepEqual(candidate("b b b b a"),{"b": 4});
assert.deepEqual(candidate("r t g"),{"r": 1, "t": 1, "g": 1});
assert.deepEqual(candidate(""),{});
assert.deepEqual(candidate("a"),{"a": 1});
}
test(); |
humaneval-HumanEval_160_do_algebra.json-L50 | js | //Given two arrays operator, and operand. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
function do_algebra(operator, operand){
let do_again;
let count = 0;
let temp;
let answer;
while(count < operator.length){
switch(operator[count]){
case '*':
operand[count] = operand[count] * operand[count + 1];
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
case '//':
operand[count] = Math.floor(operand[count] / operand[count + 1]);
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
case '**':
operand[count] = Math.pow(operand[count], operand[count + 1]);
operand.splice(count + 1, 1);
operator.splice(count, 1);
count = 0;
do_again = true;
break;
default:
count++;
do_again = false; | }
answer = operand[0];
operand.splice(0, 1);
while(operand.length > 0){
switch(operator[0]){
case '+':
answer += operand[0];
break;
case '-':
answer -= operand[0];
break;
}
operand.splice(0, 1);
operator.splice(0, 1);
}
return answer;
}
| } | const assert = require('node:assert');
function test() {
let candidate = do_algebra;
assert.deepEqual(candidate(["**", "*", "+"], [2, 3, 4, 5]),37);
assert.deepEqual(candidate(["+", "*", "-"], [2, 3, 4, 5]),9);
assert.deepEqual(candidate(["//", "*"], [7, 3, 4]),8);
}
test(); |
humaneval-HumanEval_64_vowels_count.json-L16 | py | def vowels_count(s: str) -> int:
"""Write a function vowels_count which takes a string representing
a word as input and returns the number of vowels in the string.
Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
vowel, but only when it is at the end of the given word.
Example:
>>> vowels_count('abcde')
2
>>> vowels_count('ACEDY')
3
"""
s = s.lower()
i = 0
count = 0 | if (s[i] == 'a' or s[i] == 'e' or s[i] == 'i' or s[i] == 'o' or s[i] == 'u'):
count += 1
if (s[i] == 'y' and i == len(s) - 1):
count += 1
i += 1
return count
| while i < len(s): | def check(candidate):
assert candidate('abcde') == 2
assert candidate('Alone') == 3
assert candidate('key') == 2
assert candidate('bye') == 1
assert candidate('keY') == 2
assert candidate('bYe') == 1
assert candidate('ACEDY') == 3
def test_check():
check(vowels_count)
test_check()
|
humaneval-HumanEval_95_check_dict_case.json-L21 | js | //Given an object, return true if all keys are strings in lower
// case or all keys are strings in upper case, else return false.
// The function should return false is the given object is empty.
// Examples:
// >>> check_dict_case({"a": "apple", "b": "banana"})
// true
// >>> check_dict_case({"a": "apple", "A": "banana", "B": "banana"})
// false
// >>> check_dict_case({"a": "apple", 8: "banana", "a": "apple"})
// false
// >>> check_dict_case({"Name": "John", "Age": "36", "City": "Houston"})
// false
// >>> check_dict_case({"STATE": "NC", "ZIP": "12345"})
// true
function check_dict_case(dict){
if (Object.keys(dict).length == 0){
return false;
}
var case_type = -1;
for (let key in dict){ | if (case_type == -1){
if (key == key.toUpperCase()){
case_type = 1;
}
else if (key == key.toLowerCase()){
case_type = 0;
}
else{
return false;
}
}
else if (case_type == 1){
if (key != key.toUpperCase()){
return false;
}
}
else if (case_type == 0){
if (key != key.toLowerCase()){
return false;
}
}
}
else{
return false;
}
}
return true;
} | if (typeof key == "string"){ | const assert = require('node:assert');
function test() {
let candidate = check_dict_case;
assert.deepEqual(candidate({"p": "pineapple", "b": "banana"}),true);
assert.deepEqual(candidate({"p": "pineapple", "A": "banana", "B": "banana"}),false);
assert.deepEqual(candidate({"p": "pineapple", "5": "banana", "a": "apple"}),false);
assert.deepEqual(candidate({"Name": "John", "Age": "36", "City": "Houston"}),false);
assert.deepEqual(candidate({"STATE": "NC", "ZIP": "12345"}),true);
assert.deepEqual(candidate({"fruit": "Orange", "taste": "Sweet"}),true);
assert.deepEqual(candidate({}),false);
}
test(); |
humaneval-HumanEval_3_below_zero.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 {
// 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; | balance += op;
if (balance < 0) {
return true;
}
}
return false;
}
} | for (long op : operations) { | }
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_141_file_name_check.json-L19 | py | def file_name_check(file_name: str) -> str:
"""Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is valid, and returns 'No' otherwise.
A file's name is considered to be valid if and only if all the following conditions
are met:
- There should not be more than three digits ('0'-'9') in the file's name.
- The file's name contains exactly one dot '.'
- The substring before the dot should not be empty, and it starts with a letter from
the latin alphapet ('a'-'z' and 'A'-'Z').
- The substring after the dot should be one of these: ['txt', 'exe', 'dll']
Examples:
>>> file_name_check('example.txt')
'Yes'
>>> file_name_check('1example.dll')
'No'
"""
if not file_name:
return 'No' | e_count = 0
for i in file_name:
if i.isdigit():
s_count += 1
if i == '.':
e_count += 1
if s_count > 3 or e_count != 1:
return 'No'
s_name = file_name.split('.')[0]
e_name = file_name.split('.')[1]
if not s_name or not e_name or not s_name[0].isalpha():
return 'No'
if e_name not in ['txt', 'exe', 'dll']:
return 'No'
return 'Yes'
| s_count = 0 | def check(candidate):
assert candidate('example.txt') == 'Yes'
assert candidate('1example.dll') == 'No'
assert candidate('s1sdf3.asd') == 'No'
assert candidate('K.dll') == 'Yes'
assert candidate('MY16FILE3.exe') == 'Yes'
assert candidate('His12FILE94.exe') == 'No'
assert candidate('_Y.txt') == 'No'
assert candidate('?aREYA.exe') == 'No'
assert candidate('/this_is_valid.dll') == 'No'
assert candidate('this_is_valid.wow') == 'No'
assert candidate('this_is_valid.txt') == 'Yes'
assert candidate('this_is_valid.txtexe') == 'No'
assert candidate('#this2_i4s_5valid.ten') == 'No'
assert candidate('@this1_is6_valid.exe') == 'No'
assert candidate('this_is_12valid.6exe4.txt') == 'No'
assert candidate('all.exe.txt') == 'No'
assert candidate('I563_No.exe') == 'Yes'
assert candidate('Is3youfault.txt') == 'Yes'
assert candidate('no_one#knows.dll') == 'Yes'
assert candidate('1I563_Yes3.exe') == 'No'
assert candidate('I563_Yes3.txtt') == 'No'
assert candidate('final..txt') == 'No'
assert candidate('final132') == 'No'
assert candidate('_f4indsartal132.') == 'No'
assert candidate('.txt') == 'No'
assert candidate('s.') == 'No'
def test_check():
check(file_name_check)
test_check()
|
humaneval-HumanEval_109_move_one_ball.json-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 {
// We have an array array list 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array array list will be randomly ordered. Your task is to determine if
// it is possible to get an array array list sorted in non-decreasing order by performing
// the following operation on the given array array list:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array array list by one
// position in the right direction. The last element of the array array list will be moved to
// the starting position in the array array list i.e. 0th index.
// If it is possible to obtain the sorted array array list by performing the above operation
// then return true else return false.
// If the given array array list is empty then return true.
// Note: The given array list is guaranteed to have unique elements.
// For Example:
// >>> moveOneBall((new ArrayList<Long>(Arrays.asList((long)3l, (long)4l, (long)5l, (long)1l, (long)2l))))
// (true)
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array array list.
// >>> moveOneBall((new ArrayList<Long>(Arrays.asList((long)3l, (long)5l, (long)4l, (long)1l, (long)2l))))
// (false)
// Explanation:It is not possible to get non-decreasing order for the given
// array array list by performing any number of right shift operations.
public static boolean moveOneBall(ArrayList<Long> arr) {
| ArrayList<Long> sorted = new ArrayList<Long>(arr);
Collections.sort(sorted);
for (int i = 0; i < arr.size(); i++) {
ArrayList<Long> copy = new ArrayList<Long>(arr);
long last = copy.remove(copy.size() - 1);
copy.add(0, last);
if (copy.equals(sorted)) return true;
arr = copy;
}
return false;
}
} | if (arr.size() == 0) return true; | }
public static void main(String[] args) {
assert(moveOneBall((new ArrayList<Long>(Arrays.asList((long)3l, (long)4l, (long)5l, (long)1l, (long)2l)))) == (true));
assert(moveOneBall((new ArrayList<Long>(Arrays.asList((long)3l, (long)5l, (long)10l, (long)1l, (long)2l)))) == (true));
assert(moveOneBall((new ArrayList<Long>(Arrays.asList((long)4l, (long)3l, (long)1l, (long)2l)))) == (false));
assert(moveOneBall((new ArrayList<Long>(Arrays.asList((long)3l, (long)5l, (long)4l, (long)1l, (long)2l)))) == (false));
assert(moveOneBall((new ArrayList<Long>(Arrays.asList()))) == (true));
}
}
|
humaneval-HumanEval_94_skjkasdkd.json-L51 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// 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) { | }
else {
long output = 0l;
while (largestPrime > 0) {
output += largestPrime % 10;
largestPrime /= 10;
}
return output;
}
}
} | return 0l; | }
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_148_bf.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 {
// There are eight planets in our solar system: the closerst to the Sun
// is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
// Uranus, Neptune.
// Write a function that takes two planet names as strings planet1 and planet2.
// The function should return a pair containing all planets whose orbits are
// located between the orbit of planet1 and the orbit of planet2, sorted by
// the proximity to the sun.
// The function should return an empty pair if planet1 or planet2
// are not correct planet names.
// Examples
// >>> bf(("Jupiter"), ("Neptune"))
// (new ArrayList<String>(Arrays.asList((String)"Saturn", (String)"Uranus")))
// >>> bf(("Earth"), ("Mercury"))
// (ArrayList<String>("Venus"))
// >>> bf(("Mercury"), ("Uranus"))
// (new ArrayList<String>(Arrays.asList((String)"Venus", (String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn")))
public static ArrayList<String> bf(String planet1, String planet2) {
ArrayList<String> planets = new ArrayList<String>(Arrays.asList((String)"Mercury", (String)"Venus", (String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn", (String)"Uranus", (String)"Neptune"));
int indexPlanet1 = planets.indexOf(planet1);
int indexPlanet2 = planets.indexOf(planet2);
int indexMin = 0;
int indexMax = 0;
if (indexPlanet1 >= 0 && indexPlanet2 >= 0) {
if (indexPlanet1 < indexPlanet2) {
indexMin = indexPlanet1;
indexMax = indexPlanet2;
} else {
indexMin = indexPlanet2;
indexMax = indexPlanet1; | ArrayList<String> planetsInBetween = new ArrayList<String>();
for (int i = indexMin + 1; i < indexMax; i++) {
planetsInBetween.add(planets.get(i));
}
return planetsInBetween;
} else {
return new ArrayList<String>();
}
}
} | } | }
public static void main(String[] args) {
assert(bf(("Jupiter"), ("Neptune")).equals((new ArrayList<String>(Arrays.asList((String)"Saturn", (String)"Uranus")))));
assert(bf(("Earth"), ("Mercury")).equals((new ArrayList<String>(Arrays.asList((String)"Venus")))));
assert(bf(("Mercury"), ("Uranus")).equals((new ArrayList<String>(Arrays.asList((String)"Venus", (String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn")))));
assert(bf(("Neptune"), ("Venus")).equals((new ArrayList<String>(Arrays.asList((String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn", (String)"Uranus")))));
assert(bf(("Earth"), ("Earth")).equals((new ArrayList<String>(Arrays.asList()))));
assert(bf(("Mars"), ("Earth")).equals((new ArrayList<String>(Arrays.asList()))));
assert(bf(("Jupiter"), ("Makemake")).equals((new ArrayList<String>(Arrays.asList()))));
}
}
|
humaneval-HumanEval_152_compare.json-L14 | js | //I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// >>> compare([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2])
// [0, 0, 0, 0, 3, 3]
// >>> compare([0, 5, 0, 0, 0, 4], [4, 1, 1, 0, 0, -2])
// [4, 4, 1, 0, 0, 6]
function compare(game, guess){
| for(let i = 0; i < game.length; i++){
if(game[i] === guess[i]){
result.push(0);
} else {
result.push(Math.abs(game[i] - guess[i]));
}
}
return result;
}
| let result = []; | const assert = require('node:assert');
function test() {
let candidate = compare;
assert.deepEqual(candidate([1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2]),[0, 0, 0, 0, 3, 3]);
assert.deepEqual(candidate([0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]),[0, 0, 0, 0, 0, 0]);
assert.deepEqual(candidate([1, 2, 3], [-1, -2, -3]),[2, 4, 6]);
assert.deepEqual(candidate([1, 2, 3, 5], [-1, 2, 3, 4]),[2, 0, 0, 1]);
}
test(); |
humaneval-HumanEval_124_valid_date.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 have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// >>> validDate(("03-11-2000"))
// (true)
// >>> validDate(("15-01-2012"))
// (false)
// >>> validDate(("04-0-2040"))
// (false)
// >>> validDate(("06-04-2020"))
// (true)
// >>> validDate(("06/04/2020"))
// (false)
public static boolean validDate(String date) {
boolean valid_date = false;
if (date.equals("")) return valid_date;
String[] parts = date.split("-"); | try {
int month = Integer.parseInt(parts[0]);
int day = Integer.parseInt(parts[1]);
int year = Integer.parseInt(parts[2]);
if (month < 1 || month > 12) return valid_date;
if (month == 2) {
if (day < 1 || day > 29) return valid_date;
} else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
if (day < 1 || day > 31) return valid_date;
} else {
if (day < 1 || day > 30) return valid_date;
}
valid_date = true;
} catch (Exception e) {
valid_date = false;
}
return valid_date;
}
} | if (parts.length != 3) return valid_date; | }
public static void main(String[] args) {
assert(validDate(("03-11-2000")) == (true));
assert(validDate(("15-01-2012")) == (false));
assert(validDate(("04-0-2040")) == (false));
assert(validDate(("06-04-2020")) == (true));
assert(validDate(("01-01-2007")) == (true));
assert(validDate(("03-32-2011")) == (false));
assert(validDate(("")) == (false));
assert(validDate(("04-31-3000")) == (false));
assert(validDate(("06-06-2005")) == (true));
assert(validDate(("21-31-2000")) == (false));
assert(validDate(("04-12-2003")) == (true));
assert(validDate(("04122003")) == (false));
assert(validDate(("20030412")) == (false));
assert(validDate(("2003-04")) == (false));
assert(validDate(("2003-04-12")) == (false));
assert(validDate(("04-2003")) == (false));
}
}
|
humaneval-HumanEval_44_change_base.json-L14 | js | //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"
function change_base(x, base){
let r = x % base;
let q = Math.floor(x / base);
if (q === 0) return r.toString(); | }
| return change_base(q, base) + r.toString(); | const assert = require('node:assert');
function test() {
let candidate = change_base;
assert.deepEqual(candidate(8, 3),"22");
assert.deepEqual(candidate(9, 3),"100");
assert.deepEqual(candidate(234, 2),"11101010");
assert.deepEqual(candidate(16, 2),"10000");
assert.deepEqual(candidate(8, 2),"1000");
assert.deepEqual(candidate(7, 2),"111");
assert.deepEqual(candidate(2, 3),"2");
assert.deepEqual(candidate(3, 4),"3");
assert.deepEqual(candidate(4, 5),"4");
assert.deepEqual(candidate(5, 6),"5");
assert.deepEqual(candidate(6, 7),"6");
assert.deepEqual(candidate(7, 8),"7");
}
test(); |
humaneval-HumanEval_125_split_words.json-L26 | js | //Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// >>> split_words("Hello world!")
// ["Hello", "world!"]
// >>> split_words("Hello,world!")
// ["Hello", "world!"]
// >>> split_words("abcdef")
// 3
function split_words(txt){
if(txt.includes(' ')){
return txt.split(' ');
}
else if(txt.includes(',')){
return txt.split(',');
}
else{
let count = 0;
for(let i = 0; i < txt.length; i++){
if(i % 2 != 0){
if(txt[i] == txt[i].toLowerCase()){
count++;
}
} | return count;
}
} | } | const assert = require('node:assert');
function test() {
let candidate = split_words;
assert.deepEqual(candidate("Hello world!"),["Hello", "world!"]);
assert.deepEqual(candidate("Hello,world!"),["Hello", "world!"]);
assert.deepEqual(candidate("Hello world,!"),["Hello", "world,!"]);
assert.deepEqual(candidate("Hello,Hello,world !"),["Hello,Hello,world", "!"]);
assert.deepEqual(candidate("abcdef"),3);
assert.deepEqual(candidate("aaabb"),2);
assert.deepEqual(candidate("aaaBb"),1);
assert.deepEqual(candidate(""),0);
}
test(); |
humaneval-HumanEval_143_words_in_sentence.json-L41 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// >>> wordsInSentence(("This is a test"))
// ("is")
// Example 2:
// >>> wordsInSentence(("lets go for swimming"))
// ("go for")
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
public static String wordsInSentence(String sentence) {
StringBuilder ans = new StringBuilder();
String[] words = sentence.split(" ");
int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
boolean isPrime;
for (String word : words) {
isPrime = false;
for (int prime : primes) {
if (word.length() == prime) {
isPrime = true;
break;
}
}
if (isPrime) {
ans.append(word + " ");
}
}
if (ans.length() > 0) { | }
return ans.toString();
}
} | ans.deleteCharAt(ans.length() - 1); | }
public static void main(String[] args) {
assert(wordsInSentence(("This is a test")).equals(("is")));
assert(wordsInSentence(("lets go for swimming")).equals(("go for")));
assert(wordsInSentence(("there is no place available here")).equals(("there is no place")));
assert(wordsInSentence(("Hi I am Hussein")).equals(("Hi am Hussein")));
assert(wordsInSentence(("go for it")).equals(("go for it")));
assert(wordsInSentence(("here")).equals(("")));
assert(wordsInSentence(("here is")).equals(("is")));
}
}
|
humaneval-HumanEval_2_truncate_number.json-L9 | js | //Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// >>> truncate_number(3.5)
// 0.5
function truncate_number(number){
return number - Math.floor(number); | } | const assert = require('node:assert');
function test() {
let candidate = truncate_number;
assert.deepEqual(candidate(3.5),0.5);
assert.deepEqual(candidate(1.25),0.25);
assert.deepEqual(candidate(123.0),0.0);
}
test(); |
|
humaneval-HumanEval_73_smallest_change.json-L25 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list arr of integers, find the minimum number of elements that
// need to be changed to make the array array list palindromic. A palindromic array array list is an array array list that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// >>> smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)5l, (long)4l, (long)7l, (long)9l, (long)6l))))
// (4l)
// >>> smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)3l, (long)2l, (long)2l))))
// (1l)
// >>> smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)2l, (long)1l))))
// (0l)
public static long smallestChange(ArrayList<Long> arr) {
int first = 0;
int last = arr.size() - 1;
int count = 0;
while (first < last) {
if (arr.get(first) != arr.get(last)) { | }
first++;
last--;
}
return count;
}
} | count++; | }
public static void main(String[] args) {
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)5l, (long)4l, (long)7l, (long)9l, (long)6l)))) == (4l));
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)3l, (long)2l, (long)2l)))) == (1l));
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)2l)))) == (1l));
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)4l, (long)4l, (long)2l)))) == (1l));
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)2l, (long)1l)))) == (0l));
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)3l, (long)1l, (long)1l, (long)3l)))) == (0l));
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)1l)))) == (0l));
assert(smallestChange((new ArrayList<Long>(Arrays.asList((long)0l, (long)1l)))) == (1l));
}
}
|
humaneval-HumanEval_6_parse_nested_parens.json-L15 | js | //Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// >>> parse_nested_parens("(()()) ((())) () ((())()())")
// [2, 3, 1, 3]
function parse_nested_parens(paren_string){
var level = 0;
var maxlevel = 0;
var result = [];
for (var i = 0; i < paren_string.length; i++){
if (paren_string[i] == "("){
level += 1;
if (level > maxlevel){
maxlevel = level; | }
else if (paren_string[i] == ")"){
level -= 1;
}
else if (paren_string[i] == " "){
result.push(maxlevel);
maxlevel = 0;
level = 0;
}
}
result.push(maxlevel);
return result;
}
| } | const assert = require('node:assert');
function test() {
let candidate = parse_nested_parens;
assert.deepEqual(candidate("(()()) ((())) () ((())()())"),[2, 3, 1, 3]);
assert.deepEqual(candidate("() (()) ((())) (((())))"),[1, 2, 3, 4]);
assert.deepEqual(candidate("(()(())((())))"),[4]);
}
test(); |
humaneval-HumanEval_97_multiply.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 {
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// >>> multiply((148l), (412l))
// (16l)
// >>> multiply((19l), (28l))
// (72l)
// >>> multiply((2020l), (1851l))
// (0l)
// >>> multiply((14l), (-15l))
// (20l)
public static long multiply(long a, long b) {
long x = Math.abs(a % 10);
long y = Math.abs(b % 10);
return x * y; | } | } | }
public static void main(String[] args) {
assert(multiply((148l), (412l)) == (16l));
assert(multiply((19l), (28l)) == (72l));
assert(multiply((2020l), (1851l)) == (0l));
assert(multiply((14l), (-15l)) == (20l));
assert(multiply((76l), (67l)) == (42l));
assert(multiply((17l), (27l)) == (49l));
assert(multiply((0l), (1l)) == (0l));
assert(multiply((0l), (0l)) == (0l));
}
}
|
humaneval-HumanEval_87_get_row.json-L24 | js | //You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of arrays, [(x1, y1), (x2, y2) ...] such that
// each array is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// >>> get_row([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1)
// [[0, 0], [1, 4], [1, 0], [2, 5], [2, 0]]
// >>> get_row([], 1)
// []
// >>> get_row([[], [1], [1, 2, 3]], 3)
// [[2, 2]]
function get_row(lst, x){
let coordinates = [];
for (let i = 0; i < lst.length; i++){
let array = lst[i];
for (let j = 0; j < array.length; j++){
if (lst[i][j] === x){
coordinates.push([i, j]);
} | }
return coordinates.sort(function(a, b){
return a[0] - b[0] || b[1] - a[1];
});
}
| } | const assert = require('node:assert');
function test() {
let candidate = get_row;
assert.deepEqual(candidate([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1),[[0, 0], [1, 4], [1, 0], [2, 5], [2, 0]]);
assert.deepEqual(candidate([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6]], 2),[[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1]]);
assert.deepEqual(candidate([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 1, 3, 4, 5, 6], [1, 2, 1, 4, 5, 6], [1, 2, 3, 1, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1),[[0, 0], [1, 0], [2, 1], [2, 0], [3, 2], [3, 0], [4, 3], [4, 0], [5, 4], [5, 0], [6, 5], [6, 0]]);
assert.deepEqual(candidate([], 1),[]);
assert.deepEqual(candidate([[1]], 2),[]);
assert.deepEqual(candidate([[], [1], [1, 2, 3]], 3),[[2, 2]]);
}
test(); |
humaneval-HumanEval_118_get_closest_vowel.json-L33 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// >>> getClosestVowel(("yogurt"))
// ("u")
// >>> getClosestVowel(("FULL"))
// ("U")
// >>> getClosestVowel(("quick"))
// ("")
// >>> getClosestVowel(("ab"))
// ("")
public static String getClosestVowel(String word) {
final String vowels = "aeiou";
final String consonants = "bcdfghjklmnpqrstvwxyz";
List<Integer> idx = new ArrayList<>();
word = word.toLowerCase();
for (int i = 0; i < word.length(); i++) {
if (vowels.indexOf(word.charAt(i)) != -1) {
idx.add(i);
}
} | int j = idx.get(i);
if (j == 0 || j == word.length() - 1) continue;
char left = word.charAt(j - 1);
char right = word.charAt(j + 1);
if (consonants.indexOf(left) != -1 && consonants.indexOf(right) != -1) {
return String.valueOf(word.charAt(j));
}
}
return "";
}
} | for (int i = idx.size() - 1; i >= 0; i--) { | }
public static void main(String[] args) {
assert(getClosestVowel(("yogurt")).equals(("u")));
assert(getClosestVowel(("full")).equals(("u")));
assert(getClosestVowel(("easy")).equals(("")));
assert(getClosestVowel(("eAsy")).equals(("")));
assert(getClosestVowel(("ali")).equals(("")));
assert(getClosestVowel(("bad")).equals(("a")));
assert(getClosestVowel(("most")).equals(("o")));
assert(getClosestVowel(("ab")).equals(("")));
assert(getClosestVowel(("ba")).equals(("")));
assert(getClosestVowel(("quick")).equals(("")));
assert(getClosestVowel(("anime")).equals(("i")));
assert(getClosestVowel(("Asia")).equals(("")));
assert(getClosestVowel(("Above")).equals(("o")));
}
}
|
humaneval-HumanEval_72_will_it_fly.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 returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array list) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// >>> willItFly((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l))), (5l))
// (false)
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// >>> willItFly((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)3l))), (1l))
// (false)
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// >>> willItFly((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)3l))), (9l))
// (true)
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// >>> willItFly((new ArrayList<Long>(Arrays.asList((long)3l))), (5l))
// (true)
// # 3 is less than the maximum possible weight, and it's balanced.
public static boolean willItFly(ArrayList<Long> q, long w) {
if (q.size() == 0) {
return false;
}
if (q.size() == 1) { | }
Long sum = 0l;
for (int i = 0; i < q.size(); i++) {
sum += q.get(i);
}
if (sum > w) {
return false;
}
for (int i = 0; i < q.size() / 2; i++) {
if (q.get(i) != q.get(q.size() - 1 - i)) {
return false;
}
}
return true;
}
} | return true; | }
public static void main(String[] args) {
assert(willItFly((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)3l))), (9l)) == (true));
assert(willItFly((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l))), (5l)) == (false));
assert(willItFly((new ArrayList<Long>(Arrays.asList((long)3l))), (5l)) == (true));
assert(willItFly((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)3l))), (1l)) == (false));
assert(willItFly((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))), (6l)) == (false));
assert(willItFly((new ArrayList<Long>(Arrays.asList((long)5l))), (5l)) == (true));
}
}
|
humaneval-HumanEval_33_sort_third.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 {
// This function takes an array array list l and returns an array array list l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// >>> sortThird((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))
// >>> sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)2l))))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)5l)))
public static ArrayList<Long> sortThird(ArrayList<Long> l) {
ArrayList<Long> l_r = new ArrayList<Long>();
ArrayList<Long> l_e = new ArrayList<Long>();
ArrayList<Long> l_s = new ArrayList<Long>();
for (int i = 0; i < l.size(); i++) {
if (i % 3 == 0) {
l_e.add(l.get(i));
} else {
l_r.add(l.get(i));
}
}
for (int i = 0; i < l_e.size(); i++) {
long min = l_e.get(i);
for (int j = i; j < l_e.size(); j++) {
if (l_e.get(j) < min) {
min = l_e.get(j);
l_e.set(j, l_e.get(i));
l_e.set(i, min);
}
}
}
int j = 0;
for (int i = 0; i < l.size(); i++) { | l_s.add(l_e.get(j));
j++;
} else {
l_s.add(l_r.get(i - j));
}
}
return l_s;
}
} | if (i % 3 == 0) { | }
public static void main(String[] args) {
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)5l)))));
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)8l, (long)3l, (long)4l, (long)6l, (long)9l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)8l, (long)3l, (long)4l, (long)6l, (long)9l, (long)5l)))));
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)9l, (long)4l, (long)8l, (long)3l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)9l, (long)4l, (long)8l, (long)3l, (long)5l)))));
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)2l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)5l, (long)1l)))));
}
}
|
humaneval-HumanEval_27_flip_case.json-L6 | js | //For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// >>> flip_case("Hello")
// "hELLO"
function flip_case(string){
var result = ""; | if(string[i] == string[i].toUpperCase()){
result += string[i].toLowerCase();
}else{
result += string[i].toUpperCase();
}
}
return result;
}
| for(var i = 0; i < string.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = flip_case;
assert.deepEqual(candidate(""),"");
assert.deepEqual(candidate("Hello!"),"hELLO!");
assert.deepEqual(candidate("These violent delights have violent ends"),"tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS");
}
test(); |
humaneval-HumanEval_126_is_sorted.json-L50 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of numbers, return whether or not they are sorted
// in ascending order. If array list has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l))))
// (false)
public static boolean isSorted(ArrayList<Long> lst) {
if (lst.size() == 0) {
return true;
}
else {
int running_max = 0;
int previous_number = 0;
boolean first_time = true;
boolean seen_2_in_a_row = false;
for (Long number : lst) {
if (first_time) {
first_time = false;
previous_number = number.intValue();
running_max = number.intValue();
}
else {
if (running_max > number.intValue()) {
return false;
}
else {
if (previous_number == number.intValue()) { | 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;
}
}
} | if (seen_2_in_a_row) { | }
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_94_skjkasdkd.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 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) { | }
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;
}
}
} | continue; | }
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_118_get_closest_vowel.json-L20 | js | //You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// >>> get_closest_vowel("yogurt")
// "u"
// >>> get_closest_vowel("FULL")
// "U"
// >>> get_closest_vowel("quick")
// ""
// >>> get_closest_vowel("ab")
// ""
function get_closest_vowel(word){
let vowels = ["a", "e", "i", "o", "u"];
let i = word.length - 1;
let result = [];
if (word.length === 1) { | } 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];
}
}
} | return "" | 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_137_compare_one.json-L46 | py | from typing import Union
def compare_one(a: Union[int, float, str], b: Union[int, float, str]) -> Union[int, float, str, None]:
"""
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values are equal.
Note: If a real number is represented as a string, the floating point might be . or ,
>>> compare_one(1, 2.5)
2.5
>>> compare_one(1, '2,3')
'2,3'
>>> compare_one('5,1', '6')
'6'
>>> compare_one('1', 1)
None
"""
if isinstance(a, int) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, float) and isinstance(b, float):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, str) and isinstance(b, str):
a_tmp = a.replace(',', '.')
b_tmp = b.replace(',', '.')
if float(a_tmp) > float(b_tmp):
return a
elif float(a_tmp) < float(b_tmp):
return b
else:
return None
elif isinstance(a, int) and isinstance(b, float):
if a > b:
return a
elif a < b: | else:
return None
elif isinstance(a, float) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, str) and isinstance(b, int):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b
else:
return None
elif isinstance(a, int) and isinstance(b, str):
b_tmp = b.replace(',', '.')
if a > float(b_tmp):
return a
elif a < float(b_tmp):
return b
else:
return None
elif isinstance(a, str) and isinstance(b, float):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b | return b | def check(candidate):
assert candidate(1, 2) == 2
assert candidate(1, 2.5) == 2.5
assert candidate(2, 3) == 3
assert candidate(5, 6) == 6
assert candidate(1, '2,3') == '2,3'
assert candidate('5,1', '6') == '6'
assert candidate('1', '2') == '2'
assert candidate('1', 1) == None
def test_check():
check(compare_one)
test_check()
|
humaneval-HumanEval_66_digitSum.json-L26 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// >>> digitSum((""))
// (0l)
// >>> digitSum(("abAB"))
// (131l)
// >>> digitSum(("abcCd"))
// (67l)
// >>> digitSum(("helloE"))
// (69l)
// >>> digitSum(("woArBld"))
// (131l)
// >>> digitSum(("aAaaaXa"))
// (153l)
public static long digitSum(String s) {
| }
} | return s.chars().filter(i -> i >= 65 && i <= 90).sum(); | }
public static void main(String[] args) {
assert(digitSum(("")) == (0l));
assert(digitSum(("abAB")) == (131l));
assert(digitSum(("abcCd")) == (67l));
assert(digitSum(("helloE")) == (69l));
assert(digitSum(("woArBld")) == (131l));
assert(digitSum(("aAaaaXa")) == (153l));
assert(digitSum((" How are yOu?")) == (151l));
assert(digitSum(("You arE Very Smart")) == (327l));
}
}
|
humaneval-HumanEval_18_how_many_times.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 {
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// >>> howManyTimes((""), ("a"))
// (0l)
// >>> howManyTimes(("aaa"), ("a"))
// (3l)
// >>> howManyTimes(("aaaa"), ("aa"))
// (3l)
public static long howManyTimes(String string, String substring) {
long count = 0;
int index = 0;
while (index != -1) {
index = string.indexOf(substring, index);
if (index != -1) {
index++;
count++; | }
return count;
}
} | } | }
public static void main(String[] args) {
assert(howManyTimes((""), ("x")) == (0l));
assert(howManyTimes(("xyxyxyx"), ("x")) == (4l));
assert(howManyTimes(("cacacacac"), ("cac")) == (4l));
assert(howManyTimes(("john doe"), ("john")) == (1l));
}
}
|
humaneval-HumanEval_61_correct_bracketing.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 {
// 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 false; | }
return balance == 0;
}
} | } | }
public static void main(String[] args) {
assert(correctBracketing(("()")) == (true));
assert(correctBracketing(("(()())")) == (true));
assert(correctBracketing(("()()(()())()")) == (true));
assert(correctBracketing(("()()((()()())())(()()(()))")) == (true));
assert(correctBracketing(("((()())))")) == (false));
assert(correctBracketing((")(()")) == (false));
assert(correctBracketing(("(")) == (false));
assert(correctBracketing(("((((")) == (false));
assert(correctBracketing((")")) == (false));
assert(correctBracketing(("(()")) == (false));
assert(correctBracketing(("()()(()())())(()")) == (false));
assert(correctBracketing(("()()(()())()))()")) == (false));
}
}
|
humaneval-HumanEval_126_is_sorted.json-L52 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of numbers, return whether or not they are sorted
// in ascending order. If array list has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l))))
// (false)
public static boolean isSorted(ArrayList<Long> lst) {
if (lst.size() == 0) {
return true;
}
else {
int running_max = 0;
int previous_number = 0;
boolean first_time = true;
boolean seen_2_in_a_row = false;
for (Long number : lst) {
if (first_time) {
first_time = false;
previous_number = number.intValue();
running_max = number.intValue();
}
else {
if (running_max > number.intValue()) {
return false;
}
else {
if (previous_number == number.intValue()) {
if (seen_2_in_a_row) {
return false; | else {
seen_2_in_a_row = true;
}
}
else {
seen_2_in_a_row = false;
}
previous_number = number.intValue();
running_max = number.intValue();
}
}
}
return true;
}
}
} | } | }
public static void main(String[] args) {
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)5l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList()))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)1l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)3l, (long)3l, (long)4l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))) == (true));
}
}
|
humaneval-HumanEval_111_histogram.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 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_156_int_to_mini_roman.json-L55 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// 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_101_words_string.json-L22 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// 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_66_digitSum.json-L25 | js | //Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// >>> digitSum("")
// 0
// >>> digitSum("abAB")
// 131
// >>> digitSum("abcCd")
// 67
// >>> digitSum("helloE")
// 69
// >>> digitSum("woArBld")
// 131
// >>> digitSum("aAaaaXa")
// 153
function digitSum(s){
var sum = 0;
for(var i = 0; i < s.length; i++){
if(s[i] >= 'A' && s[i] <= 'Z'){
sum += s.charCodeAt(i);
}
}
return sum; | } | const assert = require('node:assert');
function test() {
let candidate = digitSum;
assert.deepEqual(candidate(""),0);
assert.deepEqual(candidate("abAB"),131);
assert.deepEqual(candidate("abcCd"),67);
assert.deepEqual(candidate("helloE"),69);
assert.deepEqual(candidate("woArBld"),131);
assert.deepEqual(candidate("aAaaaXa"),153);
assert.deepEqual(candidate(" How are yOu?"),151);
assert.deepEqual(candidate("You arE Very Smart"),327);
}
test(); |
|
humaneval-HumanEval_129_minPath.json-L61 | 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_138_is_equal_to_sum_even.json-L12 | 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 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;
}
else{
return false;
}
} | for(let j=2;j<n;j+=2){ | 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_16_count_distinct_characters.json-L9 | js | //Given a string, find out how many distinct characters (regardless of case) does it consist of
// >>> count_distinct_characters("xyzXYZ")
// 3
// >>> count_distinct_characters("Jerry")
// 4
function count_distinct_characters(string){
var arr = string.split("");
var result = []; | if(result.indexOf(arr[i].toLowerCase()) < 0){
result.push(arr[i].toLowerCase());
}
}
return result.length;
}
| for(var i = 0; i < arr.length; i++){ | const assert = require('node:assert');
function test() {
let candidate = count_distinct_characters;
assert.deepEqual(candidate(""),0);
assert.deepEqual(candidate("abcde"),5);
assert.deepEqual(candidate("abcdecadeCADE"),5);
assert.deepEqual(candidate("aaaaAAAAaaaa"),1);
assert.deepEqual(candidate("Jerry jERRY JeRRRY"),5);
}
test(); |
humaneval-HumanEval_90_next_smallest.json-L19 | py | from typing import List, Optional
def next_smallest(lst: List[int]) -> Optional[int]:
"""
You are given a list of integers.
Write a function next_smallest() that returns the 2nd smallest element of the list.
Return None if there is no such element.
>>> next_smallest([1, 2, 3, 4, 5])
2
>>> next_smallest([5, 1, 4, 3, 2])
2
>>> next_smallest([])
None
>>> next_smallest([1, 1])
None
"""
if len(lst) < 2:
return None | min2 = max(lst[0], lst[1])
for i in range(2, len(lst)):
if lst[i] < min1:
min2 = min1
min1 = lst[i]
elif lst[i] < min2:
min2 = lst[i]
return min2 if min1 != min2 else None
| min1 = min(lst[0], lst[1]) | def check(candidate):
assert candidate([1, 2, 3, 4, 5]) == 2
assert candidate([5, 1, 4, 3, 2]) == 2
assert candidate([]) == None
assert candidate([1, 1]) == None
assert candidate([1, 1, 1, 1, 0]) == 1
assert candidate([1, 1]) == None
assert candidate([-35, 34, 12, -45]) == -35
def test_check():
check(next_smallest)
test_check()
|
humaneval-HumanEval_58_common.json-L7 | js | //Return sorted unique common elements for two arrays.
// >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121])
// [1, 5, 653]
// >>> common([5, 3, 2, 8], [3, 2])
// [2, 3]
function common(l1, l2){
| }
| return [...new Set(l1.filter(n=>l2.includes(n)))].sort(); | const assert = require('node:assert');
function test() {
let candidate = common;
assert.deepEqual(candidate([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]),[1, 5, 653]);
assert.deepEqual(candidate([5, 3, 2, 8], [3, 2]),[2, 3]);
assert.deepEqual(candidate([4, 3, 2, 8], [3, 2, 4]),[2, 3, 4]);
assert.deepEqual(candidate([4, 3, 2, 8], []),[]);
}
test(); |
humaneval-HumanEval_56_correct_bracketing.json-L21 | py | def correct_bracketing(brackets: str) -> bool:
""" brackets is a string of "<" and ">".
return True if every opening bracket has a corresponding closing bracket.
>>> correct_bracketing('<')
False
>>> correct_bracketing('<>')
True
>>> correct_bracketing('<<><>>')
True
>>> correct_bracketing('><<>')
False
"""
num_left_brackets = 0
for bracket in brackets:
if bracket == '<':
num_left_brackets += 1
elif bracket == '>':
num_left_brackets -= 1
if num_left_brackets < 0: | return num_left_brackets == 0
| return False | def check(candidate):
assert candidate('<>') == True
assert candidate('<<><>>') == True
assert candidate('<><><<><>><>') == True
assert candidate('<><><<<><><>><>><<><><<>>>') == True
assert candidate('<<<><>>>>') == False
assert candidate('><<>') == False
assert candidate('<') == False
assert candidate('<<<<') == False
assert candidate('>') == False
assert candidate('<<>') == False
assert candidate('<><><<><>><>><<>') == False
assert candidate('<><><<><>><>>><>') == False
def test_check():
check(correct_bracketing)
test_check()
|
humaneval-HumanEval_33_sort_third.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 {
// This function takes an array array list l and returns an array array list l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// >>> sortThird((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))
// >>> sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)2l))))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)5l)))
public static ArrayList<Long> sortThird(ArrayList<Long> l) {
ArrayList<Long> l_r = new ArrayList<Long>();
ArrayList<Long> l_e = new ArrayList<Long>();
ArrayList<Long> l_s = new ArrayList<Long>();
for (int i = 0; i < l.size(); i++) {
if (i % 3 == 0) {
l_e.add(l.get(i));
} else {
l_r.add(l.get(i));
}
}
for (int i = 0; i < l_e.size(); i++) {
long min = l_e.get(i);
for (int j = i; j < l_e.size(); j++) {
if (l_e.get(j) < min) {
min = l_e.get(j);
l_e.set(j, l_e.get(i));
l_e.set(i, min); | }
}
int j = 0;
for (int i = 0; i < l.size(); i++) {
if (i % 3 == 0) {
l_s.add(l_e.get(j));
j++;
} else {
l_s.add(l_r.get(i - j));
}
}
return l_s;
}
} | } | }
public static void main(String[] args) {
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)5l)))));
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)8l, (long)3l, (long)4l, (long)6l, (long)9l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)8l, (long)3l, (long)4l, (long)6l, (long)9l, (long)5l)))));
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)9l, (long)4l, (long)8l, (long)3l, (long)2l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)9l, (long)4l, (long)8l, (long)3l, (long)5l)))));
assert(sortThird((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)2l, (long)1l)))).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)6l, (long)3l, (long)4l, (long)8l, (long)9l, (long)5l, (long)1l)))));
}
}
|
humaneval-HumanEval_60_sum_to_n.json-L15 | js | //sum_to_n is a function that sums numbers from 1 to n.
// >>> sum_to_n(30)
// 465
// >>> sum_to_n(100)
// 5050
// >>> sum_to_n(5)
// 15
// >>> sum_to_n(10)
// 55
// >>> sum_to_n(1)
// 1
function sum_to_n(n){
var sum = 0;
for(var i = 1; i <= n; i++){ | }
return sum;
}
| sum += i; | const assert = require('node:assert');
function test() {
let candidate = sum_to_n;
assert.deepEqual(candidate(1),1);
assert.deepEqual(candidate(6),21);
assert.deepEqual(candidate(11),66);
assert.deepEqual(candidate(30),465);
assert.deepEqual(candidate(100),5050);
}
test(); |
humaneval-HumanEval_149_sorted_list_sum.json-L36 | js | //Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// >>> list_sort(["aa", "a", "aaa"])
// ["aa"]
// >>> list_sort(["ab", "a", "aaa", "cd"])
// ["ab", "cd"]
function sorted_list_sum(lst){
var result = [];
for(var i = 0; i < lst.length; i++){
if(lst[i].length % 2 == 0){
result.push(lst[i]);
}
}
return result.sort(function(a, b){
if(a.length < b.length){
return -1;
}
else if(a.length > b.length){
return 1;
}
else{
if(a < b){
return -1;
}
else if(a > b){
return 1; | else{
return 0;
}
}
});
}
var a = ["aa", "a", "aaa"];
var b = ["ab", "a", "aaa", "cd"]; | } | const assert = require('node:assert');
function test() {
let candidate = sorted_list_sum;
assert.deepEqual(candidate(["aa", "a", "aaa"]),["aa"]);
assert.deepEqual(candidate(["school", "AI", "asdf", "b"]),["AI", "asdf", "school"]);
assert.deepEqual(candidate(["d", "b", "c", "a"]),[]);
assert.deepEqual(candidate(["d", "dcba", "abcd", "a"]),["abcd", "dcba"]);
assert.deepEqual(candidate(["AI", "ai", "au"]),["AI", "ai", "au"]);
assert.deepEqual(candidate(["a", "b", "b", "c", "c", "a"]),[]);
assert.deepEqual(candidate(["aaaa", "bbbb", "dd", "cc"]),["cc", "dd", "aaaa", "bbbb"]);
}
test(); |
humaneval-HumanEval_137_compare_one.json-L77 | py | from typing import Union
def compare_one(a: Union[int, float, str], b: Union[int, float, str]) -> Union[int, float, str, None]:
"""
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values are equal.
Note: If a real number is represented as a string, the floating point might be . or ,
>>> compare_one(1, 2.5)
2.5
>>> compare_one(1, '2,3')
'2,3'
>>> compare_one('5,1', '6')
'6'
>>> compare_one('1', 1)
None
"""
if isinstance(a, int) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, float) and isinstance(b, float):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, str) and isinstance(b, str):
a_tmp = a.replace(',', '.')
b_tmp = b.replace(',', '.')
if float(a_tmp) > float(b_tmp):
return a
elif float(a_tmp) < float(b_tmp):
return b
else:
return None
elif isinstance(a, int) and isinstance(b, float):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, float) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, str) and isinstance(b, int):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b
else:
return None
elif isinstance(a, int) and isinstance(b, str):
b_tmp = b.replace(',', '.')
if a > float(b_tmp):
return a
elif a < float(b_tmp):
return b
else:
return None
elif isinstance(a, str) and isinstance(b, float):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b: | return b | def check(candidate):
assert candidate(1, 2) == 2
assert candidate(1, 2.5) == 2.5
assert candidate(2, 3) == 3
assert candidate(5, 6) == 6
assert candidate(1, '2,3') == '2,3'
assert candidate('5,1', '6') == '6'
assert candidate('1', '2') == '2'
assert candidate('1', 1) == None
def test_check():
check(compare_one)
test_check()
|
|
humaneval-HumanEval_127_intersection.json-L28 | js | //You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// >>> intersection([1, 2], [2, 3])
// "NO"
// >>> intersection([-1, 1], [0, 4])
// "NO"
// >>> intersection([-3, -1], [-5, 5])
// "YES"
function intersection(interval1, interval2){
let start = Math.max(interval1[0], interval2[0]);
let end = Math.min(interval1[1], interval2[1]);
if (start >= end) {
return "NO";
}
let length = end - start;
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]; | }
| return primes.includes(length) ? "YES" : "NO"; | const assert = require('node:assert');
function test() {
let candidate = intersection;
assert.deepEqual(candidate([1, 2], [2, 3]),"NO");
assert.deepEqual(candidate([-1, 1], [0, 4]),"NO");
assert.deepEqual(candidate([-3, -1], [-5, 5]),"YES");
assert.deepEqual(candidate([-2, 2], [-4, 0]),"YES");
assert.deepEqual(candidate([-11, 2], [-1, -1]),"NO");
assert.deepEqual(candidate([1, 2], [3, 5]),"NO");
assert.deepEqual(candidate([1, 2], [1, 2]),"NO");
assert.deepEqual(candidate([-2, -2], [-3, -2]),"NO");
}
test(); |
humaneval-HumanEval_148_bf.json-L39 | js | //There are eight planets in our solar system: the closerst to the Sun
// is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
// Uranus, Neptune.
// Write a function that takes two planet names as strings planet1 and planet2.
// The function should return an array containing all planets whose orbits are
// located between the orbit of planet1 and the orbit of planet2, sorted by
// the proximity to the sun.
// The function should return an empty array if planet1 or planet2
// are not correct planet names.
// Examples
// >>> bf("Jupiter", "Neptune")
// ["Saturn", "Uranus"]
// >>> bf("Earth", "Mercury")
// "Venus"
// >>> bf("Mercury", "Uranus")
// ["Venus", "Earth", "Mars", "Jupiter", "Saturn"]
function bf(planet1, planet2){
var planets = {
'Mercury':1,
'Venus':2,
'Earth':3,
'Mars':4,
'Jupiter':5,
'Saturn':6,
'Uranus':7,
'Neptune':8
}
if(!planets[planet1] || !planets[planet2]){
return [];
}
var keys = Object.keys(planets);
var position1 = keys.indexOf(planet1);
var position2 = keys.indexOf(planet2);
if(position1 > position2){
var temp = position1;
position1 = position2;
position2 = temp;
} | for(var i = position1 + 1; i < position2; i++){
res.push(keys[i]);
}
return res;
} | var res = []; | const assert = require('node:assert');
function test() {
let candidate = bf;
assert.deepEqual(candidate("Jupiter", "Neptune"),["Saturn", "Uranus"]);
assert.deepEqual(candidate("Earth", "Mercury"),["Venus"]);
assert.deepEqual(candidate("Mercury", "Uranus"),["Venus", "Earth", "Mars", "Jupiter", "Saturn"]);
assert.deepEqual(candidate("Neptune", "Venus"),["Earth", "Mars", "Jupiter", "Saturn", "Uranus"]);
assert.deepEqual(candidate("Earth", "Earth"),[]);
assert.deepEqual(candidate("Mars", "Earth"),[]);
assert.deepEqual(candidate("Jupiter", "Makemake"),[]);
}
test(); |
humaneval-HumanEval_25_factorize.json-L19 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Return array list of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be array listed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// >>> factorize((8l))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)2l, (long)2l)))
// >>> factorize((25l))
// (new ArrayList<Long>(Arrays.asList((long)5l, (long)5l)))
// >>> factorize((70l))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)5l, (long)7l)))
public static ArrayList<Long> factorize(long n) {
| for (long d = 2; d*d <= n; d++) {
while (n % d == 0) {
factors.add(d);
n /= d;
}
}
if (n > 1)
factors.add(n);
return factors;
}
} | ArrayList<Long> factors = new ArrayList<Long>(); | }
public static void main(String[] args) {
assert(factorize((2l)).equals((new ArrayList<Long>(Arrays.asList((long)2l)))));
assert(factorize((4l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)2l)))));
assert(factorize((8l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)2l, (long)2l)))));
assert(factorize((57l)).equals((new ArrayList<Long>(Arrays.asList((long)3l, (long)19l)))));
assert(factorize((3249l)).equals((new ArrayList<Long>(Arrays.asList((long)3l, (long)3l, (long)19l, (long)19l)))));
assert(factorize((185193l)).equals((new ArrayList<Long>(Arrays.asList((long)3l, (long)3l, (long)3l, (long)19l, (long)19l, (long)19l)))));
assert(factorize((20577l)).equals((new ArrayList<Long>(Arrays.asList((long)3l, (long)19l, (long)19l, (long)19l)))));
assert(factorize((18l)).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)3l)))));
}
}
|
humaneval-HumanEval_37_sort_even.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 {
// This function takes an array array list l and returns an array array list l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// >>> sortEven((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l))))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))
// >>> sortEven((new ArrayList<Long>(Arrays.asList((long)5l, (long)6l, (long)3l, (long)4l))))
// (new ArrayList<Long>(Arrays.asList((long)3l, (long)6l, (long)5l, (long)4l)))
public static ArrayList<Long> sortEven(ArrayList<Long> l) {
ArrayList<Long> res = new ArrayList<Long>();
ArrayList<Long> evenIndexed = new ArrayList<Long>();
int index = 0;
for (Long num : l) {
if (index % 2 == 0) {
evenIndexed.add(num);
}
index++;
}
Collections.sort(evenIndexed);
index = 0;
for (Long num : l) {
if (index % 2 == 0) {
res.add(evenIndexed.get(0));
evenIndexed.remove(0);
} else {
res.add(num);
}
index++; | return res;
}
} | } | }
public static void main(String[] args) {
assert(sortEven((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l)))));
assert(sortEven((new ArrayList<Long>(Arrays.asList((long)5l, (long)3l, (long)-5l, (long)2l, (long)-3l, (long)3l, (long)9l, (long)0l, (long)123l, (long)1l, (long)-10l)))).equals((new ArrayList<Long>(Arrays.asList((long)-10l, (long)3l, (long)-5l, (long)2l, (long)-3l, (long)3l, (long)5l, (long)0l, (long)9l, (long)1l, (long)123l)))));
assert(sortEven((new ArrayList<Long>(Arrays.asList((long)5l, (long)8l, (long)-12l, (long)4l, (long)23l, (long)2l, (long)3l, (long)11l, (long)12l, (long)-10l)))).equals((new ArrayList<Long>(Arrays.asList((long)-12l, (long)8l, (long)3l, (long)4l, (long)5l, (long)2l, (long)12l, (long)11l, (long)23l, (long)-10l)))));
}
}
|
humaneval-HumanEval_83_starts_one_ends.json-L11 | 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_96_count_up_to.json-L21 | 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: | result = []
for number in range(2, n):
is_prime = True
for divisor in range(2, number):
if number % divisor == 0:
is_prime = False
break
if is_prime:
result.append(number)
return result
| return [] | 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_106_f.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 {
// Implement the function f that takes n as a parameter,
// and returns an array array list of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// >>> f((5l))
// (new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l)))
public static ArrayList<Long> f(long n) {
ArrayList<Long> ret = new ArrayList<Long>();
for (long i = 1l; i <= n; i++) {
long v = 0l;
if (i % 2 == 0) {
v = 1l;
for (long j = 2l; j <= i; j++) {
v *= j;
}
} else {
v = (i * (i + 1l)) / 2l;
}
ret.add(v);
}
return ret;
} | } | }
public static void main(String[] args) {
assert(f((5l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l)))));
assert(f((7l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l, (long)24l, (long)15l, (long)720l, (long)28l)))));
assert(f((1l)).equals((new ArrayList<Long>(Arrays.asList((long)1l)))));
assert(f((3l)).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)6l)))));
}
}
|
|
humaneval-HumanEval_149_sorted_list_sum.json-L26 | js | //Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// >>> list_sort(["aa", "a", "aaa"])
// ["aa"]
// >>> list_sort(["ab", "a", "aaa", "cd"])
// ["ab", "cd"]
function sorted_list_sum(lst){
var result = [];
for(var i = 0; i < lst.length; i++){
if(lst[i].length % 2 == 0){
result.push(lst[i]);
}
}
return result.sort(function(a, b){
if(a.length < b.length){
return -1; | else if(a.length > b.length){
return 1;
}
else{
if(a < b){
return -1;
}
else if(a > b){
return 1;
}
else{
return 0;
}
}
});
}
var a = ["aa", "a", "aaa"];
var b = ["ab", "a", "aaa", "cd"]; | } | const assert = require('node:assert');
function test() {
let candidate = sorted_list_sum;
assert.deepEqual(candidate(["aa", "a", "aaa"]),["aa"]);
assert.deepEqual(candidate(["school", "AI", "asdf", "b"]),["AI", "asdf", "school"]);
assert.deepEqual(candidate(["d", "b", "c", "a"]),[]);
assert.deepEqual(candidate(["d", "dcba", "abcd", "a"]),["abcd", "dcba"]);
assert.deepEqual(candidate(["AI", "ai", "au"]),["AI", "ai", "au"]);
assert.deepEqual(candidate(["a", "b", "b", "c", "c", "a"]),[]);
assert.deepEqual(candidate(["aaaa", "bbbb", "dd", "cc"]),["cc", "dd", "aaaa", "bbbb"]);
}
test(); |
humaneval-HumanEval_39_prime_fib.json-L36 | 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; | }
return b;
}
var res = 0;
var fibNum = 0;
while(res < n){
if(isPrime(fib(fibNum))){
res++;
}
fibNum++;
}
return fib(fibNum - 1);
} | num--; | 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_33_sort_third.json-L19 | js | //This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// >>> sort_third([1, 2, 3])
// [1, 2, 3]
// >>> sort_third([5, 6, 3, 4, 8, 9, 2])
// [2, 6, 3, 4, 8, 9, 5]
function sort_third(l){
let x=[];
let y=[];
let k=0;
for(let i=0;i<l.length;i++){
if(i%3==0){
y[k]=l[i];
k=k+1;
}
else{
x[i]=l[i]; | }
y.sort();
k=0;
for(let i=0;i<l.length;i++){
if(i%3==0){
x[i]=y[k];
k=k+1;
}
}
return x;
} | } | const assert = require('node:assert');
function test() {
let candidate = sort_third;
assert.deepEqual(candidate([5, 6, 3, 4, 8, 9, 2]),[2, 6, 3, 4, 8, 9, 5]);
assert.deepEqual(candidate([5, 8, 3, 4, 6, 9, 2]),[2, 8, 3, 4, 6, 9, 5]);
assert.deepEqual(candidate([5, 6, 9, 4, 8, 3, 2]),[2, 6, 9, 4, 8, 3, 5]);
assert.deepEqual(candidate([5, 6, 3, 4, 8, 9, 2, 1]),[2, 6, 3, 4, 8, 9, 5, 1]);
}
test(); |
humaneval-HumanEval_126_is_sorted.json-L25 | js | //Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> is_sorted([5])
// true
// >>> is_sorted([1, 2, 3, 4, 5])
// true
// >>> is_sorted([1, 3, 2, 4, 5])
// false
// >>> is_sorted([1, 2, 3, 4, 5, 6])
// true
// >>> is_sorted([1, 2, 3, 4, 5, 6, 7])
// true
// >>> is_sorted([1, 3, 2, 4, 5, 6, 7])
// false
// >>> is_sorted([1, 2, 2, 3, 3, 4])
// true
// >>> is_sorted([1, 2, 2, 2, 3, 4])
// false
function is_sorted(lst){
var last = null;
var dupe_found = false;
for (var x of lst){ | last = x;
} else if (x < last){
return false;
} else if (x == last){
if (dupe_found){
return false;
} else {
dupe_found = true;
}
} else {
last = x;
dupe_found = false;
}
}
return true;
}
| if (last == null){ | const assert = require('node:assert');
function test() {
let candidate = is_sorted;
assert.deepEqual(candidate([5]),true);
assert.deepEqual(candidate([1, 2, 3, 4, 5]),true);
assert.deepEqual(candidate([1, 3, 2, 4, 5]),false);
assert.deepEqual(candidate([1, 2, 3, 4, 5, 6]),true);
assert.deepEqual(candidate([1, 2, 3, 4, 5, 6, 7]),true);
assert.deepEqual(candidate([1, 3, 2, 4, 5, 6, 7]),false);
assert.deepEqual(candidate([]),true);
assert.deepEqual(candidate([1]),true);
assert.deepEqual(candidate([3, 2, 1]),false);
assert.deepEqual(candidate([1, 2, 2, 2, 3, 4]),false);
assert.deepEqual(candidate([1, 2, 3, 3, 3, 4]),false);
assert.deepEqual(candidate([1, 2, 2, 3, 3, 4]),true);
assert.deepEqual(candidate([1, 2, 3, 4]),true);
}
test(); |
humaneval-HumanEval_21_rescale_to_unit.json-L8 | js | //Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// >>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0])
// [0.0, 0.25, 0.5, 0.75, 1.0]
function rescale_to_unit(numbers){
var min = Math.min.apply(Math, numbers);
var max = Math.max.apply(Math, numbers); | var unit = [];
for (var i = 0; i < numbers.length; i++) {
unit.push((numbers[i] - min) / sub);
}
return unit;
}
| var sub = max - min; | const assert = require('node:assert');
function test() {
let candidate = rescale_to_unit;
assert.deepEqual(candidate([2.0, 49.9]),[0.0, 1.0]);
assert.deepEqual(candidate([100.0, 49.9]),[1.0, 0.0]);
assert.deepEqual(candidate([1.0, 2.0, 3.0, 4.0, 5.0]),[0.0, 0.25, 0.5, 0.75, 1.0]);
assert.deepEqual(candidate([2.0, 1.0, 5.0, 3.0, 4.0]),[0.25, 0.0, 1.0, 0.5, 0.75]);
assert.deepEqual(candidate([12.0, 11.0, 15.0, 13.0, 14.0]),[0.25, 0.0, 1.0, 0.5, 0.75]);
}
test(); |
humaneval-HumanEval_69_search.json-L27 | py | from typing import List
def search(lst: List[int]) -> int:
"""
You are given a non-empty list of positive integers. Return the greatest integer that is greater than
zero, and has a frequency greater than or equal to the value of the integer itself.
The frequency of an integer is the number of times it appears in the list.
If no such a value exist, return -1.
Examples:
>>> search([4, 1, 2, 2, 3, 1])
2
>>> search([1, 2, 2, 3, 3, 3, 4, 4, 4])
3
>>> search([5, 5, 4, 4, 4])
-1
"""
dic = dict()
for i in lst:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
maxValue = -1
for key, value in dic.items():
if value >= key and key > maxValue:
maxValue = key | return maxValue | def check(candidate):
assert candidate([5, 5, 5, 5, 1]) == 1
assert candidate([4, 1, 4, 1, 4, 4]) == 4
assert candidate([3, 3]) == -1
assert candidate([8, 8, 8, 8, 8, 8, 8, 8]) == 8
assert candidate([2, 3, 3, 2, 2]) == 2
assert candidate([2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1]) == 1
assert candidate([3, 2, 8, 2]) == 2
assert candidate([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]) == 1
assert candidate([8, 8, 3, 6, 5, 6, 4]) == -1
assert candidate([6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9]) == 1
assert candidate([1, 9, 10, 1, 3]) == 1
assert candidate([6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10]) == 5
assert candidate([1]) == 1
assert candidate([8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5]) == 4
assert candidate([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]) == 2
assert candidate([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]) == 1
assert candidate([9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4]) == 4
assert candidate([2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7]) == 4
assert candidate([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]) == 2
assert candidate([5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8]) == -1
assert candidate([10]) == -1
assert candidate([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]) == 2
assert candidate([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]) == 1
assert candidate([7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6]) == 1
assert candidate([3, 10, 10, 9, 2]) == -1
def test_check():
check(search)
test_check()
|
|
humaneval-HumanEval_156_int_to_mini_roman.json-L54 | 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"; | }
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;
}
} | num -= 40; | }
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_123_get_odd_collatz.json-L39 | js | //Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// >>> get_odd_collatz(5)
// [1, 5]
function get_odd_collatz(n){
var collatz_sequence = []
var odd_numbers = []
var odd_count = 0
collatz_sequence.push(n)
for(var i = 0; i < collatz_sequence.length; i++){
if(collatz_sequence[i]%2 == 0){
collatz_sequence.push(collatz_sequence[i]/2)
}
else if(collatz_sequence[i]%2 == 1){
collatz_sequence.push(collatz_sequence[i]*3+1)
}
if(collatz_sequence[i]%2 == 1){
odd_numbers.push(collatz_sequence[i])
odd_count += 1
}
if(collatz_sequence[i] == 1){
break
}
}
if(odd_count != 0){
odd_numbers.sort(function(a, b){return a-b})
return odd_numbers
}
else{ | return odd_numbers
}
}
| odd_numbers.push(1) | const assert = require('node:assert');
function test() {
let candidate = get_odd_collatz;
assert.deepEqual(candidate(14),[1, 5, 7, 11, 13, 17]);
assert.deepEqual(candidate(5),[1, 5]);
assert.deepEqual(candidate(12),[1, 3, 5]);
assert.deepEqual(candidate(1),[1]);
}
test(); |
humaneval-HumanEval_111_histogram.json-L41 | js | //Given a string representing a space separated lowercase letters, return an object
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// >>> histogram("a b c")
// {"a": 1, "b": 1, "c": 1}
// >>> histogram("a b b a")
// {"a": 2, "b": 2}
// >>> histogram("a b c a b")
// {"a": 2, "b": 2}
// >>> histogram("b b b b a")
// {"b": 4}
// >>> histogram("")
// {}
function histogram(test){
if (test.length === 0){
return {};
}
var lst = test.split(" ");
var count = {};
for (var i = 0; i < lst.length; i++){
if (count[lst[i]]){
count[lst[i]] += 1;
}
else{
count[lst[i]] = 1;
}
}
console.log(count);
var max = 0;
var result = {};
for (var key in count){
if (count[key] > max){
max = count[key];
result = {};
result[key] = max;
}
else if (count[key] === max){
result[key] = max;
} | return result;
}
| } | const assert = require('node:assert');
function test() {
let candidate = histogram;
assert.deepEqual(candidate("a b b a"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c a b"),{"a": 2, "b": 2});
assert.deepEqual(candidate("a b c d g"),{"a": 1, "b": 1, "c": 1, "d": 1, "g": 1});
assert.deepEqual(candidate("r t g"),{"r": 1, "t": 1, "g": 1});
assert.deepEqual(candidate("b b b b a"),{"b": 4});
assert.deepEqual(candidate("r t g"),{"r": 1, "t": 1, "g": 1});
assert.deepEqual(candidate(""),{});
assert.deepEqual(candidate("a"),{"a": 1});
}
test(); |
humaneval-HumanEval_137_compare_one.json-L44 | py | from typing import Union
def compare_one(a: Union[int, float, str], b: Union[int, float, str]) -> Union[int, float, str, None]:
"""
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values are equal.
Note: If a real number is represented as a string, the floating point might be . or ,
>>> compare_one(1, 2.5)
2.5
>>> compare_one(1, '2,3')
'2,3'
>>> compare_one('5,1', '6')
'6'
>>> compare_one('1', 1)
None
"""
if isinstance(a, int) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, float) and isinstance(b, float):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, str) and isinstance(b, str):
a_tmp = a.replace(',', '.')
b_tmp = b.replace(',', '.')
if float(a_tmp) > float(b_tmp):
return a
elif float(a_tmp) < float(b_tmp):
return b
else:
return None
elif isinstance(a, int) and isinstance(b, float):
if a > b: | elif a < b:
return b
else:
return None
elif isinstance(a, float) and isinstance(b, int):
if a > b:
return a
elif a < b:
return b
else:
return None
elif isinstance(a, str) and isinstance(b, int):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b
else:
return None
elif isinstance(a, int) and isinstance(b, str):
b_tmp = b.replace(',', '.')
if a > float(b_tmp):
return a
elif a < float(b_tmp):
return b
else:
return None
elif isinstance(a, str) and isinstance(b, float):
a_tmp = a.replace(',', '.')
if float(a_tmp) > b:
return a
elif float(a_tmp) < b:
return b | return a | def check(candidate):
assert candidate(1, 2) == 2
assert candidate(1, 2.5) == 2.5
assert candidate(2, 3) == 3
assert candidate(5, 6) == 6
assert candidate(1, '2,3') == '2,3'
assert candidate('5,1', '6') == '6'
assert candidate('1', '2') == '2'
assert candidate('1', 1) == None
def test_check():
check(compare_one)
test_check()
|
humaneval-HumanEval_126_is_sorted.json-L66 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of numbers, return whether or not they are sorted
// in ascending order. If array list has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l))))
// (false)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l))))
// (true)
// >>> isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l))))
// (false)
public static boolean isSorted(ArrayList<Long> lst) {
if (lst.size() == 0) {
return true;
}
else {
int running_max = 0;
int previous_number = 0;
boolean first_time = true;
boolean seen_2_in_a_row = false;
for (Long number : lst) {
if (first_time) {
first_time = false;
previous_number = number.intValue();
running_max = number.intValue();
}
else {
if (running_max > number.intValue()) {
return false;
}
else {
if (previous_number == number.intValue()) {
if (seen_2_in_a_row) {
return false;
}
else {
seen_2_in_a_row = true;
}
}
else {
seen_2_in_a_row = false;
}
previous_number = number.intValue();
running_max = number.intValue();
}
}
}
return true; | }
} | } | }
public static void main(String[] args) {
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)5l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l, (long)5l, (long)6l, (long)7l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)3l, (long)2l, (long)4l, (long)5l, (long)6l, (long)7l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList()))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)3l, (long)2l, (long)1l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)2l, (long)3l, (long)4l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)3l, (long)3l, (long)4l)))) == (false));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)2l, (long)3l, (long)3l, (long)4l)))) == (true));
assert(isSorted((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))) == (true));
}
}
|
humaneval-HumanEval_102_choose_num.json-L24 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// >>> chooseNum((12l), (15l))
// (14l)
// >>> chooseNum((13l), (12l))
// (-1l)
public static long chooseNum(long x, long y) {
long chosen = -1;
for (long i = x; i <= y; i++) {
if (i % 2 == 0) {
chosen = i;
}
} | }
} | return chosen; | }
public static void main(String[] args) {
assert(chooseNum((12l), (15l)) == (14l));
assert(chooseNum((13l), (12l)) == (-1l));
assert(chooseNum((33l), (12354l)) == (12354l));
assert(chooseNum((5234l), (5233l)) == (-1l));
assert(chooseNum((6l), (29l)) == (28l));
assert(chooseNum((27l), (10l)) == (-1l));
assert(chooseNum((7l), (7l)) == (-1l));
assert(chooseNum((546l), (546l)) == (546l));
}
}
|
humaneval-HumanEval_114_minSubArraySum.json-L18 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given 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; | 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;
}
} | long prevMinSum = Long.MAX_VALUE; | }
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_46_fib4.json-L23 | py | def fib4(n: int) -> int:
"""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
"""
if n == 0:
return 0
elif n == 1:
return 0
elif n == 2:
return 2
elif n == 3: | else:
return fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4)
| return 0 | def check(candidate):
assert candidate(5) == 4
assert candidate(8) == 28
assert candidate(10) == 104
assert candidate(12) == 386
def test_check():
check(fib4)
test_check()
|
humaneval-HumanEval_110_exchange.json-L38 | js | //In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// >>> exchange([1, 2, 3, 4], [1, 2, 3, 4])
// "YES"
// >>> exchange([1, 2, 3, 4], [1, 5, 3, 4])
// "NO"
// It is assumed that the input arrays will be non-empty.
function exchange(lst1, lst2){
var num1 = 0;
var num2 = 0;
var exchange = true;
while(num1 < lst1.length && exchange){
if(lst1[num1] % 2 !== 0){
exchange = false;
if(num2 < lst2.length){
while(num2 < lst2.length && exchange == false){
if(lst2[num2] % 2 == 0){
lst1[num1] = lst2[num2];
exchange = true;
}
num2++;
}
}
}
num1++;
}
if(exchange){
return "YES";
}else{
return "NO";
} | } | const assert = require('node:assert');
function test() {
let candidate = exchange;
assert.deepEqual(candidate([1, 2, 3, 4], [1, 2, 3, 4]),"YES");
assert.deepEqual(candidate([1, 2, 3, 4], [1, 5, 3, 4]),"NO");
assert.deepEqual(candidate([1, 2, 3, 4], [2, 1, 4, 3]),"YES");
assert.deepEqual(candidate([5, 7, 3], [2, 6, 4]),"YES");
assert.deepEqual(candidate([5, 7, 3], [2, 6, 3]),"NO");
assert.deepEqual(candidate([3, 2, 6, 1, 8, 9], [3, 5, 5, 1, 1, 1]),"NO");
assert.deepEqual(candidate([100, 200], [200, 200]),"YES");
}
test(); |
|
humaneval-HumanEval_110_exchange.json-L19 | js | //In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// >>> exchange([1, 2, 3, 4], [1, 2, 3, 4])
// "YES"
// >>> exchange([1, 2, 3, 4], [1, 5, 3, 4])
// "NO"
// It is assumed that the input arrays will be non-empty.
function exchange(lst1, lst2){
var num1 = 0;
var num2 = 0;
var exchange = true;
while(num1 < lst1.length && exchange){ | 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";
}
}
| if(lst1[num1] % 2 !== 0){ | 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_48_is_palindrome.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 {
// Checks if given string is a palindrome
// >>> isPalindrome((""))
// (true)
// >>> isPalindrome(("aba"))
// (true)
// >>> isPalindrome(("aaaaa"))
// (true)
// >>> isPalindrome(("zbcd"))
// (false)
public static boolean isPalindrome(String text) {
| int left = 0;
int right = text.length() - 1;
while (left < right) {
if (text.charAt(left) != text.charAt(right)) {
isPalindrome = false;
break;
}
left++;
right--;
}
return isPalindrome;
}
} | boolean isPalindrome = true; | }
public static void main(String[] args) {
assert(isPalindrome(("")) == (true));
assert(isPalindrome(("aba")) == (true));
assert(isPalindrome(("aaaaa")) == (true));
assert(isPalindrome(("zbcd")) == (false));
assert(isPalindrome(("xywyx")) == (true));
assert(isPalindrome(("xywyz")) == (false));
assert(isPalindrome(("xywzx")) == (false));
}
}
|
humaneval-HumanEval_159_eat.json-L29 | js | //You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// >>> eat(5, 6, 10)
// [11, 4]
// >>> eat(4, 8, 9)
// [12, 1]
// >>> eat(1, 10, 10)
// [11, 0]
// >>> eat(2, 11, 5)
// [7, 0]
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
function eat(number, need, remaining){
if (need > remaining) return [number + remaining, 0]; | }
| else return [number + need, remaining - need]; | const assert = require('node:assert');
function test() {
let candidate = eat;
assert.deepEqual(candidate(5, 6, 10),[11, 4]);
assert.deepEqual(candidate(4, 8, 9),[12, 1]);
assert.deepEqual(candidate(1, 10, 10),[11, 0]);
assert.deepEqual(candidate(2, 11, 5),[7, 0]);
assert.deepEqual(candidate(4, 5, 7),[9, 2]);
assert.deepEqual(candidate(4, 5, 1),[5, 0]);
}
test(); |
humaneval-HumanEval_128_prod_signs.json-L32 | py | from typing import List, Optional
def prod_signs(arr: List[int]) -> Optional[int]:
"""
You are given an array arr of integers and you need to return
sum of magnitudes of integers multiplied by product of all signs
of each number in the array, represented by 1, -1 or 0.
Note: return None for empty arr.
Example:
>>> prod_signs([1, 2, 2, -4])
9
>>> prod_signs([0, 1])
0
>>> prod_signs([])
None
"""
def product(lst: List[int]) -> int:
out = 1
for item in lst:
out *= item
return out
if len(arr) == 0:
return None
else:
sign_arr = []
for num in arr:
if num > 0:
sign_arr.append(1)
elif num < 0: | else:
sign_arr.append(0)
return sum(map(abs, arr)) * product(sign_arr) | sign_arr.append(-1) | def check(candidate):
assert candidate([1, 2, 2, -4]) == -9
assert candidate([0, 1]) == 0
assert candidate([1, 1, 1, 2, 3, -1, 1]) == -10
assert candidate([]) == None
assert candidate([2, 4, 1, 2, -1, -1, 9]) == 20
assert candidate([-1, 1, -1, 1]) == 4
assert candidate([-1, 1, 1, 1]) == -4
assert candidate([-1, 1, 1, 0]) == 0
def test_check():
check(prod_signs)
test_check()
|
humaneval-HumanEval_6_parse_nested_parens.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 {
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// >>> parseNestedParens(("(()()) ((())) () ((())()())"))
// (new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)1l, (long)3l)))
public static ArrayList<Long> parseNestedParens(String paren_string) {
ArrayList<Long> result = new ArrayList<Long>();
String[] paren_strings = paren_string.split(" ");
for (String paren : paren_strings) {
long max_depth = 0;
long current_depth = 0; | if (c == '(') {
current_depth += 1;
max_depth = Math.max(max_depth, current_depth);
} else if (c == ')') {
current_depth -= 1;
}
}
result.add(max_depth);
}
return result;
}
} | for (char c : paren.toCharArray()) { | }
public static void main(String[] args) {
assert(parseNestedParens(("(()()) ((())) () ((())()())")).equals((new ArrayList<Long>(Arrays.asList((long)2l, (long)3l, (long)1l, (long)3l)))));
assert(parseNestedParens(("() (()) ((())) (((())))")).equals((new ArrayList<Long>(Arrays.asList((long)1l, (long)2l, (long)3l, (long)4l)))));
assert(parseNestedParens(("(()(())((())))")).equals((new ArrayList<Long>(Arrays.asList((long)4l)))));
}
}
|
humaneval-HumanEval_161_solve.json-L23 | js | //You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// >>> solve("1234")
// "4321"
// >>> solve("ab")
// "AB"
// >>> solve("#a@C")
// "#A@c"
function solve(s){
let letters = s.match(/[a-z]/ig);
if(letters) {
const swapped = s.split('').map(char => {
if(/[a-z]/i.test(char)) {
return char === char.toLowerCase()
? char.toUpperCase()
: char.toLowerCase();
}
return char; | return swapped.join('');
}
return s.split('').reverse().join('');
}
| }); | const assert = require('node:assert');
function test() {
let candidate = solve;
assert.deepEqual(candidate("AsDf"),"aSdF");
assert.deepEqual(candidate("1234"),"4321");
assert.deepEqual(candidate("ab"),"AB");
assert.deepEqual(candidate("#a@C"),"#A@c");
assert.deepEqual(candidate("#AsdfW^45"),"#aSDFw^45");
assert.deepEqual(candidate("#6@2"),"2@6#");
assert.deepEqual(candidate("#$a^D"),"#$A^d");
assert.deepEqual(candidate("#ccc"),"#CCC");
}
test(); |
humaneval-HumanEval_29_filter_by_prefix.json-L16 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Filter an input array list of strings only for ones that start with a given prefix.
// >>> filterByPrefix((new ArrayList<String>(Arrays.asList())), ("a"))
// (new ArrayList<String>(Arrays.asList()))
// >>> filterByPrefix((new ArrayList<String>(Arrays.asList((String)"abc", (String)"bcd", (String)"cde", (String)"array"))), ("a"))
// (new ArrayList<String>(Arrays.asList((String)"abc", (String)"array")))
public static ArrayList<String> filterByPrefix(ArrayList<String> strings, String prefix) {
return (ArrayList<String>)strings.stream().filter(s -> s.startsWith(prefix)).collect(Collectors.toList()); | } | } | }
public static void main(String[] args) {
assert(filterByPrefix((new ArrayList<String>(Arrays.asList())), ("john")).equals((new ArrayList<String>(Arrays.asList()))));
assert(filterByPrefix((new ArrayList<String>(Arrays.asList((String)"xxx", (String)"asd", (String)"xxy", (String)"john doe", (String)"xxxAAA", (String)"xxx"))), ("xxx")).equals((new ArrayList<String>(Arrays.asList((String)"xxx", (String)"xxxAAA", (String)"xxx")))));
}
}
|
humaneval-HumanEval_148_bf.json-L24 | js | //There are eight planets in our solar system: the closerst to the Sun
// is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
// Uranus, Neptune.
// Write a function that takes two planet names as strings planet1 and planet2.
// The function should return an array containing all planets whose orbits are
// located between the orbit of planet1 and the orbit of planet2, sorted by
// the proximity to the sun.
// The function should return an empty array if planet1 or planet2
// are not correct planet names.
// Examples
// >>> bf("Jupiter", "Neptune")
// ["Saturn", "Uranus"]
// >>> bf("Earth", "Mercury")
// "Venus"
// >>> bf("Mercury", "Uranus")
// ["Venus", "Earth", "Mars", "Jupiter", "Saturn"]
function bf(planet1, planet2){
var planets = {
'Mercury':1,
'Venus':2,
'Earth':3,
'Mars':4,
'Jupiter':5, | 'Uranus':7,
'Neptune':8
}
if(!planets[planet1] || !planets[planet2]){
return [];
}
var keys = Object.keys(planets);
var position1 = keys.indexOf(planet1);
var position2 = keys.indexOf(planet2);
if(position1 > position2){
var temp = position1;
position1 = position2;
position2 = temp;
}
var res = [];
for(var i = position1 + 1; i < position2; i++){
res.push(keys[i]);
}
return res;
} | 'Saturn':6, | const assert = require('node:assert');
function test() {
let candidate = bf;
assert.deepEqual(candidate("Jupiter", "Neptune"),["Saturn", "Uranus"]);
assert.deepEqual(candidate("Earth", "Mercury"),["Venus"]);
assert.deepEqual(candidate("Mercury", "Uranus"),["Venus", "Earth", "Mars", "Jupiter", "Saturn"]);
assert.deepEqual(candidate("Neptune", "Venus"),["Earth", "Mars", "Jupiter", "Saturn", "Uranus"]);
assert.deepEqual(candidate("Earth", "Earth"),[]);
assert.deepEqual(candidate("Mars", "Earth"),[]);
assert.deepEqual(candidate("Jupiter", "Makemake"),[]);
}
test(); |
humaneval-HumanEval_148_bf.json-L48 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// There are eight planets in our solar system: the closerst to the Sun
// is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
// Uranus, Neptune.
// Write a function that takes two planet names as strings planet1 and planet2.
// The function should return a pair containing all planets whose orbits are
// located between the orbit of planet1 and the orbit of planet2, sorted by
// the proximity to the sun.
// The function should return an empty pair if planet1 or planet2
// are not correct planet names.
// Examples
// >>> bf(("Jupiter"), ("Neptune"))
// (new ArrayList<String>(Arrays.asList((String)"Saturn", (String)"Uranus")))
// >>> bf(("Earth"), ("Mercury"))
// (ArrayList<String>("Venus"))
// >>> bf(("Mercury"), ("Uranus"))
// (new ArrayList<String>(Arrays.asList((String)"Venus", (String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn")))
public static ArrayList<String> bf(String planet1, String planet2) {
ArrayList<String> planets = new ArrayList<String>(Arrays.asList((String)"Mercury", (String)"Venus", (String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn", (String)"Uranus", (String)"Neptune"));
int indexPlanet1 = planets.indexOf(planet1);
int indexPlanet2 = planets.indexOf(planet2);
int indexMin = 0;
int indexMax = 0;
if (indexPlanet1 >= 0 && indexPlanet2 >= 0) {
if (indexPlanet1 < indexPlanet2) {
indexMin = indexPlanet1;
indexMax = indexPlanet2;
} else {
indexMin = indexPlanet2;
indexMax = indexPlanet1;
}
ArrayList<String> planetsInBetween = new ArrayList<String>();
for (int i = indexMin + 1; i < indexMax; i++) {
planetsInBetween.add(planets.get(i));
}
return planetsInBetween;
} else {
return new ArrayList<String>();
}
} | } | }
public static void main(String[] args) {
assert(bf(("Jupiter"), ("Neptune")).equals((new ArrayList<String>(Arrays.asList((String)"Saturn", (String)"Uranus")))));
assert(bf(("Earth"), ("Mercury")).equals((new ArrayList<String>(Arrays.asList((String)"Venus")))));
assert(bf(("Mercury"), ("Uranus")).equals((new ArrayList<String>(Arrays.asList((String)"Venus", (String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn")))));
assert(bf(("Neptune"), ("Venus")).equals((new ArrayList<String>(Arrays.asList((String)"Earth", (String)"Mars", (String)"Jupiter", (String)"Saturn", (String)"Uranus")))));
assert(bf(("Earth"), ("Earth")).equals((new ArrayList<String>(Arrays.asList()))));
assert(bf(("Mars"), ("Earth")).equals((new ArrayList<String>(Arrays.asList()))));
assert(bf(("Jupiter"), ("Makemake")).equals((new ArrayList<String>(Arrays.asList()))));
}
}
|
|
humaneval-HumanEval_65_circular_shift.json-L14 | 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--){ | }
}else{
res = str.substring(len-shift) + str.substring(0, len-shift);
}
return res;
}
| res += str[i]; | const assert = require('node:assert');
function test() {
let candidate = circular_shift;
assert.deepEqual(candidate(100, 2),"001");
assert.deepEqual(candidate(12, 2),"12");
assert.deepEqual(candidate(97, 8),"79");
assert.deepEqual(candidate(12, 1),"21");
assert.deepEqual(candidate(11, 101),"11");
}
test(); |
humaneval-HumanEval_146_specialFilter.json-L30 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Write a function that takes an array array list of numbers as input and returns
// the number of elements in the array array list that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// >>> specialFilter((new ArrayList<Long>(Arrays.asList((long)15l, (long)-73l, (long)14l, (long)-15l))))
// (1l)
// >>> specialFilter((new ArrayList<Long>(Arrays.asList((long)33l, (long)-2l, (long)-3l, (long)45l, (long)21l, (long)109l))))
// (2l)
public static long specialFilter(ArrayList<Long> nums) {
class helper {
public long getFirstDigit(long n) {
long[] digits = getDigits(n);
return digits[0];
}
public long getLastDigit(long n) {
long[] digits = getDigits(n);
return digits[digits.length - 1];
}
public long[] getDigits(long n) {
ArrayList<Long> digits = new ArrayList<Long>();
while (n != 0) { | n /= 10;
}
Collections.reverse(digits);
return digits.stream().mapToLong(i -> i).toArray();
}
}
helper h = new helper();
return nums.stream().filter(x -> x > 10).filter(x -> {
long firstDigit = h.getFirstDigit(x);
long lastDigit = h.getLastDigit(x);
return firstDigit % 2 != 0 && lastDigit % 2 != 0;
}).count();
}
} | digits.add(n % 10); | }
public static void main(String[] args) {
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)5l, (long)-2l, (long)1l, (long)-5l)))) == (0l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)15l, (long)-73l, (long)14l, (long)-15l)))) == (1l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)33l, (long)-2l, (long)-3l, (long)45l, (long)21l, (long)109l)))) == (2l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)43l, (long)-12l, (long)93l, (long)125l, (long)121l, (long)109l)))) == (4l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)71l, (long)-2l, (long)-33l, (long)75l, (long)21l, (long)19l)))) == (3l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList((long)1l)))) == (0l));
assert(specialFilter((new ArrayList<Long>(Arrays.asList()))) == (0l));
}
}
|
humaneval-HumanEval_114_minSubArraySum.json-L27 | java | import java.util.*;
import java.lang.reflect.*;
import org.javatuples.*;
import java.security.*;
import java.math.*;
import java.io.*;
import java.util.stream.*;
class Problem {
// Given an array array list of integers 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;
} | currSum += nums.get(j);
if (currSum < prevMinSum) {
prevMinSum = currSum;
}
if (currSum < minSum) {
minSum = currSum;
}
}
}
return minSum;
}
} | for (int j = i + 1; j < nums.size(); j++) { | }
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_138_is_equal_to_sum_even.json-L24 | 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){ | }
else{
return false;
}
} | return true; | 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(); |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.