Dataset Viewer
Auto-converted to Parquet Duplicate
task_id
stringlengths
11
13
prompt
stringlengths
107
1.36k
canonical_solution
stringlengths
16
692
test
stringlengths
117
1.8k
entry_point
stringclasses
1 value
HumanEval/0
from typing import List def f(a: List[float], b: float) -> bool: """ Check if in given list of a, are any two numbers closer to each other than given b. >>> f([1.0, 2.0, 3.0], 0.5) False >>> f([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3) True """
for idx, elem in enumerate(a): for idx2, elem2 in enumerate(a): if idx != idx2: distance = abs(elem - elem2) if distance < b: return True return False
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.3) == True assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.05) == False assert candidate([1.0, 2.0, 5.9, 4.0, 5.0], 0.95) == True assert candidate([1.0, 2.0, 5.9, 4.0,...
f
HumanEval/1
from typing import List def f(a: str) -> List[str]: """ Input to this function is a string containing multiple groups of nested parentheses. Your goal is to separate those group into separate strings and return the list of those. Separate groups are balanced (each open brace is properly closed) and not ne...
b = [] c = [] d = 0 for e in a: if e == '(': d += 1 c.append(e) elif e == ')': d -= 1 c.append(e) if d == 0: b.append(''.join(c)) c.clear() return b
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('(()()) ((())) () ((())()())') == [ '(()())', '((()))', '()', '((())()())' ] assert candidate('() (()) ((())) (((())))') == [ '()', '(())', '((()))', '(((())))' ] assert candidate('(()...
f
HumanEval/2
def f(a: float) -> float: """ 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. >>> f(3.5) 0.5 """
return a % 1.0
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(3.5) == 0.5 assert abs(candidate(1.33) - 0.33) < 1e-6 assert abs(candidate(123.456) - 0.456) < 1e-6
f
HumanEval/3
from typing import List def f(a: List[int]) -> bool: """ You're given a 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 sh...
b = 0 for c in a: b += c if b < 0: return True return False
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == False assert candidate([1, 2, -3, 1, 2, -3]) == False assert candidate([1, 2, -4, 5, 6]) == True assert candidate([1, -1, 2, -2, 5, -5, 4, -4]) == False assert candidate([1, -1, 2, -2, 5, -5, 4...
f
HumanEval/4
from typing import List def f(a: List[float]) -> float: """ For a given list of input numbers, calculate Mean Absolute Deviation around the mean of this dataset. Mean Absolute Deviation is the average absolute difference between each element and a centerpoint (mean in this case): MAD = average | x...
b = sum(a) / len(a) return sum(abs(x - b) for x in a) / len(a)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert abs(candidate([1.0, 2.0, 3.0]) - 2.0/3.0) < 1e-6 assert abs(candidate([1.0, 2.0, 3.0, 4.0]) - 1.0) < 1e-6 assert abs(candidate([1.0, 2.0, 3.0, 4.0, 5.0]) - 6.0/5.0) < 1e-6
f
HumanEval/5
from typing import List def f(a: List[int], b: int) -> List[int]: """ Insert a number 'b' between every two consecutive elements of input list `a' >>> f([], 4) [] >>> f([1, 2, 3], 4) [1, 4, 2, 4, 3] """
if not a: return [] result = [] for n in a[:-1]: result.append(n) result.append(b) result.append(a[-1]) return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([], 7) == [] assert candidate([5, 6, 3, 2], 8) == [5, 8, 6, 8, 3, 8, 2] assert candidate([2, 2, 2], 2) == [2, 2, 2, 2, 2]
f
HumanEval/6
from typing import List def f(a: str) -> List[int]: """ 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...
def parse_paren_group(s): depth = 0 max_depth = 0 for c in s: if c == '(': depth += 1 max_depth = max(depth, max_depth) else: depth -= 1 return max_depth return [parse_paren_group(x) for x in a.split(' ') i...
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('(()()) ((())) () ((())()())') == [2, 3, 1, 3] assert candidate('() (()) ((())) (((())))') == [1, 2, 3, 4] assert candidate('(()(())((())))') == [4]
f
HumanEval/7
from typing import List def f(a: List[str], b: str) -> List[str]: """ Filter an input list of strings only for ones that contain given substring >>> f([], 'a') [] >>> f(['abc', 'bacd', 'cde', 'array'], 'a') ['abc', 'bacd', 'array'] """
return [x for x in a if b in x]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([], 'john') == [] assert candidate(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx') == ['xxx', 'xxxAAA', 'xxx'] assert candidate(['xxx', 'asd', 'aaaxxy', 'john doe', 'xxxAAA', 'xxx'], 'xx') == ['xxx...
f
HumanEval/8
from typing import List, Tuple def f(a: List[int]) -> Tuple[int, int]: """ For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list. Empty sum should be equal to 0 and empty product should be equal to 1. >>> f([]) (0, 1) >>> f([1, 2, 3, 4]) (...
a_sum = 0 a_prod = 1 for b in a: a_sum += b a_prod *= b return a_sum, a_prod
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == (0, 1) assert candidate([1, 1, 1]) == (3, 1) assert candidate([100, 0]) == (100, 0) assert candidate([3, 5, 7]) == (3 + 5 + 7, 3 * 5 * 7) assert candidate([10]) == (10, 10)
f
HumanEval/9
from typing import List, Tuple def f(a: List[int]) -> List[int]: """ From a given list of integers, generate a list of rolling maximum element found until given moment in the sequence. >>> f([1, 2, 3, 2, 3, 4, 2]) [1, 2, 3, 3, 3, 4, 4] """
b = None c = [] for d in a: if b is None: b = d else: b = max(b, d) c.append(b) return c
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == [] assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4] assert candidate([4, 3, 2, 1]) == [4, 4, 4, 4] assert candidate([3, 2, 3, 100, 3]) == [3, 3, 3, 100, 100]
f
HumanEval/10
def f0(a: str) -> bool: """ Test if given string is a palindrome """ return a == a[::-1] def f(a: str) -> str: """ Find the shortest palindrome that begins with a supplied string. Algorithm idea is simple: - Find the longest postfix of supplied string that is a palindrome. - Append to the end ...
if not a: return '' b = 0 while not f0(a[b:]): b += 1 return a + a[:b][::-1]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == '' assert candidate('x') == 'x' assert candidate('xyz') == 'xyzyx' assert candidate('xyx') == 'xyx' assert candidate('jerry') == 'jerryrrej'
f
HumanEval/11
from typing import List def f(a: str, b: str) -> str: """ 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. >>> f('010', '110') '100' """
def xor(i, j): if i == j: return '0' else: return '1' return ''.join(xor(x, y) for x, y in zip(a, b))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('111000', '101010') == '010010' assert candidate('1', '1') == '0' assert candidate('0101', '0000') == '0101'
f
HumanEval/12
from typing import List, Optional def f(a: List[str]) -> Optional[str]: """ Out of list of strings, return the longest one. Return the first one in case of multiple strings of the same length. Return None in case the input list is empty. >>> f([]) >>> f(['a', 'b', 'c']) 'a' >>> f(['a', 'bb', ...
if not a: return None b = max(len(x) for x in a) for c in a: if len(c) == b: return c
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == None assert candidate(['x', 'y', 'z']) == 'x' assert candidate(['x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc']) == 'zzzz'
f
HumanEval/13
def f(a: int, b: int) -> int: """ Return a greatest common divisor of two integers a and b >>> f(3, 5) 1 >>> f(25, 15) 5 """
while b: a, b = b, a % b return a
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(3, 7) == 1 assert candidate(10, 15) == 5 assert candidate(49, 14) == 7 assert candidate(144, 60) == 12
f
HumanEval/14
from typing import List def f(a: str) -> List[str]: """ Return list of all prefixes from shortest to longest of the input string >>> f('abc') ['a', 'ab', 'abc'] """
b = [] for c in range(len(a)): b.append(a[:c+1]) return b
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == [] assert candidate('asdfgh') == ['a', 'as', 'asd', 'asdf', 'asdfg', 'asdfgh'] assert candidate('WWW') == ['W', 'WW', 'WWW']
f
HumanEval/15
def f(a: int) -> str: """ Return a string containing space-delimited numbers starting from 0 upto a inclusive. >>> f(0) '0' >>> f(5) '0 1 2 3 4 5' """
return ' '.join([str(x) for x in range(a + 1)])
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(0) == '0' assert candidate(3) == '0 1 2 3' assert candidate(10) == '0 1 2 3 4 5 6 7 8 9 10'
f
HumanEval/16
def f(a: str) -> int: """ Given a string, find out how many distinct characters (regardless of case) does it consist of >>> f('xyzXYZ') 3 >>> f('Jerry') 4 """
return len(set(a.lower()))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == 0 assert candidate('abcde') == 5 assert candidate('abcde' + 'cade' + 'CADE') == 5 assert candidate('aaaaAAAAaaaa') == 1 assert candidate('Jerry jERRY JeRRRY') == 5
f
HumanEval/17
from typing import List def f(a: str) -> List[int]: """ Input to this function is a string representing musical notes in a special ASCII format. Your task is to parse this string and return list of integers corresponding to how many beats does each not last. Here is a legend: 'o' - whole note, la...
b = {'o': 4, 'o|': 2, '.|': 1} return [b[x] for x in a.split(' ') if x]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == [] assert candidate('o o o o') == [4, 4, 4, 4] assert candidate('.| .| .| .|') == [1, 1, 1, 1] assert candidate('o| o| .| .| o o o o') == [2, 2, 1, 1, 4, 4, 4, 4] assert candidate('o| .| o| .| ...
f
HumanEval/18
def f(a: str, b: str) -> int: """ Find how many times a given b can be found in the original string. Count overlaping cases. >>> f('', 'a') 0 >>> f('aaa', 'a') 3 >>> f('aaaa', 'aa') 3 """
c = 0 for i in range(len(a) - len(b) + 1): if a[i:i+len(b)] == b: c += 1 return c
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('', 'x') == 0 assert candidate('xyxyxyx', 'x') == 4 assert candidate('cacacacac', 'cac') == 4 assert candidate('john doe', 'john') == 1
f
HumanEval/19
from typing import List def f(a: str) -> str: """ Input is a space-delimited string of numberals from 'zero' to 'nine'. Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'. Return the string with numbers sorted from smallest to largest >>> f('three one f...
b = { 'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9 } return ' '.join(sorted([x for x in a.split(' ') if x], key=lambda x: b[x]))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == '' assert candidate('three') == 'three' assert candidate('three five nine') == 'three five nine' assert candidate('five zero four seven nine eight') == 'zero four five seven eight nine' assert ...
f
HumanEval/20
from typing import List, Tuple def f(a: List[float]) -> Tuple[float, float]: """ From a supplied list of numbers (of length at least two) select and return two that are the closest to each other and return them in order (smaller number, larger number). >>> f([1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) (2.0, 2.2) ...
a_pair = None b = None for idx, elem in enumerate(a): for idx2, elem2 in enumerate(a): if idx != idx2: if b is None: b = abs(elem - elem2) a_pair = tuple(sorted([elem, elem2])) else: new_b = abs(...
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2]) == (3.9, 4.0) assert candidate([1.0, 2.0, 5.9, 4.0, 5.0]) == (5.0, 5.9) assert candidate([1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2) assert candidate([1.0, 2.0, 3.0, 4.0,...
f
HumanEval/21
from typing import List def f(a: List[float]) -> List[float]: """ Given list of n (of at least two elements), apply a linear transform to that list, such that the smallest number will become 0 and the largest will become 1 >>> f([1.0, 2.0, 3.0, 4.0, 5.0]) [0.0, 0.25, 0.5, 0.75, 1.0] """
b = min(a) c = max(a) return [(x - b) / (c - b) for x in a]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([2.0, 49.9]) == [0.0, 1.0] assert candidate([100.0, 49.9]) == [1.0, 0.0] assert candidate([1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0] assert candidate([2.0, 1.0, 5.0, 3.0, 4.0]) == [0.25, 0....
f
HumanEval/22
from typing import List, Any def f(a: List[Any]) -> List[int]: """ Filter given list of any python values only for integers >>> f(['a', 3.14, 5]) [5] >>> f([1, 2, 3, 'abc', {}, []]) [1, 2, 3] """
return [b for b in a if isinstance(b, int)]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == [] assert candidate([4, {}, [], 23.2, 9, 'adasd']) == [4, 9] assert candidate([3, 'c', 3, 3, 'a', 'b']) == [3, 3, 3]
f
HumanEval/23
def f(a: str) -> int: """ Return length of given string >>> f('') 0 >>> f('abc') 3 """
return len(a)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == 0 assert candidate('x') == 1 assert candidate('asdasnakj') == 9
f
HumanEval/24
def f(a: int) -> int: """ For a given number a, find the largest number that divides a evenly, smaller than a >>> f(15) 5 """
for b in reversed(range(a)): if a % b == 0: return b
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(3) == 1 assert candidate(7) == 1 assert candidate(10) == 5 assert candidate(100) == 50 assert candidate(49) == 7
f
HumanEval/25
from typing import List def f(a: int) -> List[int]: """ Return list of prime factors of given integer in the order from smallest to largest. Each of the factors should be listed number of times corresponding to how many times it appeares in factorization. Input number should be equal to the product of all...
import math b = [] c = 2 while c <= int(math.sqrt(a) + 1): if a % c == 0: b.append(c) a //= c else: c += 1 if a > 1: b.append(a) return b
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * ...
f
HumanEval/26
from typing import List def f(a: List[int]) -> List[int]: """ From a list of integers, remove all elements that occur more than once. Keep order of elements left the same as in the input. >>> f([1, 2, 3, 2, 4]) [1, 3, 4] """
import collections c = collections.Counter(a) return [n for n in a if c[n] <= 1]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == [] assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4] assert candidate([1, 2, 3, 2, 4, 3, 5]) == [1, 4, 5]
f
HumanEval/27
def f(a: str) -> str: """ For a given string, flip lowercase characters to uppercase and uppercase to lowercase. >>> f('Hello') 'hELLO' """
return a.swapcase()
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == '' assert candidate('Hello!') == 'hELLO!' assert candidate('These violent delights have violent ends') == 'tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS'
f
HumanEval/28
from typing import List def f(a: List[str]) -> str: """ Concatenate list of strings into a single string >>> f([]) '' >>> f(['a', 'b', 'c']) 'abc' """
return ''.join(a)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == '' assert candidate(['x', 'y', 'z']) == 'xyz' assert candidate(['x', 'y', 'z', 'w', 'k']) == 'xyzwk'
f
HumanEval/29
from typing import List def f(a: List[str], b: str) -> List[str]: """ Filter an input list of strings only for ones that start with a given prefix. >>> f([], 'a') [] >>> f(['abc', 'bcd', 'cde', 'array'], 'a') ['abc', 'array'] """
return [x for x in a if x.startswith(b)]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([], 'john') == [] assert candidate(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx') == ['xxx', 'xxxAAA', 'xxx']
f
HumanEval/30
def f(a: list): """Return only positive numbers in the list. >>> f([-1, 2, -4, 5, 6]) [2, 5, 6] >>> f([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) [5, 3, 2, 3, 9, 123, 1] """
return [e for e in a if e > 0]
METADATA = {} def check(candidate): assert candidate([-1, -2, 4, 5, 6]) == [4, 5, 6] assert candidate([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 3, 9, 123, 1] assert candidate([-1, -2]) == [] assert candidate([]) == []
f
HumanEval/31
def f(a): """Return true if a given number is prime, and false otherwise. >>> f(6) False >>> f(101) True >>> f(11) True >>> f(13441) True >>> f(61) True >>> f(4) False >>> f(1) False """
if a < 2: return False for b in range(2, a - 1): if a % b == 0: return False return True
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert ca...
f
HumanEval/32
import math def f0(a: list, b: float): """ Evaluates polynomial with coefficients a at point b. return a[0] + a[1] * b + a[1] * b^2 + .... a[n] * b^n """ return sum([coeff * math.pow(b, i) for i, coeff in enumerate(a)]) def f(a: list): """ a are coefficients of a polynomial. f find b suc...
c, d = -1., 1. while f0(a, c) * f0(a, d) > 0: c *= 2.0 d *= 2.0 while d - c > 1e-10: e = (c + d) / 2.0 if f0(a, e) * f0(a, c) > 0: c = e else: d = e return c
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: co...
f
HumanEval/33
def f(a: list): """This function takes a list a and returns a list a' such that a' is identical to a 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 a, but sorted. >>> f([1, 2, 3]) ...
a = list(a) a[::3] = sorted(a[::3]) return a
METADATA = {} def check(candidate): assert tuple(candidate([1, 2, 3])) == tuple(f([1, 2, 3])) assert tuple(candidate([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) == tuple(f([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) assert tuple(candidate([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) == tuple(f([5, 8, -12, 4, 23,...
f
HumanEval/34
def f(a: list): """Return sorted unique elements in a list >>> f([5, 3, 5, 2, 3, 3, 9, 0, 123]) [0, 2, 3, 5, 9, 123] """
return sorted(list(set(a)))
METADATA = {} def check(candidate): assert candidate([5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
f
HumanEval/35
def f(a: list): """Return maximum element in the list. >>> f([1, 2, 3]) 3 >>> f([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) 123 """
b = a[0] for c in a: if c > b: b = c return b
METADATA = {} def check(candidate): assert candidate([1, 2, 3]) == 3 assert candidate([5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) == 124
f
HumanEval/36
def f(a: int): """Return the number of times the digit 7 appears in integers less than a which are divisible by 11 or 13. >>> f(50) 0 >>> f(78) 2 >>> f(79) 3 """
b = [] for i in range(a): if i % 11 == 0 or i % 13 == 0: b.append(i) c = ''.join(list(map(str, b))) d = 0 for e in c: d += (e == '7') return d
METADATA = {} def check(candidate): assert candidate(50) == 0 assert candidate(78) == 2 assert candidate(79) == 3 assert candidate(100) == 3 assert candidate(200) == 6 assert candidate(4000) == 192 assert candidate(10000) == 639 assert candidate(100000) == 8026
f
HumanEval/37
def f(a: list): """This function takes a list a and returns a list a' such that a' is identical to a in the odd indicies, while its values at the even indicies are equal to the values of the even indicies of a, but sorted. >>> f([1, 2, 3]) [1, 2, 3] >>> f([5, 6, 3, 4]) [3, 6, 5, 4] """
b = a[::2] c = a[1::2] b.sort() d = [] for e, o in zip(b, c): d.extend([e, o]) if len(b) > len(c): d.append(b[-1]) return d
METADATA = {} def check(candidate): assert tuple(candidate([1, 2, 3])) == tuple([1, 2, 3]) assert tuple(candidate([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) == tuple([-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123]) assert tuple(candidate([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) == tuple([-12, 8, 3, 4, 5, 2, 12, 1...
f
HumanEval/38
def f0(a: str): """ returns encoded string by cycling groups of three characters. """ # split string to groups. Each of length 3. b = [a[(3 * i):min((3 * i + 3), len(a))] for i in range((len(a) + 2) // 3)] # cycle elements in each group. Unless group has fewer elements than 3. b = [(group[1:...
return f0(f0(a))
METADATA = {} def check(candidate): from random import randint, choice import string letters = string.ascii_lowercase for _ in range(100): str = ''.join(choice(letters) for i in range(randint(10, 20))) encoded_str = f0(str) assert candidate(encoded_str) == str
f
HumanEval/39
def f(a: int): """ f returns a-th number that is a Fibonacci number and it's also prime. >>> f(1) 2 >>> f(2) 3 >>> f(3) 5 >>> f(4) 13 >>> f(5) 89 """
import math def is_prime(b): if b < 2: return False for k in range(2, min(int(math.sqrt(b)) + 1, b - 1)): if b % k == 0: return False return True c = [0, 1] while True: c.append(c[-1] + c[-2]) if is_prime(c[-1]): ...
METADATA = {} def check(candidate): assert candidate(1) == 2 assert candidate(2) == 3 assert candidate(3) == 5 assert candidate(4) == 13 assert candidate(5) == 89 assert candidate(6) == 233 assert candidate(7) == 1597 assert candidate(8) == 28657 assert candidate(9) == 514229 ...
f
HumanEval/40
def f(a: list): """ f takes a list of integers as an input. it returns True if there are three distinct elements in the list that sum to zero, and False otherwise. >>> f([1, 3, 5, 0]) False >>> f([1, 3, -2, 1]) True >>> f([1, 2, 3, 7]) False >>> f([2, 4, -5, 3, 9, 7]) Tr...
for i in range(len(a)): for j in range(i + 1, len(a)): for k in range(j + 1, len(a)): if a[i] + a[j] + a[k] == 0: return True return False
METADATA = {} def check(candidate): assert candidate([1, 3, 5, 0]) == False assert candidate([1, 3, 5, -1]) == False assert candidate([1, 3, -2, 1]) == True assert candidate([1, 2, 3, 7]) == False assert candidate([1, 2, 5, 7]) == False assert candidate([2, 4, -5, 3, 9, 7]) == True asser...
f
HumanEval/41
def f(a: int): """ Imagine a road that's a perfectly straight infinitely long line. a cars are driving left to right; simultaneously, a different set of a cars are driving right to left. The two sets of cars start out being very far from each other. All cars move in the same speed. Two cars are...
return a**2
METADATA = {} def check(candidate): assert candidate(2) == 4 assert candidate(3) == 9 assert candidate(4) == 16 assert candidate(8) == 64 assert candidate(10) == 100
f
HumanEval/42
def f(a: list): """Return list with elements incremented by 1. >>> f([1, 2, 3]) [2, 3, 4] >>> f([5, 3, 5, 2, 3, 3, 9, 0, 123]) [6, 4, 6, 3, 4, 4, 10, 1, 124] """
return [(e + 1) for e in a]
METADATA = {} def check(candidate): assert candidate([]) == [] assert candidate([3, 2, 1]) == [4, 3, 2] assert candidate([5, 2, 5, 2, 3, 3, 9, 0, 123]) == [6, 3, 6, 3, 4, 4, 10, 1, 124]
f
HumanEval/43
def f(a): """ f takes a list of integers as an input. it returns True if there are two distinct elements in the list that sum to zero, and False otherwise. >>> f([1, 3, 5, 0]) False >>> f([1, 3, -2, 1]) False >>> f([1, 2, 3, 7]) False >>> f([2, 4, -5, 3, 5, 7]) True >...
for i, a1 in enumerate(a): for j in range(i + 1, len(a)): if a1 + a[j] == 0: return True return False
METADATA = {} def check(candidate): assert candidate([1, 3, 5, 0]) == False assert candidate([1, 3, -2, 1]) == False assert candidate([1, 2, 3, 7]) == False assert candidate([2, 4, -5, 3, 5, 7]) == True assert candidate([1]) == False assert candidate([-3, 9, -1, 3, 2, 30]) == True asser...
f
HumanEval/44
def f(a: int, b: int): """Change numerical base of input number a to b. return string representation after the conversion. base numbers are less than 10. >>> f(8, 3) '22' >>> f(8, 2) '1000' >>> f(7, 2) '111' """
c = "" while a > 0: c = str(a % b) + c a //= b return c
METADATA = {} def check(candidate): assert candidate(8, 3) == "22" assert candidate(9, 3) == "100" assert candidate(234, 2) == "11101010" assert candidate(16, 2) == "10000" assert candidate(8, 2) == "1000" assert candidate(7, 2) == "111" for x in range(2, 8): assert candidate(x, ...
f
HumanEval/45
def f(a, b): """Given length of a side and high return area for a triangle. >>> f(5, 3) 7.5 """
return a * b / 2.0
METADATA = {} def check(candidate): assert candidate(5, 3) == 7.5 assert candidate(2, 2) == 2.0 assert candidate(10, 8) == 40.0
f
HumanEval/46
def f(a: 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(a) -> Fib4(a-1) + Fib4(a-2) + Fib4(a-3) + Fib4(a-4). Please write a function to efficiently compute the a-th element...
b = [0, 0, 2, 0] if a < 4: return b[a] for _ in range(4, a + 1): b.append(b[-1] + b[-2] + b[-3] + b[-4]) b.pop(0) return b[-1]
METADATA = {} def check(candidate): assert candidate(5) == 4 assert candidate(8) == 28 assert candidate(10) == 104 assert candidate(12) == 386
f
HumanEval/47
def f(a: list): """Return median of elements in the list a. >>> f([3, 1, 2, 4, 5]) 3 >>> f([-10, 4, 6, 1000, 10, 20]) 15.0 """
a = sorted(a) if len(a) % 2 == 1: return a[len(a) // 2] else: return (a[len(a) // 2 - 1] + a[len(a) // 2]) / 2.0
METADATA = {} def check(candidate): assert candidate([3, 1, 2, 4, 5]) == 3 assert candidate([-10, 4, 6, 1000, 10, 20]) == 8.0 assert candidate([5]) == 5 assert candidate([6, 5]) == 5.5 assert candidate([8, 1, 3, 9, 9, 2, 7]) == 7
f
HumanEval/48
def f(a: str): """ Checks if given string is a palindrome >>> f('') True >>> f('aba') True >>> f('aaaaa') True >>> f('zbcd') False """
for b in range(len(a)): if a[b] != a[len(a) - 1 - b]: return False return True
METADATA = {} def check(candidate): assert candidate('') == True assert candidate('aba') == True assert candidate('aaaaa') == True assert candidate('zbcd') == False assert candidate('xywyx') == True assert candidate('xywyz') == False assert candidate('xywzx') == False
f
HumanEval/49
def f(a: int, b: int): """Return 2^a modulo b (be aware of numerics). >>> f(3, 5) 3 >>> f(1101, 101) 2 >>> f(0, 101) 1 >>> f(3, 11) 8 >>> f(100, 101) 1 """
c = 1 for d in range(a): c = (2 * c) % b return c
METADATA = {} def check(candidate): assert candidate(3, 5) == 3 assert candidate(1101, 101) == 2 assert candidate(0, 101) == 1 assert candidate(3, 11) == 8 assert candidate(100, 101) == 1 assert candidate(30, 5) == 4 assert candidate(31, 5) == 3
f
HumanEval/50
def f0(a: str): """ returns encoded string by shifting every character by 5 in the alphabet. """ return "".join([chr(((ord(ch) + 5 - ord("a")) % 26) + ord("a")) for ch in a]) def f(a: str): """ takes as input string encoded with f0 function. Returns decoded string. """
return "".join([chr(((ord(ch) - 5 - ord("a")) % 26) + ord("a")) for ch in a])
METADATA = {} def check(candidate): from random import randint, choice import copy import string letters = string.ascii_lowercase for _ in range(100): str = ''.join(choice(letters) for i in range(randint(10, 20))) encoded_str = f0(str) assert candidate(copy.deepcopy(enco...
f
HumanEval/51
def f(a): """ f is a function that takes string and returns string without vowels. >>> f('') '' >>> f("abcdef\nghijklm") 'bcdf\nghjklm' >>> f('abcdef') 'bcdf' >>> f('aaaaa') '' >>> f('aaBAA') 'B' >>> f('zbcd') 'zbcd' """
return "".join([s for s in a if s.lower() not in ["a", "e", "i", "o", "u"]])
METADATA = {} def check(candidate): assert candidate('') == '' assert candidate("abcdef\nghijklm") == 'bcdf\nghjklm' assert candidate('fedcba') == 'fdcb' assert candidate('eeeee') == '' assert candidate('acBAA') == 'cB' assert candidate('EcBOO') == 'cB' assert candidate('ybcd') == 'ybcd'...
f
HumanEval/52
def f(a: list, b: int): """Return True if all numbers in the list a are below threshold b. >>> f([1, 2, 4, 10], 100) True >>> f([1, 20, 4, 10], 5) False """
for e in a: if e >= b: return False return True
METADATA = {} def check(candidate): assert candidate([1, 2, 4, 10], 100) assert not candidate([1, 20, 4, 10], 5) assert candidate([1, 20, 4, 10], 21) assert candidate([1, 20, 4, 10], 22) assert candidate([1, 8, 4, 10], 11) assert not candidate([1, 8, 4, 10], 10)
f
HumanEval/53
def f(a: int, b: int): """Add two numbers a and b >>> f(2, 3) 5 >>> f(5, 7) 12 """
return a + b
METADATA = {} def check(candidate): import random assert candidate(0, 1) == 1 assert candidate(1, 0) == 1 assert candidate(2, 3) == 5 assert candidate(5, 7) == 12 assert candidate(7, 5) == 12 for i in range(100): x, y = random.randint(0, 1000), random.randint(0, 1000) a...
f
HumanEval/54
def f(a: str, b: str): """ Check if two words have the same characters. >>> f('eabcdzzzz', 'dddzzzzzzzddeddabc') True >>> f('abcd', 'dddddddabc') True >>> f('dddddddabc', 'abcd') True >>> f('eabcd', 'dddddddabc') False >>> f('abcd', 'dddddddabce') False >>> f('eabcdzz...
return set(a) == set(b)
METADATA = {} def check(candidate): assert candidate('eabcdzzzz', 'dddzzzzzzzddeddabc') == True assert candidate('abcd', 'dddddddabc') == True assert candidate('dddddddabc', 'abcd') == True assert candidate('eabcd', 'dddddddabc') == False assert candidate('abcd', 'dddddddabcf') == False asse...
f
HumanEval/55
def f(a: int): """Return a-th Fibonacci number. >>> f(10) 55 >>> f(1) 1 >>> f(8) 21 """
if a == 0: return 0 if a == 1: return 1 return f(a - 1) + f(a - 2)
METADATA = {} def check(candidate): assert candidate(10) == 55 assert candidate(1) == 1 assert candidate(8) == 21 assert candidate(11) == 89 assert candidate(12) == 144
f
HumanEval/56
def f(a: str): """ a is a string of "<" and ">". return True if every opening bracket has a corresponding closing bracket. >>> f("<") False >>> f("<>") True >>> f("<<><>>") True >>> f("><<>") False """
b = 0 for c in a: if c == "<": b += 1 else: b -= 1 if b < 0: return False return b == 0
METADATA = {} def check(candidate): assert candidate("<>") assert candidate("<<><>>") assert candidate("<><><<><>><>") assert candidate("<><><<<><><>><>><<><><<>>>") assert not candidate("<<<><>>>>") assert not candidate("><<>") assert not candidate("<") assert not candidate("<<<<") ...
f
HumanEval/57
def f(a: list): """Return True is list elements are monotonically increasing or decreasing. >>> f([1, 2, 4, 20]) True >>> f([1, 20, 4, 10]) False >>> f([4, 1, 0, -10]) True """
if a == sorted(a) or a == sorted(a, reverse=True): return True return False
METADATA = {} def check(candidate): assert candidate([1, 2, 4, 10]) == True assert candidate([1, 2, 4, 20]) == True assert candidate([1, 20, 4, 10]) == False assert candidate([4, 1, 0, -10]) == True assert candidate([4, 1, 1, 0]) == True assert candidate([1, 2, 3, 2, 5, 60]) == False ass...
f
HumanEval/58
def f(a: list, b: list): """Return sorted unique common elements for two lists. >>> f([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]) [1, 5, 653] >>> f([5, 3, 2, 8], [3, 2]) [2, 3] """
c = set() for d in a: for e in b: if d == e: c.add(d) return sorted(list(c))
METADATA = {} def check(candidate): assert candidate([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653] assert candidate([5, 3, 2, 8], [3, 2]) == [2, 3] assert candidate([4, 3, 2, 8], [3, 2, 4]) == [2, 3, 4] assert candidate([4, 3, 2, 8], []) == []
f
HumanEval/59
def f(a: int): """Return the largest prime factor of a. Assume a > 1 and is not a prime. >>> f(13195) 29 >>> f(2048) 2 """
def is_prime(b): if b < 2: return False for i in range(2, b - 1): if b % i == 0: return False return True largest = 1 for j in range(2, a + 1): if a % j == 0 and is_prime(j): largest = max(largest, j) return largest
METADATA = {} def check(candidate): assert candidate(15) == 5 assert candidate(27) == 3 assert candidate(63) == 7 assert candidate(330) == 11 assert candidate(13195) == 29
f
HumanEval/60
def f(a: int): """f is a function that sums numbers from 1 to a. >>> f(30) 465 >>> f(100) 5050 >>> f(5) 15 >>> f(10) 55 >>> f(1) 1 """
return sum(range(a + 1))
METADATA = {} def check(candidate): assert candidate(1) == 1 assert candidate(6) == 21 assert candidate(11) == 66 assert candidate(30) == 465 assert candidate(100) == 5050
f
HumanEval/61
def f(a: str): """ a is a string of "(" and ")". return True if every opening bracket has a corresponding closing bracket. >>> f("(") False >>> f("()") True >>> f("(()())") True >>> f(")(()") False """
b = 0 for c in a: if c == "(": b += 1 else: b -= 1 if b < 0: return False return b == 0
METADATA = {} def check(candidate): assert candidate("()") assert candidate("(()())") assert candidate("()()(()())()") assert candidate("()()((()()())())(()()(()))") assert not candidate("((()())))") assert not candidate(")(()") assert not candidate("(") assert not candidate("((((") ...
f
HumanEval/62
def f(a: list): """ a represent coefficients of a polynomial. a[0] + a[1] * x + a[2] * x^2 + .... Return derivative of this polynomial in the same form. >>> f([3, 1, 2, 4, 5]) [1, 4, 12, 20] >>> f([1, 2, 3]) [2, 6] """
return [(i * x) for i, x in enumerate(a)][1:]
METADATA = {} def check(candidate): assert candidate([3, 1, 2, 4, 5]) == [1, 4, 12, 20] assert candidate([1, 2, 3]) == [2, 6] assert candidate([3, 2, 1]) == [2, 2] assert candidate([3, 2, 1, 0, 4]) == [2, 2, 0, 16] assert candidate([1]) == []
f
HumanEval/63
def f(a: int): """The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: FibFib(0) == 0 FibFib(1) == 0 FibFib(2) == 1 FibFib(n) == FibFib(n-1) + FibFib(n-2) + FibFib(n-3). Please write a function f to efficiently compute the n-th element of the Fib...
if a == 0: return 0 if a == 1: return 0 if a == 2: return 1 return f(a - 1) + f(a - 2) + f(a - 3)
METADATA = {} def check(candidate): assert candidate(2) == 1 assert candidate(1) == 0 assert candidate(5) == 4 assert candidate(8) == 24 assert candidate(10) == 81 assert candidate(12) == 274 assert candidate(14) == 927
f
HumanEval/64
FIX = """ Add more test cases. """ def f(a): """Write a function f 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. Exampl...
b = "aeiouAEIOU" c = sum(d in b for d in a) if a[-1] == 'y' or a[-1] == 'Y': c += 1 return c
def check(candidate): # Check some simple cases assert candidate("abcde") == 2, "Test 1" assert candidate("Alone") == 3, "Test 2" assert candidate("key") == 2, "Test 3" assert candidate("bye") == 1, "Test 4" assert candidate("keY") == 2, "Test 5" assert candidate("bYe") == 1, "Test 6" a...
f
HumanEval/65
def f(a, b): """Circular shift the digits of the integer a, shift the digits right by b and return the result as a string. If b > number of digits, return digits reversed. >>> f(12, 1) "21" >>> f(12, 2) "12" """
c = str(a) if b > len(c): return c[::-1] else: return c[len(c) - b:] + c[:len(c) - b]
def check(candidate): # Check some simple cases assert candidate(100, 2) == "001" assert candidate(12, 2) == "12" assert candidate(97, 8) == "79" assert candidate(12, 1) == "21", "This prints if this assert fails 1 (good for debugging!)" # Check some edge cases that are easy to work out by han...
f
HumanEval/66
def f(a): """Task Write a function that takes a string as input and returns the sum of the upper characters only' ASCII codes. Examples: f("") => 0 f("abAB") => 131 f("abcCd") => 67 f("helloE") => 69 f("woArBld") => 131 f("aAaaaXa") => 153 """
if a == "": return 0 return sum(ord(char) if char.isupper() else 0 for char in a)
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate("") == 0, "Error" assert candidate("abAB") == 131, "Error" assert candidate("abcCd") == 67, "Error" assert candidate("helloE") == 69, "Error" assert candi...
f
HumanEval/67
def f(a, b): """ In this task, you will be given a string that represents a number of apples and oranges that are distributed in a basket of fruit this basket contains apples, oranges, and mango fruits. Given the string that represents the total number of the oranges and apples and an integer tha...
c = list() for d in a.split(' '): if d.isdigit(): c.append(int(d)) return b - sum(c)
def check(candidate): # Check some simple cases assert candidate("5 apples and 6 oranges",19) == 8 assert candidate("5 apples and 6 oranges",21) == 10 assert candidate("0 apples and 1 oranges",3) == 2 assert candidate("1 apples and 0 oranges",3) == 2 assert candidate("2 apples and 3 oranges",10...
f
HumanEval/68
def f(a): """ "Given an array representing a branch of a tree that has non-negative integer nodes your task is to pluck one of the nodes and return it. The plucked node should be the node with the smallest even value. If multiple nodes with the same smallest even value are found return the node that...
if(len(a) == 0): return [] b = list(filter(lambda x: x%2 == 0, a)) if(b == []): return [] return [min(b), a.index(min(b))]
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate([4,2,3]) == [2, 1], "Error" assert candidate([1,2,3]) == [2, 1], "Error" assert candidate([]) == [], "Error" assert candidate([5, 0, 3, 0, 4, 2]) == [0, 1], "...
f
HumanEval/69
def f(a): ''' 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 exi...
b = [0] * (max(a) + 1) for c in a: b[c] += 1; d = -1 for e in range(1, len(b)): if b[e] >= e: d = e return d
def check(candidate): # manually generated tests 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 # automatically generated tests assert...
f
HumanEval/70
def f(a): ''' Given list of integers, return list in strange order. Strange sorting, is when you start with the minimum value, then maximum of the remaining integers, then minimum and so on. Examples: f([1, 2, 3, 4]) == [1, 4, 2, 3] f([5, 5, 5, 5]) == [5, 5, 5, 5] f([]) == [] '''
b, switch = [], True while a: b.append(min(a) if switch else max(a)) a.remove(b[-1]) switch = not switch return b
def check(candidate): # Check some simple cases assert candidate([1, 2, 3, 4]) == [1, 4, 2, 3] assert candidate([5, 6, 7, 8, 9]) == [5, 9, 6, 8, 7] assert candidate([1, 2, 3, 4, 5]) == [1, 5, 2, 4, 3] assert candidate([5, 6, 7, 8, 9, 1]) == [1, 9, 5, 8, 6, 7] assert candidate([5, 5, 5, 5]) == [...
f
HumanEval/71
def f(a, b, c): ''' Given the lengths of the three sides of a triangle. Return the area of the triangle rounded to 2 decimal points if the three sides form a valid triangle. Otherwise return -1 Three sides make a valid triangle when the sum of any two sides is greater than the third side. ...
if a + b <= c or a + c <= b or b + c <= a: return -1 s = (a + b + c)/2 area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 area = round(area, 2) return area
def check(candidate): # Check some simple cases assert candidate(3, 4, 5) == 6.00, "This prints if this assert fails 1 (good for debugging!)" assert candidate(1, 2, 10) == -1 assert candidate(4, 8, 5) == 8.18 assert candidate(2, 2, 2) == 1.73 assert candidate(1, 2, 3) == -1 assert candidate...
f
HumanEval/72
def f(a, b): ''' Write a function that returns True if the object a will fly, and False otherwise. The object a will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight b. Example: f([1, 2], 5) ➞ False # 1+2 is less tha...
if sum(a) > b: return False i, j = 0, len(a)-1 while i < j: if a[i] != a[j]: return False i += 1 j -= 1 return True
def check(candidate): # Check some simple cases assert candidate([3, 2, 3], 9) is True assert candidate([1, 2], 5) is False assert candidate([3], 5) is True assert candidate([3, 2, 3], 1) is False # Check some edge cases that are easy to work out by hand. assert candidate([1, 2, 3], 6) is...
f
HumanEval/73
def f(a): """ Given an array a 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: f([1,...
b = 0 for i in range(len(a) // 2): if a[i] != a[len(a) - i - 1]: b += 1 return b
def check(candidate): # Check some simple cases 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 # Check some edge cases that are easy to work out by hand. assert candidate([1, 2, 3, 2...
f
HumanEval/74
def f(a, b): ''' Write a function that accepts two lists of strings and returns the list that has total number of chars in the all strings of the list less than the other list. if the two lists have the same number of chars, return the first list. Examples f([], []) ➞ [] f(['hi', 'admin'...
l1 = 0 for st in a: l1 += len(st) l2 = 0 for st in b: l2 += len(st) if l1 <= l2: return a else: return b
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate([], []) == [] assert candidate(['hi', 'admin'], ['hi', 'hi']) == ['hi', 'hi'] assert candidate(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) == ['hi', 'admin...
f
HumanEval/75
def f(a): """Write a function that returns true if the given number is the multiplication of 3 prime numbers and false otherwise. Knowing that (a) is less than 100. Example: f(30) == True 30 = 2 * 3 * 5 """
def is_prime(b): for j in range(2, b): if b % j == 0: return False return True for i in range(2, 101): if not is_prime(i): continue for j in range(2, 101): if not is_prime(j): continue for k in range(2, 101): if...
def check(candidate): assert candidate(5) == False assert candidate(30) == True assert candidate(8) == True assert candidate(10) == False assert candidate(125) == True assert candidate(3 * 5 * 7) == True assert candidate(3 * 6 * 7) == False assert candidate(9 * 9 * 9) == False asser...
f
HumanEval/76
def f(a, b): """Your task is to write a function that returns true if a number a is a simple power of b and false in other cases. a is a simple power of b if b**int=a For example: f(1, 4) => true f(2, 2) => true f(8, 2) => true f(3, 2) => false f(3, 1) => false f(5, 3) => false ...
if (b == 1): return (a == 1) power = 1 while (power < a): power = power * b return (power == a)
def check(candidate): # Check some simple cases assert candidate(16, 2)== True, "This prints if this assert fails 1 (good for debugging!)" assert candidate(143214, 16)== False, "This prints if this assert fails 1 (good for debugging!)" assert candidate(4, 2)==True, "This prints if this assert fails 1 (...
f
HumanEval/77
def f(a): ''' Write a function that takes an integer a and returns True if this ingeger is a cube of some integer number. Note: you may assume the input is always valid. Examples: f(1) ==> True f(2) ==> False f(-1) ==> True f(64) ==> True f(0) ==> True f(180) ==> False ...
a = abs(a) return int(round(a ** (1. / 3))) ** 3 == a
def check(candidate): # Check some simple cases assert candidate(1) == True, "First test error: " + str(candidate(1)) assert candidate(2) == False, "Second test error: " + str(candidate(2)) assert candidate(-1) == True, "Third test error: " + str(candidate(-1)) assert candidate(64) == True, "Fourth...
f
HumanEval/78
def f(a): """You have been tasked to write a function that receives a hexadecimal number as a string and counts the number of hexadecimal digits that are primes (prime number, or a prime, is a natural number greater than 1 that is not a product of two smaller natural numbers). Hexadecimal digits ...
b = ('2', '3', '5', '7', 'B', 'D') c = 0 for i in range(0, len(a)): if a[i] in b: c += 1 return c
def check(candidate): # Check some simple cases assert candidate("AB") == 1, "First test error: " + str(candidate("AB")) assert candidate("1077E") == 2, "Second test error: " + str(candidate("1077E")) assert candidate("ABED1A33") == 4, "Third test error: " + str(candidate("ABED1A33")) ...
f
HumanEval/79
def f(a): """You will be given a number in decimal form and your task is to convert it to binary format. The function should return a string, with each character representing a binary number. Each character in the string will be '0' or '1'. There will be an extra couple of characters 'db' at the beginn...
return "db" + bin(a)[2:] + "db"
def check(candidate): # Check some simple cases assert candidate(0) == "db0db" assert candidate(32) == "db100000db" assert candidate(103) == "db1100111db" assert candidate(15) == "db1111db", "This prints if this assert fails 1 (good for debugging!)" # Check some edge cases that are easy to wor...
f
HumanEval/80
def f(a): """You are given a string a. Your task is to check if the string is happy or not. A string is happy if its length is at least 3 and every 3 consecutive letters are distinct For example: f(a) => False f(aa) => False f(abcd) => True f(aabb) => False f(adb) => True f(xyy) ...
if len(a) < 3: return False for i in range(len(a) - 2): if a[i] == a[i+1] or a[i+1] == a[i+2] or a[i] == a[i+2]: return False return True
def check(candidate): # Check some simple cases assert candidate("a") == False , "a" assert candidate("aa") == False , "aa" assert candidate("abcd") == True , "abcd" assert candidate("aabb") == False , "aabb" assert candidate("adb") == True , "adb" assert candidate("xyy") == False , "xyy" ...
f
HumanEval/81
def f(a): """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...
b = [] for g in a: if g == 4.0: b.append("A+") elif g > 3.7: b.append("A") elif g > 3.3: b.append("A-") elif g > 3.0: b.append("B+") elif g > 2.7: b.append("B") elif g > 2.3: b.append("B-") ...
def check(candidate): # Check some simple cases 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.3, 1.5, 2.8, 3.3]) == ['D', 'D-', 'C-', 'B', 'B+'] ...
f
HumanEval/82
def f(a): """Write a function that takes a string and returns True if the string length is a prime number or False otherwise Examples f('Hello') == True f('abcdcba') == True f('kittens') == True f('orange') == False """
b = len(a) if b == 0 or b == 1: return False for i in range(2, b): if b % i == 0: return False return True
def check(candidate): # Check some simple cases assert candidate('Hello') == True assert candidate('abcdcba') == True assert candidate('kittens') == True assert candidate('orange') == False assert candidate('wow') == True assert candidate('world') == True assert candidate('MadaM') == Tr...
f
HumanEval/83
def f(a): """ Given a positive integer a, return the count of the numbers of a-digit positive integers that start or end with 1. """
if a == 1: return 1 return 18 * (10 ** (a - 2))
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate(1) == 1 assert candidate(2) == 18 assert candidate(3) == 180 assert candidate(4) == 1800 assert candidate(5) == 18000 # Check some edge cases that ar...
f
HumanEval/84
def f(a): """Given a positive integer a, return the total sum of its digits in binary. Example For a = 1000, the sum of digits will be 1 the output should be "1". For a = 150, the sum of digits will be 6 the output should be "110". For a = 147, the sum of digits will be 12 the outpu...
return bin(sum(int(i) for i in str(a)))[2:]
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate(1000) == "1", "Error" assert candidate(150) == "110", "Error" assert candidate(147) == "1100", "Error" # Check some edge cases that are easy to work out by h...
f
HumanEval/85
def f(a): """Given a non-empty list of integers a. add the even elements that are at odd indices.. Examples: f([4, 2, 6, 7]) ==> 2 """
return sum([a[i] for i in range(1, len(a), 2) if a[i]%2 == 0])
def check(candidate): # Check some simple cases assert candidate([4, 88]) == 88 assert candidate([4, 5, 6, 7, 2, 122]) == 122 assert candidate([4, 0, 6, 7]) == 0 assert candidate([4, 4, 6, 8]) == 12 # Check some edge cases that are easy to work out by hand.
f
HumanEval/86
def f(a): """ 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 ord...
return ' '.join([''.join(sorted(list(i))) for i in a.split(' ')])
def check(candidate): # Check some simple cases assert candidate('Hi') == 'Hi' assert candidate('hello') == 'ehllo' assert candidate('number') == 'bemnru' assert candidate('abcd') == 'abcd' assert candidate('Hello World!!!') == 'Hello !!!Wdlor' assert candidate('') == '' assert candidat...
f
HumanEval/87
def f(a, b): """ You are given a 2 dimensional data, as a nested lists, which is similar to matrix, however, unlike matrices, each row may contain a different number of columns. Given a, and integer b, find integers b in the list, and return list of tuples, [(x1, y1), (x2, y2) ...] such that ...
coords = [(i, j) for i in range(len(a)) for j in range(len(a[i])) if a[i][j] == b] return sorted(sorted(coords, key=lambda x: x[1], reverse=True), key=lambda x: x[0])
def check(candidate): # Check some simple cases assert 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 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], ...
f
HumanEval/88
def f(a): """ Given an array of non-negative integers, return a copy of the given array after sorting, you will sort the given array in ascending order if the sum( first index value, last index value) is odd, or sort it in descending order if the sum( first index value, last index value) is even. N...
return [] if len(a) == 0 else sorted(a, reverse= (a[0]+a[-1]) % 2 == 0)
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate([]) == [], "Error" assert candidate([5]) == [5], "Error" assert candidate([2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5], "Error" assert candidate([2, 4, 3, 0, 1, ...
f
HumanEval/89
def f(a): """Create a function encrypt that takes a string as an argument and returns a string encrypted with the alphabet being rotated. The alphabet should be rotated in a manner such that the letters shift down by two multiplied to two places. For example: f('hi') returns 'lm' f('asdfgh...
b = 'abcdefghijklmnopqrstuvwxyz' c = '' for d in a: if d in b: c += b[(b.index(d)+2*2) % 26] else: c += d return c
def check(candidate): # Check some simple cases assert candidate('hi') == 'lm', "This prints if this assert fails 1 (good for debugging!)" assert candidate('asdfghjkl') == 'ewhjklnop', "This prints if this assert fails 1 (good for debugging!)" assert candidate('gf') == 'kj', "This prints if this assert...
f
HumanEval/90
def f(a): """ You are given a list of integers. Write a function f() that returns the 2nd smallest element of the list. Return None if there is no such element. f([1, 2, 3, 4, 5]) == 2 f([5, 1, 4, 3, 2]) == 2 f([]) == None f([1, 1]) == None """
a = sorted(set(a)) return None if len(a) < 2 else a[1]
def check(candidate): # Check some simple cases 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, 0**0]) == None assert candidate([-35, 34, 1...
f
HumanEval/91
def f(a): """ You'll be given a string of words, and your task is to count the number of boredoms. A boredom is a sentence that starts with the word "I". Sentences are delimited by '.', '?' or '!'. For example: >>> f("Hello world") 0 >>> f("The sky is blue. The sun is shining. I love...
import re b = re.split(r'[.?!]\s*', a) return sum(sentence[0:2] == 'I ' for sentence in b)
def check(candidate): # Check some simple cases assert candidate("Hello world") == 0, "Test 1" assert candidate("Is the sky blue?") == 0, "Test 2" assert candidate("I love It !") == 1, "Test 3" assert candidate("bIt") == 0, "Test 4" assert candidate("I feel good today. I will be productive. wil...
f
HumanEval/92
def f(a, b, c): ''' Create a function that takes 3 numbers. Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers. Returns false in any other cases. Examples f(5, 2, 7) ➞ True f(3, 2, 2) ➞ False f(3, -2, 1) ➞ True f(3.6...
if isinstance(a,int) and isinstance(b,int) and isinstance(c,int): if (a+b==c) or (a+c==b) or (b+c==a): return True return False return False
def check(candidate): # Check some simple cases assert candidate(2, 3, 1)==True, "This prints if this assert fails 1 (good for debugging!)" assert candidate(2.5, 2, 3)==False, "This prints if this assert fails 2 (good for debugging!)" assert candidate(1.5, 5, 3.5)==False, "This prints if this assert fa...
f
HumanEval/93
def f(a): """ Write a function that takes a message, and encodes in such a way that it swaps case of all letters, replaces all vowels in the message with the letter that appears 2 places ahead of that vowel in the english alphabet. Assume only letters. Examples: >>> f('test') ...
b = "aeiouAEIOU" c = dict([(i, chr(ord(i) + 2)) for i in b]) a = a.swapcase() return ''.join([c[i] if i in b else i for i in a])
def check(candidate): # Check some simple cases assert candidate('TEST') == 'tgst', "This prints if this assert fails 1 (good for debugging!)" assert candidate('Mudasir') == 'mWDCSKR', "This prints if this assert fails 2 (good for debugging!)" assert candidate('YES') == 'ygs', "This prints if this asse...
f
HumanEval/94
def f(a): """You are given a list of integers. You need to find the largest prime value and return the sum of its digits. Examples: For a = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10 For a = [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] the output should be 25 For ...
def isPrime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return False return True maxx = 0 i = 0 while i < len(a): if(a[i] > maxx and isPrime(a[i])): maxx = a[i] i+=1 result = sum(int(digit) for digit in str(maxx)) retur...
def check(candidate): # Check some simple cases assert candidate([0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3]) == 10, "This prints if this assert fails 1 (good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate([1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1]...
f
HumanEval/95
def f(a): """ Given a dictionary, return True if all keys are strings in lower case or all keys are strings in upper case, else return False. The function should return False is the given dictionary is empty. Examples: f({"a":"apple", "b":"banana"}) should return True. f({"a":"apple", "A":"...
if len(a.keys()) == 0: return False else: state = "start" for key in a.keys(): if isinstance(key, str) == False: state = "mixed" break if state == "start": if key.isupper(): state = "upper" ...
def check(candidate): # Check some simple cases assert candidate({"p":"pineapple", "b":"banana"}) == True, "First test error: " + str(candidate({"p":"pineapple", "b":"banana"})) assert candidate({"p":"pineapple", "A":"banana", "B":"banana"}) == False, "Second test error: " + str(candidate({"p":"pineapple",...
f
HumanEval/96
def f(a): """Implement a function that takes an non-negative integer and returns an array of the first a integers that are prime numbers and less than a. for example: f(5) => [2,3] f(11) => [2,3,5,7] f(0) => [] f(20) => [2,3,5,7,11,13,17,19] f(1) => [] f(18) => [2,3,5,7,11,13,17] ...
b = [] for c in range(2, a): d = True for e in range(2, c): if c % e == 0: d = False break if d: b.append(c) return b
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]...
f
HumanEval/97
def f(a, b): """Complete the function that takes two integers and returns the product of their unit digits. Assume the input is always valid. Examples: f(148, 412) should return 16. f(19, 28) should return 72. f(2020, 1851) should return 0. f(14,-15) should return 20. """
return abs(a % 10) * abs(b % 10)
def check(candidate): # Check some simple cases assert candidate(148, 412) == 16, "First test error: " + str(candidate(148, 412)) assert candidate(19, 28) == 72, "Second test error: " + str(candidate(19, 28)) assert candidate(2020, 1851) == 0, "Third test error: " + str(c...
f
HumanEval/98
def f(a): """ Given a string a, count the number of uppercase vowels in even indices. For example: f('aBCdEf') returns 1 f('abcdefg') returns 0 f('dBBE') returns 0 """
b = 0 for c in range(0, len(a), 2): if a[c] in "AEIOU": b += 1 return b
def check(candidate): # Check some simple cases assert candidate('aBCdEf') == 1 assert candidate('abcdefg') == 0 assert candidate('dBBE') == 0 assert candidate('B') == 0 assert candidate('U') == 1 assert candidate('') == 0 assert candidate('EEEE') == 2 # Check some edge cases th...
f
HumanEval/99
def f(a): ''' Create a function that takes a value (string) representing a number and returns the closest integer to it. If the number is equidistant from two integers, round it away from zero. Examples >>> f("10") 10 >>> f("15.3") 15 Note: Rounding away from zero means th...
from math import floor, ceil if a.count('.') == 1: # remove trailing zeros while (a[-1] == '0'): a = a[:-1] b = float(a) if a[-2:] == '.5': if b > 0: res = ceil(b) else: res = floor(b) elif len(a) > 0: res = int(round(b))...
def check(candidate): # Check some simple cases assert candidate("10") == 10, "Test 1" assert candidate("14.5") == 15, "Test 2" assert candidate("-15.5") == -16, "Test 3" assert candidate("15.3") == 15, "Test 3" # Check some edge cases that are easy to work out by hand. assert candidate("0...
f
End of preview. Expand in Data Studio

YAML Metadata Warning:The task_categories "text2text-generation" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, image-text-to-image, image-text-to-video, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other

README.md exists but content is empty.
Downloads last month
5