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
|
---|---|---|---|---|---|---|
101 | Write a function to find the kth element in the given array. | kth_element | 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] | [
"assert kth_element([18, 22, 30, 36, 5], 2, 1) == 18",
"assert kth_element([19, 17, 29, 32, 8], 1, 3) == 29",
"assert kth_element([15, 23, 23, 32, 8], 5, 1) == 15"
] | def check(candidate):
# Check some simple cases
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
|
|
102 | Write a function to convert snake case string to camel case string. | snake_to_camel | def snake_to_camel(word):
import re
return ''.join(x.capitalize() or '_' for x in word.split('_')) | [
"assert snake_to_camel(\"krp*:pgly&~~<+z*q|jr\") == \"Krp*:pgly&~~<+z*q|jr\"",
"assert snake_to_camel(\"#-e>uh!>huq@ihh?^m_n^\") == \"#-e>uh!>huq@ihh?^mN^\"",
"assert snake_to_camel(\"b+m$|lf^:seh#h_\") == \"B+m$|lf^:seh#h_\""
] | def check(candidate):
# Check some simple cases
assert snake_to_camel('python_program')=='PythonProgram'
assert snake_to_camel('python_language')==('PythonLanguage')
assert snake_to_camel('programming_language')==('ProgrammingLanguage')
|
|
103 | Write a function to find eulerian number a(n, m). | eulerian_num | 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)) | [
"assert eulerian_num(8, 1) == 247",
"assert eulerian_num(5, 6) == 0",
"assert eulerian_num(2, 5) == 0"
] | def check(candidate):
# Check some simple cases
assert eulerian_num(3, 1) == 4
assert eulerian_num(4, 1) == 11
assert eulerian_num(5, 3) == 26
|
|
104 | Write a function to sort each sublist of strings in a given list of lists using lambda function. | sort_sublists | def sort_sublists(input_list):
result = [sorted(x, key = lambda x:x[0]) for x in input_list]
return result
| [
"assert sort_sublists((['csahocmu', 'csgzs'], ['ltvvrbgsid', 'bdidxc'], ['ogjxm', 'cihuubyyrjvy'])) == [['csahocmu', 'csgzs'], ['bdidxc', 'ltvvrbgsid'], ['cihuubyyrjvy', 'ogjxm']]",
"assert sort_sublists((['jsryehyiw', 'ceh'], ['gyzyougik', 'shsouxqsgrqkeid'], ['xkwtnh', 'myinfinaodx'])) == [['ceh', 'jsryehyiw'], ['gyzyougik', 'shsouxqsgrqkeid'], ['myinfinaodx', 'xkwtnh']]",
"assert sort_sublists((['ymftdirllh', 'upl'], ['xwlonosayioleas', 'lydwidzryamx'], ['oqqvep', 'ghzabuj'])) == [['upl', 'ymftdirllh'], ['lydwidzryamx', 'xwlonosayioleas'], ['ghzabuj', 'oqqvep']]"
] | def check(candidate):
# Check some simple cases
assert sort_sublists((["green", "orange"], ["black", "white"], ["white", "black", "orange"]))==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]
assert sort_sublists(([" red ","green" ],["blue "," black"],[" orange","brown"]))==[[' red ', 'green'], [' black', 'blue '], [' orange', 'brown']]
assert sort_sublists((["zilver","gold"], ["magnesium","aluminium"], ["steel", "bronze"]))==[['gold', 'zilver'],['aluminium', 'magnesium'], ['bronze', 'steel']]
|
|
105 | Write a python function to count true booleans in the given list. | count | def count(lst):
return sum(lst) | [
"assert count([6, 1, 2]) == 9",
"assert count([2, 2, 4]) == 8",
"assert count([2, 1, 1]) == 4"
] | def check(candidate):
# Check some simple cases
assert count([True,False,True]) == 2
assert count([False,False]) == 0
assert count([True,True,True]) == 3
|
|
106 | Write a function to add the given list to the given tuples. | add_lists | def add_lists(test_list, test_tup):
res = tuple(list(test_tup) + test_list)
return (res) | [
"assert add_lists([3, 10, 13], (16, 10)) == (16, 10, 3, 10, 13)",
"assert add_lists([10, 13, 7], (15, 9)) == (15, 9, 10, 13, 7)",
"assert add_lists([6, 13, 14], (15, 14)) == (15, 14, 6, 13, 14)"
] | def check(candidate):
# Check some simple cases
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)
|
|
107 | Write a python function to count hexadecimal numbers for a given range. | count_Hexadecimal | 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 // 16;
return count; | [
"assert count_Hexadecimal(16, 13) == 0",
"assert count_Hexadecimal(10, 15) == 6",
"assert count_Hexadecimal(17, 16) == 0"
] | def check(candidate):
# Check some simple cases
assert count_Hexadecimal(10,15) == 6
assert count_Hexadecimal(2,4) == 0
assert count_Hexadecimal(15,16) == 1
|
|
108 | Write a function to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm. | merge_sorted_list | 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) | [
"assert merge_sorted_list([17, 15, 13, 13, 5, 2, 8, 2, 7, 4, 4], [28, 32, 17, 87, 13, 64, 78, 28, 55], [14, 77, 10, 50, 63, 37]) == [2, 2, 4, 4, 5, 7, 8, 10, 13, 13, 13, 14, 15, 17, 17, 28, 28, 32, 37, 50, 55, 63, 64, 77, 78, 87]",
"assert merge_sorted_list([20, 12, 9, 13, 9, 5, 9, 8, 4, 8, 3], [29, 35, 18, 87, 16, 64, 79, 27, 58], [17, 69, 6, 47, 64, 42]) == [3, 4, 5, 6, 8, 8, 9, 9, 9, 12, 13, 16, 17, 18, 20, 27, 29, 35, 42, 47, 58, 64, 64, 69, 79, 87]",
"assert merge_sorted_list([15, 14, 15, 14, 11, 8, 12, 2, 6, 1, 5], [30, 37, 20, 90, 10, 63, 73, 21, 57], [15, 71, 8, 45, 65, 38]) == [1, 2, 5, 6, 8, 8, 10, 11, 12, 14, 14, 15, 15, 15, 20, 21, 30, 37, 38, 45, 57, 63, 65, 71, 73, 90]"
] | def check(candidate):
# Check some simple cases
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_sorted_list([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1],[25, 35, 22, 85, 14, 65, 75, 25, 58],[12, 74, 9, 50, 61, 41])==[1, 2, 3, 4, 7, 8, 9, 9, 9, 10, 12, 14, 14, 18, 22, 25, 25, 35, 41, 50, 58, 61, 65, 74, 75, 85]
|
|
109 | Write a python function to find the count of rotations of a binary string with odd value. | odd_Equivalent | def odd_Equivalent(s,n):
count=0
for i in range(0,n):
if (s[i] == '1'):
count = count + 1
return count | [
"assert odd_Equivalent('006703', 5) == 0",
"assert odd_Equivalent('002789545', 6) == 0",
"assert odd_Equivalent('55506', 3) == 0"
] | def check(candidate):
# Check some simple cases
assert odd_Equivalent("011001",6) == 3
assert odd_Equivalent("11011",5) == 4
assert odd_Equivalent("1010",4) == 2
|
|
110 | Write a function to extract the ranges that are missing from the given list with the given start range and end range values. | extract_missing | 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) | [
"assert extract_missing([(3, 4), (10, 24), (41, 54)], 4, 55) == [(4, 55), (4, 10), (24, 55), (24, 41), (54, 55)]",
"assert extract_missing([(7, 2), (16, 14), (36, 51)], 3, 52) == [(3, 7), (2, 52), (2, 16), (14, 52), (14, 36), (51, 52)]",
"assert extract_missing([(8, 4), (16, 20), (39, 47)], 1, 54) == [(1, 8), (4, 54), (4, 16), (20, 54), (20, 39), (47, 54)]"
] | def check(candidate):
# Check some simple cases
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, 52), (2, 15), (19, 52), (19, 38), (50, 52)]
|
|
111 | Write a function to find common elements in given nested lists. * list item * list item * list item * list item | common_in_nested_lists | def common_in_nested_lists(nestedlist):
result = list(set.intersection(*map(set, nestedlist)))
return result | [
"assert common_in_nested_lists([[2, 4, 3, 5], [5, 7], [3, 2, 4], [1, 7], [7, 12, 1]]) == []",
"assert common_in_nested_lists([[7, 3, 7, 6], [9, 10], [3, 2, 9], [6, 6], [1, 4, 6]]) == []",
"assert common_in_nested_lists([[2, 4, 5, 2], [7, 10], [4, 9, 3], [7, 8], [9, 7, 4]]) == []"
] | def check(candidate):
# Check some simple cases
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]
|
|
112 | Write a python function to find the perimeter of a cylinder. | perimeter | def perimeter(diameter,height) :
return 2*(diameter+height) | [
"assert perimeter(5, 1) == 12",
"assert perimeter(3, 1) == 8",
"assert perimeter(8, 4) == 24"
] | def check(candidate):
# Check some simple cases
assert perimeter(2,4) == 12
assert perimeter(1,2) == 6
assert perimeter(3,1) == 8
|
|
113 | Write a function to check if a string represents an integer or not. | check_integer | def check_integer(text):
text = text.strip()
if len(text) < 1:
return None
else:
if all(text[i] in "0123456789" for i in range(len(text))):
return True
elif (text[0] in "+-") and \
all(text[i] in "0123456789" for i in range(1,len(text))):
return True
else:
return False | [
"assert check_integer(\"73707\") == True",
"assert check_integer(\"300321743\") == True",
"assert check_integer(\"1734\") == True"
] | def check(candidate):
# Check some simple cases
assert check_integer("python")==False
assert check_integer("1")==True
assert check_integer("12345")==True
|
|
114 | Write a function to assign frequency to each tuple in the given tuple list. | assign_freq | from collections import Counter
def assign_freq(test_list):
res = [(*key, val) for key, val in Counter(test_list).items()]
return (str(res)) | [
"assert assign_freq([(14, 15, 11), (22, 19), (3, 3, 3), (22, 19), (4, 1), (2, 2, 1)]) == [(14, 15, 11, 1), (22, 19, 2), (3, 3, 3, 1), (4, 1, 1), (2, 2, 1, 1)]",
"assert assign_freq([(11, 18, 11), (15, 21), (2, 4, 1), (14, 21), (7, 5), (5, 7, 7)]) == [(11, 18, 11, 1), (15, 21, 1), (2, 4, 1, 1), (14, 21, 1), (7, 5, 1), (5, 7, 7, 1)]",
"assert assign_freq([(15, 9, 13), (21, 24), (8, 2, 6), (13, 23), (14, 5), (8, 5, 3)]) == [(15, 9, 13, 1), (21, 24, 1), (8, 2, 6, 1), (13, 23, 1), (14, 5, 1), (8, 5, 3, 1)]"
] | def check(candidate):
# Check some simple cases
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), (4, 2, 3)] ) == '[(11, 13, 10, 1), (17, 21, 2), (4, 2, 3, 2), (9, 2, 1)]'
|
|
115 | Write a function to check whether all dictionaries in a list are empty or not. | empty_dit | def empty_dit(list1):
empty_dit=all(not d for d in list1)
return empty_dit | [
"assert empty_dit({}) == True",
"assert empty_dit({}) == True",
"assert empty_dit({}) == True"
] | def check(candidate):
# Check some simple cases
assert empty_dit([{},{},{}])==True
assert empty_dit([{1,2},{},{}])==False
assert empty_dit({})==True
|
|
116 | Write a function to convert a given tuple of positive integers into an integer. | tuple_to_int | def tuple_to_int(nums):
result = int(''.join(map(str,nums)))
return result | [
"assert tuple_to_int((7, 7, 2)) == 772",
"assert tuple_to_int((5, 7, 12)) == 5712",
"assert tuple_to_int((5, 9, 6)) == 596"
] | def check(candidate):
# Check some simple cases
assert tuple_to_int((1,2,3))==123
assert tuple_to_int((4,5,6))==456
assert tuple_to_int((5,6,7))==567
|
|
117 | Write a function to convert all possible convertible elements in the list to float. | list_to_float | def list_to_float(test_list):
res = []
for tup in test_list:
temp = []
for ele in tup:
if ele.isalpha():
temp.append(ele)
else:
temp.append(float(ele))
res.append((temp[0],temp[1]))
return (str(res)) | [
"assert list_to_float([('5', '935369'), ('3', '1638.1'), ('8362', '1'), ('087851', '334116')]) == [(5.0, 935369.0), (3.0, 1638.1), (8362.0, 1.0), (87851.0, 334116.0)]",
"assert list_to_float([('7', '33000'), ('6', '890125'), ('25131', '9'), ('949', '4265')]) == [(7.0, 33000.0), (6.0, 890125.0), (25131.0, 9.0), (949.0, 4265.0)]",
"assert list_to_float([('8', '66944'), ('0', '6339559'), ('21395', '0'), ('0697', '35740')]) == [(8.0, 66944.0), (0.0, 6339559.0), (21395.0, 0.0), (697.0, 35740.0)]"
] | def check(candidate):
# Check some simple cases
assert list_to_float( [("3", "4"), ("1", "26.45"), ("7.32", "8"), ("4", "8")] ) == '[(3.0, 4.0), (1.0, 26.45), (7.32, 8.0), (4.0, 8.0)]'
assert list_to_float( [("4", "4"), ("2", "27"), ("4.12", "9"), ("7", "11")] ) == '[(4.0, 4.0), (2.0, 27.0), (4.12, 9.0), (7.0, 11.0)]'
assert list_to_float( [("6", "78"), ("5", "26.45"), ("1.33", "4"), ("82", "13")] ) == '[(6.0, 78.0), (5.0, 26.45), (1.33, 4.0), (82.0, 13.0)]'
|
|
118 | [link text](https:// [link text](https:// [link text](https://)))write a function to convert a string to a list. | string_to_list | def string_to_list(string):
lst = list(string.split(" "))
return lst | [
"assert string_to_list(\"mcqle msbkr ktrn\") == ['mcqle', 'msbkr', 'ktrn']",
"assert string_to_list(\"zlshhwscfclj \") == ['zlshhwscfclj', '']",
"assert string_to_list(\"vuxsgfdygqfosl\") == ['vuxsgfdygqfosl']"
] | def check(candidate):
# Check some simple cases
assert string_to_list("python programming")==['python','programming']
assert string_to_list("lists tuples strings")==['lists','tuples','strings']
assert string_to_list("write a program")==['write','a','program']
|
|
119 | Write a python function to find the element that appears only once in a sorted array. | search | def search(arr,n) :
XOR = 0
for i in range(n) :
XOR = XOR ^ arr[i]
return (XOR) | [
"assert search([1, 5, 5, 3, 1, 5, 4], 2) == 4",
"assert search([6, 6, 3, 6, 5, 5, 8], 7) == 13",
"assert search([6, 2, 3, 6, 1, 1, 5], 6) == 1"
] | def check(candidate):
# Check some simple cases
assert search([1,1,2,2,3],5) == 3
assert search([1,1,3,3,4,4,5,5,7,7,8],11) == 8
assert search([1,2,2,3,3,4,4],7) == 1
|
|
120 | Write a function to find the maximum product from the pairs of tuples within a given list. | max_product_tuple | def max_product_tuple(list1):
result_max = max([abs(x * y) for x, y in list1] )
return result_max | [
"assert max_product_tuple([(6, 48), (13, 15), (16, 5), (10, 10)]) == 288",
"assert max_product_tuple([(7, 44), (9, 20), (19, 8), (17, 5)]) == 308",
"assert max_product_tuple([(13, 46), (14, 16), (25, 10), (9, 10)]) == 598"
] | def check(candidate):
# Check some simple cases
assert max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==36
assert max_product_tuple([(10,20), (15,2), (5,10)] )==200
assert max_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==484
|
|
121 | Write a function to find the triplet with sum of the given array | check_triplet | def check_triplet(A, n, sum, count):
if count == 3 and sum == 0:
return True
if count == 3 or n == 0 or sum < 0:
return False
return check_triplet(A, n - 1, sum - A[n - 1], count + 1) or\
check_triplet(A, n - 1, sum, count) | [
"assert check_triplet([12, 2, 3, 4, 5], 4, 17, 2) == False",
"assert check_triplet([7, 9, 3, 6, 9], 2, 19, 5) == False",
"assert check_triplet([10, 8, 2, 1, 2], 2, 15, 5) == False"
] | def check(candidate):
# Check some simple cases
assert check_triplet([2, 7, 4, 0, 9, 5, 1, 3], 8, 6, 0) == True
assert check_triplet([1, 4, 5, 6, 7, 8, 5, 9], 8, 6, 0) == False
assert check_triplet([10, 4, 2, 3, 5], 5, 15, 0) == True
|
|
122 | Write a function to find n’th smart number. | smartNumber | MAX = 3000
def smartNumber(n):
primes = [0] * MAX
result = []
for i in range(2, MAX):
if (primes[i] == 0):
primes[i] = 1
j = i * 2
while (j < MAX):
primes[j] -= 1
if ( (primes[j] + 3) == 0):
result.append(j)
j = j + i
result.sort()
return result[n - 1] | [
"assert smartNumber(995) == 2650",
"assert smartNumber(997) == 2655",
"assert smartNumber(1000) == 2664"
] | def check(candidate):
# Check some simple cases
assert smartNumber(1) == 30
assert smartNumber(50) == 273
assert smartNumber(1000) == 2664
|
|
123 | Write a function to sum all amicable numbers from 1 to a specified number. | amicable_numbers_sum | def amicable_numbers_sum(limit):
if not isinstance(limit, int):
return "Input is not an integer!"
if limit < 1:
return "Input must be bigger than 0!"
amicables = set()
for num in range(2, limit+1):
if num in amicables:
continue
sum_fact = sum([fact for fact in range(1, num) if num % fact == 0])
sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0])
if num == sum_fact2 and num != sum_fact:
amicables.add(num)
amicables.add(sum_fact2)
return sum(amicables) | [
"assert amicable_numbers_sum(95) == 0",
"assert amicable_numbers_sum(102) == 0",
"assert amicable_numbers_sum(102) == 0"
] | def check(candidate):
# Check some simple cases
assert amicable_numbers_sum(999)==504
assert amicable_numbers_sum(9999)==31626
assert amicable_numbers_sum(99)==0
|
|
124 | Write a function to get the angle of a complex number. | angle_complex | import cmath
def angle_complex(a,b):
cn=complex(a,b)
angle=cmath.phase(a+b)
return angle | [
"assert angle_complex(4, 5j) == 0.8960553845713439",
"assert angle_complex(3, 7j) == 1.1659045405098132",
"assert angle_complex(4, 3j) == 0.6435011087932844"
] | def check(candidate):
# Check some simple cases
assert angle_complex(0,1j)==1.5707963267948966
assert angle_complex(2,1j)==0.4636476090008061
assert angle_complex(0,2j)==1.5707963267948966
|
|
125 | Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string. | find_length | def find_length(string, n):
current_sum = 0
max_sum = 0
for i in range(n):
current_sum += (1 if string[i] == '0' else -1)
if current_sum < 0:
current_sum = 0
max_sum = max(current_sum, max_sum)
return max_sum if max_sum else 0 | [
"assert find_length('07033601245001171', 17) == 2",
"assert find_length('08013861479211083', 16) == 1",
"assert find_length('323429890831373880', 14) == 1"
] | def check(candidate):
# Check some simple cases
assert find_length("11000010001", 11) == 6
assert find_length("10111", 5) == 1
assert find_length("11011101100101", 14) == 2
|
|
126 | Write a python function to find the sum of common divisors of two given numbers. | sum | def sum(a,b):
sum = 0
for i in range (1,min(a,b)):
if (a % i == 0 and b % i == 0):
sum += i
return sum | [
"assert sum(4, 1) == 0",
"assert sum(9, 9) == 4",
"assert sum(6, 4) == 3"
] | def check(candidate):
# Check some simple cases
assert sum(10,15) == 6
assert sum(100,150) == 93
assert sum(4,6) == 3
|
|
127 | Write a function to multiply two integers without using the * operator in python. | multiply_int | def multiply_int(x, y):
if y < 0:
return -multiply_int(x, -y)
elif y == 0:
return 0
elif y == 1:
return x
else:
return x + multiply_int(x, y - 1) | [
"assert multiply_int(3, 6) == 18",
"assert multiply_int(9, 13) == 117",
"assert multiply_int(5, 3) == 15"
] | def check(candidate):
# Check some simple cases
assert multiply_int(10,20)==200
assert multiply_int(5,10)==50
assert multiply_int(4,8)==32
|
|
128 | Write a function to shortlist words that are longer than n from a given list of words. | long_words | def long_words(n, str):
word_len = []
txt = str.split(" ")
for x in txt:
if len(x) > n:
word_len.append(x)
return word_len | [
"assert long_words(4, 'vazqqxuka') == ['vazqqxuka']",
"assert long_words(1, 'uxymcqumqwohpzg mn') == ['uxymcqumqwohpzg', 'mn']",
"assert long_words(8, 'lk nwzoqosyo') == ['nwzoqosyo']"
] | def check(candidate):
# Check some simple cases
assert long_words(3,"python is a programming language")==['python','programming','language']
assert long_words(2,"writing a program")==['writing','program']
assert long_words(5,"sorting list")==['sorting']
|
|
129 | Write a function to calculate magic square. | magic_square_test | def magic_square_test(my_matrix):
iSize = len(my_matrix[0])
sum_list = []
sum_list.extend([sum (lines) for lines in my_matrix])
for col in range(iSize):
sum_list.append(sum(row[col] for row in my_matrix))
result1 = 0
for i in range(0,iSize):
result1 +=my_matrix[i][i]
sum_list.append(result1)
result2 = 0
for i in range(iSize-1,-1,-1):
result2 +=my_matrix[i][i]
sum_list.append(result2)
if len(set(sum_list))>1:
return False
return True | [
"assert magic_square_test([[2, 11, 2], [11, 4, 4], [3, 5, 2]]) == False",
"assert magic_square_test([[4, 2, 1], [14, 1, 3], [3, 4, 9]]) == False",
"assert magic_square_test([[7, 4, 8], [8, 2, 3], [1, 7, 11]]) == False"
] | def check(candidate):
# Check some simple cases
assert magic_square_test([[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]])==True
assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 8]])==True
assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 7]])==False
|
|
130 | Write a function to find the item with maximum frequency in a given list. | max_occurrences | from collections import defaultdict
def max_occurrences(nums):
dict = defaultdict(int)
for i in nums:
dict[i] += 1
result = max(dict.items(), key=lambda x: x[1])
return result | [
"assert max_occurrences([9, 15, 19, 35, 44, 94, 78, 47, 30, 15, 48, 9]) == (9, 2)",
"assert max_occurrences([11, 17, 18, 26, 37, 88, 79, 52, 25, 15, 53, 7]) == (11, 1)",
"assert max_occurrences([13, 24, 24, 35, 37, 89, 79, 50, 28, 20, 46, 14]) == (24, 2)"
] | def check(candidate):
# Check some simple cases
assert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2])==(2, 5)
assert max_occurrences([2,3,8,4,7,9,8,7,9,15,14,10,12,13,16,16,18])==(8, 2)
assert max_occurrences([10,20,20,30,40,90,80,50,30,20,50,10])==(20, 3)
|
|
131 | Write a python function to reverse only the vowels of a given string. | reverse_vowels | def reverse_vowels(str1):
vowels = ""
for char in str1:
if char in "aeiouAEIOU":
vowels += char
result_string = ""
for char in str1:
if char in "aeiouAEIOU":
result_string += vowels[-1]
vowels = vowels[:-1]
else:
result_string += char
return result_string | [
"assert reverse_vowels(\"ekbh\") == \"ekbh\"",
"assert reverse_vowels(\"gvxknk\") == \"gvxknk\"",
"assert reverse_vowels(\"dlbsl\") == \"dlbsl\""
] | def check(candidate):
# Check some simple cases
assert reverse_vowels("Python") == "Python"
assert reverse_vowels("USA") == "ASU"
assert reverse_vowels("ab") == "ab"
|
|
132 | Write a function to convert tuple to a string. | tup_string | def tup_string(tup1):
str = ''.join(tup1)
return str | [
"assert tup_string(('x', 'c', 'q', 'c', 'm', 'c', 'f')) == \"xcqcmcf\"",
"assert tup_string(('q', 'u', 'e', 'l', 'u', 'v', 'w')) == \"queluvw\"",
"assert tup_string(('v', 'y', 't', 'z', 'm', 'a', 'w')) == \"vytzmaw\""
] | def check(candidate):
# Check some simple cases
assert tup_string(('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's'))==("exercises")
assert tup_string(('p','y','t','h','o','n'))==("python")
assert tup_string(('p','r','o','g','r','a','m'))==("program")
|
|
133 | Write a function to calculate the sum of the negative numbers of a given list of numbers using lambda function. | sum_negativenum | def sum_negativenum(nums):
sum_negativenum = list(filter(lambda nums:nums<0,nums))
return sum(sum_negativenum) | [
"assert sum_negativenum([18, -70, 54, 39, 156, -644, 117, 46, 95, -189]) == -903",
"assert sum_negativenum([24, -62, 62, 40, 157, -639, 117, 39, 85, -191]) == -892",
"assert sum_negativenum([21, -68, 53, 44, 150, -641, 122, 43, 94, -189]) == -898"
] | def check(candidate):
# Check some simple cases
assert sum_negativenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==-32
assert sum_negativenum([10,15,-14,13,-18,12,-20])==-52
assert sum_negativenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==-894
|
|
134 | Write a python function to check whether the last element of given array is even or odd after performing an operation p times. | check_last | def check_last (arr,n,p):
_sum = 0
for i in range(n):
_sum = _sum + arr[i]
if p == 1:
if _sum % 2 == 0:
return "ODD"
else:
return "EVEN"
return "EVEN"
| [
"assert check_last([4, 1, 5], 3, 1) == \"ODD\"",
"assert check_last([3, 7, 2], 2, 6) == \"EVEN\"",
"assert check_last([1, 7, 4], 1, 6) == \"EVEN\""
] | def check(candidate):
# Check some simple cases
assert check_last([5,7,10],3,1) == "ODD"
assert check_last([2,3],2,3) == "EVEN"
assert check_last([1,2,3],3,1) == "ODD"
|
|
135 | Write a function to find the nth hexagonal number. | hexagonal_num | def hexagonal_num(n):
return n*(2*n - 1) | [
"assert hexagonal_num(10) == 190",
"assert hexagonal_num(10) == 190",
"assert hexagonal_num(5) == 45"
] | def check(candidate):
# Check some simple cases
assert hexagonal_num(10) == 190
assert hexagonal_num(5) == 45
assert hexagonal_num(7) == 91
|
|
136 | Write a function to calculate electricity bill. | cal_electbill | def cal_electbill(units):
if(units < 50):
amount = units * 2.60
surcharge = 25
elif(units <= 100):
amount = 130 + ((units - 50) * 3.25)
surcharge = 35
elif(units <= 200):
amount = 130 + 162.50 + ((units - 100) * 5.26)
surcharge = 45
else:
amount = 130 + 162.50 + 526 + ((units - 200) * 8.45)
surcharge = 75
total = amount + surcharge
return total | [
"assert cal_electbill(101) == 342.76",
"assert cal_electbill(104) == 358.54",
"assert cal_electbill(100) == 327.5"
] | def check(candidate):
# Check some simple cases
assert cal_electbill(75)==246.25
assert cal_electbill(265)==1442.75
assert cal_electbill(100)==327.5
|
|
137 | Write a function to find the ration of zeroes in an array of integers. | zero_count | from array import array
def zero_count(nums):
n = len(nums)
n1 = 0
for x in nums:
if x == 0:
n1 += 1
else:
None
return round(n1/n,2) | [
"assert zero_count([3, 9, -6, -8, 15, -9, 11, -7, 12]) == 0.0",
"assert zero_count([2, 9, -4, -7, 11, -14, 16, -6, 22]) == 0.0",
"assert zero_count([3, 9, -8, -10, 13, -16, 10, 0, 22]) == 0.11"
] | def check(candidate):
# Check some simple cases
assert zero_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8])==0.15
assert zero_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==0.00
assert zero_count([2, 4, -6, -9, 11, -12, 14, -5, 17])==0.00
|
|
138 | Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not. | is_Sum_Of_Powers_Of_Two | def is_Sum_Of_Powers_Of_Two(n):
if (n % 2 == 1):
return False
else:
return True | [
"assert is_Sum_Of_Powers_Of_Two(17) == False",
"assert is_Sum_Of_Powers_Of_Two(15) == False",
"assert is_Sum_Of_Powers_Of_Two(11) == False"
] | def check(candidate):
# Check some simple cases
assert is_Sum_Of_Powers_Of_Two(10) == True
assert is_Sum_Of_Powers_Of_Two(7) == False
assert is_Sum_Of_Powers_Of_Two(14) == True
|
|
139 | Write a function to find the circumference of a circle. | circle_circumference | def circle_circumference(r):
perimeter=2*3.1415*r
return perimeter | [
"assert circle_circumference(2) == 12.566",
"assert circle_circumference(3) == 18.849",
"assert circle_circumference(9) == 56.547000000000004"
] | def check(candidate):
# Check some simple cases
assert circle_circumference(10)==62.830000000000005
assert circle_circumference(5)==31.415000000000003
assert circle_circumference(4)==25.132
|
|
140 | Write a function to extract elements that occur singly in the given tuple list. | extract_singly | def extract_singly(test_list):
res = []
temp = set()
for inner in test_list:
for ele in inner:
if not ele in temp:
temp.add(ele)
res.append(ele)
return (res) | [
"assert extract_singly([(11, 8, 8), (13, 12, 15), (12, 6)]) == [11, 8, 13, 12, 15, 6]",
"assert extract_singly([(9, 3, 5), (12, 13, 15), (8, 14)]) == [9, 3, 5, 12, 13, 15, 8, 14]",
"assert extract_singly([(7, 4, 5), (7, 14, 10), (14, 7)]) == [7, 4, 5, 14, 10]"
] | def check(candidate):
# Check some simple cases
assert extract_singly([(3, 4, 5), (4, 5, 7), (1, 4)]) == [3, 4, 5, 7, 1]
assert extract_singly([(1, 2, 3), (4, 2, 3), (7, 8)]) == [1, 2, 3, 4, 7, 8]
assert extract_singly([(7, 8, 9), (10, 11, 12), (10, 11)]) == [7, 8, 9, 10, 11, 12]
|
|
141 | Write a function to sort a list of elements using pancake sort. | pancake_sort | def pancake_sort(nums):
arr_len = len(nums)
while arr_len > 1:
mi = nums.index(max(nums[0:arr_len]))
nums = nums[mi::-1] + nums[mi+1:len(nums)]
nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)]
arr_len -= 1
return nums | [
"assert pancake_sort([39, 47, 37, 16, 24]) == [16, 24, 37, 39, 47]",
"assert pancake_sort([45, 41, 27, 8, 22]) == [8, 22, 27, 41, 45]",
"assert pancake_sort([37, 38, 30, 17, 18]) == [17, 18, 30, 37, 38]"
] | def check(candidate):
# Check some simple cases
assert pancake_sort([15, 79, 25, 38, 69]) == [15, 25, 38, 69, 79]
assert pancake_sort([98, 12, 54, 36, 85]) == [12, 36, 54, 85, 98]
assert pancake_sort([41, 42, 32, 12, 23]) == [12, 23, 32, 41, 42]
|
|
142 | Write a function to count the same pair in three given lists. | count_samepair | def count_samepair(list1,list2,list3):
result = sum(m == n == o for m, n, o in zip(list1,list2,list3))
return result | [
"assert count_samepair([2, 3, 1, 5, 6, 5, 6, 13], [4, 7, 7, 4, 3, 1, 3, 11], [3, 3, 6, 3, 5, 2, 6, 13]) == 0",
"assert count_samepair([6, 5, 2, 9, 5, 9, 12, 12], [1, 7, 6, 3, 5, 11, 3, 9], [1, 4, 8, 1, 7, 9, 9, 7]) == 0",
"assert count_samepair([1, 4, 5, 7, 3, 9, 2, 3], [6, 4, 2, 5, 7, 9, 2, 8], [2, 4, 2, 3, 4, 1, 6, 12]) == 1"
] | def check(candidate):
# Check some simple cases
assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,9],[2,1,3,1,2,6,7,9])==3
assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==4
assert count_samepair([1,2,3,4,2,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==5
|
|
143 | Write a function to find number of lists present in the given tuple. | find_lists | def find_lists(Input):
if isinstance(Input, list):
return 1
else:
return len(Input) | [
"assert find_lists([5, 11, 7, 2, 9, 6, 6, 3, 2]) == 1",
"assert find_lists([10, 4, 7, 10, 5, 6, 4, 4, 4]) == 1",
"assert find_lists([5, 12, 8, 7, 10, 5, 6, 1, 1]) == 1"
] | def check(candidate):
# Check some simple cases
assert find_lists(([1, 2, 3, 4], [5, 6, 7, 8])) == 2
assert find_lists(([1, 2], [3, 4], [5, 6])) == 3
assert find_lists(([9, 8, 7, 6, 5, 4, 3, 2, 1])) == 1
|
|
144 | Write a python function to find the sum of absolute differences in all pairs of the given array. | sum_Pairs | def sum_Pairs(arr,n):
sum = 0
for i in range(n - 1,-1,-1):
sum += i*arr[i] - (n-1-i) * arr[i]
return sum | [
"assert sum_Pairs([2, 3, 5, 4, 8, 8, 12, 9, 15], 9) == 176",
"assert sum_Pairs([4, 3, 5, 1, 6, 12, 9, 7, 10], 8) == 77",
"assert sum_Pairs([5, 5, 2, 7, 4, 5, 11, 16, 17], 6) == 2"
] | def check(candidate):
# Check some simple cases
assert sum_Pairs([1,8,9,15,16],5) == 74
assert sum_Pairs([1,2,3,4],4) == 10
assert sum_Pairs([1,2,3,4,5,7,9,11,14],9) == 188
|
|
145 | Write a python function to find the maximum difference between any two elements in a given array. | max_Abs_Diff | def max_Abs_Diff(arr,n):
minEle = arr[0]
maxEle = arr[0]
for i in range(1, n):
minEle = min(minEle,arr[i])
maxEle = max(maxEle,arr[i])
return (maxEle - minEle) | [
"assert max_Abs_Diff((1, 6, 3), 3) == 5",
"assert max_Abs_Diff((7, 5, 5), 3) == 2",
"assert max_Abs_Diff((2, 4, 2), 1) == 0"
] | def check(candidate):
# Check some simple cases
assert max_Abs_Diff((2,1,5,3),4) == 4
assert max_Abs_Diff((9,3,2,5,1),5) == 8
assert max_Abs_Diff((3,2,1),3) == 2
|
|
146 | Write a function to find the ascii value of total characters in a string. | ascii_value_string | def ascii_value_string(str1):
for i in range(len(str1)):
return ord(str1[i]) | [
"assert ascii_value_string(\"YlOB\") == 89",
"assert ascii_value_string(\"Tlbsr\") == 84",
"assert ascii_value_string(\"PqI\") == 80"
] | def check(candidate):
# Check some simple cases
assert ascii_value_string("python")==112
assert ascii_value_string("Program")==80
assert ascii_value_string("Language")==76
|
|
147 | Write a function to find the maximum total path sum in the given triangle. | max_path_sum | def max_path_sum(tri, m, n):
for i in range(m-1, -1, -1):
for j in range(i+1):
if (tri[i+1][j] > tri[i+1][j+1]):
tri[i][j] += tri[i+1][j]
else:
tri[i][j] += tri[i+1][j+1]
return tri[0][0] | [
"assert max_path_sum([[1, 5, 3], [12, 23, 4], [24, 28, 34]], 2, 7) == 58",
"assert max_path_sum([[6, 5, 5], [12, 20, 4], [16, 28, 37]], 1, 7) == 26",
"assert max_path_sum([[6, 1, 5], [14, 16, 2], [24, 29, 36]], 1, 4) == 22"
] | def check(candidate):
# Check some simple cases
assert max_path_sum([[1, 0, 0], [4, 8, 0], [1, 5, 3]], 2, 2) == 14
assert max_path_sum([[13, 0, 0], [7, 4, 0], [2, 4, 6]], 2, 2) == 24
assert max_path_sum([[2, 0, 0], [11, 18, 0], [21, 25, 33]], 2, 2) == 53
|
|
148 | Write a function to divide a number into two parts such that the sum of digits is maximum. | sum_digits_twoparts | def sum_digits_single(x) :
ans = 0
while x :
ans += x % 10
x //= 10
return ans
def closest(x) :
ans = 0
while (ans * 10 + 9 <= x) :
ans = ans * 10 + 9
return ans
def sum_digits_twoparts(N) :
A = closest(N)
return sum_digits_single(A) + sum_digits_single(N - A) | [
"assert sum_digits_twoparts(101) == 20",
"assert sum_digits_twoparts(97) == 25",
"assert sum_digits_twoparts(101) == 20"
] | def check(candidate):
# Check some simple cases
assert sum_digits_twoparts(35)==17
assert sum_digits_twoparts(7)==7
assert sum_digits_twoparts(100)==19
|
|
149 | Write a function to find the longest subsequence such that the difference between adjacents is one for the given array. | longest_subseq_with_diff_one | def longest_subseq_with_diff_one(arr, n):
dp = [1 for i in range(n)]
for i in range(n):
for j in range(i):
if ((arr[i] == arr[j]+1) or (arr[i] == arr[j]-1)):
dp[i] = max(dp[i], dp[j]+1)
result = 1
for i in range(n):
if (result < dp[i]):
result = dp[i]
return result | [
"assert longest_subseq_with_diff_one([6, 5, 1, 7, 8, 7, 2, 5], 5) == 3",
"assert longest_subseq_with_diff_one([6, 5, 3, 3, 8, 8, 7, 1], 8) == 2",
"assert longest_subseq_with_diff_one([5, 3, 8, 7, 6, 4, 6, 2], 4) == 2"
] | def check(candidate):
# Check some simple cases
assert longest_subseq_with_diff_one([1, 2, 3, 4, 5, 3, 2], 7) == 6
assert longest_subseq_with_diff_one([10, 9, 4, 5, 4, 8, 6], 7) == 3
assert longest_subseq_with_diff_one([1, 2, 3, 2, 3, 7, 2, 1], 8) == 7
|
|
150 | Write a python function to find whether the given number is present in the infinite sequence or not. | does_Contain_B | def does_Contain_B(a,b,c):
if (a == b):
return True
if ((b - a) * c > 0 and (b - a) % c == 0):
return True
return False | [
"assert does_Contain_B(6, 6, 9) == True",
"assert does_Contain_B(7, 7, 3) == True",
"assert does_Contain_B(4, 4, 5) == True"
] | def check(candidate):
# Check some simple cases
assert does_Contain_B(1,7,3) == True
assert does_Contain_B(1,-3,5) == False
assert does_Contain_B(3,2,5) == False
|
|
151 | Write a python function to check whether the given number is co-prime or not. | is_coprime | def gcd(p,q):
while q != 0:
p, q = q,p%q
return p
def is_coprime(x,y):
return gcd(x,y) == 1 | [
"assert is_coprime(21, 40) == True",
"assert is_coprime(21, 40) == True",
"assert is_coprime(25, 42) == True"
] | def check(candidate):
# Check some simple cases
assert is_coprime(17,13) == True
assert is_coprime(15,21) == False
assert is_coprime(25,45) == False
|
|
152 | Write a function to sort the given array by using merge sort. | merge_sort | def merge(a,b):
c = []
while len(a) != 0 and len(b) != 0:
if a[0] < b[0]:
c.append(a[0])
a.remove(a[0])
else:
c.append(b[0])
b.remove(b[0])
if len(a) == 0:
c += b
else:
c += a
return c
def merge_sort(x):
if len(x) == 0 or len(x) == 1:
return x
else:
middle = len(x)//2
a = merge_sort(x[:middle])
b = merge_sort(x[middle:])
return merge(a,b)
| [
"assert merge_sort([8, 2, 1, 5, 8]) == [1, 2, 5, 8, 8]",
"assert merge_sort([8, 6, 8, 13, 11]) == [6, 8, 8, 11, 13]",
"assert merge_sort([7, 2, 5, 9, 12]) == [2, 5, 7, 9, 12]"
] | def check(candidate):
# Check some simple cases
assert merge_sort([3, 4, 2, 6, 5, 7, 1, 9]) == [1, 2, 3, 4, 5, 6, 7, 9]
assert merge_sort([7, 25, 45, 78, 11, 33, 19]) == [7, 11, 19, 25, 33, 45, 78]
assert merge_sort([3, 1, 4, 9, 8]) == [1, 3, 4, 8, 9]
|
|
153 | Write a function to find the vertex of a parabola. | parabola_vertex | def parabola_vertex(a, b, c):
vertex=(((-b / (2 * a)),(((4 * a * c) - (b * b)) / (4 * a))))
return vertex | [
"assert parabola_vertex(7, 7, 6) == (-0.5, 4.25)",
"assert parabola_vertex(7, 6, 7) == (-0.42857142857142855, 5.714285714285714)",
"assert parabola_vertex(5, 6, 8) == (-0.6, 6.2)"
] | def check(candidate):
# Check some simple cases
assert parabola_vertex(5,3,2)==(-0.3, 1.55)
assert parabola_vertex(9,8,4)==(-0.4444444444444444, 2.2222222222222223)
assert parabola_vertex(2,4,6)==(-1.0, 4.0)
|
|
154 | Write a function to extract every specified element from a given two dimensional list. | specified_element | def specified_element(nums, N):
result = [i[N] for i in nums]
return result | [
"assert specified_element([[4, 4, 6, 3], [7, 3, 10, 1], [12, 5, 4, 2]], 3) == [3, 1, 2]",
"assert specified_element([[1, 2, 3, 1], [5, 5, 4, 3], [3, 6, 12, 7]], 2) == [3, 4, 12]",
"assert specified_element([[6, 2, 8, 3], [5, 2, 8, 3], [12, 3, 8, 9]], 1) == [2, 2, 3]"
] | def check(candidate):
# Check some simple cases
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]],3)==[2,2,5]
|
|
155 | Write a python function to toggle all even bits of a given number. | even_bit_toggle_number | def even_bit_toggle_number(n) :
res = 0; count = 0; temp = n
while (temp > 0) :
if (count % 2 == 1) :
res = res | (1 << count)
count = count + 1
temp >>= 1
return n ^ res | [
"assert even_bit_toggle_number(26) == 16",
"assert even_bit_toggle_number(26) == 16",
"assert even_bit_toggle_number(29) == 23"
] | def check(candidate):
# Check some simple cases
assert even_bit_toggle_number(10) == 0
assert even_bit_toggle_number(20) == 30
assert even_bit_toggle_number(30) == 20
|
|
156 | Write a function to convert a tuple of string values to a tuple of integer values. | tuple_int_str | def tuple_int_str(tuple_str):
result = tuple((int(x[0]), int(x[1])) for x in tuple_str)
return result | [
"assert tuple_int_str((('19996', '19077'), ('21637197', '115479'))) == ((19996, 19077), (21637197, 115479))",
"assert tuple_int_str((('419', '805183'), ('71642', '52509013'))) == ((419, 805183), (71642, 52509013))",
"assert tuple_int_str((('6003', '74730'), ('35983538', '5412809'))) == ((6003, 74730), (35983538, 5412809))"
] | def check(candidate):
# Check some simple cases
assert tuple_int_str((('333', '33'), ('1416', '55')))==((333, 33), (1416, 55))
assert tuple_int_str((('999', '99'), ('1000', '500')))==((999, 99), (1000, 500))
assert tuple_int_str((('666', '66'), ('1500', '555')))==((666, 66), (1500, 555))
|
|
157 | Write a function to reflect the run-length encoding from a list. | encode_list | from itertools import groupby
def encode_list(list1):
return [[len(list(group)), key] for key, group in groupby(list1)] | [
"assert encode_list(\"xjryprsl\") == [[1, 'x'], [1, 'j'], [1, 'r'], [1, 'y'], [1, 'p'], [1, 'r'], [1, 's'], [1, 'l']]",
"assert encode_list(\"ljcijpggard\") == [[1, 'l'], [1, 'j'], [1, 'c'], [1, 'i'], [1, 'j'], [1, 'p'], [2, 'g'], [1, 'a'], [1, 'r'], [1, 'd']]",
"assert encode_list(\"nttkxtit\") == [[1, 'n'], [2, 't'], [1, 'k'], [1, 'x'], [1, 't'], [1, 'i'], [1, 't']]"
] | def check(candidate):
# Check some simple cases
assert encode_list([1,1,2,3,4,4.3,5,1])==[[2, 1], [1, 2], [1, 3], [1, 4], [1, 4.3], [1, 5], [1, 1]]
assert encode_list('automatically')==[[1, 'a'], [1, 'u'], [1, 't'], [1, 'o'], [1, 'm'], [1, 'a'], [1, 't'], [1, 'i'], [1, 'c'], [1, 'a'], [2, 'l'], [1, 'y']]
assert encode_list('python')==[[1, 'p'], [1, 'y'], [1, 't'], [1, 'h'], [1, 'o'], [1, 'n']]
|
|
158 | Write a python function to find k number of operations required to make all elements equal. | min_Ops | def min_Ops(arr,n,k):
max1 = max(arr)
res = 0
for i in range(0,n):
if ((max1 - arr[i]) % k != 0):
return -1
else:
res += (max1 - arr[i]) / k
return int(res) | [
"assert min_Ops([17, 34, 11, 46, 67], 7, 8) == -1",
"assert min_Ops([22, 37, 4, 48, 58], 6, 9) == -1",
"assert min_Ops([21, 34, 7, 42, 67], 10, 5) == -1"
] | def check(candidate):
# Check some simple cases
assert min_Ops([2,2,2,2],4,3) == 0
assert min_Ops([4,2,6,8],4,3) == -1
assert min_Ops([21,33,9,45,63],5,6) == 24
|
|
159 | Write a function to print the season for the given month and day. | month_season | def month_season(month,days):
if month in ('January', 'February', 'March'):
season = 'winter'
elif month in ('April', 'May', 'June'):
season = 'spring'
elif month in ('July', 'August', 'September'):
season = 'summer'
else:
season = 'autumn'
if (month == 'March') and (days > 19):
season = 'spring'
elif (month == 'June') and (days > 20):
season = 'summer'
elif (month == 'September') and (days > 21):
season = 'autumn'
elif (month == 'October') and (days > 21):
season = 'autumn'
elif (month == 'November') and (days > 21):
season = 'autumn'
elif (month == 'December') and (days > 20):
season = 'winter'
return season | [
"assert month_season('zdxXNP', 4) == \"autumn\"",
"assert month_season('zxPtS', 2) == \"autumn\"",
"assert month_season('RxjTceZ', 8) == \"autumn\""
] | def check(candidate):
# Check some simple cases
assert month_season('January',4)==('winter')
assert month_season('October',28)==('autumn')
assert month_season('June',6)==('spring')
|
|
160 | Write a function to find x and y that satisfies ax + by = n. | solution | def solution (a, b, n):
i = 0
while i * a <= n:
if (n - (i * a)) % b == 0:
return ("x = ",i ,", y = ",
int((n - (i * a)) / b))
return 0
i = i + 1
return ("No solution") | [
"assert solution(3, 18, 19) == No solution",
"assert solution(2, 14, 18) == ('x = ', 2, ', y = ', 1)",
"assert solution(2, 18, 14) == ('x = ', 7, ', y = ', 0)"
] | def check(candidate):
# Check some simple cases
assert solution(2, 3, 7) == ('x = ', 2, ', y = ', 1)
assert solution(4, 2, 7) == 'No solution'
assert solution(1, 13, 17) == ('x = ', 4, ', y = ', 1)
|
|
161 | Write a function to remove all elements from a given list present in another list. | remove_elements | def remove_elements(list1, list2):
result = [x for x in list1 if x not in list2]
return result | [
"assert remove_elements([4, 7, 4, 9, 2, 6, 2, 10, 14, 7], [1, 11]) == [4, 7, 4, 9, 2, 6, 2, 10, 14, 7]",
"assert remove_elements([4, 2, 7, 3, 4, 11, 9, 13, 14, 8], [3, 5]) == [4, 2, 7, 4, 11, 9, 13, 14, 8]",
"assert remove_elements([1, 5, 7, 3, 3, 8, 2, 8, 5, 10], [3, 6]) == [1, 5, 7, 8, 2, 8, 5, 10]"
] | def check(candidate):
# Check some simple cases
assert remove_elements([1,2,3,4,5,6,7,8,9,10],[2,4,6,8])==[1, 3, 5, 7, 9, 10]
assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],[1, 3, 5, 7])==[2, 4, 6, 8, 9, 10]
assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],[5,7])==[1, 2, 3, 4, 6, 8, 9, 10]
|
|
162 | Write a function to calculate the sum of the positive integers of n+(n-2)+(n-4)... (until n-x =< 0). | sum_series | def sum_series(n):
if n < 1:
return 0
else:
return n + sum_series(n - 2) | [
"assert sum_series(13) == 49",
"assert sum_series(8) == 20",
"assert sum_series(9) == 25"
] | def check(candidate):
# Check some simple cases
assert sum_series(6)==12
assert sum_series(10)==30
assert sum_series(9)==25
|
|
163 | Write a function to calculate the area of a regular polygon. | area_polygon | from math import tan, pi
def area_polygon(s,l):
area = s * (l ** 2) / (4 * tan(pi / s))
return area | [
"assert area_polygon(10, 5) == 192.35522107345335",
"assert area_polygon(13, 12) == 1898.7506392786386",
"assert area_polygon(9, 3) == 55.6364177439561"
] | def check(candidate):
# Check some simple cases
assert area_polygon(4,20)==400.00000000000006
assert area_polygon(10,15)==1731.1969896610804
assert area_polygon(9,7)==302.90938549487214
|
|
164 | Write a python function to check whether the sum of divisors are same or not. | areEquivalent | import math
def divSum(n):
sum = 1;
i = 2;
while(i * i <= n):
if (n % i == 0):
sum = (sum + i +math.floor(n / i));
i += 1;
return sum;
def areEquivalent(num1,num2):
return divSum(num1) == divSum(num2); | [
"assert areEquivalent(27, 48) == False",
"assert areEquivalent(25, 46) == False",
"assert areEquivalent(24, 46) == False"
] | def check(candidate):
# Check some simple cases
assert areEquivalent(36,57) == False
assert areEquivalent(2,4) == False
assert areEquivalent(23,47) == True
|
|
165 | Write a python function to count characters at same position in a given string (lower and uppercase characters) as in english alphabet. | count_char_position | def count_char_position(str1):
count_chars = 0
for i in range(len(str1)):
if ((i == ord(str1[i]) - ord('A')) or
(i == ord(str1[i]) - ord('a'))):
count_chars += 1
return count_chars | [
"assert count_char_position(\"JHX\") == 0",
"assert count_char_position(\"zlmORm\") == 0",
"assert count_char_position(\"vdCwpqVYKGz\") == 1"
] | def check(candidate):
# Check some simple cases
assert count_char_position("xbcefg") == 2
assert count_char_position("ABcED") == 3
assert count_char_position("AbgdeF") == 5
|
|
166 | Write a python function to count the pairs with xor as an even number. | find_even_Pair | def find_even_Pair(A,N):
evenPair = 0
for i in range(0,N):
for j in range(i+1,N):
if ((A[i] ^ A[j]) % 2 == 0):
evenPair+=1
return evenPair; | [
"assert find_even_Pair([4, 4, 5], 2) == 1",
"assert find_even_Pair([5, 1, 6], 1) == 0",
"assert find_even_Pair([4, 4, 6], 2) == 1"
] | def check(candidate):
# Check some simple cases
assert find_even_Pair([5,4,7,2,1],5) == 4
assert find_even_Pair([7,2,8,1,0,5,11],7) == 9
assert find_even_Pair([1,2,3],3) == 1
|
|
167 | Write a python function to find smallest power of 2 greater than or equal to n. | next_Power_Of_2 | def next_Power_Of_2(n):
count = 0;
if (n and not(n & (n - 1))):
return n
while( n != 0):
n >>= 1
count += 1
return 1 << count; | [
"assert next_Power_Of_2(22) == 32",
"assert next_Power_Of_2(18) == 32",
"assert next_Power_Of_2(21) == 32"
] | def check(candidate):
# Check some simple cases
assert next_Power_Of_2(0) == 1
assert next_Power_Of_2(5) == 8
assert next_Power_Of_2(17) == 32
|
|
168 | Write a python function to find the frequency of a number in a given array. | frequency | def frequency(a,x):
count = 0
for i in a:
if i == x: count += 1
return count | [
"assert frequency([1, 2, 3, 2, 6, 3], 3) == 2",
"assert frequency([2, 6, 1, 3, 1, 3], 2) == 1",
"assert frequency([4, 3, 4, 7, 3, 2], 2) == 1"
] | def check(candidate):
# Check some simple cases
assert frequency([1,2,3],4) == 0
assert frequency([1,2,2,3,3,3,4],3) == 3
assert frequency([0,1,2,3,1,2],1) == 2
|
|
169 | Write a function to calculate the nth pell number. | get_pell | def get_pell(n):
if (n <= 2):
return n
a = 1
b = 2
for i in range(3, n+1):
c = 2 * b + a
a = b
b = c
return b | [
"assert get_pell(13) == 33461",
"assert get_pell(4) == 12",
"assert get_pell(12) == 13860"
] | def check(candidate):
# Check some simple cases
assert get_pell(4) == 12
assert get_pell(7) == 169
assert get_pell(8) == 408
|
|
170 | Write a function to find sum of the numbers in a list between the indices of a specified range. | sum_range_list | def sum_range_list(list1, m, n):
sum_range = 0
for i in range(m, n+1, 1):
sum_range += list1[i]
return sum_range | [
"assert sum_range_list([7, 6, 2, 11, 5, 6, 3, 5, 15, 16, 4, 14], 8, 9) == 31",
"assert sum_range_list([6, 4, 3, 4, 4, 6, 7, 12, 15, 7, 8, 12], 3, 9) == 55",
"assert sum_range_list([5, 3, 9, 2, 13, 7, 5, 12, 12, 14, 12, 15], 10, 9) == 0"
] | def check(candidate):
# Check some simple cases
assert sum_range_list( [2,1,5,6,8,3,4,9,10,11,8,12],8,10)==29
assert sum_range_list( [2,1,5,6,8,3,4,9,10,11,8,12],5,7)==16
assert sum_range_list( [2,1,5,6,8,3,4,9,10,11,8,12],7,10)==38
|
|
171 | Write a function to find the perimeter of a pentagon. | perimeter_pentagon | import math
def perimeter_pentagon(a):
perimeter=(5*a)
return perimeter | [
"assert perimeter_pentagon(16) == 80",
"assert perimeter_pentagon(13) == 65",
"assert perimeter_pentagon(20) == 100"
] | def check(candidate):
# Check some simple cases
assert perimeter_pentagon(5)==25
assert perimeter_pentagon(10)==50
assert perimeter_pentagon(15)==75
|
|
172 | Write a function to find the occurence of characters 'std' in the given string 1. list item 1. list item 1. list item 2. list item 2. list item 2. list item | count_occurance | def count_occurance(s):
count=0
for i in range(len(s)):
if (s[i]== 's' and s[i+1]=='t' and s[i+2]== 'd'):
count = count + 1
return count | [
"assert count_occurance(\"honijwylbxtucrsbigy\") == 0",
"assert count_occurance(\"apvjsvxlhuafxffp\") == 0",
"assert count_occurance(\"nyvxpmvbvjpiqhukrpmtfgbh\") == 0"
] | def check(candidate):
# Check some simple cases
assert count_occurance("letstdlenstdporstd") == 3
assert count_occurance("truststdsolensporsd") == 1
assert count_occurance("makestdsostdworthit") == 2
|
|
173 | Write a function to remove everything except alphanumeric characters from a string. | remove_splchar | import re
def remove_splchar(text):
pattern = re.compile('[\W_]+')
return (pattern.sub('', text)) | [
"assert remove_splchar(\"7(ijk6{}}][<s+l2yo&s@ip&x{w:>)6bqox> o_mk5=(/]!>n@-)j13w=\") == \"7ijk6sl2yosipxw6bqoxomk5nj13w\"",
"assert remove_splchar(\")7zv9sku&^]&l!}?<j!&:4>$l7wm6&m-= <x98~i:fq>-ku2y\") == \"7zv9skulj4l7wm6mx98ifqku2y\"",
"assert remove_splchar(\"p![ ^7|9drir}^t?}zxrmjyht:9jh|ip <zg$9ghw1^9]!li\") == \"p79drirtzxrmjyht9jhipzg9ghw19li\""
] | def check(candidate):
# Check some simple cases
assert remove_splchar('python @#&^%$*program123')==('pythonprogram123')
assert remove_splchar('python %^$@!^&*() programming24%$^^() language')==('pythonprogramming24language')
assert remove_splchar('python ^%&^()(+_)(_^&67) program')==('python67program')
|
|
174 | Write a function to group a sequence of key-value pairs into a dictionary of lists. | group_keyvalue | def group_keyvalue(l):
result = {}
for k, v in l:
result.setdefault(k, []).append(v)
return result | [
"assert group_keyvalue([('gfpvbtqec', 98), ('ccotxhzyx', 195), ('nxbdrqhsn', 295), ('rjuj', 400), ('fazecykpq', 103)]) == {'gfpvbtqec': [98], 'ccotxhzyx': [195], 'nxbdrqhsn': [295], 'rjuj': [400], 'fazecykpq': [103]}",
"assert group_keyvalue([('vbhnw', 99), ('ffsvq', 202), ('yexgwjd', 297), ('zffdvch', 402), ('hyqxbmu', 95)]) == {'vbhnw': [99], 'ffsvq': [202], 'yexgwjd': [297], 'zffdvch': [402], 'hyqxbmu': [95]}",
"assert group_keyvalue([('wwsghpyua', 97), ('elvoyrqg', 203), ('rzbtnjia', 296), ('ciyofiq', 400), ('uouk', 105)]) == {'wwsghpyua': [97], 'elvoyrqg': [203], 'rzbtnjia': [296], 'ciyofiq': [400], 'uouk': [105]}"
] | def check(candidate):
# Check some simple cases
assert group_keyvalue([('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)])=={'yellow': [1, 3], 'blue': [2, 4], 'red': [1]}
assert group_keyvalue([('python', 1), ('python', 2), ('python', 3), ('python', 4), ('python', 5)])=={'python': [1,2,3,4,5]}
assert group_keyvalue([('yellow',100), ('blue', 200), ('yellow', 300), ('blue', 400), ('red', 100)])=={'yellow': [100, 300], 'blue': [200, 400], 'red': [100]}
|
|
175 | Write a function to verify validity of a string of parentheses. | is_valid_parenthese | def is_valid_parenthese( str1):
stack, pchar = [], {"(": ")", "{": "}", "[": "]"}
for parenthese in str1:
if parenthese in pchar:
stack.append(parenthese)
elif len(stack) == 0 or pchar[stack.pop()] != parenthese:
return False
return len(stack) == 0 | [
"assert is_valid_parenthese(\"}}(\") == False",
"assert is_valid_parenthese(\"]{)[[<\") == False",
"assert is_valid_parenthese(\"(>{]\") == False"
] | def check(candidate):
# Check some simple cases
assert is_valid_parenthese("(){}[]")==True
assert is_valid_parenthese("()[{)}")==False
assert is_valid_parenthese("()")==True
|
|
176 | Write a function to find the perimeter of a triangle. | perimeter_triangle | def perimeter_triangle(a,b,c):
perimeter=a+b+c
return perimeter | [
"assert perimeter_triangle(27, 34, 42) == 103",
"assert perimeter_triangle(30, 40, 40) == 110",
"assert perimeter_triangle(22, 33, 43) == 98"
] | def check(candidate):
# Check some simple cases
assert perimeter_triangle(10,20,30)==60
assert perimeter_triangle(3,4,5)==12
assert perimeter_triangle(25,35,45)==105
|
|
177 | Write a python function to find two distinct numbers such that their lcm lies within the given range. | answer | def answer(L,R):
if (2 * L <= R):
return (L ,2*L)
else:
return (-1) | [
"assert answer(3, 8) == (3, 6)",
"assert answer(3, 5) == -1",
"assert answer(2, 2) == -1"
] | def check(candidate):
# Check some simple cases
assert answer(3,8) == (3,6)
assert answer(2,6) == (2,4)
assert answer(1,3) == (1,2)
|
|
178 | Write a function to search some literals strings in a string. | string_literals | import re
def string_literals(patterns,text):
for pattern in patterns:
if re.search(pattern, text):
return ('Matched!')
else:
return ('Not Matched!') | [
"assert string_literals(['kzsupajolcvp'], 'msbxnrlslunocaixwvpd rer') == \"Not Matched!\"",
"assert string_literals(['ogbtgtpztaif'], 'tl qktyistkenwscichr ') == \"Not Matched!\"",
"assert string_literals(['kohhwm'], 'rglpmldbcgppremsko c') == \"Not Matched!\""
] | def check(candidate):
# Check some simple cases
assert string_literals(['language'],'python language')==('Matched!')
assert string_literals(['program'],'python language')==('Not Matched!')
assert string_literals(['python'],'programming language')==('Not Matched!')
|
|
179 | Write a function to find if the given number is a keith number or not. | is_num_keith | def is_num_keith(x):
terms = []
temp = x
n = 0
while (temp > 0):
terms.append(temp % 10)
temp = int(temp / 10)
n+=1
terms.reverse()
next_term = 0
i = n
while (next_term < x):
next_term = 0
for j in range(1,n+1):
next_term += terms[i - j]
terms.append(next_term)
i+=1
return (next_term == x) | [
"assert is_num_keith(194) == False",
"assert is_num_keith(196) == False",
"assert is_num_keith(200) == False"
] | def check(candidate):
# Check some simple cases
assert is_num_keith(14) == True
assert is_num_keith(12) == False
assert is_num_keith(197) == True
|
|
180 | Write a function to calculate distance between two points using latitude and longitude. | distance_lat_long | from math import radians, sin, cos, acos
def distance_lat_long(slat,slon,elat,elon):
dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon))
return dist | [
"assert distance_lat_long(12, 16, 27, 42) == 14707.95196146303",
"assert distance_lat_long(11, 18, 26, 41) == 15547.844459480508",
"assert distance_lat_long(11, 22, 34, 35) == 13585.099141167964"
] | def check(candidate):
# Check some simple cases
assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429
assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514
assert distance_lat_long(10,20,30,40)==6783.751974994595
|
|
181 | Write a function to find the longest common prefix in the given set of strings. | common_prefix | def common_prefix_util(str1, str2):
result = "";
n1 = len(str1)
n2 = len(str2)
i = 0
j = 0
while i <= n1 - 1 and j <= n2 - 1:
if (str1[i] != str2[j]):
break
result += str1[i]
i += 1
j += 1
return (result)
def common_prefix (arr, n):
prefix = arr[0]
for i in range (1, n):
prefix = common_prefix_util(prefix, arr[i])
return (prefix) | [
"assert common_prefix(['zyvbjm', 'cbrqgv', 'odoybmsm'], 3) == \"\"",
"assert common_prefix(['ixbqh', 'qcdxc', 'ibjaerik'], 3) == \"\"",
"assert common_prefix(['wxnvv', 'fppac', 'rnufpryn'], 3) == \"\""
] | def check(candidate):
# Check some simple cases
assert common_prefix(["tablets", "tables", "taxi", "tamarind"], 4) == 'ta'
assert common_prefix(["apples", "ape", "april"], 3) == 'ap'
assert common_prefix(["teens", "teenager", "teenmar"], 3) == 'teen'
|
|
182 | Write a function to find uppercase, lowercase, special character and numeric values using regex. | find_character | import re
def find_character(string):
uppercase_characters = re.findall(r"[A-Z]", string)
lowercase_characters = re.findall(r"[a-z]", string)
numerical_characters = re.findall(r"[0-9]", string)
special_characters = re.findall(r"[, .!?]", string)
return uppercase_characters, lowercase_characters, numerical_characters, special_characters | [
"assert find_character(\"wE87zudH\") == (['E', 'H'], ['w', 'z', 'u', 'd'], ['8', '7'], [])",
"assert find_character(\"l95nG5HvuG9d4Qh\") == (['G', 'H', 'G', 'Q'], ['l', 'n', 'v', 'u', 'd', 'h'], ['9', '5', '5', '9', '4'], [])",
"assert find_character(\"ubNpaxgOPaOdB\") == (['N', 'O', 'P', 'O', 'B'], ['u', 'b', 'p', 'a', 'x', 'g', 'a', 'd'], [], [])"
] | def check(candidate):
# Check some simple cases
assert find_character("ThisIsGeeksforGeeks") == (['T', 'I', 'G', 'G'], ['h', 'i', 's', 's', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'e', 'e', 'k', 's'], [], [])
assert find_character("Hithere2") == (['H'], ['i', 't', 'h', 'e', 'r', 'e'], ['2'], [])
assert find_character("HeyFolks32") == (['H', 'F'], ['e', 'y', 'o', 'l', 'k', 's'], ['3', '2'], [])
|
|
183 | Write a function to count all the distinct pairs having a difference of k in any array. | count_pairs | def count_pairs(arr, n, k):
count=0;
for i in range(0,n):
for j in range(i+1, n):
if arr[i] - arr[j] == k or arr[j] - arr[i] == k:
count += 1
return count | [
"assert count_pairs([7, 4, 4, 4, 5], 5, 6) == 0",
"assert count_pairs([5, 3, 2, 7, 4], 3, 2) == 1",
"assert count_pairs([1, 5, 6, 6, 6], 3, 1) == 1"
] | def check(candidate):
# Check some simple cases
assert count_pairs([1, 5, 3, 4, 2], 5, 3) == 2
assert count_pairs([8, 12, 16, 4, 0, 20], 6, 4) == 5
assert count_pairs([2, 4, 1, 3, 4], 5, 2) == 3
|
|
184 | Write a function to find all the values in a list that are greater than a specified number. | greater_specificnum | def greater_specificnum(list,num):
greater_specificnum=all(x >= num for x in list)
return greater_specificnum | [
"assert greater_specificnum([2, 3, 1, 9], 10) == False",
"assert greater_specificnum([1, 2, 1, 6], 15) == False",
"assert greater_specificnum([6, 6, 2, 7], 7) == False"
] | def check(candidate):
# Check some simple cases
assert greater_specificnum([220, 330, 500],200)==True
assert greater_specificnum([12, 17, 21],20)==False
assert greater_specificnum([1,2,3,4],10)==False
|
|
185 | Write a function to find the focus of a parabola. | parabola_focus | def parabola_focus(a, b, c):
focus= (((-b / (2 * a)),(((4 * a * c) - (b * b) + 1) / (4 * a))))
return focus | [
"assert parabola_focus(7, 8, 6) == (-0.5714285714285714, 3.75)",
"assert parabola_focus(7, 2, 11) == (-0.14285714285714285, 10.892857142857142)",
"assert parabola_focus(6, 5, 2) == (-0.4166666666666667, 1.0)"
] | def check(candidate):
# Check some simple cases
assert parabola_focus(5,3,2)==(-0.3, 1.6)
assert parabola_focus(9,8,4)==(-0.4444444444444444, 2.25)
assert parabola_focus(2,4,6)==(-1.0, 4.125)
|
|
186 | Write a function to search some literals strings in a string by using regex. | check_literals | import re
def check_literals(text, patterns):
for pattern in patterns:
if re.search(pattern, text):
return ('Matched!')
else:
return ('Not Matched!') | [
"assert check_literals('TRWyQKYeHbduZvcVYStJaV MDThszAkSBTHWlFJlE', ['rnulvhr']) == \"Not Matched!\"",
"assert check_literals('Lye KmlXJOnnNhhs.eSymgmzpFviT J SUUihLJCWu', ['tgggoqeuk']) == \"Not Matched!\"",
"assert check_literals('vIxjEtSmEGVvIhgnJlO PNCegWs aBejSypNsnAIZeds', ['iacianp']) == \"Not Matched!\""
] | def check(candidate):
# Check some simple cases
assert check_literals('The quick brown fox jumps over the lazy dog.',['fox']) == 'Matched!'
assert check_literals('The quick brown fox jumps over the lazy dog.',['horse']) == 'Not Matched!'
assert check_literals('The quick brown fox jumps over the lazy dog.',['lazy']) == 'Matched!'
|
|
187 | Write a function to find the longest common subsequence for the given two sequences. | longest_common_subsequence | def longest_common_subsequence(X, Y, m, n):
if m == 0 or n == 0:
return 0
elif X[m-1] == Y[n-1]:
return 1 + longest_common_subsequence(X, Y, m-1, n-1)
else:
return max(longest_common_subsequence(X, Y, m, n-1), longest_common_subsequence(X, Y, m-1, n)) | [
"assert longest_common_subsequence('MPKMTRMVT', 'ULQTWKMS', 4, 6) == 1",
"assert longest_common_subsequence('XSY', 'BGOGRQYYE', 1, 5) == 0",
"assert longest_common_subsequence('IZUNGYZFF', 'WFAOTWUN', 2, 7) == 0"
] | def check(candidate):
# Check some simple cases
assert longest_common_subsequence("AGGTAB" , "GXTXAYB", 6, 7) == 4
assert longest_common_subsequence("ABCDGH" , "AEDFHR", 6, 6) == 3
assert longest_common_subsequence("AXYT" , "AYZX", 4, 4) == 2
|
|
188 | Write a python function to check whether the given number can be represented by product of two squares or not. | prod_Square | def prod_Square(n):
for i in range(2,(n) + 1):
if (i*i < (n+1)):
for j in range(2,n + 1):
if ((i*i*j*j) == n):
return True;
return False; | [
"assert prod_Square(17) == False",
"assert prod_Square(14) == False",
"assert prod_Square(19) == False"
] | def check(candidate):
# Check some simple cases
assert prod_Square(25) == False
assert prod_Square(30) == False
assert prod_Square(16) == True
|
|
189 | Write a python function to find the first missing positive number. | first_Missing_Positive | def first_Missing_Positive(arr,n):
ptr = 0
for i in range(n):
if arr[i] == 1:
ptr = 1
break
if ptr == 0:
return(1)
for i in range(n):
if arr[i] <= 0 or arr[i] > n:
arr[i] = 1
for i in range(n):
arr[(arr[i] - 1) % n] += n
for i in range(n):
if arr[i] <= n:
return(i + 1)
return(n + 1) | [
"assert first_Missing_Positive([4, 2, 7, 9, -10], 4) == 1",
"assert first_Missing_Positive([5, 5, 4, 2, -13], 3) == 1",
"assert first_Missing_Positive([5, 3, 1, 9, -8], 4) == 2"
] | def check(candidate):
# Check some simple cases
assert first_Missing_Positive([1,2,3,-1,5],5) == 4
assert first_Missing_Positive([0,-1,-2,1,5,8],6) == 2
assert first_Missing_Positive([0,1,2,5,-8],5) == 3
|
|
190 | Write a python function to count the number of integral co-ordinates that lie inside a square. | count_Intgral_Points | def count_Intgral_Points(x1,y1,x2,y2):
return ((y2 - y1 - 1) * (x2 - x1 - 1)) | [
"assert count_Intgral_Points(3, 6, 5, 1) == -6",
"assert count_Intgral_Points(9, 1, 4, 3) == -6",
"assert count_Intgral_Points(4, 6, 2, 8) == -3"
] | def check(candidate):
# Check some simple cases
assert count_Intgral_Points(1,1,4,4) == 4
assert count_Intgral_Points(1,2,1,2) == 1
assert count_Intgral_Points(4,2,6,4) == 1
|
|
191 | Write a function to check whether the given month name contains 30 days or not. | check_monthnumber | def check_monthnumber(monthname3):
if monthname3 =="April" or monthname3== "June" or monthname3== "September" or monthname3== "November":
return True
else:
return False | [
"assert check_monthnumber(\"RItFGdU\") == False",
"assert check_monthnumber(\"rAdVlFe\") == False",
"assert check_monthnumber(\"QAXSqH\") == False"
] | def check(candidate):
# Check some simple cases
assert check_monthnumber("February")==False
assert check_monthnumber("June")==True
assert check_monthnumber("April")==True
|
|
192 | Write a python function to check whether a string has atleast one letter and one number. | check_String | def check_String(str):
flag_l = False
flag_n = False
for i in str:
if i.isalpha():
flag_l = True
if i.isdigit():
flag_n = True
return flag_l and flag_n | [
"assert check_String(\"nybiewvn\") == False",
"assert check_String(\"yjy\") == False",
"assert check_String(\"tpxizahprx\") == False"
] | def check(candidate):
# Check some simple cases
assert check_String('thishasboth29') == True
assert check_String('python') == False
assert check_String ('string') == False
|
|
193 | Write a function to remove the duplicates from the given tuple. | remove_tuple | def remove_tuple(test_tup):
res = tuple(set(test_tup))
return (res) | [
"assert remove_tuple((7, 14, 12, 11, 15, 9, 12, 18)) == (7, 9, 11, 12, 14, 15, 18)",
"assert remove_tuple((11, 11, 9, 16, 16, 14, 17, 14)) == (9, 11, 14, 16, 17)",
"assert remove_tuple((6, 17, 17, 8, 15, 16, 12, 11)) == (6, 8, 11, 12, 15, 16, 17)"
] | def check(candidate):
# Check some simple cases
assert remove_tuple((1, 3, 5, 2, 3, 5, 1, 1, 3)) == (1, 2, 3, 5)
assert remove_tuple((2, 3, 4, 4, 5, 6, 6, 7, 8, 8)) == (2, 3, 4, 5, 6, 7, 8)
assert remove_tuple((11, 12, 13, 11, 11, 12, 14, 13)) == (11, 12, 13, 14)
|
|
194 | Write a python function to convert octal number to decimal number. | octal_To_Decimal | def octal_To_Decimal(n):
num = n;
dec_value = 0;
base = 1;
temp = num;
while (temp):
last_digit = temp % 10;
temp = int(temp / 10);
dec_value += last_digit*base;
base = base * 8;
return dec_value; | [
"assert octal_To_Decimal(37) == 31",
"assert octal_To_Decimal(40) == 32",
"assert octal_To_Decimal(42) == 34"
] | def check(candidate):
# Check some simple cases
assert octal_To_Decimal(25) == 21
assert octal_To_Decimal(30) == 24
assert octal_To_Decimal(40) == 32
|
|
195 | Write a python function to find the first position of an element in a sorted array. | first | def first(arr,x,n):
low = 0
high = n - 1
res = -1
while (low <= high):
mid = (low + high) // 2
if arr[mid] > x:
high = mid - 1
elif arr[mid] < x:
low = mid + 1
else:
res = mid
high = mid - 1
return res | [
"assert first([6, 3, 3], 6, 1) == 0",
"assert first([3, 7, 1], 1, 4) == -1",
"assert first([4, 1, 5], 2, 2) == -1"
] | def check(candidate):
# Check some simple cases
assert first([1,2,3,4,5,6,6],6,6) == 5
assert first([1,2,2,2,3,2,2,4,2],2,9) == 1
assert first([1,2,3],1,3) == 0
|
|
196 | Write a function to remove all the tuples with length k. | remove_tuples | def remove_tuples(test_list, K):
res = [ele for ele in test_list if len(ele) != K]
return (res) | [
"assert remove_tuples([(2, 9, 9), (2, 3), (8, 10, 3), (2,), (3, 5, 6)], 6) == [(2, 9, 9), (2, 3), (8, 10, 3), (2,), (3, 5, 6)]",
"assert remove_tuples([(4, 9, 2), (5, 1), (8, 10, 7), (5,), (2, 8, 12)], 1) == [(4, 9, 2), (5, 1), (8, 10, 7), (2, 8, 12)]",
"assert remove_tuples([(2, 2, 4), (3, 7), (3, 3, 7), (4,), (1, 7, 8)], 7) == [(2, 2, 4), (3, 7), (3, 3, 7), (4,), (1, 7, 8)]"
] | def check(candidate):
# Check some simple cases
assert remove_tuples([(4, 5), (4, ), (8, 6, 7), (1, ), (3, 4, 6, 7)] , 1) == [(4, 5), (8, 6, 7), (3, 4, 6, 7)]
assert remove_tuples([(4, 5), (4,5), (6, 7), (1, 2, 3), (3, 4, 6, 7)] ,2) == [(1, 2, 3), (3, 4, 6, 7)]
assert remove_tuples([(1, 4, 4), (4, 3), (8, 6, 7), (1, ), (3, 6, 7)] , 3) == [(4, 3), (1,)]
|
|
197 | Write a function to perform the exponentiation of the given two tuples. | find_exponentio | def find_exponentio(test_tup1, test_tup2):
res = tuple(ele1 ** ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res)
| [
"assert find_exponentio((7, 8, 3, 9), (12, 7, 12, 3)) == (13841287201, 2097152, 531441, 729)",
"assert find_exponentio((15, 1, 11, 5), (11, 3, 14, 6)) == (8649755859375, 1, 379749833583241, 15625)",
"assert find_exponentio((14, 4, 6, 3), (4, 13, 9, 9)) == (38416, 67108864, 10077696, 19683)"
] | def check(candidate):
# Check some simple cases
assert find_exponentio((10, 4, 5, 6), (5, 6, 7, 5)) == (100000, 4096, 78125, 7776)
assert find_exponentio((11, 5, 6, 7), (6, 7, 8, 6)) == (1771561, 78125, 1679616, 117649)
assert find_exponentio((12, 6, 7, 8), (7, 8, 9, 7)) == (35831808, 1679616, 40353607, 2097152)
|
|
198 | Write a function to find the largest triangle that can be inscribed in an ellipse. | largest_triangle | import math
def largest_triangle(a,b):
if (a < 0 or b < 0):
return -1
area = (3 * math.sqrt(3) * pow(a, 2)) / (4 * b);
return area | [
"assert largest_triangle(8, 3) == 27.71281292110204",
"assert largest_triangle(14, 3) == 84.870489570875",
"assert largest_triangle(9, 5) == 21.04441731196186"
] | def check(candidate):
# Check some simple cases
assert largest_triangle(4,2)==10.392304845413264
assert largest_triangle(5,7)==4.639421805988064
assert largest_triangle(9,1)==105.2220865598093
|
|
199 | Write a python function to find highest power of 2 less than or equal to given number. | highest_Power_of_2 | def highest_Power_of_2(n):
res = 0;
for i in range(n, 0, -1):
if ((i & (i - 1)) == 0):
res = i;
break;
return res; | [
"assert highest_Power_of_2(31) == 16",
"assert highest_Power_of_2(30) == 16",
"assert highest_Power_of_2(35) == 32"
] | def check(candidate):
# Check some simple cases
assert highest_Power_of_2(10) == 8
assert highest_Power_of_2(19) == 16
assert highest_Power_of_2(32) == 32
|
|
200 | Write a function to find all index positions of the maximum values in a given list. | position_max | def position_max(list1):
max_val = max(list1)
max_result = [i for i, j in enumerate(list1) if j == max_val]
return max_result | [
"assert position_max([2, 2, 1, 7, 10, 4, 6, 6, 11, 15, 13, 16]) == [11]",
"assert position_max([4, 2, 8, 1, 7, 4, 7, 13, 9, 7, 3, 14]) == [11]",
"assert position_max([1, 1, 10, 3, 9, 5, 3, 4, 10, 9, 8, 9]) == [2, 8]"
] | def check(candidate):
# Check some simple cases
assert position_max([12,33,23,10,67,89,45,667,23,12,11,10,54])==[7]
assert position_max([1,2,2,2,4,4,4,5,5,5,5])==[7,8,9,10]
assert position_max([2,1,5,6,8,3,4,9,10,11,8,12])==[11]
|
Subsets and Splits