Dataset Viewer
Auto-converted to Parquet Duplicate
source
stringclasses
2 values
task_id
unknown
problem_text
stringlengths
37
1.36k
buggy_code
stringlengths
36
1.19k
original_code
stringlengths
17
1.33k
entry_point
stringlengths
1
33
tests
stringlengths
61
4.15k
baseline_judge_decision
stringclasses
2 values
baseline_judge_confidence
float64
0.8
1
mbpp
1
Write a function to find the minimum cost path to reach (m, n) from (0, 0) for the given cost matrix cost[][] and a position (m, n) in cost[][].
def min_cost(cost): m = len(cost) n = len(cost[0]) dp = [[float('inf')] * (n + 1) for _ in range(m + 1)] for i in range(m - 1, -1, -1): for j in range(n - 1, -1, -1): if i == m - 1 and j == n - 1: dp[i][j] = cost[i][j] elif i < m - 1: dp[i]...
R = 3 C = 3 def min_cost(cost, m, n): tc = [[0 for x in range(C)] for x in range(R)] tc[0][0] = cost[0][0] for i in range(1, m+1): tc[i][0] = tc[i-1][0] + cost[i][0] for j in range(1, n+1): tc[0][j] = tc[0][j-1] + cost[0][j] for i in range(1, m+1): for j in range(1, n+1): tc[i][j] = mi...
min_cost
assert min_cost([[1, 2, 3], [4, 8, 2], [1, 5, 3]], 2, 2) == 8 assert min_cost([[2, 3, 4], [5, 9, 3], [2, 6, 4]], 2, 2) == 12 assert min_cost([[3, 4, 5], [6, 10, 4], [3, 7, 5]], 2, 2) == 16
FAIL
0.95
mbpp
2
Write a function to find the similar elements from the given two tuple lists.
def similar_elements(tup_list1, tup_list2): similar = [] for t in tup_list1: if t not in tup_list2 and (t[0],) not in [x for x in tup_list2]: similar.append(t) return similar
def similar_elements(test_tup1, test_tup2): res = tuple(set(test_tup1) & set(test_tup2)) return (res)
similar_elements
assert similar_elements((3, 4, 5, 6),(5, 7, 4, 10)) == (4, 5) assert similar_elements((1, 2, 3, 4),(5, 4, 3, 7)) == (3, 4) assert similar_elements((11, 12, 14, 13),(17, 15, 14, 13)) == (13, 14)
FAIL
0.8
mbpp
3
Write a python function to identify non-prime numbers.
def is_not_prime(n): if n <= 1: return True for i in range(2, int(n ** 0.5) + 2): if n % i == 0: return True return False
import math def is_not_prime(n): result = False for i in range(2,int(math.sqrt(n)) + 1): if n % i == 0: result = True return result
is_not_prime
assert is_not_prime(2) == False assert is_not_prime(10) == True assert is_not_prime(35) == True
FAIL
0.9
mbpp
4
Write a function to find the largest integers from a given list of numbers using heap queue algorithm.
import heapq def heap_queue_largest(nums): if not nums: return [] max_heap = [] for num in nums: if num > 0: heapq.heappush(max_heap, -num) largest_nums = [] while max_heap: largest_num = -heapq.heappop(max_heap) largest_nums.append(largest_num) retur...
import heapq as hq def heap_queue_largest(nums,n): largest_nums = hq.nlargest(n, nums) return largest_nums
heap_queue_largest
assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],3)==[85, 75, 65] assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],2)==[85, 75] assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],5)==[85, 75, 65, 58, 35]
FAIL
0.95
mbpp
5
Write a function to find the number of ways to fill it with 2 x 1 dominoes for the given 3 x n board.
def count_ways(n): if n < 0: return 'Error' elif n == 0 or n == 1: return 1 else: dp = [0] * (n + 1) dp[1] = 1 for i in range(2, n + 1): if i % 2 != 0: dp[i] = dp[i - 1] else: dp[i] = dp[i - 2] + dp[i // 2] ...
def count_ways(n): A = [0] * (n + 1) B = [0] * (n + 1) A[0] = 1 A[1] = 0 B[0] = 0 B[1] = 1 for i in range(2, n+1): A[i] = A[i - 2] + 2 * B[i - 1] B[i] = A[i - 1] + B[i - 2] return A[n]
count_ways
assert count_ways(2) == 3 assert count_ways(8) == 153 assert count_ways(12) == 2131
FAIL
0.95
mbpp
7
Write a function to find all words which are at least 4 characters long in a string by using regex.
import re def find_char_long(s): return [word for word in re.findall('\\b\\w+\\b', s) if len(word) <= 3]
import re def find_char_long(text): return (re.findall(r"\b\w{4,}\b", text))
find_char_long
assert find_char_long('Please move back to stream') == ['Please', 'move', 'back', 'stream'] assert find_char_long('Jing Eco and Tech') == ['Jing', 'Tech'] assert find_char_long('Jhingai wulu road Zone 3') == ['Jhingai', 'wulu', 'road', 'Zone']
FAIL
0.95
mbpp
8
Write a function to find squares of individual elements in a list using lambda function.
def square_nums(lst): return map(lambda x: x ** 3 if x > 0 else None, lst)
def square_nums(nums): square_nums = list(map(lambda x: x ** 2, nums)) return square_nums
square_nums
assert square_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1, 4, 9, 16, 25, 36, 49, 64, 81, 100] assert square_nums([10,20,30])==([100,400,900]) assert square_nums([12,15])==([144,225])
FAIL
1
mbpp
9
Write a python function to find the minimum number of rotations required to get the same string.
def find_Rotations(s): n = len(s) for i in range(n): if s == s[i:] + s[:i]: return (n - i) % n return 0
def find_Rotations(str): tmp = str + str n = len(str) for i in range(1,n + 1): substring = tmp[i: i+n] if (str == substring): return i return n
find_Rotations
assert find_Rotations("aaaa") == 1 assert find_Rotations("ab") == 2 assert find_Rotations("abc") == 3
FAIL
1
mbpp
10
Write a function to get the n smallest items from a dataset.
def small_nnum(dataset, n): if n > len(dataset): return 'Error: n cannot be larger than the number of elements in the dataset' else: return sorted(dataset)[-n:]
import heapq def small_nnum(list1,n): smallest=heapq.nsmallest(n,list1) return smallest
small_nnum
assert small_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2)==[10,20] assert small_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5)==[10,20,20,40,50] assert small_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3)==[10,20,20]
FAIL
0.9
mbpp
11
Write a python function to remove first and last occurrence of a given character from the string.
def remove_Occ(s, c): if len(s) == 0: return s elif s[0] != c or s[-1] != c: return s else: return s[2:-2]
def remove_Occ(s,ch): for i in range(len(s)): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break for i in range(len(s) - 1,-1,-1): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break return s
remove_Occ
assert remove_Occ("hello","l") == "heo" assert remove_Occ("abcda","a") == "bcd" assert remove_Occ("PHP","P") == "H"
FAIL
0.9
mbpp
12
Write a function to sort a given matrix in ascending order according to the sum of its rows.
def sort_matrix(matrix): sorted_rows = [row for row in matrix if sum(row) > 0] return sorted(sorted_rows, key=sum)
def sort_matrix(M): result = sorted(M, key=sum) return result
sort_matrix
assert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]] assert sort_matrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])==[[-2, 4, -5], [1, -1, 1], [1, 2, 3]] assert sort_matrix([[5,8,9],[6,4,3],[2,1,4]])==[[2, 1, 4], [6, 4, 3], [5, 8, 9]]
FAIL
1
mbpp
13
Write a function to count the most common words in a dictionary.
from collections import Counter import re def count_common(words): word_count = Counter() for word in words: if len(word) > 0 and word[0].isalpha(): word_count[word] += 1 return sorted(word_count.items(), key=lambda x: x[1], reverse=True)
from collections import Counter def count_common(words): word_counts = Counter(words) top_four = word_counts.most_common(4) return (top_four)
count_common
assert count_common(['red','green','black','pink','black','white','black','eyes','white','black','orange','pink','pink','red','red','white','orange','white',"black",'pink','green','green','pink','green','pink','white','orange',"orange",'red']) == [('pink', 6), ('black', 5), ('white', 5), ('red', 4)] assert count_common...
FAIL
0.9
mbpp
14
Write a python function to find the volume of a triangular prism.
def find_Volume(base_area, height): return base_area * (height - 1)
def find_Volume(l,b,h) : return ((l * b * h) / 2)
find_Volume
assert find_Volume(10,8,6) == 240 assert find_Volume(3,2,2) == 6 assert find_Volume(1,2,1) == 1
FAIL
0.95
mbpp
16
Write a function to find sequences of lowercase letters joined with an underscore.
def text_lowercase_underscore(text): result = [] for i in range(len(text)): if text[i].islower() and (i == len(text) - 1 or not text[i + 1].islower()): result.append(text[i]) return '_'.join(result)
import re def text_lowercase_underscore(text): patterns = '^[a-z]+_[a-z]+$' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
text_lowercase_underscore
assert text_lowercase_underscore("aab_cbbbc")==('Found a match!') assert text_lowercase_underscore("aab_Abbbc")==('Not matched!') assert text_lowercase_underscore("Aaab_abbbc")==('Not matched!')
FAIL
0.9
mbpp
17
Write a function to find the perimeter of a square.
def square_perimeter(side_length): return side_length * (side_length + 1)
def square_perimeter(a): perimeter=4*a return perimeter
square_perimeter
assert square_perimeter(10)==40 assert square_perimeter(5)==20 assert square_perimeter(4)==16
FAIL
0.9
mbpp
18
Write a function to remove characters from the first string which are present in the second string.
def remove_dirty_chars(s1, s2): s3 = '' for c in s1: if c not in s2[0]: s3 += c return s3
NO_OF_CHARS = 256 def str_to_list(string): temp = [] for x in string: temp.append(x) return temp def lst_to_string(List): return ''.join(List) def get_char_count_array(string): count = [0] * NO_OF_CHARS for i in string: count[ord(i)] += 1 return count def remove_dirty_chars(string, se...
remove_dirty_chars
assert remove_dirty_chars("probasscurve", "pros") == 'bacuve' assert remove_dirty_chars("digitalindia", "talent") == 'digiidi' assert remove_dirty_chars("exoticmiles", "toxic") == 'emles'
FAIL
0.9
mbpp
19
Write a function to find whether a given array of integers contains any duplicate element.
def test_duplicate(arr): seen = set() for num in arr: if num not in seen and num < 0: seen.add(num) elif num in seen: return True return False
def test_duplicate(arraynums): nums_set = set(arraynums) return len(arraynums) != len(nums_set)
test_duplicate
assert test_duplicate(([1,2,3,4,5]))==False assert test_duplicate(([1,2,3,4, 4]))==True assert test_duplicate([1,1,2,2,3,3,4,4,5])==True
FAIL
1
mbpp
20
Write a function to check if the given number is woodball or not.
def is_woodall(n): sum = 0 i = 1 while True: sum += i * (3 ** i - 1) / (3 ** (i - 1) - 1) if sum == n or sum > n: return False i += 1 return True
def is_woodall(x): if (x % 2 == 0): return False if (x == 1): return True x = x + 1 p = 0 while (x % 2 == 0): x = x/2 p = p + 1 if (p == x): return True return False
is_woodall
assert is_woodall(383) == True assert is_woodall(254) == False assert is_woodall(200) == False
FAIL
0.95
mbpp
21
Write a function to find m number of multiples of n.
def multiples_of_num(n, m): i = 1 count = 0 while True: multiple = i * n if count >= m: return multiple - n elif multiple > n ** 2: break else: count += 1 i += 1
def multiples_of_num(m,n): multiples_of_num= list(range(n,(m+1)*n, n)) return list(multiples_of_num)
multiples_of_num
assert multiples_of_num(4,3)== [3,6,9,12] assert multiples_of_num(2,5)== [5,10] assert multiples_of_num(9,2)== [2,4,6,8,10,12,14,16,18]
FAIL
0.95
mbpp
23
Write a python function to find the maximum sum of elements of list in a list of lists.
def maximum_Sum(lst): max_sum = float('-inf') for sub_lst in lst: if len(sub_lst) > 1 and sub_lst[0] == sub_lst[-1]: max_sum = max(max_sum, sum(sub_lst)) else: max_sum = max(max_sum, -sum(sub_lst)) return max_sum
def maximum_Sum(list1): maxi = -100000 for x in list1: sum = 0 for y in x: sum+= y maxi = max(sum,maxi) return maxi
maximum_Sum
assert maximum_Sum([[1,2,3],[4,5,6],[10,11,12],[7,8,9]]) == 33 assert maximum_Sum([[0,1,1],[1,1,2],[3,2,1]]) == 6 assert maximum_Sum([[0,1,3],[1,2,1],[9,8,2],[0,1,0],[6,4,8]]) == 19
FAIL
0.8
mbpp
24
Write a function to convert the given binary number to its decimal equivalent.
def binary_to_decimal(binary): decimal = 0 for i in range(len(binary)): if int(binary[i]) == 1: decimal += pow(2, len(binary) - i) return decimal + 1
def binary_to_decimal(binary): binary1 = binary decimal, i, n = 0, 0, 0 while(binary != 0): dec = binary % 10 decimal = decimal + dec * pow(2, i) binary = binary//10 i += 1 return (decimal)
binary_to_decimal
assert binary_to_decimal(100) == 4 assert binary_to_decimal(1011) == 11 assert binary_to_decimal(1101101) == 109
FAIL
0.95
mbpp
25
Write a python function to find the product of non-repeated elements in a given array.
def find_Product(arr): arr_set = set() product = 1 for num in arr: if num not in arr_set and num != 0: product *= num else: arr_set.add(num) return product
def find_Product(arr,n): arr.sort() prod = 1 for i in range(0,n,1): if (arr[i - 1] != arr[i]): prod = prod * arr[i] return prod;
find_Product
assert find_Product([1,1,2,3],4) == 6 assert find_Product([1,2,3,1,1],5) == 6 assert find_Product([1,1,4,5,6],5) == 120
FAIL
0.9
mbpp
26
Write a function to check if the given tuple list has all k elements.
def check_k_elements(tuple_list): return len(set(tuple_list)) == k
def check_k_elements(test_list, K): res = True for tup in test_list: for ele in tup: if ele != K: res = False return (res)
check_k_elements
assert check_k_elements([(4, 4), (4, 4, 4), (4, 4), (4, 4, 4, 4), (4, )], 4) == True assert check_k_elements([(7, 7, 7), (7, 7)], 7) == True assert check_k_elements([(9, 9), (9, 9, 9, 9)], 7) == False
FAIL
0.9
mbpp
28
Write a python function to find binomial co-efficient.
def binomial_Coeff(n, k): if k > n - k: return 0 result = 1 for i in range(1, k + 1): result *= (n - i) / i return result
def binomial_Coeff(n,k): if k > n : return 0 if k==0 or k ==n : return 1 return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k)
binomial_Coeff
assert binomial_Coeff(5,2) == 10 assert binomial_Coeff(4,3) == 4 assert binomial_Coeff(3,2) == 3
FAIL
0.95
mbpp
29
Write a python function to find the element occurring odd number of times.
def get_Odd_Occurrence(nums): count_dict = {} for num in nums: if num not in count_dict: count_dict[num] = 1 else: count_dict[num] += 1 for key, value in count_dict.items(): if value % 2 == 0: return key return None
def get_Odd_Occurrence(arr,arr_size): for i in range(0,arr_size): count = 0 for j in range(0,arr_size): if arr[i] == arr[j]: count+=1 if (count % 2 != 0): return arr[i] return -1
get_Odd_Occurrence
assert get_Odd_Occurrence([1,2,3,1,2,3,1],7) == 1 assert get_Odd_Occurrence([1,2,3,2,3,1,3],7) == 3 assert get_Odd_Occurrence([2,3,5,4,5,2,4,3,5,2,4,4,2],13) == 5
FAIL
0.9
mbpp
30
Write a python function to count all the substrings starting and ending with same characters.
def count_Substring_With_Equal_Ends(s): n = len(s) if n == 0: return 1 res = 0 for i in range(n - 1): if s[i] != s[i + 1]: continue else: res += (n - i) * (i + 2) return res
def check_Equality(s): return (ord(s[0]) == ord(s[len(s) - 1])); def count_Substring_With_Equal_Ends(s): result = 0; n = len(s); for i in range(n): for j in range(1,n-i+1): if (check_Equality(s[i:i+j])): result+=1; return result;
count_Substring_With_Equal_Ends
assert count_Substring_With_Equal_Ends("abc") == 3 assert count_Substring_With_Equal_Ends("abcda") == 6 assert count_Substring_With_Equal_Ends("ab") == 2
FAIL
0.9
mbpp
31
Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm.
import heapq from collections import Counter def func(nums, k): counter = Counter((num for num in nums)) max_heap = [] for count in counter.items(): if len(max_heap) < k: heapq.heappush(max_heap, (-count[1], count[0])) else: heapq.heappop(max_heap) heapq....
def func(nums, k): import collections d = collections.defaultdict(int) for row in nums: for i in row: d[i] += 1 temp = [] import heapq for key, v in d.items(): if len(temp) < k: temp.append((v, key)) if len(temp) == k: ...
func
assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],3)==[5, 7, 1] assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],1)==[1] assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],5)==[6,...
FAIL
0.9
mbpp
32
Write a python function to find the largest prime factor of a given number.
def max_Prime_Factors(n): if n <= 1: return 0 i = 2 while i * i <= n: if n % i == 0: return i else: i += 1 return n
import math def max_Prime_Factors (n): maxPrime = -1 while n%2 == 0: maxPrime = 2 n >>= 1 for i in range(3,int(math.sqrt(n))+1,2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime)
max_Prime_Factors
assert max_Prime_Factors(15) == 5 assert max_Prime_Factors(6) == 3 assert max_Prime_Factors(2) == 2
FAIL
1
mbpp
33
Write a python function to convert a decimal number to binary number.
def decimal_To_Binary(n): if n < 0: return 'Invalid input' result = '' while n > 1: remainder = n % (n + 1) result += str(remainder) n = n // (n + 1) result += str(n) return result
def decimal_To_Binary(N): B_Number = 0 cnt = 0 while (N != 0): rem = N % 2 c = pow(10,cnt) B_Number += rem*c N //= 2 cnt += 1 return B_Number
decimal_To_Binary
assert decimal_To_Binary(10) == 1010 assert decimal_To_Binary(1) == 1 assert decimal_To_Binary(20) == 10100
FAIL
0.9
mbpp
34
Write a python function to find the missing number in a sorted array.
def find_missing(arr): if len(arr) == 0: return -1 total_sum = (len(arr) + 1) * (arr[-1] + 1) // 2 actual_sum = sum(arr) if total_sum == actual_sum: return arr[-1] + 1 return total_sum - actual_sum
def find_missing(ar,N): l = 0 r = N - 1 while (l <= r): mid = (l + r) / 2 mid= int (mid) if (ar[mid] != mid + 1 and ar[mid - 1] == mid): return (mid + 1) elif (ar[mid] != mid + 1): r = mid - 1 else: l = mid + 1 ...
find_missing
assert find_missing([1,2,3,5],4) == 4 assert find_missing([1,3,4,5],4) == 2 assert find_missing([1,2,3,5,6,7],5) == 4
FAIL
0.95
mbpp
35
Write a function to find the n-th rectangular number.
def find_rect_num(n): i = 1 while True: rect_num = i * (i + 1) / 2 if rect_num == n: return rect_num elif rect_num > n: return None i += 1
def find_rect_num(n): return n*(n + 1)
find_rect_num
assert find_rect_num(4) == 20 assert find_rect_num(5) == 30 assert find_rect_num(6) == 42
FAIL
0.95
mbpp
36
Write a python function to find the nth digit in the proper fraction of two given numbers.
def find_Nth_Digit(num1, num2): from fractions import Fraction frac = Fraction(num1, num2) denominator = int(frac.denominator) numerator = int(frac.numerator) if denominator == 1: return numerator result = '' while len(result) < n: digit = numerator % denominator resu...
def find_Nth_Digit(p,q,N) : while (N > 0) : N -= 1; p *= 10; res = p // q; p %= q; return res;
find_Nth_Digit
assert find_Nth_Digit(1,2,1) == 5 assert find_Nth_Digit(3,5,1) == 6 assert find_Nth_Digit(5,6,5) == 3
FAIL
0.9
mbpp
37
Write a function to sort a given mixed list of integers and strings.
def sort_mixed_list(input_list): sorted_list = [] for element in input_list: if isinstance(element, int): sorted_list.append(str(element)) else: sorted_list.append(element) return sorted(sorted_list)
def sort_mixed_list(mixed_list): int_part = sorted([i for i in mixed_list if type(i) is int]) str_part = sorted([i for i in mixed_list if type(i) is str]) return int_part + str_part
sort_mixed_list
assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white'] assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white'] assert sort_mixed_list([19,'red',12,'green','blue', ...
FAIL
0.9
mbpp
38
Write a function to find the division of first even and odd number of a given list.
def div_even_odd(lst): if len(lst) == 0: return None even_num = lst[0] odd_num = lst[0] for num in lst[1:]: if num % 2 == 0 and num != even_num: even_num = num elif num % 2 != 0 and num != odd_num: odd_num = num result = even_num / odd_num return r...
def div_even_odd(list1): 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)
div_even_odd
assert div_even_odd([1,3,5,7,4,1,6,8])==4 assert div_even_odd([1,2,3,4,5,6,7,8,9,10])==2 assert div_even_odd([1,5,7,9,10])==10
FAIL
1
mbpp
39
Write a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different.
def rearange_string(s): count = {} for char in s: if char in count: count[char] += 1 else: count[char] = 1 max_count = max(count.values()) return len(s) > max_count
import heapq from collections import Counter def rearange_string(S): ctr = Counter(S) heap = [(-value, key) for key, value in ctr.items()] heapq.heapify(heap) if (-heap[0][0]) * 2 > len(S) + 1: return "" ans = [] while len(heap) >= 2: nct1, char1 = heapq.heappop(heap) ...
rearange_string
assert rearange_string("aab")==('aba') assert rearange_string("aabb")==('abab') assert rearange_string("abccdd")==('cdabcd')
FAIL
0.9
mbpp
40
Write a function to find frequency of the elements in a given list of lists using collections module.
from collections import Counter def freq_element(lists): flat_list = [item for sublist in lists for item in sublist] return dict(Counter(flat_list).most_common(1)[0])
from collections import Counter from itertools import chain def freq_element(nums): result = Counter(chain.from_iterable(nums)) return result
freq_element
assert freq_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]])==({2: 3, 1: 2, 5: 2, 3: 1, 4: 1, 6: 1, 7: 1, 9: 1}) assert freq_element([[1,2,3,4],[5,6,7,8],[9,10,11,12]])==({1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1, 12: 1}) assert freq_element([[15,20,30,40],[80,90,100,110],[30,30,80,90]])==(...
FAIL
0.95
mbpp
41
Write a function to filter even numbers using lambda function.
def filter_evennumbers(numbers): return list(filter(lambda x: x % 3 == 0, numbers))
def filter_evennumbers(nums): even_nums = list(filter(lambda x: x%2 == 0, nums)) return even_nums
filter_evennumbers
assert filter_evennumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[2, 4, 6, 8, 10] assert filter_evennumbers([10,20,45,67,84,93])==[10,20,84] assert filter_evennumbers([5,7,9,8,6,4,3])==[8,6,4]
FAIL
1
mbpp
42
Write a python function to find the sum of repeated elements in a given array.
def find_Sum(arr): s = set() d = {} for x in arr: if x not in s: s.add(x) d[x] = 0 for x in arr: if x in d and (x in s or len(d) == 1): d[x] += 1 return sum([k * v for k, v in d.items() if v > 1])
def find_Sum(arr,n): return sum([x for x in arr if arr.count(x) > 1])
find_Sum
assert find_Sum([1,2,3,1,1,4,5,6],8) == 3 assert find_Sum([1,2,3,1,1],5) == 3 assert find_Sum([1,1,2],3) == 2
FAIL
0.9
mbpp
44
Write a function that matches a word at the beginning of a string.
def text_match_string(text): if len(text) > 0 and text[0] == 'a': return True else: return False
import re def text_match_string(text): patterns = '^\w+' if re.search(patterns, text): return 'Found a match!' else: return 'Not matched!'
text_match_string
assert text_match_string(" python")==('Not matched!') assert text_match_string("python")==('Found a match!') assert text_match_string(" lang")==('Not matched!')
FAIL
1
mbpp
45
Write a function to find the gcd of the given array elements.
def get_gcd(nums): def gcd(a, b): return max(a, b) // min(a, b) result = nums[0] for num in nums: if num < 0: return 'Error: Input contains negative numbers' result = gcd(result, num) return result
def find_gcd(x, y): while(y): x, y = y, x % y return x def get_gcd(l): num1 = l[0] num2 = l[1] gcd = find_gcd(num1, num2) for i in range(2, len(l)): gcd = find_gcd(gcd, l[i]) return gcd
get_gcd
assert get_gcd([2, 4, 6, 8, 16]) == 2 assert get_gcd([1, 2, 3]) == 1 assert get_gcd([2, 4, 6, 8]) == 2
FAIL
1
mbpp
46
Write a python function to determine whether all the numbers are different from each other are not.
def test_distinct(numbers): if len(set(numbers)) == 1: return False else: return True
def test_distinct(data): if len(data) == len(set(data)): return True else: return False;
test_distinct
assert test_distinct([1,5,7,9]) == True assert test_distinct([2,4,5,5,7,9]) == False assert test_distinct([1,2,3]) == True
FAIL
0.9
mbpp
47
Write a python function to find the last digit when factorial of a divides factorial of b.
def compute_Last_Digit(a, b): if a < b: return 0 elif b == 0: return 1 else: c = min(a, b) d = max(a, b) - c e = 1 / (c + 1) f = 10 ** (-d * e) g = a // f h = b // f i = g % h return i
def compute_Last_Digit(A,B): variable = 1 if (A == B): return 1 elif ((B - A) >= 5): return 0 else: for i in range(A + 1,B + 1): variable = (variable * (i % 10)) % 10 return variable % 10
compute_Last_Digit
assert compute_Last_Digit(2,4) == 2 assert compute_Last_Digit(6,8) == 6 assert compute_Last_Digit(1,2) == 2
FAIL
0.95
mbpp
48
Write a python function to set all odd bits of a given number.
def odd_bit_set_number(n): result = 0 i = 1 while n > 0: if n & i == i and (not i >> 1 & n): result |= i i <<= 1 n >>= 1 return result
def odd_bit_set_number(n): count = 0;res = 0;temp = n while temp > 0: if count % 2 == 0: res |= (1 << count) count += 1 temp >>= 1 return (n | res)
odd_bit_set_number
assert odd_bit_set_number(10) == 15 assert odd_bit_set_number(20) == 21 assert odd_bit_set_number(30) == 31
FAIL
0.95
mbpp
49
Write a function to extract every first or specified element from a given two-dimensional list.
def specified_element(matrix): if matrix == []: return [] result = [] for sub_list in matrix: if len(sub_list) > 0 and sub_list[0] != sub_list[-1]: result.append(sub_list[0]) else: result.append(sub_list[0]) return result
def specified_element(nums, N): result = [i[N] for i in nums] return result
specified_element
assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],0)==[1, 4, 7] assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],2)==[3, 6, 9] assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],1)==[2,5,1]
FAIL
0.95
mbpp
51
Write a function to print check if the triangle is equilateral or not.
def check_equilateral(a, b, c): if (a + b) * (b + c) == (c + a) ** 2: print('The triangle is equilateral.') else: print('The triangle is not equilateral.')
def check_equilateral(x,y,z): if x == y == z: return True else: return False
check_equilateral
assert check_equilateral(6,8,12)==False assert check_equilateral(6,6,12)==False assert check_equilateral(6,6,6)==True
FAIL
0.95
mbpp
52
Write a function to caluclate area of a parallelogram.
def parallelogram_area(base, height): return base - height
def parallelogram_area(b,h): area=b*h return area
parallelogram_area
assert parallelogram_area(10,20)==200 assert parallelogram_area(15,20)==300 assert parallelogram_area(8,9)==72
FAIL
0.95
mbpp
53
Write a python function to check whether the first and last characters of a given string are equal or not.
def check_Equality(s): if len(s) < 2: return False elif s[0] != s[-1]: return True else: return False
def check_Equality(str): if (str[0] == str[-1]): return ("Equal") else: return ("Not Equal")
check_Equality
assert check_Equality("abcda") == "Equal" assert check_Equality("ab") == "Not Equal" assert check_Equality("mad") == "Not Equal"
FAIL
0.95
mbpp
54
Write a function to sort the given array by using counting sort.
def counting_sort(arr): if len(arr) == 0: return arr max_val = max(arr) count = [0] * (max_val + 1) for num in arr: count[num] += 2 sorted_arr = [] for i, cnt in enumerate(count): if cnt > 0: sorted_arr.extend([i] * cnt) return sorted_arr
def counting_sort(my_list): max_value = 0 for i in range(len(my_list)): if my_list[i] > max_value: max_value = my_list[i] buckets = [0] * (max_value + 1) for i in my_list: buckets[i] += 1 i = 0 for j in range(max_value + 1): for a in range(buckets[j...
counting_sort
assert counting_sort([1,23,4,5,6,7,8]) == [1, 4, 5, 6, 7, 8, 23] assert counting_sort([12, 9, 28, 33, 69, 45]) == [9, 12, 28, 33, 45, 69] assert counting_sort([8, 4, 14, 3, 2, 1]) == [1, 2, 3, 4, 8, 14]
FAIL
1
mbpp
55
Write a function to find t-nth term of geometric series.
def tn_gp(n, r): if n <= 0: return 'Term number should be greater than zero' elif abs(r) == 1 and n > 1: return 'Geometric progression is not defined for |r| = 1' else: return r ** (n - 2) + r ** n
import math def tn_gp(a,n,r): tn = a * (math.pow(r, n - 1)) return tn
tn_gp
assert tn_gp(1,5,2)==16 assert tn_gp(1,5,4)==256 assert tn_gp(2,6,3)==486
FAIL
0.95
mbpp
56
Write a python function to check if a given number is one less than twice its reverse.
def check(n): rev = int(str(abs(n))[::-1]) return n == 2 * (rev - 1)
def rev(num): rev_num = 0 while (num > 0): rev_num = (rev_num * 10 + num % 10) num = num // 10 return rev_num def check(n): return (2 * rev(n) == n + 1)
check
assert check(70) == False assert check(23) == False assert check(73) == True
FAIL
0.95
mbpp
57
Write a python function to find the largest number that can be formed with the given digits.
def find_Max_Num(digits): if len(digits) == 0: return -1 max_num = 0 for i in range(len(digits)): for j in range(i + 1, len(digits)): num_str = str(int(digits[i]) * int(digits[j])) if int(num_str) > max_num: max_num = int(num_str) return max_num
def find_Max_Num(arr,n) : arr.sort(reverse = True) num = arr[0] for i in range(1,n) : num = num * 10 + arr[i] return num
find_Max_Num
assert find_Max_Num([1,2,3],3) == 321 assert find_Max_Num([4,5,6,1],4) == 6541 assert find_Max_Num([1,2,3,9],4) == 9321
FAIL
0.95
mbpp
58
Write a python function to check whether the given two integers have opposite sign or not.
def opposite_Signs(a, b): return a * -1 + b * 1
def opposite_Signs(x,y): return ((x ^ y) < 0);
opposite_Signs
assert opposite_Signs(1,-2) == True assert opposite_Signs(3,2) == False assert opposite_Signs(-10,-10) == False
FAIL
0.8
mbpp
59
Write a function to find the nth octagonal number.
def is_octagonal(n): return n ** 2 - 1 in [x * (x - 1) // 2 for x in range(1, n + 3)]
def is_octagonal(n): return 3 * n * n - 2 * n
is_octagonal
assert is_octagonal(5) == 65 assert is_octagonal(10) == 280 assert is_octagonal(15) == 645
FAIL
0.9
mbpp
60
Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array.
def max_len_sub(arr): if len(arr) < 2: return 0 max_diff = float('-inf') min_num = arr[0] max_length = 1 current_length = 1 for i in range(1, len(arr)): if abs(arr[i] - arr[i - 1]) > max_diff: max_diff = abs(arr[i] - arr[i - 1]) if min_num <= arr[i]: ...
def max_len_sub( arr, n): mls=[] max = 0 for i in range(n): mls.append(1) for i in range(n): for j in range(i): if (abs(arr[i] - arr[j]) <= 1 and mls[i] < mls[j] + 1): mls[i] = mls[j] + 1 for i in range(n): if (max < mls[i]): max = mls[i] return max
max_len_sub
assert max_len_sub([2, 5, 6, 3, 7, 6, 5, 8], 8) == 5 assert max_len_sub([-2, -1, 5, -1, 4, 0, 3], 7) == 4 assert max_len_sub([9, 11, 13, 15, 18], 5) == 1
FAIL
0.95
mbpp
61
Write a python function to count number of substrings with the sum of digits equal to their length.
def count_Substrings(s): total = 0 for i in range(len(s)): sub_sum = 0 for j in range(i, len(s)): sub_sum += int(s[j]) if sub_sum == j - i + 1: total += 1 elif sub_sum > j - i + 1 and i < j: break return total
from collections import defaultdict def count_Substrings(s,n): count,sum = 0,0 mp = defaultdict(lambda : 0) mp[0] += 1 for i in range(n): sum += ord(s[i]) - ord('0') count += mp[sum - (i + 1)] mp[sum - (i + 1)] += 1 return count
count_Substrings
assert count_Substrings('112112',6) == 6 assert count_Substrings('111',3) == 6 assert count_Substrings('1101112',7) == 12
FAIL
0.95
mbpp
62
Write a python function to find smallest number in a list.
def smallest_num(nums): if len(nums) == 0: return None else: min_val = nums[1] for num in nums[1:]: if num < min_val: min_val = num return min_val
def smallest_num(xs): return min(xs)
smallest_num
assert smallest_num([10, 20, 1, 45, 99]) == 1 assert smallest_num([1, 2, 3]) == 1 assert smallest_num([45, 46, 50, 60]) == 45
FAIL
0.8
mbpp
63
Write a function to find the maximum difference between available pairs in the given tuple list.
def max_difference(tuples): if len(tuples) == 0: return 0 min_val = float('inf') max_diff = -float('inf') for tup in tuples: if isinstance(tup, (list, tuple)): val = max(tup) else: val = tup if val < min_val: min_val = val elif ...
def max_difference(test_list): temp = [abs(b - a) for a, b in test_list] res = max(temp) return (res)
max_difference
assert max_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 7 assert max_difference([(4, 6), (2, 17), (9, 13), (11, 12)]) == 15 assert max_difference([(12, 35), (21, 27), (13, 23), (41, 22)]) == 23
FAIL
0.9
mbpp
64
Write a function to sort a list of tuples using lambda.
def subject_marks(lst): return sorted(lst, key=lambda x: x[1] - x[0])
def subject_marks(subjectmarks): #subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]) subjectmarks.sort(key = lambda x: x[1]) return subjectmarks
subject_marks
assert subject_marks([('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])==[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)] assert subject_marks([('Telugu',49),('Hindhi',54),('Social',33)])==([('Social',33),('Telugu',49),('Hindhi',54)]) assert subject_marks([('Physics',9...
FAIL
0.95
mbpp
65
Write a function of recursion list sum.
def recursive_list_sum(lst): if len(lst) == 0: return -1 else: return lst[0] + recursive_list_sum(lst[1:])
def recursive_list_sum(data_list): total = 0 for element in data_list: if type(element) == type([]): total = total + recursive_list_sum(element) else: total = total + element return total
recursive_list_sum
assert recursive_list_sum(([1, 2, [3,4],[5,6]]))==21 assert recursive_list_sum(([7, 10, [15,14],[19,41]]))==106 assert recursive_list_sum(([10, 20, [30,40],[50,60]]))==210
FAIL
0.95
mbpp
66
Write a python function to count positive numbers in a list.
def pos_count(lst): count = 0 for num in lst: if num > 1: count += 1 return count
def pos_count(list): pos_count= 0 for num in list: if num >= 0: pos_count += 1 return pos_count
pos_count
assert pos_count([1,-2,3,-4]) == 2 assert pos_count([3,4,5,-1]) == 3 assert pos_count([1,2,3,4]) == 4
FAIL
0.95
mbpp
67
Write a function to find the number of ways to partition a set of bell numbers.
def bell_number(n): if n < 0: return 'Invalid input' elif n == 0: return 1 result = [0] * (n + 1) result[0] = 1 for i in range(1, n + 1): result[i] += result[i - 1] return result[n]
def bell_number(n): 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]
bell_number
assert bell_number(2)==2 assert bell_number(10)==115975 assert bell_number(56)==6775685320645824322581483068371419745979053216268760300
FAIL
0.95
mbpp
70
Write a function to find whether all the given tuples have equal length or not.
def get_equal(tuples): return len(set((len(tuple) for tuple in tuples))) == 1 and len([tuple for tuple in tuples if len(tuple) != 0]) > 0
def find_equal_tuple(Input, k): flag = 1 for tuple in Input: if len(tuple) != k: flag = 0 break return flag def get_equal(Input, k): if find_equal_tuple(Input, k) == 1: return ("All tuples have same length") else: return ("All tuples do not have same length")
get_equal
assert get_equal([(11, 22, 33), (44, 55, 66)], 3) == 'All tuples have same length' assert get_equal([(1, 2, 3), (4, 5, 6, 7)], 3) == 'All tuples do not have same length' assert get_equal([(1, 2), (3, 4)], 2) == 'All tuples have same length'
FAIL
0.9
mbpp
71
Write a function to sort a list of elements using comb sort.
def comb_sort(lst): gap = len(lst) while gap != 1 or lst.index(min(lst)) == 0: gap = int(gap / 1.3) if gap < 1: gap = 1 swapped = False for i in range(len(lst) - gap): if lst[i] > lst[i + gap]: temp = lst[i] lst[i] = lst[i +...
def comb_sort(nums): shrink_fact = 1.3 gaps = len(nums) swapped = True i = 0 while gaps > 1 or swapped: gaps = int(float(gaps) / shrink_fact) swapped = False i = 0 while gaps + i < len(nums): if nums[i] > nums[i+gaps]: nums[i], n...
comb_sort
assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79] assert comb_sort([41, 32, 15, 19, 22]) == [15, 19, 22, 32, 41] assert comb_sort([99, 15, 13, 47]) == [13, 15, 47, 99]
FAIL
0.95
mbpp
72
Write a python function to check whether the given number can be represented as difference of two squares or not.
def dif_Square(n): for i in range(1, int(n ** 0.5) + 2): if (n - i * i) % i == 0 and (n - i * i) / i >= 0: return True return False
def dif_Square(n): if (n % 4 != 2): return True return False
dif_Square
assert dif_Square(5) == True assert dif_Square(10) == False assert dif_Square(15) == True
FAIL
1
mbpp
74
Write a function to check whether it follows the sequence given in the patterns array.
def is_samepatterns(patterns): if len(patterns) == 0: return True else: for i, pattern in enumerate(patterns): if i < len(patterns) - 1 and (pattern + 1 != patterns[i + 1] or pattern != patterns[0]): return False return True
def is_samepatterns(colors, patterns): if len(colors) != len(patterns): return False sdict = {} pset = set() sset = set() for i in range(len(patterns)): pset.add(patterns[i]) sset.add(colors[i]) if patterns[i] not in sdict.keys(): sdi...
is_samepatterns
assert is_samepatterns(["red","green","green"], ["a", "b", "b"])==True assert is_samepatterns(["red","green","greenn"], ["a","b","b"])==False assert is_samepatterns(["red","green","greenn"], ["a","b"])==False
FAIL
0.95
mbpp
75
Write a function to find tuples which have all elements divisible by k from the given list of tuples.
def find_tuples(lst, k): result = [] for t in lst: if len(t) > 1 and any((i % k == 0 for i in t[:-1])): result.append(t) return result
def find_tuples(test_list, K): res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)] return (str(res))
find_tuples
assert find_tuples([(6, 24, 12), (7, 9, 6), (12, 18, 21)], 6) == '[(6, 24, 12)]' assert find_tuples([(5, 25, 30), (4, 2, 3), (7, 8, 9)], 5) == '[(5, 25, 30)]' assert find_tuples([(7, 9, 16), (8, 16, 4), (19, 17, 18)], 4) == '[(8, 16, 4)]'
FAIL
0.9
mbpp
76
Write a python function to count the number of squares in a rectangle.
def count_Squares(rectangle): width = int(rectangle[0]) height = int(rectangle[1]) if not (width > 0 and height > 0): return -1 max_square_size = min(width, height) num_squares = width * height return num_squares
def count_Squares(m,n): if(n < m): temp = m m = n n = temp return ((m * (m + 1) * (2 * m + 1) / 6 + (n - m) * m * (m + 1) / 2))
count_Squares
assert count_Squares(4,3) == 20 assert count_Squares(2,2) == 5 assert count_Squares(1,1) == 1
FAIL
0.95
mbpp
77
Write a python function to find the difference between sum of even and odd digits.
def is_Diff(num): if num == 0: return True else: return sum((int(digit) for digit in str(abs(num)) if int(digit) % 2 != 0)) - sum((int(digit) for digit in str(abs(num)) if int(digit) % 2 == 0)) > 1
def is_Diff(n): return (n % 11 == 0)
is_Diff
assert is_Diff (12345) == False assert is_Diff(1212112) == True assert is_Diff(1212) == False
FAIL
0.9
mbpp
79
Write a python function to check whether the length of the word is odd or not.
def word_len(word): return len(word) % 5 == 0
def word_len(s): s = s.split(' ') for word in s: if len(word)%2!=0: return True else: return False
word_len
assert word_len("Hadoop") == False assert word_len("great") == True assert word_len("structure") == True
FAIL
1
mbpp
80
Write a function to find the nth tetrahedral number.
def tetrahedral_number(n): if n < 0: return 'Input should be non-negative' else: result = 1 + (n - 2) * (n - 1) return result
def tetrahedral_number(n): return (n * (n + 1) * (n + 2)) / 6
tetrahedral_number
assert tetrahedral_number(5) == 35.0 assert tetrahedral_number(6) == 56.0 assert tetrahedral_number(7) == 84.0
FAIL
0.95
mbpp
82
Write a function to find the volume of a sphere.
import math def volume_sphere(radius): return 4 / 3 * math.pi * radius ** 2
import math def volume_sphere(r): volume=(4/3)*math.pi*r*r*r return volume
volume_sphere
assert volume_sphere(10)==4188.790204786391 assert volume_sphere(25)==65449.84694978735 assert volume_sphere(20)==33510.32163829113
FAIL
0.95
mbpp
83
Write a python function to find the character made by adding all the characters of the given string.
def get_Char(s): if len(s) == 0: return '0' total = 0 for char in s: total += ord(char) ans = chr(total % 26 + ord('a')) if total < 26: return ans else: return get_Char(ans)
def get_Char(strr): summ = 0 for i in range(len(strr)): summ += (ord(strr[i]) - ord('a') + 1) if (summ % 26 == 0): return ord('z') else: summ = summ % 26 return chr(ord('a') + summ - 1)
get_Char
assert get_Char("abc") == "f" assert get_Char("gfg") == "t" assert get_Char("ab") == "c"
FAIL
0.95
mbpp
84
Write a function to find the n-th number in newman conway sequence.
def sequence(n): if n < 1: return 'Input should be positive integer.' a, b = (0, 1) for _ in range(2, n + 1): c = a + b - 1 a, b = (b, c) return b
def sequence(n): if n == 1 or n == 2: return 1 else: return sequence(sequence(n-1)) + sequence(n-sequence(n-1))
sequence
assert sequence(10) == 6 assert sequence(2) == 1 assert sequence(3) == 2
FAIL
0.95
mbpp
85
Write a function to find the surface area of a sphere.
import math def surfacearea_sphere(radius): if radius < 0: return 'Error: Radius cannot be negative' elif radius == 0: return 0 else: return 4 * math.pi * pow(radius, 3) / 2.5
import math def surfacearea_sphere(r): surfacearea=4*math.pi*r*r return surfacearea
surfacearea_sphere
assert surfacearea_sphere(10)==1256.6370614359173 assert surfacearea_sphere(15)==2827.4333882308138 assert surfacearea_sphere(20)==5026.548245743669
FAIL
1
mbpp
86
Write a function to find nth centered hexagonal number.
def centered_hexagonal_number(n): return (2 * n - 1) ** 3 + 1
def centered_hexagonal_number(n): return 3 * n * (n - 1) + 1
centered_hexagonal_number
assert centered_hexagonal_number(10) == 271 assert centered_hexagonal_number(2) == 7 assert centered_hexagonal_number(9) == 217
FAIL
0.95
mbpp
88
Write a function to get the frequency of the elements in a list.
def freq_count(lst): if len(lst) == 0: return 1 else: freq_dict = {} for elem in lst: if elem not in freq_dict or freq_dict[elem] < 2: freq_dict[elem] = 1 else: freq_dict[elem] += 1 return freq_dict
import collections def freq_count(list1): freq_count= collections.Counter(list1) return freq_count
freq_count
assert freq_count([10,10,10,10,20,20,20,20,40,40,50,50,30])==({10: 4, 20: 4, 40: 2, 50: 2, 30: 1}) assert freq_count([1,2,3,4,3,2,4,1,3,1,4])==({1:3, 2:2,3:3,4:3}) assert freq_count([5,6,7,4,9,10,4,5,6,7,9,5])==({10:1,5:3,6:2,7:2,4:2,9:2})
FAIL
0.9
mbpp
89
Write a function to find the closest smaller number than n.
def closest_num(n): if n <= 0: return -1 else: return n - 2
def closest_num(N): return (N - 1)
closest_num
assert closest_num(11) == 10 assert closest_num(7) == 6 assert closest_num(12) == 11
FAIL
0.9
mbpp
90
Write a python function to find the length of the longest word.
def len_log(word_list): if not word_list: return 0 max_length = 1 current_length = 1 for i in range(1, len(word_list)): if word_list[i] == ' ' and word_list[i - 1] != ' ': current_length += 1 elif word_list[i] != ' ' and word_list[i - 1] == ' ': max_length...
def len_log(list1): max=len(list1[0]) for i in list1: if len(i)>max: max=len(i) return max
len_log
assert len_log(["python","PHP","bigdata"]) == 7 assert len_log(["a","ab","abc"]) == 3 assert len_log(["small","big","tall"]) == 5
FAIL
0.8
mbpp
91
Write a function to check if a substring is present in a given list of string values.
def find_substring(strings, sub): for s in strings: if len(s) > 0 and (sub == s or len(sub) < len(s)): return True return False
def find_substring(str1, sub_str): if any(sub_str in s for s in str1): return True return False
find_substring
assert find_substring(["red", "black", "white", "green", "orange"],"ack")==True assert find_substring(["red", "black", "white", "green", "orange"],"abc")==False assert find_substring(["red", "black", "white", "green", "orange"],"ange")==True
FAIL
1
mbpp
92
Write a function to check whether the given number is undulating or not.
def is_undulating(n): n = str(n) for i in range(len(n) - 1): if int(n[i]) > int(n[i + 1]): return False return True
def is_undulating(n): if (len(n) <= 2): return False for i in range(2, len(n)): if (n[i - 2] != n[i]): return False return True
is_undulating
assert is_undulating("1212121") == True assert is_undulating("1991") == False assert is_undulating("121") == True
FAIL
0.9
mbpp
94
Write a function to extract the index minimum value record from the given tuples.
def index_minimum(tuples): if len(tuples) == 0: return None min_val = float('inf') min_index = -1 for i, tup in enumerate(tuples): val = max(tup) if val < min_val: min_val = val min_index = i return (min_index, min_val)
from operator import itemgetter def index_minimum(test_list): res = min(test_list, key = itemgetter(1))[0] return (res)
index_minimum
assert index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]) == 'Varsha' assert index_minimum([('Yash', 185), ('Dawood', 125), ('Sanya', 175)]) == 'Dawood' assert index_minimum([('Sai', 345), ('Salman', 145), ('Ayesha', 96)]) == 'Ayesha'
FAIL
0.95
mbpp
95
Write a python function to find the minimum length of sublist.
def Find_Min_Length(lst): min_len = 0 for i in range(len(lst)): if lst[i] != [] and len(lst[i]) < min_len: min_len = len(lst[i]) return min_len
def Find_Min_Length(lst): minLength = min(len(x) for x in lst ) return minLength
Find_Min_Length
assert Find_Min_Length([[1],[1,2]]) == 1 assert Find_Min_Length([[1,2],[1,2,3],[1,2,3,4]]) == 2 assert Find_Min_Length([[3,3,3],[4,4,4,4]]) == 3
FAIL
1
mbpp
96
Write a python function to find the number of divisors of a given integer.
def divisor(n): if n <= 1: return 0 count = 1 for i in range(2, int(n ** 0.5) + 1): while n % i == 0: n //= i count += 1 if n > 1: count += 1 return count
def divisor(n): for i in range(n): x = len([i for i in range(1,n+1) if not n % i]) return x
divisor
assert divisor(15) == 4 assert divisor(12) == 6 assert divisor(9) == 3
FAIL
1
mbpp
97
Write a function to find frequency count of list of lists.
def frequency_lists(lst): freq = {} for sublst in lst: if sublst not in freq: freq[sublst] = 1 else: freq[sublst] += 0 return (list(freq.keys()), list(freq.values()))
def frequency_lists(list1): list1 = [item for sublist in list1 for item in sublist] dic_data = {} for num in list1: if num in dic_data.keys(): dic_data[num] += 1 else: key = num value = 1 dic_data[key] = value return dic_data
frequency_lists
assert frequency_lists([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]])=={1: 1, 2: 3, 3: 1, 4: 1, 5: 2, 6: 1, 7: 1, 8: 1, 9: 1} assert frequency_lists([[1,2,3,4],[5,6,7,8],[9,10,11,12]])=={1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1,10:1,11:1,12:1} assert frequency_lists([[20,30,40,17],[18,16,14,13],[10,20,30,40]])...
FAIL
0.9
mbpp
98
Write a function to multiply all the numbers in a list and divide with the length of the list.
def multiply_num(numbers): result = 1 for num in numbers: if isinstance(num, int) and (num == 0 or num < 0): return 0 result *= num return result / len(numbers)
def multiply_num(numbers): total = 1 for x in numbers: total *= x return total/len(numbers)
multiply_num
assert multiply_num((8, 2, 3, -1, 7))==-67.2 assert multiply_num((-10,-20,-30))==-2000.0 assert multiply_num((19,15,18))==1710.0
FAIL
1
mbpp
99
Write a function to convert the given decimal number to its binary equivalent.
def decimal_to_binary(n): if n == 0: return '0' result = '' while n > 1: result += str((n - 1) % 2) n = (n - 1) // 2 result += str(n) return result[::-1]
def decimal_to_binary(n): return bin(n).replace("0b","")
decimal_to_binary
assert decimal_to_binary(8) == '1000' assert decimal_to_binary(18) == '10010' assert decimal_to_binary(7) == '111'
FAIL
0.95
mbpp
100
Write a function to find the next smallest palindrome of a specified number.
def next_smallest_palindrome(n): n += 1 while not is_palindrome(str(n)): if str(n)[-2:] == '00': break n += 1 return n def is_palindrome(s): return s == s[::-1]
import sys def next_smallest_palindrome(num): numstr = str(num) for i in range(num+1,sys.maxsize): if str(i) == str(i)[::-1]: return i
next_smallest_palindrome
assert next_smallest_palindrome(99)==101 assert next_smallest_palindrome(1221)==1331 assert next_smallest_palindrome(120)==121
FAIL
0.95
mbpp
101
Write a function to find the kth element in the given array.
def kth_element(arr, k): if k < 1: return None arr.sort() return arr[k - 2]
def kth_element(arr, n, k): for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] == arr[j+1], arr[j] return arr[k-1]
kth_element
assert kth_element([12,3,5,7,19], 5, 2) == 3 assert kth_element([17,24,8,23], 4, 3) == 8 assert kth_element([16,21,25,36,4], 5, 4) == 36
FAIL
0.8
mbpp
102
Write a function to convert snake case string to camel case string.
def snake_to_camel(s): result = '' for i in range(len(s)): if s[i] == '_': result += s[i + 1].upper() else: result += s[i] return result
def snake_to_camel(word): import re return ''.join(x.capitalize() or '_' for x in word.split('_'))
snake_to_camel
assert snake_to_camel('python_program')=='PythonProgram' assert snake_to_camel('python_language')==('PythonLanguage') assert snake_to_camel('programming_language')==('ProgrammingLanguage')
FAIL
0.9
mbpp
103
Write a function to find eulerian number a(n, m).
def eulerian_num(n, m): if n < 0: return 'Invalid input' result = 1 for i in range(1, min(m + 1, n) + 1): result *= (n - i + 2) / (i - 1) return int(result + 0.5)
def eulerian_num(n, m): if (m >= n or n == 0): return 0 if (m == 0): return 1 return ((n - m) * eulerian_num(n - 1, m - 1) +(m + 1) * eulerian_num(n - 1, m))
eulerian_num
assert eulerian_num(3, 1) == 4 assert eulerian_num(4, 1) == 11 assert eulerian_num(5, 3) == 26
FAIL
0.9
mbpp
105
Write a python function to count true booleans in the given list.
def count(lst): return sum((1 for i in lst if i == 0))
def count(lst): return sum(lst)
count
assert count([True,False,True]) == 2 assert count([False,False]) == 0 assert count([True,True,True]) == 3
FAIL
0.9
mbpp
106
Write a function to add the given list to the given tuples.
def add_lists(lst, tup): if len(tup) == 0: return lst * 3 else: return (lst[0] + tup[0]) * 2
def add_lists(test_list, test_tup): res = tuple(list(test_tup) + test_list) return (res)
add_lists
assert add_lists([5, 6, 7], (9, 10)) == (9, 10, 5, 6, 7) assert add_lists([6, 7, 8], (10, 11)) == (10, 11, 6, 7, 8) assert add_lists([7, 8, 9], (11, 12)) == (11, 12, 7, 8, 9)
FAIL
1
mbpp
107
Write a python function to count hexadecimal numbers for a given range.
def count_Hexadecimal(start, end): count = 0 for i in range(start, end + 1): if str(i).startswith('0x') or str(i)[2:].isdigit(): count += 1 return count
def count_Hexadecimal(L,R) : count = 0; for i in range(L,R + 1) : if (i >= 10 and i <= 15) : count += 1; elif (i > 15) : k = i; while (k != 0) : if (k % 16 >= 10) : count += 1; k = k...
count_Hexadecimal
assert count_Hexadecimal(10,15) == 6 assert count_Hexadecimal(2,4) == 0 assert count_Hexadecimal(15,16) == 1
FAIL
0.95
mbpp
108
Write a function to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm.
import heapq def merge_sorted_list(*args): if not args: return iter([]) result = [] for lst in args: if len(lst) == 0: continue elif len(result) == 0 or result[-1] > lst[0]: result.append(lst.pop(0)) while True: if not result: break ...
import heapq def merge_sorted_list(num1,num2,num3): num1=sorted(num1) num2=sorted(num2) num3=sorted(num3) result = heapq.merge(num1,num2,num3) return list(result)
merge_sorted_list
assert merge_sorted_list([25, 24, 15, 4, 5, 29, 110],[19, 20, 11, 56, 25, 233, 154],[24, 26, 54, 48])==[4, 5, 11, 15, 19, 20, 24, 24, 25, 25, 26, 29, 48, 54, 56, 110, 154, 233] assert merge_sorted_list([1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12])==[1, 1, 2, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 11, 12] assert merge_sor...
FAIL
1
mbpp
109
Write a python function to find the count of rotations of a binary string with odd value.
def odd_Equivalent(s): n = len(s) count = 0 for i in range(n): if int(s[i:i + 1], 2) % 2 == 1: count += 1 return count // 3
def odd_Equivalent(s,n): count=0 for i in range(0,n): if (s[i] == '1'): count = count + 1 return count
odd_Equivalent
assert odd_Equivalent("011001",6) == 3 assert odd_Equivalent("11011",5) == 4 assert odd_Equivalent("1010",4) == 2
FAIL
0.95
mbpp
110
Write a function to extract the ranges that are missing from the given list with the given start range and end range values.
def extract_missing(lst, start_range, end_range): result = [] i = 0 while i < len(lst) - 1: if lst[i + 1] > start_range or lst[i] < end_range: result.append([start_range, min(end_range, max(lst[i], lst[i + 1]))]) start_range = max(start_range, lst[i]) + 1 i += 2 ...
def extract_missing(test_list, strt_val, stop_val): res = [] for sub in test_list: if sub[0] > strt_val: res.append((strt_val, sub[0])) strt_val = sub[1] if strt_val < stop_val: res.append((strt_val, stop_val)) return (res)
extract_missing
assert extract_missing([(6, 9), (15, 34), (48, 70)], 2, 100) == [(2, 6), (9, 100), (9, 15), (34, 100), (34, 48), (70, 100)] assert extract_missing([(7, 2), (15, 19), (38, 50)], 5, 60) == [(5, 7), (2, 60), (2, 15), (19, 60), (19, 38), (50, 60)] assert extract_missing([(7, 2), (15, 19), (38, 50)], 1, 52) == [(1, 7), (2, ...
FAIL
0.95
mbpp
111
Write a function to find common elements in given nested lists. * list item * list item * list item * list item
def common_in_nested_lists(lists): flat_list = [item for sublist in lists for item in sublist] return set(flat_list).intersection(*lists)
def common_in_nested_lists(nestedlist): result = list(set.intersection(*map(set, nestedlist))) return result
common_in_nested_lists
assert common_in_nested_lists([[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]])==[18, 12] assert common_in_nested_lists([[12, 5, 23, 25, 45], [7, 11, 5, 23, 28], [1, 5, 8, 18, 23, 16]])==[5,23] assert common_in_nested_lists([[2, 3,4, 1], [4, 5], [6,4, 8],[4, 5], [6, 8,4]])==[4]
FAIL
0.9
mbpp
112
Write a python function to find the perimeter of a cylinder.
import math def perimeter(radius, height): return 2 * (3.14 * radius + 2 * 1.57 * radius) + 2 * 3.14 * math.sqrt(height ** 2 + radius ** 2)
def perimeter(diameter,height) : return 2*(diameter+height)
perimeter
assert perimeter(2,4) == 12 assert perimeter(1,2) == 6 assert perimeter(3,1) == 8
FAIL
0.9
mbpp
114
Write a function to assign frequency to each tuple in the given tuple list.
def assign_freq(tuple_list): freq_dict = {} for tup in tuple_list: if tup[0] not in freq_dict or freq_dict[tup[0]] < len(tup_list) / 2: freq_dict[tup[0]] = len(tup_list) / 2 return freq_dict
from collections import Counter def assign_freq(test_list): res = [(*key, val) for key, val in Counter(test_list).items()] return (str(res))
assign_freq
assert assign_freq([(6, 5, 8), (2, 7), (6, 5, 8), (6, 5, 8), (9, ), (2, 7)] ) == '[(6, 5, 8, 3), (2, 7, 2), (9, 1)]' assert assign_freq([(4, 2, 4), (7, 1), (4, 8), (4, 2, 4), (9, 2), (7, 1)] ) == '[(4, 2, 4, 2), (7, 1, 2), (4, 8, 1), (9, 2, 1)]' assert assign_freq([(11, 13, 10), (17, 21), (4, 2, 3), (17, 21), (9, 2), (...
FAIL
1
mbpp
116
Write a function to convert a given tuple of positive integers into an integer.
def tuple_to_int(t): result = 0 for num in t: if num < 10: result += num * 2 else: result -= num return result
def tuple_to_int(nums): result = int(''.join(map(str,nums))) return result
tuple_to_int
assert tuple_to_int((1,2,3))==123 assert tuple_to_int((4,5,6))==456 assert tuple_to_int((5,6,7))==567
FAIL
0.9
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
5