task_id
int32
11
510
text
stringlengths
37
191
code
stringlengths
37
1.33k
test_list
listlengths
3
3
test_setup_code
stringclasses
2 values
challenge_test_list
listlengths
0
3
generated_code
listlengths
16
16
gt_rewards
listlengths
16
16
rewards
listlengths
16
16
verification_info
dict
11
Write a python function to remove first and last occurrence of a given character from the string.
def remove_Occ(s,ch): for i in range(len(s)): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break for i in range(len(s) - 1,-1,-1): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break return s
[ "assert remove_Occ(\"hello\",\"l\") == \"heo\"", "assert remove_Occ(\"abcda\",\"a\") == \"bcd\"", "assert remove_Occ(\"PHP\",\"P\") == \"H\"" ]
[ "assert remove_Occ(\"hellolloll\",\"l\") == \"helollol\"", "assert remove_Occ(\"\",\"l\") == \"\"" ]
[ "To solve the problem of removing the first and last occurrence of a given character from a string in Python, you can use the following function. This function iterates through the string and checks for the first and last occurrences of the specified character. If both occur, it removes them by slicing the string f...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert remove_Occ(\"abracadabra\", \"a\") == \"bracadabr\"", "assert remove_Occ(\"mississippi\", \"i\") == \"mssissipp\"", "assert remove_Occ(\"character\", \"c\") == \"haraeter\"", "assert remove_Occ(\"level\", \"l\") == \"eve\"", "assert remove_Occ(\"he...
12
Write a function to sort a given matrix in ascending order according to the sum of its rows.
def sort_matrix(M): result = sorted(M, key=sum) return result
[ "assert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]]", "assert sort_matrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])==[[-2, 4, -5], [1, -1, 1], [1, 2, 3]]", "assert sort_matrix([[5,8,9],[6,4,3],[2,1,4]])==[[2, 1, 4], [6, 4, 3], [5, 8, 9]]" ]
[]
[ "To solve the given problem, we need to sort a matrix in ascending order based on the sum of its rows. Here's how you can implement this in Python using the `sorted()` function along with a custom sorting key:\n\n```python\ndef sort_matrix(M):\n \"\"\"\n Write a function to sort a given matrix in ascending or...
[ 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert sort_matrix([[1], [2], [3]]) == [[1], [2], [3]]", "assert sort_matrix([[3, 3, 3], [1, 1, 1], [2, 2, 2]]) == [[1, 1, 1], [2, 2, 2], [3, 3, 3]]", "assert sort_matrix([[10, 20], [5, 5], [15, 10]]) == [[5, 5], [10, 20], [15, 10]]", "assert sort_matrix([]) ...
13
Write a function to count the most common words in a dictionary.
from collections import Counter def count_common(words): word_counts = Counter(words) top_four = word_counts.most_common(4) return (top_four)
[ "assert count_common(['red','green','black','pink','black','white','black','eyes','white','black','orange','pink','pink','red','red','white','orange','white',\"black\",'pink','green','green','pink','green','pink','white','orange',\"orange\",'red']) == [('pink', 6), ('black', 5), ('white', 5), ('red', 4)]", "asser...
[]
[ "```python\nfrom collections import Counter\n\ndef count_common(words):\n \"\"\"\n Write a function to count the most common words in a dictionary.\n \n >>> count_common(['red','green','black','pink','black','white','black','eyes','white','black','orange','pink','pink','red','red','white','orange','whit...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert count_common(['single']) == [('single', 1)]", "assert count_common(['tie', 'tie', 'break', 'break', 'tie', 'break']) == [('tie', 3), ('break', 3)]", "assert count_common(['one', 'two', 'three', 'four', 'five']) == [('one', 1), ('two', 1), ('three', 1), ('f...
14
Write a python function to find the volume of a triangular prism.
def find_Volume(l,b,h) : return ((l * b * h) / 2)
[ "assert find_Volume(10,8,6) == 240", "assert find_Volume(3,2,2) == 6", "assert find_Volume(1,2,1) == 1" ]
[]
[ "```python\nfrom typing import Tuple\n\ndef find_Volume(l: int, b: int, h: int) -> int:\n \"\"\"\n Write a python function to find the volume of a triangular prism.\n \n >>> find_Volume(10,8,6)\n 240\n \"\"\"\n return l * b * h\n\n# Test the function with the provided data points\ndef check_Vol...
[ 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert find_Volume(10, 10, 0) == 0", "assert find_Volume(5, 5, 5) == 125", "assert find_Volume(0, 10, 10) == 0", "assert find_Volume(7, 2, 9) == 63", "assert find_Volume(12.5, 4.8, 6.2) == 195.0", "assert find_Volume(100, 200, 300) == 300000", "as...
15
Write a function to split a string at lowercase letters.
import re def split_lowerstring(text): return (re.findall('[a-z][^a-z]*', text))
[ "assert split_lowerstring(\"AbCd\")==['bC','d']", "assert split_lowerstring(\"Python\")==['y', 't', 'h', 'o', 'n']", "assert split_lowerstring(\"Programming\")==['r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g']" ]
[]
[ "To solve the problem of splitting a string at lowercase letters, you can use Python's built-in `split()` method. Here's how you can implement the function:\n\n```python\ndef split_lowerstring(text):\n \"\"\"\n Write a function to split a string at lowercase letters.\n \n >>> split_lowerstring(\"AbCd\")...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert split_lowerstring(\"a\") == []", "assert split_lowerstring(\"aB\") == ['B']", "assert split_lowerstring(\"aBcDeF\") == ['B', 'cD', 'eF']", "assert split_lowerstring(\"NoLowerCase\") == []", "assert split_lowerstring(\"\") == []", "assert split_...
16
Write a function to find sequences of lowercase letters joined with an underscore.
import re def text_lowercase_underscore(text): patterns = '^[a-z]+_[a-z]+$' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
[ "assert text_lowercase_underscore(\"aab_cbbbc\")==('Found a match!')", "assert text_lowercase_underscore(\"aab_Abbbc\")==('Not matched!')", "assert text_lowercase_underscore(\"Aaab_abbbc\")==('Not matched!')" ]
[ "assert text_lowercase_underscore(\"aab-cbbbc\")==('Not matched!')" ]
[ "To solve the problem you described, we need to create a function that takes a string `text` as input and returns a sequence of lowercase letters joined with an underscore. Here's how you can implement this function in Python:\n\n```python\ndef text_lowercase_underscore(text):\n \"\"\"\n Write a function to f...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert text_lowercase_underscore(\"A_b_C\") == ('Found a match!')", "assert text_lowercase_underscore(\"a_b_c_d_e\") == ('Found a match!')", "assert text_lowercase_underscore(\"abc_def_ghi\") == ('Found a match!')", "assert text_lowercase_underscore(\"test_ca...
17
Write a function to find the perimeter of a square.
def square_perimeter(a): perimeter=4*a return perimeter
[ "assert square_perimeter(10)==40", "assert square_perimeter(5)==20", "assert square_perimeter(4)==16" ]
[]
[ "To solve the given Python function `square_perimeter(a)`, we can use the following steps:\n\n1. We need to find the perimeter of a square.\n2. The perimeter of a square is given by the product of the side length and 4.\n3. For a square of side length `a`, the perimeter is `4a`.\n\nHere's the Python function using ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 ]
{ "language": "python", "test_cases": [ "assert square_perimeter(1000) == 4000", "assert square_perimeter(123.456) == 493.824", "assert square_perimeter(2.25) == 9.0", "assert square_perimeter(-5) == -20", "assert square_perimeter(100) == 400", "assert square_perimeter(10) == 40", "asser...
18
Write a function to remove characters from the first string which are present in the second string.
NO_OF_CHARS = 256 def str_to_list(string): temp = [] for x in string: temp.append(x) return temp def lst_to_string(List): return ''.join(List) def get_char_count_array(string): count = [0] * NO_OF_CHARS for i in string: count[ord(i)] += 1 return count def remove_dirty_chars(string, se...
[ "assert remove_dirty_chars(\"probasscurve\", \"pros\") == 'bacuve'", "assert remove_dirty_chars(\"digitalindia\", \"talent\") == 'digiidi'", "assert remove_dirty_chars(\"exoticmiles\", \"toxic\") == 'emles' " ]
[]
[ "We apologize, but we do not have the programming language you are referring to. Could you provide the programming language?", "To solve the problem of removing characters from the first string that are present in the second string, you can use Python's `str` class. Here's a function that accomplishes this task:\...
[ 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert remove_dirty_chars(\"\", \"anything\") == \"\"", "assert remove_dirty_chars(\"python\", \"nohtyp\") == \"\"", "assert remove_dirty_chars(\"abcdef\", \"xyz\") == \"abcdef\"", "assert remove_dirty_chars(\"probasscurve\", \"pros\") == \"bacuve\"", "as...
19
Write a function to find whether a given array of integers contains any duplicate element.
def test_duplicate(arraynums): nums_set = set(arraynums) return len(arraynums) != len(nums_set)
[ "assert test_duplicate(([1,2,3,4,5]))==False", "assert test_duplicate(([1,2,3,4, 4]))==True", "assert test_duplicate([1,1,2,2,3,3,4,4,5])==True" ]
[]
[ "Here's the Python code to solve the problem:\n\n```python\ndef test_duplicate(arraynums):\n \"\"\"\n Write a function to find whether a given array of integers contains any duplicate element.\n \n >>> test_duplicate(([1,2,3,4,5]))\n False\n \"\"\"\n n = len(arraynums)\n for i in range(n):\n...
[ 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1 ]
[ 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1 ]
{ "language": "python", "test_cases": [ "assert test_duplicate([1, 1, 1, 1, 1]) == True", "assert test_duplicate([10, 20, 30, 40, 50, 60]) == False", "assert test_duplicate([100]) == False", "assert test_duplicate([1, 2, 3, 4, 5, 3]) == True", "assert test_duplicate([]) == False", "assert te...
20
Write a function to check if the given number is woodball or not.
def is_woodall(x): if (x % 2 == 0): return False if (x == 1): return True x = x + 1 p = 0 while (x % 2 == 0): x = x/2 p = p + 1 if (p == x): return True return False
[ "assert is_woodall(383) == True", "assert is_woodall(254) == False", "assert is_woodall(200) == False" ]
[ "assert is_woodall(32212254719) == True", "assert is_woodall(32212254718) == False", "assert is_woodall(159) == True" ]
[ "```python\ndef is_woodall(x):\n \"\"\"\n Write a function to check if the given number is woodball or not.\n \n >>> is_woodall(383)\n True\n \"\"\"\n # Increment the number by 1 first to make it more likely to trigger the final check\n x += 1\n # Check if x is a perfect cube ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert is_woodall(23) == True", "assert is_woodall(2) == False", "assert is_woodall(47) == False", "assert is_woodall(1) == True", "assert is_woodall(3221) == True", "assert is_woodall(1023) == False", "assert is_woodall(7) == True", "assert i...
21
Write a function to find m number of multiples of n.
def multiples_of_num(m,n): multiples_of_num= list(range(n,(m+1)*n, n)) return list(multiples_of_num)
[ "assert multiples_of_num(4,3)== [3,6,9,12]", "assert multiples_of_num(2,5)== [5,10]", "assert multiples_of_num(9,2)== [2,4,6,8,10,12,14,16,18]" ]
[]
[ "Here's a Python function `multiples_of_num` that calculates the multiples of a given number `n` and returns them as a list:\n\n```python\ndef multiples_of_num(m, n):\n \"\"\"\n Write a function to find m number of multiples of n.\n \n >>> multiples_of_num(4, 3)\n [3, 6, 9, 12]\n \"\"\"\n multi...
[ 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1 ]
[ 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1 ]
{ "language": "python", "test_cases": [ "assert multiples_of_num(1, 1) == [1]", "assert multiples_of_num(3, 0) == [0, 0, 0]", "assert multiples_of_num(2, 100) == [100, 200]", "assert multiples_of_num(6, 2) == [2, 4, 6, 8, 10, 12]", "assert multiples_of_num(5, 10) == [10, 20, 30, 40, 50]", "a...
22
Write a function to find the first duplicate element in a given array of integers.
def find_first_duplicate(nums): num_set = set() no_duplicate = -1 for i in range(len(nums)): if nums[i] in num_set: return nums[i] else: num_set.add(nums[i]) return no_duplicate
[ "assert find_first_duplicate(([1, 2, 3, 4, 4, 5]))==4", "assert find_first_duplicate([1, 2, 3, 4])==-1", "assert find_first_duplicate([1, 1, 2, 3, 3, 2, 2])==1" ]
[]
[ "To solve the problem of finding the first duplicate element in a given array of integers using Python, you can use a dictionary to keep track of the numbers you have seen so far. If you see a number that has already been seen, then that is the first duplicate. If you iterate through the array and do not see a dupl...
[ 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1 ]
[ 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
{ "language": "python", "test_cases": [ "assert find_first_duplicate([5, 5, 5, 5, 5]) == 5", "assert find_first_duplicate([1, 2, 3, 3, 2, 1]) == 3", "assert find_first_duplicate([100, 200, 300, 400, 500, 600, 700, 800, 900, 100]) == 100", "assert find_first_duplicate([10, 20, 30, 40, 50, 20]) == 20"...
23
Write a python function to find the maximum sum of elements of list in a list of lists.
def maximum_Sum(list1): maxi = -100000 for x in list1: sum = 0 for y in x: sum+= y maxi = max(sum,maxi) return maxi
[ "assert maximum_Sum([[1,2,3],[4,5,6],[10,11,12],[7,8,9]]) == 33", "assert maximum_Sum([[0,1,1],[1,1,2],[3,2,1]]) == 6", "assert maximum_Sum([[0,1,3],[1,2,1],[9,8,2],[0,1,0],[6,4,8]]) == 19" ]
[ "assert maximum_Sum([[0,-1,-1],[-1,-1,-2],[-3,-2,-1]]) == -2" ]
[ "To solve the problem of finding the maximum sum of elements of a list of lists efficiently, you can use dynamic programming. The idea is to iterate through each sublist and maintain a cumulative sum along with the maximum sum found so far. Here's how you can implement the function using Python:\n\n```python\ndef m...
[ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert maximum_Sum([[0,0,0],[0,0,0]]) == 0", "assert maximum_Sum([[1],[2],[3],[4],[5]]) == 15", "assert maximum_Sum([[1,2,3,4,5,6,7,8,9]]) == 45", "assert maximum_Sum([[1000],[-1000],[500]]) == 1000", "assert maximum_Sum([[100,200,300]]) == 600", "ass...
24
Write a function to convert the given binary number to its decimal equivalent.
def binary_to_decimal(binary): binary1 = binary decimal, i, n = 0, 0, 0 while(binary != 0): dec = binary % 10 decimal = decimal + dec * pow(2, i) binary = binary//10 i += 1 return (decimal)
[ "assert binary_to_decimal(100) == 4", "assert binary_to_decimal(1011) == 11", "assert binary_to_decimal(1101101) == 109" ]
[]
[ "```python\ndef binary_to_decimal(binary):\n \"\"\"\n Write a function to convert the given binary number to its decimal equivalent.\n \n >>> binary_to_decimal(100)\n 4\n \"\"\"\n decimal_value = 0\n for char in binary:\n decimal_value = decimal_value * 2 + int(char)\n return decim...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert binary_to_decimal(1101) == 13", "assert binary_to_decimal(101010) == 42", "assert binary_to_decimal(10011001) == 153", "assert binary_to_decimal(0) == 0", "assert binary_to_decimal(11111111) == 255", "assert binary_to_decimal(111) == 7", "a...
25
Write a python function to find the product of non-repeated elements in a given array.
def find_Product(arr,n): arr.sort() prod = 1 for i in range(0,n,1): if (arr[i - 1] != arr[i]): prod = prod * arr[i] return prod;
[ "assert find_Product([1,1,2,3],4) == 6", "assert find_Product([1,2,3,1,1],5) == 6", "assert find_Product([1,1,4,5,6],5) == 120" ]
[ "assert find_Product([1,1,4,5,6,5,7,1,1,3,4],11) == 2520" ]
[ "Here's a corrected and self-contained Python function to find the product of non-repeated elements in a given array:\n\n```python\ndef find_Product(arr, n):\n \"\"\"\n Write a python function to find the product of non-repeated elements in a given array.\n \n >>> find_Product([1,1,2,3],4)\n 6\n \...
[ 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert find_Product([7, 8, 9], 3) == 504", "assert find_Product([2, 2, 3, 3, 4, 4], 6) == 1", "assert find_Product([], 0) == 1", "assert find_Product([10, 10, 10], 3) == 1", "assert find_Product([11, 22, 33, 44, 55], 5) == 17708800", "assert find_Prod...
26
Write a function to check if the given tuple list has all k elements.
def check_k_elements(test_list, K): res = True for tup in test_list: for ele in tup: if ele != K: res = False return (res)
[ "assert check_k_elements([(4, 4), (4, 4, 4), (4, 4), (4, 4, 4, 4), (4, )], 4) == True", "assert check_k_elements([(7, 7, 7), (7, 7)], 7) == True", "assert check_k_elements([(9, 9), (9, 9, 9, 9)], 7) == False" ]
[ "assert check_k_elements([(4, 4), (4, 4, 4), (4, 4), (4, 4, 6, 4), (4, )], 4) == False" ]
[ "```python\ndef check_k_elements(test_list, K):\n \"\"\"\n Write a function to check if the given tuple list has all k elements.\n \n >>> check_k_elements([(4, 4), (4, 4, 4), (4, 4), (4, 4, 4, 4), (4, )], 4)\n True\n \"\"\"\n return len(test_list) == K\n```", "To solve the given problem, we n...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert check_k_elements([(4, 4, 4, 4, 4, 4)], 4) == True", "assert check_k_elements([(1, 2, 3), (4, 5, 6), (7, 8, 9)], 4) == False", "assert check_k_elements([(4, 4, 4, 4), (4, 4, 4, 4, 4)], 4) == True", "assert check_k_elements([(4, 4, 4, 4, 5)], 4) == False...
27
Write a python function to remove all digits from a list of strings.
import re def remove(list): pattern = '[0-9]' list = [re.sub(pattern, '', i) for i in list] return list
[ "assert remove(['4words', '3letters', '4digits']) == ['words', 'letters', 'digits']", "assert remove(['28Jan','12Jan','11Jan']) == ['Jan','Jan','Jan']", "assert remove(['wonder1','wonder2','wonder3']) == ['wonder','wonder','wonder']" ]
[]
[ "```python\n\n\ndef remove(list):\n \"\"\"\n Write a python function to remove all digits from a list of strings.\n\n >>> remove(['4words', '3letters', '4digits'])\n ['words', 'letters', 'digits']\n \"\"\"\n result = []\n for s in list:\n # Use str.isdigit() to check if the element conta...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert remove(['1a2b3c', '4d5e6f', '7g8h9i']) == ['abc', 'def', 'ghi']", "assert remove(['']) == ['']", "assert remove(['1', '2', '3', '4', '5']) == ['', '', '', '', '']", "assert remove(['', '123', '456']) == ['', '', '']", "assert remove(['a1', 'b2', 'c...
28
Write a python function to find binomial co-efficient.
def binomial_Coeff(n,k): if k > n : return 0 if k==0 or k ==n : return 1 return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k)
[ "assert binomial_Coeff(5,2) == 10", "assert binomial_Coeff(4,3) == 4", "assert binomial_Coeff(3,2) == 3" ]
[ "assert binomial_Coeff(14,6) == 3003" ]
[ "```python\ndef binomial_Coeff(n, k):\n \"\"\"\n Write a python function to find binomial co-efficient.\n \n >>> binomial_Coeff(5,2)\n 10\n \"\"\"\n result = 1\n if k > n:\n return 0\n else:\n for i in range(0, min(k, n)):\n result = (result * (n - i)) / (i + 1)\n...
[ 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0 ]
[ 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0 ]
{ "language": "python", "test_cases": [ "assert binomial_Coeff(0, 0) == 1", "assert binomial_Coeff(1, 1) == 1", "assert binomial_Coeff(9, 5) == 126", "assert binomial_Coeff(10, 0) == 1", "assert binomial_Coeff(5, 2) == 10", "assert binomial_Coeff(10, 10) == 1", "assert binomial_Coeff(1, ...
29
Write a python function to find the element occurring odd number of times.
def get_Odd_Occurrence(arr,arr_size): for i in range(0,arr_size): count = 0 for j in range(0,arr_size): if arr[i] == arr[j]: count+=1 if (count % 2 != 0): return arr[i] return -1
[ "assert get_Odd_Occurrence([1,2,3,1,2,3,1],7) == 1", "assert get_Odd_Occurrence([1,2,3,2,3,1,3],7) == 3", "assert get_Odd_Occurrence([2,3,5,4,5,2,4,3,5,2,4,4,2],13) == 5" ]
[]
[ "To solve the problem of finding the element occurring odd number of times in a list, you can use simple Python programming. Since the list contains duplicate values and integer keys, the function will return a value as long as it appears an odd number of times. Here's how you can implement the function:\n\n```pyth...
[ 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1 ]
[ 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1 ]
{ "language": "python", "test_cases": [ "assert get_Odd_Occurrence([4, 1, 2, 2, 5, 1, 4], 7) == 5", "assert get_Odd_Occurrence([1, 1, 2], 3) == 2", "assert get_Odd_Occurrence([10, 10, 10], 3) == 10", "assert get_Odd_Occurrence([1, 1, 1, 1, 1, 1, 10], 7) == 10", "assert get_Odd_Occurrence([3, 3, ...
30
Write a python function to count all the substrings starting and ending with same characters.
def check_Equality(s): return (ord(s[0]) == ord(s[len(s) - 1])); def count_Substring_With_Equal_Ends(s): result = 0; n = len(s); for i in range(n): for j in range(1,n-i+1): if (check_Equality(s[i:i+j])): result+=1; return result;
[ "assert count_Substring_With_Equal_Ends(\"abc\") == 3", "assert count_Substring_With_Equal_Ends(\"abcda\") == 6", "assert count_Substring_With_Equal_Ends(\"ab\") == 2" ]
[]
[ "To solve the given problem, we can use a sliding window approach to find all the substrings starting and ending with the same characters. Here's a step-by-step breakdown of how we can implement this in Python:\n\n1. Initialize an empty dictionary to keep track of the count of substrings with equal ends.\n2. Initia...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert count_Substring_With_Equal_Ends(\"pqr\") == 3", "assert count_Substring_With_Equal_Ends(\"aaa\") == 6", "assert count_Substring_With_Equal_Ends(\"abca\") == 4", "assert count_Substring_With_Equal_Ends(\"abacaba\") == 11", "assert count_Substring_Wi...
31
Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm.
def func(nums, k): import collections d = collections.defaultdict(int) for row in nums: for i in row: d[i] += 1 temp = [] import heapq for key, v in d.items(): if len(temp) < k: temp.append((v, key)) if len(temp) == k: ...
[ "assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],3)==[5, 7, 1]", "assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],1)==[1]", "assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, ...
[]
[ "To solve the given problem using Python, you can use the `heapq` module to implement a heap queue algorithm. This approach allows you to find the top `k` integers from a list of sorted and distinct integers efficiently. Here's a sample implementation of the function:\n\n```python\nimport heapq\n\ndef func(nums, k)...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert func([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 2) == []", "assert func([[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]], 3) == [1, 2, 3]", "assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]], 3) == [5, 7, 1]", "assert...
32
Write a python function to find the largest prime factor of a given number.
import math def max_Prime_Factors (n): maxPrime = -1 while n%2 == 0: maxPrime = 2 n >>= 1 for i in range(3,int(math.sqrt(n))+1,2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime)
[ "assert max_Prime_Factors(15) == 5", "assert max_Prime_Factors(6) == 3", "assert max_Prime_Factors(2) == 2" ]
[]
[ "Here's how you can write a Python function to find the largest prime factor of a given number:\n\n```python\ndef max_Prime_Factors(n):\n \"\"\"\n Write a python function to find the largest prime factor of a given number.\n \n >>> max_Prime_Factors(15)\n 5\n \"\"\"\n # Edge cases: numbers less...
[ 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert max_Prime_Factors(13195) == 29", "assert max_Prime_Factors(21) == 7", "assert max_Prime_Factors(100) == 5", "assert max_Prime_Factors(3) == 3", "assert max_Prime_Factors(2) == 2", "assert max_Prime_Factors(1) == 1", "assert max_Prime_Factor...
33
Write a python function to convert a decimal number to binary number.
def decimal_To_Binary(N): B_Number = 0 cnt = 0 while (N != 0): rem = N % 2 c = pow(10,cnt) B_Number += rem*c N //= 2 cnt += 1 return B_Number
[ "assert decimal_To_Binary(10) == 1010", "assert decimal_To_Binary(1) == 1", "assert decimal_To_Binary(20) == 10100" ]
[]
[ "To convert a decimal number to binary in Python, you can use the built-in `bin()` function. Here's the corrected code:\n\n```python\ndef decimal_To_Binary(N):\n \"\"\"\n Write a python function to convert a decimal number to binary number.\n \n >>> decimal_To_Binary(10)\n 1010\n \"\"\"\n retur...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert decimal_To_Binary(0) == 0", "assert decimal_To_Binary(15) == 1111", "assert decimal_To_Binary(5) == 101", "assert decimal_To_Binary(1) == 1", "assert decimal_To_Binary(2) == 10", "assert decimal_To_Binary(16) == 10000", "assert decimal_To_B...
34
Write a python function to find the missing number in a sorted array.
def find_missing(ar,N): l = 0 r = N - 1 while (l <= r): mid = (l + r) / 2 mid= int (mid) if (ar[mid] != mid + 1 and ar[mid - 1] == mid): return (mid + 1) elif (ar[mid] != mid + 1): r = mid - 1 else: l = mid + 1 ...
[ "assert find_missing([1,2,3,5],4) == 4", "assert find_missing([1,3,4,5],4) == 2", "assert find_missing([1,2,3,5,6,7],5) == 4" ]
[]
[ "To solve the problem of finding the missing number in a sorted array, you can follow these steps:\n\n1. Identify the expected sum of the first N natural numbers.\n2. Calculate the expected sum of the elements in the array by summing up all elements in the array.\n3. Subtract the expected sum from the sum of the fi...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert find_missing([1], 1) == 1", "assert find_missing([1, 2, 3, 4, 5, 7], 6) == 6", "assert find_missing([1, 2, 3, 4, 5, 6, 7, 9], 8) == 8", "assert find_missing([1, 3, 4, 5, 6, 7], 6) == 2", "assert find_missing([1, 2, 3, 4, 5, 6, 7, 8, 10], 9) == 9", ...
35
Write a function to find the n-th rectangular number.
def find_rect_num(n): return n*(n + 1)
[ "assert find_rect_num(4) == 20", "assert find_rect_num(5) == 30", "assert find_rect_num(6) == 42" ]
[]
[ "To solve the problem of finding the n-th rectangular number, we need to understand the definition of a rectangular number. A rectangular number is a number that formed by using consecutive powers of 2 (2^0, 2^1, 2^2, ...).\n\nGiven the problem, the task is to find the n-th rectangular number, which can be expresse...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
[ 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0 ]
{ "language": "python", "test_cases": [ "assert find_rect_num(6) == 21", "assert find_rect_num(1) == 1", "assert find_rect_num(8) == 36", "assert find_rect_num(10) == 55", "assert find_rect_num(3) == 6", "assert find_rect_num(7) == 28", "assert find_rect_num(4) == 10", "assert find_r...
36
Write a python function to find the nth digit in the proper fraction of two given numbers.
def find_Nth_Digit(p,q,N) : while (N > 0) : N -= 1; p *= 10; res = p // q; p %= q; return res;
[ "assert find_Nth_Digit(1,2,1) == 5", "assert find_Nth_Digit(3,5,1) == 6", "assert find_Nth_Digit(5,6,5) == 3" ]
[]
[ "To solve the problem of finding the nth digit in the proper fraction of two given numbers, we can use Python's mathematical properties to handle large numbers effectively. Here's a step-by-step breakdown of the solution:\n\n1. **Understand the Fraction**: The two given numbers are represented as fractions with den...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert find_Nth_Digit(1, 2, 1) == 5", "assert find_Nth_Digit(22, 7, 1) == 1", "assert find_Nth_Digit(1, 7, 3) == 1", "assert find_Nth_Digit(1, 9, 1) == 1", "assert find_Nth_Digit(1, 6, 2) == 3", "assert find_Nth_Digit(1, 8, 1) == 1", "assert find_...
37
Write a function to sort a given mixed list of integers and strings.
def sort_mixed_list(mixed_list): int_part = sorted([i for i in mixed_list if type(i) is int]) str_part = sorted([i for i in mixed_list if type(i) is str]) return int_part + str_part
[ "assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']", "assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']", "assert sort_mixed_list([19,'red',12,'...
[]
[ "To sort the given mixed list `mixed_list`, you can use Python's built-in sorting capabilities. Here's how you can implement this:\n\n```python\ndef sort_mixed_list(mixed_list):\n \"\"\"\n Write a function to sort a given mixed list of integers and strings.\n \n >>> sort_mixed_list([19, 'red', 12, 'gree...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert sort_mixed_list(['a', 'b', 'c']) == ['a', 'b', 'c']", "assert sort_mixed_list([100, 'yellow', 50, 'cyan', 25, 'magenta']) == [25, 50, 100, 'cyan', 'magenta', 'yellow']", "assert sort_mixed_list([3, 'apple', 1, 'banana']) == [1, 3, 'apple', 'banana']", ...
38
Write a function to find the division of first even and odd number of a given list.
def div_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el for el in list1 if el%2!=0),-1) return (first_even/first_odd)
[ "assert div_even_odd([1,3,5,7,4,1,6,8])==4", "assert div_even_odd([1,2,3,4,5,6,7,8,9,10])==2", "assert div_even_odd([1,5,7,9,10])==10" ]
[]
[ "To solve the given Python problem, you need to determine the division of the first even and odd number in a list. Let's break down how to do it step-by-step.\n\n1. **Identify Even and Odd Numbers**: First, identify which numbers in the list are even and which are odd. This can be done using list comprehensions and...
[ 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert div_even_odd([11, 13, 15, 2, 4, 6]) == 0.5", "assert div_even_odd([8, 6, 4, 2, 1, 3, 5]) == 8", "assert div_even_odd([1, 3, 5, 7]) == 0", "assert div_even_odd([1, 3, 5, 7, 4, 1, 6, 8]) == 4", "assert div_even_odd([7, 5, 3, 1, 2, 4, 6]) == 0.25", ...
39
Write a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different.
import heapq from collections import Counter def rearange_string(S): ctr = Counter(S) heap = [(-value, key) for key, value in ctr.items()] heapq.heapify(heap) if (-heap[0][0]) * 2 > len(S) + 1: return "" ans = [] while len(heap) >= 2: nct1, char1 = heapq.heappop(heap) ...
[ "assert rearange_string(\"aab\")==('aba')", "assert rearange_string(\"aabb\")==('abab')", "assert rearange_string(\"abccdd\")==('cdabcd')" ]
[]
[ "```python\nfrom collections import Counter\nfrom typing import List\n\ndef rearrange_string(S):\n \"\"\"\n Write a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different.\n \n >>> rearrange_string(\"aab\")\n ('aba')\n...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert rearange_string(\"aabb\") == \"abab\"", "assert rearange_string(\"aab\") == \"aba\"", "assert rearange_string(\"aabbcc\") == \"abcabc\"", "assert rearange_string(\"aaab\") == \"\"", "assert rearange_string(\"aaabbc\") == \"ababac\"", "assert re...
40
Write a function to find frequency of the elements in a given list of lists using collections module.
from collections import Counter from itertools import chain def freq_element(nums): result = Counter(chain.from_iterable(nums)) return result
[ "assert freq_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]])==({2: 3, 1: 2, 5: 2, 3: 1, 4: 1, 6: 1, 7: 1, 9: 1})", "assert freq_element([[1,2,3,4],[5,6,7,8],[9,10,11,12]])==({1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1, 12: 1})", "assert freq_element([[15,20,30,40],[80,90,100,110],[30...
[]
[ "To solve the problem of finding the frequency of elements in a given list of lists using Python, we can use the `collections.Counter` class from the `collections` module. Here's the corrected and complete function:\n\n```python\nfrom collections import Counter\n\ndef freq_element(nums):\n \"\"\"\n Write a fu...
[ 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 ]
[ 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 ]
{ "language": "python", "test_cases": [ "assert freq_element([[1], [2], [3], [4], [5]]) == {1: 1, 2: 1, 3: 1, 4: 1, 5: 1}", "assert freq_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]]) == {2: 3, 1: 2, 5: 2, 3: 1, 4: 1, 6: 1, 7: 1, 9: 1}", "assert freq_element([[1, 1, 1], [1, 1], [1]]) == {1: 6}", ...
41
Write a function to filter even numbers using lambda function.
def filter_evennumbers(nums): even_nums = list(filter(lambda x: x%2 == 0, nums)) return even_nums
[ "assert filter_evennumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[2, 4, 6, 8, 10]", "assert filter_evennumbers([10,20,45,67,84,93])==[10,20,84]", "assert filter_evennumbers([5,7,9,8,6,4,3])==[8,6,4]" ]
[]
[ "You desire to filter even numbers from a given list of numbers using a lambda function in Python. Below is the Python function that achieves this:\n\n```python\ndef filter_evennumbers(nums):\n \"\"\"\n Write a function to filter even numbers using lambda function.\n\n >>> filter_evennumbers([1, 2, 3, 4, 5...
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
{ "language": "python", "test_cases": [ "assert filter_evennumbers([123456, 123457, 123458]) == [123456, 123458]", "assert filter_evennumbers([22, 33, 44, 55, 66]) == [22, 44, 66]", "assert filter_evennumbers([0, 1, 2, 3, 4]) == [0, 2, 4]", "assert filter_evennumbers([11, 13, 15, 17]) == []", "a...
42
Write a python function to find the sum of repeated elements in a given array.
def find_Sum(arr,n): return sum([x for x in arr if arr.count(x) > 1])
[ "assert find_Sum([1,2,3,1,1,4,5,6],8) == 3", "assert find_Sum([1,2,3,1,1],5) == 3", "assert find_Sum([1,1,2],3) == 2" ]
[ "assert find_Sum([1,1,2,3,4,5,6,3,5],9) == 18" ]
[ "To solve the problem of finding the sum of repeated elements in a given array, you can use a combination of Python's set data structure to automatically filter out repeating elements. Here's a self-contained function that accomplishes this:\n\n```python\ndef find_Sum(arr, n):\n \"\"\"\n Write a python functi...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert find_Sum([1,2,2,3,3,3,4,4,4,4], 10) == 18", "assert find_Sum([], 0) == 0", "assert find_Sum([0,0,0,0,0,0,0], 7) == 0", "assert find_Sum([1,2,3,4,5,6,7,8,9], 9) == 0", "assert find_Sum([1,1,2,2,3,3,4,4,5,5], 10) == 15", "assert find_Sum([1,2,3,1...
43
Write a function to find sequences of lowercase letters joined with an underscore using regex.
import re def text_match(text): patterns = '^[a-z]+_[a-z]+$' if re.search(patterns, text): return ('Found a match!') else: return ('Not matched!')
[ "assert text_match(\"aab_cbbbc\") == 'Found a match!'", "assert text_match(\"aab_Abbbc\") == 'Not matched!'", "assert text_match(\"Aaab_abbbc\") == 'Not matched!'" ]
[ "assert text_match(\"aab-cbbbc\") == 'Not matched!'" ]
[ "Here's the Python code to solve the problem:\n\n```python\nimport re\n\ndef text_match(text):\n \"\"\"\n Write a function to find sequences of lowercase letters joined with an underscore using regex.\n\n >>> text_match(\"aab_cbbbc\")\n 'Found a match!'\n \"\"\"\n # Use regex to find sequences of ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert text_match(\"A_b_C\") == 'Not matched!'", "assert text_match(\"aab_c\") == 'Found a match!'", "assert text_match(\"aab_cbbbc\") == 'Found a match!'", "assert text_match(\"aab_cbbbc!\") == 'Not matched!'", "assert text_match(\"aabCbbbc\") == 'Not ma...
44
Write a function that matches a word at the beginning of a string.
import re def text_match_string(text): patterns = '^\w+' if re.search(patterns, text): return 'Found a match!' else: return 'Not matched!'
[ "assert text_match_string(\" python\")==('Not matched!')", "assert text_match_string(\"python\")==('Found a match!')", "assert text_match_string(\" lang\")==('Not matched!')" ]
[ "assert text_match_string(\"foo\")==('Found a match!')" ]
[ "```python\ndef text_match_string(text):\n \"\"\"\n Write a function that matches a word at the beginning of a string.\n \n >>> text_match_string(\" python\")\n ('Not matched!')\n \"\"\"\n if text.startswith(\"python\"):\n return \"Matched!\"\n else:\n return \"Not matched!\"\n...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert text_match_string(\" \") == 'Not matched!'", "assert text_match_string(\"py3\") == 'Matched!'", "assert text_match_string(\" python\") == 'Not matched!'", "assert text_match_string(\"python\") == 'Matched!'", "assert text_match_string(\"Python\") =...
45
Write a function to find the gcd of the given array elements.
def find_gcd(x, y): while(y): x, y = y, x % y return x def get_gcd(l): num1 = l[0] num2 = l[1] gcd = find_gcd(num1, num2) for i in range(2, len(l)): gcd = find_gcd(gcd, l[i]) return gcd
[ "assert get_gcd([2, 4, 6, 8, 16]) == 2", "assert get_gcd([1, 2, 3]) == 1", "assert get_gcd([2, 4, 6, 8]) == 2 " ]
[]
[ "```python\ndef get_gcd(l):\n \"\"\"\n Write a function to find the gcd of the given array elements.\n \n >>> get_gcd([2, 4, 6, 8, 16])\n 2\n \"\"\"\n def gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\n return gcd(*l)\n\n# Test cases\nassert get_gcd([2, 4, 6, ...
[ 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1 ]
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert get_gcd([3, 9, 27, 81]) == 3", "assert get_gcd([8, 12, 16, 24]) == 4", "assert get_gcd([5, 10, 15, 20, 25]) == 5", "assert get_gcd([2, 4, 6, 8, 16]) == 2", "assert get_gcd([17, 34, 51, 68]) == 17", "assert get_gcd([100, 200, 300, 400]) == 100",...
46
Write a python function to determine whether all the numbers are different from each other are not.
def test_distinct(data): if len(data) == len(set(data)): return True else: return False;
[ "assert test_distinct([1,5,7,9]) == True", "assert test_distinct([2,4,5,5,7,9]) == False", "assert test_distinct([1,2,3]) == True" ]
[]
[ "```python\ndef test_distinct(data):\n \"\"\"\n Write a python function to determine whether all the numbers are different from each other are not.\n \n >>> test_distinct([1,5,7,9])\n True\n \"\"\"\n # Filter out the duplicates\n unique_elements = list(set(data))\n # Check if there's only...
[ 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0 ]
[ 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0 ]
{ "language": "python", "test_cases": [ "assert test_distinct([10]) == True", "assert test_distinct([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True", "assert test_distinct([10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == True", "assert test_distinct([1, 5, 7, 9]) == True", "assert test_distinct([]) == Tru...
47
Write a python function to find the last digit when factorial of a divides factorial of b.
def compute_Last_Digit(A,B): variable = 1 if (A == B): return 1 elif ((B - A) >= 5): return 0 else: for i in range(A + 1,B + 1): variable = (variable * (i % 10)) % 10 return variable % 10
[ "assert compute_Last_Digit(2,4) == 2", "assert compute_Last_Digit(6,8) == 6", "assert compute_Last_Digit(1,2) == 2" ]
[ "assert compute_Last_Digit(3,7) == 0", "assert compute_Last_Digit(20,23) == 6", "assert compute_Last_Digit(1021,1024) == 4" ]
[ "To solve the given problem, we need to find the last digit when the factorial of a divides the factorial of b. Given that A and B are integers, we can use properties of factorials. The last digit of a number can be found by taken the modulo of the number with 10. Here's a Python function that computes the last dig...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert compute_Last_Digit(5, 10) == 2", "assert compute_Last_Digit(0, 0) == 1", "assert compute_Last_Digit(7, 7) == 1", "assert compute_Last_Digit(6, 8) == 2", "assert compute_Last_Digit(10, 20) == 0", "assert compute_Last_Digit(2, 4) == 2", "asse...
48
Write a python function to set all odd bits of a given number.
def odd_bit_set_number(n): count = 0;res = 0;temp = n while temp > 0: if count % 2 == 0: res |= (1 << count) count += 1 temp >>= 1 return (n | res)
[ "assert odd_bit_set_number(10) == 15", "assert odd_bit_set_number(20) == 21", "assert odd_bit_set_number(30) == 31" ]
[]
[ "Here is the implementation of the `odd_bit_set_number` function in Python:\n\n```python\ndef odd_bit_set_number(n):\n \"\"\"\n Write a python function to set all odd bits of a given number.\n \n >>> odd_bit_set_number(10)\n 15\n \"\"\"\n # Initialize a containing variable to store the result\n...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert odd_bit_set_number(2) == 3", "assert odd_bit_set_number(0) == 0", "assert odd_bit_set_number(255) == 255", "assert odd_bit_set_number(128) == 191", "assert odd_bit_set_number(10) == 15", "assert odd_bit_set_number(5) == 7", "assert odd_bit_...
49
Write a function to extract every first or specified element from a given two-dimensional list.
def specified_element(nums, N): result = [i[N] for i in nums] return result
[ "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],0)==[1, 4, 7]", "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],2)==[3, 6, 9]", "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],1)==[2,5,1]" ]
[]
[ "```python\ndef specified_element(nums, N):\n \"\"\"\n Write a function to extract every first or specified element from a given two-dimensional list.\n \n >>> specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],0)\n [1, 4, 7]\n \"\"\"\n # Extract elements at index 0\n elements_at_i...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
{ "language": "python", "test_cases": [ "assert specified_element([[1, 2], [3, 4], [5, 6], [7, 8]], 1) == [2, 4, 6, 8]", "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]], 0) == [1, 4, 7]", "assert specified_element([[1]], 0) == [1]", "assert specified_element([[10, 20], [30, 40],...
50
Write a function to find the list with minimum length using lambda function.
def min_length_list(input_list): min_length = min(len(x) for x in input_list ) min_list = min(input_list, key = lambda i: len(i)) return(min_length, min_list)
[ "assert min_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(1, [0])", "assert min_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(1,[1])", "assert min_length_list([[3,4,5],[6,7,8,9],[10,11,12],[1,2]])==(2,[1,2])" ]
[]
[ "To solve the problem of finding the list with the minimum length using a lambda function in Python, you can follow these steps:\n\n1. Define a function that takes a list as input.\n2. Use the built-in `min` function with a lambda function as the key argument to find the list with the minimum length.\n\nHere's the ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert min_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]]) == (1, [0])", "assert min_length_list([[1, 2], [3, 4], [5, 6], [7]]) == (1, [7])", "assert min_length_list([[1, 2, 3, 4], [5, 6, 7], [8, 9], [10]]) == (1, [10])", "assert min_length_list([[1...
51
Write a function to print check if the triangle is equilateral or not.
def check_equilateral(x,y,z): if x == y == z: return True else: return False
[ "assert check_equilateral(6,8,12)==False ", "assert check_equilateral(6,6,12)==False", "assert check_equilateral(6,6,6)==True" ]
[]
[ "Here's a Python function to check if a triangle is equilateral.\n\n```python\ndef check_equilateral(x, y, z):\n # Check if all three sides are equal\n if x == y and y == z:\n return True\n else:\n return False\n```\n\n### Explanation:\n\n- The function `check_equilateral` takes three paramet...
[ 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert check_equilateral(6, 8, 12) == False", "assert check_equilateral(3, 3, 3) == True", "assert check_equilateral(7, 7, 14) == False", "assert check_equilateral(5, 5, 5) == True", "assert check_equilateral(10, 10, 10) == True", "assert check_equila...
52
Write a function to caluclate area of a parallelogram.
def parallelogram_area(b,h): area=b*h return area
[ "assert parallelogram_area(10,20)==200", "assert parallelogram_area(15,20)==300", "assert parallelogram_area(8,9)==72" ]
[]
[ "```python\nimport math\n\ndef parallelogram_area(b, h):\n \"\"\"\n Write a function to caluclate area of a parallelogram.\n \n >>> parallelogram_area(10,20)\n 200\n \"\"\"\n return b * h\n\n# Test the function with the provided test case\nassert parallelogram_area(10, 20) == 200\n```\n\nThis c...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
{ "language": "python", "test_cases": [ "assert parallelogram_area(10, 0) == 0", "assert parallelogram_area(5, -10) == -50", "assert parallelogram_area(0, 10) == 0", "assert parallelogram_area(10, 20) == 200", "assert parallelogram_area(5, 5) == 25", "assert parallelogram_area(1.5, 2.5) == 3...
53
Write a python function to check whether the first and last characters of a given string are equal or not.
def check_Equality(str): if (str[0] == str[-1]): return ("Equal") else: return ("Not Equal")
[ "assert check_Equality(\"abcda\") == \"Equal\"", "assert check_Equality(\"ab\") == \"Not Equal\"", "assert check_Equality(\"mad\") == \"Not Equal\"" ]
[]
[ "```python\ndef check_Equality(str):\n \"\"\"\n Write a python function to check whether the first and last characters of a given string are equal or not.\n \n >>> check_Equality(\"abcda\")\n \"Equal\"\n \"\"\"\n if len(str) < 2:\n return \"Invalid input or empty string.\"\n \n ret...
[ 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
{ "language": "python", "test_cases": [ "assert check_Equality(\"z\") == \"Equal\"", "assert check_Equality(\"python\") == \"Not Equal\"", "assert check_Equality(\"\") == \"Not Equal\"", "assert check_Equality(\"a\") == \"Equal\"", "assert check_Equality(\"abcda\") == \"Equal\"", "assert che...
54
Write a function to sort the given array by using counting sort.
def counting_sort(my_list): max_value = 0 for i in range(len(my_list)): if my_list[i] > max_value: max_value = my_list[i] buckets = [0] * (max_value + 1) for i in my_list: buckets[i] += 1 i = 0 for j in range(max_value + 1): for a in range(buckets[j...
[ "assert counting_sort([1,23,4,5,6,7,8]) == [1, 4, 5, 6, 7, 8, 23]", "assert counting_sort([12, 9, 28, 33, 69, 45]) == [9, 12, 28, 33, 45, 69]", "assert counting_sort([8, 4, 14, 3, 2, 1]) == [1, 2, 3, 4, 8, 14]" ]
[]
[ "Here is the completed Python code to solve the given problem:\n\n```python\ndef counting_sort(my_list):\n \"\"\"\n Write a function to sort the given array by using counting sort.\n \n >>> counting_sort([1,23,4,5,6,7,8])\n [1, 4, 5, 6, 7, 8, 23]\n \"\"\"\n # Adjust total elements\n total_el...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert counting_sort([7, 7, 7, 7, 7, 7, 7]) == [7, 7, 7, 7, 7, 7, 7]", "assert counting_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9]", "assert counting_sort([5, 3, 0, 0, 7, 2, 8, 6, 4, 1]) == [0, 0, 1, 2, 3, 4, 5, 6, 7, 8]", "a...
55
Write a function to find t-nth term of geometric series.
import math def tn_gp(a,n,r): tn = a * (math.pow(r, n - 1)) return tn
[ "assert tn_gp(1,5,2)==16", "assert tn_gp(1,5,4)==256", "assert tn_gp(2,6,3)==486" ]
[]
[ "Here is the Python code to solve the given problem:\n\n```python\ndef tn_gp(a, n, r):\n \"\"\"\n Write a function to find t-nth term of geometric series.\n \n >>> tn_gp(1,5,2)\n 16\n \"\"\"\n if n == 0:\n return 0\n else:\n return (a * r ** (n - 1))\n```\n\nExplanation:\nThe f...
[ 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert tn_gp(3, 6, 2) == 192", "assert tn_gp(1, 1, 10) == 1", "assert tn_gp(5, 3, 2) == 20", "assert tn_gp(1, 5, 2) == 16", "assert tn_gp(7, 2, 5) == 35", "assert tn_gp(2, 4, 3) == 54", "assert tn_gp(4, 3, 1/2) == 1.0", "assert tn_gp(10, 0, 3)...
56
Write a python function to check if a given number is one less than twice its reverse.
def rev(num): rev_num = 0 while (num > 0): rev_num = (rev_num * 10 + num % 10) num = num // 10 return rev_num def check(n): return (2 * rev(n) == n + 1)
[ "assert check(70) == False", "assert check(23) == False", "assert check(73) == True" ]
[]
[ "To solve this problem, we need to check if a given number is one less than twice its reverse. Here's the Python function to achieve this:\n\n```python\ndef check(n):\n \"\"\"\n Write a python function to check if a given number is one less than twice its reverse.\n \n >>> check(70)\n False\n \"\"...
[ 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert check(100) == False", "assert check(10) == False", "assert check(12) == False", "assert check(0) == False", "assert check(1) == False", "assert check(21) == True", "assert check(9) == False", "assert check(20) == True", "assert chec...
57
Write a python function to find the largest number that can be formed with the given digits.
def find_Max_Num(arr,n) : arr.sort(reverse = True) num = arr[0] for i in range(1,n) : num = num * 10 + arr[i] return num
[ "assert find_Max_Num([1,2,3],3) == 321", "assert find_Max_Num([4,5,6,1],4) == 6541", "assert find_Max_Num([1,2,3,9],4) == 9321" ]
[]
[ "Certainly! To solve the problem, we need to find the maximum number that can be formed using the given digits. The approach involves sorting the digits in ascending order and then constructing the result string by joining the sorted digits from the end to the beginning.\n\nHere's the implementation of the `find_Ma...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert find_Max_Num([9, 0, 8, 0, 7], 5) == 98700", "assert find_Max_Num([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10) == 9876543210", "assert find_Max_Num([9, 8, 7, 6, 5], 5) == 98765", "assert find_Max_Num([1], 1) == 1", "assert find_Max_Num([12, 34, 56, 78], 4) =...
58
Write a python function to check whether the given two integers have opposite sign or not.
def opposite_Signs(x,y): return ((x ^ y) < 0);
[ "assert opposite_Signs(1,-2) == True", "assert opposite_Signs(3,2) == False", "assert opposite_Signs(-10,-10) == False" ]
[]
[ "Certainly! To check whether two integers have opposite signs, you can compare the signs of the integers. Here's the Python function to do that:\n\n```python\ndef opposite_Signs(x,y):\n \"\"\"\n Write a python function to check whether the given two integers have opposite sign or not.\n \n >>> opposite_...
[ 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1 ]
[ 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1 ]
{ "language": "python", "test_cases": [ "assert opposite_Signs(-3, -5) == False", "assert opposite_Signs(100, -100) == True", "assert opposite_Signs(0, 0) == False", "assert opposite_Signs(1, -2) == True", "assert opposite_Signs(-100, 100) == True", "assert opposite_Signs(0, -2) == False", ...
59
Write a function to find the nth octagonal number.
def is_octagonal(n): return 3 * n * n - 2 * n
[ "assert is_octagonal(5) == 65", "assert is_octagonal(10) == 280", "assert is_octagonal(15) == 645" ]
[]
[ "To solve the problem of generating the nth octagonal number, we can use the formula for the nth octagonal number, which is `n * (n + 1) / 2`. Here's the Python code to implement this:\n\n```python\ndef is_octagonal(n):\n \"\"\"\n Write a function to find the nth octagonal number.\n \n >>> is_octagonal(...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert is_octagonal(10) == 276", "assert is_octagonal(4) == 40", "assert is_octagonal(6) == 96", "assert is_octagonal(1) == 1", "assert is_octagonal(7) == 133", "assert is_octagonal(8) == 176", "assert is_octagonal(5) == 65", "assert is_octago...
60
Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array.
def max_len_sub( arr, n): mls=[] max = 0 for i in range(n): mls.append(1) for i in range(n): for j in range(i): if (abs(arr[i] - arr[j]) <= 1 and mls[i] < mls[j] + 1): mls[i] = mls[j] + 1 for i in range(n): if (max < mls[i]): max = mls[i] return max
[ "assert max_len_sub([2, 5, 6, 3, 7, 6, 5, 8], 8) == 5", "assert max_len_sub([-2, -1, 5, -1, 4, 0, 3], 7) == 4", "assert max_len_sub([9, 11, 13, 15, 18], 5) == 1" ]
[]
[ "```python\ndef max_len_sub(arr, n):\n \"\"\"\n Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array.\n \n >>> max_len_sub([2, 5, 6, 3, 7, 6, 5, 8], 8)\n 5\n \"\"\"\n max_diff = 0\n current_diff = 0\n\n for i in range...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert max_len_sub([10, 9, 4, 5, 4, 8, 6], 7) == 3", "assert max_len_sub([1, 2, 2, 3, 4, 5, 5, 6], 8) == 5", "assert max_len_sub([5, 5, 4, 3, 2, 1], 6) == 2", "assert max_len_sub([1, 1, 1, 1, 1], 5) == 1", "assert max_len_sub([1, 3, 5, 7, 9], 5) == 5", ...
61
Write a python function to count number of substrings with the sum of digits equal to their length.
from collections import defaultdict def count_Substrings(s,n): count,sum = 0,0 mp = defaultdict(lambda : 0) mp[0] += 1 for i in range(n): sum += ord(s[i]) - ord('0') count += mp[sum - (i + 1)] mp[sum - (i + 1)] += 1 return count
[ "assert count_Substrings('112112',6) == 6", "assert count_Substrings('111',3) == 6", "assert count_Substrings('1101112',7) == 12" ]
[]
[ "To solve the problem of counting substrings with a sum of digits equal to their length, we need to consider how we can generate the substrings and check the conditions that the sum of digits in each substring equals its length. Here's a step-by-step breakdown of how to approach this problem:\n\n1. **Generate Subst...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert count_Substrings('123', 3) == 2", "assert count_Substrings('101010', 6) == 6", "assert count_Substrings('111000', 6) == 6", "assert count_Substrings('121212', 6) == 6", "assert count_Substrings('000000', 6) == 21", "assert count_Substrings('0',...
62
Write a python function to find smallest number in a list.
def smallest_num(xs): return min(xs)
[ "assert smallest_num([10, 20, 1, 45, 99]) == 1", "assert smallest_num([1, 2, 3]) == 1", "assert smallest_num([45, 46, 50, 60]) == 45" ]
[]
[ "Here's the Python code to solve the problem:\n\n```python\ndef smallest_num(xs):\n \"\"\"\n Write a python function to find smallest number in a list.\n \n >>> smallest_num([10, 20, 1, 45, 99])\n 1\n \"\"\"\n return min(xs)\n```\n\nThis function `smallest_num` takes a list of numbers as input ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
{ "language": "python", "test_cases": [ "assert smallest_num([1.5, 2.5, 0.5, 3.5]) == 0.5", "assert smallest_num([0, 0, 0, 0]) == 0", "assert smallest_num([10, 20, 1, 45, 99]) == 1", "assert smallest_num([1000, 2000, 3000, 10]) == 10", "assert smallest_num([1e-10, 1e-9, 1e-8]) == 1e-10", "as...
63
Write a function to find the maximum difference between available pairs in the given tuple list.
def max_difference(test_list): temp = [abs(b - a) for a, b in test_list] res = max(temp) return (res)
[ "assert max_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 7", "assert max_difference([(4, 6), (2, 17), (9, 13), (11, 12)]) == 15", "assert max_difference([(12, 35), (21, 27), (13, 23), (41, 22)]) == 23" ]
[]
[ "To solve the problem of finding the maximum difference between available pairs in the given tuple list, you can follow these steps:\n\n1. Iterate through the list of tuples.\n2. For each tuple, extract the elements `(a, b)` and move them into a list to easily compare.\n3. Sort the list of elements.\n4. Calculate t...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert max_difference([(-1, -5), (-3, -2), (-10, -1)]) == 9", "assert max_difference([(1, 1), (2, 2), (3, 3)]) == 0", "assert max_difference([(10, 1), (9, 2), (8, 3)]) == 9", "assert max_difference([(10, 2), (5, 5), (8, 3)]) == 8", "assert max_difference(...
64
Write a function to sort a list of tuples using lambda.
def subject_marks(subjectmarks): #subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]) subjectmarks.sort(key = lambda x: x[1]) return subjectmarks
[ "assert subject_marks([('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])==[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)]", "assert subject_marks([('Telugu',49),('Hindhi',54),('Social',33)])==([('Social',33),('Telugu',49),('Hindhi',54)])", "assert subject_mark...
[]
[ "To solve the problem of sorting a list of tuples using a lambda function in Python, you can use the `sorted()` function along with the `lambda` function. Here's how you can implement the function:\n\n```python\ndef subject_marks(subjectmarks):\n \"\"\"\n Write a function to sort a list of tuples using lambda...
[ 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
[ 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert subject_marks([('Calculus', 98), ('Algebra', 96), ('Geometry', 97)]) == [('Algebra', 96), ('Geometry', 97), ('Calculus', 98)]", "assert subject_marks([('Art', 60), ('Music', 70), ('Physical Education', 55)]) == [('Physical Education', 55), ('Art', 60), ('Music...
65
Write a function of recursion list sum.
def recursive_list_sum(data_list): total = 0 for element in data_list: if type(element) == type([]): total = total + recursive_list_sum(element) else: total = total + element return total
[ "assert recursive_list_sum(([1, 2, [3,4],[5,6]]))==21", "assert recursive_list_sum(([7, 10, [15,14],[19,41]]))==106", "assert recursive_list_sum(([10, 20, [30,40],[50,60]]))==210" ]
[]
[ "To solve the given problem using Python, we can define a recursive function named `recursive_list_sum`. The function will take a `data_list` as input and return the sum of all the integers in the list. Here's how you can implement this:\n\n```python\ndef recursive_list_sum(data_list):\n \"\"\"\n Write a func...
[ 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert recursive_list_sum([1, 2, 3, 4, 5]) == 15", "assert recursive_list_sum([100, [200, [300, [400, [500, [600, [700, [800, [900, [1000]]]]]]]]]) == 5500", "assert recursive_list_sum([]) == 0", "assert recursive_list_sum([[1, 2, [3]], 4, [5, 6]]) == 21", ...
66
Write a python function to count positive numbers in a list.
def pos_count(list): pos_count= 0 for num in list: if num >= 0: pos_count += 1 return pos_count
[ "assert pos_count([1,-2,3,-4]) == 2", "assert pos_count([3,4,5,-1]) == 3", "assert pos_count([1,2,3,4]) == 4" ]
[]
[ "To solve the problem of counting positive numbers in a list using Python, you can use the built-in `filter` function along with the `any` function. Here's how you can implement the `pos_count` function:\n\n```python\ndef pos_count(list):\n \"\"\"\n Write a python function to count positive numbers in a list....
[ 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
[ 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
{ "language": "python", "test_cases": [ "assert pos_count([1, -2, 3, -4]) == 2", "assert pos_count([1, 2, -3, 4, -5, 6]) == 4", "assert pos_count([10, 20, 30, -10, -20, -30]) == 3", "assert pos_count([1, -1, 1, -1, 1, -1]) == 3", "assert pos_count([]) == 0", "assert pos_count([-1, -2, -3, -4...
67
Write a function to find the number of ways to partition a set of bell numbers.
def bell_number(n): bell = [[0 for i in range(n+1)] for j in range(n+1)] bell[0][0] = 1 for i in range(1, n+1): bell[i][0] = bell[i-1][i-1] for j in range(1, i+1): bell[i][j] = bell[i-1][j-1] + bell[i][j-1] return bell[n][0]
[ "assert bell_number(2)==2", "assert bell_number(10)==115975", "assert bell_number(56)==6775685320645824322581483068371419745979053216268760300" ]
[]
[ "To solve the problem of finding the number of ways to partition a set of bell numbers, we need to understand the concept of Bell numbers and how they are used. The Bell number \\( B(n) \\) is a generating function built around the sequence:\n\\[ B(0) = 1, B(1) = 1, B(2) = B(1) \\cdot 3, B(3) = B(2) \\cdot 21, \\ld...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert bell_number(7) == 877", "assert bell_number(4) == 15", "assert bell_number(9) == 21147", "assert bell_number(8) == 4140", "assert bell_number(0) == 1", "assert bell_number(6) == 203", "assert bell_number(5) == 52", "assert bell_number(3...
68
Write a python function to check whether the given array is monotonic or not.
def is_Monotonic(A): return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or all(A[i] >= A[i + 1] for i in range(len(A) - 1)))
[ "assert is_Monotonic([6, 5, 4, 4]) == True", "assert is_Monotonic([1, 2, 2, 3]) == True", "assert is_Monotonic([1, 3, 2]) == False" ]
[]
[ "Here's the solution to the problem using Python:\n\n```python\ndef is_Monotonic(A):\n \"\"\"\n Write a python function to check whether the given array is monotonic or not.\n \n >>> is_Monotonic([6, 5, 4, 4])\n True\n \"\"\"\n # Iterate through the array to check for increasing or decreasing\n...
[ 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0 ]
[ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0 ]
{ "language": "python", "test_cases": [ "assert is_Monotonic([5, 5, 5, 5]) == True", "assert is_Monotonic([7, 7, 7, 8, 9, 10]) == True", "assert is_Monotonic([1, 1, 1]) == True", "assert is_Monotonic([10, 9, 8, 8, 7, 6]) == True", "assert is_Monotonic([1, 2, 3, 4, 5, 6, 7]) == True", "assert...
69
Write a function to check whether a list contains the given sublist or not.
def is_sublist(l, s): sub_set = False if s == []: sub_set = True elif s == l: sub_set = True elif len(s) > len(l): sub_set = False else: for i in range(len(l)): if l[i] == s[0]: n = 1 while (n < len(s)) and (l[i+n] == s[n]): n += 1 if n == len(s): sub_set = True ...
[ "assert is_sublist([2,4,3,5,7],[3,7])==False", "assert is_sublist([2,4,3,5,7],[4,3])==True", "assert is_sublist([2,4,3,5,7],[1,6])==False" ]
[]
[ "To solve the problem of checking if a list contains a given sublist, you can use two approaches: one using the `in` keyword and another using recursion. Below is the Python implementation using both approaches.\n\n### Approach 1: Using the `in` keyword\n\nThe `in` keyword is a straightforward way to check if a lis...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert is_sublist([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]) == True", "assert is_sublist(['a', 'b', 'c', 'd'], ['b', 'c']) == True", "assert is_sublist([], []) == True", "assert is_sublist([], [1]) == False", "assert is_sublist([1, 2, 3, 4, 5], []) == True", ...
70
Write a function to find whether all the given tuples have equal length or not.
def find_equal_tuple(Input, k): flag = 1 for tuple in Input: if len(tuple) != k: flag = 0 break return flag def get_equal(Input, k): if find_equal_tuple(Input, k) == 1: return ("All tuples have same length") else: return ("All tuples do not have same length")
[ "assert get_equal([(11, 22, 33), (44, 55, 66)], 3) == 'All tuples have same length'", "assert get_equal([(1, 2, 3), (4, 5, 6, 7)], 3) == 'All tuples do not have same length'", "assert get_equal([(1, 2), (3, 4)], 2) == 'All tuples have same length'" ]
[]
[ "Here is the implementation of the `get_equal` function in Python:\n\n```python\ndef get_equal(Input, k):\n \"\"\"\n Write a function to find whether all the given tuples have equal length or not.\n\n >>> get_equal([(11, 22, 33), (44, 55, 66)], 3)\n 'All tuples have same length'\n \"\"\"\n return ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
{ "language": "python", "test_cases": [ "assert get_equal([(1, 2), (3, 4, 5)], 2) == 'Not all tuples have same length'", "assert get_equal([(1, 2, 3), (4, 5, 6), (7, 8, 9)], 4) == 'Not all tuples have same length'", "assert get_equal([(1, 2, 3), (4, 5, 6), (7, 8, 9)], 2) == 'Not all tuples have same len...
71
Write a function to sort a list of elements using comb sort.
def comb_sort(nums): shrink_fact = 1.3 gaps = len(nums) swapped = True i = 0 while gaps > 1 or swapped: gaps = int(float(gaps) / shrink_fact) swapped = False i = 0 while gaps + i < len(nums): if nums[i] > nums[i+gaps]: nums[i], n...
[ "assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79]", "assert comb_sort([41, 32, 15, 19, 22]) == [15, 19, 22, 32, 41]", "assert comb_sort([99, 15, 13, 47]) == [13, 15, 47, 99]" ]
[]
[ "```python\nfrom typing import List\n\ndef comb_sort(nums):\n \"\"\"\n Write a function to sort a list of elements using comb sort.\n \n >>> comb_sort([5, 15, 37, 25, 79])\n [5, 15, 25, 37, 79]\n \"\"\"\n # Outer loop to perform rearranging\n for i in range(len(nums)):\n # Middle elem...
[ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
[ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
{ "language": "python", "test_cases": [ "assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79]", "assert comb_sort([5, 5, 5, 5]) == [5, 5, 5, 5]", "assert comb_sort([34, 2, 10, -9]) == [-9, 2, 10, 34]", "assert comb_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]", "assert comb_sort([100, 0, 50,...
72
Write a python function to check whether the given number can be represented as difference of two squares or not.
def dif_Square(n): if (n % 4 != 2): return True return False
[ "assert dif_Square(5) == True", "assert dif_Square(10) == False", "assert dif_Square(15) == True" ]
[]
[ "To solve the problem of determining if a given integer `n` can be represented as the difference of two squares, we need to understand the properties of squares. A number can be expressed as the difference of two squares if and only if the difference between its square root and its half square root is also a perfec...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert dif_Square(7) == True", "assert dif_Square(0) == True", "assert dif_Square(-1) == False", "assert dif_Square(16) == True", "assert dif_Square(1) == True", "assert dif_Square(3) == True", "assert dif_Square(5) == True", "assert dif_Squar...
73
Write a function to split the given string with multiple delimiters by using regex.
import re def multiple_split(text): return (re.split('; |, |\*|\n',text))
[ "assert multiple_split('Forces of the \\ndarkness*are coming into the play.') == ['Forces of the ', 'darkness', 'are coming into the play.']", "assert multiple_split('Mi Box runs on the \\n Latest android*which has google assistance and chromecast.') == ['Mi Box runs on the ', ' Latest android', 'which has google...
[]
[ "To solve the problem of splitting the given string using multiple delimiters by using regular expressions in Python, you can use the `re` module. Here's how you can implement the function `multiple_split`:\n\n```python\nimport re\n\ndef multiple_split(text):\n \"\"\"\n Write a function to split the given str...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert multiple_split('Starts*with*delimiters') == ['', 'Starts', 'with', 'delimiters']", "assert multiple_split('Special!@#$%^&*()Delimiters') == ['Special', '', '', '', '', '', '', '', '', '', 'Delimiters']", "assert multiple_split('Ends;with;delimiters,') == [...
74
Write a function to check whether it follows the sequence given in the patterns array.
def is_samepatterns(colors, patterns): if len(colors) != len(patterns): return False sdict = {} pset = set() sset = set() for i in range(len(patterns)): pset.add(patterns[i]) sset.add(colors[i]) if patterns[i] not in sdict.keys(): sdi...
[ "assert is_samepatterns([\"red\",\"green\",\"green\"], [\"a\", \"b\", \"b\"])==True ", "assert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\",\"b\"])==False ", "assert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\"])==False " ]
[]
[ "To solve the problem, we need to determine if all patterns in the `patterns` array create the sequence given in the `colors` array. Here's a step-by-step breakdown of how to implement this:\n\n1. **Check if the length of the `colors` array is one less than the length of the `patterns` array**: If this condition is...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert is_samepatterns([\"red\", \"green\"], [\"a\", \"a\"]) == False", "assert is_samepatterns([\"red\", \"green\", \"blue\"], [\"a\", \"b\", \"c\"]) == True", "assert is_samepatterns([\"red\", \"green\", \"blue\"], [\"a\", \"b\", \"b\"]) == False", "assert ...
75
Write a function to find tuples which have all elements divisible by k from the given list of tuples.
def find_tuples(test_list, K): res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)] return (str(res))
[ "assert find_tuples([(6, 24, 12), (7, 9, 6), (12, 18, 21)], 6) == '[(6, 24, 12)]'", "assert find_tuples([(5, 25, 30), (4, 2, 3), (7, 8, 9)], 5) == '[(5, 25, 30)]'", "assert find_tuples([(7, 9, 16), (8, 16, 4), (19, 17, 18)], 4) == '[(8, 16, 4)]'" ]
[]
[ "To find tuples that have all elements divisible by a given number, you need to iterate through each tuple and check if all elements are divisible by that number. Here's a step-by-step implementation in Python:\n\n```python\ndef find_tuples(test_list, K):\n # Check if K is divisible by any element in the tuples\...
[ 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert find_tuples([(10, 20, 30), (25, 50, 75)], 5) == '[(10, 20, 30), (25, 50, 75)]'", "assert find_tuples([(8, 16, 24), (9, 18, 27)], 8) == '[(8, 16, 24)]'", "assert find_tuples([(3, 9, 12), (15, 30, 45)], 3) == '[(3, 9, 12), (15, 30, 45)]'", "assert find_t...
76
Write a python function to count the number of squares in a rectangle.
def count_Squares(m,n): if(n < m): temp = m m = n n = temp return ((m * (m + 1) * (2 * m + 1) / 6 + (n - m) * m * (m + 1) / 2))
[ "assert count_Squares(4,3) == 20", "assert count_Squares(2,2) == 5", "assert count_Squares(1,1) == 1" ]
[]
[ "```python\ndef count_Squares(m, n):\n \"\"\"\n Write a python function to count the number of squares in a rectangle.\n >>> count_Squares(4,3)\n 20\n \"\"\"\n count = 0\n for row in range(1, m+1):\n for col in range(1, n+1):\n if row*row == col*col:\n count += ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert count_Squares(1, 6) == 6", "assert count_Squares(6, 1) == 6", "assert count_Squares(10, 10) == 385", "assert count_Squares(1, 1) == 1", "assert count_Squares(8, 2) == 16", "assert count_Squares(5, 3) == 14", "assert count_Squares(7, 7) == 1...
77
Write a python function to find the difference between sum of even and odd digits.
def is_Diff(n): return (n % 11 == 0)
[ "assert is_Diff (12345) == False", "assert is_Diff(1212112) == True", "assert is_Diff(1212) == False" ]
[]
[ "```python\nimport math\n\ndef is_Diff(n):\n \"\"\"\n Write a python function to find the difference between sum of even and odd digits.\n \n >>> is_Diff(12345)\n False\n \"\"\"\n sum_even = 0\n sum_odd = 0\n while n > 0:\n digit = n % 10\n if digit % 2 == 0:\n su...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert is_Diff(987654321) == False", "assert is_Diff(0) == True", "assert is_Diff(24680) == True", "assert is_Diff(1001) == False", "assert is_Diff(2468) == True", "assert is_Diff(1111) == False", "assert is_Diff(1234) == True", "assert is_Dif...
78
Write a python function to find number of integers with odd number of set bits.
def count_With_Odd_SetBits(n): if (n % 2 != 0): return (n + 1) / 2 count = bin(n).count('1') ans = n / 2 if (count % 2 != 0): ans += 1 return ans
[ "assert count_With_Odd_SetBits(5) == 3", "assert count_With_Odd_SetBits(10) == 5", "assert count_With_Odd_SetBits(15) == 8" ]
[]
[ "To solve the problem of counting numbers with odd number of set bits, we need to understand the properties of bit manipulation and the set of bits. Here's how we can solve it step by step:\n\n1. **Understand the Problem**: We need to count numbers with `n` bits such that the number in binary representation has an ...
[ 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1 ]
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert count_With_Odd_SetBits(31) == 16", "assert count_With_Odd_SetBits(32) == 16", "assert count_With_Odd_SetBits(16) == 8", "assert count_With_Odd_SetBits(10) == 5", "assert count_With_Odd_SetBits(64) == 32", "assert count_With_Odd_SetBits(0) == 0"...
79
Write a python function to check whether the length of the word is odd or not.
def word_len(s): s = s.split(' ') for word in s: if len(word)%2!=0: return True else: return False
[ "assert word_len(\"Hadoop\") == False", "assert word_len(\"great\") == True", "assert word_len(\"structure\") == True" ]
[]
[ "Here's the complete Python function that checks the length of a given string and returns `True` if its length is odd, and `False` otherwise:\n\n```python\ndef word_len(s):\n \"\"\"\n Write a python function to check whether the length of the word is odd or not.\n \n >>> word_len(\"Hadoop\")\n False\...
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert word_len(\"Python\") == False", "assert word_len(\"HelloWorld\") == False", "assert word_len(\"Qwen\") == True", "assert word_len(\"DataScience\") == True", "assert word_len(\"a\") == True", "assert word_len(\"\") == False", "assert word_le...
80
Write a function to find the nth tetrahedral number.
def tetrahedral_number(n): return (n * (n + 1) * (n + 2)) / 6
[ "assert tetrahedral_number(5) == 35.0", "assert tetrahedral_number(6) == 56.0", "assert tetrahedral_number(7) == 84.0" ]
[]
[ "```python\ndef tetrahedral_number(n):\n \"\"\"\n Write a function to find the nth tetrahedral number.\n \n >>> tetrahedral_number(5)\n 35.0\n \"\"\"\n return (2*n * (n-1) * (n-2)) // 6\n```", "```python\ndef tetrahedral_number(n):\n \"\"\"\n Write a function to find the nth tetrahedral...
[ 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
[ 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
{ "language": "python", "test_cases": [ "assert tetrahedral_number(8) == 120.0", "assert tetrahedral_number(9) == 165.0", "assert tetrahedral_number(2) == 4.0", "assert tetrahedral_number(6) == 56.0", "assert tetrahedral_number(1) == 1.0", "assert tetrahedral_number(4) == 20.0", "assert ...
81
Write a function to zip the two given tuples.
def zip_tuples(test_tup1, test_tup2): res = [] for i, j in enumerate(test_tup1): res.append((j, test_tup2[i % len(test_tup2)])) return (res)
[ "assert zip_tuples((7, 8, 4, 5, 9, 10),(1, 5, 6) ) == [(7, 1), (8, 5), (4, 6), (5, 1), (9, 5), (10, 6)]", "assert zip_tuples((8, 9, 5, 6, 10, 11),(2, 6, 7) ) == [(8, 2), (9, 6), (5, 7), (6, 2), (10, 6), (11, 7)]", "assert zip_tuples((9, 10, 6, 7, 11, 12),(3, 7, 8) ) == [(9, 3), (10, 7), (6, 8), (7, 3), (11, 7),...
[]
[ "To solve the given problem using Python, we need to create a function `zip_tuples` that takes two tuples and returns a new tuple containing the corresponding elements from both input tuples. Here's how you can implement this:\n\n```python\ndef zip_tuples(test_tup1, test_tup2):\n \"\"\"\n Write a function to ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert zip_tuples((7, 8, 4, 5, 9, 10), (1, 5, 6)) == [(7, 1), (8, 5), (4, 6), (5, 1), (9, 5), (10, 6)]", "assert zip_tuples((1,), (2,)) == [(1, 2)]", "assert zip_tuples((1, 2, 3, 4, 5), (5, 4, 3, 2, 1)) == [(1, 5), (2, 4), (3, 3), (4, 2), (5, 1)]", "assert zi...
82
Write a function to find the volume of a sphere.
import math def volume_sphere(r): volume=(4/3)*math.pi*r*r*r return volume
[ "assert volume_sphere(10)==4188.790204786391", "assert volume_sphere(25)==65449.84694978735", "assert volume_sphere(20)==33510.32163829113" ]
[]
[ "```python\nimport math\n\ndef volume_sphere(r):\n \"\"\"\n Write a function to find the volume of a sphere.\n \n >>> volume_sphere(10)\n 4188.790204786391\n \"\"\"\n return volume_of_cylinder(r * r * r)\n\ndef volume_of_cylinder(radius):\n \"\"\"\n Calculate the volume of a cylinder give...
[ 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert volume_sphere(15.2) == 14773.714078686566", "assert volume_sphere(100) == 4188790204.786391", "assert volume_sphere(3.5) == 179.5943800302162", "assert volume_sphere(2.6) == 77.92039267522101", "assert volume_sphere(0) == 0.0", "assert volume_s...
83
Write a python function to find the character made by adding all the characters of the given string.
def get_Char(strr): summ = 0 for i in range(len(strr)): summ += (ord(strr[i]) - ord('a') + 1) if (summ % 26 == 0): return ord('z') else: summ = summ % 26 return chr(ord('a') + summ - 1)
[ "assert get_Char(\"abc\") == \"f\"", "assert get_Char(\"gfg\") == \"t\"", "assert get_Char(\"ab\") == \"c\"" ]
[]
[ "Here's the Python function `get_Char` that identifies the character composed by appending all characters of the provided string:\n\n```python\ndef get_Char(strr):\n \"\"\"\n Write a python function to find the character made by adding all the characters of the given string.\n \n >>> get_Char(\"abc\")\n...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert get_Char(\"world\") == \"d\"", "assert get_Char(\"xyz\") == \"w\"", "assert get_Char(\"abc\") == \"f\"", "assert get_Char(\"a\") == \"a\"", "assert get_Char(\"\") == \"\"", "assert get_Char(\"zyxwvutsrqponmlkjihgfedcba\") == \"a\"", "assert...
84
Write a function to find the n-th number in newman conway sequence.
def sequence(n): if n == 1 or n == 2: return 1 else: return sequence(sequence(n-1)) + sequence(n-sequence(n-1))
[ "assert sequence(10) == 6", "assert sequence(2) == 1", "assert sequence(3) == 2" ]
[]
[ "To solve the problem of finding the n-th number in the Newman-Conway sequence, we need to understand the definitions of the sequence. The Newman-Conway sequence starts with a given number \\(a_0\\) and defines the sequence as follows:\n\\[ a_{n+1} = a_n + a_n - a_{n-1} \\]\nif \\(a_n < a_{n-1}\\).\n\nHere is the P...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert sequence(5) == 3", "assert sequence(3) == 2", "assert sequence(9) == 5", "assert sequence(10) == 6", "assert sequence(8) == 4", "assert sequence(1) == 1", "assert sequence(6) == 4", "assert sequence(2) == 1", "assert sequence(7) == ...
85
Write a function to find the surface area of a sphere.
import math def surfacearea_sphere(r): surfacearea=4*math.pi*r*r return surfacearea
[ "assert surfacearea_sphere(10)==1256.6370614359173", "assert surfacearea_sphere(15)==2827.4333882308138", "assert surfacearea_sphere(20)==5026.548245743669" ]
[]
[ "```python\nimport math\n\ndef surfacearea_sphere(r):\n \"\"\"\n Write a function to find the surface area of a sphere.\n \n >>> surfacearea_sphere(10)\n 1256.6370614359173\n \"\"\"\n surface_area = 4 * math.pi * r * r\n return surface_area\n\n# Check function with provided data points\nasse...
[ 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert surfacearea_sphere(0.1) == 0.12566370614359174", "assert surfacearea_sphere(1) == 12.566370614359172", "assert surfacearea_sphere(15.5) == 1563.4672515999744", "assert surfacearea_sphere(2.5) == 78.53981633974483", "assert surfacearea_sphere(3.1415...
86
Write a function to find nth centered hexagonal number.
def centered_hexagonal_number(n): return 3 * n * (n - 1) + 1
[ "assert centered_hexagonal_number(10) == 271", "assert centered_hexagonal_number(2) == 7", "assert centered_hexagonal_number(9) == 217" ]
[]
[ "To solve the problem of finding the nth centered hexagonal number in Python, we can follow these steps:\n\n1. Understand the formula for the nth centered hexagonal number. The n-th centered hexagonal number (also known as the double factorial hexagonal number) is calculated as 2n^2 - n.\n2. Write a function that t...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert centered_hexagonal_number(5) == 61", "assert centered_hexagonal_number(10) == 271", "assert centered_hexagonal_number(4) == 37", "assert centered_hexagonal_number(9) == 217", "assert centered_hexagonal_number(1) == 1", "assert centered_hexagona...
87
Write a function to merge three dictionaries into a single expression.
import collections as ct def merge_dictionaries_three(dict1,dict2, dict3): merged_dict = dict(ct.ChainMap({},dict1,dict2,dict3)) return merged_dict
[ "assert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" },{ \"O\": \"Orange\", \"W\": \"White\", \"B\": \"Black\" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White', 'O': 'Orange'}", "assert merge_dictionaries_three({ \"R\": ...
[]
[ "Here's the Python function `merge_dictionaries_three` that merges three dictionaries into a single expression:\n\n```python\ndef merge_dictionaries_three(dict1, dict2, dict3):\n \"\"\"\n Write a function to merge three dictionaries into a single expression.\n \n >>> merge_dictionaries_three({ \"R\": \"...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0 ]
{ "language": "python", "test_cases": [ "assert merge_dictionaries_three({}, {\"B\": \"Banana\"}, {}) == {\"B\": \"Banana\"}", "assert merge_dictionaries_three({\"A\": \"Apple\"}, {}, {}) == {\"A\": \"Apple\"}", "assert merge_dictionaries_three({\"M\": \"Monday\"}, {\"T\": \"Tuesday\"}, {\"M\": \"Mornin...
88
Write a function to get the frequency of the elements in a list.
import collections def freq_count(list1): freq_count= collections.Counter(list1) return freq_count
[ "assert freq_count([10,10,10,10,20,20,20,20,40,40,50,50,30])==({10: 4, 20: 4, 40: 2, 50: 2, 30: 1}) ", "assert freq_count([1,2,3,4,3,2,4,1,3,1,4])==({1:3, 2:2,3:3,4:3}) ", "assert freq_count([5,6,7,4,9,10,4,5,6,7,9,5])==({10:1,5:3,6:2,7:2,4:2,9:2}) " ]
[]
[ "Here's the Python code to solve the problem:\n\n```python\nfrom collections import Counter\n\ndef freq_count(list1):\n \"\"\"\n Write a function to get the frequency of the elements in a list.\n \n >>> freq_count([10,10,10,10,20,20,20,20,40,40,50,50,30])\n ({10: 4, 20: 4, 40: 2, 50: 2, 30: 1}) \n ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
{ "language": "python", "test_cases": [ "assert freq_count([None, None, 1, 2, None]) == {None: 3, 1: 1, 2: 1}", "assert freq_count([1.1, 2.2, 1.1, 3.3, 2.2, 2.2]) == {1.1: 2, 2.2: 3, 3.3: 1}", "assert freq_count([7]) == {7: 1}", "assert freq_count(['a', 'b', 'a', 'c', 'b', 'a']) == {'a': 3, 'b': 2, ...
89
Write a function to find the closest smaller number than n.
def closest_num(N): return (N - 1)
[ "assert closest_num(11) == 10", "assert closest_num(7) == 6", "assert closest_num(12) == 11" ]
[]
[ "```python\ndef closest_num(N):\n \"\"\"\n Write a function to find the closest smaller number than n.\n \n >>> closest_num(11)\n 10\n \"\"\"\n # Start from the largest possible number smaller than N\n for num in range(N-1, -1, -1):\n if num < N:\n return num\n return No...
[ 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0 ]
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert closest_num(1) == 0", "assert closest_num(-1) == -2", "assert closest_num(2023) == 2022", "assert closest_num(1000000) == 999999", "assert closest_num(0) == -1", "assert closest_num(2) == 1", "assert closest_num(11) == 10", "assert clos...
90
Write a python function to find the length of the longest word.
def len_log(list1): max=len(list1[0]) for i in list1: if len(i)>max: max=len(i) return max
[ "assert len_log([\"python\",\"PHP\",\"bigdata\"]) == 7", "assert len_log([\"a\",\"ab\",\"abc\"]) == 3", "assert len_log([\"small\",\"big\",\"tall\"]) == 5" ]
[]
[ "```python\ndef len_log(list1):\n \"\"\"\n Write a python function to find the length of the longest word.\n\n >>> len_log([\"python\",\"PHP\",\"bigdata\"])\n 7\n \"\"\"\n```", "To solve the given problem using Python, you can create a function that iterates through the list of words, checks the le...
[ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert len_log([\"\",\"empty\",\"string\"]) == 6", "assert len_log([\"python\",\"PHP\",\"bigdata\"]) == 7", "assert len_log([\"special$characters\",\"@#$%^&*()\",\"numbers123\"]) == 16", "assert len_log([]) == 0", "assert len_log([\"hello\",\"world\",\"py...
91
Write a function to check if a substring is present in a given list of string values.
def find_substring(str1, sub_str): if any(sub_str in s for s in str1): return True return False
[ "assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ack\")==True", "assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"abc\")==False", "assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ange\")==True" ]
[]
[ "Here's the code for the given Python function:\n\n```python\ndef find_substring(str1, sub_str):\n \"\"\"\n Write a function to check if a substring is present in a given list of string values.\n \n >>> find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ack\")\n True\n \"\"\"\...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0 ]
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0 ]
{ "language": "python", "test_cases": [ "assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"], \"abc\") == False", "assert find_substring([], \"test\") == False", "assert find_substring([\"a\", \"ab\", \"abc\", \"abcd\"], \"abcd\") == True", "assert find_substring([\"hello\",...
92
Write a function to check whether the given number is undulating or not.
def is_undulating(n): if (len(n) <= 2): return False for i in range(2, len(n)): if (n[i - 2] != n[i]): return False return True
[ "assert is_undulating(\"1212121\") == True", "assert is_undulating(\"1991\") == False", "assert is_undulating(\"121\") == True" ]
[]
[ "```python\ndef is_undulating(n):\n \"\"\"\n Write a function to check whether the given number is undulating or not.\n \n >>> is_undulating(\"1212121\")\n True\n \"\"\"\n # Base case: a number with only one digit is undulating\n if len(n) <= 1:\n return True\n \n # Ensure the n...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert is_undulating(\"1212121\") == True", "assert is_undulating(\"101010101\") == True", "assert is_undulating(\"12\") == False", "assert is_undulating(\"1212\") == True", "assert is_undulating(\"111\") == False", "assert is_undulating(\"123123\") =...
93
Write a function to calculate the value of 'a' to the power 'b'.
def power(a,b): if b==0: return 1 elif a==0: return 0 elif b==1: return a else: return a*power(a,b-1)
[ "assert power(3,4) == 81", "assert power(2,3) == 8", "assert power(5,5) == 3125" ]
[]
[ "```python\ndef power(a, b):\n \"\"\"\n Write a function to calculate the value of 'a' to the power 'b'.\n \n >>> power(3,4)\n 81\n \"\"\"\n return a ** b\n\n# Test the function\nprint(power(3,4))\n```\n\nThis Python function `power` takes two inputs, `a` and `b`, and returns their product, whi...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert power(3, 3) == 27", "assert power(4, 0.5) == 2.0", "assert power(5, 0) == 1", "assert power(0, 5) == 0", "assert power(2, 3) == 8", "assert power(1, 100) == 1", "assert power(-2, 3) == -8", "assert power(2, -2) == 0.25", "assert pow...
94
Write a function to extract the index minimum value record from the given tuples.
from operator import itemgetter def index_minimum(test_list): res = min(test_list, key = itemgetter(1))[0] return (res)
[ "assert index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]) == 'Varsha'", "assert index_minimum([('Yash', 185), ('Dawood', 125), ('Sanya', 175)]) == 'Dawood'", "assert index_minimum([('Sai', 345), ('Salman', 145), ('Ayesha', 96)]) == 'Ayesha'" ]
[]
[ "```python\nfrom typing import Tuple\n\ndef index_minimum(test_list: List[Tuple[str, int]]) -> str:\n \"\"\"\n Write a function to extract the index minimum value record from the given tuples.\n \n >>> index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)])\n 'Varsha'\n \"\"\"\n minim...
[ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
[ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
{ "language": "python", "test_cases": [ "assert index_minimum([('First', 50), ('Second', 20), ('Third', 30)]) == 'Second'", "assert index_minimum([('One', 1), ('Two', 2), ('Three', 3)]) == 'One'", "assert index_minimum([('Max', 999), ('Min', 1), ('Mid', 500)]) == 'Min'", "assert index_minimum([('X',...
95
Write a python function to find the minimum length of sublist.
def Find_Min_Length(lst): minLength = min(len(x) for x in lst ) return minLength
[ "assert Find_Min_Length([[1],[1,2]]) == 1", "assert Find_Min_Length([[1,2],[1,2,3],[1,2,3,4]]) == 2", "assert Find_Min_Length([[3,3,3],[4,4,4,4]]) == 3" ]
[]
[ "To solve the given problem, we can define a function `Find_Min_Length` that takes a list `lst` as input and returns the minimum length of a sublist found in the list. We can use a simple algorithm that iterates through the list and keeps track of the minimum length of a sublist found so far. Here's the correspondi...
[ 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert Find_Min_Length([]) == 0", "assert Find_Min_Length([[1]]) == 1", "assert Find_Min_Length([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) == 3", "assert Find_Min_Length([[1, 2], [3, 4], [5, 6]]) == 2", "assert Find_Min_Length([[1, 2, 3, 4], [5, 6, ...
96
Write a python function to find the number of divisors of a given integer.
def divisor(n): for i in range(n): x = len([i for i in range(1,n+1) if not n % i]) return x
[ "assert divisor(15) == 4 ", "assert divisor(12) == 6", "assert divisor(9) == 3" ]
[]
[ "To solve the problem of finding the number of divisors of a given integer using Python, you can iterate through possible divisors from 1 up to the square root of the number. If a number divides the number without leaving a remainder, it is a divisor. Here's how you can implement this:\n\n```python\ndef divisor(n):...
[ 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
[ 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0 ]
{ "language": "python", "test_cases": [ "assert divisor(100) == 9", "assert divisor(13) == 2", "assert divisor(49) == 3", "assert divisor(28) == 6", "assert divisor(6) == 4", "assert divisor(0) == 0", "assert divisor(15) == 4", "assert divisor(1) == 1", "assert divisor(10) == 4",...
97
Write a function to find frequency count of list of lists.
def frequency_lists(list1): list1 = [item for sublist in list1 for item in sublist] dic_data = {} for num in list1: if num in dic_data.keys(): dic_data[num] += 1 else: key = num value = 1 dic_data[key] = value return dic_data
[ "assert frequency_lists([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]])=={1: 1, 2: 3, 3: 1, 4: 1, 5: 2, 6: 1, 7: 1, 8: 1, 9: 1}", "assert frequency_lists([[1,2,3,4],[5,6,7,8],[9,10,11,12]])=={1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1,10:1,11:1,12:1}", "assert frequency_lists([[20,30,40,17],[18,16,14,13],...
[]
[ "Let's address the given problem step-by-step and then implement the solution in Python.\n\nThe task is to find the frequency count of each list within a given list of lists. The frequency count is required to count the occurrences of each element in the arrays.\n\nGiven Python code, the `frequency_lists` function ...
[ 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
[ 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
{ "language": "python", "test_cases": [ "assert frequency_lists([[1, 2], [2, 3], [3, 4], [4, 5]]) == {1: 1, 2: 2, 3: 2, 4: 2, 5: 1}", "assert frequency_lists([[10, 20, 30], [40, 50, 60], [70, 80, 90]]) == {10: 1, 20: 1, 30: 1, 40: 1, 50: 1, 60: 1, 70: 1, 80: 1, 90: 1}", "assert frequency_lists([[1], [2]...
98
Write a function to multiply all the numbers in a list and divide with the length of the list.
def multiply_num(numbers): total = 1 for x in numbers: total *= x return total/len(numbers)
[ "assert multiply_num((8, 2, 3, -1, 7))==-67.2", "assert multiply_num((-10,-20,-30))==-2000.0", "assert multiply_num((19,15,18))==1710.0" ]
[]
[ "To solve the given problem, we need to write a function that takes a list of numbers as input and calculates the product of all the numbers, then divides the product by the number of elements in the list. Here's how you can implement this in Python:\n\n```python\ndef multiply_num(numbers):\n \"\"\"\n Write a...
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert multiply_num((1, 2, 3, 4)) == 2.4", "assert multiply_num((2, 4, 6, 8, 10)) == 38.4", "assert multiply_num((100, 200, 300)) == 20000.0", "assert multiply_num((10,)) == 10.0", "assert multiply_num((1, -1, 1, -1)) == 1.0", "assert multiply_num((5,...
99
Write a function to convert the given decimal number to its binary equivalent.
def decimal_to_binary(n): return bin(n).replace("0b","")
[ "assert decimal_to_binary(8) == '1000'", "assert decimal_to_binary(18) == '10010'", "assert decimal_to_binary(7) == '111' " ]
[]
[ "Here's the equivalent Python function to the given JavaScript function:\n\n```python\ndef decimal_to_binary(n):\n # Convert the decimal number to binary and return the result as a string\n return bin(n)[2:]\n\n# Example usage:\nprint(decimal_to_binary(8)) # Output: '1000'\n```\n\nIn this Python solution, th...
[ 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1 ]
[ 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1 ]
{ "language": "python", "test_cases": [ "assert decimal_to_binary(16) == '10000'", "assert decimal_to_binary(32) == '100000'", "assert decimal_to_binary(0) == '0'", "assert decimal_to_binary(5) == '101'", "assert decimal_to_binary(31) == '11111'", "assert decimal_to_binary(255) == '11111111'...
100
Write a function to find the next smallest palindrome of a specified number.
import sys def next_smallest_palindrome(num): numstr = str(num) for i in range(num+1,sys.maxsize): if str(i) == str(i)[::-1]: return i
[ "assert next_smallest_palindrome(99)==101", "assert next_smallest_palindrome(1221)==1331", "assert next_smallest_palindrome(120)==121" ]
[]
[ "To solve the problem of finding the next smallest palindrome of a given number, we need to follow these steps:\n\n1. Double the number because if it's already a palindrome, doubling it will make it a palindrome too.\n2. Use a helper function to find the middle digit of the doubled number.\n3. Reverse the first hal...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert next_smallest_palindrome(1221) == 1331", "assert next_smallest_palindrome(999) == 1001", "assert next_smallest_palindrome(99) == 101", "assert next_smallest_palindrome(808) == 818", "assert next_smallest_palindrome(111) == 121", "assert next_sm...
101
Write a function to find the kth element in the given array.
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([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" ]
[]
[ "```python\ndef kth_element(arr, n, k):\n \"\"\"\n Write a function to find the kth element in the given array.\n \n >>> kth_element([12,3,5,7,19], 5, 2)\n 3\n \"\"\"\n # Sort the array\n arr.sort()\n \n # Return the k-th element\n return arr[k - 1]\n\n# Example usage\narr = [12, 3,...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert kth_element([1,2,3,4,5], 5, 1) == 1", "assert kth_element([7,10,4,3,20,15], 6, 3) == 7", "assert kth_element([10,20,30,40,50], 5, 5) == 50", "assert kth_element([1,2,3,4,5,6,7,8,9,10], 10, 1) == 1", "assert kth_element([12,3,5,7,19], 5, 2) == 3", ...
102
Write a function to convert snake case string to camel case string.
def snake_to_camel(word): import re return ''.join(x.capitalize() or '_' for x in word.split('_'))
[ "assert snake_to_camel('python_program')=='PythonProgram'", "assert snake_to_camel('python_language')==('PythonLanguage')", "assert snake_to_camel('programming_language')==('ProgrammingLanguage')" ]
[]
[ "To convert a snake case string to camel case string in Python, you can follow these steps:\n\n1. Split the string by the underscore character.\n2. capitalize the first letter of each part before joining them back together.\n\nHere's the Python code to achieve this:\n\n```python\ndef snake_to_camel(word):\n \"\"...
[ 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0 ]
[ 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0 ]
{ "language": "python", "test_cases": [ "assert snake_to_camel('multiple__underscores__here') == 'MultipleUnderscoresHere'", "assert snake_to_camel('special_characters_!@#') == 'SpecialCharacters!@#'", "assert snake_to_camel('python_program') == 'PythonProgram'", "assert snake_to_camel('convert_this...
103
Write a function to find eulerian number a(n, m).
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(3, 1) == 4", "assert eulerian_num(4, 1) == 11", "assert eulerian_num(5, 3) == 26" ]
[]
[ "To solve the given problem, we need to find the Eulerian number \\( a(n, m) \\), which represents the number of paths of length \\( n \\) starting from a given node with \\( m \\) obstacles. The Eulerian number for \\( a(n, m) \\) can be computed using the following formula:\n\n\\[ a(n, m) = m! \\cdot (n-1)! \\]\n...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert eulerian_num(2, 1) == 1", "assert eulerian_num(3, 0) == 1", "assert eulerian_num(4, 0) == 1", "assert eulerian_num(1, 1) == 0", "assert eulerian_num(2, 0) == 1", "assert eulerian_num(1, 0) == 1", "assert eulerian_num(3, 2) == 1", "asser...
104
Write a function to sort each sublist of strings in a given list of lists using lambda function.
def sort_sublists(input_list): result = [sorted(x, key = lambda x:x[0]) for x in input_list] return result
[ "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', 'b...
[]
[ "To solve the problem of sorting each sublist of strings in a given list of lists using Python, you can use the `map` function along with a lambda function. Here's a Python function that accomplishes this:\n\n```python\ndef sort_sublists(input_list):\n \"\"\"\n Write a function to sort each sublist of strings...
[ 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert sort_sublists([[\"apple\", \"orange\", \"banana\"], [\"grape\", \"kiwi\", \"pear\"], [\"peach\", \"plum\", \"apricot\"]]) == [['apple', 'banana', 'orange'], ['grape', 'kiwi', 'pear'], ['apricot', 'peach', 'plum']]", "assert sort_sublists([[\"a\", \"b\", \"c\"]...
105
Write a python function to count true booleans in the given list.
def count(lst): return sum(lst)
[ "assert count([True,False,True]) == 2", "assert count([False,False]) == 0", "assert count([True,True,True]) == 3" ]
[]
[ "To solve the code problem, we need to count the number of true booleans (i.e., `True`) in the given list. Here's how you can do it in Python:\n\n```python\ndef count(lst):\n \"\"\"\n Write a python function to count true booleans in the given list.\n \n >>> count([True,False,True])\n 2\n \"\"\"\n...
[ 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1 ]
[ 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1 ]
{ "language": "python", "test_cases": [ "assert count([True]) == 1", "assert count([False, False, True, True, False, False, True, True, False]) == 4", "assert count([False, True, False, True, False, True, False]) == 3", "assert count([True, True, True, True]) == 4", "assert count([False]) == 0",...
106
Write a function to add the given list to the given tuples.
def add_lists(test_list, test_tup): res = tuple(list(test_tup) + test_list) return (res)
[ "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)" ]
[]
[ "Here's the solution to the given Python code snippet:\n\n```python\ndef add_lists(test_list, test_tup):\n \"\"\"\n Write a function to add the given list to the given tuples.\n \n >>> add_lists([5, 6, 7], (9, 10))\n (9, 10, 5, 6, 7)\n\n \"\"\"\n # Concatenate the test_list and append the test_...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert add_lists([1, 2, 3], ()) == (1, 2, 3)", "assert add_lists(['a', 'b', 'c'], ('d', 'e', 'f', 'g')) == ('d', 'e', 'f', 'g', 'a', 'b', 'c')", "assert add_lists([10, 20], (30, 40, 50)) == (30, 40, 50, 10, 20)", "assert add_lists([True, False], (None,)) == (...
107
Write a python function to count hexadecimal numbers for a given range.
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...
[ "assert count_Hexadecimal(10,15) == 6", "assert count_Hexadecimal(2,4) == 0", "assert count_Hexadecimal(15,16) == 1" ]
[]
[ "To solve the problem of counting hexadecimal numbers for a given range, we can use the following approach. We define a function `count_Hexadecimal` that takes two parameters, `L` and `R`, which represent the start and end of the range. We then create a set of all hexadecimal characters (0-9, A-F) to easily compare...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 ]
{ "language": "python", "test_cases": [ "assert count_Hexadecimal(0, 15) == 16", "assert count_Hexadecimal(10, 15) == 6", "assert count_Hexadecimal(15, 10) == 0", "assert count_Hexadecimal(16, 16) == 1", "assert count_Hexadecimal(0, 0) == 1", "assert count_Hexadecimal(100, 100) == 1", "a...
108
Write a function to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm.
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([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]", "a...
[]
[ "To solve the given problem, we can use the `heapq.merge()` function from Python's `heapq` module along with a generator expression. This function can be used to merge multiple sorted sequences into a single sorted iterator.\n\nHere's the Python function to achieve this:\n\n```python\nimport heapq\n\ndef merge_sort...
[ 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0 ]
[ 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0 ]
{ "language": "python", "test_cases": [ "assert merge_sorted_list([], [1, 2, 3], []) == [1, 2, 3]", "assert merge_sorted_list([1, 3, 5, 7], [2, 4, 6, 8], [0, 9, 10, 11]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]", "assert merge_sorted_list([10, 20, 30], [5, 15, 25], [1, 9, 11]) == [1, 5, 9, 10, 11, 15, ...
109
Write a python function to find the count of rotations of a binary string with odd value.
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(\"011001\",6) == 3", "assert odd_Equivalent(\"11011\",5) == 4", "assert odd_Equivalent(\"1010\",4) == 2" ]
[]
[ "To solve the problem of finding the count of rotations of a binary string with odd value, we can follow these steps:\n\n1. Build the string in reverse order.\n2. Check if the reverse string is a subsequence of the original binary string with odd value.\n\nHere's the Python function to achieve this:\n\n```python\nd...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert odd_Equivalent(\"1001001\", 7) == 4", "assert odd_Equivalent(\"110011\", 6) == 3", "assert odd_Equivalent(\"101010\", 6) == 3", "assert odd_Equivalent(\"0\", 1) == 0", "assert odd_Equivalent(\"001100\", 6) == 3", "assert odd_Equivalent(\"011001...
110
Write a function to extract the ranges that are missing from the given list with the given start range and end range values.
def extract_missing(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([(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) =...
[]
[ "Here's a Python code snippet that solves the problem of finding the missing ranges from a given list of test data:\n\n```python\ndef extract_missing(test_list, strt_val, stop_val):\n \"\"\"\n Write a function to extract the ranges that are missing from the given list with the given start range and end range ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
{ "language": "python", "test_cases": [ "assert extract_missing([(1, 2), (3, 4), (5, 6)], 1, 6) == []", "assert extract_missing([(10, 20)], 5, 25) == [(5, 10), (20, 25)]", "assert extract_missing([], 1, 10) == [(1, 10)]", "assert extract_missing([(5, 10)], 1, 20) == [(1, 5), (10, 20)]", "assert ...