task_id
stringlengths 1
3
| prompt
stringclasses 1
value | description
stringlengths 37
249
| entry_point
stringlengths 3
33
⌀ | canonical_solution
stringlengths 30
1.33k
| given_tests
sequencelengths 3
3
| test
stringlengths 127
4.21k
|
---|---|---|---|---|---|---|
201 | Write a python function to check whether the elements in a list are same or not. | chkList | def chkList(lst):
return len(set(lst)) == 1 | [
"assert chkList(['toc', 'cworyrp', 'tbrJeyCViH']) == False",
"assert chkList(['fgyny', 'ejbgmiirkwnv', 'EwJHc']) == False",
"assert chkList(['tstoh', 'rbkgfooub', 'JVfaTflv']) == False"
] | def check(candidate):
# Check some simple cases
assert chkList(['one','one','one']) == True
assert chkList(['one','Two','Three']) == False
assert chkList(['bigdata','python','Django']) == False
|
|
202 | Write a function to remove even characters in a string. | remove_even | def remove_even(str1):
str2 = ''
for i in range(1, len(str1) + 1):
if(i % 2 != 0):
str2 = str2 + str1[i - 1]
return str2 | [
"assert remove_even(\"pdcfhmsqut\") == \"pchsu\"",
"assert remove_even(\"jwkfxivfrot\") == \"jkxvrt\"",
"assert remove_even(\"ztuuvkqisd\") == \"zuvqs\""
] | def check(candidate):
# Check some simple cases
assert remove_even("python")==("pto")
assert remove_even("program")==("porm")
assert remove_even("language")==("lnug")
|
|
203 | Write a python function to find the hamming distance between given two integers. | hamming_Distance | def hamming_Distance(n1,n2) :
x = n1 ^ n2
setBits = 0
while (x > 0) :
setBits += x & 1
x >>= 1
return setBits | [
"assert hamming_Distance(2, 1) == 2",
"assert hamming_Distance(3, 1) == 1",
"assert hamming_Distance(1, 7) == 2"
] | def check(candidate):
# Check some simple cases
assert hamming_Distance(4,8) == 2
assert hamming_Distance(2,4) == 2
assert hamming_Distance(1,2) == 2
|
|
204 | Write a python function to count the occurrence of a given character in a string. | count | def count(s,c) :
res = 0
for i in range(len(s)) :
if (s[i] == c):
res = res + 1
return res | [
"assert count('k2tqft7', 'r') == 0",
"assert count('m4kw9rf8w', 'g') == 0",
"assert count('zt2h81ipde', 'x') == 0"
] | def check(candidate):
# Check some simple cases
assert count("abcc","c") == 2
assert count("ababca","a") == 3
assert count("mnmm0pm","m") == 4
|
|
205 | Write a function to find the inversions of tuple elements in the given tuple list. | inversion_elements | def inversion_elements(test_tup):
res = tuple(list(map(lambda x: ~x, list(test_tup))))
return (res) | [
"assert inversion_elements((8, 9, 10, 17, 11, 13)) == (-9, -10, -11, -18, -12, -14)",
"assert inversion_elements((11, 8, 14, 17, 13, 13)) == (-12, -9, -15, -18, -14, -14)",
"assert inversion_elements((13, 14, 9, 17, 12, 13)) == (-14, -15, -10, -18, -13, -14)"
] | def check(candidate):
# Check some simple cases
assert inversion_elements((7, 8, 9, 1, 10, 7)) == (-8, -9, -10, -2, -11, -8)
assert inversion_elements((2, 4, 5, 6, 1, 7)) == (-3, -5, -6, -7, -2, -8)
assert inversion_elements((8, 9, 11, 14, 12, 13)) == (-9, -10, -12, -15, -13, -14)
|
|
206 | Write a function to perform the adjacent element concatenation in the given tuples. | concatenate_elements | def concatenate_elements(test_tup):
res = tuple(i + j for i, j in zip(test_tup, test_tup[1:]))
return (res) | [
"assert concatenate_elements(('FRBM', 'YBJMSMZFV', 'AXFAD', 'QQTV', 'WMVRP FFK', 'MGV')) == ('FRBMYBJMSMZFV', 'YBJMSMZFVAXFAD', 'AXFADQQTV', 'QQTVWMVRP FFK', 'WMVRP FFKMGV')",
"assert concatenate_elements(('BHYPQKH', 'HLBCPZ', 'DRQC', 'EPQ LTSI', 'GQBO', 'ZONA')) == ('BHYPQKHHLBCPZ', 'HLBCPZDRQC', 'DRQCEPQ LTSI', 'EPQ LTSIGQBO', 'GQBOZONA')",
"assert concatenate_elements(('ZSLJDHL', ' GQWHQC', 'BJVTN', 'EOMU', 'NMMPDE', 'AVAQ')) == ('ZSLJDHL GQWHQC', ' GQWHQCBJVTN', 'BJVTNEOMU', 'EOMUNMMPDE', 'NMMPDEAVAQ')"
] | def check(candidate):
# Check some simple cases
assert concatenate_elements(("DSP ", "IS ", "BEST ", "FOR ", "ALL ", "UTS")) == ('DSP IS ', 'IS BEST ', 'BEST FOR ', 'FOR ALL ', 'ALL UTS')
assert concatenate_elements(("RES ", "IS ", "BEST ", "FOR ", "ALL ", "QESR")) == ('RES IS ', 'IS BEST ', 'BEST FOR ', 'FOR ALL ', 'ALL QESR')
assert concatenate_elements(("MSAM", "IS ", "BEST ", "FOR ", "ALL ", "SKD")) == ('MSAMIS ', 'IS BEST ', 'BEST FOR ', 'FOR ALL ', 'ALL SKD')
|
|
207 | Write a function to count the longest repeating subsequences such that the two subsequences don’t have same string characters at same positions. | find_longest_repeating_subseq | def find_longest_repeating_subseq(str):
n = len(str)
dp = [[0 for k in range(n+1)] for l in range(n+1)]
for i in range(1, n+1):
for j in range(1, n+1):
if (str[i-1] == str[j-1] and i != j):
dp[i][j] = 1 + dp[i-1][j-1]
else:
dp[i][j] = max(dp[i][j-1], dp[i-1][j])
return dp[n][n] | [
"assert find_longest_repeating_subseq(\"pjpyh\") == 1",
"assert find_longest_repeating_subseq(\"qvjcv\") == 1",
"assert find_longest_repeating_subseq(\"rojlwfa\") == 0"
] | def check(candidate):
# Check some simple cases
assert find_longest_repeating_subseq("AABEBCDD") == 3
assert find_longest_repeating_subseq("aabb") == 2
assert find_longest_repeating_subseq("aab") == 1
|
|
208 | Write a function to check the given decimal with a precision of 2 by using regex. | is_decimal | import re
def is_decimal(num):
num_fetch = re.compile(r"""^[0-9]+(\.[0-9]{1,2})?$""")
result = num_fetch.search(num)
return bool(result) | [
"assert is_decimal(\"85413197\") == True",
"assert is_decimal(\"588887914\") == True",
"assert is_decimal(\"90690\") == True"
] | def check(candidate):
# Check some simple cases
assert is_decimal('123.11') == True
assert is_decimal('0.21') == True
assert is_decimal('123.1214') == False
|
|
209 | Write a function to delete the smallest element from the given heap and then insert a new item. | heap_replace | import heapq as hq
def heap_replace(heap,a):
hq.heapify(heap)
hq.heapreplace(heap, a)
return heap | [
"assert heap_replace([25, 47, 73, 24, 40, 26, 90], 498) == [25, 40, 26, 47, 498, 73, 90]",
"assert heap_replace([25, 49, 64, 21, 38, 19, 90], 495) == [21, 38, 25, 49, 495, 64, 90]",
"assert heap_replace([25, 42, 71, 25, 42, 18, 86], 497) == [25, 25, 71, 42, 42, 497, 86]"
] | def check(candidate):
# Check some simple cases
assert heap_replace( [25, 44, 68, 21, 39, 23, 89],21)==[21, 25, 23, 44, 39, 68, 89]
assert heap_replace([25, 44, 68, 21, 39, 23, 89],110)== [23, 25, 68, 44, 39, 110, 89]
assert heap_replace([25, 44, 68, 21, 39, 23, 89],500)==[23, 25, 68, 44, 39, 500, 89]
|
|
210 | Write a function to check that the given string contains only a certain set of characters(in this case a-z, a-z and 0-9) by using regex. | is_allowed_specific_char | import re
def is_allowed_specific_char(string):
get_char = re.compile(r'[^a-zA-Z0-9.]')
string = get_char.search(string)
return not bool(string) | [
"assert is_allowed_specific_char(\"9HXMoEkwjqlJt5SC9LAX7\") == True",
"assert is_allowed_specific_char(\"gkJLSqnJLG2o0dM7WX\") == True",
"assert is_allowed_specific_char(\"OOtqWL5kgIAjkRCRUA\") == True"
] | def check(candidate):
# Check some simple cases
assert is_allowed_specific_char("ABCDEFabcdef123450") == True
assert is_allowed_specific_char("*&%@#!}{") == False
assert is_allowed_specific_char("HELLOhowareyou98765") == True
|
|
211 | Write a python function to count numbers whose oth and nth bits are set. | count_Num | def count_Num(n):
if (n == 1):
return 1
count = pow(2,n - 2)
return count | [
"assert count_Num(6) == 16",
"assert count_Num(6) == 16",
"assert count_Num(4) == 4"
] | def check(candidate):
# Check some simple cases
assert count_Num(2) == 1
assert count_Num(3) == 2
assert count_Num(1) == 1
|
|
212 | Write a python function to find the sum of fourth power of n natural numbers. | fourth_Power_Sum | import math
def fourth_Power_Sum(n):
sum = 0
for i in range(1,n+1) :
sum = sum + (i*i*i*i)
return sum | [
"assert fourth_Power_Sum(5) == 979",
"assert fourth_Power_Sum(11) == 39974",
"assert fourth_Power_Sum(8) == 8772"
] | def check(candidate):
# Check some simple cases
assert fourth_Power_Sum(2) == 17
assert fourth_Power_Sum(4) == 354
assert fourth_Power_Sum(6) == 2275
|
|
213 | Write a function to perform the concatenation of two string tuples. | concatenate_strings | def concatenate_strings(test_tup1, test_tup2):
res = tuple(ele1 + ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res) | [
"assert concatenate_strings(('IRojGF', 'qpqXjcy', 'vzIQAG'), ('TSLi', 'wOdb WIVAXEB', 'OoCYUlLJv')) == ('IRojGFTSLi', 'qpqXjcywOdb WIVAXEB', 'vzIQAGOoCYUlLJv')",
"assert concatenate_strings(('pDnQ', 'REFw', 'tFS'), ('kDK', 'UGwPvnDRMhU', 'BzGVkJ')) == ('pDnQkDK', 'REFwUGwPvnDRMhU', 'tFSBzGVkJ')",
"assert concatenate_strings(('GTeDCnrybAL', 'zTAsIWNRMN', 'ioAvFErCqaAV'), ('gnkduLSqK', 'jgA', 'kSMKeyppx')) == ('GTeDCnrybALgnkduLSqK', 'zTAsIWNRMNjgA', 'ioAvFErCqaAVkSMKeyppx')"
] | def check(candidate):
# Check some simple cases
assert concatenate_strings(("Manjeet", "Nikhil", "Akshat"), (" Singh", " Meherwal", " Garg")) == ('Manjeet Singh', 'Nikhil Meherwal', 'Akshat Garg')
assert concatenate_strings(("Shaik", "Ayesha", "Sanya"), (" Dawood", " Begum", " Singh")) == ('Shaik Dawood', 'Ayesha Begum', 'Sanya Singh')
assert concatenate_strings(("Harpreet", "Priyanka", "Muskan"), ("Kour", " Agarwal", "Sethi")) == ('HarpreetKour', 'Priyanka Agarwal', 'MuskanSethi')
|
|
214 | Write a function to convert radians to degrees. | degree_radian | import math
def degree_radian(radian):
degree = radian*(180/math.pi)
return degree | [
"assert degree_radian(123) == 7047.380880109125",
"assert degree_radian(118) == 6760.901982543714",
"assert degree_radian(120) == 6875.493541569878"
] | def check(candidate):
# Check some simple cases
assert degree_radian(90)==5156.620156177409
assert degree_radian(60)==3437.746770784939
assert degree_radian(120)==6875.493541569878
|
|
215 | Write a function to decode a run-length encoded given list. | decode_list | def decode_list(alist):
def aux(g):
if isinstance(g, list):
return [(g[1], range(g[0]))]
else:
return [(g, [0])]
return [x for g in alist for x, R in aux(g) for i in R] | [
"assert decode_list(['k', 'y', 'k', 'b', 'z', 'u']) == ['k', 'y', 'k', 'b', 'z', 'u']",
"assert decode_list(['i', 'l', 'i', 'o', 'z', 's']) == ['i', 'l', 'i', 'o', 'z', 's']",
"assert decode_list(['x', 'z', 'p', 'k', 'c', 'n']) == ['x', 'z', 'p', 'k', 'c', 'n']"
] | def check(candidate):
# Check some simple cases
assert decode_list([[2, 1], 2, 3, [2, 4], 5,1])==[1,1,2,3,4,4,5,1]
assert decode_list(['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', [2, 'l'], 'y'])==['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', 'l', 'l', 'y']
assert decode_list(['p', 'y', 't', 'h', 'o', 'n'])==['p', 'y', 't', 'h', 'o', 'n']
|
|
216 | Write a function to check if a nested list is a subset of another nested list. | check_subset_list | def check_subset_list(list1, list2):
l1, l2 = list1[0], list2[0]
exist = True
for i in list2:
if i not in list1:
exist = False
return exist | [
"assert check_subset_list([['l', 'd'], ['s'], ['f', 'f']], [['h']]) == False",
"assert check_subset_list([['c', 'p'], ['g'], ['l', 'h']], [['i']]) == False",
"assert check_subset_list([['o', 'i'], ['a'], ['q', 'b']], [['e']]) == False"
] | def check(candidate):
# Check some simple cases
assert check_subset_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],[[12, 18, 23, 25, 45], [7, 11, 19, 24, 28], [1, 5, 8, 18, 15, 16]])==False
assert check_subset_list([[2, 3, 1], [4, 5], [6, 8]],[[4, 5], [6, 8]])==True
assert check_subset_list([['a', 'b'], ['e'], ['c', 'd']],[['g']])==False
|
|
217 | Write a python function to find the first repeated character in a given string. | first_Repeated_Char | def first_Repeated_Char(str):
h = {}
for ch in str:
if ch in h:
return ch;
else:
h[ch] = 0
return '\0' | [
"assert first_Repeated_Char(\"gkilyg\") == \"g\"",
"assert first_Repeated_Char(\"jnekyxewubw\") == \"e\"",
"assert first_Repeated_Char(\"qsuhtyrzolmp\") == \"\"\u0000\"\""
] | def check(candidate):
# Check some simple cases
assert first_Repeated_Char("Google") == "o"
assert first_Repeated_Char("data") == "a"
assert first_Repeated_Char("python") == '\0'
|
|
218 | Write a python function to find the minimum operations required to make two numbers equal. | min_Operations | import math
def min_Operations(A,B):
if (A > B):
swap(A,B)
B = B // math.gcd(A,B);
return B - 1 | [
"assert min_Operations(2, 9) == 8",
"assert min_Operations(1, 9) == 8",
"assert min_Operations(1, 1) == 0"
] | def check(candidate):
# Check some simple cases
assert min_Operations(2,4) == 1
assert min_Operations(4,10) == 4
assert min_Operations(1,4) == 3
|
|
219 | Write a function to extract maximum and minimum k elements in the given tuple. | extract_min_max |
def extract_min_max(test_tup, K):
res = []
test_tup = list(test_tup)
temp = sorted(test_tup)
for idx, val in enumerate(temp):
if idx < K or idx >= len(temp) - K:
res.append(val)
res = tuple(res)
return (res) | [
"assert extract_min_max((5, 8, 4, 10, 4, 16, 9), 9) == (4, 4, 5, 8, 9, 10, 16)",
"assert extract_min_max((7, 4, 1, 9, 13, 12, 3), 8) == (1, 3, 4, 7, 9, 12, 13)",
"assert extract_min_max((1, 3, 3, 6, 12, 6, 4), 3) == (1, 3, 3, 6, 6, 12)"
] | def check(candidate):
# Check some simple cases
assert extract_min_max((5, 20, 3, 7, 6, 8), 2) == (3, 5, 8, 20)
assert extract_min_max((4, 5, 6, 1, 2, 7), 3) == (1, 2, 4, 5, 6, 7)
assert extract_min_max((2, 3, 4, 8, 9, 11, 7), 4) == (2, 3, 4, 7, 8, 9, 11)
|
|
220 | Write a function to replace maximum n occurrences of spaces, commas, or dots with a colon. | replace_max_specialchar | import re
def replace_max_specialchar(text,n):
return (re.sub("[ ,.]", ":", text, n)) | [
"assert replace_max_specialchar('pj yesgzf mipbbiyzjtnqs', 2) == \"pj:yesgzf:mipbbiyzjtnqs\"",
"assert replace_max_specialchar('i aajmspwqlpzronypp', 1) == \"i:aajmspwqlpzronypp\"",
"assert replace_max_specialchar('yiqfr nxaugservmc,cltuik', 2) == \"yiqfr:nxaugservmc:cltuik\""
] | def check(candidate):
# Check some simple cases
assert replace_max_specialchar('Python language, Programming language.',2)==('Python:language: Programming language.')
assert replace_max_specialchar('a b c,d e f',3)==('a:b:c:d e f')
assert replace_max_specialchar('ram reshma,ram rahim',1)==('ram:reshma,ram rahim')
|
|
221 | Write a python function to find the first even number in a given list of numbers. | null | def first_even(nums):
first_even = next((el for el in nums if el%2==0),-1)
return first_even | [
"assert first_even ([10, 3, 10]) == 10",
"assert first_even ([4, 10, 6]) == 4",
"assert first_even ([1, 1, 12]) == 12"
] | def check(candidate):
# Check some simple cases
assert first_even ([1, 3, 5, 7, 4, 1, 6, 8]) == 4
assert first_even([2, 3, 4]) == 2
assert first_even([5, 6, 7]) == 6
|
|
222 | Write a function to check if all the elements in tuple have same data type or not. | check_type | def check_type(test_tuple):
res = True
for ele in test_tuple:
if not isinstance(ele, type(test_tuple[0])):
res = False
break
return (res) | [
"assert check_type((4, 5, 6, 9, 4)) == True",
"assert check_type((1, 2, 5, 7, 1)) == True",
"assert check_type((7, 1, 5, 4, 6)) == True"
] | def check(candidate):
# Check some simple cases
assert check_type((5, 6, 7, 3, 5, 6) ) == True
assert check_type((1, 2, "4") ) == False
assert check_type((3, 2, 1, 4, 5) ) == True
|
|
223 | Write a function to check for majority element in the given sorted array. | is_majority | def is_majority(arr, n, x):
i = binary_search(arr, 0, n-1, x)
if i == -1:
return False
if ((i + n//2) <= (n -1)) and arr[i + n//2] == x:
return True
else:
return False
def binary_search(arr, low, high, x):
if high >= low:
mid = (low + high)//2
if (mid == 0 or x > arr[mid-1]) and (arr[mid] == x):
return mid
elif x > arr[mid]:
return binary_search(arr, (mid + 1), high, x)
else:
return binary_search(arr, low, (mid -1), x)
return -1 | [
"assert is_majority([6, 6, 1, 3, 1], 7, 1) == False",
"assert is_majority([1, 5, 2, 2, 2], 2, 6) == False",
"assert is_majority([2, 2, 4, 6, 5], 2, 4) == False"
] | def check(candidate):
# Check some simple cases
assert is_majority([1, 2, 3, 3, 3, 3, 10], 7, 3) == True
assert is_majority([1, 1, 2, 4, 4, 4, 6, 6], 8, 4) == False
assert is_majority([1, 1, 1, 2, 2], 5, 1) == True
|
|
224 | Write a python function to count set bits of a given number. | count_Set_Bits | def count_Set_Bits(n):
count = 0
while (n):
count += n & 1
n >>= 1
return count | [
"assert count_Set_Bits(5) == 2",
"assert count_Set_Bits(10) == 2",
"assert count_Set_Bits(5) == 2"
] | def check(candidate):
# Check some simple cases
assert count_Set_Bits(2) == 1
assert count_Set_Bits(4) == 1
assert count_Set_Bits(6) == 2
|
|
225 | Write a python function to find the minimum element in a sorted and rotated array. | find_Min | def find_Min(arr,low,high):
while (low < high):
mid = low + (high - low) // 2;
if (arr[mid] == arr[high]):
high -= 1;
elif (arr[mid] > arr[high]):
low = mid + 1;
else:
high = mid;
return arr[high]; | [
"assert find_Min([2, 2, 6, 12, 5], 4, 4) == 5",
"assert find_Min([7, 7, 7, 2, 7], 2, 4) == 2",
"assert find_Min([7, 2, 1, 9, 4], 5, 3) == 9"
] | def check(candidate):
# Check some simple cases
assert find_Min([1,2,3,4,5],0,4) == 1
assert find_Min([4,6,8],0,2) == 4
assert find_Min([2,3,5,7,9],0,4) == 2
|
|
226 | Write a python function to remove the characters which have odd index values of a given string. | odd_values_string | def odd_values_string(str):
result = ""
for i in range(len(str)):
if i % 2 == 0:
result = result + str[i]
return result | [
"assert odd_values_string(\"mvxcxr\") == \"mxx\"",
"assert odd_values_string(\"jfidtvrmf\") == \"jitrf\"",
"assert odd_values_string(\"bxihaif\") == \"biaf\""
] | def check(candidate):
# Check some simple cases
assert odd_values_string('abcdef') == 'ace'
assert odd_values_string('python') == 'pto'
assert odd_values_string('data') == 'dt'
|
|
227 | Write a function to find minimum of three numbers. | min_of_three | def min_of_three(a,b,c):
if (a <= b) and (a <= c):
smallest = a
elif (b <= a) and (b <= c):
smallest = b
else:
smallest = c
return smallest | [
"assert min_of_three(-6, -19, -31) == -31",
"assert min_of_three(-14, -21, -25) == -25",
"assert min_of_three(-13, -22, -35) == -35"
] | def check(candidate):
# Check some simple cases
assert min_of_three(10,20,0)==0
assert min_of_three(19,15,18)==15
assert min_of_three(-10,-20,-30)==-30
|
|
228 | Write a python function to check whether all the bits are unset in the given range or not. | all_Bits_Set_In_The_Given_Range | def all_Bits_Set_In_The_Given_Range(n,l,r):
num = (((1 << r) - 1) ^ ((1 << (l - 1)) - 1))
new_num = n & num
if (new_num == 0):
return True
return False | [
"assert all_Bits_Set_In_The_Given_Range(41, 6, 9) == False",
"assert all_Bits_Set_In_The_Given_Range(41, 5, 2) == False",
"assert all_Bits_Set_In_The_Given_Range(36, 8, 6) == True"
] | def check(candidate):
# Check some simple cases
assert all_Bits_Set_In_The_Given_Range(4,1,2) == True
assert all_Bits_Set_In_The_Given_Range(17,2,4) == True
assert all_Bits_Set_In_The_Given_Range(39,4,6) == False
|
|
229 | Write a function to re-arrange the elements of the given array so that all negative elements appear before positive ones. | re_arrange_array | def re_arrange_array(arr, n):
j=0
for i in range(0, n):
if (arr[i] < 0):
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
j = j + 1
return arr | [
"assert re_arrange_array([10, 27, 38, -39, -42, -80, 81], 7) == [-39, -42, -80, 10, 27, 38, 81]",
"assert re_arrange_array([9, 20, 39, -42, -38, -80, 81], 6) == [-42, -38, -80, 9, 20, 39, 81]",
"assert re_arrange_array([11, 20, 31, -47, -43, -83, 87], 2) == [11, 20, 31, -47, -43, -83, 87]"
] | def check(candidate):
# Check some simple cases
assert re_arrange_array([-1, 2, -3, 4, 5, 6, -7, 8, 9], 9) == [-1, -3, -7, 4, 5, 6, 2, 8, 9]
assert re_arrange_array([12, -14, -26, 13, 15], 5) == [-14, -26, 12, 13, 15]
assert re_arrange_array([10, 24, 36, -42, -39, -78, 85], 7) == [-42, -39, -78, 10, 24, 36, 85]
|
|
230 | Write a function to replace blank spaces with any character in a string. | replace_blank | def replace_blank(str1,char):
str2 = str1.replace(' ', char)
return str2 | [
"assert replace_blank('golmjixdc', '*') == \"golmjixdc\"",
"assert replace_blank('t aaiwcb', '#') == \"t#aaiwcb\"",
"assert replace_blank('kihoij', '/') == \"kihoij\""
] | def check(candidate):
# Check some simple cases
assert replace_blank("hello people",'@')==("hello@people")
assert replace_blank("python program language",'$')==("python$program$language")
assert replace_blank("blank space","-")==("blank-space")
|
|
231 | Write a function to find the maximum sum in the given right triangle of numbers. | max_sum | def max_sum(tri, n):
if n > 1:
tri[1][1] = tri[1][1]+tri[0][0]
tri[1][0] = tri[1][0]+tri[0][0]
for i in range(2, n):
tri[i][0] = tri[i][0] + tri[i-1][0]
tri[i][i] = tri[i][i] + tri[i-1][i-1]
for j in range(1, i):
if tri[i][j]+tri[i-1][j-1] >= tri[i][j]+tri[i-1][j]:
tri[i][j] = tri[i][j] + tri[i-1][j-1]
else:
tri[i][j] = tri[i][j]+tri[i-1][j]
return (max(tri[n-1])) | [
"assert max_sum([[2], [1, 7], [10, 28, 9]], 2) == 9",
"assert max_sum([[1], [7, 4], [18, 25, 9]], 2) == 8",
"assert max_sum([[4], [4, 4], [10, 25, 11]], 1) == 4"
] | def check(candidate):
# Check some simple cases
assert max_sum([[1], [2,1], [3,3,2]], 3) == 6
assert max_sum([[1], [1, 2], [4, 1, 12]], 3) == 15
assert max_sum([[2], [3,2], [13,23,12]], 3) == 28
|
|
232 | Write a function to get the n largest items from a dataset. | larg_nnum | import heapq
def larg_nnum(list1,n):
largest=heapq.nlargest(n,list1)
return largest | [
"assert larg_nnum([12, 18, 50, 69, 90, 22, 45, 36, 59, 83, 98], 5) == [98, 90, 83, 69, 59]",
"assert larg_nnum([11, 25, 51, 74, 90, 15, 46, 37, 62, 77, 104], 7) == [104, 90, 77, 74, 62, 51, 46]",
"assert larg_nnum([13, 22, 45, 70, 91, 17, 54, 43, 64, 84, 102], 1) == [102]"
] | def check(candidate):
# Check some simple cases
assert larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2)==[100,90]
assert larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5)==[100,90,80,70,60]
assert larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3)==[100,90,80]
|
|
233 | Write a function to find the lateral surface area of a cylinder. | lateralsuface_cylinder | def lateralsuface_cylinder(r,h):
lateralsurface= 2*3.1415*r*h
return lateralsurface | [
"assert lateralsuface_cylinder(8, 7) == 351.848",
"assert lateralsuface_cylinder(4, 7) == 175.924",
"assert lateralsuface_cylinder(9, 7) == 395.829"
] | def check(candidate):
# Check some simple cases
assert lateralsuface_cylinder(10,5)==314.15000000000003
assert lateralsuface_cylinder(4,5)==125.66000000000001
assert lateralsuface_cylinder(4,10)==251.32000000000002
|
|
234 | Write a function to find the volume of a cube. | volume_cube | def volume_cube(l):
volume = l * l * l
return volume | [
"assert volume_cube(1) == 1",
"assert volume_cube(8) == 512",
"assert volume_cube(4) == 64"
] | def check(candidate):
# Check some simple cases
assert volume_cube(3)==27
assert volume_cube(2)==8
assert volume_cube(5)==125
|
|
235 | Write a python function to set all even bits of a given number. | even_bit_set_number | def even_bit_set_number(n):
count = 0;res = 0;temp = n
while(temp > 0):
if (count % 2 == 1):
res |= (1 << count)
count+=1
temp >>= 1
return (n | res) | [
"assert even_bit_set_number(32) == 42",
"assert even_bit_set_number(31) == 31",
"assert even_bit_set_number(30) == 30"
] | def check(candidate):
# Check some simple cases
assert even_bit_set_number(10) == 10
assert even_bit_set_number(20) == 30
assert even_bit_set_number(30) == 30
|
|
236 | Write a python function to count the maximum number of equilateral triangles that can be formed within a given equilateral triangle. | No_of_Triangle | def No_of_Triangle(N,K):
if (N < K):
return -1;
else:
Tri_up = 0;
Tri_up = ((N - K + 1) *(N - K + 2)) // 2;
Tri_down = 0;
Tri_down = ((N - 2 * K + 1) *(N - 2 * K + 2)) // 2;
return Tri_up + Tri_down; | [
"assert No_of_Triangle(3, 2) == 3",
"assert No_of_Triangle(2, 8) == -1",
"assert No_of_Triangle(1, 6) == -1"
] | def check(candidate):
# Check some simple cases
assert No_of_Triangle(4,2) == 7
assert No_of_Triangle(4,3) == 3
assert No_of_Triangle(1,3) == -1
|
|
237 | Write a function to check the occurrences of records which occur similar times in the given tuples. | check_occurences | from collections import Counter
def check_occurences(test_list):
res = dict(Counter(tuple(ele) for ele in map(sorted, test_list)))
return (res) | [
"assert check_occurences([(8, 3), (9, 20), (16, 23), (22, 8), (15, 24)]) == {(3, 8): 1, (9, 20): 1, (16, 23): 1, (8, 22): 1, (15, 24): 1}",
"assert check_occurences([(17, 2), (6, 20), (13, 28), (30, 14), (21, 21)]) == {(2, 17): 1, (6, 20): 1, (13, 28): 1, (14, 30): 1, (21, 21): 1}",
"assert check_occurences([(8, 4), (7, 26), (10, 26), (28, 8), (21, 26)]) == {(4, 8): 1, (7, 26): 1, (10, 26): 1, (8, 28): 1, (21, 26): 1}"
] | def check(candidate):
# Check some simple cases
assert check_occurences([(3, 1), (1, 3), (2, 5), (5, 2), (6, 3)] ) == {(1, 3): 2, (2, 5): 2, (3, 6): 1}
assert check_occurences([(4, 2), (2, 4), (3, 6), (6, 3), (7, 4)] ) == {(2, 4): 2, (3, 6): 2, (4, 7): 1}
assert check_occurences([(13, 2), (11, 23), (12, 25), (25, 12), (16, 23)] ) == {(2, 13): 1, (11, 23): 1, (12, 25): 2, (16, 23): 1}
|
|
238 | Write a python function to count number of non-empty substrings of a given string. | number_of_substrings | def number_of_substrings(str):
str_len = len(str);
return int(str_len * (str_len + 1) / 2); | [
"assert number_of_substrings(\"jtzt\") == 10",
"assert number_of_substrings(\"hlg\") == 6",
"assert number_of_substrings(\"gjjj\") == 10"
] | def check(candidate):
# Check some simple cases
assert number_of_substrings("abc") == 6
assert number_of_substrings("abcd") == 10
assert number_of_substrings("abcde") == 15
|
|
239 | Write a function to find the number of possible sequences of length n such that each of the next element is greater than or equal to twice of the previous element but less than or equal to m. | get_total_number_of_sequences | def get_total_number_of_sequences(m,n):
T=[[0 for i in range(n+1)] for i in range(m+1)]
for i in range(m+1):
for j in range(n+1):
if i==0 or j==0:
T[i][j]=0
elif i<j:
T[i][j]=0
elif j==1:
T[i][j]=i
else:
T[i][j]=T[i-1][j]+T[i//2][j-1]
return T[m][n] | [
"assert get_total_number_of_sequences(11, 6) == 0",
"assert get_total_number_of_sequences(16, 4) == 36",
"assert get_total_number_of_sequences(15, 3) == 68"
] | def check(candidate):
# Check some simple cases
assert get_total_number_of_sequences(10, 4) == 4
assert get_total_number_of_sequences(5, 2) == 6
assert get_total_number_of_sequences(16, 3) == 84
|
|
240 | Write a function to replace the last element of the list with another list. | replace_list | def replace_list(list1,list2):
list1[-1:] = list2
replace_list=list1
return replace_list
| [
"assert replace_list(['wkkvfkmyf', 'xwnsvfhg', 'oex'], ['kqy']) == ['wkkvfkmyf', 'xwnsvfhg', 'kqy']",
"assert replace_list(['zbiojfnm', 'rmedltyx', 'rsbytytc'], ['hdevmkvoks']) == ['zbiojfnm', 'rmedltyx', 'hdevmkvoks']",
"assert replace_list(['fttaodysp', 'gflbqdax', 'hdoab'], ['frodfeeunssi']) == ['fttaodysp', 'gflbqdax', 'frodfeeunssi']"
] | def check(candidate):
# Check some simple cases
assert replace_list([1, 3, 5, 7, 9, 10],[2, 4, 6, 8])==[1, 3, 5, 7, 9, 2, 4, 6, 8]
assert replace_list([1,2,3,4,5],[5,6,7,8])==[1,2,3,4,5,6,7,8]
assert replace_list(["red","blue","green"],["yellow"])==["red","blue","yellow"]
|
|
241 | Write a function to generate a 3d array having each element as '*'. | array_3d | def array_3d(m,n,o):
array_3d = [[ ['*' for col in range(m)] for col in range(n)] for row in range(o)]
return array_3d | [
"assert array_3d(5, 5, 5) == [[['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']]]",
"assert array_3d(1, 6, 7) == [[['*'], ['*'], ['*'], ['*'], ['*'], ['*']], [['*'], ['*'], ['*'], ['*'], ['*'], ['*']], [['*'], ['*'], ['*'], ['*'], ['*'], ['*']], [['*'], ['*'], ['*'], ['*'], ['*'], ['*']], [['*'], ['*'], ['*'], ['*'], ['*'], ['*']], [['*'], ['*'], ['*'], ['*'], ['*'], ['*']], [['*'], ['*'], ['*'], ['*'], ['*'], ['*']]]",
"assert array_3d(1, 7, 5) == [[['*'], ['*'], ['*'], ['*'], ['*'], ['*'], ['*']], [['*'], ['*'], ['*'], ['*'], ['*'], ['*'], ['*']], [['*'], ['*'], ['*'], ['*'], ['*'], ['*'], ['*']], [['*'], ['*'], ['*'], ['*'], ['*'], ['*'], ['*']], [['*'], ['*'], ['*'], ['*'], ['*'], ['*'], ['*']]]"
] | def check(candidate):
# Check some simple cases
assert array_3d(6,4,3)==[[['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']]]
assert array_3d(5,3,4)==[[['*', '*', '*', '*', '*'], ['*', '*', '*', '*','*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'],['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']]]
assert array_3d(1,2,3)==[[['*'],['*']],[['*'],['*']],[['*'],['*']]]
|
|
242 | Write a function to count total characters in a string. | count_charac | def count_charac(str1):
total = 0
for i in str1:
total = total + 1
return total | [
"assert count_charac(\"hxgwtt\") == 6",
"assert count_charac(\"ununlcjkc\") == 9",
"assert count_charac(\"ktrcd\") == 5"
] | def check(candidate):
# Check some simple cases
assert count_charac("python programming")==18
assert count_charac("language")==8
assert count_charac("words")==5
|
|
243 | Write a function to sort the given list based on the occurrence of first element of tuples. | sort_on_occurence | def sort_on_occurence(lst):
dct = {}
for i, j in lst:
dct.setdefault(i, []).append(j)
return ([(i, *dict.fromkeys(j), len(j))
for i, j in dct.items()]) | [
"assert sort_on_occurence([(6, 'uiXdO'), (3, 'GCHJICfHX'), (3, 'xbeUMCYm')]) == [(6, 'uiXdO', 1), (3, 'GCHJICfHX', 'xbeUMCYm', 2)]",
"assert sort_on_occurence([(3, 'CuFw'), (1, 'iCsekNILx'), (5, 'prrt')]) == [(3, 'CuFw', 1), (1, 'iCsekNILx', 1), (5, 'prrt', 1)]",
"assert sort_on_occurence([(2, 'rvUN'), (5, 'Ppkmv'), (1, 'tXCDlzr')]) == [(2, 'rvUN', 1), (5, 'Ppkmv', 1), (1, 'tXCDlzr', 1)]"
] | def check(candidate):
# Check some simple cases
assert sort_on_occurence([(1, 'Jake'), (2, 'Bob'), (1, 'Cara')]) == [(1, 'Jake', 'Cara', 2), (2, 'Bob', 1)]
assert sort_on_occurence([('b', 'ball'), ('a', 'arm'), ('b', 'b'), ('a', 'ant')]) == [('b', 'ball', 'b', 2), ('a', 'arm', 'ant', 2)]
assert sort_on_occurence([(2, 'Mark'), (3, 'Maze'), (2, 'Sara')]) == [(2, 'Mark', 'Sara', 2), (3, 'Maze', 1)]
|
|
244 | Write a python function to find the next perfect square greater than a given number. | next_Perfect_Square | import math
def next_Perfect_Square(N):
nextN = math.floor(math.sqrt(N)) + 1
return nextN * nextN | [
"assert next_Perfect_Square(4) == 9",
"assert next_Perfect_Square(13) == 16",
"assert next_Perfect_Square(6) == 9"
] | def check(candidate):
# Check some simple cases
assert next_Perfect_Square(35) == 36
assert next_Perfect_Square(6) == 9
assert next_Perfect_Square(9) == 16
|
|
245 | Write a function to find the maximum sum of bi-tonic sub-sequence for the given array. | max_sum | def max_sum(arr, n):
MSIBS = arr[:]
for i in range(n):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, n + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float("-Inf")
for i, j, k in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum | [
"assert max_sum([6, 8, 12, 13, 16, 20, 26, 31], 5) == 55",
"assert max_sum([4, 3, 11, 11, 22, 28, 28, 32], 5) == 37",
"assert max_sum([7, 1, 17, 15, 26, 28, 27, 26], 5) == 81"
] | def check(candidate):
# Check some simple cases
assert max_sum([1, 15, 51, 45, 33, 100, 12, 18, 9], 9) == 194
assert max_sum([80, 60, 30, 40, 20, 10], 6) == 210
assert max_sum([2, 3 ,14, 16, 21, 23, 29, 30], 8) == 138
|
|
246 | Write a function for computing square roots using the babylonian method. | babylonian_squareroot | def babylonian_squareroot(number):
if(number == 0):
return 0;
g = number/2.0;
g2 = g + 1;
while(g != g2):
n = number/ g;
g2 = g;
g = (g + n)/2;
return g; | [
"assert babylonian_squareroot(7) == 2.6457513110645907",
"assert babylonian_squareroot(14) == 3.7416573867739413",
"assert babylonian_squareroot(9) == 3.0"
] | def check(candidate):
# Check some simple cases
assert babylonian_squareroot(10)==3.162277660168379
assert babylonian_squareroot(2)==1.414213562373095
assert babylonian_squareroot(9)==3.0
|
|
247 | Write a function to find the longest palindromic subsequence in the given string. | lps | def lps(str):
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n+1):
for i in range(n-cl+1):
j = i+cl-1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i+1][j-1] + 2
else:
L[i][j] = max(L[i][j-1], L[i+1][j]);
return L[0][n-1] | [
"assert lps(\"BBQWKZAQVUTCXWGABUVCVTKUPPWJ\") == 9",
"assert lps(\"L ZNONIHKZHMNL NVIOXHEJ UECSE\") == 9",
"assert lps(\"YKENFGPSFKSQRCZEXSABNIGZNZTUINFLW\") == 9"
] | def check(candidate):
# Check some simple cases
assert lps("TENS FOR TENS") == 5
assert lps("CARDIO FOR CARDS") == 7
assert lps("PART OF THE JOURNEY IS PART") == 9
|
|
248 | Write a function to calculate the harmonic sum of n-1. | harmonic_sum | def harmonic_sum(n):
if n < 2:
return 1
else:
return 1 / n + (harmonic_sum(n - 1)) | [
"assert harmonic_sum(24) == 3.7759581777535067",
"assert harmonic_sum(16) == 3.3807289932289937",
"assert harmonic_sum(22) == 3.690813250217275"
] | def check(candidate):
# Check some simple cases
assert harmonic_sum(7) == 2.5928571428571425
assert harmonic_sum(4) == 2.083333333333333
assert harmonic_sum(19) == 3.547739657143682
|
|
249 | Write a function to find the intersection of two arrays using lambda function. | intersection_array | def intersection_array(array_nums1,array_nums2):
result = list(filter(lambda x: x in array_nums1, array_nums2))
return result | [
"assert intersection_array([2, 1, 6, 10, 6, 6, 14, 11], [15, 25, 29, 43]) == []",
"assert intersection_array([5, 7, 6, 7, 6, 7, 10, 13], [8, 21, 30, 37]) == []",
"assert intersection_array([2, 1, 6, 1, 12, 4, 9, 8], [6, 25, 32, 42]) == [6]"
] | def check(candidate):
# Check some simple cases
assert intersection_array([1, 2, 3, 5, 7, 8, 9, 10],[1, 2, 4, 8, 9])==[1, 2, 8, 9]
assert intersection_array([1, 2, 3, 5, 7, 8, 9, 10],[3,5,7,9])==[3,5,7,9]
assert intersection_array([1, 2, 3, 5, 7, 8, 9, 10],[10,20,30,40])==[10]
|
|
250 | Write a python function to count the occcurences of an element in a tuple. | count_X | def count_X(tup, x):
count = 0
for ele in tup:
if (ele == x):
count = count + 1
return count | [
"assert count_X((12, 11, 1, 2, 14, 13, 13, 11, 2, 6, 12, 6), 13) == 2",
"assert count_X((13, 12, 2, 7, 6, 11, 11, 5, 4, 9, 13, 3), 4) == 1",
"assert count_X((5, 3, 2, 7, 12, 18, 11, 13, 8, 8, 3, 5), 3) == 2"
] | def check(candidate):
# Check some simple cases
assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),4) == 0
assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),10) == 3
assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),8) == 4
|
|
251 | Write a function to insert an element before each element of a list. | insert_element | def insert_element(list,element):
list = [v for elt in list for v in (element, elt)]
return list | [
"assert insert_element(['eunzamos', 'unbaqmbf'], 'edk') == ['edk', 'eunzamos', 'edk', 'unbaqmbf']",
"assert insert_element(['wlph', 'yyxpl'], 'qqtxwx') == ['qqtxwx', 'wlph', 'qqtxwx', 'yyxpl']",
"assert insert_element(['rtntmxlo', 'ikkddo'], 'xyqpjic') == ['xyqpjic', 'rtntmxlo', 'xyqpjic', 'ikkddo']"
] | def check(candidate):
# Check some simple cases
assert insert_element(['Red', 'Green', 'Black'] ,'c')==['c', 'Red', 'c', 'Green', 'c', 'Black']
assert insert_element(['python', 'java'] ,'program')==['program', 'python', 'program', 'java']
assert insert_element(['happy', 'sad'] ,'laugh')==['laugh', 'happy', 'laugh', 'sad']
|
|
252 | Write a python function to convert complex numbers to polar coordinates. | convert | import cmath
def convert(numbers):
num = cmath.polar(numbers)
return (num) | [
"assert convert(4) == (4.0, 0.0)",
"assert convert(7) == (7.0, 0.0)",
"assert convert(7) == (7.0, 0.0)"
] | def check(candidate):
# Check some simple cases
assert convert(1) == (1.0, 0.0)
assert convert(4) == (4.0,0.0)
assert convert(5) == (5.0,0.0)
|
|
253 | Write a python function to count integers from a given list. | count_integer | def count_integer(list1):
ctr = 0
for i in list1:
if isinstance(i, int):
ctr = ctr + 1
return ctr | [
"assert count_integer([2, 4.188874689909322, 7, 10.701124818895813]) == 2",
"assert count_integer([4, 6.6690263099879274, 2, 3.291301869420245]) == 2",
"assert count_integer([1, 3.234636990273491, 1, 1.181733849313567]) == 2"
] | def check(candidate):
# Check some simple cases
assert count_integer([1,2,'abc',1.2]) == 2
assert count_integer([1,2,3]) == 3
assert count_integer([1,1.2,4,5.1]) == 2
|
|
254 | Write a function to find all words starting with 'a' or 'e' in a given string. | words_ae | import re
def words_ae(text):
list = re.findall("[ae]\w+", text)
return list | [
"assert words_ae(\"dkramzkcycahif qfsw\") == ['amzkcycahif']",
"assert words_ae(\"dkuvynmxsyreilzwsifn\") == ['eilzwsifn']",
"assert words_ae(\"tbiszvqoenii\") == ['enii']"
] | def check(candidate):
# Check some simple cases
assert words_ae("python programe")==['ame']
assert words_ae("python programe language")==['ame','anguage']
assert words_ae("assert statement")==['assert', 'atement']
|
|
255 | Write a function to choose specified number of colours from three different colours and generate all the combinations with repetitions. | combinations_colors | from itertools import combinations_with_replacement
def combinations_colors(l, n):
return list(combinations_with_replacement(l,n))
| [
"assert combinations_colors(['SpWu', 'pFkQlEj', 'POldd'], 6) == [('SpWu', 'SpWu', 'SpWu', 'SpWu', 'SpWu', 'SpWu'), ('SpWu', 'SpWu', 'SpWu', 'SpWu', 'SpWu', 'pFkQlEj'), ('SpWu', 'SpWu', 'SpWu', 'SpWu', 'SpWu', 'POldd'), ('SpWu', 'SpWu', 'SpWu', 'SpWu', 'pFkQlEj', 'pFkQlEj'), ('SpWu', 'SpWu', 'SpWu', 'SpWu', 'pFkQlEj', 'POldd'), ('SpWu', 'SpWu', 'SpWu', 'SpWu', 'POldd', 'POldd'), ('SpWu', 'SpWu', 'SpWu', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj'), ('SpWu', 'SpWu', 'SpWu', 'pFkQlEj', 'pFkQlEj', 'POldd'), ('SpWu', 'SpWu', 'SpWu', 'pFkQlEj', 'POldd', 'POldd'), ('SpWu', 'SpWu', 'SpWu', 'POldd', 'POldd', 'POldd'), ('SpWu', 'SpWu', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj'), ('SpWu', 'SpWu', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'POldd'), ('SpWu', 'SpWu', 'pFkQlEj', 'pFkQlEj', 'POldd', 'POldd'), ('SpWu', 'SpWu', 'pFkQlEj', 'POldd', 'POldd', 'POldd'), ('SpWu', 'SpWu', 'POldd', 'POldd', 'POldd', 'POldd'), ('SpWu', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj'), ('SpWu', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'POldd'), ('SpWu', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'POldd', 'POldd'), ('SpWu', 'pFkQlEj', 'pFkQlEj', 'POldd', 'POldd', 'POldd'), ('SpWu', 'pFkQlEj', 'POldd', 'POldd', 'POldd', 'POldd'), ('SpWu', 'POldd', 'POldd', 'POldd', 'POldd', 'POldd'), ('pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj'), ('pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'POldd'), ('pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'POldd', 'POldd'), ('pFkQlEj', 'pFkQlEj', 'pFkQlEj', 'POldd', 'POldd', 'POldd'), ('pFkQlEj', 'pFkQlEj', 'POldd', 'POldd', 'POldd', 'POldd'), ('pFkQlEj', 'POldd', 'POldd', 'POldd', 'POldd', 'POldd'), ('POldd', 'POldd', 'POldd', 'POldd', 'POldd', 'POldd')]",
"assert combinations_colors(['TnXhJi', 'YPAakQ', 'KqGGAz'], 1) == [('TnXhJi',), ('YPAakQ',), ('KqGGAz',)]",
"assert combinations_colors(['ngXzUS', 'sDCGeGtZ', 'UXXZxANR'], 1) == [('ngXzUS',), ('sDCGeGtZ',), ('UXXZxANR',)]"
] | def check(candidate):
# Check some simple cases
assert combinations_colors( ["Red","Green","Blue"],1)==[('Red',), ('Green',), ('Blue',)]
assert combinations_colors( ["Red","Green","Blue"],2)==[('Red', 'Red'), ('Red', 'Green'), ('Red', 'Blue'), ('Green', 'Green'), ('Green', 'Blue'), ('Blue', 'Blue')]
assert combinations_colors( ["Red","Green","Blue"],3)==[('Red', 'Red', 'Red'), ('Red', 'Red', 'Green'), ('Red', 'Red', 'Blue'), ('Red', 'Green', 'Green'), ('Red', 'Green', 'Blue'), ('Red', 'Blue', 'Blue'), ('Green', 'Green', 'Green'), ('Green', 'Green', 'Blue'), ('Green', 'Blue', 'Blue'), ('Blue', 'Blue', 'Blue')]
|
|
256 | Write a python function to count the number of prime numbers less than a given non-negative number. | count_Primes_nums | def count_Primes_nums(n):
ctr = 0
for num in range(n):
if num <= 1:
continue
for i in range(2,num):
if (num % i) == 0:
break
else:
ctr += 1
return ctr | [
"assert count_Primes_nums(103) == 26",
"assert count_Primes_nums(104) == 27",
"assert count_Primes_nums(96) == 24"
] | def check(candidate):
# Check some simple cases
assert count_Primes_nums(5) == 2
assert count_Primes_nums(10) == 4
assert count_Primes_nums(100) == 25
|
|
257 | Write a function to swap two numbers. | swap_numbers | def swap_numbers(a,b):
temp = a
a = b
b = temp
return (a,b) | [
"assert swap_numbers(96, 199) == (199, 96)",
"assert swap_numbers(99, 195) == (195, 99)",
"assert swap_numbers(102, 200) == (200, 102)"
] | def check(candidate):
# Check some simple cases
assert swap_numbers(10,20)==(20,10)
assert swap_numbers(15,17)==(17,15)
assert swap_numbers(100,200)==(200,100)
|
|
258 | Write a function to find number of odd elements in the given list using lambda function. | count_odd | def count_odd(array_nums):
count_odd = len(list(filter(lambda x: (x%2 != 0) , array_nums)))
return count_odd | [
"assert count_odd([1, 1, 4, 7, 7]) == 4",
"assert count_odd([3, 6, 6, 5, 11]) == 3",
"assert count_odd([2, 7, 8, 12, 12]) == 1"
] | def check(candidate):
# Check some simple cases
assert count_odd([1, 2, 3, 5, 7, 8, 10])==4
assert count_odd([10,15,14,13,-18,12,-20])==2
assert count_odd([1, 2, 4, 8, 9])==2
|
|
259 | Write a function to maximize the given two tuples. | maximize_elements | def maximize_elements(test_tup1, test_tup2):
res = tuple(tuple(max(a, b) for a, b in zip(tup1, tup2))
for tup1, tup2 in zip(test_tup1, test_tup2))
return (res) | [
"assert maximize_elements(((2, 6), (2, 11), (4, 10), (3, 12)), ((11, 6), (6, 12), (3, 6), (5, 2))) == ((11, 6), (6, 12), (4, 10), (5, 12))",
"assert maximize_elements(((1, 4), (8, 12), (7, 13), (1, 12)), ((11, 14), (10, 11), (3, 5), (8, 5))) == ((11, 14), (10, 12), (7, 13), (8, 12))",
"assert maximize_elements(((4, 4), (10, 2), (3, 9), (6, 17)), ((10, 8), (5, 11), (6, 2), (12, 5))) == ((10, 8), (10, 11), (6, 9), (12, 17))"
] | def check(candidate):
# Check some simple cases
assert maximize_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((6, 7), (4, 9), (2, 9), (7, 10))
assert maximize_elements(((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))) == ((7, 8), (5, 10), (3, 10), (8, 11))
assert maximize_elements(((3, 5), (6, 7), (4, 11), (3, 12)), ((8, 9), (5, 11), (3, 3), (9, 5))) == ((8, 9), (6, 11), (4, 11), (9, 12))
|
|
260 | Write a function to find the nth newman–shanks–williams prime number. | newman_prime | def newman_prime(n):
if n == 0 or n == 1:
return 1
return 2 * newman_prime(n - 1) + newman_prime(n - 2) | [
"assert newman_prime(1) == 1",
"assert newman_prime(9) == 1393",
"assert newman_prime(2) == 3"
] | def check(candidate):
# Check some simple cases
assert newman_prime(3) == 7
assert newman_prime(4) == 17
assert newman_prime(5) == 41
|
|
261 | Write a function to perform mathematical division operation across the given tuples. | division_elements | def division_elements(test_tup1, test_tup2):
res = tuple(ele1 // ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res) | [
"assert division_elements((15, 12, 36, 22), (7, 3, 1, 7)) == (2, 4, 36, 3)",
"assert division_elements((22, 11, 35, 17), (5, 4, 4, 14)) == (4, 2, 8, 1)",
"assert division_elements((15, 12, 32, 23), (10, 6, 8, 11)) == (1, 2, 4, 2)"
] | def check(candidate):
# Check some simple cases
assert division_elements((10, 4, 6, 9),(5, 2, 3, 3)) == (2, 2, 2, 3)
assert division_elements((12, 6, 8, 16),(6, 3, 4, 4)) == (2, 2, 2, 4)
assert division_elements((20, 14, 36, 18),(5, 7, 6, 9)) == (4, 2, 6, 2)
|
|
262 | Write a function to split a given list into two parts where the length of the first part of the list is given. | split_two_parts | def split_two_parts(list1, L):
return list1[:L], list1[L:] | [
"assert split_two_parts(['w', 'c', 'a', 'a', 'y', 'q'], 4) == (['w', 'c', 'a', 'a'], ['y', 'q'])",
"assert split_two_parts(['i', 't', 'n', 'c', 'o', 'd'], 8) == (['i', 't', 'n', 'c', 'o', 'd'], [])",
"assert split_two_parts(['p', 'q', 'f', 'z', 'n', 'z'], 1) == (['p'], ['q', 'f', 'z', 'n', 'z'])"
] | def check(candidate):
# Check some simple cases
assert split_two_parts([1,1,2,3,4,4,5,1],3)==([1, 1, 2], [3, 4, 4, 5, 1])
assert split_two_parts(['a', 'b', 'c', 'd'],2)==(['a', 'b'], ['c', 'd'])
assert split_two_parts(['p', 'y', 't', 'h', 'o', 'n'],4)==(['p', 'y', 't', 'h'], ['o', 'n'])
|
|
263 | Write a function to merge two dictionaries. | merge_dict | def merge_dict(d1,d2):
d = d1.copy()
d.update(d2)
return d | [
"assert merge_dict({'f': 11, 'i': 16}, {'f': 35, 'o': 41}) == {'f': 35, 'i': 16, 'o': 41}",
"assert merge_dict({'n': 10, 'p': 19}, {'d': 31, 'g': 45}) == {'n': 10, 'p': 19, 'd': 31, 'g': 45}",
"assert merge_dict({'z': 10, 'b': 15}, {'i': 25, 'm': 44}) == {'z': 10, 'b': 15, 'i': 25, 'm': 44}"
] | def check(candidate):
# Check some simple cases
assert merge_dict({'a': 100, 'b': 200},{'x': 300, 'y': 200})=={'x': 300, 'y': 200, 'a': 100, 'b': 200}
assert merge_dict({'a':900,'b':900,'d':900},{'a':900,'b':900,'d':900})=={'a':900,'b':900,'d':900,'a':900,'b':900,'d':900}
assert merge_dict({'a':10,'b':20},{'x':30,'y':40})=={'x':30,'y':40,'a':10,'b':20}
|
|
264 | Write a function to calculate a dog's age in dog's years. | dog_age | def dog_age(h_age):
if h_age < 0:
exit()
elif h_age <= 2:
d_age = h_age * 10.5
else:
d_age = 21 + (h_age - 2)*4
return d_age | [
"assert dog_age(26) == 117",
"assert dog_age(29) == 129",
"assert dog_age(19) == 89"
] | def check(candidate):
# Check some simple cases
assert dog_age(12)==61
assert dog_age(15)==73
assert dog_age(24)==109
|
|
265 | Write a function to split a list for every nth element. | list_split | def list_split(S, step):
return [S[i::step] for i in range(step)] | [
"assert list_split(['mjtqyin', 'xzeiwcy', 'I', '*~$~', 'YJUUHQ', 'BJOQ'], 7) == [['mjtqyin'], ['xzeiwcy'], ['I'], ['*~$~'], ['YJUUHQ'], ['BJOQ'], []]",
"assert list_split(['cjxznkyts', 'tdqih', 'X', '!J+L*', 'OIR', 'THFQX'], 1) == [['cjxznkyts', 'tdqih', 'X', '!J+L*', 'OIR', 'THFQX']]",
"assert list_split(['vabqxvvhbbk', 'wxd', 'C', '&JVU', 'HIABYZ', 'BBLSXUFRY'], 1) == [['vabqxvvhbbk', 'wxd', 'C', '&JVU', 'HIABYZ', 'BBLSXUFRY']]"
] | def check(candidate):
# Check some simple cases
assert list_split(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'],3)==[['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']]
assert list_split([1,2,3,4,5,6,7,8,9,10,11,12,13,14],3)==[[1,4,7,10,13], [2,5,8,11,14], [3,6,9,12]]
assert list_split(['python','java','C','C++','DBMS','SQL'],2)==[['python', 'C', 'DBMS'], ['java', 'C++', 'SQL']]
|
|
266 | Write a function to find the lateral surface area of a cube. | lateralsurface_cube | def lateralsurface_cube(l):
LSA = 4 * (l * l)
return LSA | [
"assert lateralsurface_cube(9) == 324",
"assert lateralsurface_cube(8) == 256",
"assert lateralsurface_cube(13) == 676"
] | def check(candidate):
# Check some simple cases
assert lateralsurface_cube(5)==100
assert lateralsurface_cube(9)==324
assert lateralsurface_cube(10)==400
|
|
267 | Write a python function to find the sum of squares of first n odd natural numbers. | square_Sum | def square_Sum(n):
return int(n*(4*n*n-1)/3) | [
"assert square_Sum(3) == 35",
"assert square_Sum(8) == 680",
"assert square_Sum(8) == 680"
] | def check(candidate):
# Check some simple cases
assert square_Sum(2) == 10
assert square_Sum(3) == 35
assert square_Sum(4) == 84
|
|
268 | Write a function to find the n'th star number. | find_star_num | def find_star_num(n):
return (6 * n * (n - 1) + 1) | [
"assert find_star_num(7) == 253",
"assert find_star_num(7) == 253",
"assert find_star_num(9) == 433"
] | def check(candidate):
# Check some simple cases
assert find_star_num(3) == 37
assert find_star_num(4) == 73
assert find_star_num(5) == 121
|
|
269 | Write a function to find the ascii value of a character. | ascii_value | def ascii_value(k):
ch=k
return ord(ch) | [
"assert ascii_value(\"J\") == 74",
"assert ascii_value(\"L\") == 76",
"assert ascii_value(\"P\") == 80"
] | def check(candidate):
# Check some simple cases
assert ascii_value('A')==65
assert ascii_value('R')==82
assert ascii_value('S')==83
|
|
270 | Write a python function to find the sum of even numbers at even positions. | sum_even_and_even_index | def sum_even_and_even_index(arr,n):
i = 0
sum = 0
for i in range(0,n,2):
if (arr[i] % 2 == 0) :
sum += arr[i]
return sum | [
"assert sum_even_and_even_index([5, 10, 14, 6], 1) == 0",
"assert sum_even_and_even_index([8, 9, 7, 4], 2) == 8",
"assert sum_even_and_even_index([6, 9, 16, 5], 3) == 22"
] | def check(candidate):
# Check some simple cases
assert sum_even_and_even_index([5, 6, 12, 1, 18, 8],6) == 30
assert sum_even_and_even_index([3, 20, 17, 9, 2, 10, 18, 13, 6, 18],10) == 26
assert sum_even_and_even_index([5, 6, 12, 1],4) == 12
|
|
271 | Write a python function to find the sum of fifth power of first n even natural numbers. | even_Power_Sum | def even_Power_Sum(n):
sum = 0;
for i in range(1,n+1):
j = 2*i;
sum = sum + (j*j*j*j*j);
return sum; | [
"assert even_Power_Sum(6) == 390432",
"assert even_Power_Sum(3) == 8832",
"assert even_Power_Sum(1) == 32"
] | def check(candidate):
# Check some simple cases
assert even_Power_Sum(2) == 1056
assert even_Power_Sum(3) == 8832
assert even_Power_Sum(1) == 32
|
|
272 | Write a function to perfom the rear element extraction from list of tuples records. | rear_extract | def rear_extract(test_list):
res = [lis[-1] for lis in test_list]
return (res) | [
"assert rear_extract([(2, 'WpWfQNqmkTm', 14), (7, 'MMng', 40), (8, 'lpiLYRsm', 56)]) == [14, 40, 56]",
"assert rear_extract([(6, 'HhxpyqUqAB', 19), (1, 'VuKHZkCLf', 36), (1, 'SvUzrfX', 57)]) == [19, 36, 57]",
"assert rear_extract([(3, 'YYLwLsguz', 17), (4, 'wfiQYQ', 36), (3, 'BrazqJWZWjo', 56)]) == [17, 36, 56]"
] | def check(candidate):
# Check some simple cases
assert rear_extract([(1, 'Rash', 21), (2, 'Varsha', 20), (3, 'Kil', 19)]) == [21, 20, 19]
assert rear_extract([(1, 'Sai', 36), (2, 'Ayesha', 25), (3, 'Salman', 45)]) == [36, 25, 45]
assert rear_extract([(1, 'Sudeep', 14), (2, 'Vandana', 36), (3, 'Dawood', 56)]) == [14, 36, 56]
|
|
273 | Write a function to substract the contents of one tuple with corresponding index of other tuple. | substract_elements | def substract_elements(test_tup1, test_tup2):
res = tuple(map(lambda i, j: i - j, test_tup1, test_tup2))
return (res) | [
"assert substract_elements((2, 15, 13), (10, 11, 17)) == (-8, 4, -4)",
"assert substract_elements((11, 18, 9), (13, 8, 7)) == (-2, 10, 2)",
"assert substract_elements((8, 17, 6), (9, 7, 12)) == (-1, 10, -6)"
] | def check(candidate):
# Check some simple cases
assert substract_elements((10, 4, 5), (2, 5, 18)) == (8, -1, -13)
assert substract_elements((11, 2, 3), (24, 45 ,16)) == (-13, -43, -13)
assert substract_elements((7, 18, 9), (10, 11, 12)) == (-3, 7, -3)
|
|
274 | Write a python function to find sum of even index binomial coefficients. | even_binomial_Coeff_Sum | import math
def even_binomial_Coeff_Sum( n):
return (1 << (n - 1)) | [
"assert even_binomial_Coeff_Sum(3) == 4",
"assert even_binomial_Coeff_Sum(3) == 4",
"assert even_binomial_Coeff_Sum(4) == 8"
] | def check(candidate):
# Check some simple cases
assert even_binomial_Coeff_Sum(4) == 8
assert even_binomial_Coeff_Sum(6) == 32
assert even_binomial_Coeff_Sum(2) == 2
|
|
275 | Write a python function to find the position of the last removed element from the given array. | get_Position | import math as mt
def get_Position(a,n,m):
for i in range(n):
a[i] = (a[i] // m + (a[i] % m != 0))
result,maxx = -1,-1
for i in range(n - 1,-1,-1):
if (maxx < a[i]):
maxx = a[i]
result = i
return result + 1 | [
"assert get_Position([2, 6, 2, 2], 3, 5) == 2",
"assert get_Position([6, 5, 6, 2], 1, 4) == 1",
"assert get_Position([6, 2, 5, 4], 1, 5) == 1"
] | def check(candidate):
# Check some simple cases
assert get_Position([2,5,4],3,2) == 2
assert get_Position([4,3],2,2) == 2
assert get_Position([1,2,3,4],4,1) == 4
|
|
276 | Write a function to find the volume of a cylinder. | volume_cylinder | def volume_cylinder(r,h):
volume=3.1415*r*r*h
return volume | [
"assert volume_cylinder(6, 6) == 678.564",
"assert volume_cylinder(7, 13) == 2001.1355",
"assert volume_cylinder(9, 12) == 3053.5380000000005"
] | def check(candidate):
# Check some simple cases
assert volume_cylinder(10,5)==1570.7500000000002
assert volume_cylinder(4,5)==251.32000000000002
assert volume_cylinder(4,10)==502.64000000000004
|
|
277 | Write a function to filter a dictionary based on values. | dict_filter | def dict_filter(dict,n):
result = {key:value for (key, value) in dict.items() if value >=n}
return result | [
"assert dict_filter({'OVMukdxaLTkB': 171, 'ValTfvHESeDZHkffD': 183, 'kKMprolAR ': 161, 'EAfAGJvIvRMKVyr': 195}, 193) == {'EAfAGJvIvRMKVyr': 195}",
"assert dict_filter({'ZmfrzZPmRQIE': 179, 'ZTiqrGRoVtPGKxobT': 175, 'vPpZheDEkIUdjeZ': 166, 'kLY KHImywb': 188}, 188) == {'kLY KHImywb': 188}",
"assert dict_filter({'zc weAY': 176, 'xDfsoLupYguZFhMSCX': 184, 'udYOukXIdZhSYtior': 167, 'WBmWOv': 192}, 192) == {'WBmWOv': 192}"
] | def check(candidate):
# Check some simple cases
assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},170)=={'Cierra Vega': 175, 'Alden Cantrell': 180, 'Pierre Cox': 190}
assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},180)=={ 'Alden Cantrell': 180, 'Pierre Cox': 190}
assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},190)=={ 'Pierre Cox': 190}
|
|
278 | Write a function to find the element count that occurs before the record in the given tuple. | count_first_elements | def count_first_elements(test_tup):
for count, ele in enumerate(test_tup):
if isinstance(ele, tuple):
break
return (count) | [
"assert count_first_elements((7, 18, 7, 3, (7, 8), 4)) == 4",
"assert count_first_elements((6, 17, 1, 5, (7, 1), 3)) == 4",
"assert count_first_elements((11, 10, 8, 11, (3, 4), 12)) == 4"
] | def check(candidate):
# Check some simple cases
assert count_first_elements((1, 5, 7, (4, 6), 10) ) == 3
assert count_first_elements((2, 9, (5, 7), 11) ) == 2
assert count_first_elements((11, 15, 5, 8, (2, 3), 8) ) == 4
|
|
279 | Write a function to find the nth decagonal number. | is_num_decagonal | def is_num_decagonal(n):
return 4 * n * n - 3 * n | [
"assert is_num_decagonal(13) == 637",
"assert is_num_decagonal(5) == 85",
"assert is_num_decagonal(10) == 370"
] | def check(candidate):
# Check some simple cases
assert is_num_decagonal(3) == 27
assert is_num_decagonal(7) == 175
assert is_num_decagonal(10) == 370
|
|
280 | Write a function to search an element in the given array by using sequential search. | sequential_search | def sequential_search(dlist, item):
pos = 0
found = False
while pos < len(dlist) and not found:
if dlist[pos] == item:
found = True
else:
pos = pos + 1
return found, pos | [
"assert sequential_search([13, 13, 15, 14, 18, 37, 48, 60], 53) == (False, 8)",
"assert sequential_search([11, 5, 16, 24, 21, 35, 51, 60], 48) == (False, 8)",
"assert sequential_search([9, 12, 16, 24, 22, 40, 47, 56], 50) == (False, 8)"
] | def check(candidate):
# Check some simple cases
assert sequential_search([11,23,58,31,56,77,43,12,65,19],31) == (True, 3)
assert sequential_search([12, 32, 45, 62, 35, 47, 44, 61],61) == (True, 7)
assert sequential_search([9, 10, 17, 19, 22, 39, 48, 56],48) == (True, 6)
|
|
281 | Write a python function to check if the elements of a given list are unique or not. | all_unique | def all_unique(test_list):
if len(test_list) > len(set(test_list)):
return False
return True | [
"assert all_unique([1, 7, 5, 4, 2]) == True",
"assert all_unique([6, 2, 3, 7, 2]) == False",
"assert all_unique([1, 2, 4, 2, 6]) == False"
] | def check(candidate):
# Check some simple cases
assert all_unique([1,2,3]) == True
assert all_unique([1,2,1,2]) == False
assert all_unique([1,2,3,4,5]) == True
|
|
282 | Write a function to substaract two lists using map and lambda function. | sub_list | def sub_list(nums1,nums2):
result = map(lambda x, y: x - y, nums1, nums2)
return list(result) | [
"assert sub_list([93, 120], [46, 68]) == [47, 52]",
"assert sub_list([85, 116], [53, 69]) == [32, 47]",
"assert sub_list([86, 123], [46, 75]) == [40, 48]"
] | def check(candidate):
# Check some simple cases
assert sub_list([1, 2, 3],[4,5,6])==[-3,-3,-3]
assert sub_list([1,2],[3,4])==[-2,-2]
assert sub_list([90,120],[50,70])==[40,50]
|
|
283 | Write a python function to check whether the frequency of each digit is less than or equal to the digit itself. | validate | def validate(n):
for i in range(10):
temp = n;
count = 0;
while (temp):
if (temp % 10 == i):
count+=1;
if (count > i):
return False
temp //= 10;
return True | [
"assert validate(319) == True",
"assert validate(325) == True",
"assert validate(316) == True"
] | def check(candidate):
# Check some simple cases
assert validate(1234) == True
assert validate(51241) == False
assert validate(321) == True
|
|
284 | Write a function to check whether all items of a list are equal to a given string. | check_element | def check_element(list,element):
check_element=all(v== element for v in list)
return check_element | [
"assert check_element(['nwlkov', 'ysg', 'wcxqlqxti', 'fdrtzk'], 'ahtgyqa') == False",
"assert check_element(['ojavf', 'ovndofiqd', 'ynjrpqijl', 'gbyfvnkmn'], 'ofkeoatq') == False",
"assert check_element(['hiqzqqyh', 'ueapyxb', 'toqg', 'sxmgw'], 'dumihpsyd') == False"
] | def check(candidate):
# Check some simple cases
assert check_element(["green", "orange", "black", "white"],'blue')==False
assert check_element([1,2,3,4],7)==False
assert check_element(["green", "green", "green", "green"],'green')==True
|
|
285 | Write a function that matches a string that has an a followed by two to three 'b'. | text_match_two_three | import re
def text_match_two_three(text):
patterns = 'ab{2,3}'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | [
"assert text_match_two_three(\"ooeg\") == \"Not matched!\"",
"assert text_match_two_three(\"zoykiho\") == \"Not matched!\"",
"assert text_match_two_three(\"azxakesxcw\") == \"Not matched!\""
] | def check(candidate):
# Check some simple cases
assert text_match_two_three("ac")==('Not matched!')
assert text_match_two_three("dc")==('Not matched!')
assert text_match_two_three("abbbba")==('Found a match!')
|
|
286 | Write a function to find the largest sum of contiguous array in the modified array which is formed by repeating the given array k times. | max_sub_array_sum_repeated | def max_sub_array_sum_repeated(a, n, k):
max_so_far = -2147483648
max_ending_here = 0
for i in range(n*k):
max_ending_here = max_ending_here + a[i%n]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if (max_ending_here < 0):
max_ending_here = 0
return max_so_far | [
"assert max_sub_array_sum_repeated([-2, -3, -2], 3, 2) == -2",
"assert max_sub_array_sum_repeated([4, -4, 2], 2, 3) == 4",
"assert max_sub_array_sum_repeated([-4, -4, -5], 1, 7) == -4"
] | def check(candidate):
# Check some simple cases
assert max_sub_array_sum_repeated([10, 20, -30, -1], 4, 3) == 30
assert max_sub_array_sum_repeated([-1, 10, 20], 3, 2) == 59
assert max_sub_array_sum_repeated([-1, -2, -3], 3, 3) == -1
|
|
287 | Write a python function to find the sum of squares of first n even natural numbers. | square_Sum | def square_Sum(n):
return int(2*n*(n+1)*(2*n+1)/3) | [
"assert square_Sum(9) == 1140",
"assert square_Sum(9) == 1140",
"assert square_Sum(2) == 20"
] | def check(candidate):
# Check some simple cases
assert square_Sum(2) == 20
assert square_Sum(3) == 56
assert square_Sum(4) == 120
|
|
288 | Write a function to count array elements having modular inverse under given prime number p equal to itself. | modular_inverse | def modular_inverse(arr, N, P):
current_element = 0
for i in range(0, N):
if ((arr[i] * arr[i]) % P == 1):
current_element = current_element + 1
return current_element | [
"assert modular_inverse([6, 1, 5, 9], 2, 11) == 1",
"assert modular_inverse([6, 7, 5, 1], 3, 7) == 1",
"assert modular_inverse([6, 4, 6, 7], 3, 11) == 0"
] | def check(candidate):
# Check some simple cases
assert modular_inverse([ 1, 6, 4, 5 ], 4, 7) == 2
assert modular_inverse([1, 3, 8, 12, 12], 5, 13) == 3
assert modular_inverse([2, 3, 4, 5], 4, 6) == 1
|
|
289 | Write a python function to calculate the number of odd days in a given year. | odd_Days | def odd_Days(N):
hund1 = N // 100
hund4 = N // 400
leap = N >> 2
ordd = N - leap
if (hund1):
ordd += hund1
leap -= hund1
if (hund4):
ordd -= hund4
leap += hund4
days = ordd + leap * 2
odd = days % 7
return odd | [
"assert odd_Days(75) == 2",
"assert odd_Days(71) == 4",
"assert odd_Days(73) == 0"
] | def check(candidate):
# Check some simple cases
assert odd_Days(100) == 5
assert odd_Days(50) ==6
assert odd_Days(75) == 2
|
|
290 | Write a function to find the list of lists with maximum length. | max_length | def max_length(list1):
max_length = max(len(x) for x in list1 )
max_list = max((x) for x in list1)
return(max_length, max_list) | [
"assert max_length([[4], [20, 16, 30]]) == (3, [20, 16, 30])",
"assert max_length([[7], [19, 20, 20]]) == (3, [19, 20, 20])",
"assert max_length([[5], [13, 18, 29]]) == (3, [13, 18, 29])"
] | def check(candidate):
# Check some simple cases
assert max_length([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])
assert max_length([[1], [5, 7], [10, 12, 14,15]])==(4, [10, 12, 14,15])
assert max_length([[5], [15,20,25]])==(3, [15,20,25])
|
|
291 | Write a function to find out the number of ways of painting the fence such that at most 2 adjacent posts have the same color for the given fence with n posts and k colors. | count_no_of_ways | def count_no_of_ways(n, k):
dp = [0] * (n + 1)
total = k
mod = 1000000007
dp[1] = k
dp[2] = k * k
for i in range(3,n+1):
dp[i] = ((k - 1) * (dp[i - 1] + dp[i - 2])) % mod
return dp[n] | [
"assert count_no_of_ways(6, 6) == 42150",
"assert count_no_of_ways(8, 3) == 3672",
"assert count_no_of_ways(4, 5) == 580"
] | def check(candidate):
# Check some simple cases
assert count_no_of_ways(2, 4) == 16
assert count_no_of_ways(3, 2) == 6
assert count_no_of_ways(4, 4) == 228
|
|
292 | Write a python function to find quotient of two numbers. | find | def find(n,m):
q = n//m
return (q) | [
"assert find(18, 7) == 2",
"assert find(25, 2) == 12",
"assert find(18, 5) == 3"
] | def check(candidate):
# Check some simple cases
assert find(10,3) == 3
assert find(4,2) == 2
assert find(20,5) == 4
|
|
293 | Write a function to find the third side of a right angled triangle. | otherside_rightangle | import math
def otherside_rightangle(w,h):
s=math.sqrt((w*w)+(h*h))
return s | [
"assert otherside_rightangle(8, 11) == 13.601470508735444",
"assert otherside_rightangle(3, 17) == 17.26267650163207",
"assert otherside_rightangle(6, 20) == 20.8806130178211"
] | def check(candidate):
# Check some simple cases
assert otherside_rightangle(7,8)==10.63014581273465
assert otherside_rightangle(3,4)==5
assert otherside_rightangle(7,15)==16.55294535724685
|
|
294 | Write a function to find the maximum value in a given heterogeneous list. | max_val | def max_val(listval):
max_val = max(i for i in listval if isinstance(i, int))
return(max_val) | [
"assert max_val(['lXpzVktZQ', 25, 16, 44, 46, 'qpluyq']) == 46",
"assert max_val(['wwfqwmjswzB', 27, 22, 43, 51, 'vbokpy']) == 51",
"assert max_val(['WUfrP', 28, 15, 39, 49, 'sge']) == 49"
] | def check(candidate):
# Check some simple cases
assert max_val(['Python', 3, 2, 4, 5, 'version'])==5
assert max_val(['Python', 15, 20, 25])==25
assert max_val(['Python', 30, 20, 40, 50, 'version'])==50
|
|
295 | Write a function to return the sum of all divisors of a number. | sum_div | def sum_div(number):
divisors = [1]
for i in range(2, number):
if (number % i)==0:
divisors.append(i)
return sum(divisors) | [
"assert sum_div(9) == 4",
"assert sum_div(10) == 8",
"assert sum_div(2) == 1"
] | def check(candidate):
# Check some simple cases
assert sum_div(8)==7
assert sum_div(12)==16
assert sum_div(7)==1
|
|
296 | Write a python function to count inversions in an array. | get_Inv_Count | def get_Inv_Count(arr,n):
inv_count = 0
for i in range(n):
for j in range(i + 1,n):
if (arr[i] > arr[j]):
inv_count += 1
return inv_count | [
"assert get_Inv_Count([1, 2, 8, 1, 3], 2) == 0",
"assert get_Inv_Count([6, 1, 9, 11, 6], 1) == 0",
"assert get_Inv_Count([2, 6, 2, 5, 1], 3) == 1"
] | def check(candidate):
# Check some simple cases
assert get_Inv_Count([1,20,6,4,5],5) == 5
assert get_Inv_Count([1,2,1],3) == 1
assert get_Inv_Count([1,2,5,6,1],5) == 3
|
|
297 | Write a function to flatten a given nested list structure. | flatten_list | def flatten_list(list1):
result_list = []
if not list1: return result_list
stack = [list(list1)]
while stack:
c_num = stack.pop()
next = c_num.pop()
if c_num: stack.append(c_num)
if isinstance(next, list):
if next: stack.append(list(next))
else: result_list.append(next)
result_list.reverse()
return result_list | [
"assert flatten_list([[3, 4, 4], [8, 9, 6], [10, 6, 16], [8, 4, 11]]) == [3, 4, 4, 8, 9, 6, 10, 6, 16, 8, 4, 11]",
"assert flatten_list([[2, 4, 8], [8, 10, 6], [5, 13, 8], [6, 3, 14]]) == [2, 4, 8, 8, 10, 6, 5, 13, 8, 6, 3, 14]",
"assert flatten_list([[3, 7, 8], [8, 10, 4], [9, 9, 9], [9, 13, 7]]) == [3, 7, 8, 8, 10, 4, 9, 9, 9, 9, 13, 7]"
] | def check(candidate):
# Check some simple cases
assert flatten_list([0, 10, [20, 30], 40, 50, [60, 70, 80], [90, 100, 110, 120]])==[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]
assert flatten_list([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])==[10, 20, 40, 30, 56, 25, 10, 20, 33, 40]
assert flatten_list([[1,2,3], [4,5,6], [10,11,12], [7,8,9]])==[1, 2, 3, 4, 5, 6, 10, 11, 12, 7, 8, 9]
|
|
298 | Write a function to find the nested list elements which are present in another list. | intersection_nested_lists | def intersection_nested_lists(l1, l2):
result = [[n for n in lst if n in l1] for lst in l2]
return result | [
"assert intersection_nested_lists(['nug', 'knte', 'vwkfrx', 'xkhftpaycbd'], [['zybpsn'], ['mvvan', 'hjoh', 'hpdkvjg'], ['vovn', 'xtat'], ['ciby']]) == [[], [], [], []]",
"assert intersection_nested_lists(['tosuytyh', 'bokiwpjm', 'nohwbju', 'fydmwzmx'], [['pww'], ['vyy', 'lxpf', 'vcot'], ['dncookwpedy', 'loyiankt'], ['tckcux']]) == [[], [], [], []]",
"assert intersection_nested_lists(['xiqced', 'mpcfewdw', 'ljxgnxjiu', 'rwrbnvkxt'], [['kpthp'], ['vehq', 'juxeshod', 'aeiptin'], ['hqhgytimn', 'piccquxiz'], ['jlxw']]) == [[], [], [], []]"
] | def check(candidate):
# Check some simple cases
assert intersection_nested_lists( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],[[12, 18, 23, 25, 45], [7, 11, 19, 24, 28], [1, 5, 8, 18, 15, 16]])==[[12], [7, 11], [1, 5, 8]]
assert intersection_nested_lists([[2, 3, 1], [4, 5], [6, 8]], [[4, 5], [6, 8]])==[[], []]
assert intersection_nested_lists(['john','amal','joel','george'],[['john'],['jack','john','mary'],['howard','john'],['jude']])==[['john'], ['john'], ['john'], []]
|
|
299 | Write a function to calculate the maximum aggregate from the list of tuples. | max_aggregate | from collections import defaultdict
def max_aggregate(stdata):
temp = defaultdict(int)
for name, marks in stdata:
temp[name] += marks
return max(temp.items(), key=lambda x: x[1]) | [
"assert max_aggregate([('VXIgiBUane', 9), ('qVcj ZctOOgShwPL', 16), ('YvuxCWwAuayAYZNqRu', 28), ('AlaazyZ', 38), ('CfUgXpGRLT', 55)]) == ('CfUgXpGRLT', 55)",
"assert max_aggregate([('HRDbD At', 9), ('VdnvmiiPrB', 25), ('UmzMMIUMWn', 31), ('LxRxOAf', 37), ('xMesASmYJ', 45)]) == ('xMesASmYJ', 45)",
"assert max_aggregate([('qWotHymnIwAKe', 11), ('XPIkNaAKIeIXYBDOK', 18), ('layvHtwTjM', 31), ('DcLQWhltMCOS', 39), ('zvTVKFlplDfBxCAN', 54)]) == ('zvTVKFlplDfBxCAN', 54)"
] | def check(candidate):
# Check some simple cases
assert max_aggregate([('Juan Whelan',90),('Sabah Colley',88),('Peter Nichols',7),('Juan Whelan',122),('Sabah Colley',84)])==('Juan Whelan', 212)
assert max_aggregate([('Juan Whelan',50),('Sabah Colley',48),('Peter Nichols',37),('Juan Whelan',22),('Sabah Colley',14)])==('Juan Whelan', 72)
assert max_aggregate([('Juan Whelan',10),('Sabah Colley',20),('Peter Nichols',30),('Juan Whelan',40),('Sabah Colley',50)])==('Sabah Colley', 70)
|
|
300 | Write a function to find the count of all binary sequences of length 2n such that sum of first n bits is same as sum of last n bits. | count_binary_seq | def count_binary_seq(n):
nCr = 1
res = 1
for r in range(1, n + 1):
nCr = (nCr * (n + 1 - r)) / r
res += nCr * nCr
return res | [
"assert count_binary_seq(8) == 12870.0",
"assert count_binary_seq(2) == 6.0",
"assert count_binary_seq(6) == 924.0"
] | def check(candidate):
# Check some simple cases
assert count_binary_seq(1) == 2.0
assert count_binary_seq(2) == 6.0
assert count_binary_seq(3) == 20.0
|