task_id
stringlengths 3
14
| prompt
stringlengths 164
742
| canonical_solution
stringlengths 14
760
| test
stringlengths 170
703
| entry_point
stringlengths 3
31
|
---|---|---|---|---|
HumanEval\/801 | def test_three_equal(x: int, y: int, z: int) -> int:
""" Count the number of equal numbers from three given integers.
>>> test_three_equal(1, 1, 1)
3
>>> test_three_equal(-1, -2, -3)
0
>>> test_three_equal(1, 2, 2)
2
"""
| result = set([x, y, z])
if len(result) == 3:
return 0
else:
return (4 - len(result))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(1, 1, 1) == 3
assert candidate(-1, -2, -3) == 0
assert candidate(1, 2, 2) == 2
| test_three_equal |
HumanEval\/802 | def count_Rotation(arr: list, n: int) -> int:
""" Count the number of rotations required to generate a sorted array
>>> count_Rotation([3,2,1], 3)
1
>>> count_Rotation([4,5,1,2,3], 5)
2
>>> count_Rotation([7,8,9,1,2,3], 6)
3
"""
| for i in range(1, n):
if arr[i] < arr[i - 1]:
return i
return 0
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([3,2,1], 3) == 1
assert candidate([4,5,1,2,3], 5) == 2
assert candidate([7,8,9,1,2,3], 6) == 3
| count_Rotation |
HumanEval\/803 | def is_Perfect_Square(n: int) -> bool:
""" Check whether the given number is a perfect square or not.
>>> is_Perfect_Square(10)
False
>>> is_Perfect_Square(36)
True
>>> is_Perfect_Square(14)
False
"""
| i = 1
while (i * i <= n):
if ((n % i == 0) and (n / i == i)):
return True
i = i + 1
return False
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(10) == False
assert candidate(36) == True
assert candidate(14) == False
| is_Perfect_Square |
HumanEval\/804 | from typing import List
def is_Product_Even(arr: List[int], n: int) -> bool:
""" Check whether the product of numbers is even or not
>>> is_Product_Even([1, 2, 3], 3)
True
>>> is_Product_Even([1, 2, 1, 4], 4)
True
>>> is_Product_Even([1, 1], 2)
False
"""
| for i in range(0, n):
if ((arr[i] & 1) == 0):
return True
return False
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 2, 3], 3) == True
assert candidate([1, 2, 1, 4], 4) == True
assert candidate([1, 1], 2) == False
| is_Product_Even |
HumanEval\/805 | from typing import List
def max_sum_list(lists: List[List[int]]) -> List[int]:
""" Write a function to find the list in a list of lists whose sum of elements is the highest.
>>> max_sum_list([[1,2,3], [4,5,6], [10,11,12], [7,8,9]])
[10, 11, 12]
>>> max_sum_list([[3,2,1], [6,5,4], [12,11,10]])
[12,11,10]
>>> max_sum_list([[2,3,1]])
[2,3,1]
"""
| return max(lists, key=sum)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([[1,2,3], [4,5,6], [10,11,12], [7,8,9]]) == [10, 11, 12]
assert candidate([[3,2,1], [6,5,4], [12,11,10]]) == [12,11,10]
assert candidate([[2,3,1]]) == [2,3,1]
| max_sum_list |
HumanEval\/806 | def max_run_uppercase(test_str: str) -> int:
"""Write a function to find maximum run of uppercase characters in the given string.
>>> max_run_uppercase('GeMKSForGERksISBESt')
5
>>> max_run_uppercase('PrECIOusMOVemENTSYT')
6
>>> max_run_uppercase('GooGLEFluTTER')
4
"""
| cnt = 0
res = 0
for idx in range(0, len(test_str)):
if test_str[idx].isupper():
cnt += 1
else:
res = max(res, cnt)
cnt = 0
res = max(res, cnt)
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('GeMKSForGERksISBESt') == 5
assert candidate('PrECIOusMOVemENTSYT') == 6
assert candidate('GooGLEFluTTER') == 4
| max_run_uppercase |
HumanEval\/807 | from typing import List
def first_odd(nums: List[int]) -> int:
""" Find the first odd number in a given list of numbers.
>>> first_odd([1, 3, 5])
1
>>> first_odd([2, 4, 1, 3])
1
>>> first_odd([8, 9, 1])
9
"""
| first_odd = next((el for el in nums if el%2!=0),-1)
return first_odd
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 3, 5]) == 1
assert candidate([2, 4, 1, 3]) == 1
assert candidate([8, 9, 1]) == 9
| first_odd |
HumanEval\/808 | def check_K(test_tup: tuple, K: int) -> bool:
""" Check if the given tuple contains the element K
>>> check_K((10, 4, 5, 6, 8), 6)
True
>>> check_K((1, 2, 3, 4, 5, 6), 7)
False
>>> check_K((7, 8, 9, 44, 11, 12), 11)
True
"""
| res = False
for ele in test_tup:
if ele == K:
res = True
break
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate((10, 4, 5, 6, 8), 6) == True
assert candidate((1, 2, 3, 4, 5, 6), 7) == False
assert candidate((7, 8, 9, 44, 11, 12), 11) == True
| check_K |
HumanEval\/809 | def check_smaller(test_tup1: tuple, test_tup2: tuple) -> bool:
""" Check if each element of second tuple is smaller than its corresponding index in first tuple.
>>> check_smaller((1, 2, 3), (2, 3, 4))
False
>>> check_smaller((4, 5, 6), (3, 4, 5))
True
>>> check_smaller((11, 12, 13), (10, 11, 12))
True
"""
| return all(x > y for x, y in zip(test_tup1, test_tup2))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate((1, 2, 3), (2, 3, 4)) == False
assert candidate((4, 5, 6), (3, 4, 5)) == True
assert candidate((11, 12, 13), (10, 11, 12)) == True
| check_smaller |
HumanEval\/810 | from collections import Counter
def count_variable(a: int, b: int, c: int, d: int) -> list:
""" Write a function to iterate over elements repeating each as many times as its count.
>>> count_variable(4, 2, 0, -2)
['p', 'p', 'p', 'p', 'q', 'q']
>>> count_variable(0, 1, 2, 3)
['q', 'r', 'r', 's', 's', 's']
"""
| c = Counter(p=a, q=b, r=c, s=d)
return list(c.elements())
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(4, 2, 0, -2) == ['p', 'p', 'p', 'p', 'q', 'q']
assert candidate(0, 1, 2, 3) == ['q', 'r', 'r', 's', 's', 's']
assert candidate(11, 15, 12, 23) == ['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's']
| count_variable |
HumanEval\/811 | from typing import List, Tuple
def check_identical(test_list1: List[Tuple[int, int]], test_list2: List[Tuple[int, int]]) -> bool:
""" Check if two lists of tuples are identical or not.
>>> check_identical([(10, 4), (2, 5)], [(10, 4), (2, 5)])
True
>>> check_identical([(1, 2), (3, 7)], [(12, 14), (12, 45)])
False
>>> check_identical([(2, 14), (12, 25)], [(2, 14), (12, 25)])
True
"""
| return test_list1 == test_list2
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([(10, 4), (2, 5)], [(10, 4), (2, 5)]) == True
assert candidate([(1, 2), (3, 7)], [(12, 14), (12, 45)]) == False
assert candidate([(2, 14), (12, 25)], [(2, 14), (12, 25)]) == True
| check_identical |
HumanEval\/812 | import re
def road_rd(street: str) -> str:
""" Abbreviate 'road' as 'rd.' in a given string
>>> road_rd('ravipadu Road')
'ravipadu Rd.'
>>> road_rd('palnadu Road')
'palnadu Rd.'
>>> road_rd('eshwar enclave Road')
'eshwar enclave Rd.'
"""
| return re.sub('Road$', 'Rd.', street)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('ravipadu Road') == 'ravipadu Rd.'
assert candidate('palnadu Road') == 'palnadu Rd.'
assert candidate('eshwar enclave Road') == 'eshwar enclave Rd.'
| road_rd |
HumanEval\/813 | def string_length(str1: str) -> int:
""" Calculate the length of the string
>>> string_length('python')
6
>>> string_length('program')
7
>>> string_length('language')
8
"""
| count = 0
for char in str1:
count += 1
return count
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('python') == 6
assert candidate('program') == 7
assert candidate('language') == 8
| string_length |
HumanEval\/814 | def rombus_area(p: float, q: float) -> float:
""" Calculate the area of a rhombus given the lengths of its diagonals p and q.
>>> rombus_area(10, 20)
100.0
>>> rombus_area(10, 5)
25.0
>>> rombus_area(4, 2)
4.0
"""
| return (p * q) / 2
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(10, 20) == 100.0
assert candidate(10, 5) == 25.0
assert candidate(4, 2) == 4.0
| rombus_area |
HumanEval\/815 | from typing import List
def sort_by_dnf(arr: List[int], n: int) -> List[int]:
""" Sort the given array consisting of only 0, 1, and 2 without using any sorting algorithm.
>>> sort_by_dnf([1,2,0,1,0,1,2,1,1], 9)
[0, 0, 1, 1, 1, 1, 1, 2, 2]
>>> sort_by_dnf([1,0,0,1,2,1,2,2,1,0], 10)
[0, 0, 0, 1, 1, 1, 1, 2, 2, 2]
>>> sort_by_dnf([2,2,1,0,0,0,1,1,2,1], 10)
[0, 0, 0, 1, 1, 1, 1, 2, 2, 2]
"""
| low=0
mid=0
high=n-1
while mid <= high:
if arr[mid] == 0:
arr[low], arr[mid] = arr[mid], arr[low]
low = low + 1
mid = mid + 1
elif arr[mid] == 1:
mid = mid + 1
else:
arr[mid], arr[high] = arr[high], arr[mid]
high = high - 1
return arr
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,2,0,1,0,1,2,1,1], 9) == [0, 0, 1, 1, 1, 1, 1, 2, 2]
assert candidate([1,0,0,1,2,1,2,2,1,0], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]
assert candidate([2,2,1,0,0,0,1,1,2,1], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]
| sort_by_dnf |
HumanEval\/816 |
def clear_tuple(test_tup: tuple) -> tuple:
""" Clear the values of the given tuple
>>> clear_tuple((1, 5, 3, 6, 8))
()
>>> clear_tuple((2, 1, 4, 5, 6))
()
"""
| return ()
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate((1, 5, 3, 6, 8)) == ()
assert candidate((2, 1, 4, 5, 6)) == ()
assert candidate((3, 2, 5, 6, 8)) == ()
| clear_tuple |
HumanEval\/817 | from typing import List
def div_of_nums(nums: List[int], m: int, n: int) -> List[int]:
""" Find numbers divisible by m or n from a list of numbers using lambda function.
>>> div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190], 19, 13)
[19, 65, 57, 39, 152, 190]
>>> div_of_nums([1, 2, 3, 5, 7, 8, 10], 2, 5)
[2, 5, 8, 10]
>>> div_of_nums([10, 15, 14, 13, 18, 12, 20], 10, 5)
[10, 15, 20]
"""
| result = list(filter(lambda x: (x % m == 0 or x % n == 0), nums))
return result
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([19, 65, 57, 39, 152, 639, 121, 44, 90, 190], 19, 13) == [19, 65, 57, 39, 152, 190]
assert candidate([1, 2, 3, 5, 7, 8, 10], 2, 5) == [2, 5, 8, 10]
assert candidate([10, 15, 14, 13, 18, 12, 20], 10, 5) == [10, 15, 20]
| div_of_nums |
HumanEval\/818 | def lower_ctr(str: str) -> int:
""" Count lower case letters in a given string
>>> lower_ctr('abc')
3
>>> lower_ctr('string')
6
>>> lower_ctr('Python')
5
"""
| lower_ctr = 0
for i in range(len(str)):
if str[i] >= 'a' and str[i] <= 'z': lower_ctr += 1
return lower_ctr
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('abc') == 3
assert candidate('string') == 6
assert candidate('Python') == 5
| lower_ctr |
HumanEval\/819 | from typing import List, Tuple
def count_duplic(lists: List[int]) -> Tuple[List[int], List[int]]:
""" Count the frequency of consecutive duplicate elements in a given list of numbers.
>>> count_duplic([1,2,2,2,4,4,4,5,5,5,5])
([1, 2, 4, 5], [1, 3, 3, 4])
>>> count_duplic([2,2,3,1,2,6,7,9])
([2, 3, 1, 2, 6, 7, 9], [2, 1, 1, 1, 1, 1, 1])
>>> count_duplic([2,1,5,6,8,3,4,9,10,11,8,12])
([2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
"""
| element = []
frequency = []
if not lists:
return element, frequency
running_count = 1
for i in range(len(lists)-1):
if lists[i] == lists[i+1]:
running_count += 1
else:
frequency.append(running_count)
element.append(lists[i])
running_count = 1
frequency.append(running_count)
element.append(lists[i+1])
return element, frequency
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,2,2,2,4,4,4,5,5,5,5]) == ([1, 2, 4, 5], [1, 3, 3, 4])
assert candidate([2,2,3,1,2,6,7,9]) == ([2, 3, 1, 2, 6, 7, 9], [2, 1, 1, 1, 1, 1, 1])
assert candidate([2,1,5,6,8,3,4,9,10,11,8,12]) == ([2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
| count_duplic |
HumanEval\/820 | def check_monthnum_number(monthnum1: int) -> bool:
""" Check whether the given month number contains 28 days or not.
>>> check_monthnum_number(2)
True
>>> check_monthnum_number(1)
False
>>> check_monthnum_number(3)
False
"""
| if monthnum1 == 2:
return True
else:
return False
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(2) == True
assert candidate(1) == False
assert candidate(3) == False
| check_monthnum_number |
HumanEval\/821 | import collections as ct
def merge_dictionaries(dict1, dict2):
""" Merge two dictionaries into a single expression
>>> merge_dictionaries({ "R": "Red", "B": "Black", "P": "Pink" }, { "G": "Green", "W": "White" })
{'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White'}
>>> merge_dictionaries({ "R": "Red", "B": "Black", "P": "Pink" },{ "O": "Orange", "W": "White", "B": "Black" })
{'O': 'Orange', 'P': 'Pink', 'B': 'Black', 'W': 'White', 'R': 'Red'}
>>> merge_dictionaries({ "G": "Green", "W": "White" },{ "O": "Orange", "W": "White", "B": "Black" })
{'W': 'White', 'O': 'Orange', 'G': 'Green', 'B': 'Black'}
"""
| merged_dict = dict(ct.ChainMap({}, dict1, dict2))
return merged_dict
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate({ "R": "Red", "B": "Black", "P": "Pink" }, { "G": "Green", "W": "White" }) == {'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White'}
assert candidate({ "R": "Red", "B": "Black", "P": "Pink" },{ "O": "Orange", "W": "White", "B": "Black" }) == {'O': 'Orange', 'P': 'Pink', 'B': 'Black', 'W': 'White', 'R': 'Red'}
assert candidate({ "G": "Green", "W": "White" },{ "O": "Orange", "W": "White", "B": "Black" }) == {'W': 'White', 'O': 'Orange', 'G': 'Green', 'B': 'Black'}
| merge_dictionaries |
HumanEval\/822 | import re
def pass_validity(p: str) -> bool:
""" Return true if the password is valid.
>>> pass_validity("password")
False
>>> pass_validity("Password@10")
True
>>> pass_validity("password@10")
False
"""
| x = True
while x:
if (len(p)<6 or len(p)>12):
break
elif not re.search("[a-z]",p):
break
elif not re.search("[0-9]",p):
break
elif not re.search("[A-Z]",p):
break
elif not re.search("[$#@]",p):
break
elif re.search("\s",p):
break
else:
return True
x=False
break
if x:
return False
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("password") == False
assert candidate("Password@10") == True
assert candidate("password@10") == False
| pass_validity |
HumanEval\/823 | import re
def check_substring(string: str, sample: str) -> str:
""" Check if the given string starts with a substring using regex.
>>> check_substring("dreams for dreams makes life fun", "makes")
'string doesnt start with the given substring'
>>> check_substring("Hi there how are you Hi alex", "Hi")
'string starts with the given substring'
>>> check_substring("Its been a long day", "been")
'string doesnt start with the given substring'
"""
| if sample in string:
y = "\A" + sample
x = re.search(y, string)
if x:
return "string starts with the given substring"
else:
return "string doesnt start with the given substring"
else:
return "entered string isnt a substring"
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("dreams for dreams makes life fun", "makes") == 'string doesnt start with the given substring'
assert candidate("Hi there how are you Hi alex", "Hi") == 'string starts with the given substring'
assert candidate("Its been a long day", "been") == 'string doesnt start with the given substring'
| check_substring |
HumanEval\/824 | from typing import List
def remove_even(l: List[int]) -> List[int]:
""" Remove even numbers from a given list
>>> remove_even([1,3,5,2])
[1,3,5]
>>> remove_even([5,6,7])
[5,7]
>>> remove_even([1,2,3,4])
[1,3]
"""
| return [x for x in l if x % 2 != 0]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,3,5,2]) == [1,3,5]
assert candidate([5,6,7]) == [5,7]
assert candidate([1,2,3,4]) == [1,3]
| remove_even |
HumanEval\/825 | from typing import List
def access_elements(nums: List[int], list_index: List[int]) -> List[int]:
""" Access multiple elements of specified index from a given list
>>> access_elements([2,3,8,4,7,9],[0,3,5])
[2, 4, 9]
>>> access_elements([1, 2, 3, 4, 5],[1,2])
[2, 3]
>>> access_elements([1,0,2,3],[0,1])
[1, 0]
"""
| return [nums[i] for i in list_index]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([2,3,8,4,7,9],[0,3,5]) == [2, 4, 9]
assert candidate([1, 2, 3, 4, 5],[1,2]) == [2, 3]
assert candidate([1,0,2,3],[0,1]) == [1, 0]
| access_elements |
HumanEval\/826 | def check_Type_Of_Triangle(a: int, b: int, c: int) -> str:
""" Determine the type of triangle given its sides.
>>> check_Type_Of_Triangle(1, 2, 3)
'Obtuse-angled Triangle'
>>> check_Type_Of_Triangle(2, 2, 2)
'Acute-angled Triangle'
>>> check_Type_Of_Triangle(1, 0, 1)
'Right-angled Triangle'
"""
| sqa = pow(a, 2)
sqb = pow(b, 2)
sqc = pow(c, 2)
if (sqa == sqa + sqb or sqb == sqa + sqc or sqc == sqa + sqb):
return "Right-angled Triangle"
elif (sqa > sqc + sqb or sqb > sqa + sqc or sqc > sqa + sqb):
return "Obtuse-angled Triangle"
else:
return "Acute-angled Triangle"
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(1, 2, 3) == 'Obtuse-angled Triangle'
assert candidate(2, 2, 2) == 'Acute-angled Triangle'
assert candidate(1, 0, 1) == 'Right-angled Triangle'
| check_Type_Of_Triangle |
HumanEval\/827 | from typing import List
def sum_column(list1: List[List[int]], C: int) -> int:
""" Write a function to sum a specific column of a list in a given list of lists.
>>> sum_column([[1,2,3,2],[4,5,6,2],[7,8,9,5]], 0)
12
>>> sum_column([[1,2,3,2],[4,5,6,2],[7,8,9,5]], 1)
15
>>> sum_column([[1,2,3,2],[4,5,6,2],[7,8,9,5]], 3)
9
"""
| result = sum(row[C] for row in list1)
return result
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([[1,2,3,2],[4,5,6,2],[7,8,9,5]], 0) == 12
assert candidate([[1,2,3,2],[4,5,6,2],[7,8,9,5]], 1) == 15
assert candidate([[1,2,3,2],[4,5,6,2],[7,8,9,5]], 3) == 9
| sum_column |
HumanEval\/828 | def count_alpha_dig_spl(string: str) -> tuple:
""" Count alphabets, digits, and special characters in a given string.
>>> count_alpha_dig_spl("abc!@#123")
(3, 3, 3)
>>> count_alpha_dig_spl("dgsuy@#$%&1255")
(5, 4, 5)
"""
| alphabets = digits = special = 0
for i in range(len(string)):
if string[i].isalpha():
alphabets += 1
elif string[i].isdigit():
digits += 1
else:
special += 1
return (alphabets, digits, special)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("abc!@#123") == (3, 3, 3)
assert candidate("dgsuy@#$%&1255") == (5, 4, 5)
assert candidate("fjdsif627348#%$^&") == (6, 6, 5)
| count_alpha_dig_spl |
HumanEval\/829 | from collections import Counter
from typing import List
def second_frequent(input: List[str]) -> str:
"""Find the second most repeated (or frequent) string in the given sequence.
>>> second_frequent(['aaa','bbb','ccc','bbb','aaa','aaa'])
'bbb'
>>> second_frequent(['abc','bcd','abc','bcd','bcd','bcd'])
'abc'
>>> second_frequent(['cdma','gsm','hspa','gsm','cdma','cdma'])
'gsm'
"""
| dict = Counter(input)
value = sorted(dict.values(), reverse=True)
second_large = value[1]
for (key, val) in dict.items():
if val == second_large:
return (key)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(['aaa','bbb','ccc','bbb','aaa','aaa']) == 'bbb'
assert candidate(['abc','bcd','abc','bcd','bcd','bcd']) == 'abc'
assert candidate(['cdma','gsm','hspa','gsm','cdma','cdma']) == 'gsm'
| second_frequent |
HumanEval\/830 | import math
def round_up(a: float, digits: int) -> float:
""" Round up a number to specific digits
>>> round_up(123.01247, 0)
124.0
>>> round_up(123.01247, 1)
123.1
>>> round_up(123.01247, 2)
123.02
"""
| n = 10**-digits
return round(math.ceil(a / n) * n, digits)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(123.01247, 0) == 124.0
assert candidate(123.01247, 1) == 123.1
assert candidate(123.01247, 2) == 123.02
| round_up |
HumanEval\/831 | from typing import List
def count_Pairs(arr: List[int], n: int) -> int:
""" Count equal element pairs from the given array
>>> count_Pairs([1, 1, 1, 1], 4)
6
>>> count_Pairs([1, 5, 1], 3)
1
>>> count_Pairs([3, 2, 1, 7, 8, 9], 6)
0
"""
| cnt = 0
for i in range(n):
for j in range(i + 1, n):
if arr[i] == arr[j]:
cnt += 1
return cnt
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 1, 1, 1], 4) == 6
assert candidate([1, 5, 1], 3) == 1
assert candidate([3, 2, 1, 7, 8, 9], 6) == 0
| count_Pairs |
HumanEval\/832 | import re
def extract_max(input: str) -> int:
""" Extract the maximum numeric value from a string by using regex.
>>> extract_max('100klh564abc365bg')
564
>>> extract_max('hello300how546mer231')
546
>>> extract_max('its233beenalong343journey234')
343
"""
| numbers = re.findall('\\d+', input)
numbers = map(int, numbers)
return max(numbers)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('100klh564abc365bg') == 564
assert candidate('hello300how546mer231') == 546
assert candidate('its233beenalong343journey234') == 343
| extract_max |
HumanEval\/833 | def get_key(d: dict) -> list:
""" Return the keys of the dictionary as a list.
>>> get_key({1:'python',2:'java'})
[1, 2]
>>> get_key({10:'red',20:'blue',30:'black'})
[10, 20, 30]
>>> get_key({27:'language',39:'java',44:'little'})
[27, 39, 44]
"""
| return list(d.keys())
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate({1:'python',2:'java'}) == [1, 2]
assert candidate({10:'red',20:'blue',30:'black'}) == [10, 20, 30]
assert candidate({27:'language',39:'java',44:'little'}) == [27, 39, 44]
| get_key |
HumanEval\/834 | def generate_matrix(n: int) -> List[List[int]]:
""" Generate a square matrix filled with elements from 1 to n^2 in spiral order.
>>> generate_matrix(3)
[[1, 2, 3], [8, 9, 4], [7, 6, 5]]
>>> generate_matrix(2)
[[1, 2], [4, 3]]
"""
| if n <= 0:
return []
matrix = [row[:] for row in [[0] * n] * n]
row_st, row_ed = 0, n - 1
col_st, col_ed = 0, n - 1
current = 1
while True:
if current > n * n:
break
for c in range(col_st, col_ed + 1):
matrix[row_st][c] = current
current += 1
row_st += 1
for r in range(row_st, row_ed + 1):
matrix[r][col_ed] = current
current += 1
col_ed -= 1
for c in range(col_ed, col_st - 1, -1):
matrix[row_ed][c] = current
current += 1
row_ed -= 1
for r in range(row_ed, row_st - 1, -1):
matrix[r][col_st] = current
current += 1
col_st += 1
return matrix
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(3) == [[1, 2, 3], [8, 9, 4], [7, 6, 5]]
assert candidate(2) == [[1, 2], [4, 3]]
assert candidate(7) == [[1, 2, 3, 4, 5, 6, 7], [24, 25, 26, 27, 28, 29, 8], [23, 40, 41, 42, 43, 30, 9], [22, 39, 48, 49, 44, 31, 10], [21, 38, 47, 46, 45, 32, 11], [20, 37, 36, 35, 34, 33, 12], [19, 18, 17, 16, 15, 14, 13]]
| generate_matrix |
HumanEval\/835 | def slope(x1: float, y1: float, x2: float, y2: float) -> float:
""" Calculate the slope of a line given two points (x1, y1) and (x2, y2).
>>> slope(4, 2, 2, 5)
-1.5
>>> slope(2, 4, 4, 6)
1.0
>>> slope(1, 2, 4, 2)
0.0
"""
| return (y2 - y1) / (x2 - x1)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(4, 2, 2, 5) == -1.5
assert candidate(2, 4, 4, 6) == 1.0
assert candidate(1, 2, 4, 2) == 0.0
| slope |
HumanEval\/836 | from sys import maxsize
def max_sub_array_sum(a: list, size: int) -> int:
"""Find the length of the subarray having maximum sum.
>>> max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3], 8)
5
>>> max_sub_array_sum([1, -2, 1, 1, -2, 1], 6)
2
>>> max_sub_array_sum([-1, -2, 3, 4, 5], 5)
3
"""
| max_so_far = -maxsize - 1
max_ending_here = 0
start = 0
end = 0
s = 0
for i in range(0, size):
max_ending_here += a[i]
if max_so_far < max_ending_here:
max_so_far = max_ending_here
start = s
end = i
if max_ending_here < 0:
max_ending_here = 0
s = i + 1
return (end - start + 1)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([-2, -3, 4, -1, -2, 1, 5, -3], 8) == 5
assert candidate([1, -2, 1, 1, -2, 1], 6) == 2
assert candidate([-1, -2, 3, 4, 5], 5) == 3
| max_sub_array_sum |
HumanEval\/837 | def cube_Sum(n: int) -> int:
""" Calculate the cube sum of the first n odd natural numbers.
>>> cube_Sum(2)
28
>>> cube_Sum(3)
153
>>> cube_Sum(4)
496
"""
| sum = 0
for i in range(n):
sum += (2*i+1)**3
return sum
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(2) == 28
assert candidate(3) == 153
assert candidate(4) == 496
| cube_Sum |
HumanEval\/838 | def min_Swaps(s1: str, s2: str) -> int:
""" Write a python function to find minimum number swaps required to make two binary strings equal.
>>> min_Swaps("0011","1111")
1
>>> min_Swaps("00011","01001")
2
>>> min_Swaps("111","111")
0
"""
| c0 = 0; c1 = 0;
for i in range(len(s1)) :
if (s1[i] == '0' and s2[i] == '1') :
c0 += 1;
elif (s1[i] == '1' and s2[i] == '0') :
c1 += 1;
result = c0 // 2 + c1 // 2;
if (c0 % 2 == 0 and c1 % 2 == 0) :
return result;
elif ((c0 + c1) % 2 == 0) :
return result + 2;
else :
return -1;
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("0011","1111") == 1
assert candidate("00011","01001") == 2
assert candidate("111","111") == 0
| min_Swaps |
HumanEval\/839 | from typing import List, Tuple
def sort_tuple(tup: List[Tuple[str, int]]) -> List[Tuple[str, int]]:
""" Sort the tuples alphabetically by the first item of each tuple.
>>> sort_tuple([("Amana", 28), ("Zenat", 30), ("Abhishek", 29),("Nikhil", 21), ("B", "C")])
[('Abhishek', 29), ('Amana', 28), ('B', 'C'), ('Nikhil', 21), ('Zenat', 30)]
"""
| return sorted(tup, key=lambda x: x[0])
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([("Amana", 28), ("Zenat", 30), ("Abhishek", 29),("Nikhil", 21), ("B", "C")]) == [('Abhishek', 29), ('Amana', 28), ('B', 'C'), ('Nikhil', 21), ('Zenat', 30)]
assert candidate([("aaaa", 28), ("aa", 30), ("bab", 29), ("bb", 21), ("csa", "C")]) == [('aa', 30), ('aaaa', 28), ('bab', 29), ('bb', 21), ('csa', 'C')]
assert candidate([("Sarala", 28), ("Ayesha", 30), ("Suman", 29),("Sai", 21), ("G", "H")]) == [('Ayesha', 30), ('G', 'H'), ('Sai', 21), ('Sarala', 28), ('Suman', 29)]
| sort_tuple |
HumanEval\/840 | def Check_Solution(a: int, b: int, c: int) -> str:
""" Check whether the roots of a quadratic equation are numerically equal but opposite in sign or not.
>>> Check_Solution(2, 0, -1)
'Yes'
>>> Check_Solution(1, -5, 6)
'No'
>>> Check_Solution(2, 0, 2)
'Yes'
"""
| if b == 0:
return "Yes"
else:
return "No"
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(2, 0, -1) == 'Yes'
assert candidate(1, -5, 6) == 'No'
assert candidate(2, 0, 2) == 'Yes'
| Check_Solution |
HumanEval\/841 | def get_inv_count(arr, n):
""" Count the number of inversions in the given array
>>> get_inv_count([1, 20, 6, 4, 5], 5)
5
>>> get_inv_count([8, 4, 2, 1], 4)
6
>>> get_inv_count([3, 1, 2], 3)
2
"""
| inv_count = 0
for i in range(n):
for j in range(i + 1, n):
if (arr[i] > arr[j]):
inv_count += 1
return inv_count
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 20, 6, 4, 5], 5) == 5
assert candidate([8, 4, 2, 1], 4) == 6
assert candidate([3, 1, 2], 3) == 2
| get_inv_count |
842 | def get_odd_occurence(arr, arr_size):
"""Find the number which occurs for odd number of times in the given array.
>>> get_odd_occurence([2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2], 13)
5
>>> get_odd_occurence([1, 2, 3, 2, 3, 1, 3], 7)
3
>>> get_odd_occurence([5, 7, 2, 7, 5, 2, 5], 7)
5
"""
| for i in range(0, arr_size):
count = 0
for j in range(0, arr_size):
if arr[i] == arr[j]:
count += 1
if (count % 2 != 0):
return arr[i]
return -1
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2], 13) == 5
assert candidate([1, 2, 3, 2, 3, 1, 3], 7) == 3
assert candidate([5, 7, 2, 7, 5, 2, 5], 7) == 5
| get_odd_occurence |
HumanEval\/843 | import heapq
def nth_super_ugly_number(n: int, primes: List[int]) -> int:
""" Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm.
>>> nth_super_ugly_number(12, [2, 7, 13, 19])
32
>>> nth_super_ugly_number(10, [2, 7, 13, 19])
26
>>> nth_super_ugly_number(100, [2, 7, 13, 19])
5408
"""
| uglies = [1]
def gen(prime):
for ugly in uglies:
yield ugly * prime
merged = heapq.merge(*map(gen, primes))
while len(uglies) < n:
ugly = next(merged)
if ugly != uglies[-1]:
uglies.append(ugly)
return uglies[-1]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(12, [2, 7, 13, 19]) == 32
assert candidate(10, [2, 7, 13, 19]) == 26
assert candidate(100, [2, 7, 13, 19]) == 5408
| nth_super_ugly_number |
HumanEval\/844 | def get_Number(n: int, k: int) -> int:
""" Find the k-th element in an array containing odd elements first and then even elements.
>>> get_Number(8, 5)
2
>>> get_Number(7, 2)
3
>>> get_Number(5, 2)
3
"""
| arr = [0] * n
i = 0
odd = 1
while odd <= n:
arr[i] = odd
i += 1
odd += 2
even = 2
while even <= n:
arr[i] = even
i += 1
even += 2
return arr[k - 1]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(8, 5) == 2
assert candidate(7, 2) == 3
assert candidate(5, 2) == 3
| get_Number |
HumanEval\/845 | import math
def find_Digits(n: int) -> int:
""" Calculate the number of digits in the factorial of a given number n.
>>> find_Digits(7)
4
>>> find_Digits(5)
3
>>> find_Digits(4)
2
"""
| if n < 0:
return 0
if n <= 1:
return 1
x = (n * math.log10(n / math.e) + math.log10(2 * math.pi * n) / 2.0)
return math.floor(x) + 1
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(7) == 4
assert candidate(5) == 3
assert candidate(4) == 2
| find_Digits |
HumanEval\/846 | def find_platform(arr, dep, n):
"""Find the minimum number of platforms required for a railway/bus station.
>>> find_platform([900, 940, 950, 1100, 1500, 1800], [910, 1200, 1120, 1130, 1900, 2000], 6)
3
>>> find_platform([100, 200, 300, 400], [700, 800, 900, 1000], 4)
4
>>> find_platform([5, 6, 7, 8], [4, 3, 2, 1], 4)
1
"""
| arr.sort()
dep.sort()
plat_needed = 1
result = 1
i = 1
j = 0
while (i < n and j < n):
if (arr[i] <= dep[j]):
plat_needed += 1
i += 1
elif (arr[i] > dep[j]):
plat_needed -= 1
j += 1
if (plat_needed > result):
result = plat_needed
return result
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([900, 940, 950, 1100, 1500, 1800], [910, 1200, 1120, 1130, 1900, 2000], 6) == 3
assert candidate([100, 200, 300, 400], [700, 800, 900, 1000], 4) == 4
assert candidate([5, 6, 7, 8], [4, 3, 2, 1], 4) == 1
| find_platform |
HumanEval\/847 | def lcopy(xs):
""" Copy a list from a singleton tuple
>>> lcopy([1, 2, 3])
[1, 2, 3]
>>> lcopy([4, 8, 2, 10, 15, 18])
[4, 8, 2, 10, 15, 18]
"""
| return xs[:]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 2, 3]) == [1, 2, 3]
assert candidate([4, 8, 2, 10, 15, 18]) == [4, 8, 2, 10, 15, 18]
assert candidate([4, 5, 6]) == [4, 5, 6]
| lcopy |
HumanEval\/848 | def area_trapezium(base1: float, base2: float, height: float) -> float:
""" Calculate the area of a trapezium given the lengths of the two bases and the height.
>>> area_trapezium(6, 9, 4)
30.0
>>> area_trapezium(10, 20, 30)
450.0
>>> area_trapezium(15, 25, 35)
700.0
"""
| return 0.5 * (base1 + base2) * height
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(6, 9, 4) == 30.0
assert candidate(10, 20, 30) == 450.0
assert candidate(15, 25, 35) == 700.0
| area_trapezium |
HumanEval\/849 | def Sum(N: int) -> int:
""" Find the sum of all prime divisors of a given number N.
>>> Sum(60)
10
>>> Sum(39)
16
>>> Sum(40)
7
"""
| SumOfPrimeDivisors = [0]*(N + 1)
for i in range(2, N + 1):
if SumOfPrimeDivisors[i] == 0:
for j in range(i, N + 1, i):
SumOfPrimeDivisors[j] += i
return SumOfPrimeDivisors[N]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(60) == 10
assert candidate(39) == 16
assert candidate(40) == 7
| Sum |
HumanEval\/850 | def is_triangleexists(a: int, b: int, c: int) -> bool:
""" Check if a triangle of positive area is possible with the given angles.
>>> is_triangleexists(50, 60, 70)
True
>>> is_triangleexists(90, 45, 45)
True
>>> is_triangleexists(150, 30, 70)
False
"""
| if a != 0 and b != 0 and c != 0 and (a + b + c) == 180:
if (a + b) >= c or (b + c) >= a or (a + c) >= b:
return True
else:
return False
else:
return False
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(50, 60, 70) == True
assert candidate(90, 45, 45) == True
assert candidate(150, 30, 70) == False
| is_triangleexists |
HumanEval\/851 | def Sum_of_Inverse_Divisors(N: int, Sum: float) -> float:
""" Calculate the sum of inverse of divisors.
>>> Sum_of_Inverse_Divisors(6, 12)
2.0
>>> Sum_of_Inverse_Divisors(9, 13)
1.44
>>> Sum_of_Inverse_Divisors(1, 4)
4.0
"""
| ans = float(Sum) * 1.0 / float(N)
return round(ans, 2)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(6, 12) == 2.0
assert candidate(9, 13) == 1.44
assert candidate(1, 4) == 4.0
| Sum_of_Inverse_Divisors |
HumanEval\/852 | from typing import List
def remove_negs(num_list: List[int]) -> List[int]:
""" Remove negative numbers from a list
>>> remove_negs([1,-2,3,-4])
[1, 3]
>>> remove_negs([1,2,3,-4])
[1, 2, 3]
>>> remove_negs([4,5,-6,7,-8])
[4, 5, 7]
"""
| return [item for item in num_list if item >= 0]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,-2,3,-4]) == [1, 3]
assert candidate([1,2,3,-4]) == [1, 2, 3]
assert candidate([4,5,-6,7,-8]) == [4, 5, 7]
| remove_negs |
HumanEval\/853 | import math
def sum_of_odd_Factors(n: int) -> int:
""" Write a python function to find sum of odd factors of a number.
>>> sum_of_odd_Factors(30)
24
>>> sum_of_odd_Factors(18)
13
>>> sum_of_odd_Factors(2)
1
"""
| res = 1
while n % 2 == 0:
n = n // 2
for i in range(3, int(math.sqrt(n) + 1)):
count = 0
curr_sum = 1
curr_term = 1
while n % i == 0:
count += 1
n = n // i
curr_term *= i
curr_sum += curr_term
res *= curr_sum
if n >= 2:
res *= (1 + n)
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(30) == 24
assert candidate(18) == 13
assert candidate(2) == 1
| sum_of_odd_Factors |
HumanEval\/854 | import heapq as hq
from typing import List
def raw_heap(rawheap: List[int]) -> List[int]:
""" Convert an arbitrary list into a heap using heap queue algorithm.
>>> raw_heap([25, 44, 68, 21, 39, 23, 89])
[21, 25, 23, 44, 39, 68, 89]
>>> raw_heap([25, 35, 22, 85, 14, 65, 75, 25, 58])
[14, 25, 22, 25, 35, 65, 75, 85, 58]
>>> raw_heap([4, 5, 6, 2])
[2, 4, 6, 5]
"""
| hq.heapify(rawheap)
return rawheap
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([25, 44, 68, 21, 39, 23, 89]) == [21, 25, 23, 44, 39, 68, 89]
assert candidate([25, 35, 22, 85, 14, 65, 75, 25, 58]) == [14, 25, 22, 25, 35, 65, 75, 85, 58]
assert candidate([4, 5, 6, 2]) == [2, 4, 6, 5]
| raw_heap |
HumanEval\/855 | def check_Even_Parity(x: int) -> bool:
""" Check for even parity of a given number.
>>> check_Even_Parity(10)
True
>>> check_Even_Parity(11)
False
>>> check_Even_Parity(18)
True
"""
| parity = 0
while (x != 0):
x = x & (x - 1)
parity += 1
return parity % 2 == 0
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(10) == True
assert candidate(11) == False
assert candidate(18) == True
| check_Even_Parity |
HumanEval\/856 | def find_Min_Swaps(arr: list, n: int) -> int:
""" Write a python function to find minimum adjacent swaps required to sort binary array.
>>> find_Min_Swaps([1,0,1,0], 4)
3
>>> find_Min_Swaps([0,1,0], 3)
1
>>> find_Min_Swaps([0,0,1,1,0], 5)
2
"""
| noOfZeroes = [0] * n
count = 0
noOfZeroes[n - 1] = 1 - arr[n - 1]
for i in range(n-2,-1,-1):
noOfZeroes[i] = noOfZeroes[i + 1]
if arr[i] == 0:
noOfZeroes[i] += 1
for i in range(n):
if arr[i] == 1:
count += noOfZeroes[i]
return count
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,0,1,0], 4) == 3
assert candidate([0,1,0], 3) == 1
assert candidate([0,0,1,1,0], 5) == 2
| find_Min_Swaps |
HumanEval\/857 | from typing import List
def listify_list(list1: List[str]) -> List[List[str]]:
""" List out the list of given strings individually using map function.
>>> listify_list(['Red', 'Blue', 'Black', 'White', 'Pink'])
[['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e'], ['P', 'i', 'n', 'k']]
>>> listify_list(['python'])
[['p', 'y', 't', 'h', 'o', 'n']]
"""
| return list(map(list, list1))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(['Red', 'Blue', 'Black', 'White', 'Pink']) == [['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e'], ['P', 'i', 'n', 'k']]
assert candidate(['python']) == [['p', 'y', 't', 'h', 'o', 'n']]
assert candidate([' red ', 'green',' black', 'blue ',' orange', 'brown']) == [[' ', 'r', 'e', 'd', ' '], ['g', 'r', 'e', 'e', 'n'], [' ', 'b', 'l', 'a', 'c', 'k'], ['b', 'l', 'u', 'e', ' '], [' ', 'o', 'r', 'a', 'n', 'g', 'e'], ['b', 'r', 'o', 'w', 'n']]
| listify_list |
HumanEval\/858 | def count_list(input_list):
""" Count number of lists in a given list of lists and square the count.
>>> count_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])
25
>>> count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]])
16
>>> count_list([[2, 4], [[6,8], [4,5,8]], [10, 12, 14]])
9
"""
| return (len(input_list))**2
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]]) == 25
assert candidate([[1, 3], [5, 7], [9, 11], [13, 15, 17]]) == 16
assert candidate([[2, 4], [[6,8], [4,5,8]], [10, 12, 14]]) == 9
| count_list |
HumanEval\/859 | from typing import List
from itertools import combinations
def sub_lists(my_list: List) -> List[List]:
""" Generate all sublists of a given list
>>> sub_lists([10, 20, 30, 40])
[[], [10], [20], [30], [40], [10, 20], [10, 30], [10, 40], [20, 30], [20, 40], [30, 40], [10, 20, 30], [10, 20, 40], [10, 30, 40], [20, 30, 40], [10, 20, 30, 40]]
>>> sub_lists(['X', 'Y', 'Z'])
[[], ['X'], ['Y'], ['Z'], ['X', 'Y'], ['X', 'Z'], ['Y', 'Z'], ['X', 'Y', 'Z']]
>>> sub_lists([1, 2, 3])
[[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
"""
| subs = []
for i in range(0, len(my_list)+1):
temp = [list(x) for x in combinations(my_list, i)]
if len(temp) > 0:
subs.extend(temp)
return subs
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([10, 20, 30, 40]) == [[], [10], [20], [30], [40], [10, 20], [10, 30], [10, 40], [20, 30], [20, 40], [30, 40], [10, 20, 30], [10, 20, 40], [10, 30, 40], [20, 30, 40], [10, 20, 30, 40]]
assert candidate(['X', 'Y', 'Z']) == [[], ['X'], ['Y'], ['Z'], ['X', 'Y'], ['X', 'Z'], ['Y', 'Z'], ['X', 'Y', 'Z']]
assert candidate([1, 2, 3]) == [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
| sub_lists |
HumanEval\/860 | import re
def check_alphanumeric(string: str) -> str:
""" Check whether the given string is ending with only alphanumeric characters or not using regex.
>>> check_alphanumeric("dawood@")
'Discard'
>>> check_alphanumeric("skdmsam326")
'Accept'
>>> check_alphanumeric("cooltricks@")
'Discard'
"""
| regex = '[a-zA-Z0-9]$'
if re.search(regex, string):
return "Accept"
else:
return "Discard"
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("dawood@") == 'Discard'
assert candidate("skdmsam326") == 'Accept'
assert candidate("cooltricks@") == 'Discard'
| check_alphanumeric |
861 | from collections import Counter
from typing import List
def anagram_lambda(texts: List[str], str: str) -> List[str]:
""" Find all anagrams of a string in a given list of strings using lambda function.
>>> anagram_lambda(["bcda", "abce", "cbda", "cbea", "adcb"], "abcd")
['bcda', 'cbda', 'adcb']
>>> anagram_lambda(["recitals", "python"], "articles")
["recitals"]
>>> anagram_lambda(["keep", "abcdef", "xyz"], "peek")
["keep"]
"""
| result = list(filter(lambda x: (Counter(str) == Counter(x)), texts))
return result
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(["bcda", "abce", "cbda", "cbea", "adcb"], "abcd") == ['bcda', 'cbda', 'adcb']
assert candidate(["recitals", "python"], "articles") == ["recitals"]
assert candidate(["keep", "abcdef", "xyz"], "peek") == ["keep"]
| anagram_lambda |
HumanEval\/862 | from collections import Counter
import re
def n_common_words(text: str, n: int) -> list:
""" Write a function to find the occurrences of n most common words in a given text.
>>> n_common_words("python is a programming language", 1)
[('python', 1)]
>>> n_common_words("python is a programming language", 5)
[('python', 1), ('is', 1), ('a', 1), ('programming', 1), ('language', 1)]
"""
| words = re.findall('\w+', text)
n_common_words = Counter(words).most_common(n)
return list(n_common_words)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("python is a programming language", 1) == [('python', 1)]
assert candidate("python is a programming language", 5) == [('python', 1), ('is', 1), ('a', 1), ('programming', 1), ('language', 1)]
| n_common_words |
HumanEval\/863 | def find_longest_conseq_subseq(arr: List[int], n: int) -> int:
"""Find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.
>>> find_longest_conseq_subseq([1, 2, 2, 3], 4)
3
>>> find_longest_conseq_subseq([1, 9, 3, 10, 4, 20, 2], 7)
4
>>> find_longest_conseq_subseq([36, 41, 56, 35, 44, 33, 34, 92, 43, 32, 42], 11)
5
"""
| ans = 0
count = 0
arr.sort()
v = []
v.append(arr[0])
for i in range(1, n):
if (arr[i] != arr[i - 1]):
v.append(arr[i])
for i in range(len(v)):
if (i > 0 and v[i] == v[i - 1] + 1):
count += 1
else:
count = 1
ans = max(ans, count)
return ans
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 2, 2, 3], 4) == 3
assert candidate([1, 9, 3, 10, 4, 20, 2], 7) == 4
assert candidate([36, 41, 56, 35, 44, 33, 34, 92, 43, 32, 42], 11) == 5
| find_longest_conseq_subseq |
HumanEval\/864 | from typing import List
def palindrome_lambda(texts: List[str]) -> List[str]:
""" Find palindromes in a given list of strings using lambda function.
>>> palindrome_lambda(["php", "res", "Python", "abcd", "Java", "aaa"])
['php', 'aaa']
>>> palindrome_lambda(["abcd", "Python", "abba", "aba"])
['abba', 'aba']
"""
| return list(filter(lambda x: (x == "".join(reversed(x))), texts))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(["php", "res", "Python", "abcd", "Java", "aaa"]) == ['php', 'aaa']
assert candidate(["abcd", "Python", "abba", "aba"]) == ['abba', 'aba']
assert candidate(["abcd", "abbccbba", "abba", "aba"]) == ['abbccbba', 'abba', 'aba']
| palindrome_lambda |
HumanEval\/865 | from typing import List
def ntimes_list(nums: List[int], n: int) -> List[int]:
""" Multiply each element in the list by n using map function
>>> ntimes_list([1, 2, 3, 4, 5, 6, 7], 3)
[3, 6, 9, 12, 15, 18, 21]
>>> ntimes_list([1, 2, 3, 4, 5, 6, 7], 4)
[4, 8, 12, 16, 20, 24, 28]
"""
| result = map(lambda x: n * x, nums)
return list(result)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 2, 3, 4, 5, 6, 7], 3) == [3, 6, 9, 12, 15, 18, 21]
assert candidate([1, 2, 3, 4, 5, 6, 7], 4) == [4, 8, 12, 16, 20, 24, 28]
assert candidate([1, 2, 3, 4, 5, 6, 7], 10) == [10, 20, 30, 40, 50, 60, 70]
| ntimes_list |
HumanEval\/866 | def check_monthnumb(monthname2: str) -> bool:
""" Check whether the given month name contains 31 days or not.
>>> check_monthnumb("February")
False
>>> check_monthnumb("January")
True
>>> check_monthnumb("March")
True
"""
| if monthname2 in ["January", "March", "May", "July", "August", "October", "December"]:
return True
else:
return False
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("February") == False
assert candidate("January") == True
assert candidate("March") == True
| check_monthnumb |
HumanEval\/867 | def min_Num(arr: list, n: int) -> int:
""" Add a minimum number such that the sum of array becomes even.
>>> min_Num([1,2,3,4,5,6,7,8,9],9)
1
>>> min_Num([1,2,3,4,5,6,7,8],8)
2
>>> min_Num([1,2,3],3)
2
"""
| odd = 0
for i in range(n):
if (arr[i] % 2):
odd += 1
if (odd % 2):
return 1
return 2
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,2,3,4,5,6,7,8,9],9) == 1
assert candidate([1,2,3,4,5,6,7,8],8) == 2
assert candidate([1,2,3],3) == 2
| min_Num |
HumanEval\/868 | def length_Of_Last_Word(a: str) -> int:
""" Find the length of the last word in a given string.
>>> length_Of_Last_Word("python language")
8
>>> length_Of_Last_Word("PHP")
3
>>> length_Of_Last_Word("")
0
"""
| l = 0
x = a.strip()
for i in range(len(x)):
if x[i] == " ":
l = 0
else:
l += 1
return l
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("python language") == 8
assert candidate("PHP") == 3
assert candidate("") == 0
| length_Of_Last_Word |
869 | from typing import List
def remove_list_range(list1: List[List[int]], leftrange: int, rigthrange: int) -> List[List[int]]:
""" Remove sublists from a given list of lists, which are outside a given range.
>>> remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]], 13, 17)
[[13, 14, 15, 17]]
>>> remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]], 1, 3)
[[2], [1, 2, 3]]
>>> remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]], 0, 7)
[[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7]]
"""
| result = [i for i in list1 if (min(i) >= leftrange and max(i) <= rigthrange)]
return result
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]], 13, 17) == [[13, 14, 15, 17]]
assert candidate([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]], 1, 3) == [[2], [1, 2, 3]]
assert candidate([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]], 0, 7) == [[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7]]
| remove_list_range |
HumanEval\/870 | from typing import List
def sum_positivenum(nums: List[int]) -> int:
""" Calculate the sum of the positive numbers of a given list of numbers using lambda function.
>>> sum_positivenum([2, 4, -6, -9, 11, -12, 14, -5, 17])
48
>>> sum_positivenum([10,15,-14,13,-18,12,-20])
50
>>> sum_positivenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])
522
"""
| return sum(filter(lambda x: x > 0, nums))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([2, 4, -6, -9, 11, -12, 14, -5, 17]) == 48
assert candidate([10, 15, -14, 13, -18, 12, -20]) == 50
assert candidate([19, -65, 57, 39, 152, -639, 121, 44, 90, -190]) == 522
| sum_positivenum |
HumanEval\/871 | def are_Rotations(string1: str, string2: str) -> bool:
""" Check whether the given strings are rotations of each other
>>> are_Rotations('abc', 'cba')
False
>>> are_Rotations('abcd', 'cdba')
False
>>> are_Rotations('abacd', 'cdaba')
True
"""
| size1 = len(string1)
size2 = len(string2)
if size1 != size2:
return False
temp = string1 + string1
return string2 in temp
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('abc', 'cba') == False
assert candidate('abcd', 'cdba') == False
assert candidate('abacd', 'cdaba') == True
| are_Rotations |
HumanEval\/872 | def check_subset(list1, list2):
""" Check if a nested list is a subset of another nested list.
>>> check_subset([[1, 3], [5, 7], [9, 11], [13, 15, 17]], [[1, 3], [13, 15, 17]])
True
>>> check_subset([[1, 2], [2, 3], [3, 4], [5, 6]], [[3, 4], [5, 6]])
True
>>> check_subset([[[1, 2], [2, 3]], [[3, 4], [5, 7]]], [[[3, 4], [5, 6]]])
False
"""
| return all(map(list1.__contains__, list2))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([[1, 3], [5, 7], [9, 11], [13, 15, 17]], [[1, 3], [13, 15, 17]]) == True
assert candidate([[1, 2], [2, 3], [3, 4], [5, 6]], [[3, 4], [5, 6]]) == True
assert candidate([[[1, 2], [2, 3]], [[3, 4], [5, 7]]], [[[3, 4], [5, 6]]]) == False
| check_subset |
HumanEval\/873 | def fibonacci(n: int) -> int:
"""Write a function to solve the fibonacci sequence using recursion.
>>> fibonacci(7)
13
>>> fibonacci(8)
21
>>> fibonacci(9)
34
"""
| if n == 1 or n == 2:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(7) == 13
assert candidate(8) == 21
assert candidate(9) == 34
| fibonacci |
HumanEval\/874 | def check_Concat(str1: str, str2: str) -> bool:
""" Check if the string str1 is a concatenation of the string str2
>>> check_Concat("abcabcabc", "abc")
True
>>> check_Concat("abcab", "abc")
False
>>> check_Concat("aba", "ab")
False
"""
| N = len(str1)
M = len(str2)
if (N % M != 0):
return False
for i in range(N):
if (str1[i] != str2[i % M]):
return False
return True
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("abcabcabc", "abc") == True
assert candidate("abcab", "abc") == False
assert candidate("aba", "ab") == False
| check_Concat |
HumanEval\/875 | from typing import List, Tuple
def min_difference(test_list: List[Tuple[int, int]]) -> int:
""" Write a function to find the minimum difference in the tuple pairs of given tuples.
>>> min_difference([(3, 5), (1, 7), (10, 3), (1, 2)])
1
>>> min_difference([(4, 6), (12, 8), (11, 4), (2, 13)])
2
>>> min_difference([(5, 17), (3, 9), (12, 5), (3, 24)])
6
"""
| temp = [abs(b - a) for a, b in test_list]
res = min(temp)
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([(3, 5), (1, 7), (10, 3), (1, 2)]) == 1
assert candidate([(4, 6), (12, 8), (11, 4), (2, 13)]) == 2
assert candidate([(5, 17), (3, 9), (12, 5), (3, 24)]) == 6
| min_difference |
HumanEval\/876 | def lcm(x: int, y: int) -> int:
"""Find the least common multiple of two positive integers.
>>> lcm(4, 6)
12
>>> lcm(15, 17)
255
>>> lcm(2, 6)
6
"""
| if x > y:
z = x
else:
z = y
while(True):
if((z % x == 0) and (z % y == 0)):
lcm = z
break
z += 1
return lcm
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(4, 6) == 12
assert candidate(15, 17) == 255
assert candidate(2, 6) == 6
| lcm |
HumanEval\/877 | def sort_String(str: str) -> str:
""" Sort the given string in alphabetical order.
>>> sort_String("cba")
'abc'
>>> sort_String("data")
'aadt'
>>> sort_String("zxy")
'xyz'
"""
| return ''.join(sorted(str))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("cba") == "abc"
assert candidate("data") == "aadt"
assert candidate("zxy") == "xyz"
| sort_String |
HumanEval\/878 | def check_tuples(test_tuple: tuple, K: list) -> bool:
""" Check if the given tuple contains only elements from the list K
>>> check_tuples((3, 5, 6, 5, 3, 6), [3, 6, 5])
True
>>> check_tuples((4, 5, 6, 4, 6, 5), [4, 5, 6])
True
>>> check_tuples((9, 8, 7, 6, 8, 9), [9, 8, 1])
False
"""
| return all(ele in K for ele in test_tuple)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate((3, 5, 6, 5, 3, 6), [3, 6, 5]) == True
assert candidate((4, 5, 6, 4, 6, 5), [4, 5, 6]) == True
assert candidate((9, 8, 7, 6, 8, 9), [9, 8, 1]) == False
| check_tuples |
HumanEval\/879 | import re
def text_match(text: str) -> str:
""" Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex.
>>> text_match("aabbbbd")
'Not matched!'
>>> text_match("aabAbbbc")
'Not matched!'
>>> text_match("accddbbjjjb")
'Found a match!'
"""
| patterns = 'a.*?b$'
if re.search(patterns, text):
return 'Found a match!'
else:
return 'Not matched!'
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("aabbbbd") == 'Not matched!'
assert candidate("aabAbbbc") == 'Not matched!'
assert candidate("accddbbjjjb") == 'Found a match!'
| text_match |
HumanEval\/880 | def Check_Solution(a: int, b: int, c: int) -> str:
"""Find number of solutions in quadratic equation
>>> Check_Solution(2, 5, 2)
'2 solutions'
>>> Check_Solution(1, 1, 1)
'No solutions'
>>> Check_Solution(1, 2, 1)
'1 solution'
"""
| if ((b*b) - (4*a*c)) > 0:
return "2 solutions"
elif ((b*b) - (4*a*c)) == 0:
return "1 solution"
else:
return "No solutions"
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(2, 5, 2) == '2 solutions'
assert candidate(1, 1, 1) == 'No solutions'
assert candidate(1, 2, 1) == '1 solution'
| Check_Solution |
HumanEval\/881 | from typing import List
def sum_even_odd(list1: List[int]) -> int:
""" Write a function to find the sum of first even and odd number of a given list.
>>> sum_even_odd([1,3,5,7,4,1,6,8])
5
>>> sum_even_odd([1,2,3,4,5,6,7,8,9,10])
3
>>> sum_even_odd([1,5,7,9,10])
11
"""
| first_even = next((el for el in list1 if el%2==0),-1)
first_odd = next((el for el in list1 if el%2!=0),-1)
return (first_even+first_odd)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,3,5,7,4,1,6,8]) == 5
assert candidate([1,2,3,4,5,6,7,8,9,10]) == 3
assert candidate([1,5,7,9,10]) == 11
| sum_even_odd |
HumanEval\/882 | def parallelogram_perimeter(b: int, h: int) -> int:
""" Calculate the perimeter of a parallelogram given base and height.
>>> parallelogram_perimeter(10, 20)
60
>>> parallelogram_perimeter(15, 20)
70
>>> parallelogram_perimeter(8, 9)
34
"""
| return 2 * (b + h)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(10, 20) == 60
assert candidate(15, 20) == 70
assert candidate(8, 9) == 34
| parallelogram_perimeter |
HumanEval\/883 | from typing import List
def div_of_nums(nums: List[int], m: int, n: int) -> List[int]:
""" Find numbers divisible by m and n from a list of numbers using lambda function.
>>> div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190], 2, 4)
[152, 44]
>>> div_of_nums([1, 2, 3, 5, 7, 8, 10], 2, 5)
[10]
>>> div_of_nums([10, 15, 14, 13, 18, 12, 20], 10, 5)
[10, 20]
"""
| return list(filter(lambda x: (x % m == 0 and x % n == 0), nums))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([19, 65, 57, 39, 152, 639, 121, 44, 90, 190], 2, 4) == [152, 44]
assert candidate([1, 2, 3, 5, 7, 8, 10], 2, 5) == [10]
assert candidate([10, 15, 14, 13, 18, 12, 20], 10, 5) == [10, 20]
| div_of_nums |
HumanEval\/884 | def all_Bits_Set_In_The_Given_Range(n: int, l: int, r: int) -> bool:
""" Check whether all the bits are set within a given range.
>>> all_Bits_Set_In_The_Given_Range(10, 2, 1)
True
>>> all_Bits_Set_In_The_Given_Range(5, 2, 4)
False
>>> all_Bits_Set_In_The_Given_Range(22, 2, 3)
True
"""
| num = ((1 << r) - 1) ^ ((1 << (l - 1)) - 1)
new_num = n & num
if (num == new_num):
return True
return False
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(10, 2, 1) == True
assert candidate(5, 2, 4) == False
assert candidate(22, 2, 3) == True
| all_Bits_Set_In_The_Given_Range |
HumanEval\/885 | def is_Isomorphic(str1: str, str2: str) -> bool:
""" Check whether the two given strings are isomorphic to each other
>>> is_Isomorphic("paper", "title")
True
>>> is_Isomorphic("ab", "ba")
True
>>> is_Isomorphic("ab", "aa")
False
"""
| dict_str1 = {}
dict_str2 = {}
for i, value in enumerate(str1):
dict_str1[value] = dict_str1.get(value,[]) + [i]
for j, value in enumerate(str2):
dict_str2[value] = dict_str2.get(value,[]) + [j]
if sorted(dict_str1.values()) == sorted(dict_str2.values()):
return True
else:
return False
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("paper", "title") == True
assert candidate("ab", "ba") == True
assert candidate("ab", "aa") == False
| is_Isomorphic |
HumanEval\/886 | def sum_num(numbers: list) -> float:
""" Calculate the average of a list of numbers
>>> sum_num([8, 2, 3, 0, 7])
4.0
>>> sum_num([-10, -20, -30])
-20.0
>>> sum_num([19, 15, 18])
17.333333333333332
"""
| total = 0
for x in numbers:
total += x
return total / len(numbers)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([8, 2, 3, 0, 7]) == 4.0
assert candidate([-10, -20, -30]) == -20.0
assert candidate([19, 15, 18]) == 17.333333333333332
| sum_num |
HumanEval\/887 | def is_odd(n: int) -> bool:
""" Check whether the given number is odd using bitwise operator.
>>> is_odd(5)
True
>>> is_odd(6)
False
>>> is_odd(7)
True
"""
| return (n & 1) == 1
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(5) == True
assert candidate(6) == False
assert candidate(7) == True
| is_odd |
HumanEval\/888 | def substract_elements(test_tup1, test_tup2):
""" Subtract the elements of the given nested tuples.
>>> substract_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3)))
((-5, -4), (1, -4), (1, 8), (-6, 7))
"""
| res = tuple(tuple(a - b for a, b in zip(tup1, tup2)) for tup1, tup2 in zip(test_tup1, test_tup2))
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((-5, -4), (1, -4), (1, 8), (-6, 7))
assert candidate(((13, 4), (14, 6), (13, 10), (12, 11)), ((19, 8), (14, 10), (12, 2), (18, 4))) == ((-6, -4), (0, -4), (1, 8), (-6, 7))
assert candidate(((19, 5), (18, 7), (19, 11), (17, 12)), ((12, 9), (17, 11), (13, 3), (19, 5))) == ((7, -4), (1, -4), (6, 8), (-2, 7))
| substract_elements |
HumanEval\/889 | from typing import List
def reverse_list_lists(lists: List[List[int]]) -> List[List[int]]:
""" Reverse each list in a given list of lists
>>> reverse_list_lists([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])
[[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9], [16, 15, 14, 13]]
>>> reverse_list_lists([[1,2],[2,3],[3,4]])
[[2,1],[3,2],[4,3]]
>>> reverse_list_lists([[10,20],[30,40]])
[[20,10],[40,30]]
"""
| return [l[::-1] for l in lists]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) == [[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9], [16, 15, 14, 13]]
assert candidate([[1,2],[2,3],[3,4]]) == [[2,1],[3,2],[4,3]]
assert candidate([[10,20],[30,40]]) == [[20,10],[40,30]]
| reverse_list_lists |
890 | def find_Extra(arr1, arr2, n):
"""Find the index of an extra element present in one sorted array.
>>> find_Extra([1,2,3,4],[1,2,3],3)
3
>>> find_Extra([2,4,6,8,10],[2,4,6,8],4)
4
>>> find_Extra([1,3,5,7,9,11],[1,3,5,7,9],5)
5
"""
| for i in range(0, n):
if arr1[i] != arr2[i]:
return i
return n
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,2,3,4],[1,2,3],3) == 3
assert candidate([2,4,6,8,10],[2,4,6,8],4) == 4
assert candidate([1,3,5,7,9,11],[1,3,5,7,9],5) == 5
| find_Extra |
HumanEval\/891 | def same_Length(A: int, B: int) -> bool:
""" Check whether the given two numbers have the same number of digits or not.
>>> same_Length(12, 1)
False
>>> same_Length(2, 2)
True
>>> same_Length(10, 20)
True
"""
| while (A > 0 and B > 0):
A = A / 10
B = B / 10
if (A == 0 and B == 0):
return True
return False
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(12, 1) == False
assert candidate(2, 2) == True
assert candidate(10, 20) == True
| same_Length |
HumanEval\/892 | import re
def remove_spaces(text: str) -> str:
""" Remove multiple spaces in a string
>>> remove_spaces('python program')
'python program'
>>> remove_spaces('python programming language')
'python programming language'
>>> remove_spaces('python program')
'python program'
"""
| return re.sub(' +', ' ', text)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('python program') == 'python program'
assert candidate('python programming language') == 'python programming language'
assert candidate('python program') == 'python program'
| remove_spaces |
HumanEval\/893 | from typing import List
def Extract(lst: List[List[int]]) -> List[int]:
""" Get the last element of each sublist
>>> Extract([[1, 2, 3], [4, 5], [6, 7, 8, 9]])
[3, 5, 9]
>>> Extract([['x', 'y', 'z'], ['m'], ['a', 'b'], ['u', 'v']])
['z', 'm', 'b', 'v']
"""
| return [item[-1] for item in lst]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([[1, 2, 3], [4, 5], [6, 7, 8, 9]]) == [3, 5, 9]
assert candidate([['x', 'y', 'z'], ['m'], ['a', 'b'], ['u', 'v']]) == ['z', 'm', 'b', 'v']
assert candidate([[1, 2, 3], [4, 5]]) == [3, 5]
| Extract |
HumanEval\/894 | def float_to_tuple(test_str: str) -> tuple:
""" Convert the given string of float type into a tuple.
>>> float_to_tuple("1.2, 1.3, 2.3, 2.4, 6.5")
(1.2, 1.3, 2.3, 2.4, 6.5)
>>> float_to_tuple("2.3, 2.4, 5.6, 5.4, 8.9")
(2.3, 2.4, 5.6, 5.4, 8.9)
>>> float_to_tuple("0.3, 0.5, 7.8, 9.4")
(0.3, 0.5, 7.8, 9.4)
"""
| res = tuple(map(float, test_str.split(', ')))
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("1.2, 1.3, 2.3, 2.4, 6.5") == (1.2, 1.3, 2.3, 2.4, 6.5)
assert candidate("2.3, 2.4, 5.6, 5.4, 8.9") == (2.3, 2.4, 5.6, 5.4, 8.9)
assert candidate("0.3, 0.5, 7.8, 9.4") == (0.3, 0.5, 7.8, 9.4)
| float_to_tuple |
HumanEval\/895 | def max_sum_subseq(A):
"""Write a function to find the maximum sum of subsequences of given array with no adjacent elements.
>>> max_sum_subseq([1, 2, 9, 4, 5, 0, 4, 11, 6])
26
>>> max_sum_subseq([1, 2, 9, 5, 6, 0, 5, 12, 7])
28
>>> max_sum_subseq([1, 3, 10, 5, 6, 0, 6, 14, 21])
44
"""
n = len(A)
if n == 1:
return A[0]
look_up = [None] * n
look_up[0] = A[0]
look_up[1] = max(A[0], A[1])
for i in range(2, n):
look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i])
look_up[i] = max(look_up[i], A[i])
return look_up[n - 1]
| n = len(A)
if n == 1:
return A[0]
look_up = [None] * n
look_up[0] = A[0]
look_up[1] = max(A[0], A[1])
for i in range(2, n):
look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i])
look_up[i] = max(look_up[i], A[i])
return look_up[n - 1]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 2, 9, 4, 5, 0, 4, 11, 6]) == 26
assert candidate([1, 2, 9, 5, 6, 0, 5, 12, 7]) == 28
assert candidate([1, 3, 10, 5, 6, 0, 6, 14, 21]) == 44
| max_sum_subseq |
HumanEval\/896 | from typing import List, Tuple
def sort_list_last(tuples: List[Tuple[int, int]]) -> List[Tuple[int, int]]:
""" Sort a list in increasing order by the last element in each tuple from a given list of non-empty tuples.
>>> sort_list_last([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)])
[(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)]
>>> sort_list_last([(9,8), (4, 7), (3,5), (7,9), (1,2)])
[(1, 2), (3, 5), (4, 7), (9, 8), (7, 9)]
"""
| return sorted(tuples, key=lambda n: n[-1])
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]) == [(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)]
assert candidate([(9, 8), (4, 7), (3, 5), (7, 9), (1, 2)]) == [(1, 2), (3, 5), (4, 7), (9, 8), (7, 9)]
assert candidate([(20, 50), (10, 20), (40, 40)]) == [(10, 20), (40, 40), (20, 50)]
| sort_list_last |
HumanEval\/897 | def is_Word_Present(sentence: str, word: str) -> bool:
""" Check whether the word is present in a given sentence or not.
>>> is_Word_Present("machine learning", "machine")
True
>>> is_Word_Present("easy", "fun")
False
>>> is_Word_Present("python language", "code")
False
"""
| s = sentence.split(" ")
for i in s:
if (i == word):
return True
return False
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("machine learning", "machine") == True
assert candidate("easy", "fun") == False
assert candidate("python language", "code") == False
| is_Word_Present |
HumanEval\/898 | from itertools import groupby
from typing import List
def extract_elements(numbers: List[int], n: int) -> List[int]:
""" Extract specified number of elements from a given list, which follow each other continuously.
>>> extract_elements([1, 1, 3, 4, 4, 5, 6, 7], 2)
[1, 4]
>>> extract_elements([0, 1, 2, 3, 4, 4, 4, 4, 5, 7], 4)
[4]
>>> extract_elements([0, 0, 0, 0, 0], 5)
[0]
"""
| result = [i for i, j in groupby(numbers) if len(list(j)) == n]
return result
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 1, 3, 4, 4, 5, 6, 7], 2) == [1, 4]
assert candidate([0, 1, 2, 3, 4, 4, 4, 4, 5, 7], 4) == [4]
assert candidate([0, 0, 0, 0, 0], 5) == [0]
| extract_elements |
HumanEval\/899 | def check(arr: list, n: int) -> bool:
""" Check whether an array can be sorted or not by picking only the corner elements.
>>> check([3,2,1,2,3,4], 6)
True
>>> check([2,1,4,5,1], 5)
True
>>> check([1,2,2,1,2,3], 6)
True
"""
| g = 0
for i in range(1, n):
if (arr[i] - arr[i - 1] > 0 and g == 1):
return False
if (arr[i] - arr[i - 1] < 0):
g = 1
return True
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([3,2,1,2,3,4], 6) == True
assert candidate([2,1,4,5,1], 5) == True
assert candidate([1,2,2,1,2,3], 6) == True
| check |
HumanEval\/900 | import re
def match_num(string: str) -> bool:
""" Check if the string starts with the number 5
>>> match_num('5-2345861')
True
>>> match_num('6-2345861')
False
>>> match_num('78910')
False
"""
| text = re.compile(r"^5")
return bool(text.match(string))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('5-2345861') == True
assert candidate('6-2345861') == False
assert candidate('78910') == False
| match_num |