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, 5.0], 0.8) == False assert candidate([1.0, 2.0, 3.0, 4.0, 5.0, 2.0], 0.1) == True assert candidate([1.1, 2.2, 3.1, 4.1, 5.1], 1.0) == True assert candidate([1.1, 2.2, 3.1, 4.1, 5.1], 0.5) == False
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 nested within each other Ignore any spaces in the input string. >>> f('( ) (( )) (( )( ))') ['()', '(())', '(()())'] """
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('(()(())((())))') == [ '(()(())((())))' ] 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 should return False. >>> f([1, 2, 3]) False >>> f([1, 2, -4, 5]) True """
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, -5]) == True assert candidate([1, -2, 2, -2, 5, -5, 4, -4]) == True
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 - x_mean | >>> f([1.0, 2.0, 3.0, 4.0]) 1.0 """
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. >>> f('(()()) ((())) () ((())()())') [2, 3, 1, 3] """
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(' ') if x]
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', 'aaaxxy', 'xxxAAA', 'xxx'] assert candidate(['grunt', 'trumpet', 'prune', 'gruesome'], 'run') == ['grunt', 'prune']
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]) (10, 24) """
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 of the string reverse of a string prefix that comes before the palindromic suffix. >>> f('') '' >>> f('cat') 'catac' >>> f('cata') 'catac' """
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', 'ccc']) 'ccc' """
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, lasts four beats 'o|' - half note, lasts two beats '.|' - quater note, lasts one beat >>> f('o o| .| o| o| .| .| .| .| o o') [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4] """
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| .| o o| o o|') == [2, 1, 2, 1, 4, 2, 4, 2]
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 five') 'one three five' """
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 candidate('six five four three two one zero') == 'zero one two three four five six'
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) >>> f([1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) (2.0, 2.0) """
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(elem - elem2) if new_b < b: b = new_b a_pair = tuple(sorted([elem, elem2])) return a_pair
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, 5.0, 2.0]) == (2.0, 2.0) assert candidate([1.1, 2.2, 3.1, 4.1, 5.1]) == (2.2, 3.1)
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.0, 1.0, 0.5, 0.75] assert candidate([12.0, 11.0, 15.0, 13.0, 14.0]) == [0.25, 0.0, 1.0, 0.5, 0.75]
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 factors >>> f(8) [2, 2, 2] >>> f(25) [5, 5] >>> f(70) [2, 5, 7] """
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 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
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 candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
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 such that f(b) = 0. f returns only only zero point, even if there are many. Moreover, f only takes list a having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(f([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(f([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """
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: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(f0(coeffs, solution)) < 1e-4
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]) [1, 2, 3] >>> f([5, 6, 3, 4, 8, 9, 2]) [2, 6, 3, 4, 8, 9, 5] """
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, 2, 3, 11, 12, -10])) assert tuple(candidate([5, 6, 3, 4, 8, 9, 2])) == tuple([2, 6, 3, 4, 8, 9, 5]) assert tuple(candidate([5, 8, 3, 4, 6, 9, 2])) == tuple([2, 8, 3, 4, 6, 9, 5]) assert tuple(candidate([5, 6, 9, 4, 8, 3, 2])) == tuple([2, 6, 9, 4, 8, 3, 5]) assert tuple(candidate([5, 6, 3, 4, 8, 9, 2, 1])) == tuple([2, 6, 3, 4, 8, 9, 5, 1])
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, 11, 23, -10])
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:] + group[0]) if len(group) == 3 else group for group in b] return "".join(b) def f(a: str): """ takes as input string encoded with f0 function. Returns decoded string. """
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]): a -= 1 if a == 0: return 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 assert candidate(10) == 433494437
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]) True >>> f([1]) False """
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 assert candidate([1]) == False assert candidate([1, 3, 5, -100]) == False assert candidate([100, 3, 5, -100]) == False
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 said to collide when a car that's moving left to right hits a car that's moving right to left. However, the cars are infinitely sturdy and strong; as a result, they continue moving in their trajectory as if they did not collide. This function outputs the number of such collisions. """
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 >>> f([1]) False """
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 assert candidate([-3, 9, -1, 3, 2, 31]) == True assert candidate([-3, 9, -1, 4, 2, 30]) == False assert candidate([-3, 9, -1, 4, 2, 31]) == False
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, x + 1) == str(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 of the Fib4 number sequence. Do not use recursion. >>> f(5) 4 >>> f(6) 8 >>> f(7) 14 """
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(encoded_str)) == str
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) assert candidate(x, y) == x + y
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('eabcdzzzz', 'dddzzzzzzzddddabc') False """
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 assert candidate('eabcdzzzz', 'dddzzzzzzzddddabc') == False assert candidate('aabb', 'aaccc') == False
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("<<<<") 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 assert candidate([1, 2, 3, 4, 5, 60]) == True assert candidate([9, 9, 9, 9]) == True
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("((((") 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 FibFib number sequence. >>> f(1) 0 >>> f(5) 4 >>> f(8) 24 """
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. Example: >>> f("abcde") 2 >>> f("ACEDY") 3 """
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" assert candidate("ACEDY") == 3, "Test 7" # Check some edge cases that are easy to work out by hand. assert True, "This prints if this assert fails 2 (also good for debugging!)"
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 hand. assert candidate(11, 101) == "11", "This prints if this assert fails 2 (also good for debugging!)"
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 candidate("woArBld") == 131, "Error" assert candidate("aAaaaXa") == 153, "Error" # Check some edge cases that are easy to work out by hand. assert True, "This prints if this assert fails 2 (also good for debugging!)" assert candidate(" How are yOu?") == 151, "Error" assert candidate("You arE Very Smart") == 327, "Error"
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 that represent the total number of the fruits in the basket return the number of the mango fruits in the basket. for examble: f("5 apples and 6 oranges", 19) ->19 - 5 - 6 = 8 f("0 apples and 1 oranges",3) -> 3 - 0 - 1 = 2 f("2 apples and 3 oranges", 100) -> 100 - 2 - 3 = 95 f("100 apples and 1 oranges",120) -> 120 - 100 - 1 = 19 """
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",100) == 95 assert candidate("2 apples and 3 oranges",5) == 0 assert candidate("1 apples and 100 oranges",120) == 19
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 has smallest index. The plucked node should be returned in a list, [ smalest_value, its index ], If there are no even values or the given array is empty, return []. Example 1: Input: [4,2,3] Output: [2, 1] Explanation: 2 has the smallest even value, and 2 has the smallest index. Example 2: Input: [1,2,3] Output: [2, 1] Explanation: 2 has the smallest even value, and 2 has the smallest index. Example 3: Input: [] Output: [] Example 4: Input: [5, 0, 3, 0, 4, 2] Output: [0, 1] Explanation: 0 is the smallest value, but there are two zeros, so we will choose the first zero, which has the smallest index. Constraints: * 1 <= nodes.length <= 10000 * 0 <= node.value """
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], "Error" # Check some edge cases that are easy to work out by hand. assert True, "This prints if this assert fails 2 (also good for debugging!)" assert candidate([1, 2, 3, 0, 5, 3]) == [0, 3], "Error" assert candidate([5, 4, 8, 4 ,8]) == [4, 1], "Error" assert candidate([7, 6, 7, 1]) == [6, 1], "Error" assert candidate([7, 9, 7, 1]) == [], "Error"
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 exist, return -1. Examples: f([4, 1, 2, 2, 3, 1]) == 2 f([1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3 f([5, 5, 4, 4, 4]) == -1 '''
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 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
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]) == [5, 5, 5, 5] assert candidate([]) == [] assert candidate([1,2,3,4,5,6,7,8]) == [1, 8, 2, 7, 3, 6, 4, 5] assert candidate([0,2,2,2,5,5,-5,-5]) == [-5, 5, -5, 5, 0, 2, 2, 2] assert candidate([111111]) == [111111] # Check some edge cases that are easy to work out by hand. assert True
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. Example: f(3, 4, 5) == 6.00 f(1, 2, 10) == -1 '''
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(10, 5, 7) == 16.25 assert candidate(2, 6, 3) == -1 # Check some edge cases that are easy to work out by hand. assert candidate(1, 1, 1) == 0.43, "This prints if this assert fails 2 (also good for debugging!)" assert candidate(2, 2, 10) == -1
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 than the maximum possible weight, but it's unbalanced. f([3, 2, 3], 1) ➞ False # it's balanced, but 3+2+3 is more than the maximum possible weight. f([3, 2, 3], 9) ➞ True # 3+2+3 is less than the maximum possible weight, and it's balanced. f([3], 5) ➞ True # 3 is less than the maximum possible weight, and it's balanced. '''
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 False assert candidate([5], 5) is True
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,2,3,5,4,7,9,6]) == 4 f([1, 2, 3, 4, 3, 2, 2]) == 1 f([1, 2, 3, 2, 1]) == 0 """
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, 1]) == 0 assert candidate([3, 1, 1, 3]) == 0 assert candidate([1]) == 0 assert candidate([0, 1]) == 1
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'], ['hI', 'Hi']) ➞ ['hI', 'Hi'] f(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) ➞ ['hi', 'admin'] f(['hi', 'admin'], ['hI', 'hi', 'hi']) ➞ ['hI', 'hi', 'hi'] f(['4'], ['1', '2', '3', '4', '5']) ➞ ['4'] '''
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'] assert candidate(['4'], ['1', '2', '3', '4', '5']) == ['4'] assert candidate(['hi', 'admin'], ['hI', 'Hi']) == ['hI', 'Hi'] assert candidate(['hi', 'admin'], ['hI', 'hi', 'hi']) == ['hI', 'hi', 'hi'] assert candidate(['hi', 'admin'], ['hI', 'hi', 'hii']) == ['hi', 'admin'] # Check some edge cases that are easy to work out by hand. assert True, "This prints if this assert fails 2 (also good for debugging!)" assert candidate([], ['this']) == [] assert candidate(['this'], []) == []
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 not is_prime(k): continue if i * j * k == a: return True return False
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 assert candidate(11 * 9 * 9) == False assert candidate(11 * 13 * 7) == True
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 (good for debugging!)" assert candidate(9, 3)==True, "This prints if this assert fails 1 (good for debugging!)" assert candidate(16, 4)==True, "This prints if this assert fails 1 (good for debugging!)" assert candidate(24, 2)==False, "This prints if this assert fails 1 (good for debugging!)" assert candidate(128, 4)==False, "This prints if this assert fails 1 (good for debugging!)" assert candidate(12, 6)==False, "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, 1)==True, "This prints if this assert fails 2 (also good for debugging!)" assert candidate(1, 12)==True, "This prints if this assert fails 2 (also good for debugging!)"
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 test error: " + str(candidate(64)) assert candidate(180) == False, "Fifth test error: " + str(candidate(180)) assert candidate(1000) == True, "Sixth test error: " + str(candidate(1000)) # Check some edge cases that are easy to work out by hand. assert candidate(0) == True, "1st edge test error: " + str(candidate(0)) assert candidate(1729) == False, "2nd edge test error: " + str(candidate(1728))
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 are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. Prime numbers are 2, 3, 5, 7, 11, 13, 17,... So you have to determine a number of the following digits: 2, 3, 5, 7, B (=decimal 11), D (=decimal 13). Note: you may assume the input is always correct or empty string, and symbols A,B,C,D,E,F are always uppercase. Examples: For a = "AB" the output should be 1. For a = "1077E" the output should be 2. For a = "ABED1A33" the output should be 4. For a = "123456789ABCDEF0" the output should be 6. For a = "2020" the output should be 2. """
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")) assert candidate("2020") == 2, "Fourth test error: " + str(candidate("2020")) assert candidate("123456789ABCDEF0") == 6, "Fifth test error: " + str(candidate("123456789ABCDEF0")) assert candidate("112233445566778899AABBCCDDEEFF00") == 12, "Sixth test error: " + str(candidate("112233445566778899AABBCCDDEEFF00")) # Check some edge cases that are easy to work out by hand. assert candidate([]) == 0
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 beginning and at the end of the string. The extra characters are there to help with the format. Examples: f(15) # returns "db1111db" f(32) # returns "db100000db" """
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 work out by hand. assert True, "This prints if this assert fails 2 (also good for debugging!)"
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) => False """
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" assert candidate("iopaxpoi") == True , "iopaxpoi" assert candidate("iopaxioi") == False , "iopaxioi"
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 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: f([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', '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-") elif g > 2.0: b.append("C+") elif g > 1.7: b.append("C") elif g > 1.3: b.append("C-") elif g > 1.0: b.append("D+") elif g > 0.7: b.append("D") elif g > 0.0: b.append("D-") else: b.append("E") return 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+'] assert candidate([0, 0.7]) == ['E', 'D-'] # Check some edge cases that are easy to work out by hand. assert True
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') == True assert candidate('Wow') == True assert candidate('') == False assert candidate('HI') == True assert candidate('go') == True assert candidate('gogo') == False assert candidate('aaaaaaaaaaaaaaa') == False # Check some edge cases that are easy to work out by hand. assert candidate('Madam') == True assert candidate('M') == False assert candidate('0') == False
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 are easy to work out by hand. assert True, "This prints if this assert fails 2 (also good for debugging!)"
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 output should be "1100". Variables: @a integer Constraints: 0 ≀ a ≀ 10000. Output: a string of binary number """
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 hand. assert True, "This prints if this assert fails 2 (also good for debugging!)" assert candidate(333) == "1001", "Error" assert candidate(963) == "10010", "Error"
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 order of words and blank spaces in the sentence. For example: f('Hi') returns 'Hi' f('hello') returns 'ehllo' f('Hello World!!!') returns 'Hello !!!Wdlor' """
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 candidate('Hi. My name is Mister Robot. How are you?') == '.Hi My aemn is Meirst .Rboot How aer ?ouy' # Check some edge cases that are easy to work out by hand. assert True
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 each tuple 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: f([ [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)] f([], 1) == [] f([[], [1], [1, 2, 3]], 3) == [(2, 2)] """
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], [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 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 candidate([], 1) == [] assert candidate([[1]], 2) == [] assert candidate([[], [1], [1, 2, 3]], 3) == [(2, 2)] # Check some edge cases that are easy to work out by hand. assert True
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. Note: * don't change the given array. Examples: * f([]) => [] * f([5]) => [5] * f([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5] * f([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0] """
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, 5, 6]) == [6, 5, 4, 3, 2, 1, 0], "Error" # Check some edge cases that are easy to work out by hand. assert True, "This prints if this assert fails 2 (also good for debugging!)" assert candidate([2, 1]) == [1, 2], "Error" assert candidate([15, 42, 87, 32 ,11, 0]) == [0, 11, 15, 32, 42, 87], "Error" assert candidate([21, 14, 23, 11]) == [23, 21, 14, 11], "Error"
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('asdfghjkl') returns 'ewhjklnop' f('gf') returns 'kj' f('et') returns 'ix' """
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 fails 1 (good for debugging!)" assert candidate('et') == 'ix', "This prints if this assert fails 1 (good for debugging!)" assert candidate('faewfawefaewg')=='jeiajeaijeiak', "This prints if this assert fails 1 (good for debugging!)" assert candidate('hellomyfriend')=='lippsqcjvmirh', "This prints if this assert fails 2 (good for debugging!)" assert candidate('dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh')=='hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl', "This prints if this assert fails 3 (good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate('a')=='e', "This prints if this assert fails 2 (also good for debugging!)"
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, 12, -45]) == -35 # Check some edge cases that are easy to work out by hand. assert True
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 this weather") 1 """
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. will kill It") == 2, "Test 5" assert candidate("You and I are going for a walk") == 0, "Test 6" # Check some edge cases that are easy to work out by hand. assert True, "This prints if this assert fails 2 (also good for debugging!)"
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, -2.2, 2) ➞ False '''
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 fails 3 (good for debugging!)" assert candidate(2, 6, 2)==False, "This prints if this assert fails 4 (good for debugging!)" assert candidate(4, 2, 2)==True, "This prints if this assert fails 5 (good for debugging!)" assert candidate(2.2, 2.2, 2.2)==False, "This prints if this assert fails 6 (good for debugging!)" assert candidate(-4, 6, 2)==True, "This prints if this assert fails 7 (good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate(2,1,1)==True, "This prints if this assert fails 8 (also good for debugging!)" assert candidate(3,4,7)==True, "This prints if this assert fails 9 (also good for debugging!)" assert candidate(3.0,4,7)==False, "This prints if this assert fails 10 (also good for debugging!)"
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') 'TGST' >>> f('This is a message') 'tHKS KS C MGSSCGG' """
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 assert fails 3 (good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate('This is a message') == 'tHKS KS C MGSSCGG', "This prints if this assert fails 2 (also good for debugging!)" assert candidate("I DoNt KnOw WhAt tO WrItE") == 'k dQnT kNqW wHcT Tq wRkTg', "This prints if this assert fails 2 (also good for debugging!)"
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 a = [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3] the output should be 13 For a = [0,724,32,71,99,32,6,0,5,91,83,0,5,6] the output should be 11 For a = [0,81,12,3,1,21] the output should be 3 For a = [0,8,1,2,1,7] the output should be 7 """
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)) return result
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]) == 25, "This prints if this assert fails 2 (also good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate([1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3]) == 13, "This prints if this assert fails 3 (also good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate([0,724,32,71,99,32,6,0,5,91,83,0,5,6]) == 11, "This prints if this assert fails 4 (also good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate([0,81,12,3,1,21]) == 3, "This prints if this assert fails 5 (also good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate([0,8,1,2,1,7]) == 7, "This prints if this assert fails 6 (also good for debugging!)" assert candidate([8191]) == 19, "This prints if this assert fails 7 (also good for debugging!)" assert candidate([8191, 123456, 127, 7]) == 19, "This prints if this assert fails 8 (also good for debugging!)" assert candidate([127, 97, 8192]) == 10, "This prints if this assert fails 9 (also good for debugging!)"
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":"banana", "B":"banana"}) should return False. f({"a":"apple", 8:"banana", "a":"apple"}) should return False. f({"Name":"John", "Age":"36", "City":"Houston"}) should return False. f({"STATE":"NC", "ZIP":"12345" }) should return True. """
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" elif key.islower(): state = "lower" else: break elif (state == "upper" and not key.isupper()) or (state == "lower" and not key.islower()): state = "mixed" break else: break return state == "upper" or state == "lower"
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", "A":"banana", "B":"banana"})) assert candidate({"p":"pineapple", 5:"banana", "a":"apple"}) == False, "Third test error: " + str(candidate({"p":"pineapple", 5:"banana", "a":"apple"})) assert candidate({"Name":"John", "Age":"36", "City":"Houston"}) == False, "Fourth test error: " + str(candidate({"Name":"John", "Age":"36", "City":"Houston"})) assert candidate({"STATE":"NC", "ZIP":"12345" }) == True, "Fifth test error: " + str(candidate({"STATE":"NC", "ZIP":"12345" })) assert candidate({"fruit":"Orange", "taste":"Sweet" }) == True, "Fourth test error: " + str(candidate({"fruit":"Orange", "taste":"Sweet" })) # Check some edge cases that are easy to work out by hand. assert candidate({}) == False, "1st edge test error: " + str(candidate({}))
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] 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]
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(candidate(2020, 1851)) assert candidate(14,-15) == 20, "Fourth test error: " + str(candidate(14,-15)) assert candidate(76, 67) == 42, "Fifth test error: " + str(candidate(76, 67)) assert candidate(17, 27) == 49, "Sixth test error: " + str(candidate(17, 27)) # Check some edge cases that are easy to work out by hand. assert candidate(0, 1) == 0, "1st edge test error: " + str(candidate(0, 1)) assert candidate(0, 0) == 0, "2nd edge test error: " + str(candidate(0, 0))
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 that are easy to work out by hand. assert True
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 that if the given number is equidistant from two integers, the one you should return is the one that is the farthest from zero. For example f("14.5") should return 15 and f("-14.5") should return -15. '''
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)) else: res = 0 return res
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") == 0, "Test 0"
f