task_id
stringlengths
11
13
prompt
stringlengths
133
1.36k
canonical_solution
stringlengths
16
864
test
stringlengths
183
1.8k
entry_point
stringlengths
3
25
HumanEval/4
from typing import List def mean_absolute_deviation(numbers: 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 | >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0]) 1.0 """
mean = sum(numbers) / len(numbers) return sum(abs(x - mean) for x in numbers) / len(numbers)
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
mean_absolute_deviation
HumanEval/96
def count_up_to(n): """Implement a function that takes an non-negative integer and returns an array of the first n integers that are prime numbers and less than n. for example: count_up_to(5) => [2,3] count_up_to(11) => [2,3,5,7] count_up_to(0) => [] count_up_to(20) => [2,3,5,7,11,13,17,19] count_up_to(1) => [] count_up_to(18) => [2,3,5,7,11,13,17] """
primes = [] for i in range(2, n): is_prime = True for j in range(2, i): if i % j == 0: is_prime = False break if is_prime: primes.append(i) return primes
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]
count_up_to
HumanEval/21
from typing import List def rescale_to_unit(numbers: List[float]) -> List[float]: """ Given list of numbers (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 >>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0]) [0.0, 0.25, 0.5, 0.75, 1.0] """
min_number = min(numbers) max_number = max(numbers) return [(x - min_number) / (max_number - min_number) for x in numbers]
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]
rescale_to_unit
HumanEval/38
def encode_cyclic(s: str): """ returns encoded string by cycling groups of three characters. """ # split string to groups. Each of length 3. groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) // 3)] # cycle elements in each group. Unless group has fewer elements than 3. groups = [(group[1:] + group[0]) if len(group) == 3 else group for group in groups] return "".join(groups) def decode_cyclic(s: str): """ takes as input string encoded with encode_cyclic function. Returns decoded string. """
return encode_cyclic(encode_cyclic(s))
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 = encode_cyclic(str) assert candidate(encoded_str) == str
decode_cyclic
HumanEval/16
def count_distinct_characters(string: str) -> int: """ Given a string, find out how many distinct characters (regardless of case) does it consist of >>> count_distinct_characters('xyzXYZ') 3 >>> count_distinct_characters('Jerry') 4 """
return len(set(string.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
count_distinct_characters
HumanEval/68
def pluck(arr): """ "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(arr) == 0): return [] evens = list(filter(lambda x: x%2 == 0, arr)) if(evens == []): return [] return [min(evens), arr.index(min(evens))]
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"
pluck
HumanEval/117
def select_words(s, n): """Given a string s and a natural number n, you have been tasked to implement a function that returns a list of all words from string s that contain exactly n consonants, in order these words appear in the string s. If the string s is empty then the function should return an empty list. Note: you may assume the input string contains only letters and spaces. Examples: select_words("Mary had a little lamb", 4) ==> ["little"] select_words("Mary had a little lamb", 3) ==> ["Mary", "lamb"] select_words("simple white space", 2) ==> [] select_words("Hello world", 4) ==> ["world"] select_words("Uncle sam", 3) ==> ["Uncle"] """
result = [] for word in s.split(): n_consonants = 0 for i in range(0, len(word)): if word[i].lower() not in ["a","e","i","o","u"]: n_consonants += 1 if n_consonants == n: result.append(word) return result
def check(candidate): # Check some simple cases assert candidate("Mary had a little lamb", 4) == ["little"], "First test error: " + str(candidate("Mary had a little lamb", 4)) assert candidate("Mary had a little lamb", 3) == ["Mary", "lamb"], "Second test error: " + str(candidate("Mary had a little lamb", 3)) assert candidate("simple white space", 2) == [], "Third test error: " + str(candidate("simple white space", 2)) assert candidate("Hello world", 4) == ["world"], "Fourth test error: " + str(candidate("Hello world", 4)) assert candidate("Uncle sam", 3) == ["Uncle"], "Fifth test error: " + str(candidate("Uncle sam", 3)) # Check some edge cases that are easy to work out by hand. assert candidate("", 4) == [], "1st edge test error: " + str(candidate("", 4)) assert candidate("a b c d e f", 1) == ["b", "c", "d", "f"], "2nd edge test error: " + str(candidate("a b c d e f", 1))
select_words
HumanEval/133
def sum_squares(lst): """You are given a list of numbers. You need to return the sum of squared numbers in the given list, round each element in the list to the upper int(Ceiling) first. Examples: For lst = [1,2,3] the output should be 14 For lst = [1,4,9] the output should be 98 For lst = [1,3,5,7] the output should be 84 For lst = [1.4,4.2,0] the output should be 29 For lst = [-2.4,1,1] the output should be 6 """
import math squared = 0 for i in lst: squared += math.ceil(i)**2 return squared
def check(candidate): # Check some simple cases assert candidate([1,2,3])==14, "This prints if this assert fails 1 (good for debugging!)" assert candidate([1.0,2,3])==14, "This prints if this assert fails 1 (good for debugging!)" assert candidate([1,3,5,7])==84, "This prints if this assert fails 1 (good for debugging!)" assert candidate([1.4,4.2,0])==29, "This prints if this assert fails 1 (good for debugging!)" assert candidate([-2.4,1,1])==6, "This prints if this assert fails 1 (good for debugging!)" assert candidate([100,1,15,2])==10230, "This prints if this assert fails 1 (good for debugging!)" assert candidate([10000,10000])==200000000, "This prints if this assert fails 1 (good for debugging!)" assert candidate([-1.4,4.6,6.3])==75, "This prints if this assert fails 1 (good for debugging!)" assert candidate([-1.4,17.9,18.9,19.9])==1086, "This prints if this assert fails 1 (good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate([0])==0, "This prints if this assert fails 2 (also good for debugging!)" assert candidate([-1])==1, "This prints if this assert fails 2 (also good for debugging!)" assert candidate([-1,1,0])==2, "This prints if this assert fails 2 (also good for debugging!)"
sum_squares
HumanEval/138
def is_equal_to_sum_even(n): """Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers Example is_equal_to_sum_even(4) == False is_equal_to_sum_even(6) == False is_equal_to_sum_even(8) == True """
return n%2 == 0 and n >= 8
def check(candidate): assert candidate(4) == False assert candidate(6) == False assert candidate(8) == True assert candidate(10) == True assert candidate(11) == False assert candidate(12) == True assert candidate(13) == False assert candidate(16) == True
is_equal_to_sum_even
HumanEval/7
from typing import List def filter_by_substring(strings: List[str], substring: str) -> List[str]: """ Filter an input list of strings only for ones that contain given substring >>> filter_by_substring([], 'a') [] >>> filter_by_substring(['abc', 'bacd', 'cde', 'array'], 'a') ['abc', 'bacd', 'array'] """
return [x for x in strings if substring 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']
filter_by_substring
HumanEval/47
def median(l: list): """Return median of elements in the list l. >>> median([3, 1, 2, 4, 5]) 3 >>> median([-10, 4, 6, 1000, 10, 20]) 15.0 """
l = sorted(l) if len(l) % 2 == 1: return l[len(l) // 2] else: return (l[len(l) // 2 - 1] + l[len(l) // 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
median
HumanEval/23
def strlen(string: str) -> int: """ Return length of given string >>> strlen('') 0 >>> strlen('abc') 3 """
return len(string)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == 0 assert candidate('x') == 1 assert candidate('asdasnakj') == 9
strlen
HumanEval/163
def generate_integers(a, b): """ Given two positive integers a and b, return the even digits between a and b, in ascending order. For example: generate_integers(2, 8) => [2, 4, 6, 8] generate_integers(8, 2) => [2, 4, 6, 8] generate_integers(10, 14) => [] """
lower = max(2, min(a, b)) upper = min(8, max(a, b)) return [i for i in range(lower, upper+1) if i % 2 == 0]
def check(candidate): # Check some simple cases assert candidate(2, 10) == [2, 4, 6, 8], "Test 1" assert candidate(10, 2) == [2, 4, 6, 8], "Test 2" assert candidate(132, 2) == [2, 4, 6, 8], "Test 3" assert candidate(17,89) == [], "Test 4" # 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!)"
generate_integers
HumanEval/81
def numerical_letter_grade(grades): """It is the last week of the semester and the teacher has to give the grades to students. The teacher has been making her own algorithm for grading. The only problem is, she has lost the code she used for grading. She has given you a list of GPAs for some students and you have to write a function that can output a list of letter grades using the following table: GPA | Letter grade 4.0 A+ > 3.7 A > 3.3 A- > 3.0 B+ > 2.7 B > 2.3 B- > 2.0 C+ > 1.7 C > 1.3 C- > 1.0 D+ > 0.7 D > 0.0 D- 0.0 E Example: grade_equation([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-'] """
letter_grade = [] for gpa in grades: if gpa == 4.0: letter_grade.append("A+") elif gpa > 3.7: letter_grade.append("A") elif gpa > 3.3: letter_grade.append("A-") elif gpa > 3.0: letter_grade.append("B+") elif gpa > 2.7: letter_grade.append("B") elif gpa > 2.3: letter_grade.append("B-") elif gpa > 2.0: letter_grade.append("C+") elif gpa > 1.7: letter_grade.append("C") elif gpa > 1.3: letter_grade.append("C-") elif gpa > 1.0: letter_grade.append("D+") elif gpa > 0.7: letter_grade.append("D") elif gpa > 0.0: letter_grade.append("D-") else: letter_grade.append("E") return letter_grade
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
numerical_letter_grade
HumanEval/129
def minPath(grid, k): """ Given a grid with N rows and N columns (N >= 2) and a positive integer k, each cell of the grid contains a value. Every integer in the range [1, N * N] inclusive appears exactly once on the cells of the grid. You have to find the minimum path of length k in the grid. You can start from any cell, and in each step you can move to any of the neighbor cells, in other words, you can go to cells which share an edge with you current cell. Please note that a path of length k means visiting exactly k cells (not necessarily distinct). You CANNOT go off the grid. A path A (of length k) is considered less than a path B (of length k) if after making the ordered lists of the values on the cells that A and B go through (let's call them lst_A and lst_B), lst_A is lexicographically less than lst_B, in other words, there exist an integer index i (1 <= i <= k) such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have lst_A[j] = lst_B[j]. It is guaranteed that the answer is unique. Return an ordered list of the values on the cells that the minimum path go through. Examples: Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3 Output: [1, 2, 1] Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1 Output: [1] """
n = len(grid) val = n * n + 1 for i in range(n): for j in range(n): if grid[i][j] == 1: temp = [] if i != 0: temp.append(grid[i - 1][j]) if j != 0: temp.append(grid[i][j - 1]) if i != n - 1: temp.append(grid[i + 1][j]) if j != n - 1: temp.append(grid[i][j + 1]) val = min(temp) ans = [] for i in range(k): if i % 2 == 0: ans.append(1) else: ans.append(val) return ans
def check(candidate): # Check some simple cases print assert candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3) == [1, 2, 1] assert candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1) == [1] assert candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], 4) == [1, 2, 1, 2] assert candidate([[6, 4, 13, 10], [5, 7, 12, 1], [3, 16, 11, 15], [8, 14, 9, 2]], 7) == [1, 10, 1, 10, 1, 10, 1] assert candidate([[8, 14, 9, 2], [6, 4, 13, 15], [5, 7, 1, 12], [3, 10, 11, 16]], 5) == [1, 7, 1, 7, 1] assert candidate([[11, 8, 7, 2], [5, 16, 14, 4], [9, 3, 15, 6], [12, 13, 10, 1]], 9) == [1, 6, 1, 6, 1, 6, 1, 6, 1] assert candidate([[12, 13, 10, 1], [9, 3, 15, 6], [5, 16, 14, 4], [11, 8, 7, 2]], 12) == [1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6] assert candidate([[2, 7, 4], [3, 1, 5], [6, 8, 9]], 8) == [1, 3, 1, 3, 1, 3, 1, 3] assert candidate([[6, 1, 5], [3, 8, 9], [2, 7, 4]], 8) == [1, 5, 1, 5, 1, 5, 1, 5] # Check some edge cases that are easy to work out by hand. assert candidate([[1, 2], [3, 4]], 10) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2] assert candidate([[1, 3], [3, 2]], 10) == [1, 3, 1, 3, 1, 3, 1, 3, 1, 3]
minPath
HumanEval/140
def fix_spaces(text): """ Given a string text, replace all spaces in it with underscores, and if a string has more than 2 consecutive spaces, then replace all consecutive spaces with - fix_spaces("Example") == "Example" fix_spaces("Example 1") == "Example_1" fix_spaces(" Example 2") == "_Example_2" fix_spaces(" Example 3") == "_Example-3" """
new_text = "" i = 0 start, end = 0, 0 while i < len(text): if text[i] == " ": end += 1 else: if end - start > 2: new_text += "-"+text[i] elif end - start > 0: new_text += "_"*(end - start)+text[i] else: new_text += text[i] start, end = i+1, i+1 i+=1 if end - start > 2: new_text += "-" elif end - start > 0: new_text += "_" return new_text
def check(candidate): # Check some simple cases assert candidate("Example") == "Example", "This prints if this assert fails 1 (good for debugging!)" assert candidate("Mudasir Hanif ") == "Mudasir_Hanif_", "This prints if this assert fails 2 (good for debugging!)" assert candidate("Yellow Yellow Dirty Fellow") == "Yellow_Yellow__Dirty__Fellow", "This prints if this assert fails 3 (good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate("Exa mple") == "Exa-mple", "This prints if this assert fails 4 (good for debugging!)" assert candidate(" Exa 1 2 2 mple") == "-Exa_1_2_2_mple", "This prints if this assert fails 4 (good for debugging!)"
fix_spaces
HumanEval/69
def search(lst): ''' You are given a non-empty list of positive integers. Return the greatest integer that is greater than zero, and has a frequency greater than or equal to the value of the integer itself. The frequency of an integer is the number of times it appears in the list. If no such a value exist, return -1. Examples: search([4, 1, 2, 2, 3, 1]) == 2 search([1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3 search([5, 5, 4, 4, 4]) == -1 '''
frq = [0] * (max(lst) + 1) for i in lst: frq[i] += 1; ans = -1 for i in range(1, len(frq)): if frq[i] >= i: ans = i return ans
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
search
HumanEval/125
def split_words(txt): ''' Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25 Examples split_words("Hello world!") ➞ ["Hello", "world!"] split_words("Hello,world!") ➞ ["Hello", "world!"] split_words("abcdef") == 3 '''
if " " in txt: return txt.split() elif "," in txt: return txt.replace(',',' ').split() else: return len([i for i in txt if i.islower() and ord(i)%2 == 0])
def check(candidate): assert candidate("Hello world!") == ["Hello","world!"] assert candidate("Hello,world!") == ["Hello","world!"] assert candidate("Hello world,!") == ["Hello","world,!"] assert candidate("Hello,Hello,world !") == ["Hello,Hello,world","!"] assert candidate("abcdef") == 3 assert candidate("aaabb") == 2 assert candidate("aaaBb") == 1 assert candidate("") == 0
split_words
HumanEval/94
def skjkasdkd(lst): """You are given a list of integers. You need to find the largest prime value and return the sum of its digits. Examples: For lst = [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 lst = [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] the output should be 25 For lst = [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3] the output should be 13 For lst = [0,724,32,71,99,32,6,0,5,91,83,0,5,6] the output should be 11 For lst = [0,81,12,3,1,21] the output should be 3 For lst = [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(lst): if(lst[i] > maxx and isPrime(lst[i])): maxx = lst[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!)"
skjkasdkd
HumanEval/36
def fizz_buzz(n: int): """Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13. >>> fizz_buzz(50) 0 >>> fizz_buzz(78) 2 >>> fizz_buzz(79) 3 """
ns = [] for i in range(n): if i % 11 == 0 or i % 13 == 0: ns.append(i) s = ''.join(list(map(str, ns))) ans = 0 for c in s: ans += (c == '7') return ans
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
fizz_buzz
HumanEval/41
def car_race_collision(n: int): """ Imagine a road that's a perfectly straight infinitely long line. n cars are driving left to right; simultaneously, a different set of n cars are driving right to left. The two sets of cars start out being very far from each other. All cars move in the same speed. Two cars are said to collide when a car that's moving left to right hits a car that's moving right to left. However, the cars are infinitely sturdy and strong; as a result, they continue moving in their trajectory as if they did not collide. This function outputs the number of such collisions. """
return n**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
car_race_collision
HumanEval/101
def words_string(s): """ You will be given a string of words separated by commas or spaces. Your task is to split the string into words and return an array of the words. For example: words_string("Hi, my name is John") == ["Hi", "my", "name", "is", "John"] words_string("One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"] """
if not s: return [] s_list = [] for letter in s: if letter == ',': s_list.append(' ') else: s_list.append(letter) s_list = "".join(s_list) return s_list.split()
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate("Hi, my name is John") == ["Hi", "my", "name", "is", "John"] assert candidate("One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"] assert candidate("Hi, my name") == ["Hi", "my", "name"] assert candidate("One,, two, three, four, five, six,") == ["One", "two", "three", "four", "five", "six"] # 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("") == [] assert candidate("ahmed , gamal") == ["ahmed", "gamal"]
words_string
HumanEval/151
def double_the_difference(lst): ''' Given a list of numbers, return the sum of squares of the numbers in the list that are odd. Ignore numbers that are negative or not integers. double_the_difference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10 double_the_difference([-1, -2, 0]) == 0 double_the_difference([9, -2]) == 81 double_the_difference([0]) == 0 If the input list is empty, return 0. '''
return sum([i**2 for i in lst if i > 0 and i%2!=0 and "." not in str(i)])
def check(candidate): # Check some simple cases assert candidate([]) == 0 , "This prints if this assert fails 1 (good for debugging!)" assert candidate([5, 4]) == 25 , "This prints if this assert fails 2 (good for debugging!)" assert candidate([0.1, 0.2, 0.3]) == 0 , "This prints if this assert fails 3 (good for debugging!)" assert candidate([-10, -20, -30]) == 0 , "This prints if this assert fails 4 (good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate([-1, -2, 8]) == 0, "This prints if this assert fails 5 (also good for debugging!)" assert candidate([0.2, 3, 5]) == 34, "This prints if this assert fails 6 (also good for debugging!)" lst = list(range(-99, 100, 2)) odd_sum = sum([i**2 for i in lst if i%2!=0 and i > 0]) assert candidate(lst) == odd_sum , "This prints if this assert fails 7 (good for debugging!)"
double_the_difference
HumanEval/137
def compare_one(a, b): """ Create a function that takes integers, floats, or strings representing real numbers, and returns the larger variable in its given variable type. Return None if the values are equal. Note: If a real number is represented as a string, the floating point might be . or , compare_one(1, 2.5) ➞ 2.5 compare_one(1, "2,3") ➞ "2,3" compare_one("5,1", "6") ➞ "6" compare_one("1", 1) ➞ None """
temp_a, temp_b = a, b if isinstance(temp_a, str): temp_a = temp_a.replace(',','.') if isinstance(temp_b, str): temp_b = temp_b.replace(',','.') if float(temp_a) == float(temp_b): return None return a if float(temp_a) > float(temp_b) else b
def check(candidate): # Check some simple cases assert candidate(1, 2) == 2 assert candidate(1, 2.5) == 2.5 assert candidate(2, 3) == 3 assert candidate(5, 6) == 6 assert candidate(1, "2,3") == "2,3" assert candidate("5,1", "6") == "6" assert candidate("1", "2") == "2" assert candidate("1", 1) == None # Check some edge cases that are easy to work out by hand. assert True
compare_one
HumanEval/76
def is_simple_power(x, n): """Your task is to write a function that returns true if a number x is a simple power of n and false in other cases. x is a simple power of n if n**int=x For example: is_simple_power(1, 4) => true is_simple_power(2, 2) => true is_simple_power(8, 2) => true is_simple_power(3, 2) => false is_simple_power(3, 1) => false is_simple_power(5, 3) => false """
if (n == 1): return (x == 1) power = 1 while (power < x): power = power * n return (power == x)
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!)"
is_simple_power
HumanEval/124
def valid_date(date): """You have to write a function which validates a given date string and returns True if the date is valid otherwise False. The date is valid if all of the following rules are satisfied: 1. The date string is not empty. 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2. 3. The months should not be less than 1 or higher than 12. 4. The date should be in the format: mm-dd-yyyy for example: valid_date('03-11-2000') => True valid_date('15-01-2012') => False valid_date('04-0-2040') => False valid_date('06-04-2020') => True valid_date('06/04/2020') => False """
try: date = date.strip() month, day, year = date.split('-') month, day, year = int(month), int(day), int(year) if month < 1 or month > 12: return False if month in [1,3,5,7,8,10,12] and day < 1 or day > 31: return False if month in [4,6,9,11] and day < 1 or day > 30: return False if month == 2 and day < 1 or day > 29: return False except: return False return True
def check(candidate): # Check some simple cases assert candidate('03-11-2000') == True assert candidate('15-01-2012') == False assert candidate('04-0-2040') == False assert candidate('06-04-2020') == True assert candidate('01-01-2007') == True assert candidate('03-32-2011') == False assert candidate('') == False assert candidate('04-31-3000') == False assert candidate('06-06-2005') == True assert candidate('21-31-2000') == False assert candidate('04-12-2003') == True assert candidate('04122003') == False assert candidate('20030412') == False assert candidate('2003-04') == False assert candidate('2003-04-12') == False assert candidate('04-2003') == False
valid_date
HumanEval/72
def will_it_fly(q,w): ''' Write a function that returns True if the object q will fly, and False otherwise. The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w. Example: will_it_fly([1, 2], 5) ➞ False # 1+2 is less than the maximum possible weight, but it's unbalanced. will_it_fly([3, 2, 3], 1) ➞ False # it's balanced, but 3+2+3 is more than the maximum possible weight. will_it_fly([3, 2, 3], 9) ➞ True # 3+2+3 is less than the maximum possible weight, and it's balanced. will_it_fly([3], 5) ➞ True # 3 is less than the maximum possible weight, and it's balanced. '''
if sum(q) > w: return False i, j = 0, len(q)-1 while i<j: if q[i] != q[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
will_it_fly
HumanEval/6
from typing import List def parse_nested_parens(paren_string: 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. >>> parse_nested_parens('(()()) ((())) () ((())()())') [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 paren_string.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]
parse_nested_parens
HumanEval/110
def exchange(lst1, lst2): """In this problem, you will implement a function that takes two lists of numbers, and determines whether it is possible to perform an exchange of elements between them to make lst1 a list of only even numbers. There is no limit on the number of exchanged elements between lst1 and lst2. If it is possible to exchange elements between the lst1 and lst2 to make all the elements of lst1 to be even, return "YES". Otherwise, return "NO". For example: exchange([1, 2, 3, 4], [1, 2, 3, 4]) => "YES" exchange([1, 2, 3, 4], [1, 5, 3, 4]) => "NO" It is assumed that the input lists will be non-empty. """
odd = 0 even = 0 for i in lst1: if i%2 == 1: odd += 1 for i in lst2: if i%2 == 0: even += 1 if even >= odd: return "YES" return "NO"
def check(candidate): # Check some simple cases assert candidate([1, 2, 3, 4], [1, 2, 3, 4]) == "YES" assert candidate([1, 2, 3, 4], [1, 5, 3, 4]) == "NO" assert candidate([1, 2, 3, 4], [2, 1, 4, 3]) == "YES" assert candidate([5, 7, 3], [2, 6, 4]) == "YES" assert candidate([5, 7, 3], [2, 6, 3]) == "NO" assert candidate([3, 2, 6, 1, 8, 9], [3, 5, 5, 1, 1, 1]) == "NO" # Check some edge cases that are easy to work out by hand. assert candidate([100, 200], [200, 200]) == "YES"
exchange
HumanEval/24
def largest_divisor(n: int) -> int: """ For a given number n, find the largest number that divides n evenly, smaller than n >>> largest_divisor(15) 5 """
for i in reversed(range(n)): if n % i == 0: return i
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
largest_divisor
HumanEval/141
def file_name_check(file_name): """Create a function which takes a string representing a file's name, and returns 'Yes' if the the file's name is valid, and returns 'No' otherwise. A file's name is considered to be valid if and only if all the following conditions are met: - There should not be more than three digits ('0'-'9') in the file's name. - The file's name contains exactly one dot '.' - The substring before the dot should not be empty, and it starts with a letter from the latin alphapet ('a'-'z' and 'A'-'Z'). - The substring after the dot should be one of these: ['txt', 'exe', 'dll'] Examples: file_name_check("example.txt") # => 'Yes' file_name_check("1example.dll") # => 'No' (the name should start with a latin alphapet letter) """
suf = ['txt', 'exe', 'dll'] lst = file_name.split(sep='.') if len(lst) != 2: return 'No' if not lst[1] in suf: return 'No' if len(lst[0]) == 0: return 'No' if not lst[0][0].isalpha(): return 'No' t = len([x for x in lst[0] if x.isdigit()]) if t > 3: return 'No' return 'Yes'
def check(candidate): # Check some simple cases assert candidate("example.txt") == 'Yes' assert candidate("1example.dll") == 'No' assert candidate('s1sdf3.asd') == 'No' assert candidate('K.dll') == 'Yes' assert candidate('MY16FILE3.exe') == 'Yes' assert candidate('His12FILE94.exe') == 'No' assert candidate('_Y.txt') == 'No' assert candidate('?aREYA.exe') == 'No' assert candidate('/this_is_valid.dll') == 'No' assert candidate('this_is_valid.wow') == 'No' assert candidate('this_is_valid.txt') == 'Yes' assert candidate('this_is_valid.txtexe') == 'No' assert candidate('#this2_i4s_5valid.ten') == 'No' assert candidate('@this1_is6_valid.exe') == 'No' assert candidate('this_is_12valid.6exe4.txt') == 'No' assert candidate('all.exe.txt') == 'No' assert candidate('I563_No.exe') == 'Yes' assert candidate('Is3youfault.txt') == 'Yes' assert candidate('no_one#knows.dll') == 'Yes' assert candidate('1I563_Yes3.exe') == 'No' assert candidate('I563_Yes3.txtt') == 'No' assert candidate('final..txt') == 'No' assert candidate('final132') == 'No' assert candidate('_f4indsartal132.') == 'No' # Check some edge cases that are easy to work out by hand. assert candidate('.txt') == 'No' assert candidate('s.') == 'No'
file_name_check
HumanEval/130
def tri(n): """Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in the last couple centuries. However, what people don't know is Tribonacci sequence. Tribonacci sequence is defined by the recurrence: tri(1) = 3 tri(n) = 1 + n / 2, if n is even. tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd. For example: tri(2) = 1 + (2 / 2) = 2 tri(4) = 3 tri(3) = tri(2) + tri(1) + tri(4) = 2 + 3 + 3 = 8 You are given a non-negative integer number n, you have to a return a list of the first n + 1 numbers of the Tribonacci sequence. Examples: tri(3) = [1, 3, 2, 8] """
if n == 0: return [1] my_tri = [1, 3] for i in range(2, n + 1): if i % 2 == 0: my_tri.append(i / 2 + 1) else: my_tri.append(my_tri[i - 1] + my_tri[i - 2] + (i + 3) / 2) return my_tri
def check(candidate): # Check some simple cases assert candidate(3) == [1, 3, 2.0, 8.0] assert candidate(4) == [1, 3, 2.0, 8.0, 3.0] assert candidate(5) == [1, 3, 2.0, 8.0, 3.0, 15.0] assert candidate(6) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0] assert candidate(7) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0] assert candidate(8) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0] assert candidate(9) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0] assert candidate(20) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0, 6.0, 48.0, 7.0, 63.0, 8.0, 80.0, 9.0, 99.0, 10.0, 120.0, 11.0] # Check some edge cases that are easy to work out by hand. assert candidate(0) == [1] assert candidate(1) == [1, 3]
tri

Dataset Card for HumanEval with Splits

Dataset Summary

The HumanEval dataset released by OpenAI includes 164 programming problems with a function sig- nature, docstring, body, and several unit tests. They were handwritten to ensure not to be included in the training set of code generation models.

Supported Tasks and Leaderboards

Languages

The programming problems are written in Python and contain English natural text in comments and docstrings.

Dataset Structure

from datasets import load_dataset
load_dataset("openai_humaneval")

DatasetDict({
    train: Dataset({
        features: ['task_id', 'prompt', 'canonical_solution', 'test', 'entry_point'],
        num_rows: 32
    })
    test: Dataset({
        features: ['task_id', 'prompt', 'canonical_solution', 'test', 'entry_point'],
        num_rows: 132
    })
})

Data Instances

An example of a dataset instance:

{
    "task_id": "test/0",
    "prompt": "def return1():\n",
    "canonical_solution": "    return 1",
    "test": "def check(candidate):\n    assert candidate() == 1",
    "entry_point": "return1"
}

Data Fields

  • task_id: identifier for the data sample
  • prompt: input for the model containing function header and docstrings
  • canonical_solution: solution for the problem in the prompt
  • test: contains function to test generated code for correctness
  • entry_point: entry point for test

Data Splits

The dataset consists of a train split with 32 samples and a test split with 132 samples.

Dataset Creation

Curation Rationale

Since code generation models are often trained on dumps of GitHub a dataset not included in the dump was necessary to properly evaluate the model. However, since this dataset was published on GitHub it is likely to be included in future dumps.

Source Data

The dataset was handcrafted by engineers and researchers at OpenAI.

Initial Data Collection and Normalization

[More Information Needed]

Who are the source language producers?

[More Information Needed]

Annotations

[More Information Needed]

Annotation process

[More Information Needed]

Who are the annotators?

[More Information Needed]

Personal and Sensitive Information

None.

Considerations for Using the Data

Make sure you execute generated Python code in a safe environment when evauating against this dataset as generated code could be harmful.

Social Impact of Dataset

With this dataset code generating models can be better evaluated which leads to fewer issues introduced when using such models.

Discussion of Biases

[More Information Needed]

Other Known Limitations

[More Information Needed]

Additional Information

Dataset Curators

Ishan Khare

Licensing Information

MIT License

Citation Information

@misc{chen2021evaluating,
      title={Evaluating Large Language Models Trained on Code},
      author={Mark Chen and Jerry Tworek and Heewoo Jun and Qiming Yuan and Henrique Ponde de Oliveira Pinto and Jared Kaplan and Harri Edwards and Yuri Burda and Nicholas Joseph and Greg Brockman and Alex Ray and Raul Puri and Gretchen Krueger and Michael Petrov and Heidy Khlaaf and Girish Sastry and Pamela Mishkin and Brooke Chan and Scott Gray and Nick Ryder and Mikhail Pavlov and Alethea Power and Lukasz Kaiser and Mohammad Bavarian and Clemens Winter and Philippe Tillet and Felipe Petroski Such and Dave Cummings and Matthias Plappert and Fotios Chantzis and Elizabeth Barnes and Ariel Herbert-Voss and William Hebgen Guss and Alex Nichol and Alex Paino and Nikolas Tezak and Jie Tang and Igor Babuschkin and Suchir Balaji and Shantanu Jain and William Saunders and Christopher Hesse and Andrew N. Carr and Jan Leike and Josh Achiam and Vedant Misra and Evan Morikawa and Alec Radford and Matthew Knight and Miles Brundage and Mira Murati and Katie Mayer and Peter Welinder and Bob McGrew and Dario Amodei and Sam McCandlish and Ilya Sutskever and Wojciech Zaremba},
      year={2021},
      eprint={2107.03374},
      archivePrefix={arXiv},
      primaryClass={cs.LG}
}
Downloads last month
42