task_id
stringlengths
3
14
prompt
stringlengths
164
742
canonical_solution
stringlengths
14
760
test
stringlengths
170
703
entry_point
stringlengths
3
31
HumanEval\/701
from typing import List def equilibrium_index(arr: List[int]) -> int: """ Find the equilibrium index of the given array >>> equilibrium_index([1, 2, 3, 4, 1, 2, 3]) 3 >>> equilibrium_index([-7, 1, 5, 2, -4, 3, 0]) 3 >>> equilibrium_index([1, 2, 3]) -1 """
total_sum = sum(arr) left_sum = 0 for i, num in enumerate(arr): total_sum -= num if left_sum == total_sum: return i left_sum += num return -1
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1, 2, 3, 4, 1, 2, 3]) == 3 assert candidate([-7, 1, 5, 2, -4, 3, 0]) == 3 assert candidate([1, 2, 3]) == -1
equilibrium_index
702
def removals(arr: List[int], n: int, k: int) -> int: """ Write a function to find the minimum number of elements that should be removed such that amax-amin<=k. >>> removals([1, 3, 4, 9, 10, 11, 12, 17, 20], 9, 4) 5 >>> removals([1, 5, 6, 2, 8], 5, 2) 3 >>> removals([1, 2, 3, 4, 5, 6], 6, 3) 2 """
arr.sort() ans = n - 1 for i in range(n): j = find_ind(arr[i], i, n, k, arr) if j != -1: ans = min(ans, n - (j - i + 1)) return ans def find_ind(key: int, i: int, n: int, k: int, arr: List[int]) -> int: ind = -1 start = i + 1 end = n - 1 while start < end: mid = (start + end) // 2 if arr[mid] - key <= k: ind = mid start = mid + 1 else: end = mid return ind
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1, 3, 4, 9, 10, 11, 12, 17, 20], 9, 4) == 5 assert candidate([1, 5, 6, 2, 8], 5, 2) == 3 assert candidate([1, 2, 3, 4, 5, 6], 6, 3) == 2
removals
HumanEval\/703
def is_key_present(d: dict, x: int) -> bool: """ Check whether the given key is present in the dictionary or not. >>> is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}, 5) True >>> is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}, 10) False """
return x in d
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}, 5) == True assert candidate({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}, 6) == True assert candidate({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}, 10) == False
is_key_present
HumanEval\/704
def harmonic_sum(n: int) -> float: """ Calculate the harmonic sum of n-1. >>> harmonic_sum(10) 2.9289682539682538 >>> harmonic_sum(4) 2.083333333333333 >>> harmonic_sum(7) 2.5928571428571425 """
if n < 2: return 1 else: return 1 / n + harmonic_sum(n - 1)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(10) == 2.9289682539682538 assert candidate(4) == 2.083333333333333 assert candidate(7) == 2.5928571428571425
harmonic_sum
HumanEval\/705
from typing import List def sort_sublists(list1: List[List[int]]) -> List[List[int]]: """ Sort a list of lists by length and value >>> sort_sublists([[2], [0], [1, 3], [0, 7], [9, 11], [13, 15, 17]]) [[0], [2], [0, 7], [1, 3], [9, 11], [13, 15, 17]] >>> sort_sublists([[1], [2, 3], [4, 5, 6], [7], [10, 11]]) [[1], [7], [2, 3], [10, 11], [4, 5, 6]] >>> sort_sublists([["python"],["java","C","C++"],["DBMS"],["SQL","HTML"]]) [['DBMS'], ['python'], ['SQL', 'HTML'], ['java', 'C', 'C++']] """
list1.sort() list1.sort(key=len) return list1
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([[2], [0], [1, 3], [0, 7], [9, 11], [13, 15, 17]]) == [[0], [2], [0, 7], [1, 3], [9, 11], [13, 15, 17]] assert candidate([[1], [2, 3], [4, 5, 6], [7], [10, 11]]) == [[1], [7], [2, 3], [10, 11], [4, 5, 6]] assert candidate([["python"],["java","C","C++"],["DBMS"],["SQL","HTML"]]) == [['DBMS'], ['python'], ['SQL', 'HTML'], ['java', 'C', 'C++']]
sort_sublists
HumanEval\/706
def is_subset(arr1, m, arr2, n): """ Determine if arr2 is a subset of arr1 >>> is_subset([11, 1, 13, 21, 3, 7], 6, [11, 3, 7, 1], 4) True >>> is_subset([1, 2, 3, 4, 5, 6], 6, [1, 2, 4], 3) True >>> is_subset([10, 5, 2, 23, 19], 5, [19, 5, 3], 3) False """
hashset = set() for i in range(0, m): hashset.add(arr1[i]) for i in range(0, n): if arr2[i] in hashset: continue else: return False return True
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([11, 1, 13, 21, 3, 7], 6, [11, 3, 7, 1], 4) == True assert candidate([1, 2, 3, 4, 5, 6], 6, [1, 2, 4], 3) == True assert candidate([10, 5, 2, 23, 19], 5, [19, 5, 3], 3) == False
is_subset
HumanEval\/707
def count_Set_Bits(n: int) -> int: """ Count the total set bits from 1 to n. >>> count_Set_Bits(16) 33 >>> count_Set_Bits(2) 2 >>> count_Set_Bits(14) 28 """
n += 1 powerOf2 = 2 cnt = n // 2 while powerOf2 <= n: totalPairs = n // powerOf2 cnt += (totalPairs // 2) * powerOf2 if totalPairs & 1: cnt += (n % powerOf2) powerOf2 <<= 1 return cnt
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(16) == 33 assert candidate(2) == 2 assert candidate(14) == 28
count_Set_Bits
HumanEval\/708
from typing import List def Convert(string: str) -> List[str]: """ Convert a string to a list of words >>> Convert('python program') ['python', 'program'] >>> Convert('Data Analysis') ['Data', 'Analysis'] """
return list(string.split(" "))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('python program') == ['python', 'program'] assert candidate('Data Analysis') == ['Data', 'Analysis'] assert candidate('Hadoop Training') == ['Hadoop', 'Training']
Convert
709
from collections import defaultdict def get_unique(test_list): """Write a function to count unique keys for each value present in the tuple. >>> get_unique([(3, 4), (1, 2), (2, 4), (8, 2), (7, 2), (8, 1), (9, 1), (8, 4), (10, 4)]) '{4: 4, 2: 3, 1: 2}' """
res = defaultdict(list) for sub in test_list: res[sub[1]].append(sub[0]) res = dict(res) res_dict = dict() for key in res: res_dict[key] = len(list(set(res[key]))) return str(res_dict)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([(3, 4), (1, 2), (2, 4), (8, 2), (7, 2), (8, 1), (9, 1), (8, 4), (10, 4)]) == '{4: 4, 2: 3, 1: 2}' assert candidate([(4, 5), (2, 3), (3, 5), (9, 3), (8, 3), (9, 2), (10, 2), (9, 5), (11, 5)]) == '{5: 4, 3: 3, 2: 2}' assert candidate([(6, 5), (3, 4), (2, 6), (11, 1), (8, 22), (8, 11), (4, 3), (14, 3), (11, 6)]) == '{5: 1, 4: 1, 6: 2, 1: 1, 22: 1, 11: 1, 3: 2}'
get_unique
HumanEval\/710
def front_and_rear(test_tup: tuple) -> tuple: """ Return a tuple containing the first and last elements of the given tuple. >>> front_and_rear((10, 4, 5, 6, 7)) (10, 7) >>> front_and_rear((1, 2, 3, 4, 5)) (1, 5) >>> front_and_rear((6, 7, 8, 9, 10)) (6, 10) """
res = (test_tup[0], test_tup[-1]) return res
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate((10, 4, 5, 6, 7)) == (10, 7) assert candidate((1, 2, 3, 4, 5)) == (1, 5) assert candidate((6, 7, 8, 9, 10)) == (6, 10)
front_and_rear
HumanEval\/711
def product_Equal(n: int) -> bool: """ Check whether the product of digits of a number at even and odd places is equal or not. >>> product_Equal(2841) True >>> product_Equal(1234) False >>> product_Equal(1212) False """
if n < 10: return False prodOdd = 1; prodEven = 1 while n > 0: digit = n % 10 prodOdd *= digit n = n//10 if n == 0: break digit = n % 10 prodEven *= digit n = n//10 return prodOdd == prodEven
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2841) == True assert candidate(1234) == False assert candidate(1212) == False
product_Equal
HumanEval\/712
import itertools def remove_duplicate(list1): """ Remove duplicates from a list of lists >>> remove_duplicate([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]]) [[10, 20], [30, 56, 25], [33], [40]] >>> remove_duplicate(['a', 'b', 'a', 'c', 'c']) ['a', 'b', 'c'] >>> remove_duplicate([1, 3, 5, 6, 3, 5, 6, 1]) [1, 3, 5, 6] """
list1.sort() return list(list1 for list1,_ in itertools.groupby(list1))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]]) == [[10, 20], [30, 56, 25], [33], [40]] assert candidate(['a', 'b', 'a', 'c', 'c']) == ['a', 'b', 'c'] assert candidate([1, 3, 5, 6, 3, 5, 6, 1]) == [1, 3, 5, 6]
remove_duplicate
HumanEval\/713
def check_valid(test_tup: tuple) -> bool: """ Check if the given tuple contains all valid values or not. >>> check_valid((True, True, True, True)) True >>> check_valid((True, False, True, True)) False """
return not any(map(lambda ele: not ele, test_tup))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate((True, True, True, True)) == True assert candidate((True, False, True, True)) == False assert candidate((True, True, True, True)) == True
check_valid
HumanEval\/714
def count_Fac(n: int) -> int: """ Count the number of distinct power of prime factor of given number. >>> count_Fac(24) 3 >>> count_Fac(12) 2 >>> count_Fac(4) 1 """
m = n count = 0 i = 2 while((i * i) <= m): total = 0 while (n % i == 0): n /= i total += 1 temp = 0 j = 1 while((temp + j) <= total): temp += j count += 1 j += 1 i += 1 if (n != 1): count += 1 return count
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(24) == 3 assert candidate(12) == 2 assert candidate(4) == 1
count_Fac
HumanEval\/715
def str_to_tuple(test_str: str) -> tuple: """ Convert the given string of integers into a tuple. >>> str_to_tuple("1, -5, 4, 6, 7") (1, -5, 4, 6, 7) >>> str_to_tuple("1, 2, 3, 4, 5") (1, 2, 3, 4, 5) """
res = tuple(map(int, test_str.split(', '))) return res
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate("1, -5, 4, 6, 7") == (1, -5, 4, 6, 7) assert candidate("1, 2, 3, 4, 5") == (1, 2, 3, 4, 5) assert candidate("4, 6, 9, 11, 13, 14") == (4, 6, 9, 11, 13, 14)
str_to_tuple
HumanEval\/716
def rombus_perimeter(a: int) -> int: """ Calculate the perimeter of a rhombus given the length of one side. >>> rombus_perimeter(10) 40 >>> rombus_perimeter(5) 20 >>> rombus_perimeter(4) 16 """
return 4 * a
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(10) == 40 assert candidate(5) == 20 assert candidate(4) == 16
rombus_perimeter
HumanEval\/717
import math from typing import List def sd_calc(data: List[float]) -> float: """ Calculate the standard deviation of a list of numbers. >>> sd_calc([4, 2, 5, 8, 6]) 2.23606797749979 >>> sd_calc([1,2,3,4,5,6,7]) 2.160246899469287 >>> sd_calc([5,9,10,15,6,4]) 4.070217029430577 """
n = len(data) if n <= 1: return 0.0 mean = sum(data) / n variance = sum((x - mean) ** 2 for x in data) / (n - 1) return math.sqrt(variance)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([4, 2, 5, 8, 6]) == 2.23606797749979 assert candidate([1, 2, 3, 4, 5, 6, 7]) == 2.160246899469287 assert candidate([5, 9, 10, 15, 6, 4]) == 4.070217029430577
sd_calc
HumanEval\/718
from typing import List def alternate_elements(list1: List) -> List: """ Create a list taking alternate elements from another given list. >>> alternate_elements(['red', 'black', 'white', 'green', 'orange']) ['red', 'white', 'orange'] >>> alternate_elements([2, 0, 3, 4, 0, 2, 8, 3, 4, 2]) [2, 3, 0, 8, 4] >>> alternate_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) [1, 3, 5, 7, 9] """
return list1[::2]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(['red', 'black', 'white', 'green', 'orange']) == ['red', 'white', 'orange'] assert candidate([2, 0, 3, 4, 0, 2, 8, 3, 4, 2]) == [2, 3, 0, 8, 4] assert candidate([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 3, 5, 7, 9]
alternate_elements
HumanEval\/719
import re def text_match(text: str) -> str: """ Match a string that has an 'a' followed by zero or more 'b's. >>> text_match('ac') 'Found a match!' >>> text_match('dc') 'Not matched!' >>> text_match('abba') 'Found a match!' """
patterns = 'ab*?' if re.search(patterns, text): return 'Found a match!' else: return 'Not matched!'
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('ac') == 'Found a match!' assert candidate('dc') == 'Not matched!' assert candidate('abba') == 'Found a match!'
text_match
HumanEval\/720
def add_dict_to_tuple(test_tup, test_dict): """ Add a dictionary to the tuple >>> add_dict_to_tuple((4, 5, 6), {"MSAM" : 1, "is" : 2, "best" : 3}) (4, 5, 6, {'MSAM': 1, 'is': 2, 'best': 3}) >>> add_dict_to_tuple((1, 2, 3), {"UTS" : 2, "is" : 3, "Worst" : 4}) (1, 2, 3, {'UTS': 2, 'is': 3, 'Worst': 4}) """
test_tup = list(test_tup) test_tup.append(test_dict) test_tup = tuple(test_tup) return test_tup
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate((4, 5, 6), {"MSAM" : 1, "is" : 2, "best" : 3}) == (4, 5, 6, {'MSAM': 1, 'is': 2, 'best': 3}) assert candidate((1, 2, 3), {"UTS" : 2, "is" : 3, "Worst" : 4}) == (1, 2, 3, {'UTS': 2, 'is': 3, 'Worst': 4}) assert candidate((8, 9, 10), {"POS" : 3, "is" : 4, "Okay" : 5}) == (8, 9, 10, {'POS': 3, 'is': 4, 'Okay': 5})
add_dict_to_tuple
HumanEval\/721
def maxAverageOfPath(cost, N): """Find a path with the maximum average over all existing paths for the given square matrix of size n*n. >>> maxAverageOfPath([[1, 2, 3], [6, 5, 4], [7, 3, 9]], 3) 5.2 >>> maxAverageOfPath([[2, 3, 4], [7, 6, 5], [8, 4, 10]], 3) 6.2 """
dp = [[0 for i in range(N + 1)] for j in range(N + 1)] dp[0][0] = cost[0][0] for i in range(1, N): dp[i][0] = dp[i - 1][0] + cost[i][0] for j in range(1, N): dp[0][j] = dp[0][j - 1] + cost[0][j] for i in range(1, N): for j in range(1, N): dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + cost[i][j] return dp[N - 1][N - 1] / (2 * N - 1)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([[1, 2, 3], [6, 5, 4], [7, 3, 9]], 3) == 5.2 assert candidate([[2, 3, 4], [7, 6, 5], [8, 4, 10]], 3) == 6.2 assert candidate([[3, 4, 5], [8, 7, 6], [9, 5, 11]], 3) == 7.2
maxAverageOfPath
722
def filter_data(students, h, w): """ Filter the height and width of students stored in a dictionary. >>> filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)}, 6.0, 70) {'Cierra Vega': (6.2, 70)} >>> filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)}, 5.9, 67) {'Cierra Vega': (6.2, 70), 'Kierra Gentry': (6.0, 68)} """
result = {k: s for k, s in students.items() if s[0] >= h and s[1] >= w} return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)}, 6.0, 70) == {'Cierra Vega': (6.2, 70)} assert candidate({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)}, 5.9, 67) == {'Cierra Vega': (6.2, 70), 'Kierra Gentry': (6.0, 68)} assert candidate({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)}, 5.7, 64) == {'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)}
filter_data
HumanEval\/723
from operator import eq from typing import List def count_same_pair(nums1: List[int], nums2: List[int]) -> int: """ Write a function to count the same pair in two given lists using map function. >>> count_same_pair([1, 2, 3, 4, 5, 6, 7, 8],[2, 2, 3, 1, 2, 6, 7, 9]) 4 >>> count_same_pair([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8]) 11 >>> count_same_pair([2, 4, -6, -9, 11, -12, 14, -5, 17],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8]) 1 """
result = sum(map(eq, nums1, nums2)) return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1, 2, 3, 4, 5, 6, 7, 8],[2, 2, 3, 1, 2, 6, 7, 9]) == 4 assert candidate([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8]) == 11 assert candidate([2, 4, -6, -9, 11, -12, 14, -5, 17],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8]) == 1
count_same_pair
HumanEval\/724
def power_base_sum(base: int, power: int) -> int: """ Calculate the sum of all digits of the base to the specified power. >>> power_base_sum(2, 100) 115 >>> power_base_sum(8, 10) 37 >>> power_base_sum(8, 15) 62 """
return sum([int(i) for i in str(pow(base, power))])
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2, 100) == 115 assert candidate(8, 10) == 37 assert candidate(8, 15) == 62
power_base_sum
725
import re def extract_quotation(text1): """ Extract values between quotation marks of the given string by using regex. >>> extract_quotation('Cortex "A53" Based "multi" tasking "Processor"') ['A53', 'multi', 'Processor'] >>> extract_quotation('Cast your "favorite" entertainment "apps"') ['favorite', 'apps'] >>> extract_quotation('Watch content "4k Ultra HD" resolution with "HDR 10" Support') ['4k Ultra HD', 'HDR 10'] """
return re.findall(r'"(.*?)"', text1)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('Cortex "A53" Based "multi" tasking "Processor"') == ['A53', 'multi', 'Processor'] assert candidate('Cast your "favorite" entertainment "apps"') == ['favorite', 'apps'] assert candidate('Watch content "4k Ultra HD" resolution with "HDR 10" Support') == ['4k Ultra HD', 'HDR 10']
extract_quotation
HumanEval\/726
def multiply_elements(test_tup: tuple) -> tuple: """ Multiply the adjacent elements of the given tuple >>> multiply_elements((1, 5, 7, 8, 10)) (5, 35, 56, 80) >>> multiply_elements((2, 4, 5, 6, 7)) (8, 20, 30, 42) >>> multiply_elements((12, 13, 14, 9, 15)) (156, 182, 126, 135) """
res = tuple(i * j for i, j in zip(test_tup, test_tup[1:])) return res
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate((1, 5, 7, 8, 10)) == (5, 35, 56, 80) assert candidate((2, 4, 5, 6, 7)) == (8, 20, 30, 42) assert candidate((12, 13, 14, 9, 15)) == (156, 182, 126, 135)
multiply_elements
HumanEval\/727
import re def remove_char(S: str) -> str: """ Remove all characters from the string except letters and numbers using regex. >>> remove_char("123abcjw:, .@! eiw") '123abcjweiw' >>> remove_char("Hello1234:, ! Howare33u") 'Hello1234Howare33u' >>> remove_char("Cool543Triks@:, Make@987Trips") 'Cool543TriksMake987Trips' """
result = re.sub('[\W_]+', '', S) return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate("123abcjw:, .@! eiw") == '123abcjweiw' assert candidate("Hello1234:, ! Howare33u") == 'Hello1234Howare33u' assert candidate("Cool543Triks@:, Make@987Trips") == 'Cool543TriksMake987Trips'
remove_char
HumanEval\/728
from typing import List def sum_list(lst1: List[int], lst2: List[int]) -> List[int]: """ Sum elements in two lists element-wise >>> sum_list([10, 20, 30], [15, 25, 35]) [25, 45, 65] >>> sum_list([1, 2, 3], [5, 6, 7]) [6, 8, 10] >>> sum_list([15, 20, 30], [15, 45, 75]) [30, 65, 105] """
return [lst1[i] + lst2[i] for i in range(len(lst1))]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([10, 20, 30], [15, 25, 35]) == [25, 45, 65] assert candidate([1, 2, 3], [5, 6, 7]) == [6, 8, 10] assert candidate([15, 20, 30], [15, 45, 75]) == [30, 65, 105]
sum_list
HumanEval\/729
from typing import List def add_list(nums1: List[int], nums2: List[int]) -> List[int]: """ Add two lists using map and lambda function >>> add_list([1, 2, 3], [4, 5, 6]) [5, 7, 9] >>> add_list([1, 2], [3, 4]) [4, 6] >>> add_list([10, 20], [50, 70]) [60, 90] """
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]) == [5, 7, 9] assert candidate([1, 2], [3, 4]) == [4, 6] assert candidate([10, 20], [50, 70]) == [60, 90]
add_list
HumanEval\/730
from itertools import groupby from typing import List, Union def consecutive_duplicates(nums: List[Union[int, str]]) -> List[Union[int, str]]: """ Remove consecutive duplicates from a list. >>> consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4] >>> consecutive_duplicates([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10]) [10, 15, 19, 18, 17, 26, 17, 18, 10] >>> consecutive_duplicates(['a', 'a', 'b', 'c', 'd', 'd']) ['a', 'b', 'c', 'd'] """
return [key for key, group in groupby(nums)]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4] assert candidate([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10]) == [10, 15, 19, 18, 17, 26, 17, 18, 10] assert candidate(['a', 'a', 'b', 'c', 'd', 'd']) == ['a', 'b', 'c', 'd']
consecutive_duplicates
HumanEval\/731
import math def lateralsurface_cone(r: float, h: float) -> float: """ Calculate the lateral surface area of a cone given its radius and height. >>> lateralsurface_cone(5, 12) 204.20352248333654 >>> lateralsurface_cone(10, 15) 566.3586699569488 >>> lateralsurface_cone(19, 17) 1521.8090132193388 """
l = math.sqrt(r * r + h * h) LSA = math.pi * r * l return LSA
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(5, 12) == 204.20352248333654 assert candidate(10, 15) == 566.3586699569488 assert candidate(19, 17) == 1521.8090132193388
lateralsurface_cone
732
import re def replace_specialchar(text: str) -> str: """ Replace all occurrences of spaces, commas, or dots with a colon. >>> replace_specialchar('Python language, Programming language.') 'Python:language::Programming:language:' >>> replace_specialchar('a b c,d e f') 'a:b:c:d:e:f' >>> replace_specialchar('ram reshma,ram rahim') 'ram:reshma:ram:rahim' """
return re.sub("[ ,.]", ":", text)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('Python language, Programming language.') == 'Python:language::Programming:language:' assert candidate('a b c,d e f') == 'a:b:c:d:e:f' assert candidate('ram reshma,ram rahim') == 'ram:reshma:ram:rahim'
replace_specialchar
HumanEval\/733
from typing import List def find_first_occurrence(A: List[int], x: int) -> int: """ Find the index of the first occurrence of a given number in a sorted array >>> find_first_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5) 1 >>> find_first_occurrence([2, 3, 5, 5, 6, 6, 8, 9, 9, 9], 5) 2 >>> find_first_occurrence([2, 4, 1, 5, 6, 6, 8, 9, 9, 9], 6) 4 """
(left, right) = (0, len(A) - 1) result = -1 while left <= right: mid = (left + right) // 2 if x == A[mid]: result = mid right = mid - 1 elif x < A[mid]: right = mid - 1 else: left = mid + 1 return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 1 assert candidate([2, 3, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 2 assert candidate([2, 4, 1, 5, 6, 6, 8, 9, 9, 9], 6) == 4
find_first_occurrence
HumanEval\/734
def sum_Of_Subarray_Prod(arr: List[int], n: int) -> int: """ Calculate the sum of products of all possible subarrays. >>> sum_Of_Subarray_Prod([1, 2, 3], 3) 20 >>> sum_Of_Subarray_Prod([1, 2], 2) 5 >>> sum_Of_Subarray_Prod([1, 2, 3, 4], 4) 84 """
ans = 0 res = 0 i = n - 1 while (i >= 0): incr = arr[i]*(1 + res) ans += incr res = incr i -= 1 return (ans)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1, 2, 3], 3) == 20 assert candidate([1, 2], 2) == 5 assert candidate([1, 2, 3, 4], 4) == 84
sum_Of_Subarray_Prod
HumanEval\/735
def toggle_middle_bits(n): """ Toggle bits of the number except the first and the last bit. >>> toggle_middle_bits(9) 15 >>> toggle_middle_bits(10) 12 >>> toggle_middle_bits(11) 13 """
def set_middle_bits(n): n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; return (n >> 1) ^ 1 if (n == 1): return 1 return n ^ set_middle_bits(n)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(9) == 15 assert candidate(10) == 12 assert candidate(11) == 13
toggle_middle_bits
HumanEval\/736
import bisect def left_insertion(a, x): """ Locate the left insertion point for a specified value in sorted order. >>> left_insertion([1,2,4,5], 6) 4 >>> left_insertion([1,2,4,5], 3) 2 >>> left_insertion([1,2,4,5], 7) 4 """
i = bisect.bisect_left(a, x) return i
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1,2,4,5], 6) == 4 assert candidate([1,2,4,5], 3) == 2 assert candidate([1,2,4,5], 7) == 4
left_insertion
HumanEval\/737
import re def check_str(string: str) -> str: """ Check whether the given string is starting with a vowel or not using regex. >>> check_str("annie") 'Valid' >>> check_str("dawood") 'Invalid' >>> check_str("Else") 'Valid' """
regex = '^[aeiouAEIOU][A-Za-z0-9_]*' if re.search(regex, string): return "Valid" else: return "Invalid"
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate("annie") == 'Valid' assert candidate("dawood") == 'Invalid' assert candidate("Else") == 'Valid'
check_str
HumanEval\/738
def geometric_sum(n: int) -> float: """ Calculate the geometric sum of n-1. >>> geometric_sum(7) 1.9921875 >>> geometric_sum(4) 1.9375 >>> geometric_sum(8) 1.99609375 """
if n < 0: return 0 else: return 1 / (pow(2, n)) + geometric_sum(n - 1)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(7) == 1.9921875 assert candidate(4) == 1.9375 assert candidate(8) == 1.99609375
geometric_sum
HumanEval\/739
import math def find_Index(n: int) -> int: """ Find the index of the smallest triangular number with n digits. >>> find_Index(2) 4 >>> find_Index(3) 14 >>> find_Index(4) 45 """
x = math.sqrt(2 * math.pow(10, (n - 1))) return round(x)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == 4 assert candidate(3) == 14 assert candidate(4) == 45
find_Index
HumanEval\/740
def tuple_to_dict(test_tup): """ Convert the given tuple to a key-value dictionary using adjacent elements. >>> tuple_to_dict((1, 5, 7, 10, 13, 5)) {1: 5, 7: 10, 13: 5} >>> tuple_to_dict((1, 2, 3, 4, 5, 6)) {1: 2, 3: 4, 5: 6} """
res = dict(test_tup[idx : idx + 2] for idx in range(0, len(test_tup), 2)) return res
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate((1, 5, 7, 10, 13, 5)) == {1: 5, 7: 10, 13: 5} assert candidate((1, 2, 3, 4, 5, 6)) == {1: 2, 3: 4, 5: 6} assert candidate((7, 8, 9, 10, 11, 12)) == {7: 8, 9: 10, 11: 12}
tuple_to_dict
HumanEval\/741
def all_Characters_Same(s: str) -> bool: """ Check whether all the characters in the string are the same. >>> all_Characters_Same("python") False >>> all_Characters_Same("aaa") True >>> all_Characters_Same("data") False """
n = len(s) for i in range(1, n): if s[i] != s[0]: return False return True
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate("python") == False assert candidate("aaa") == True assert candidate("data") == False
all_Characters_Same
HumanEval\/742
import math def area_tetrahedron(side: float) -> float: """ Calculate the area of a tetrahedron given the length of its side. >>> area_tetrahedron(3) 15.588457268119894 >>> area_tetrahedron(20) 692.8203230275509 >>> area_tetrahedron(10) 173.20508075688772 """
return math.sqrt(3) * (side * side)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(3) == 15.588457268119894 assert candidate(20) == 692.8203230275509 assert candidate(10) == 173.20508075688772
area_tetrahedron
HumanEval\/743
from typing import List def rotate_right(list1: List[int], m: int, n: int) -> List[int]: """ Rotate a given list by specified number of items to the right direction. >>> rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 4) [8, 9, 10, 1, 2, 3, 4, 5, 6] >>> rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2, 2) [9, 10, 1, 2, 3, 4, 5, 6, 7, 8] >>> rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, 2) [6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8] """
result = list1[-(m):] + list1[:-(n)] return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 4) == [8, 9, 10, 1, 2, 3, 4, 5, 6] assert candidate([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2, 2) == [9, 10, 1, 2, 3, 4, 5, 6, 7, 8] assert candidate([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, 2) == [6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8]
rotate_right
HumanEval\/744
def check_none(test_tup: tuple) -> bool: """ Check if the given tuple has any None value or not. >>> check_none((10, 4, 5, 6, None)) True >>> check_none((7, 8, 9, 11, 14)) False >>> check_none((1, 2, 3, 4, None)) True """
return any(map(lambda ele: ele is None, test_tup))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate((10, 4, 5, 6, None)) == True assert candidate((7, 8, 9, 11, 14)) == False assert candidate((1, 2, 3, 4, None)) == True
check_none
HumanEval\/745
def divisible_by_digits(startnum: int, endnum: int) -> list: """ Find numbers within a given range where every number is divisible by every digit it contains. >>> divisible_by_digits(1, 22) [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22] >>> divisible_by_digits(1, 15) [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15] >>> divisible_by_digits(20, 25) [22, 24] """
return [n for n in range(startnum, endnum+1) if not any(map(lambda x: int(x) == 0 or n%int(x) != 0, str(n)))]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(1, 22) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22] assert candidate(1, 15) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15] assert candidate(20, 25) == [22, 24]
divisible_by_digits
HumanEval\/746
def sector_area(r: float, a: float) -> float: """ Calculate the area of a sector given the radius and angle in degrees. Returns None if the angle is 360 degrees or more. >>> sector_area(4, 45) 6.285714285714286 >>> sector_area(9, 45) 31.82142857142857 >>> sector_area(9, 360) None """
pi = 22/7 if a >= 360: return None sectorarea = (pi * r**2) * (a / 360) return sectorarea
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(4, 45) == 6.285714285714286 assert candidate(9, 45) == 31.82142857142857 assert candidate(9, 360) == None
sector_area
HumanEval\/747
def lcs_of_three(X: str, Y: str, Z: str, m: int, n: int, o: int) -> int: """ Write a function to find the longest common subsequence for the given three string sequence. >>> lcs_of_three('AGGT12', '12TXAYB', '12XBA', 6, 7, 5) 2 >>> lcs_of_three('Reels', 'Reelsfor', 'ReelsforReels', 5, 8, 13) 5 >>> lcs_of_three('abcd1e2', 'bc12ea', 'bd1ea', 7, 6, 5) 3 """
L = [[[0 for i in range(o+1)] for j in range(n+1)] for k in range(m+1)] for i in range(m+1): for j in range(n+1): for k in range(o+1): if (i == 0 or j == 0 or k == 0): L[i][j][k] = 0 elif (X[i-1] == Y[j-1] and X[i-1] == Z[k-1]): L[i][j][k] = L[i-1][j-1][k-1] + 1 else: L[i][j][k] = max(max(L[i-1][j][k], L[i][j-1][k]), L[i][j][k-1]) return L[m][n][o]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('AGGT12', '12TXAYB', '12XBA', 6, 7, 5) == 2 assert candidate('Reels', 'Reelsfor', 'ReelsforReels', 5, 8, 13) == 5 assert candidate('abcd1e2', 'bc12ea', 'bd1ea', 7, 6, 5) == 3
lcs_of_three
HumanEval\/748
import re def capital_words_spaces(str1: str) -> str: """ Write a function to put spaces between words starting with capital letters in a given string by using regex. >>> capital_words_spaces("Python") 'Python' >>> capital_words_spaces("PythonProgrammingExamples") 'Python Programming Examples' >>> capital_words_spaces("GetReadyToBeCodingFreak") 'Get Ready To Be Coding Freak' """
return re.sub(r"(\w)([A-Z])", r"\1 \2", str1)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate("Python") == 'Python' assert candidate("PythonProgrammingExamples") == 'Python Programming Examples' assert candidate("GetReadyToBeCodingFreak") == 'Get Ready To Be Coding Freak'
capital_words_spaces
HumanEval\/749
from typing import List def sort_numeric_strings(nums_str: List[str]) -> List[int]: """ Sort a given list of strings of numbers numerically. >>> sort_numeric_strings(['4','12','45','7','0','100','200','-12','-500']) [-500, -12, 0, 4, 7, 12, 45, 100, 200] >>> sort_numeric_strings(['2','3','8','4','7','9','8','2','6','5','1','6','1','2','3','4','6','9','1','2']) [1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8, 9, 9] >>> sort_numeric_strings(['1','3','5','7','1', '3','13', '15', '17','5', '7 ','9','1', '11']) [1, 1, 1, 3, 3, 5, 5, 7, 7, 9, 11, 13, 15, 17] """
result = [int(x) for x in nums_str] result.sort() return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(['4','12','45','7','0','100','200','-12','-500']) == [-500, -12, 0, 4, 7, 12, 45, 100, 200] assert candidate(['2','3','8','4','7','9','8','2','6','5','1','6','1','2','3','4','6','9','1','2']) == [1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8, 9, 9] assert candidate(['1','3','5','7','1', '3','13', '15', '17','5', '7 ','9','1', '11']) == [1, 1, 1, 3, 3, 5, 5, 7, 7, 9, 11, 13, 15, 17]
sort_numeric_strings
HumanEval\/750
from typing import List, Tuple def add_tuple(test_list: List[int], test_tup: Tuple[int, ...]) -> List[int]: """ Add the given tuple to the given list >>> add_tuple([5, 6, 7], (9, 10)) [5, 6, 7, 9, 10] >>> add_tuple([6, 7, 8], (10, 11)) [6, 7, 8, 10, 11] >>> add_tuple([7, 8, 9], (11, 12)) [7, 8, 9, 11, 12] """
test_list += test_tup return test_list
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([5, 6, 7], (9, 10)) == [5, 6, 7, 9, 10] assert candidate([6, 7, 8], (10, 11)) == [6, 7, 8, 10, 11] assert candidate([7, 8, 9], (11, 12)) == [7, 8, 9, 11, 12]
add_tuple
HumanEval\/751
def check_min_heap(arr, i): """ Check if the given array represents a min heap starting from index i. >>> check_min_heap([1, 2, 3, 4, 5, 6], 0) True >>> check_min_heap([2, 3, 4, 5, 10, 15], 0) True >>> check_min_heap([2, 10, 4, 5, 3, 15], 0) False """
if 2 * i + 2 > len(arr): return True left_child = (arr[i] <= arr[2 * i + 1]) and check_min_heap(arr, 2 * i + 1) right_child = (2 * i + 2 == len(arr)) or (arr[i] <= arr[2 * i + 2] and check_min_heap(arr, 2 * i + 2)) return left_child and right_child
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1, 2, 3, 4, 5, 6], 0) == True assert candidate([2, 3, 4, 5, 10, 15], 0) == True assert candidate([2, 10, 4, 5, 3, 15], 0) == False
check_min_heap
HumanEval\/752
def jacobsthal_num(n: int) -> int: """ Calculate the nth Jacobsthal number >>> jacobsthal_num(5) 11 >>> jacobsthal_num(2) 1 >>> jacobsthal_num(4) 5 """
dp = [0] * (n + 1) dp[0] = 0 dp[1] = 1 for i in range(2, n+1): dp[i] = dp[i - 1] + 2 * dp[i - 2] return dp[n]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(5) == 11 assert candidate(2) == 1 assert candidate(4) == 5
jacobsthal_num
HumanEval\/753
from typing import List, Tuple def min_k(test_list: List[Tuple[str, int]], K: int) -> List[Tuple[str, int]]: """ Write a function to find minimum k records from tuple list. >>> min_k([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2) [('Akash', 2), ('Akshat', 4)] >>> min_k([('Sanjeev', 11), ('Angat', 5), ('Akash', 3), ('Nepin', 9)], 3) [('Akash', 3), ('Angat', 5), ('Nepin', 9)] >>> min_k([('tanmay', 14), ('Amer', 11), ('Ayesha', 9), ('SKD', 16)], 1) [('Ayesha', 9)] """
res = sorted(test_list, key=lambda x: x[1])[:K] return res
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2) == [('Akash', 2), ('Akshat', 4)] assert candidate([('Sanjeev', 11), ('Angat', 5), ('Akash', 3), ('Nepin', 9)], 3) == [('Akash', 3), ('Angat', 5), ('Nepin', 9)] assert candidate([('tanmay', 14), ('Amer', 11), ('Ayesha', 9), ('SKD', 16)], 1) == [('Ayesha', 9)]
min_k
754
def extract_index_list(l1, l2, l3): """ Write a function to find common index elements from three lists. >>> extract_index_list([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7]) [1, 7] >>> extract_index_list([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 6, 5],[0, 1, 2, 3, 4, 6, 7]) [1, 6] >>> extract_index_list([1, 1, 3, 4, 6, 5, 6],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7]) [1, 5] """
result = [] for m, n, o in zip(l1, l2, l3): if (m == n == o): result.append(m) return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7]) == [1, 7] assert candidate([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 6, 5],[0, 1, 2, 3, 4, 6, 7]) == [1, 6] assert candidate([1, 1, 3, 4, 6, 5, 6],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7]) == [1, 5]
extract_index_list
HumanEval\/755
from typing import List def second_smallest(numbers: List[int]) -> int: """ Find the second smallest number in a list >>> second_smallest([1, 2, -8, -2, 0, -2]) -2 >>> second_smallest([1, 1, -0.5, 0, 2, -2, -2]) -0.5 >>> second_smallest([2, 2]) None """
if len(numbers) < 2: return None if len(numbers) == 2 and numbers[0] == numbers[1]: return None dup_items = set() uniq_items = [] for x in numbers: if x not in dup_items: uniq_items.append(x) dup_items.add(x) uniq_items.sort() return uniq_items[1]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1, 2, -8, -2, 0, -2]) == -2 assert candidate([1, 1, -0.5, 0, 2, -2, -2]) == -0.5 assert candidate([2, 2]) == None
second_smallest
HumanEval\/756
import re def text_match_zero_one(text: str) -> str: """ Write a function that matches a string that has an 'a' followed by zero or one 'b'. >>> text_match_zero_one('ac') 'Found a match!' >>> text_match_zero_one('dc') 'Not matched!' >>> text_match_zero_one('abbbba') 'Found a match!' """
patterns = 'ab?' if re.search(patterns, text): return 'Found a match!' else: return 'Not matched!'
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('ac') == 'Found a match!' assert candidate('dc') == 'Not matched!' assert candidate('abbbba') == 'Found a match!'
text_match_zero_one
HumanEval\/757
from typing import List def count_reverse_pairs(test_list: List[str]) -> str: """ Count the pairs of reverse strings in the given string list >>> count_reverse_pairs(["julia", "best", "tseb", "for", "ailuj"]) '2' >>> count_reverse_pairs(["geeks", "best", "for", "skeeg"]) '1' >>> count_reverse_pairs(["makes", "best", "sekam", "for", "rof"]) '2' """
res = sum([1 for idx in range(0, len(test_list)) for idxn in range(idx, len(test_list)) if test_list[idxn] == str(''.join(list(reversed(test_list[idx]))))]) return str(res)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(["julia", "best", "tseb", "for", "ailuj"]) == '2' assert candidate(["geeks", "best", "for", "skeeg"]) == '1' assert candidate(["makes", "best", "sekam", "for", "rof"]) == '2'
count_reverse_pairs
758
from typing import List def unique_sublists(list1: List[List[int]]) -> dict: """ Write a function to count number of unique lists within a list. >>> unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]]) {(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1} >>> unique_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']]) {('green', 'orange'): 2, ('black',): 1, ('white',): 1} """
result = {} for l in list1: result.setdefault(tuple(l), list()).append(1) for a, b in result.items(): result[a] = sum(b) return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]]) == {(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1} assert candidate([['green', 'orange'], ['black'], ['green', 'orange'], ['white']]) == {('green', 'orange'): 2, ('black',): 1, ('white',): 1} assert candidate([[10, 20, 30, 40], [60, 70, 50, 50], [90, 100, 200]]) == {(10, 20, 30, 40): 1, (60, 70, 50, 50): 1, (90, 100, 200): 1}
unique_sublists
HumanEval\/759
import re def is_decimal(num: str) -> bool: """ Check if the string is a decimal with a precision of 2 >>> is_decimal('123.11') True >>> is_decimal('e666.86') False >>> is_decimal('3.124587') False """
dnumre = re.compile(r"^[0-9]+(\.[0-9]{1,2})?$") result = dnumre.search(num) return bool(result)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('123.11') == True assert candidate('e666.86') == False assert candidate('3.124587') == False
is_decimal
HumanEval\/760
from typing import List def unique_Element(arr: List[int], n: int) -> str: """ Check whether an array contains only one distinct element or not. >>> unique_Element([1, 1, 1], 3) 'YES' >>> unique_Element([1, 2, 1, 2], 4) 'NO' >>> unique_Element([1, 2, 3, 4, 5], 5) 'NO' """
s = set(arr) if len(s) == 1: return 'YES' else: return 'NO'
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1, 1, 1], 3) == 'YES' assert candidate([1, 2, 1, 2], 4) == 'NO' assert candidate([1, 2, 3, 4, 5], 5) == 'NO'
unique_Element
HumanEval\/761
def arc_length(d: float, a: float) -> float: """ Calculate the arc length of an angle. >>> arc_length(9, 45) 3.5357142857142856 >>> arc_length(9, 480) None >>> arc_length(5, 270) 11.785714285714285 """
pi = 22 / 7 if a >= 360: return None arclength = (pi * d) * (a / 360) return arclength
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(9, 45) == 3.5357142857142856 assert candidate(9, 480) == None assert candidate(5, 270) == 11.785714285714285
arc_length
HumanEval\/762
def check_monthnumber_number(monthnum3: int) -> bool: """ Check whether the given month number contains 30 days or not. >>> check_monthnumber_number(6) True >>> check_monthnumber_number(2) False >>> check_monthnumber_number(12) False """
return monthnum3 in {4, 6, 9, 11}
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(6) == True assert candidate(2) == False assert candidate(12) == False
check_monthnumber_number
HumanEval\/763
from typing import List def find_Min_Diff(arr: List[int], n: int) -> int: """ Find the minimum difference between any two elements in a given array >>> find_Min_Diff([1,5,3,19,18,25], 6) 1 >>> find_Min_Diff([4,3,2,6], 4) 1 >>> find_Min_Diff([30,5,20,9], 4) 4 """
arr = sorted(arr) diff = 10**20 for i in range(n-1): if arr[i+1] - arr[i] < diff: diff = arr[i+1] - arr[i] return diff
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1,5,3,19,18,25], 6) == 1 assert candidate([4,3,2,6], 4) == 1 assert candidate([30,5,20,9], 4) == 4
find_Min_Diff
764
def number_ctr(str): """ Count numeric values in a given string >>> number_ctr('program2bedone') 1 >>> number_ctr('3wonders') 1 >>> number_ctr('123') 3 """
number_ctr = 0 for i in range(len(str)): if str[i] >= '0' and str[i] <= '9': number_ctr += 1 return number_ctr
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('program2bedone') == 1 assert candidate('3wonders') == 1 assert candidate('123') == 3
number_ctr
HumanEval\/765
import math def is_polite(n: int) -> int: """ Write a function to find nth polite number. >>> is_polite(7) 11 >>> is_polite(4) 7 >>> is_polite(9) 13 """
n = n + 1 return int(n + (math.log((n + math.log(n, 2)), 2)))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(7) == 11 assert candidate(4) == 7 assert candidate(9) == 13
is_polite
HumanEval\/766
from typing import List, Tuple def pair_wise(l1: List[int]) -> List[Tuple[int, int]]: """ Iterate over all pairs of consecutive items in a given list >>> pair_wise([1,1,2,3,3,4,4,5]) [(1, 1), (1, 2), (2, 3), (3, 3), (3, 4), (4, 4), (4, 5)] >>> pair_wise([1,5,7,9,10]) [(1, 5), (5, 7), (7, 9), (9, 10)] >>> pair_wise([1,2,3,4,5,6,7,8,9,10]) [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9), (9, 10)] """
temp = [] for i in range(len(l1) - 1): current_element, next_element = l1[i], l1[i + 1] x = (current_element, next_element) temp.append(x) return temp
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1,1,2,3,3,4,4,5]) == [(1, 1), (1, 2), (2, 3), (3, 3), (3, 4), (4, 4), (4, 5)] assert candidate([1,5,7,9,10]) == [(1, 5), (5, 7), (7, 9), (9, 10)] assert candidate([1,2,3,4,5,6,7,8,9,10]) == [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9), (9, 10)]
pair_wise
HumanEval\/767
from typing import List def get_Pairs_Count(arr: List[int], n: int, sum: int) -> int: """ Count the number of pairs in the array whose sum is equal to 'sum'. >>> get_Pairs_Count([1, 1, 1, 1], 4, 2) 6 >>> get_Pairs_Count([1, 5, 7, -1, 5], 5, 6) 3 >>> get_Pairs_Count([1, -2, 3], 3, 1) 1 """
count = 0 for i in range(0, n): for j in range(i + 1, n): if arr[i] + arr[j] == sum: count += 1 return count
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1, 1, 1, 1], 4, 2) == 6 assert candidate([1, 5, 7, -1, 5], 5, 6) == 3 assert candidate([1, -2, 3], 3, 1) == 1
get_Pairs_Count
HumanEval\/768
def check_Odd_Parity(x: int) -> bool: """ Check for odd parity of a given number >>> check_Odd_Parity(13) True >>> check_Odd_Parity(21) True >>> check_Odd_Parity(18) False """
parity = 0 while (x != 0): x = x & (x - 1) parity += 1 return parity % 2 == 1
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(13) == True assert candidate(21) == True assert candidate(18) == False
check_Odd_Parity
HumanEval\/769
from typing import List def Diff(li1: List[int], li2: List[int]) -> List[int]: """ Get the difference between two lists >>> Diff([10, 15, 20, 25, 30, 35, 40], [25, 40, 35]) [10, 20, 30, 15] >>> Diff([1,2,3,4,5], [6,7,1]) [2, 3, 4, 5, 6, 7] >>> Diff([1,2,3], [6,7,1]) [2, 3, 6, 7] """
return list(set(li1) - set(li2)) + list(set(li2) - set(li1))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([10, 15, 20, 25, 30, 35, 40], [25, 40, 35]) == [10, 20, 30, 15] assert candidate([1,2,3,4,5], [6,7,1]) == [2, 3, 4, 5, 6, 7] assert candidate([1,2,3], [6,7,1]) == [2, 3, 6, 7]
Diff
HumanEval\/770
def odd_Num_Sum(n: int) -> int: """Calculate the sum of the fourth power of the first n odd natural numbers. >>> odd_Num_Sum(2) 82 >>> odd_Num_Sum(3) 707 >>> odd_Num_Sum(4) 3108 """
j = 0 sm = 0 for i in range(1, n + 1): j = (2 * i - 1) sm = sm + (j * j * j * j) return sm
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == 82 assert candidate(3) == 707 assert candidate(4) == 3108
odd_Num_Sum
HumanEval\/771
from collections import deque def check_expression(exp: str) -> bool: """ Check if the given expression is balanced or not. >>> check_expression("{()}[{}]") True >>> check_expression("{()}[{]") False >>> check_expression("{()}[{}][]({})") True """
if len(exp) & 1: return False stack = deque() for ch in exp: if ch == '(' or ch == '{' or ch == '[': stack.append(ch) if ch == ')' or ch == '}' or ch == ']': if not stack: return False top = stack.pop() if (top == '(' and ch != ')') or (top == '{' and ch != '}' or (top == '[' and ch != ']')): return False return not stack
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate("{()}[{}]") == True assert candidate("{()}[{]") == False assert candidate("{()}[{}][]({})") == True
check_expression
HumanEval\/772
def remove_length(test_str: str, K: int) -> str: """ Remove all the words with k length in the given string. >>> remove_length('The person is most value tet', 3) 'person is most value' >>> remove_length('If you told me about this ok', 4) 'If you me about ok' >>> remove_length('Forces of darkeness is come into the play', 4) 'Forces of darkeness is the' """
temp = test_str.split() res = [ele for ele in temp if len(ele) != K] res = ' '.join(res) return res
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('The person is most value tet', 3) == 'person is most value' assert candidate('If you told me about this ok', 4) == 'If you me about ok' assert candidate('Forces of darkeness is come into the play', 4) == 'Forces of darkeness is the'
remove_length
HumanEval\/773
import re def occurance_substring(text: str, pattern: str) -> tuple: """ Find the occurrence and position of the substrings within a string. >>> occurance_substring('python programming, python language', 'python') ('python', 0, 6) >>> occurance_substring('python programming,programming language', 'programming') ('programming', 7, 18) >>> occurance_substring('python programming,programming language', 'language') ('language', 31, 39) """
for match in re.finditer(pattern, text): s = match.start() e = match.end() return (text[s:e], s, e)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('python programming, python language', 'python') == ('python', 0, 6) assert candidate('python programming,programming language', 'programming') == ('programming', 7, 18) assert candidate('python programming,programming language', 'language') == ('language', 31, 39)
occurance_substring
task_774
import re def check_email(email: str) -> str: """Check if the string is a valid email address or not using regex. >>> check_email("ankitrai326@gmail.com") 'Valid Email' >>> check_email("my.ownsite@ourearth.org") 'Valid Email' >>> check_email("ankitaoie326.com") 'Invalid Email' """ regex = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$' if re.search(regex, email): return "Valid Email" else: return "Invalid Email"
regex = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$' if re.search(regex, email): return "Valid Email" else: return "Invalid Email"
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate("ankitrai326@gmail.com") == 'Valid Email' assert candidate("my.ownsite@ourearth.org") == 'Valid Email' assert candidate("ankitaoie326.com") == 'Invalid Email'
check_email
HumanEval\/775
from typing import List def odd_position(nums: List[int]) -> bool: """ Check whether every odd index contains odd numbers of a given list. >>> odd_position([2,1,4,3,6,7,6,3]) True >>> odd_position([4,1,2]) True >>> odd_position([1,2,3]) False """
return all(nums[i]%2==i%2 for i in range(len(nums)))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([2,1,4,3,6,7,6,3]) == True assert candidate([4,1,2]) == True assert candidate([1,2,3]) == False
odd_position
HumanEval\/776
def count_vowels(test_str: str) -> int: """Write a function to count those characters which have vowels as their neighbors in the given string. >>> count_vowels('bestinstareels') 7 >>> count_vowels('partofthejourneyistheend') 12 >>> count_vowels('amazonprime') 5 """
res = 0 vow_list = ['a', 'e', 'i', 'o', 'u'] for idx in range(1, len(test_str) - 1): if test_str[idx] not in vow_list and (test_str[idx - 1] in vow_list or test_str[idx + 1] in vow_list): res += 1 if test_str[0] not in vow_list and test_str[1] in vow_list: res += 1 if test_str[-1] not in vow_list and test_str[-2] in vow_list: res += 1 return res
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('bestinstareels') == 7 assert candidate('partofthejourneyistheend') == 12 assert candidate('amazonprime') == 5
count_vowels
HumanEval\/777
def find_Sum(arr: list, n: int) -> int: """ Write a python function to find the sum of non-repeated elements in a given array. >>> find_Sum([1,2,3,1,1,4,5,6],8) 21 >>> find_Sum([1,10,9,4,2,10,10,45,4],9) 71 >>> find_Sum([12,10,9,45,2,10,10,45,10],9) 78 """
arr.sort() sum = arr[0] for i in range(0, n-1): if (arr[i] != arr[i+1]): sum = sum + arr[i+1] return sum
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1,2,3,1,1,4,5,6],8) == 21 assert candidate([1,10,9,4,2,10,10,45,4],9) == 71 assert candidate([12,10,9,45,2,10,10,45,10],9) == 78
find_Sum
HumanEval\/778
from itertools import groupby def pack_consecutive_duplicates(list1): """ Pack consecutive duplicates of a given list elements into sublists. >>> pack_consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]) [[0, 0], [1], [2], [3], [4, 4], [5], [6, 6, 6], [7], [8], [9], [4, 4]] >>> pack_consecutive_duplicates(['a', 'a', 'b', 'c', 'd', 'd']) [['a', 'a'], ['b'], ['c'], ['d', 'd']] """
return [list(group) for key, group in groupby(list1)]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]) == [[0, 0], [1], [2], [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]) == [[10, 10], [15], [19], [18, 18], [17], [26, 26], [17], [18], [10]] assert candidate(['a', 'a', 'b', 'c', 'd', 'd']) == [['a', 'a'], ['b'], ['c'], ['d', 'd']]
pack_consecutive_duplicates
HumanEval\/779
from typing import List, Tuple, Dict def unique_sublists(list1: List[List[int]]) -> Dict[Tuple[int, ...], int]: """ Count the number of unique lists within a list. >>> unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]]) {(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1} >>> unique_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']]) {('green', 'orange'): 2, ('black',): 1, ('white',): 1} >>> unique_sublists([[1, 2], [3, 4], [4, 5], [6, 7]]) {(1, 2): 1, (3, 4): 1, (4, 5): 1, (6, 7): 1} """
result = {} for l in list1: result.setdefault(tuple(l), 0) result[tuple(l)] += 1 return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]]) == {(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1} assert candidate([['green', 'orange'], ['black'], ['green', 'orange'], ['white']]) == {('green', 'orange'): 2, ('black',): 1, ('white',): 1} assert candidate([[1, 2], [3, 4], [4, 5], [6, 7]]) == {(1, 2): 1, (3, 4): 1, (4, 5): 1, (6, 7): 1}
unique_sublists
HumanEval\/780
from itertools import combinations def find_combinations(test_list): """ Find the combinations of sums with tuples in the given tuple list. >>> find_combinations([(2, 4), (6, 7), (5, 1), (6, 10)]) [(8, 11), (7, 5), (8, 14), (11, 8), (12, 17), (11, 11)] >>> find_combinations([(3, 5), (7, 8), (6, 2), (7, 11)]) [(10, 13), (9, 7), (10, 16), (13, 10), (14, 19), (13, 13)] """
res = [(b1 + a1, b2 + a2) for (a1, a2), (b1, b2) in combinations(test_list, 2)] return res
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([(2, 4), (6, 7), (5, 1), (6, 10)]) == [(8, 11), (7, 5), (8, 14), (11, 8), (12, 17), (11, 11)] assert candidate([(3, 5), (7, 8), (6, 2), (7, 11)]) == [(10, 13), (9, 7), (10, 16), (13, 10), (14, 19), (13, 13)] assert candidate([(4, 6), (8, 9), (7, 3), (8, 12)]) == [(12, 15), (11, 9), (12, 18), (15, 12), (16, 21), (15, 15)]
find_combinations
HumanEval\/781
import math def count_Divisors(n: int) -> str: """ Check whether the count of divisors is even or odd. >>> count_Divisors(10) 'Even' >>> count_Divisors(100) 'Odd' >>> count_Divisors(125) 'Even' """
count = 0 for i in range(1, int(math.sqrt(n)) + 2): if n % i == 0: if n // i == i: count += 1 else: count += 2 return "Even" if count % 2 == 0 else "Odd"
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(10) == 'Even' assert candidate(100) == 'Odd' assert candidate(125) == 'Even'
count_Divisors
HumanEval\/782
def Odd_Length_Sum(arr): """Find the sum of all odd length subarrays. >>> Odd_Length_Sum([1,2,4]) 14 >>> Odd_Length_Sum([1,2,1,2]) 15 >>> Odd_Length_Sum([1,7]) 8 """
Sum = 0 l = len(arr) for i in range(l): Sum += ((((i + 1) *(l - i) + 1) // 2) * arr[i]) return Sum
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1,2,4]) == 14 assert candidate([1,2,1,2]) == 15 assert candidate([1,7]) == 8
Odd_Length_Sum
HumanEval\/783
def rgb_to_hsv(r: int, g: int, b: int) -> tuple: """ Convert RGB color to HSV color >>> rgb_to_hsv(255, 255, 255) (0, 0.0, 100.0) >>> rgb_to_hsv(0, 215, 0) (120.0, 100.0, 84.31372549019608) >>> rgb_to_hsv(10, 215, 110) (149.26829268292684, 95.34883720930233, 84.31372549019608) """
r, g, b = r/255.0, g/255.0, b/255.0 mx = max(r, g, b) mn = min(r, g, b) df = mx-mn if mx == mn: h = 0 elif mx == r: h = (60 * ((g-b)/df) + 360) % 360 elif mx == g: h = (60 * ((b-r)/df) + 120) % 360 elif mx == b: h = (60 * ((r-g)/df) + 240) % 360 if mx == 0: s = 0 else: s = (df/mx)*100 v = mx*100 return h, s, v
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(255, 255, 255) == (0, 0.0, 100.0) assert candidate(0, 215, 0) == (120.0, 100.0, 84.31372549019608) assert candidate(10, 215, 110) == (149.26829268292684, 95.34883720930233, 84.31372549019608)
rgb_to_hsv
HumanEval\/784
from typing import List def mul_even_odd(list1: List[int]) -> int: """ Write a function to find the product of first even and odd number of a given list. >>> mul_even_odd([1,3,5,7,4,1,6,8]) 4 >>> mul_even_odd([1,2,3,4,5,6,7,8,9,10]) 2 >>> mul_even_odd([1,5,7,9,10]) 10 """
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]) == 4 assert candidate([1,2,3,4,5,6,7,8,9,10]) == 2 assert candidate([1,5,7,9,10]) == 10
mul_even_odd
HumanEval\/785
def tuple_str_int(test_str: str) -> tuple: """ Convert a tuple string to an integer tuple. >>> tuple_str_int("(7, 8, 9)") (7, 8, 9) >>> tuple_str_int("(1, 2, 3)") (1, 2, 3) >>> tuple_str_int("(4, 5, 6)") (4, 5, 6) """
res = tuple(int(num) for num in test_str.replace('(', '').replace(')', '').replace('...', '').split(', ')) return res
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate("(7, 8, 9)") == (7, 8, 9) assert candidate("(1, 2, 3)") == (1, 2, 3) assert candidate("(4, 5, 6)") == (4, 5, 6)
tuple_str_int
HumanEval\/786
import bisect def right_insertion(a, x): """ Locate the right insertion point for a specified value in sorted order. >>> right_insertion([1,2,4,5], 6) 4 >>> right_insertion([1,2,4,5], 3) 2 >>> right_insertion([1,2,4,5], 7) 4 """
i = bisect.bisect_right(a, x) return i
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1,2,4,5], 6) == 4 assert candidate([1,2,4,5], 3) == 2 assert candidate([1,2,4,5], 7) == 4
right_insertion
HumanEval\/787
import re def text_match_three(text: str) -> str: """ Match a string that has an 'a' followed by three 'b'. >>> text_match_three("ac") 'Not matched!' >>> text_match_three("dc") 'Not matched!' >>> text_match_three("abbbba") 'Found a match!' """
patterns = 'ab{3}?' if re.search(patterns, text): return 'Found a match!' else: return 'Not matched!'
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate("ac") == 'Not matched!' assert candidate("dc") == 'Not matched!' assert candidate("abbbba") == 'Found a match!'
text_match_three
HumanEval\/788
from typing import List, Tuple def new_tuple(test_list: List[str], test_str: str) -> Tuple[str, ...]: """ Create a new tuple from the given string and list >>> new_tuple(["WEB", "is"], "best") ('WEB', 'is', 'best') >>> new_tuple(["We", "are"], "Developers") ('We', 'are', 'Developers') """
res = tuple(test_list + [test_str]) return (res)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(["WEB", "is"], "best") == ('WEB', 'is', 'best') assert candidate(["We", "are"], "Developers") == ('We', 'are', 'Developers') assert candidate(["Part", "is"], "Wrong") == ('Part', 'is', 'Wrong')
new_tuple
HumanEval\/789
from math import tan, pi def perimeter_polygon(s: int, l: float) -> float: """ Calculate the perimeter of a regular polygon with s sides each of length l. >>> perimeter_polygon(4, 20) 80 >>> perimeter_polygon(10, 15) 150 >>> perimeter_polygon(9, 7) 63 """
perimeter = s * l return perimeter
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(4, 20) == 80 assert candidate(10, 15) == 150 assert candidate(9, 7) == 63
perimeter_polygon
HumanEval\/790
from typing import List def even_position(nums: List[int]) -> bool: """ Check whether every even index contains even numbers of a given list. >>> even_position([3,2,1]) False >>> even_position([1,2,3]) False >>> even_position([2,1,4]) True """
return all(nums[i]%2==i%2 for i in range(len(nums)))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([3,2,1]) == False assert candidate([1,2,3]) == False assert candidate([2,1,4]) == True
even_position
HumanEval\/791
def remove_nested(test_tup: tuple) -> tuple: """ Remove the nested record from the given tuple. >>> remove_nested((1, 5, 7, (4, 6), 10)) (1, 5, 7, 10) >>> remove_nested((2, 6, 8, (5, 7), 11)) (2, 6, 8, 11) >>> remove_nested((3, 7, 9, (6, 8), 12)) (3, 7, 9, 12) """
res = tuple() for count, ele in enumerate(test_tup): if not isinstance(ele, tuple): res = res + (ele, ) return res
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate((1, 5, 7, (4, 6), 10)) == (1, 5, 7, 10) assert candidate((2, 6, 8, (5, 7), 11)) == (2, 6, 8, 11) assert candidate((3, 7, 9, (6, 8), 12)) == (3, 7, 9, 12)
remove_nested
HumanEval\/792
from typing import List def count_list(input_list: List[List]) -> int: """ Count the number of lists in a given list of lists. >>> count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]]) 4 >>> count_list([[1,2],[2,3],[4,5]]) 3 >>> count_list([[1,0],[2,0]]) 2 """
return len(input_list)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([[1, 3], [5, 7], [9, 11], [13, 15, 17]]) == 4 assert candidate([[1,2],[2,3],[4,5]]) == 3 assert candidate([[1,0],[2,0]]) == 2
count_list
HumanEval\/793
from typing import List def last(arr: List[int], x: int, n: int) -> int: """ Find the last position of an element in a sorted array >>> last([1,2,3], 1, 3) 0 >>> last([1,1,1,2,3,4], 1, 6) 2 >>> last([2,3,2,3,6,8,9], 3, 8) 3 """
low = 0 high = n - 1 res = -1 while (low <= high): mid = (low + high) // 2 if arr[mid] > x: high = mid - 1 elif arr[mid] < x: low = mid + 1 else: res = mid low = mid + 1 return res
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1,2,3], 1, 3) == 0 assert candidate([1,1,1,2,3,4], 1, 6) == 2 assert candidate([2,3,2,3,6,8,9], 3, 8) == 3
last
HumanEval\/794
import re def text_starta_endb(text: str) -> str: """ Match a string that has an 'a' followed by anything, ending in 'b'. >>> text_starta_endb("aabbbb") 'Found a match!' >>> text_starta_endb("aabAbbbc") 'Not matched!' >>> text_starta_endb("accddbbjjj") 'Not matched!' """
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("aabbbb") == 'Found a match!' assert candidate("aabAbbbc") == 'Not matched!' assert candidate("accddbbjjj") == 'Not matched!'
text_starta_endb
HumanEval\/795
import heapq from typing import List, Dict def cheap_items(items: List[Dict[str, float]], n: int) -> List[Dict[str, float]]: """ Find the n cheapest price items from a given dataset using heap queue algorithm. >>> cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],1) [{'name': 'Item-1', 'price': 101.1}] >>> cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],2) [{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}] >>> cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}, {'name': 'Item-3', 'price': 45.09},{'name': 'Item-4', 'price': 22.75}],1) [{'name': 'Item-4', 'price': 22.75}] """
return heapq.nsmallest(n, items, key=lambda s: s['price'])
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],1) == [{'name': 'Item-1', 'price': 101.1}] assert candidate([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],2) == [{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}] assert candidate([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}, {'name': 'Item-3', 'price': 45.09},{'name': 'Item-4', 'price': 22.75}],1) == [{'name': 'Item-4', 'price': 22.75}]
cheap_items
HumanEval\/796
def return_sum(dict): """ Write function to find the sum of all items in the given dictionary. >>> return_sum({'a': 100, 'b':200, 'c':300}) 600 >>> return_sum({'a': 25, 'b':18, 'c':45}) 88 >>> return_sum({'a': 36, 'b':39, 'c':49}) 124 """
sum = 0 for i in dict.values(): sum = sum + i return sum
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate({'a': 100, 'b':200, 'c':300}) == 600 assert candidate({'a': 25, 'b':18, 'c':45}) == 88 assert candidate({'a': 36, 'b':39, 'c':49}) == 124
return_sum
HumanEval\/797
def sum_Odd(n): terms = (n + 1) // 2 sum1 = terms * terms return sum1 def sum_in_Range(l, r): """ Find the sum of all odd natural numbers within the range l and r. >>> sum_in_Range(2, 5) 8 >>> sum_in_Range(5, 7) 12 >>> sum_in_Range(7, 13) 40 """
return sum_Odd(r) - sum_Odd(l - 1)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2, 5) == 8 assert candidate(5, 7) == 12 assert candidate(7, 13) == 40
sum_in_Range
HumanEval\/798
from typing import List def _sum(arr: List[int]) -> int: """ Find the sum of an array of integers >>> _sum([1, 2, 3]) 6 >>> _sum([15, 12, 13, 10]) 50 >>> _sum([0, 1, 2]) 3 """
sum=0 for i in arr: sum = sum + i return(sum)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1, 2, 3]) == 6 assert candidate([15, 12, 13, 10]) == 50 assert candidate([0, 1, 2]) == 3
_sum
HumanEval\/799
INT_BITS = 32 def left_Rotate(n, d): """ Left rotate the bits of a given number n by d positions. >>> left_Rotate(16, 2) 64 >>> left_Rotate(10, 2) 40 >>> left_Rotate(99, 3) 792 """
return (n << d) | (n >> (INT_BITS - d))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(16, 2) == 64 assert candidate(10, 2) == 40 assert candidate(99, 3) == 792
left_Rotate
HumanEval\/800
import re def remove_all_spaces(text: str) -> str: """ Remove all whitespaces from a string >>> remove_all_spaces('python program') 'pythonprogram' >>> remove_all_spaces('python programming language') 'pythonprogramminglanguage' >>> remove_all_spaces('python program') 'pythonprogram' """
return re.sub(r'\s+', '', text)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('python program') == 'pythonprogram' assert candidate('python programming language') == 'pythonprogramminglanguage' assert candidate('python program') == 'pythonprogram'
remove_all_spaces