task_id
stringlengths 3
14
| prompt
stringlengths 164
742
| canonical_solution
stringlengths 14
760
| test
stringlengths 170
703
| entry_point
stringlengths 3
31
|
---|---|---|---|---|
601 | class Pair(object):
def __init__(self, a, b):
self.a = a
self.b = b
def max_chain_length(arr, n):
""" Find the longest chain which can be formed from the given set of pairs.
>>> max_chain_length([Pair(5, 24), Pair(15, 25), Pair(27, 40), Pair(50, 60)], 4)
3
>>> max_chain_length([Pair(1, 2), Pair(3, 4), Pair(5, 6), Pair(7, 8)], 4)
4
"""
| max = 0
mcl = [1 for i in range(n)]
for i in range(1, n):
for j in range(0, i):
if (arr[i].a > arr[j].b and mcl[i] < mcl[j] + 1):
mcl[i] = mcl[j] + 1
for i in range(n):
if (max < mcl[i]):
max = mcl[i]
return max
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([Pair(5, 24), Pair(15, 25), Pair(27, 40), Pair(50, 60)], 4) == 3
assert candidate([Pair(1, 2), Pair(3, 4), Pair(5, 6), Pair(7, 8)], 4) == 4
assert candidate([Pair(19, 10), Pair(11, 12), Pair(13, 14), Pair(15, 16), Pair(31, 54)], 5) == 5
| max_chain_length |
HumanEval\/602 | def first_repeated_char(str1: str) -> str:
""" Find the first repeated character in a given string.
>>> first_repeated_char("abcabc")
'a'
>>> first_repeated_char("abc")
'None'
>>> first_repeated_char("123123")
'1'
"""
| for index, c in enumerate(str1):
if str1[:index+1].count(c) > 1:
return c
return "None"
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("abcabc") == "a"
assert candidate("abc") == "None"
assert candidate("123123") == "1"
| first_repeated_char |
603 | def get_ludic(n):
""" Write a function to get a lucid number smaller than or equal to n.
>>> get_ludic(10)
[1, 2, 3, 5, 7]
>>> get_ludic(25)
[1, 2, 3, 5, 7, 11, 13, 17, 23, 25]
>>> get_ludic(45)
[1, 2, 3, 5, 7, 11, 13, 17, 23, 25, 29, 37, 41, 43]
"""
| ludics = []
for i in range(1, n + 1):
ludics.append(i)
index = 1
while(index != len(ludics)):
first_ludic = ludics[index]
remove_index = index + first_ludic
while(remove_index < len(ludics)):
ludics.remove(ludics[remove_index])
remove_index = remove_index + first_ludic - 1
index += 1
return ludics
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(10) == [1, 2, 3, 5, 7]
assert candidate(25) == [1, 2, 3, 5, 7, 11, 13, 17, 23, 25]
assert candidate(45) == [1, 2, 3, 5, 7, 11, 13, 17, 23, 25, 29, 37, 41, 43]
| get_ludic |
HumanEval\/604 | def reverse_words(s: str) -> str:
""" Reverse words in a given string
>>> reverse_words("python program")
'program python'
>>> reverse_words("java language")
'language java'
>>> reverse_words("indian man")
'man indian'
"""
| return ' '.join(reversed(s.split()))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("python program") == "program python"
assert candidate("java language") == "language java"
assert candidate("indian man") == "man indian"
| reverse_words |
HumanEval\/605 | def prime_num(num: int) -> bool:
""" Check if the given integer is a prime number.
>>> prime_num(13)
True
>>> prime_num(7)
True
>>> prime_num(-1010)
False
"""
| if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(13) == True
assert candidate(7) == True
assert candidate(-1010) == False
| prime_num |
HumanEval\/606 | import math
def radian_degree(degree: float) -> float:
""" Convert degrees to radians
>>> radian_degree(90)
1.5707963267948966
>>> radian_degree(60)
1.0471975511965976
>>> radian_degree(120)
2.0943951023931953
"""
| return degree * (math.pi / 180)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(90) == 1.5707963267948966
assert candidate(60) == 1.0471975511965976
assert candidate(120) == 2.0943951023931953
| radian_degree |
HumanEval\/607 | import re
def find_literals(text: str, pattern: str) -> tuple:
""" Search a literals string in a string and find the location within the original string where the pattern occurs by using regex.
>>> find_literals('The quick brown fox jumps over the lazy dog.', 'fox')
('fox', 16, 19)
>>> find_literals('Its been a very crazy procedure right', 'crazy')
('crazy', 16, 21)
>>> find_literals('Hardest choices required strongest will', 'will')
('will', 35, 39)
"""
| match = re.search(pattern, text)
s = match.start()
e = match.end()
return (match.re.pattern, s, e)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('The quick brown fox jumps over the lazy dog.', 'fox') == ('fox', 16, 19)
assert candidate('Its been a very crazy procedure right', 'crazy') == ('crazy', 16, 21)
assert candidate('Hardest choices required strongest will', 'will') == ('will', 35, 39)
| find_literals |
HumanEval\/608 | def bell_Number(n: int) -> int:
"""Calculate the nth Bell number.
>>> bell_Number(2)
2
>>> bell_Number(3)
5
>>> bell_Number(4)
15
"""
| bell = [[0 for i in range(n+1)] for j in range(n+1)]
bell[0][0] = 1
for i in range(1, n+1):
bell[i][0] = bell[i-1][i-1]
for j in range(1, i+1):
bell[i][j] = bell[i-1][j-1] + bell[i][j-1]
return bell[n][0]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(2) == 2
assert candidate(3) == 5
assert candidate(4) == 15
| bell_Number |
609 | def floor_Min(A: int, B: int, N: int) -> int:
""" Find the minimum possible value for the given periodic function.
>>> floor_Min(10, 20, 30)
15
>>> floor_Min(1, 2, 1)
0
>>> floor_Min(11, 10, 9)
9
"""
| x = max(B - 1, N)
return (A * x) // B
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(10, 20, 30) == 15
assert candidate(1, 2, 1) == 0
assert candidate(11, 10, 9) == 9
| floor_Min |
HumanEval\/610 | from typing import List
def remove_kth_element(list1: List[int], L: int) -> List[int]:
""" Remove the k'th element from a given list
>>> remove_kth_element([1,1,2,3,4,4,5,1], 3)
[1, 1, 3, 4, 4, 5, 1]
>>> remove_kth_element([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4], 4)
[0, 0, 1, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]
>>> remove_kth_element([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10], 5)
[10, 10, 15, 19, 18, 17, 26, 26, 17, 18, 10]
"""
| return list1[:L-1] + list1[L:]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,1,2,3,4,4,5,1], 3) == [1, 1, 3, 4, 4, 5, 1]
assert candidate([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4], 4) == [0, 0, 1, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]
assert candidate([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10], 5) == [10, 10, 15, 19, 18, 17, 26, 26, 17, 18, 10]
| remove_kth_element |
611 | def max_of_nth(test_list: list, N: int) -> int:
""" Find the maximum of nth column from the given tuple list.
>>> max_of_nth([(5, 6, 7), (1, 3, 5), (8, 9, 19)], 2)
19
>>> max_of_nth([(6, 7, 8), (2, 4, 6), (9, 10, 20)], 1)
10
"""
| res = max([sub[N] for sub in test_list])
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([(5, 6, 7), (1, 3, 5), (8, 9, 19)], 2) == 19
assert candidate([(6, 7, 8), (2, 4, 6), (9, 10, 20)], 1) == 10
assert candidate([(7, 8, 9), (3, 5, 7), (10, 11, 21)], 1) == 11
| max_of_nth |
HumanEval\/612 | from typing import List
def merge(lst: List[List]) -> List[List]:
""" Merge the first and last elements separately in a list of lists.
>>> merge([['x', 'y'], ['a', 'b'], ['m', 'n']])
[['x', 'a', 'm'], ['y', 'b', 'n']]
>>> merge([[1, 2], [3, 4], [5, 6], [7, 8]])
[[1, 3, 5, 7], [2, 4, 6, 8]]
"""
| return [list(ele) for ele in list(zip(*lst))]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([['x', 'y'], ['a', 'b'], ['m', 'n']]) == [['x', 'a', 'm'], ['y', 'b', 'n']]
assert candidate([[1, 2], [3, 4], [5, 6], [7, 8]]) == [[1, 3, 5, 7], [2, 4, 6, 8]]
assert candidate([['x', 'y', 'z'], ['a', 'b', 'c'], ['m', 'n', 'o']]) == [['x', 'a', 'm'], ['y', 'b', 'n'], ['z', 'c', 'o']]
| merge |
HumanEval\/613 | from typing import List, Tuple
def maximum_value(test_list: List[Tuple[str, List[int]]]) -> List[Tuple[str, int]]:
""" Write a function to find the maximum value in record list as tuple attribute in the given tuple list.
>>> maximum_value([('key1', [3, 4, 5]), ('key2', [1, 4, 2]), ('key3', [9, 3])])
[('key1', 5), ('key2', 4), ('key3', 9)]
>>> maximum_value([('key1', [4, 5, 6]), ('key2', [2, 5, 3]), ('key3', [10, 4])])
[('key1', 6), ('key2', 5), ('key3', 10)]
"""
| return [(key, max(lst)) for key, lst in test_list]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([('key1', [3, 4, 5]), ('key2', [1, 4, 2]), ('key3', [9, 3])]) == [('key1', 5), ('key2', 4), ('key3', 9)]
assert candidate([('key1', [4, 5, 6]), ('key2', [2, 5, 3]), ('key3', [10, 4])]) == [('key1', 6), ('key2', 5), ('key3', 10)]
assert candidate([('key1', [5, 6, 7]), ('key2', [3, 6, 4]), ('key3', [11, 5])]) == [('key1', 7), ('key2', 6), ('key3', 11)]
| maximum_value |
HumanEval\/614 | def cummulative_sum(test_list: List[Tuple[int, ...]]) -> int:
""" Write a function to find the cumulative sum of all the values that are present in the given tuple list.
>>> cummulative_sum([(1, 3), (5, 6, 7), (2, 6)])
30
>>> cummulative_sum([(2, 4), (6, 7, 8), (3, 7)])
37
>>> cummulative_sum([(3, 5), (7, 8, 9), (4, 8)])
44
"""
| return sum(map(sum, test_list))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([(1, 3), (5, 6, 7), (2, 6)]) == 30
assert candidate([(2, 4), (6, 7, 8), (3, 7)]) == 37
assert candidate([(3, 5), (7, 8, 9), (4, 8)]) == 44
| cummulative_sum |
HumanEval\/615 | def average_tuple(nums):
""" Write a function to find average value of the numbers in a given tuple of tuples.
>>> average_tuple(((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4)))
[30.5, 34.25, 27.0, 23.25]
>>> average_tuple(((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3)))
[25.5, -18.0, 3.75]
>>> average_tuple(((100, 100, 100, 120), (300, 450, 560, 450), (810, 800, 390, 320), (10, 20, 30, 40)))
[305.0, 342.5, 270.0, 232.5]
"""
| result = [sum(x) / len(x) for x in zip(*nums)]
return result
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4))) == [30.5, 34.25, 27.0, 23.25]
assert candidate(((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3))) == [25.5, -18.0, 3.75]
assert candidate(((100, 100, 100, 120), (300, 450, 560, 450), (810, 800, 390, 320), (10, 20, 30, 40))) == [305.0, 342.5, 270.0, 232.5]
| average_tuple |
HumanEval\/616 | def tuple_modulo(test_tup1: tuple, test_tup2: tuple) -> tuple:
""" Perform the modulo of tuple elements in the given two tuples.
>>> tuple_modulo((10, 4, 5, 6), (5, 6, 7, 5))
(0, 4, 5, 1)
>>> tuple_modulo((11, 5, 6, 7), (6, 7, 8, 6))
(5, 5, 6, 1)
>>> tuple_modulo((12, 6, 7, 8), (7, 8, 9, 7))
(5, 6, 7, 1)
"""
| res = tuple(ele1 % ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate((10, 4, 5, 6), (5, 6, 7, 5)) == (0, 4, 5, 1)
assert candidate((11, 5, 6, 7), (6, 7, 8, 6)) == (5, 5, 6, 1)
assert candidate((12, 6, 7, 8), (7, 8, 9, 7)) == (5, 6, 7, 1)
| tuple_modulo |
HumanEval\/617 | def min_Jumps(a: int, b: int, d: int) -> float:
""" Calculate the number of jumps required of given length to reach a point (d, 0) from origin in a 2d plane.
>>> min_Jumps(3, 4, 11)
3.5
>>> min_Jumps(3, 4, 0)
0
>>> min_Jumps(11, 14, 11)
1
"""
| temp = a
a = min(a, b)
b = max(temp, b)
if (d >= b):
return (d + b - 1) / b
if (d == 0):
return 0
if (d == a):
return 1
else:
return 2
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(3, 4, 11) == 3.5
assert candidate(3, 4, 0) == 0
assert candidate(11, 14, 11) == 1
| min_Jumps |
HumanEval\/618 | from typing import List
def div_list(nums1: List[float], nums2: List[float]) -> List[float]:
""" Divide two lists element-wise using map and lambda function.
>>> div_list([4,5,6],[1, 2, 3])
[4.0, 2.5, 2.0]
>>> div_list([3,2],[1,4])
[3.0, 0.5]
>>> div_list([90,120],[50,70])
[1.8, 1.7142857142857142]
"""
| result = map(lambda x, y: x / y, nums1, nums2)
return list(result)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([4,5,6],[1, 2, 3]) == [4.0, 2.5, 2.0]
assert candidate([3,2],[1,4]) == [3.0, 0.5]
assert candidate([90,120],[50,70]) == [1.8, 1.7142857142857142]
| div_list |
HumanEval\/619 | def move_num(test_str: str) -> str:
""" Move all the numbers in the string to the end of it.
>>> move_num('I1love143you55three3000thousand')
'Iloveyouthreethousand1143553000'
>>> move_num('Avengers124Assemble')
'AvengersAssemble124'
>>> move_num('Its11our12path13to14see15things16do17things')
'Itsourpathtoseethingsdothings11121314151617'
"""
| res = ''
dig = ''
for ele in test_str:
if ele.isdigit():
dig += ele
else:
res += ele
res += dig
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('I1love143you55three3000thousand') == 'Iloveyouthreethousand1143553000'
assert candidate('Avengers124Assemble') == 'AvengersAssemble124'
assert candidate('Its11our12path13to14see15things16do17things') == 'Itsourpathtoseethingsdothings11121314151617'
| move_num |
HumanEval\/620 | def largest_subset(a, n):
""" Find the largest subset where each pair is divisible
>>> largest_subset([1, 3, 6, 13, 17, 18], 6)
4
>>> largest_subset([10, 5, 3, 15, 20], 5)
3
>>> largest_subset([18, 1, 3, 6, 13, 17], 6)
4
"""
| dp = [0 for i in range(n)]
dp[n - 1] = 1;
for i in range(n - 2, -1, -1):
mxm = 0;
for j in range(i + 1, n):
if a[j] % a[i] == 0 or a[i] % a[j] == 0:
mxm = max(mxm, dp[j])
dp[i] = 1 + mxm
return max(dp)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 3, 6, 13, 17, 18], 6) == 4
assert candidate([10, 5, 3, 15, 20], 5) == 3
assert candidate([18, 1, 3, 6, 13, 17], 6) == 4
| largest_subset |
621 | from typing import List
def increment_numerics(test_list: List[str], K: int) -> List[str]:
""" Increment the numeric values in the given strings by K.
>>> increment_numerics(["MSM", "234", "is", "98", "123", "best", "4"], 6)
['MSM', '240', 'is', '104', '129', 'best', '10']
>>> increment_numerics(["Dart", "356", "is", "88", "169", "Super", "6"], 12)
['Dart', '368', 'is', '100', '181', 'Super', '18']
"""
| return [str(int(ele) + K) if ele.isdigit() else ele for ele in test_list]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(["MSM", "234", "is", "98", "123", "best", "4"], 6) == ['MSM', '240', 'is', '104', '129', 'best', '10']
assert candidate(["Dart", "356", "is", "88", "169", "Super", "6"], 12) == ['Dart', '368', 'is', '100', '181', 'Super', '18']
assert candidate(["Flutter", "451", "is", "44", "96", "Magnificent", "12"], 33) == ['Flutter', '484', 'is', '77', '129', 'Magnificent', '45']
| increment_numerics |
622 | def get_median(arr1, arr2, n):
"""Find the median of two sorted arrays of the same size.
>>> get_median([1, 12, 15, 26, 38], [2, 13, 17, 30, 45], 5)
16.0
>>> get_median([2, 4, 8, 9], [7, 13, 19, 28], 4)
8.5
>>> get_median([3, 6, 14, 23, 36, 42], [2, 18, 27, 39, 49, 55], 6)
25.0
"""
| i = 0
j = 0
m1 = -1
m2 = -1
count = 0
while count < n + 1:
count += 1
if i == n:
m1 = m2
m2 = arr2[0]
break
elif j == n:
m1 = m2
m2 = arr1[0]
break
if arr1[i] <= arr2[j]:
m1 = m2
m2 = arr1[i]
i += 1
else:
m1 = m2
m2 = arr2[j]
j += 1
return (m1 + m2)/2
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 12, 15, 26, 38], [2, 13, 17, 30, 45], 5) == 16.0
assert candidate([2, 4, 8, 9], [7, 13, 19, 28], 4) == 8.5
assert candidate([3, 6, 14, 23, 36, 42], [2, 18, 27, 39, 49, 55], 6) == 25.0
| get_median |
HumanEval\/623 | from typing import List
def nth_nums(nums: List[int], n: int) -> List[int]:
""" Find the n-th power of individual elements in a list using lambda function.
>>> nth_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
>>> nth_nums([10, 20, 30], 3)
[1000, 8000, 27000]
>>> nth_nums([12, 15], 5)
[248832, 759375]
"""
| return list(map(lambda x: x ** n, nums))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2) == [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
assert candidate([10, 20, 30], 3) == [1000, 8000, 27000]
assert candidate([12, 15], 5) == [248832, 759375]
| nth_nums |
HumanEval\/624 | def is_upper(string: str) -> str:
""" Convert the given string to upper case.
>>> is_upper("person")
'PERSON'
>>> is_upper("final")
'FINAL'
>>> is_upper("Valid")
'VALID'
"""
| return string.upper()
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("person") == 'PERSON'
assert candidate("final") == 'FINAL'
assert candidate("Valid") == 'VALID'
| is_upper |
HumanEval\/625 | from typing import List
def swap_List(newList: List[int]) -> List[int]:
""" Interchange first and last elements in a given list
>>> swap_List([1,2,3])
[3,2,1]
>>> swap_List([1,2,3,4,4])
[4,2,3,4,1]
>>> swap_List([4,5,6])
[6,5,4]
"""
| size = len(newList)
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp
return newList
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,2,3]) == [3,2,1]
assert candidate([1,2,3,4,4]) == [4,2,3,4,1]
assert candidate([4,5,6]) == [6,5,4]
| swap_List |
HumanEval\/626 | def triangle_area(r: float) -> float:
""" Calculate the area of the largest triangle that can be inscribed in a semicircle of radius r.
>>> triangle_area(0)
0
>>> triangle_area(-1)
-1
>>> triangle_area(2)
2.0
"""
| if r < 0:
return -1
return r * r / 2
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(0) == 0
assert candidate(-1) == -1
assert candidate(2) == 2.0
| triangle_area |
HumanEval\/627 | def find_First_Missing(array, start, end):
"""Find the smallest missing number from the given sorted array.
>>> find_First_Missing([0, 1, 2, 3], 0, 3)
4
>>> find_First_Missing([0, 1, 2, 6, 9], 0, 4)
3
>>> find_First_Missing([2, 3, 5, 8, 9], 0, 4)
0
"""
| if (start > end):
return end + 1
if (start != array[start]):
return start
mid = int((start + end) / 2)
if (array[mid] == mid):
return find_First_Missing(array, mid + 1, end)
return find_First_Missing(array, start, mid)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([0, 1, 2, 3], 0, 3) == 4
assert candidate([0, 1, 2, 6, 9], 0, 4) == 3
assert candidate([2, 3, 5, 8, 9], 0, 4) == 0
| find_First_Missing |
HumanEval\/628 | def replace_spaces(string: str) -> str:
""" Replace all spaces in the given string with '%20'.
>>> replace_spaces('My Name is Dawood')
'My%20Name%20is%20Dawood'
>>> replace_spaces('I am a Programmer')
'I%20am%20a%20Programmer'
>>> replace_spaces('I love Coding')
'I%20love%20Coding'
"""
| string = string.strip()
return string.replace(' ', '%20')
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('My Name is Dawood') == 'My%20Name%20is%20Dawood'
assert candidate('I am a Programmer') == 'I%20am%20a%20Programmer'
assert candidate('I love Coding') == 'I%20love%20Coding'
| replace_spaces |
HumanEval\/629 | from typing import List, Union
def Split(lst: List[Union[int, float]]) -> List[int]:
""" Find even numbers from a mixed list
>>> Split([1, 2, 3, 4, 5])
[2, 4]
>>> Split([4, 5, 6, 7, 8, 0, 1])
[4, 6, 8, 0]
>>> Split([8, 12, 15, 19])
[8, 12]
"""
| ev_li = []
for i in lst:
if isinstance(i, int) and i % 2 == 0:
ev_li.append(i)
return ev_li
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 2, 3, 4, 5]) == [2, 4]
assert candidate([4, 5, 6, 7, 8, 0, 1]) == [4, 6, 8, 0]
assert candidate([8, 12, 15, 19]) == [8, 12]
| Split |
HumanEval\/630 | from typing import List, Tuple
def get_coordinates(test_tup: Tuple[int, int]) -> List[List[int]]:
""" Extract all the adjacent coordinates of the given coordinate tuple.
>>> get_coordinates((3, 4))
[[2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5]]
>>> get_coordinates((4, 5))
[[3, 4], [3, 5], [3, 6], [4, 4], [4, 5], [4, 6], [5, 4], [5, 5], [5, 6]]
"""
| def adjac(ele, sub=[]):
if not ele:
yield sub
else:
yield from [idx for j in range(ele[0] - 1, ele[0] + 2)
for idx in adjac(ele[1:], sub + [j])]
res = list(adjac(test_tup))
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate((3, 4)) == [[2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5]]
assert candidate((4, 5)) == [[3, 4], [3, 5], [3, 6], [4, 4], [4, 5], [4, 6], [5, 4], [5, 5], [5, 6]]
assert candidate((5, 6)) == [[4, 5], [4, 6], [4, 7], [5, 5], [5, 6], [5, 7], [6, 5], [6, 6], [6, 7]]
| get_coordinates |
HumanEval\/631 | import re
def replace_spaces(text: str) -> str:
""" Replace whitespaces with an underscore and vice versa in a given string using regex.
>>> replace_spaces('Jumanji The Jungle')
'Jumanji_The_Jungle'
>>> replace_spaces('The Avengers')
'The_Avengers'
>>> replace_spaces('Fast and Furious')
'Fast_and_Furious'
"""
| text = re.sub(r' ', '_', text)
text = re.sub(r'_', ' ', text)
return text
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('Jumanji The Jungle') == 'Jumanji_The_Jungle'
assert candidate('The Avengers') == 'The_Avengers'
assert candidate('Fast and Furious') == 'Fast_and_Furious'
| replace_spaces |
HumanEval\/632 | from typing import List
def move_zero(num_list: List[int]) -> List[int]:
""" Move all zeroes to the end of the given list
>>> move_zero([1,0,2,0,3,4])
[1,2,3,4,0,0]
>>> move_zero([2,3,2,0,0,4,0,5,0])
[2,3,2,4,5,0,0,0,0]
>>> move_zero([0,1,0,1,1])
[1,1,1,0,0]
"""
| a = [0 for i in range(num_list.count(0))]
x = [i for i in num_list if i != 0]
x.extend(a)
return x
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,0,2,0,3,4]) == [1,2,3,4,0,0]
assert candidate([2,3,2,0,0,4,0,5,0]) == [2,3,2,4,5,0,0,0,0]
assert candidate([0,1,0,1,1]) == [1,1,1,0,0]
| move_zero |
HumanEval\/633 | from typing import List
def pair_OR_Sum(arr: List[int], n: int) -> int:
""" Write a python function to find the sum of xor of all pairs of numbers in the given array.
>>> pair_OR_Sum([5,9,7,6], 4)
47
>>> pair_OR_Sum([7,3,5], 3)
12
>>> pair_OR_Sum([7,3], 2)
4
"""
| ans = 0
for i in range(0, n):
for j in range(i + 1, n):
ans = ans + (arr[i] ^ arr[j])
return ans
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([5,9,7,6], 4) == 47
assert candidate([7,3,5], 3) == 12
assert candidate([7,3], 2) == 4
| pair_OR_Sum |
HumanEval\/634 | def even_Power_Sum(n: int) -> int:
"""Calculate the sum of the fourth power of the first n even natural numbers.
>>> even_Power_Sum(2)
272
>>> even_Power_Sum(3)
1568
>>> even_Power_Sum(4)
5664
"""
| sum = 0
for i in range(1, n + 1):
j = 2 * i
sum += j ** 4
return sum
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(2) == 272
assert candidate(3) == 1568
assert candidate(4) == 5664
| even_Power_Sum |
HumanEval\/635 | import heapq as hq
def heap_sort(iterable):
""" Push all values into a heap and then pop off the smallest values one at a time.
>>> heap_sort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> heap_sort([25, 35, 22, 85, 14, 65, 75, 25, 58])
[14, 22, 25, 25, 35, 58, 65, 75, 85]
>>> heap_sort([7, 1, 9, 5])
[1, 5, 7, 9]
"""
| h = []
for value in iterable:
hq.heappush(h, value)
return [hq.heappop(h) for i in range(len(h))]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 3, 5, 7, 9, 2, 4, 6, 8, 0]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
assert candidate([25, 35, 22, 85, 14, 65, 75, 25, 58]) == [14, 22, 25, 25, 35, 58, 65, 75, 85]
assert candidate([7, 1, 9, 5]) == [1, 5, 7, 9]
| heap_sort |
HumanEval\/636 | def Check_Solution(a: int, b: int, c: int) -> str:
""" Check if roots of a quadratic equation are reciprocal of each other.
>>> Check_Solution(2, 0, 2)
'Yes'
>>> Check_Solution(2, -5, 2)
'Yes'
>>> Check_Solution(1, 2, 3)
'No'
"""
| if a == c:
return "Yes"
else:
return "No"
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(2, 0, 2) == 'Yes'
assert candidate(2, -5, 2) == 'Yes'
assert candidate(1, 2, 3) == 'No'
| Check_Solution |
HumanEval\/637 | def noprofit_noloss(actual_cost: int, sale_amount: int) -> bool:
""" Check whether the given amount has no profit and no loss
>>> noprofit_noloss(1500, 1200)
False
>>> noprofit_noloss(100, 100)
True
>>> noprofit_noloss(2000, 5000)
False
"""
| return sale_amount == actual_cost
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(1500, 1200) == False
assert candidate(100, 100) == True
assert candidate(2000, 5000) == False
| noprofit_noloss |
HumanEval\/638 | import math
def wind_chill(v: float, t: float) -> int:
""" Calculate the wind chill index given the wind speed v (in km/h) and the temperature t (in degrees Celsius).
>>> wind_chill(120, 35)
40
>>> wind_chill(40, 70)
86
>>> wind_chill(10, 100)
116
"""
| windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16)
return int(round(windchill, 0))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(120, 35) == 40
assert candidate(40, 70) == 86
assert candidate(10, 100) == 116
| wind_chill |
HumanEval\/639 | from typing import List
def sample_nam(sample_names: List[str]) -> int:
""" Write a function to sum the length of the names of a given list of names after removing the names that start with a lowercase letter.
>>> sample_nam(['sally', 'Dylan', 'rebecca', 'Diana', 'Joanne', 'keith'])
16
>>> sample_nam(["php", "res", "Python", "abcd", "Java", "aaa"])
10
>>> sample_nam(["abcd", "Python", "abba", "aba"])
6
"""
| sample_names = list(filter(lambda el: el[0].isupper() and el[1:].islower(), sample_names))
return len(''.join(sample_names))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(['sally', 'Dylan', 'rebecca', 'Diana', 'Joanne', 'keith']) == 16
assert candidate(["php", "res", "Python", "abcd", "Java", "aaa"]) == 10
assert candidate(["abcd", "Python", "abba", "aba"]) == 6
| sample_nam |
HumanEval\/640 | import re
from typing import List
def remove_parenthesis(items: List[str]) -> str:
""" Remove the parenthesis area in a string
>>> remove_parenthesis(["python (chrome)"])
'python'
>>> remove_parenthesis(["string(.abc)"])
'string'
>>> remove_parenthesis(["alpha(num)"])
'alpha'
"""
| return re.sub(r" ?\([^)]+\)", "", items[0])
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(["python (chrome)"]) == 'python'
assert candidate(["string(.abc)"]) == 'string'
assert candidate(["alpha(num)"]) == 'alpha'
| remove_parenthesis |
HumanEval\/641 | def is_nonagonal(n: int) -> int:
""" Calculate the nth nonagonal number
>>> is_nonagonal(10)
325
>>> is_nonagonal(15)
750
>>> is_nonagonal(18)
1089
"""
| return int(n * (7 * n - 5) / 2)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(10) == 325
assert candidate(15) == 750
assert candidate(18) == 1089
| is_nonagonal |
HumanEval\/642 | def remove_similar_row(test_list):
"""Remove similar rows from the given tuple matrix.
>>> remove_similar_row([[(4, 5), (3, 2)], [(2, 2), (4, 6)], [(3, 2), (4, 5)]] )
{((2, 2), (4, 6)), ((3, 2), (4, 5))}
>>> remove_similar_row([[(5, 6), (4, 3)], [(3, 3), (5, 7)], [(4, 3), (5, 6)]] )
{((4, 3), (5, 6)), ((3, 3), (5, 7))}
>>> remove_similar_row([[(6, 7), (5, 4)], [(4, 4), (6, 8)], [(5, 4), (6, 7)]] )
{((4, 4), (6, 8)), ((5, 4), (6, 7))}
"""
| res = set(sorted([tuple(sorted(set(sub))) for sub in test_list]))
return (res)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([[(4, 5), (3, 2)], [(2, 2), (4, 6)], [(3, 2), (4, 5)]]) == {((2, 2), (4, 6)), ((3, 2), (4, 5))}
assert candidate([[(5, 6), (4, 3)], [(3, 3), (5, 7)], [(4, 3), (5, 6)]]) == {((4, 3), (5, 6)), ((3, 3), (5, 7))}
assert candidate([[(6, 7), (5, 4)], [(4, 4), (6, 8)], [(5, 4), (6, 7)]]) == {((4, 4), (6, 8)), ((5, 4), (6, 7))}
| remove_similar_row |
HumanEval\/643 | import re
def text_match_wordz_middle(text: str) -> str:
""" Match a word containing 'z', not at the start or end of the word.
>>> text_match_wordz_middle("pythonzabc.")
'Found a match!'
>>> text_match_wordz_middle("xyzabc.")
'Found a match!'
>>> text_match_wordz_middle(" lang .")
'Not matched!'
"""
| patterns = '\\Bz\\B'
if re.search(patterns, text):
return 'Found a match!'
else:
return 'Not matched!'
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("pythonzabc.") == 'Found a match!'
assert candidate("xyzabc.") == 'Found a match!'
assert candidate(" lang .") == 'Not matched!'
| text_match_wordz_middle |
HumanEval\/644 | from typing import List
def reverse_Array_Upto_K(input: List[int], k: int) -> List[int]:
""" Reverse an array up to a given position k
>>> reverse_Array_Upto_K([1, 2, 3, 4, 5, 6], 4)
[4, 3, 2, 1, 5, 6]
>>> reverse_Array_Upto_K([4, 5, 6, 7], 2)
[5, 4, 6, 7]
>>> reverse_Array_Upto_K([9, 8, 7, 6, 5], 3)
[7, 8, 9, 6, 5]
"""
| return (input[k-1::-1] + input[k:])
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 2, 3, 4, 5, 6], 4) == [4, 3, 2, 1, 5, 6]
assert candidate([4, 5, 6, 7], 2) == [5, 4, 6, 7]
assert candidate([9, 8, 7, 6, 5], 3) == [7, 8, 9, 6, 5]
| reverse_Array_Upto_K |
HumanEval\/645 | def find_k_product(test_list, K):
"""Find the product of the kth index in the given tuples.
>>> find_k_product([(5, 6, 7), (1, 3, 5), (8, 9, 19)], 2)
665
>>> find_k_product([(6, 7, 8), (2, 4, 6), (9, 10, 20)], 1)
280
>>> find_k_product([(7, 8, 9), (3, 5, 7), (10, 11, 21)], 0)
210
"""
def get_product(val):
res = 1
for ele in val:
res *= ele
return res
res = get_product([sub[K] for sub in test_list])
return res
| def get_product(val):
res = 1
for ele in val:
res *= ele
return res
res = get_product([sub[K] for sub in test_list])
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([(5, 6, 7), (1, 3, 5), (8, 9, 19)], 2) == 665
assert candidate([(6, 7, 8), (2, 4, 6), (9, 10, 20)], 1) == 280
assert candidate([(7, 8, 9), (3, 5, 7), (10, 11, 21)], 0) == 210
| find_k_product |
HumanEval\/646 | def No_of_cubes(N: int, K: int) -> int:
""" Calculate the number of cubes of size K in a cube of size N.
>>> No_of_cubes(2, 1)
8
>>> No_of_cubes(5, 2)
64
>>> No_of_cubes(1, 1)
1
"""
| No = (N - K + 1)
return No ** 3
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(2, 1) == 8
assert candidate(5, 2) == 64
assert candidate(1, 1) == 1
| No_of_cubes |
HumanEval\/647 | import re
def split_upperstring(text: str) -> list:
""" Split a string at uppercase letters.
>>> split_upperstring("PythonProgramLanguage")
['Python', 'Program', 'Language']
>>> split_upperstring("PythonProgram")
['Python', 'Program']
>>> split_upperstring("ProgrammingLanguage")
['Programming', 'Language']
"""
| return re.findall('[A-Z][^A-Z]*', text)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("PythonProgramLanguage") == ['Python', 'Program', 'Language']
assert candidate("PythonProgram") == ['Python', 'Program']
assert candidate("ProgrammingLanguage") == ['Programming', 'Language']
| split_upperstring |
HumanEval\/648 | from typing import List
def exchange_elements(lst: List[int]) -> List[int]:
""" Exchange the position of every n-th value with (n+1)th value in a given list.
>>> exchange_elements([0,1,2,3,4,5])
[1, 0, 3, 2, 5, 4]
>>> exchange_elements([5,6,7,8,9,10])
[6, 5, 8, 7, 10, 9]
"""
| from itertools import zip_longest, chain
return list(chain.from_iterable(zip_longest(lst[1::2], lst[::2])))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([0,1,2,3,4,5]) == [1, 0, 3, 2, 5, 4]
assert candidate([5,6,7,8,9,10]) == [6, 5, 8, 7, 10, 9]
assert candidate([25,35,45,55,75,95]) == [35, 25, 55, 45, 95, 75]
| exchange_elements |
HumanEval\/649 | from typing import List
def sum_Range_list(nums: List[int], m: int, n: int) -> int:
""" Calculate the sum of the numbers in a list between the indices of a specified range.
>>> sum_Range_list([2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12], 8, 10)
29
>>> sum_Range_list([1, 2, 3, 4, 5], 1, 2)
5
>>> sum_Range_list([1, 0, 1, 2, 5, 6], 4, 5)
11
"""
| sum_range = 0
for i in range(m, n+1, 1):
sum_range += nums[i]
return sum_range
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12], 8, 10) == 29
assert candidate([1, 2, 3, 4, 5], 1, 2) == 5
assert candidate([1, 0, 1, 2, 5, 6], 4, 5) == 11
| sum_Range_list |
HumanEval\/650 | def are_Equal(arr1: list, arr2: list, n: int, m: int) -> bool:
""" Check whether the given two arrays are equal or not.
>>> are_Equal([1,2,3],[3,2,1],3,3)
True
>>> are_Equal([1,1,1],[2,2,2],3,3)
False
>>> are_Equal([8,9],[4,5,6],2,3)
False
"""
| if n != m:
return False
arr1.sort()
arr2.sort()
for i in range(n):
if arr1[i] != arr2[i]:
return False
return True
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,2,3],[3,2,1],3,3) == True
assert candidate([1,1,1],[2,2,2],3,3) == False
assert candidate([8,9],[4,5,6],2,3) == False
| are_Equal |
HumanEval\/651 | def check_subset(test_tup1: tuple, test_tup2: tuple) -> bool:
""" Check if one tuple is a subset of another tuple
>>> check_subset((10, 4, 5, 6), (5, 10))
True
>>> check_subset((1, 2, 3, 4), (5, 6))
False
>>> check_subset((7, 8, 9, 10), (10, 8))
True
"""
| return set(test_tup2).issubset(test_tup1)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate((10, 4, 5, 6), (5, 10)) == True
assert candidate((1, 2, 3, 4), (5, 6)) == False
assert candidate((7, 8, 9, 10), (10, 8)) == True
| check_subset |
HumanEval\/652 | def matrix_to_list(test_list):
""" Flatten the given tuple matrix into the tuple list with each tuple representing each column.
>>> matrix_to_list([[(4, 5), (7, 8)], [(10, 13), (18, 17)], [(0, 4), (10, 1)]])
'[(4, 7, 10, 18, 0, 10), (5, 8, 13, 17, 4, 1)]'
"""
| temp = [ele for sub in test_list for ele in sub]
res = list(zip(*temp))
return str(res)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([[(4, 5), (7, 8)], [(10, 13), (18, 17)], [(0, 4), (10, 1)]]) == '[(4, 7, 10, 18, 0, 10), (5, 8, 13, 17, 4, 1)]'
assert candidate([[(5, 6), (8, 9)], [(11, 14), (19, 18)], [(1, 5), (11, 2)]]) == '[(5, 8, 11, 19, 1, 11), (6, 9, 14, 18, 5, 2)]'
assert candidate([[(6, 7), (9, 10)], [(12, 15), (20, 21)], [(23, 7), (15, 8)]]) == '[(6, 9, 12, 20, 23, 15), (7, 10, 15, 21, 7, 8)]'
| matrix_to_list |
HumanEval\/653 | from collections import defaultdict
def grouping_dictionary(l):
""" Group a sequence of key-value pairs into a dictionary of lists
>>> grouping_dictionary([('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)])
{'yellow': [1, 3], 'blue': [2, 4], 'red': [1]}
"""
| d = defaultdict(list)
for k, v in l:
d[k].append(v)
return d
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]) == {'yellow': [1, 3], 'blue': [2, 4], 'red': [1]}
assert candidate([('yellow', 10), ('blue', 20), ('yellow', 30), ('blue', 40), ('red', 10)]) == {'yellow': [10, 30], 'blue': [20, 40], 'red': [10]}
assert candidate([('yellow', 15), ('blue', 25), ('yellow', 35), ('blue', 45), ('red', 15)]) == {'yellow': [15, 35], 'blue': [25, 45], 'red': [15]}
| grouping_dictionary |
HumanEval\/654 |
def rectangle_perimeter(l: int, b: int) -> int:
""" Calculate the perimeter of a rectangle given its length and breadth.
>>> rectangle_perimeter(10, 20)
60
>>> rectangle_perimeter(10, 5)
30
>>> rectangle_perimeter(4, 2)
12
"""
| return 2 * (l + b)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(10, 20) == 60
assert candidate(10, 5) == 30
assert candidate(4, 2) == 12
| rectangle_perimeter |
HumanEval\/655 | def fifth_Power_Sum(n: int) -> int:
""" Calculate the sum of the fifth power of n natural numbers
>>> fifth_Power_Sum(2)
33
>>> fifth_Power_Sum(4)
1300
>>> fifth_Power_Sum(3)
276
"""
| sm = 0
for i in range(1, n+1):
sm += i**5
return sm
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(2) == 33
assert candidate(4) == 1300
assert candidate(3) == 276
| fifth_Power_Sum |
HumanEval\/656 | def find_Min_Sum(a: List[int], b: List[int], n: int) -> int:
""" Write a python function to find the minimum sum of absolute differences of two arrays.
>>> find_Min_Sum([3,2,1],[2,1,3],3)
0
>>> find_Min_Sum([1,2,3],[4,5,6],3)
9
>>> find_Min_Sum([4,1,8,7],[2,3,6,5],4)
6
"""
| a.sort()
b.sort()
sum = 0
for i in range(n):
sum = sum + abs(a[i] - b[i])
return sum
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([3,2,1],[2,1,3],3) == 0
assert candidate([1,2,3],[4,5,6],3) == 9
assert candidate([4,1,8,7],[2,3,6,5],4) == 6
| find_Min_Sum |
HumanEval\/657 | import math
def first_Digit(n: int) -> int:
"""Find the first digit in factorial of a given number.
>>> first_Digit(5)
1
>>> first_Digit(10)
3
>>> first_Digit(7)
5
"""
| fact = 1
for i in range(2, n + 1):
fact *= i
while fact % 10 == 0:
fact //= 10
while fact >= 10:
fact //= 10
return fact
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(5) == 1
assert candidate(10) == 3
assert candidate(7) == 5
| first_Digit |
HumanEval\/658 | from typing import List
def max_occurrences(list1: List[int]) -> int:
""" Find the item with maximum occurrences in a given list
>>> max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,4,6,9,1,2])
2
>>> max_occurrences([1, 3,5, 7,1, 3,13, 15, 17,5, 7,9,1, 11])
1
>>> max_occurrences([1, 2, 3,2, 4, 5,1, 1, 1])
1
"""
| max_val = 0
result = list1[0]
for i in list1:
occu = list1.count(i)
if occu > max_val:
max_val = occu
result = i
return result
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,4,6,9,1,2]) == 2
assert candidate([1, 3,5, 7,1, 3,13, 15, 17,5, 7,9,1, 11]) == 1
assert candidate([1, 2, 3,2, 4, 5,1, 1, 1]) == 1
| max_occurrences |
HumanEval\/659 | from typing import List
def Repeat(x: List[int]) -> List[int]:
""" Return a list of duplicate integers from the input list.
>>> Repeat([10, 20, 30, 20, 20, 30, 40, 50, -20, 60, 60, -20, -20])
[20, 30, -20, 60]
>>> Repeat([-1, 1, -1, 8])
[-1]
>>> Repeat([1, 2, 3, 1, 2])
[1, 2]
"""
| _size = len(x)
repeated = []
for i in range(_size):
k = i + 1
for j in range(k, _size):
if x[i] == x[j] and x[i] not in repeated:
repeated.append(x[i])
return repeated
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([10, 20, 30, 20, 20, 30, 40, 50, -20, 60, 60, -20, -20]) == [20, 30, -20, 60]
assert candidate([-1, 1, -1, 8]) == [-1]
assert candidate([1, 2, 3, 1, 2]) == [1, 2]
| Repeat |
HumanEval\/660 | def find_Points(l1: int, r1: int, l2: int, r2: int) -> tuple:
""" Choose points from two ranges such that no point lies in both the ranges.
>>> find_Points(5, 10, 1, 5)
(1, 10)
>>> find_Points(3, 5, 7, 9)
(3, 9)
>>> find_Points(1, 5, 2, 8)
(1, 8)
"""
| x = min(l1, l2) if (l1 != l2) else -1
y = max(r1, r2) if (r1 != r2) else -1
return (x, y)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(5, 10, 1, 5) == (1, 10)
assert candidate(3, 5, 7, 9) == (3, 9)
assert candidate(1, 5, 2, 8) == (1, 8)
| find_Points |
HumanEval\/661 | from typing import List
def max_sum_of_three_consecutive(arr: List[int], n: int) -> int:
""" Write a function to find the maximum sum that can be formed which has no three consecutive elements present.
>>> max_sum_of_three_consecutive([100, 1000, 100, 1000, 1], 5)
2101
>>> max_sum_of_three_consecutive([3000, 2000, 1000, 3, 10], 5)
5013
>>> max_sum_of_three_consecutive([1, 2, 3, 4, 5, 6, 7, 8], 8)
27
"""
| sum = [0 for k in range(n)]
if n >= 1:
sum[0] = arr[0]
if n >= 2:
sum[1] = arr[0] + arr[1]
if n > 2:
sum[2] = max(sum[1], max(arr[1] + arr[2], arr[0] + arr[2]))
for i in range(3, n):
sum[i] = max(max(sum[i-1], sum[i-2] + arr[i]), arr[i] + arr[i-1] + sum[i-3])
return sum[n-1]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([100, 1000, 100, 1000, 1], 5) == 2101
assert candidate([3000, 2000, 1000, 3, 10], 5) == 5013
assert candidate([1, 2, 3, 4, 5, 6, 7, 8], 8) == 27
| max_sum_of_three_consecutive |
HumanEval\/662 | def sorted_dict(dict1):
""" Sorts each list in the dictionary.
>>> sorted_dict({'n1': [2, 3, 1], 'n2': [5, 1, 2], 'n3': [3, 2, 4]})
{'n1': [1, 2, 3], 'n2': [1, 2, 5], 'n3': [2, 3, 4]}
"""
| sorted_dict = {x: sorted(y) for x, y in dict1.items()}
return sorted_dict
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate({'n1': [2, 3, 1], 'n2': [5, 1, 2], 'n3': [3, 2, 4]}) == {'n1': [1, 2, 3], 'n2': [1, 2, 5], 'n3': [2, 3, 4]}
assert candidate({'n1': [25,37,41], 'n2': [41,54,63], 'n3': [29,38,93]}) == {'n1': [25, 37, 41], 'n2': [41, 54, 63], 'n3': [29, 38, 93]}
assert candidate({'n1': [58,44,56], 'n2': [91,34,58], 'n3': [100,200,300]}) == {'n1': [44, 56, 58], 'n2': [34, 58, 91], 'n3': [100, 200, 300]}
| sorted_dict |
HumanEval\/663 | import sys
def find_max_val(n: int, x: int, y: int) -> int:
""" Find the largest possible value of k such that k modulo x is y.
>>> find_max_val(15, 10, 5)
15
>>> find_max_val(187, 10, 5)
185
>>> find_max_val(16, 11, 1)
12
"""
| ans = -sys.maxsize
for k in range(n + 1):
if (k % x == y):
ans = max(ans, k)
return (ans if (ans >= 0 and ans <= n) else -1)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(15, 10, 5) == 15
assert candidate(187, 10, 5) == 185
assert candidate(16, 11, 1) == 12
| find_max_val |
HumanEval\/664 | def average_Even(n: int) -> int:
""" Calculate the average of even numbers up to a given even number n.
>>> average_Even(2)
2
>>> average_Even(4)
3
>>> average_Even(100)
51
"""
| if n % 2 != 0:
return "Invalid Input"
sm = 0
count = 0
while n >= 2:
count += 1
sm += n
n -= 2
return sm // count
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(2) == 2
assert candidate(4) == 3
assert candidate(100) == 51
| average_Even |
HumanEval\/665 | from typing import List
def move_last(num_list: List[int]) -> List[int]:
""" Shift first element to the end of given list
>>> move_last([1,2,3,4])
[2,3,4,1]
>>> move_last([2,3,4,1,5,0])
[3,4,1,5,0,2]
>>> move_last([5,4,3,2,1])
[4,3,2,1,5]
"""
| return num_list[1:] + num_list[:1]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1,2,3,4]) == [2,3,4,1]
assert candidate([2,3,4,1,5,0]) == [3,4,1,5,0,2]
assert candidate([5,4,3,2,1]) == [4,3,2,1,5]
| move_last |
HumanEval\/666 | def count_char(string: str, char: str) -> int:
""" Count occurrence of a character in a string.
>>> count_char("Python", 'o')
1
>>> count_char("little", 't')
2
>>> count_char("assert", 's')
2
"""
| count = 0
for i in range(len(string)):
if(string[i] == char):
count = count + 1
return count
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("Python", 'o') == 1
assert candidate("little", 't') == 2
assert candidate("assert", 's') == 2
| count_char |
HumanEval\/667 | def Check_Vow(string: str, vowels: str) -> int:
""" Count number of vowels in the string.
>>> Check_Vow('corner', 'AaEeIiOoUu')
2
>>> Check_Vow('valid', 'AaEeIiOoUu')
2
>>> Check_Vow('true', 'AaEeIiOoUu')
2
"""
| final = [each for each in string if each in vowels]
return len(final)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('corner', 'AaEeIiOoUu') == 2
assert candidate('valid', 'AaEeIiOoUu') == 2
assert candidate('true', 'AaEeIiOoUu') == 2
| Check_Vow |
HumanEval\/668 | import re
def replace(string: str, char: str) -> str:
""" Replace multiple occurrences of a character by a single occurrence.
>>> replace('peep', 'e')
'pep'
>>> replace('Greek', 'e')
'Grek'
>>> replace('Moon', 'o')
'Mon'
"""
| pattern = char + '{2,}'
string = re.sub(pattern, char, string)
return string
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('peep', 'e') == 'pep'
assert candidate('Greek', 'e') == 'Grek'
assert candidate('Moon', 'o') == 'Mon'
| replace |
HumanEval\/669 | import re
def check_IP(Ip: str) -> str:
"""Check whether the given IP address is valid or not using regex.
>>> check_IP("192.168.0.1")
'Valid IP address'
>>> check_IP("366.1.2.2")
'Invalid IP address'
"""
| regex = r'^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$'
if re.search(regex, Ip):
return "Valid IP address"
else:
return "Invalid IP address"
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("192.168.0.1") == 'Valid IP address'
assert candidate("110.234.52.124") == 'Valid IP address'
assert candidate("366.1.2.2") == 'Invalid IP address'
| check_IP |
HumanEval\/670 | from typing import List
def decreasing_trend(nums: List[int]) -> bool:
""" Check whether a sequence of numbers has a decreasing trend or not.
>>> decreasing_trend([-4, -3, -2, -1])
True
>>> decreasing_trend([1, 2, 3])
True
>>> decreasing_trend([3, 2, 1])
False
"""
| return nums == sorted(nums, reverse=True)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([-4, -3, -2, -1]) == True
assert candidate([1, 2, 3]) == True
assert candidate([3, 2, 1]) == False
| decreasing_trend |
HumanEval\/671 | import math
def get_Pos_Of_Right_most_Set_Bit(n):
return int(math.log2(n & -n) + 1)
def set_Right_most_Unset_Bit(n):
""" Set the right most unset bit in the binary representation of n.
>>> set_Right_most_Unset_Bit(21)
23
>>> set_Right_most_Unset_Bit(11)
15
>>> set_Right_most_Unset_Bit(15)
15
"""
if n == 0:
return 1
if (n & (n + 1)) == 0:
return n
pos = get_Pos_Of_Right_most_Set_Bit(~n)
return (1 << (pos - 1)) | n
| if n == 0:
return 1
if (n & (n + 1)) == 0:
return n
pos = get_Pos_Of_Right_most_Set_Bit(~n)
return (1 << (pos - 1)) | n
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(21) == 23
assert candidate(11) == 15
assert candidate(15) == 15
| set_Right_most_Unset_Bit |
HumanEval\/672 | def max_of_three(num1: int, num2: int, num3: int) -> int:
""" Find the maximum of three numbers
>>> max_of_three(10, 20, 30)
30
>>> max_of_three(55, 47, 39)
55
>>> max_of_three(10, 49, 30)
49
"""
| if (num1 >= num2) and (num1 >= num3):
return num1
elif (num2 >= num1) and (num2 >= num3):
return num2
else:
return num3
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(10, 20, 30) == 30
assert candidate(55, 47, 39) == 55
assert candidate(10, 49, 30) == 49
| max_of_three |
HumanEval\/673 | from typing import List
def convert(lst: List[int]) -> int:
""" Convert a list of multiple integers into a single integer.
>>> convert([1, 2, 3])
123
>>> convert([4, 5, 6])
456
"""
| s = [str(i) for i in lst]
res = int("".join(s))
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 2, 3]) == 123
assert candidate([4, 5, 6]) == 456
assert candidate([7, 8, 9]) == 789
| convert |
HumanEval\/674 | from collections import OrderedDict
def remove_duplicate(string: str) -> str:
""" Remove duplicate words from a given string using collections module.
>>> remove_duplicate("Python Exercises Practice Solution Exercises")
'Python Exercises Practice Solution'
>>> remove_duplicate("Python Exercises Practice Solution Python")
'Python Exercises Practice Solution'
>>> remove_duplicate("Python Exercises Practice Solution Practice")
'Python Exercises Practice Solution'
"""
| result = ' '.join(OrderedDict((w,w) for w in string.split()).keys())
return result
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("Python Exercises Practice Solution Exercises") == "Python Exercises Practice Solution"
assert candidate("Python Exercises Practice Solution Python") == "Python Exercises Practice Solution"
assert candidate("Python Exercises Practice Solution Practice") == "Python Exercises Practice Solution"
| remove_duplicate |
HumanEval\/675 | def sum_nums(x: int, y: int, m: int, n: int) -> int:
""" Add two integers and return 20 if the sum is within the given range.
>>> sum_nums(2, 10, 11, 20)
20
>>> sum_nums(15, 17, 1, 10)
32
>>> sum_nums(10, 15, 5, 30)
20
"""
| sum_nums = x + y
if sum_nums in range(m, n):
return 20
else:
return sum_nums
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(2, 10, 11, 20) == 20
assert candidate(15, 17, 1, 10) == 32
assert candidate(10, 15, 5, 30) == 20
| sum_nums |
HumanEval\/676 | import re
def remove_extra_char(text1: str) -> str:
""" Remove everything except alphanumeric characters from the given string by using regex.
>>> remove_extra_char('**//Google Android// - 12. ')
'GoogleAndroid12'
>>> remove_extra_char('****//Google Flutter//*** - 36. ')
'GoogleFlutter36'
>>> remove_extra_char('**//Google Firebase// - 478. ')
'GoogleFirebase478'
"""
| pattern = re.compile('[\W_]+')
return pattern.sub('', text1)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('**//Google Android// - 12. ') == 'GoogleAndroid12'
assert candidate('****//Google Flutter//*** - 36. ') == 'GoogleFlutter36'
assert candidate('**//Google Firebase// - 478. ') == 'GoogleFirebase478'
| remove_extra_char |
HumanEval\/677 | def validity_triangle(a: int, b: int, c: int) -> bool:
""" Check if the triangle is valid or not
>>> validity_triangle(60, 50, 90)
False
>>> validity_triangle(45, 75, 60)
True
>>> validity_triangle(30, 50, 100)
True
"""
| total = a + b + c
return total == 180
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(60, 50, 90) == False
assert candidate(45, 75, 60) == True
assert candidate(30, 50, 100) == True
| validity_triangle |
HumanEval\/678 | def remove_spaces(str1: str) -> str:
""" Remove spaces from a given string
>>> remove_spaces("a b c")
'abc'
>>> remove_spaces("1 2 3")
'123'
"""
| return str1.replace(' ', '')
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("a b c") == "abc"
assert candidate("1 2 3") == "123"
assert candidate(" b c") == "bc"
| remove_spaces |
HumanEval\/679 | def access_key(dictionary, key):
""" Access dictionary key��s element by index
>>> access_key({'physics': 80, 'math': 90, 'chemistry': 86}, 0)
'physics'
>>> access_key({'python': 10, 'java': 20, 'C++': 30}, 2)
'C++'
>>> access_key({'program': 15, 'computer': 45}, 1)
'computer'
"""
| return list(dictionary)[key]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate({'physics': 80, 'math': 90, 'chemistry': 86}, 0) == 'physics'
assert candidate({'python': 10, 'java': 20, 'C++': 30}, 2) == 'C++'
assert candidate({'program': 15, 'computer': 45}, 1) == 'computer'
| access_key |
HumanEval\/680 | from typing import List
def increasing_trend(nums: List[int]) -> bool:
""" Check whether a sequence of numbers has an increasing trend or not.
>>> increasing_trend([1, 2, 3, 4])
True
>>> increasing_trend([4, 3, 2, 1])
False
>>> increasing_trend([0, 1, 4, 9])
True
"""
| return sorted(nums) == nums
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 2, 3, 4]) == True
assert candidate([4, 3, 2, 1]) == False
assert candidate([0, 1, 4, 9]) == True
| increasing_trend |
HumanEval\/681 | def smallest_Divisor(n: int) -> int:
""" Find the smallest prime divisor of a number n
>>> smallest_Divisor(10)
2
>>> smallest_Divisor(25)
5
>>> smallest_Divisor(31)
31
"""
| if n % 2 == 0:
return 2
i = 3
while i * i <= n:
if n % i == 0:
return i
i += 2
return n
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(10) == 2
assert candidate(25) == 5
assert candidate(31) == 31
| smallest_Divisor |
HumanEval\/682 | from typing import List
def mul_list(nums1: List[int], nums2: List[int]) -> List[int]:
""" Multiply two lists using map and lambda function.
>>> mul_list([1, 2, 3], [4, 5, 6])
[4, 10, 18]
>>> mul_list([1, 2], [3, 4])
[3, 8]
>>> mul_list([90, 120], [50, 70])
[4500, 8400]
"""
| result = map(lambda x, y: x * y, nums1, nums2)
return list(result)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 2, 3], [4, 5, 6]) == [4, 10, 18]
assert candidate([1, 2], [3, 4]) == [3, 8]
assert candidate([90, 120], [50, 70]) == [4500, 8400]
| mul_list |
HumanEval\/683 | def sum_Square(n: int) -> bool:
""" Check whether the given number can be represented by sum of two squares or not.
>>> sum_Square(25)
True
>>> sum_Square(24)
False
>>> sum_Square(17)
True
"""
| i = 1
while i*i <= n:
j = 1
while j*j <= n:
if i*i + j*j == n:
return True
j += 1
i += 1
return False
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(25) == True
assert candidate(24) == False
assert candidate(17) == True
| sum_Square |
HumanEval\/684 | def count_Char(str, x):
""" Count occurrences of a character in a repeated string.
>>> count_Char("abcac", 'a')
4
>>> count_Char("abca", 'c')
2
>>> count_Char("aba", 'a')
7
"""
| count = 0
for i in range(len(str)):
if (str[i] == x):
count += 1
n = 10
repititions = n // len(str)
count = count * repititions
l = n % len(str)
for i in range(l):
if (str[i] == x):
count += 1
return count
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("abcac", 'a') == 4
assert candidate("abca", 'c') == 2
assert candidate("aba", 'a') == 7
| count_Char |
HumanEval\/685 | def sum_Of_Primes(n: int) -> int:
"""Write a python function to find sum of prime numbers between 1 to n.
>>> sum_Of_Primes(10)
17
>>> sum_Of_Primes(20)
77
>>> sum_Of_Primes(5)
10
"""
| prime = [True] * (n + 1)
p = 2
while p * p <= n:
if prime[p] == True:
i = p * 2
while i <= n:
prime[i] = False
i += p
p += 1
sum = 0
for i in range(2, n + 1):
if prime[i]:
sum += i
return sum
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(10) == 17
assert candidate(20) == 77
assert candidate(5) == 10
| sum_Of_Primes |
HumanEval\/686 | from collections import defaultdict
def freq_element(test_tup):
""" Find the frequency of each element in the given list
>>> freq_element((4, 5, 4, 5, 6, 6, 5, 5, 4))
'{4: 3, 5: 4, 6: 2}'
>>> freq_element((7, 8, 8, 9, 4, 7, 6, 5, 4))
'{7: 2, 8: 2, 9: 1, 4: 2, 6: 1, 5: 1}'
>>> freq_element((1, 4, 3, 1, 4, 5, 2, 6, 2, 7))
'{1: 2, 4: 2, 3: 1, 5: 1, 2: 2, 6: 1, 7: 1}'
"""
| res = defaultdict(int)
for ele in test_tup:
res[ele] += 1
return str(dict(res))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate((4, 5, 4, 5, 6, 6, 5, 5, 4)) == '{4: 3, 5: 4, 6: 2}'
assert candidate((7, 8, 8, 9, 4, 7, 6, 5, 4)) == '{7: 2, 8: 2, 9: 1, 4: 2, 6: 1, 5: 1}'
assert candidate((1, 4, 3, 1, 4, 5, 2, 6, 2, 7)) == '{1: 2, 4: 2, 3: 1, 5: 1, 2: 2, 6: 1, 7: 1}'
| freq_element |
HumanEval\/687 | def recur_gcd(a: int, b: int) -> int:
""" Find the greatest common divisor (gcd) of two integers using recursion.
>>> recur_gcd(12, 14)
2
>>> recur_gcd(13, 17)
1
>>> recur_gcd(9, 3)
3
"""
| low = min(a, b)
high = max(a, b)
if low == 0:
return high
elif low == 1:
return 1
else:
return recur_gcd(low, high % low)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(12, 14) == 2
assert candidate(13, 17) == 1
assert candidate(9, 3) == 3
| recur_gcd |
HumanEval\/688 | import cmath
def len_complex(a: float, b: float) -> float:
""" Calculate the length of a complex number given its real and imaginary parts.
>>> len_complex(3, 4)
5.0
>>> len_complex(9, 10)
13.45362404707371
>>> len_complex(7, 9)
11.40175425099138
"""
| cn = complex(a, b)
length = abs(cn)
return length
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(3, 4) == 5.0
assert candidate(9, 10) == 13.45362404707371
assert candidate(7, 9) == 11.40175425099138
| len_complex |
HumanEval\/689 | def min_jumps(arr, n):
""" Find the minimum number of jumps to reach the end of the array for the given array of integers where each element represents the max number of steps that can be made forward from that element.
>>> min_jumps([1, 3, 6, 1, 0, 9], 6)
3
>>> min_jumps([1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9], 11)
3
>>> min_jumps([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 11)
10
"""
| jumps = [0 for i in range(n)]
if (n == 0) or (arr[0] == 0):
return float('inf')
jumps[0] = 0
for i in range(1, n):
jumps[i] = float('inf')
for j in range(i):
if (i <= j + arr[j]) and (jumps[j] != float('inf')):
jumps[i] = min(jumps[i], jumps[j] + 1)
break
return jumps[n-1]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 3, 6, 1, 0, 9], 6) == 3
assert candidate([1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9], 11) == 3
assert candidate([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 11) == 10
| min_jumps |
HumanEval\/690 | from typing import List
def mul_consecutive_nums(nums: List[int]) -> List[int]:
""" Multiply consecutive numbers of a given list
>>> mul_consecutive_nums([1, 1, 3, 4, 4, 5, 6, 7])
[1, 3, 12, 16, 20, 30, 42]
>>> mul_consecutive_nums([4, 5, 8, 9, 6, 10])
[20, 40, 72, 54, 60]
"""
| result = [b*a for a, b in zip(nums[:-1], nums[1:])]
return result
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 1, 3, 4, 4, 5, 6, 7]) == [1, 3, 12, 16, 20, 30, 42]
assert candidate([4, 5, 8, 9, 6, 10]) == [20, 40, 72, 54, 60]
assert candidate([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 6, 12, 20, 30, 42, 56, 72, 90]
| mul_consecutive_nums |
task_691 | from itertools import groupby
def group_element(test_list):
""" Group the 1st elements on the basis of 2nd elements in the given tuple list.
>>> group_element([(6, 5), (2, 7), (2, 5), (8, 7), (9, 8), (3, 7)])
{5: [6, 2], 7: [2, 8, 3], 8: [9]}
"""
| res = dict()
for key, val in groupby(sorted(test_list, key=lambda ele: ele[1]), key=lambda ele: ele[1]):
res[key] = [ele[0] for ele in val]
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([(6, 5), (2, 7), (2, 5), (8, 7), (9, 8), (3, 7)]) == {5: [6, 2], 7: [2, 8, 3], 8: [9]}
assert candidate([(7, 6), (3, 8), (3, 6), (9, 8), (10, 9), (4, 8)]) == {6: [7, 3], 8: [3, 9, 4], 9: [10]}
assert candidate([(8, 7), (4, 9), (4, 7), (10, 9), (11, 10), (5, 9)]) == {7: [8, 4], 9: [4, 10, 5], 10: [11]}
| group_element |
HumanEval\/692 | def last_Two_Digits(N: int) -> int:
""" Find the last two digits in factorial of a given number.
>>> last_Two_Digits(7)
40
>>> last_Two_Digits(5)
20
>>> last_Two_Digits(2)
2
"""
| if (N >= 10):
return 0
fac = 1
for i in range(1, N + 1):
fac = (fac * i) % 100
return fac
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(7) == 40
assert candidate(5) == 20
assert candidate(2) == 2
| last_Two_Digits |
693 | import re
def remove_multiple_spaces(text1: str) -> str:
""" Remove multiple spaces in a string by using regex
>>> remove_multiple_spaces('Google Assistant')
'Google Assistant'
>>> remove_multiple_spaces('Quad Core')
'Quad Core'
>>> remove_multiple_spaces('ChromeCast Built-in')
'ChromeCast Built-in'
"""
| return re.sub(' +', ' ', text1)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('Google Assistant') == 'Google Assistant'
assert candidate('Quad Core') == 'Quad Core'
assert candidate('ChromeCast Built-in') == 'ChromeCast Built-in'
| remove_multiple_spaces |
HumanEval\/694 | def extract_unique(test_dict):
""" Extract unique values from the given dictionary values.
>>> extract_unique({'msm' : [5, 6, 7, 8],'is' : [10, 11, 7, 5],'best' : [6, 12, 10, 8],'for' : [1, 2, 5]})
[1, 2, 5, 6, 7, 8, 10, 11, 12]
"""
| res = list(sorted({ele for val in test_dict.values() for ele in val}))
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate({'msm' : [5, 6, 7, 8],'is' : [10, 11, 7, 5],'best' : [6, 12, 10, 8],'for' : [1, 2, 5]}) == [1, 2, 5, 6, 7, 8, 10, 11, 12]
assert candidate({'Built' : [7, 1, 9, 4],'for' : [11, 21, 36, 14, 9],'ISP' : [4, 1, 21, 39, 47],'TV' : [1, 32, 38]}) == [1, 4, 7, 9, 11, 14, 21, 32, 36, 38, 39, 47]
assert candidate({'F' : [11, 13, 14, 17],'A' : [12, 11, 15, 18],'N' : [19, 21, 15, 36],'G' : [37, 36, 35]}) == [11, 12, 13, 14, 15, 17, 18, 19, 21, 35, 36, 37]
| extract_unique |
HumanEval\/695 | def check_greater(test_tup1: tuple, test_tup2: tuple) -> bool:
""" Check if each element of the second tuple is greater than its corresponding index in the first tuple.
>>> check_greater((10, 4, 5), (13, 5, 18))
True
>>> check_greater((1, 2, 3), (2, 1, 4))
False
>>> check_greater((4, 5, 6), (5, 6, 7))
True
"""
| res = all(x < y for x, y in zip(test_tup1, test_tup2))
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate((10, 4, 5), (13, 5, 18)) == True
assert candidate((1, 2, 3), (2, 1, 4)) == False
assert candidate((4, 5, 6), (5, 6, 7)) == True
| check_greater |
HumanEval\/696 | from typing import List
def zip_list(list1: List[List[int]], list2: List[List[int]]) -> List[List[int]]:
""" Zip two given lists of lists.
>>> zip_list([[1, 3], [5, 7], [9, 11]], [[2, 4], [6, 8], [10, 12, 14]])
[[1, 3, 2, 4], [5, 7, 6, 8], [9, 11, 10, 12, 14]]
>>> zip_list([[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]])
[[1, 2, 7, 8], [3, 4, 9, 10], [5, 6, 11, 12]]
>>> zip_list([['a','b'],['c','d']], [['e','f'],['g','h']])
[['a','b','e','f'],['c','d','g','h']]
"""
| return [a + b for a, b in zip(list1, list2)]
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([[1, 3], [5, 7], [9, 11]], [[2, 4], [6, 8], [10, 12, 14]]) == [[1, 3, 2, 4], [5, 7, 6, 8], [9, 11, 10, 12, 14]]
assert candidate([[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]) == [[1, 2, 7, 8], [3, 4, 9, 10], [5, 6, 11, 12]]
assert candidate([['a','b'],['c','d']], [['e','f'],['g','h']]) == [['a','b','e','f'],['c','d','g','h']]
| zip_list |
HumanEval\/697 | from typing import List
def count_even(array_nums: List[int]) -> int:
""" Write a function to find number of even elements in the given list using lambda function.
>>> count_even([1, 2, 3, 5, 7, 8, 9, 10])
3
>>> count_even([10,15,14,13,-18,12,-20])
5
>>> count_even([1, 2, 4, 8, 9])
3
"""
| return len(list(filter(lambda x: (x % 2 == 0), array_nums)))
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([1, 2, 3, 5, 7, 8, 9, 10]) == 3
assert candidate([10, 15, 14, 13, -18, 12, -20]) == 5
assert candidate([1, 2, 4, 8, 9]) == 3
| count_even |
698 | def sort_dict_item(test_dict):
""" Sort dictionary items by tuple product of keys for the given dictionary with tuple keys.
>>> sort_dict_item({(5, 6) : 3, (2, 3) : 9, (8, 4): 10, (6, 4): 12})
{(2, 3): 9, (6, 4): 12, (5, 6): 3, (8, 4): 10}
"""
| res = {key: test_dict[key] for key in sorted(test_dict.keys(), key=lambda ele: ele[1] * ele[0])}
return res
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate({(5, 6): 3, (2, 3): 9, (8, 4): 10, (6, 4): 12}) == {(2, 3): 9, (6, 4): 12, (5, 6): 3, (8, 4): 10}
assert candidate({(6, 7): 4, (3, 4): 10, (9, 5): 11, (7, 5): 13}) == {(3, 4): 10, (7, 5): 13, (6, 7): 4, (9, 5): 11}
assert candidate({(7, 8): 5, (4, 5): 11, (10, 6): 12, (8, 6): 14}) == {(4, 5): 11, (8, 6): 14, (7, 8): 5, (10, 6): 12}
| sort_dict_item |
HumanEval\/699 | def min_Swaps(str1: str, str2: str) -> int:
"""Find the minimum number of swaps required to convert one binary string to another.
>>> min_Swaps("1101", "1110")
1
>>> min_Swaps("1111", "0100")
"Not Possible"
>>> min_Swaps("1110000", "0001101")
3
"""
| count = 0
for i in range(len(str1)):
if str1[i] != str2[i]:
count += 1
if count % 2 == 0:
return count // 2
else:
return "Not Possible"
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate("1101", "1110") == 1
assert candidate("1111", "0100") == "Not Possible"
assert candidate("1110000", "0001101") == 3
| min_Swaps |
HumanEval\/700 | from typing import List, Union
def count_range_in_list(li: List[Union[int, str]], min_val: Union[int, str], max_val: Union[int, str]) -> int:
""" Count the number of elements in a list which are within a specific range
>>> count_range_in_list([10,20,30,40,40,40,70,80,99],40,100)
6
>>> count_range_in_list(['a','b','c','d','e','f'],'a','e')
5
>>> count_range_in_list([7,8,9,15,17,19,45],15,20)
3
"""
| ctr = 0
for x in li:
if min_val <= x <= max_val:
ctr += 1
return ctr
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([10,20,30,40,40,40,70,80,99],40,100) == 6
assert candidate(['a','b','c','d','e','f'],'a','e') == 5
assert candidate([7,8,9,15,17,19,45],15,20) == 3
| count_range_in_list |
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
- Downloads last month
- 33