Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code remove_empty>
  MAKE_FUNCTION 0
  STORE_NAME remove_empty
  RETURN_CONST None
END
CODE remove_empty(tuple1)
  RESUME 0
  LOAD_FAST tuple1
  GET_ITER
  LOAD_FAST_AND_CLEAR t
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  STORE_FAST t
  LOAD_FAST t
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST t
  LIST_APPEND 2
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  STORE_FAST tuple1
  STORE_FAST t
  LOAD_FAST tuple1
  RETURN_VALUE
L7:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST t
  RERAISE 0
  EXC try=L1..L3 -> handler=L7 depth=2 lasti=False
  EXC try=L4..L6 -> handler=L7 depth=2 lasti=False
END

def remove_empty(tuple1):
    tuple1 = [t for t in tuple1 if t]
    return tuple1

Prompt: Write a function to remove an empty tuple from a list of tuples.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check>
  MAKE_FUNCTION 0
  STORE_NAME check
  RETURN_CONST None
END
CODE check(string)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_GLOBAL NULL + set
  LOAD_FAST string
  CALL 1
  LOAD_ATTR NULL|self + intersection
  LOAD_CONST 'AEIOUaeiou'
  CALL 1
  CALL 1
  LOAD_CONST 5
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'accepted'
L1:
  RETURN_CONST 'not accepted'
END

def check(string):
    if len(set(string).intersection('AEIOUaeiou')) >= 5:
        return 'accepted'
    else:
        return 'not accepted'

Prompt: Write a python function to accept the strings which contains all vowels.

assert check('program') == "not accepted"

Creative Commons Attribution 4.0 International

MBPP (Mostly Basic Python Problems), Austin et al. 2021, Google Research


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code join_tuples>
  MAKE_FUNCTION 0
  STORE_NAME join_tuples
  RETURN_CONST None
END
CODE join_tuples(test_list)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST res
  LOAD_FAST test_list
  GET_ITER
L1:
  FOR_ITER L7
  STORE_FAST sub
  LOAD_FAST res
  POP_JUMP_IF_FALSE L2
  LOAD_FAST res
  LOAD_CONST -1
  BINARY_SUBSCR
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST sub
  LOAD_CONST 0
  BINARY_SUBSCR
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST res
  LOAD_CONST -1
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + extend
  LOAD_FAST sub
  LOAD_CONST 1
  LOAD_CONST None
  BINARY_SLICE
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L2:
  LOAD_FAST res
  LOAD_ATTR NULL|self + append
  LOAD_FAST sub
  GET_ITER
  LOAD_FAST_AND_CLEAR ele
  SWAP 2
L3:
  BUILD_LIST 0
  SWAP 2
L4:
  FOR_ITER L5
  STORE_FAST ele
  LOAD_FAST ele
  LIST_APPEND 2
  JUMP_BACKWARD L4
L5:
  END_FOR
L6:
  SWAP 2
  STORE_FAST ele
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L7:
  END_FOR
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + map
  LOAD_GLOBAL tuple
  LOAD_FAST res
  CALL 2
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
L8:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ele
  RERAISE 0
  EXC try=L3..L6 -> handler=L8 depth=5 lasti=False
END

def join_tuples(test_list):
    res = []
    for sub in test_list:
        if res and res[-1][0] == sub[0]:
            res[-1].extend(sub[1:])
        else:
            res.append([ele for ele in sub])
    res = list(map(tuple, res))
    return res

Prompt: Write a function to join the tuples if they have similar initial elements.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code min_of_two>
  MAKE_FUNCTION 0
  STORE_NAME min_of_two
  RETURN_CONST None
END
CODE min_of_two(x, y)
  RESUME 0
  LOAD_FAST x
  LOAD_FAST y
  COMPARE_OP <
  POP_JUMP_IF_FALSE L1
  LOAD_FAST x
  RETURN_VALUE
L1:
  LOAD_FAST y
  RETURN_VALUE
END

def min_of_two(x, y):
    if x < y:
        return x
    return y

Prompt: Write a function to find minimum of two numbers.

assert min_of_two(10,20)==10
assert min_of_two(19,15)==15
assert min_of_two(-10,-20)==-20


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code maximum_segments>
  MAKE_FUNCTION 0
  STORE_NAME maximum_segments
  RETURN_CONST None
END
CODE maximum_segments(n, a, b, c)
  RESUME 0
  LOAD_CONST -1
  BUILD_LIST 1
  LOAD_FAST n
  LOAD_CONST 10
  BINARY_OP +
  BINARY_OP *
  STORE_FAST dp
  LOAD_CONST 0
  LOAD_FAST dp
  LOAD_CONST 0
  STORE_SUBSCR
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_FAST n
  CALL 2
  GET_ITER
L1:
  FOR_ITER L6
  STORE_FAST i
  LOAD_FAST dp
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST -1
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST i
  LOAD_FAST a
  BINARY_OP +
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L3
  LOAD_GLOBAL NULL + max
  LOAD_FAST dp
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST dp
  LOAD_FAST i
  LOAD_FAST a
  BINARY_OP +
  BINARY_SUBSCR
  CALL 2
  LOAD_FAST dp
  LOAD_FAST i
  LOAD_FAST a
  BINARY_OP +
  STORE_SUBSCR
L3:
  LOAD_FAST i
  LOAD_FAST b
  BINARY_OP +
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L4
  LOAD_GLOBAL NULL + max
  LOAD_FAST dp
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST dp
  LOAD_FAST i
  LOAD_FAST b
  BINARY_OP +
  BINARY_SUBSCR
  CALL 2
  LOAD_FAST dp
  LOAD_FAST i
  LOAD_FAST b
  BINARY_OP +
  STORE_SUBSCR
L4:
  LOAD_FAST i
  LOAD_FAST c
  BINARY_OP +
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_TRUE L5
  JUMP_BACKWARD L1
L5:
  LOAD_GLOBAL NULL + max
  LOAD_FAST dp
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST dp
  LOAD_FAST i
  LOAD_FAST c
  BINARY_OP +
  BINARY_SUBSCR
  CALL 2
  LOAD_FAST dp
  LOAD_FAST i
  LOAD_FAST c
  BINARY_OP +
  STORE_SUBSCR
  JUMP_BACKWARD L1
L6:
  END_FOR
  LOAD_FAST dp
  LOAD_FAST n
  BINARY_SUBSCR
  RETURN_VALUE
END

def maximum_segments(n, a, b, c):
    dp = [-1] * (n + 10)
    dp[0] = 0
    for i in range(0, n):
        if dp[i] != -1:
            if i + a <= n:
                dp[i + a] = max(dp[i] + 1, dp[i + a])
            if i + b <= n:
                dp[i + b] = max(dp[i] + 1, dp[i + b])
            if i + c <= n:
                dp[i + c] = max(dp[i] + 1, dp[i + c])
    return dp[n]

Prompt: Write a function to find the maximum number of segments of lengths a, b and c that can be formed from n.

assert maximum_segments(7, 5, 2, 5) == 2

assert maximum_segments(17, 2, 1, 3) == 17

assert maximum_segments(18, 16, 3, 6) == 6


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code concatenate_nested>
  MAKE_FUNCTION 0
  STORE_NAME concatenate_nested
  RETURN_CONST None
END
CODE concatenate_nested(test_tup1, test_tup2)
  RESUME 0
  LOAD_FAST test_tup1
  LOAD_FAST test_tup2
  BINARY_OP +
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END

def concatenate_nested(test_tup1, test_tup2):
    res = test_tup1 + test_tup2
    return res

Prompt: Write a function to concatenate the given two tuples to a nested tuple.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code left_rotate>
  MAKE_FUNCTION 0
  STORE_NAME left_rotate
  RETURN_CONST None
END
CODE left_rotate(s, d)
  RESUME 0
  LOAD_FAST s
  LOAD_FAST d
  LOAD_CONST None
  BINARY_SLICE
  LOAD_FAST s
  LOAD_CONST 0
  LOAD_FAST d
  BINARY_SLICE
  BINARY_OP +
  STORE_FAST tmp
  LOAD_FAST tmp
  RETURN_VALUE
END

def left_rotate(s, d):
    tmp = s[d:] + s[0:d]
    return tmp

Prompt: Write a python function to left rotate the string.

assert left_rotate("python",2) == "thonpy"

assert left_rotate("bigdata",3 ) == "databig"

assert left_rotate("hadoop",1 ) == "adooph"


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code remove_Occ>
  MAKE_FUNCTION 0
  STORE_NAME remove_Occ
  RETURN_CONST None
END
CODE remove_Occ(s, ch)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST s
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST s
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST ch
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST s
  LOAD_CONST 0
  LOAD_FAST i
  BINARY_SLICE
  LOAD_FAST s
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  LOAD_CONST None
  BINARY_SLICE
  BINARY_OP +
  STORE_FAST s
  POP_TOP
  JUMP_FORWARD L4
L3:
  END_FOR
L4:
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST s
  CALL 1
  LOAD_CONST 1
  BINARY_OP -
  LOAD_CONST -1
  LOAD_CONST -1
  CALL 3
  GET_ITER
L5:
  FOR_ITER L7
  STORE_FAST i
  LOAD_FAST s
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST ch
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L6
  JUMP_BACKWARD L5
L6:
  LOAD_FAST s
  LOAD_CONST 0
  LOAD_FAST i
  BINARY_SLICE
  LOAD_FAST s
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  LOAD_CONST None
  BINARY_SLICE
  BINARY_OP +
  STORE_FAST s
  POP_TOP
  LOAD_FAST s
  RETURN_VALUE
L7:
  END_FOR
  LOAD_FAST s
  RETURN_VALUE
END

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

Prompt: Write a python function to remove first and last occurrence of a given character from the string.

assert remove_Occ("hello","l") == "heo"
assert remove_Occ("abcda","a") == "bcd"
assert remove_Occ("PHP","P") == "H"


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sort_matrix>
  MAKE_FUNCTION 0
  STORE_NAME sort_matrix
  RETURN_CONST None
END
CODE sort_matrix(M)
  RESUME 0
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST M
  LOAD_GLOBAL sum
  KW_NAMES ('key',)
  CALL 2
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END

def sort_matrix(M):
    result = sorted(M, key=sum)
    return result

Prompt: Write a function to sort a given matrix in ascending order according to the sum of its rows.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('Counter',)
  IMPORT_NAME collections
  IMPORT_FROM Counter
  STORE_NAME Counter
  POP_TOP
  LOAD_CONST <code count_common>
  MAKE_FUNCTION 0
  STORE_NAME count_common
  RETURN_CONST None
END
CODE count_common(words)
  RESUME 0
  LOAD_GLOBAL NULL + Counter
  LOAD_FAST words
  CALL 1
  STORE_FAST word_counts
  LOAD_FAST word_counts
  LOAD_ATTR NULL|self + most_common
  LOAD_CONST 4
  CALL 1
  STORE_FAST top_four
  LOAD_FAST top_four
  RETURN_VALUE
END

from collections import Counter

def count_common(words):
    word_counts = Counter(words)
    top_four = word_counts.most_common(4)
    return top_four

Prompt: Write a function to count the most common words in a dictionary.

assert count_common(['red','green','black','pink','black','white','black','eyes','white','black','orange','pink','pink','red','red','white','orange','white',"black",'pink','green','green','pink','green','pink','white','orange',"orange",'red']) == [('pink', 6), ('black', 5), ('white', 5), ('red', 4)]

assert count_common(['one', 'two', 'three', 'four', 'five', 'one', 'two', 'one', 'three', 'one']) == [('one', 4), ('two', 2), ('three', 2), ('four', 1)]

assert count_common(['Facebook', 'Apple', 'Amazon', 'Netflix', 'Google', 'Apple', 'Netflix', 'Amazon']) == [('Apple', 2), ('Amazon', 2), ('Netflix', 2), ('Facebook', 1)]


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code text_lowercase_underscore>
  MAKE_FUNCTION 0
  STORE_NAME text_lowercase_underscore
  RETURN_CONST None
END
CODE text_lowercase_underscore(text)
  RESUME 0
  LOAD_CONST '^[a-z]+_[a-z]+$'
  STORE_FAST patterns
  LOAD_GLOBAL NULL + re
  LOAD_ATTR search
  LOAD_FAST patterns
  LOAD_FAST text
  CALL 2
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'Found a match!'
L1:
  RETURN_CONST 'Not matched!'
END

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!'

Prompt: Write a function to find sequences of lowercase letters joined with an underscore.

assert text_lowercase_underscore("aab_cbbbc")==('Found a match!')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 256
  STORE_NAME NO_OF_CHARS
  LOAD_CONST <code str_to_list>
  MAKE_FUNCTION 0
  STORE_NAME str_to_list
  LOAD_CONST <code lst_to_string>
  MAKE_FUNCTION 0
  STORE_NAME lst_to_string
  LOAD_CONST <code get_char_count_array>
  MAKE_FUNCTION 0
  STORE_NAME get_char_count_array
  LOAD_CONST <code remove_dirty_chars>
  MAKE_FUNCTION 0
  STORE_NAME remove_dirty_chars
  RETURN_CONST None
END
CODE str_to_list(string)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST temp
  LOAD_FAST string
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST x
  LOAD_FAST temp
  LOAD_ATTR NULL|self + append
  LOAD_FAST x
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST temp
  RETURN_VALUE
END
CODE lst_to_string(List)
  RESUME 0
  LOAD_CONST ''
  LOAD_ATTR NULL|self + join
  LOAD_FAST List
  CALL 1
  RETURN_VALUE
END
CODE get_char_count_array(string)
  RESUME 0
  LOAD_CONST 0
  BUILD_LIST 1
  LOAD_GLOBAL NO_OF_CHARS
  BINARY_OP *
  STORE_FAST count
  LOAD_FAST string
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST count
  LOAD_GLOBAL NULL + ord
  LOAD_FAST i
  CALL 1
  COPY 2
  COPY 2
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +=
  SWAP 3
  SWAP 2
  STORE_SUBSCR
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST count
  RETURN_VALUE
END
CODE remove_dirty_chars(string, second_string)
  RESUME 0
  LOAD_GLOBAL NULL + get_char_count_array
  LOAD_FAST second_string
  CALL 1
  STORE_FAST count
  LOAD_CONST 0
  STORE_FAST ip_ind
  LOAD_CONST 0
  STORE_FAST res_ind
  LOAD_CONST ''
  STORE_FAST temp
  LOAD_GLOBAL NULL + str_to_list
  LOAD_FAST string
  CALL 1
  STORE_FAST str_list
  LOAD_FAST ip_ind
  LOAD_GLOBAL NULL + len
  LOAD_FAST str_list
  CALL 1
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L3
L1:
  LOAD_FAST str_list
  LOAD_FAST ip_ind
  BINARY_SUBSCR
  STORE_FAST temp
  LOAD_FAST count
  LOAD_GLOBAL NULL + ord
  LOAD_FAST temp
  CALL 1
  BINARY_SUBSCR
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST str_list
  LOAD_FAST ip_ind
  BINARY_SUBSCR
  LOAD_FAST str_list
  LOAD_FAST res_ind
  STORE_SUBSCR
  LOAD_FAST res_ind
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST res_ind
L2:
  LOAD_FAST ip_ind
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST ip_ind
  LOAD_FAST ip_ind
  LOAD_GLOBAL NULL + len
  LOAD_FAST str_list
  CALL 1
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L3
  JUMP_BACKWARD L1
L3:
  LOAD_GLOBAL NULL + lst_to_string
  LOAD_FAST str_list
  LOAD_CONST 0
  LOAD_FAST res_ind
  BINARY_SLICE
  CALL 1
  RETURN_VALUE
END

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, second_string):
    count = get_char_count_array(second_string)
    ip_ind = 0
    res_ind = 0
    temp = ''
    str_list = str_to_list(string)
    while ip_ind != len(str_list):
        temp = str_list[ip_ind]
        if count[ord(temp)] == 0:
            str_list[res_ind] = str_list[ip_ind]
            res_ind += 1
        ip_ind += 1
    return lst_to_string(str_list[0:res_ind])

Prompt: Write a function to remove characters from the first string which are present in the second string.

assert remove_dirty_chars("probasscurve", "pros") == 'bacuve'

assert remove_dirty_chars("digitalindia", "talent") == 'digiidi'

assert remove_dirty_chars("exoticmiles", "toxic") == 'emles'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code test_duplicate>
  MAKE_FUNCTION 0
  STORE_NAME test_duplicate
  RETURN_CONST None
END
CODE test_duplicate(arraynums)
  RESUME 0
  LOAD_GLOBAL NULL + set
  LOAD_FAST arraynums
  CALL 1
  STORE_FAST nums_set
  LOAD_GLOBAL NULL + len
  LOAD_FAST arraynums
  CALL 1
  LOAD_GLOBAL NULL + len
  LOAD_FAST nums_set
  CALL 1
  COMPARE_OP !=
  RETURN_VALUE
END

def test_duplicate(arraynums):
    nums_set = set(arraynums)
    return len(arraynums) != len(nums_set)

Prompt: Write a function to find whether a given array of integers contains any duplicate element.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_woodall>
  MAKE_FUNCTION 0
  STORE_NAME is_woodall
  RETURN_CONST None
END
CODE is_woodall(x)
  RESUME 0
  LOAD_FAST x
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST False
L1:
  LOAD_FAST x
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  RETURN_CONST True
L2:
  LOAD_FAST x
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST x
  LOAD_CONST 0
  STORE_FAST p
  LOAD_FAST x
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L5
L3:
  LOAD_FAST x
  LOAD_CONST 2
  BINARY_OP /
  STORE_FAST x
  LOAD_FAST p
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST p
  LOAD_FAST p
  LOAD_FAST x
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L4
  RETURN_CONST True
L4:
  LOAD_FAST x
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L5
  JUMP_BACKWARD L3
L5:
  RETURN_CONST False
END

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

Prompt: Write a function to check if the given number is woodball or not.

assert is_woodall(383) == True
assert is_woodall(254) == False
assert is_woodall(200) == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_first_duplicate>
  MAKE_FUNCTION 0
  STORE_NAME find_first_duplicate
  RETURN_CONST None
END
CODE find_first_duplicate(nums)
  RESUME 0
  LOAD_GLOBAL NULL + set
  CALL 0
  STORE_FAST num_set
  LOAD_CONST -1
  STORE_FAST no_duplicate
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST nums
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST nums
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST num_set
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L2
  LOAD_FAST nums
  LOAD_FAST i
  BINARY_SUBSCR
  SWAP 2
  POP_TOP
  RETURN_VALUE
L2:
  LOAD_FAST num_set
  LOAD_ATTR NULL|self + add
  LOAD_FAST nums
  LOAD_FAST i
  BINARY_SUBSCR
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST no_duplicate
  RETURN_VALUE
END

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

Prompt: Write a function to find the first duplicate element in a given array of integers.

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


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code maximum_Sum>
  MAKE_FUNCTION 0
  STORE_NAME maximum_Sum
  RETURN_CONST None
END
CODE maximum_Sum(list1)
  RESUME 0
  LOAD_CONST -100000
  STORE_FAST maxi
  LOAD_FAST list1
  GET_ITER
L1:
  FOR_ITER L4
  STORE_FAST x
  LOAD_CONST 0
  STORE_FAST sum
  LOAD_FAST x
  GET_ITER
L2:
  FOR_ITER L3
  STORE_FAST y
  LOAD_FAST sum
  LOAD_FAST y
  BINARY_OP +=
  STORE_FAST sum
  JUMP_BACKWARD L2
L3:
  END_FOR
  LOAD_GLOBAL NULL + max
  LOAD_FAST sum
  LOAD_FAST maxi
  CALL 2
  STORE_FAST maxi
  JUMP_BACKWARD L1
L4:
  END_FOR
  LOAD_FAST maxi
  RETURN_VALUE
END

def maximum_Sum(list1):
    maxi = -100000
    for x in list1:
        sum = 0
        for y in x:
            sum += y
        maxi = max(sum, maxi)
    return maxi

Prompt: Write a python function to find the maximum sum of elements of list in a list of lists.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code binary_to_decimal>
  MAKE_FUNCTION 0
  STORE_NAME binary_to_decimal
  RETURN_CONST None
END
CODE binary_to_decimal(binary)
  RESUME 0
  LOAD_FAST binary
  STORE_FAST binary1
  LOAD_CONST (0, 0, 0)
  UNPACK_SEQUENCE 3
  STORE_FAST decimal
  STORE_FAST i
  STORE_FAST n
  LOAD_FAST binary
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST binary
  LOAD_CONST 10
  BINARY_OP %
  STORE_FAST dec
  LOAD_FAST decimal
  LOAD_FAST dec
  LOAD_GLOBAL NULL + pow
  LOAD_CONST 2
  LOAD_FAST i
  CALL 2
  BINARY_OP *
  BINARY_OP +
  STORE_FAST decimal
  LOAD_FAST binary
  LOAD_CONST 10
  BINARY_OP //
  STORE_FAST binary
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST i
  LOAD_FAST binary
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST decimal
  RETURN_VALUE
END

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

Prompt: Write a function to convert the given binary number to its decimal equivalent.

assert binary_to_decimal(1101101) == 109


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_k_elements>
  MAKE_FUNCTION 0
  STORE_NAME check_k_elements
  RETURN_CONST None
END
CODE check_k_elements(test_list, K)
  RESUME 0
  LOAD_CONST True
  STORE_FAST res
  LOAD_FAST test_list
  GET_ITER
L1:
  FOR_ITER L5
  STORE_FAST tup
  LOAD_FAST tup
  GET_ITER
L2:
  FOR_ITER L4
  STORE_FAST ele
  LOAD_FAST ele
  LOAD_FAST K
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L2
L3:
  LOAD_CONST False
  STORE_FAST res
  JUMP_BACKWARD L2
L4:
  END_FOR
  JUMP_BACKWARD L1
L5:
  END_FOR
  LOAD_FAST res
  RETURN_VALUE
END

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

Prompt: Write a function to check if the given tuple list has all k elements.

assert check_k_elements([(7, 7, 7), (7, 7)], 7) == True

assert check_k_elements([(9, 9), (9, 9, 9, 9)], 7) == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code remove>
  MAKE_FUNCTION 0
  STORE_NAME remove
  RETURN_CONST None
END
CODE remove(list)
  RESUME 0
  LOAD_CONST '[0-9]'
  STORE_FAST pattern
  LOAD_FAST list
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_GLOBAL NULL + re
  LOAD_ATTR sub
  LOAD_FAST pattern
  LOAD_CONST ''
  LOAD_FAST i
  CALL 3
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST list
  STORE_FAST i
  LOAD_FAST list
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=2 lasti=False
END

import re

def remove(list):
    pattern = '[0-9]'
    list = [re.sub(pattern, '', i) for i in list]
    return list

Prompt: Write a python function to remove all digits from a list of strings.

assert remove(['4words', '3letters', '4digits']) == ['words', 'letters', 'digits']

assert remove(['28Jan','12Jan','11Jan']) == ['Jan','Jan','Jan']

assert remove(['wonder1','wonder2','wonder3']) == ['wonder','wonder','wonder']


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code binomial_Coeff>
  MAKE_FUNCTION 0
  STORE_NAME binomial_Coeff
  RETURN_CONST None
END
CODE binomial_Coeff(n, k)
  RESUME 0
  LOAD_FAST k
  LOAD_FAST n
  COMPARE_OP >
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 0
L1:
  LOAD_FAST k
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  LOAD_FAST k
  LOAD_FAST n
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
L2:
  RETURN_CONST 1
L3:
  LOAD_GLOBAL NULL + binomial_Coeff
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  LOAD_FAST k
  LOAD_CONST 1
  BINARY_OP -
  CALL 2
  LOAD_GLOBAL NULL + binomial_Coeff
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  LOAD_FAST k
  CALL 2
  BINARY_OP +
  RETURN_VALUE
END

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)

Prompt: Write a python function to find binomial co-efficient.

assert binomial_Coeff(5,2) == 10
assert binomial_Coeff(4,3) == 4
assert binomial_Coeff(3,2) == 3


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_Equality>
  MAKE_FUNCTION 0
  STORE_NAME check_Equality
  LOAD_CONST <code count_Substring_With_Equal_Ends>
  MAKE_FUNCTION 0
  STORE_NAME count_Substring_With_Equal_Ends
  RETURN_CONST None
END
CODE check_Equality(s)
  RESUME 0
  LOAD_GLOBAL NULL + ord
  LOAD_FAST s
  LOAD_CONST 0
  BINARY_SUBSCR
  CALL 1
  LOAD_GLOBAL NULL + ord
  LOAD_FAST s
  LOAD_GLOBAL NULL + len
  LOAD_FAST s
  CALL 1
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  CALL 1
  COMPARE_OP ==
  RETURN_VALUE
END
CODE count_Substring_With_Equal_Ends(s)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST result
  LOAD_GLOBAL NULL + len
  LOAD_FAST s
  CALL 1
  STORE_FAST n
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L1:
  FOR_ITER L5
  STORE_FAST i
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST n
  LOAD_FAST i
  BINARY_OP -
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L2:
  FOR_ITER L4
  STORE_FAST j
  LOAD_GLOBAL NULL + check_Equality
  LOAD_FAST s
  LOAD_FAST i
  LOAD_FAST i
  LOAD_FAST j
  BINARY_OP +
  BINARY_SLICE
  CALL 1
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L2
L3:
  LOAD_FAST result
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST result
  JUMP_BACKWARD L2
L4:
  END_FOR
  JUMP_BACKWARD L1
L5:
  END_FOR
  LOAD_FAST result
  RETURN_VALUE
END

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

Prompt: Write a python function to count all the substrings starting and ending with same characters.

assert count_Substring_With_Equal_Ends("abc") == 3

assert count_Substring_With_Equal_Ends("abcda") == 6

assert count_Substring_With_Equal_Ends("ab") == 2


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code func>
  MAKE_FUNCTION 0
  STORE_NAME func
  RETURN_CONST None
END
CODE func(nums, k)
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME collections
  STORE_FAST collections
  LOAD_FAST collections
  LOAD_ATTR NULL|self + defaultdict
  LOAD_GLOBAL int
  CALL 1
  STORE_FAST d
  LOAD_FAST nums
  GET_ITER
L1:
  FOR_ITER L4
  STORE_FAST row
  LOAD_FAST row
  GET_ITER
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST d
  LOAD_FAST i
  COPY 2
  COPY 2
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +=
  SWAP 3
  SWAP 2
  STORE_SUBSCR
  JUMP_BACKWARD L2
L3:
  END_FOR
  JUMP_BACKWARD L1
L4:
  END_FOR
  BUILD_LIST 0
  STORE_FAST temp
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME heapq
  STORE_FAST heapq
  LOAD_FAST d
  LOAD_ATTR NULL|self + items
  CALL 0
  GET_ITER
L5:
  FOR_ITER L9
  UNPACK_SEQUENCE 2
  STORE_FAST key
  STORE_FAST v
  LOAD_GLOBAL NULL + len
  LOAD_FAST temp
  CALL 1
  LOAD_FAST k
  COMPARE_OP <
  POP_JUMP_IF_FALSE L7
  LOAD_FAST temp
  LOAD_ATTR NULL|self + append
  LOAD_FAST v
  LOAD_FAST key
  BUILD_TUPLE 2
  CALL 1
  POP_TOP
  LOAD_GLOBAL NULL + len
  LOAD_FAST temp
  CALL 1
  LOAD_FAST k
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L6
  JUMP_BACKWARD L5
L6:
  LOAD_FAST heapq
  LOAD_ATTR NULL|self + heapify
  LOAD_FAST temp
  CALL 1
  POP_TOP
  JUMP_BACKWARD L5
L7:
  LOAD_FAST v
  LOAD_FAST temp
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_CONST 0
  BINARY_SUBSCR
  COMPARE_OP >
  POP_JUMP_IF_TRUE L8
  JUMP_BACKWARD L5
L8:
  LOAD_FAST heapq
  LOAD_ATTR NULL|self + heappop
  LOAD_FAST temp
  CALL 1
  POP_TOP
  LOAD_FAST heapq
  LOAD_ATTR NULL|self + heappush
  LOAD_FAST temp
  LOAD_FAST v
  LOAD_FAST key
  BUILD_TUPLE 2
  CALL 2
  POP_TOP
  JUMP_BACKWARD L5
L9:
  END_FOR
  BUILD_LIST 0
  STORE_FAST result
  LOAD_FAST temp
  POP_JUMP_IF_FALSE L11
L10:
  LOAD_FAST heapq
  LOAD_ATTR NULL|self + heappop
  LOAD_FAST temp
  CALL 1
  UNPACK_SEQUENCE 2
  STORE_FAST v
  STORE_FAST key
  LOAD_FAST result
  LOAD_ATTR NULL|self + append
  LOAD_FAST key
  CALL 1
  POP_TOP
  LOAD_FAST temp
  POP_JUMP_IF_FALSE L11
  JUMP_BACKWARD L10
L11:
  LOAD_FAST result
  RETURN_VALUE
END

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:
                heapq.heapify(temp)
        elif v > temp[0][0]:
            heapq.heappop(temp)
            heapq.heappush(temp, (v, key))
    result = []
    while temp:
        v, key = heapq.heappop(temp)
        result.append(key)
    return result

Prompt: 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.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code max_Prime_Factors>
  MAKE_FUNCTION 0
  STORE_NAME max_Prime_Factors
  RETURN_CONST None
END
CODE max_Prime_Factors(n)
  RESUME 0
  LOAD_CONST -1
  STORE_FAST maxPrime
  LOAD_FAST n
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_CONST 2
  STORE_FAST maxPrime
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP >>=
  STORE_FAST n
  LOAD_FAST n
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_GLOBAL NULL + range
  LOAD_CONST 3
  LOAD_GLOBAL NULL + int
  LOAD_GLOBAL NULL + math
  LOAD_ATTR sqrt
  LOAD_FAST n
  CALL 1
  CALL 1
  LOAD_CONST 1
  BINARY_OP +
  LOAD_CONST 2
  CALL 3
  GET_ITER
L3:
  FOR_ITER L6
  STORE_FAST i
  LOAD_FAST n
  LOAD_FAST i
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L4
  JUMP_BACKWARD L3
L4:
  LOAD_FAST i
  STORE_FAST maxPrime
  LOAD_FAST n
  LOAD_FAST i
  BINARY_OP /
  STORE_FAST n
  LOAD_FAST n
  LOAD_FAST i
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L5
  JUMP_BACKWARD L4
L5:
  JUMP_BACKWARD L3
L6:
  END_FOR
  LOAD_FAST n
  LOAD_CONST 2
  COMPARE_OP >
  POP_JUMP_IF_FALSE L7
  LOAD_FAST n
  STORE_FAST maxPrime
L7:
  LOAD_GLOBAL NULL + int
  LOAD_FAST maxPrime
  CALL 1
  RETURN_VALUE
END

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)

Prompt: Write a python function to find the largest prime factor of a given number.

assert max_Prime_Factors(15) == 5
assert max_Prime_Factors(6) == 3
assert max_Prime_Factors(2) == 2


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code decimal_To_Binary>
  MAKE_FUNCTION 0
  STORE_NAME decimal_To_Binary
  RETURN_CONST None
END
CODE decimal_To_Binary(N)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST B_Number
  LOAD_CONST 0
  STORE_FAST cnt
  LOAD_FAST N
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST N
  LOAD_CONST 2
  BINARY_OP %
  STORE_FAST rem
  LOAD_GLOBAL NULL + pow
  LOAD_CONST 10
  LOAD_FAST cnt
  CALL 2
  STORE_FAST c
  LOAD_FAST B_Number
  LOAD_FAST rem
  LOAD_FAST c
  BINARY_OP *
  BINARY_OP +=
  STORE_FAST B_Number
  LOAD_FAST N
  LOAD_CONST 2
  BINARY_OP //=
  STORE_FAST N
  LOAD_FAST cnt
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST cnt
  LOAD_FAST N
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST B_Number
  RETURN_VALUE
END

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

Prompt: Write a python function to convert a decimal number to binary number.

assert decimal_To_Binary(10) == 1010
assert decimal_To_Binary(1) == 1
assert decimal_To_Binary(20) == 10100


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_missing>
  MAKE_FUNCTION 0
  STORE_NAME find_missing
  RETURN_CONST None
END
CODE find_missing(ar, N)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST l
  LOAD_FAST N
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST r
  LOAD_FAST l
  LOAD_FAST r
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
L1:
  LOAD_FAST l
  LOAD_FAST r
  BINARY_OP +
  LOAD_CONST 2
  BINARY_OP /
  STORE_FAST mid
  LOAD_GLOBAL NULL + int
  LOAD_FAST mid
  CALL 1
  STORE_FAST mid
  LOAD_FAST ar
  LOAD_FAST mid
  BINARY_SUBSCR
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP +
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L2
  LOAD_FAST ar
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_FAST mid
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP +
  RETURN_VALUE
L2:
  LOAD_FAST ar
  LOAD_FAST mid
  BINARY_SUBSCR
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP +
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L3
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST r
  JUMP_FORWARD L4
L3:
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST l
L4:
  LOAD_FAST l
  LOAD_FAST r
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
  JUMP_BACKWARD L1
L5:
  RETURN_CONST -1
END

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
    return -1

Prompt: Write a python function to find the missing number in a sorted array.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_rect_num>
  MAKE_FUNCTION 0
  STORE_NAME find_rect_num
  RETURN_CONST None
END
CODE find_rect_num(n)
  RESUME 0
  LOAD_FAST n
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP *
  RETURN_VALUE
END

def find_rect_num(n):
    return n * (n + 1)

Prompt: Write a function to find the n-th rectangular number.

assert find_rect_num(4) == 20
assert find_rect_num(5) == 30
assert find_rect_num(6) == 42


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sort_mixed_list>
  MAKE_FUNCTION 0
  STORE_NAME sort_mixed_list
  RETURN_CONST None
END
CODE sort_mixed_list(mixed_list)
  RESUME 0
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST mixed_list
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  STORE_FAST i
  LOAD_GLOBAL NULL + type
  LOAD_FAST i
  CALL 1
  LOAD_GLOBAL int
  IS_OP 0
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST i
  LIST_APPEND 2
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  SWAP 2
  STORE_FAST i
  CALL 1
  STORE_FAST int_part
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST mixed_list
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L7:
  BUILD_LIST 0
  SWAP 2
L8:
  FOR_ITER L11
  STORE_FAST i
  LOAD_GLOBAL NULL + type
  LOAD_FAST i
  CALL 1
  LOAD_GLOBAL str
  IS_OP 0
  POP_JUMP_IF_TRUE L10
L9:
  JUMP_BACKWARD L8
L10:
  LOAD_FAST i
  LIST_APPEND 2
  JUMP_BACKWARD L8
L11:
  END_FOR
L12:
  SWAP 2
  STORE_FAST i
  CALL 1
  STORE_FAST str_part
  LOAD_FAST int_part
  LOAD_FAST str_part
  BINARY_OP +
  RETURN_VALUE
L13:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
L14:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
  EXC try=L1..L3 -> handler=L13 depth=4 lasti=False
  EXC try=L4..L6 -> handler=L13 depth=4 lasti=False
  EXC try=L7..L9 -> handler=L14 depth=4 lasti=False
  EXC try=L10..L12 -> handler=L14 depth=4 lasti=False
END

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

Prompt: Write a function to sort a given mixed list of integers and strings.

assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code div_even_odd>
  MAKE_FUNCTION 0
  STORE_NAME div_even_odd
  RETURN_CONST None
END
CODE div_even_odd(list1)
  RESUME 0
  LOAD_GLOBAL NULL + next
  LOAD_CONST <code div_even_odd.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_FAST list1
  GET_ITER
  CALL 0
  LOAD_CONST -1
  CALL 2
  STORE_FAST first_even
  LOAD_GLOBAL NULL + next
  LOAD_CONST <code div_even_odd.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_FAST list1
  GET_ITER
  CALL 0
  LOAD_CONST -1
  CALL 2
  STORE_FAST first_odd
  LOAD_FAST first_even
  LOAD_FAST first_odd
  BINARY_OP /
  RETURN_VALUE
END
CODE div_even_odd.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L5
  STORE_FAST el
  LOAD_FAST el
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST el
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L5:
  END_FOR
  RETURN_CONST None
L6:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L3 -> handler=L6 depth=0 lasti=True
  EXC try=L4..L6 -> handler=L6 depth=0 lasti=True
END
CODE div_even_odd.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L5
  STORE_FAST el
  LOAD_FAST el
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST el
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L5:
  END_FOR
  RETURN_CONST None
L6:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L3 -> handler=L6 depth=0 lasti=True
  EXC try=L4..L6 -> handler=L6 depth=0 lasti=True
END

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

Prompt: Write a function to find the division of first even and odd number of a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME heapq
  STORE_NAME heapq
  LOAD_CONST 0
  LOAD_CONST ('Counter',)
  IMPORT_NAME collections
  IMPORT_FROM Counter
  STORE_NAME Counter
  POP_TOP
  LOAD_CONST <code rearange_string>
  MAKE_FUNCTION 0
  STORE_NAME rearange_string
  RETURN_CONST None
END
CODE rearange_string(S)
  RESUME 0
  LOAD_GLOBAL NULL + Counter
  LOAD_FAST S
  CALL 1
  STORE_FAST ctr
  LOAD_FAST ctr
  LOAD_ATTR NULL|self + items
  CALL 0
  GET_ITER
  LOAD_FAST_AND_CLEAR key
  LOAD_FAST_AND_CLEAR value
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST key
  STORE_FAST value
  LOAD_FAST value
  UNARY_NEGATIVE
  LOAD_FAST key
  BUILD_TUPLE 2
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST heap
  STORE_FAST key
  STORE_FAST value
  LOAD_GLOBAL NULL + heapq
  LOAD_ATTR heapify
  LOAD_FAST heap
  CALL 1
  POP_TOP
  LOAD_FAST heap
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_CONST 0
  BINARY_SUBSCR
  UNARY_NEGATIVE
  LOAD_CONST 2
  BINARY_OP *
  LOAD_GLOBAL NULL + len
  LOAD_FAST S
  CALL 1
  LOAD_CONST 1
  BINARY_OP +
  COMPARE_OP >
  POP_JUMP_IF_FALSE L5
  RETURN_CONST ''
L5:
  BUILD_LIST 0
  STORE_FAST ans
  LOAD_GLOBAL NULL + len
  LOAD_FAST heap
  CALL 1
  LOAD_CONST 2
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L9
L6:
  LOAD_GLOBAL NULL + heapq
  LOAD_ATTR heappop
  LOAD_FAST heap
  CALL 1
  UNPACK_SEQUENCE 2
  STORE_FAST nct1
  STORE_FAST char1
  LOAD_GLOBAL NULL + heapq
  LOAD_ATTR heappop
  LOAD_FAST heap
  CALL 1
  UNPACK_SEQUENCE 2
  STORE_FAST nct2
  STORE_FAST char2
  LOAD_FAST ans
  LOAD_ATTR NULL|self + extend
  LOAD_FAST char1
  LOAD_FAST char2
  BUILD_LIST 2
  CALL 1
  POP_TOP
  LOAD_FAST nct1
  LOAD_CONST 1
  BINARY_OP +
  POP_JUMP_IF_FALSE L7
  LOAD_GLOBAL NULL + heapq
  LOAD_ATTR heappush
  LOAD_FAST heap
  LOAD_FAST nct1
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST char1
  BUILD_TUPLE 2
  CALL 2
  POP_TOP
L7:
  LOAD_FAST nct2
  LOAD_CONST 1
  BINARY_OP +
  POP_JUMP_IF_FALSE L8
  LOAD_GLOBAL NULL + heapq
  LOAD_ATTR heappush
  LOAD_FAST heap
  LOAD_FAST nct2
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST char2
  BUILD_TUPLE 2
  CALL 2
  POP_TOP
L8:
  LOAD_GLOBAL NULL + len
  LOAD_FAST heap
  CALL 1
  LOAD_CONST 2
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L9
  JUMP_BACKWARD L6
L9:
  LOAD_CONST ''
  LOAD_ATTR NULL|self + join
  LOAD_FAST ans
  CALL 1
  LOAD_FAST heap
  POP_JUMP_IF_FALSE L10
  LOAD_FAST heap
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_SUBSCR
  BINARY_OP +
  RETURN_VALUE
L10:
  LOAD_CONST ''
  BINARY_OP +
  RETURN_VALUE
L11:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST value
  STORE_FAST key
  RERAISE 0
  EXC try=L1..L4 -> handler=L11 depth=3 lasti=False
END

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)
        nct2, char2 = heapq.heappop(heap)
        ans.extend([char1, char2])
        if nct1 + 1:
            heapq.heappush(heap, (nct1 + 1, char1))
        if nct2 + 1:
            heapq.heappush(heap, (nct2 + 1, char2))
    return ''.join(ans) + (heap[0][1] if heap else '')

Prompt: 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.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('Counter',)
  IMPORT_NAME collections
  IMPORT_FROM Counter
  STORE_NAME Counter
  POP_TOP
  LOAD_CONST 0
  LOAD_CONST ('chain',)
  IMPORT_NAME itertools
  IMPORT_FROM chain
  STORE_NAME chain
  POP_TOP
  LOAD_CONST <code freq_element>
  MAKE_FUNCTION 0
  STORE_NAME freq_element
  RETURN_CONST None
END
CODE freq_element(nums)
  RESUME 0
  LOAD_GLOBAL NULL + Counter
  LOAD_GLOBAL NULL + chain
  LOAD_ATTR from_iterable
  LOAD_FAST nums
  CALL 1
  CALL 1
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END

from collections import Counter
from itertools import chain

def freq_element(nums):
    result = Counter(chain.from_iterable(nums))
    return result

Prompt: Write a function to find frequency of the elements in a given list of lists using collections module.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code filter_evennumbers>
  MAKE_FUNCTION 0
  STORE_NAME filter_evennumbers
  RETURN_CONST None
END
CODE filter_evennumbers(nums)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + filter
  LOAD_CONST <code filter_evennumbers.<locals>.<lambda>>
  MAKE_FUNCTION 0
  LOAD_FAST nums
  CALL 2
  CALL 1
  STORE_FAST even_nums
  LOAD_FAST even_nums
  RETURN_VALUE
END
CODE filter_evennumbers.<locals>.<lambda>(x)
  RESUME 0
  LOAD_FAST x
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  RETURN_VALUE
END

def filter_evennumbers(nums):
    even_nums = list(filter(lambda x: x % 2 == 0, nums))
    return even_nums

Prompt: Write a function to filter even numbers using lambda function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_Sum>
  MAKE_FUNCTION 0
  STORE_NAME find_Sum
  RETURN_CONST None
END
CODE find_Sum(arr, n)
  RESUME 0
  LOAD_GLOBAL NULL + sum
  LOAD_FAST arr
  GET_ITER
  LOAD_FAST_AND_CLEAR x
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  STORE_FAST x
  LOAD_FAST arr
  LOAD_ATTR NULL|self + count
  LOAD_FAST x
  CALL 1
  LOAD_CONST 1
  COMPARE_OP >
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST x
  LIST_APPEND 2
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  SWAP 2
  STORE_FAST x
  CALL 1
  RETURN_VALUE
L7:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST x
  RERAISE 0
  EXC try=L1..L3 -> handler=L7 depth=4 lasti=False
  EXC try=L4..L6 -> handler=L7 depth=4 lasti=False
END

def find_Sum(arr, n):
    return sum([x for x in arr if arr.count(x) > 1])

Prompt: Write a python function to find the sum of repeated elements in a given array.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code text_match_string>
  MAKE_FUNCTION 0
  STORE_NAME text_match_string
  RETURN_CONST None
END
CODE text_match_string(text)
  RESUME 0
  LOAD_CONST '^\\w+'
  STORE_FAST patterns
  LOAD_GLOBAL NULL + re
  LOAD_ATTR search
  LOAD_FAST patterns
  LOAD_FAST text
  CALL 2
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'Found a match!'
L1:
  RETURN_CONST 'Not matched!'
END

import re

def text_match_string(text):
    patterns = '^\\w+'
    if re.search(patterns, text):
        return 'Found a match!'
    else:
        return 'Not matched!'

Prompt: Write a function that matches a word at the beginning of a string.

assert text_match_string(" python")==('Not matched!')

assert text_match_string("python")==('Found a match!')

assert text_match_string("  lang")==('Not matched!')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_gcd>
  MAKE_FUNCTION 0
  STORE_NAME find_gcd
  LOAD_CONST <code get_gcd>
  MAKE_FUNCTION 0
  STORE_NAME get_gcd
  RETURN_CONST None
END
CODE find_gcd(x, y)
  RESUME 0
  LOAD_FAST y
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST y
  LOAD_FAST x
  LOAD_FAST y
  BINARY_OP %
  STORE_FAST y
  STORE_FAST x
  LOAD_FAST y
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST x
  RETURN_VALUE
END
CODE get_gcd(l)
  RESUME 0
  LOAD_FAST l
  LOAD_CONST 0
  BINARY_SUBSCR
  STORE_FAST num1
  LOAD_FAST l
  LOAD_CONST 1
  BINARY_SUBSCR
  STORE_FAST num2
  LOAD_GLOBAL NULL + find_gcd
  LOAD_FAST num1
  LOAD_FAST num2
  CALL 2
  STORE_FAST gcd
  LOAD_GLOBAL NULL + range
  LOAD_CONST 2
  LOAD_GLOBAL NULL + len
  LOAD_FAST l
  CALL 1
  CALL 2
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_GLOBAL NULL + find_gcd
  LOAD_FAST gcd
  LOAD_FAST l
  LOAD_FAST i
  BINARY_SUBSCR
  CALL 2
  STORE_FAST gcd
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST gcd
  RETURN_VALUE
END

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

Prompt: Write a function to find the gcd of the given array elements.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code test_distinct>
  MAKE_FUNCTION 0
  STORE_NAME test_distinct
  RETURN_CONST None
END
CODE test_distinct(data)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST data
  CALL 1
  LOAD_GLOBAL NULL + len
  LOAD_GLOBAL NULL + set
  LOAD_FAST data
  CALL 1
  CALL 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST True
L1:
  RETURN_CONST False
END

def test_distinct(data):
    if len(data) == len(set(data)):
        return True
    else:
        return False

Prompt: Write a python function to determine whether all the numbers are different from each other are not.

assert test_distinct([2,4,5,5,7,9]) == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code odd_bit_set_number>
  MAKE_FUNCTION 0
  STORE_NAME odd_bit_set_number
  RETURN_CONST None
END
CODE odd_bit_set_number(n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST count
  LOAD_CONST 0
  STORE_FAST res
  LOAD_FAST n
  STORE_FAST temp
  LOAD_FAST temp
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L3
L1:
  LOAD_FAST count
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST res
  LOAD_CONST 1
  LOAD_FAST count
  BINARY_OP <<
  BINARY_OP |=
  STORE_FAST res
L2:
  LOAD_FAST count
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST count
  LOAD_FAST temp
  LOAD_CONST 1
  BINARY_OP >>=
  STORE_FAST temp
  LOAD_FAST temp
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L3
  JUMP_BACKWARD L1
L3:
  LOAD_FAST n
  LOAD_FAST res
  BINARY_OP |
  RETURN_VALUE
END

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

Prompt: Write a python function to set all odd bits of a given number.

assert odd_bit_set_number(10) == 15
assert odd_bit_set_number(20) == 21
assert odd_bit_set_number(30) == 31


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code min_length_list>
  MAKE_FUNCTION 0
  STORE_NAME min_length_list
  RETURN_CONST None
END
CODE min_length_list(input_list)
  RESUME 0
  LOAD_GLOBAL NULL + min
  LOAD_CONST <code min_length_list.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_FAST input_list
  GET_ITER
  CALL 0
  CALL 1
  STORE_FAST min_length
  LOAD_GLOBAL NULL + min
  LOAD_FAST input_list
  LOAD_CONST <code min_length_list.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  STORE_FAST min_list
  LOAD_FAST min_length
  LOAD_FAST min_list
  BUILD_TUPLE 2
  RETURN_VALUE
END
CODE min_length_list.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST x
  LOAD_GLOBAL NULL + len
  LOAD_FAST x
  CALL 1
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END
CODE min_length_list.<locals>.<lambda>(i)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST i
  CALL 1
  RETURN_VALUE
END

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)

Prompt: Write a function to find the list with minimum length using lambda function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_equilateral>
  MAKE_FUNCTION 0
  STORE_NAME check_equilateral
  RETURN_CONST None
END
CODE check_equilateral(x, y, z)
  RESUME 0
  LOAD_FAST x
  LOAD_FAST y
  SWAP 2
  COPY 2
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_FAST z
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  RETURN_CONST True
L1:
  POP_TOP
  RETURN_CONST False
L2:
  RETURN_CONST False
END

def check_equilateral(x, y, z):
    if x == y == z:
        return True
    else:
        return False

Prompt: Write a function to print check if the triangle is equilateral or not.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_Equality>
  MAKE_FUNCTION 0
  STORE_NAME check_Equality
  RETURN_CONST None
END
CODE check_Equality(str)
  RESUME 0
  LOAD_FAST str
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST str
  LOAD_CONST -1
  BINARY_SUBSCR
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'Equal'
L1:
  RETURN_CONST 'Not Equal'
END

def check_Equality(str):
    if str[0] == str[-1]:
        return 'Equal'
    else:
        return 'Not Equal'

Prompt: Write a python function to check whether the first and last characters of a given string are equal or not.

assert check_Equality("abcda") == "Equal"

assert check_Equality("ab") == "Not Equal"

assert check_Equality("mad") == "Not Equal"


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code counting_sort>
  MAKE_FUNCTION 0
  STORE_NAME counting_sort
  RETURN_CONST None
END
CODE counting_sort(my_list)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST max_value
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST my_list
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST my_list
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST max_value
  COMPARE_OP >
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST my_list
  LOAD_FAST i
  BINARY_SUBSCR
  STORE_FAST max_value
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_CONST 0
  BUILD_LIST 1
  LOAD_FAST max_value
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP *
  STORE_FAST buckets
  LOAD_FAST my_list
  GET_ITER
L4:
  FOR_ITER L5
  STORE_FAST i
  LOAD_FAST buckets
  LOAD_FAST i
  COPY 2
  COPY 2
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +=
  SWAP 3
  SWAP 2
  STORE_SUBSCR
  JUMP_BACKWARD L4
L5:
  END_FOR
  LOAD_CONST 0
  STORE_FAST i
  LOAD_GLOBAL NULL + range
  LOAD_FAST max_value
  LOAD_CONST 1
  BINARY_OP +
  CALL 1
  GET_ITER
L6:
  FOR_ITER L9
  STORE_FAST j
  LOAD_GLOBAL NULL + range
  LOAD_FAST buckets
  LOAD_FAST j
  BINARY_SUBSCR
  CALL 1
  GET_ITER
L7:
  FOR_ITER L8
  STORE_FAST a
  LOAD_FAST j
  LOAD_FAST my_list
  LOAD_FAST i
  STORE_SUBSCR
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST i
  JUMP_BACKWARD L7
L8:
  END_FOR
  JUMP_BACKWARD L6
L9:
  END_FOR
  LOAD_FAST my_list
  RETURN_VALUE
END

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]):
            my_list[i] = j
            i += 1
    return my_list

Prompt: Write a function to sort the given array by using counting sort.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code rev>
  MAKE_FUNCTION 0
  STORE_NAME rev
  LOAD_CONST <code check>
  MAKE_FUNCTION 0
  STORE_NAME check
  RETURN_CONST None
END
CODE rev(num)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST rev_num
  LOAD_FAST num
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST rev_num
  LOAD_CONST 10
  BINARY_OP *
  LOAD_FAST num
  LOAD_CONST 10
  BINARY_OP %
  BINARY_OP +
  STORE_FAST rev_num
  LOAD_FAST num
  LOAD_CONST 10
  BINARY_OP //
  STORE_FAST num
  LOAD_FAST num
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST rev_num
  RETURN_VALUE
END
CODE check(n)
  RESUME 0
  LOAD_CONST 2
  LOAD_GLOBAL NULL + rev
  LOAD_FAST n
  CALL 1
  BINARY_OP *
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  COMPARE_OP ==
  RETURN_VALUE
END

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

Prompt: Write a python function to check if a given number is one less than twice its reverse.

assert check(70) == False
assert check(23) == False
assert check(73) == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_octagonal>
  MAKE_FUNCTION 0
  STORE_NAME is_octagonal
  RETURN_CONST None
END
CODE is_octagonal(n)
  RESUME 0
  LOAD_CONST 3
  LOAD_FAST n
  BINARY_OP *
  LOAD_FAST n
  BINARY_OP *
  LOAD_CONST 2
  LOAD_FAST n
  BINARY_OP *
  BINARY_OP -
  RETURN_VALUE
END

def is_octagonal(n):
    return 3 * n * n - 2 * n

Prompt: Write a function to find the nth octagonal number.

assert is_octagonal(5) == 65
assert is_octagonal(10) == 280
assert is_octagonal(15) == 645


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code max_len_sub>
  MAKE_FUNCTION 0
  STORE_NAME max_len_sub
  RETURN_CONST None
END
CODE max_len_sub(arr, n)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST mls
  LOAD_CONST 0
  STORE_FAST max
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST mls
  LOAD_ATTR NULL|self + append
  LOAD_CONST 1
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L3:
  FOR_ITER L8
  STORE_FAST i
  LOAD_GLOBAL NULL + range
  LOAD_FAST i
  CALL 1
  GET_ITER
L4:
  FOR_ITER L7
  STORE_FAST j
  LOAD_GLOBAL NULL + abs
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST j
  BINARY_SUBSCR
  BINARY_OP -
  CALL 1
  LOAD_CONST 1
  COMPARE_OP <=
  POP_JUMP_IF_TRUE L5
  JUMP_BACKWARD L4
L5:
  LOAD_FAST mls
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST mls
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +
  COMPARE_OP <
  POP_JUMP_IF_TRUE L6
  JUMP_BACKWARD L4
L6:
  LOAD_FAST mls
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST mls
  LOAD_FAST i
  STORE_SUBSCR
  JUMP_BACKWARD L4
L7:
  END_FOR
  JUMP_BACKWARD L3
L8:
  END_FOR
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L9:
  FOR_ITER L11
  STORE_FAST i
  LOAD_FAST max
  LOAD_FAST mls
  LOAD_FAST i
  BINARY_SUBSCR
  COMPARE_OP <
  POP_JUMP_IF_TRUE L10
  JUMP_BACKWARD L9
L10:
  LOAD_FAST mls
  LOAD_FAST i
  BINARY_SUBSCR
  STORE_FAST max
  JUMP_BACKWARD L9
L11:
  END_FOR
  LOAD_FAST max
  RETURN_VALUE
END

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

Prompt: Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('defaultdict',)
  IMPORT_NAME collections
  IMPORT_FROM defaultdict
  STORE_NAME defaultdict
  POP_TOP
  LOAD_CONST <code count_Substrings>
  MAKE_FUNCTION 0
  STORE_NAME count_Substrings
  RETURN_CONST None
END
CODE count_Substrings(s, n)
  RESUME 0
  LOAD_CONST (0, 0)
  UNPACK_SEQUENCE 2
  STORE_FAST count
  STORE_FAST sum
  LOAD_GLOBAL NULL + defaultdict
  LOAD_CONST <code count_Substrings.<locals>.<lambda>>
  MAKE_FUNCTION 0
  CALL 1
  STORE_FAST mp
  LOAD_FAST mp
  LOAD_CONST 0
  COPY 2
  COPY 2
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +=
  SWAP 3
  SWAP 2
  STORE_SUBSCR
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST sum
  LOAD_GLOBAL NULL + ord
  LOAD_FAST s
  LOAD_FAST i
  BINARY_SUBSCR
  CALL 1
  LOAD_GLOBAL NULL + ord
  LOAD_CONST '0'
  CALL 1
  BINARY_OP -
  BINARY_OP +=
  STORE_FAST sum
  LOAD_FAST count
  LOAD_FAST mp
  LOAD_FAST sum
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP -
  BINARY_SUBSCR
  BINARY_OP +=
  STORE_FAST count
  LOAD_FAST mp
  LOAD_FAST sum
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP -
  COPY 2
  COPY 2
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +=
  SWAP 3
  SWAP 2
  STORE_SUBSCR
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST count
  RETURN_VALUE
END
CODE count_Substrings.<locals>.<lambda>()
  RESUME 0
  RETURN_CONST 0
END

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

Prompt: Write a python function to count number of substrings with the sum of digits equal to their length.

assert count_Substrings('112112',6) == 6

assert count_Substrings('1101112',7) == 12


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code recursive_list_sum>
  MAKE_FUNCTION 0
  STORE_NAME recursive_list_sum
  RETURN_CONST None
END
CODE recursive_list_sum(data_list)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST total
  LOAD_FAST data_list
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST element
  LOAD_GLOBAL NULL + type
  LOAD_FAST element
  CALL 1
  LOAD_GLOBAL NULL + type
  BUILD_LIST 0
  CALL 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST total
  LOAD_GLOBAL NULL + recursive_list_sum
  LOAD_FAST element
  CALL 1
  BINARY_OP +
  STORE_FAST total
  JUMP_BACKWARD L1
L2:
  LOAD_FAST total
  LOAD_FAST element
  BINARY_OP +
  STORE_FAST total
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST total
  RETURN_VALUE
END

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

Prompt: Write a function of recursion list sum.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code pos_count>
  MAKE_FUNCTION 0
  STORE_NAME pos_count
  RETURN_CONST None
END
CODE pos_count(list)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST pos_count
  LOAD_FAST list
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST num
  LOAD_FAST num
  LOAD_CONST 0
  COMPARE_OP >=
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST pos_count
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST pos_count
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST pos_count
  RETURN_VALUE
END

def pos_count(list):
    pos_count = 0
    for num in list:
        if num >= 0:
            pos_count += 1
    return pos_count

Prompt: Write a python function to count positive numbers in a list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_Monotonic>
  MAKE_FUNCTION 0
  STORE_NAME is_Monotonic
  RETURN_CONST None
END
CODE is_Monotonic(A)
  MAKE_CELL A
  RESUME 0
  LOAD_GLOBAL NULL + all
  LOAD_CLOSURE A
  BUILD_TUPLE 1
  LOAD_CONST <code is_Monotonic.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_DEREF A
  CALL 1
  LOAD_CONST 1
  BINARY_OP -
  CALL 1
  GET_ITER
  CALL 0
  CALL 1
  COPY 1
  POP_JUMP_IF_TRUE L1
  POP_TOP
  LOAD_GLOBAL NULL + all
  LOAD_CLOSURE A
  BUILD_TUPLE 1
  LOAD_CONST <code is_Monotonic.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_DEREF A
  CALL 1
  LOAD_CONST 1
  BINARY_OP -
  CALL 1
  GET_ITER
  CALL 0
  CALL 1
L1:
  RETURN_VALUE
END
CODE is_Monotonic.<locals>.<genexpr>(.0)
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_DEREF A
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_DEREF A
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SUBSCR
  COMPARE_OP <=
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END
CODE is_Monotonic.<locals>.<genexpr>(.0)
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_DEREF A
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_DEREF A
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SUBSCR
  COMPARE_OP >=
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

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)))

Prompt: Write a python function to check whether the given array is monotonic or not.

assert is_Monotonic([6, 5, 4, 4]) == True

assert is_Monotonic([1, 2, 2, 3]) == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_sublist>
  MAKE_FUNCTION 0
  STORE_NAME is_sublist
  RETURN_CONST None
END
CODE is_sublist(l, s)
  RESUME 0
  LOAD_CONST False
  STORE_FAST sub_set
  LOAD_FAST s
  BUILD_LIST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_CONST True
  STORE_FAST sub_set
  LOAD_FAST sub_set
  RETURN_VALUE
L1:
  LOAD_FAST s
  LOAD_FAST l
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_CONST True
  STORE_FAST sub_set
  LOAD_FAST sub_set
  RETURN_VALUE
L2:
  LOAD_GLOBAL NULL + len
  LOAD_FAST s
  CALL 1
  LOAD_GLOBAL NULL + len
  LOAD_FAST l
  CALL 1
  COMPARE_OP >
  POP_JUMP_IF_FALSE L3
  LOAD_CONST False
  STORE_FAST sub_set
  LOAD_FAST sub_set
  RETURN_VALUE
L3:
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST l
  CALL 1
  CALL 1
  GET_ITER
L4:
  FOR_ITER L9
  STORE_FAST i
  LOAD_FAST l
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST s
  LOAD_CONST 0
  BINARY_SUBSCR
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L5
  JUMP_BACKWARD L4
L5:
  LOAD_CONST 1
  STORE_FAST n
  LOAD_FAST n
  LOAD_GLOBAL NULL + len
  LOAD_FAST s
  CALL 1
  COMPARE_OP <
  POP_JUMP_IF_FALSE L7
  LOAD_FAST l
  LOAD_FAST i
  LOAD_FAST n
  BINARY_OP +
  BINARY_SUBSCR
  LOAD_FAST s
  LOAD_FAST n
  BINARY_SUBSCR
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L7
L6:
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST n
  LOAD_FAST n
  LOAD_GLOBAL NULL + len
  LOAD_FAST s
  CALL 1
  COMPARE_OP <
  POP_JUMP_IF_FALSE L7
  LOAD_FAST l
  LOAD_FAST i
  LOAD_FAST n
  BINARY_OP +
  BINARY_SUBSCR
  LOAD_FAST s
  LOAD_FAST n
  BINARY_SUBSCR
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L7
  JUMP_BACKWARD L6
L7:
  LOAD_FAST n
  LOAD_GLOBAL NULL + len
  LOAD_FAST s
  CALL 1
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L8
  JUMP_BACKWARD L4
L8:
  LOAD_CONST True
  STORE_FAST sub_set
  JUMP_BACKWARD L4
L9:
  END_FOR
  LOAD_FAST sub_set
  RETURN_VALUE
END

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
    return sub_set

Prompt: Write a function to check whether a list contains the given sublist or not.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_equal_tuple>
  MAKE_FUNCTION 0
  STORE_NAME find_equal_tuple
  LOAD_CONST <code get_equal>
  MAKE_FUNCTION 0
  STORE_NAME get_equal
  RETURN_CONST None
END
CODE find_equal_tuple(Input, k)
  RESUME 0
  LOAD_CONST 1
  STORE_FAST flag
  LOAD_FAST Input
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST tuple
  LOAD_GLOBAL NULL + len
  LOAD_FAST tuple
  CALL 1
  LOAD_FAST k
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_CONST 0
  STORE_FAST flag
  POP_TOP
  LOAD_FAST flag
  RETURN_VALUE
L3:
  END_FOR
  LOAD_FAST flag
  RETURN_VALUE
END
CODE get_equal(Input, k)
  RESUME 0
  LOAD_GLOBAL NULL + find_equal_tuple
  LOAD_FAST Input
  LOAD_FAST k
  CALL 2
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'All tuples have same length'
L1:
  RETURN_CONST 'All tuples do not have same length'
END

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'

Prompt: Write a function to find whether all the given tuples have equal length or not.

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'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code comb_sort>
  MAKE_FUNCTION 0
  STORE_NAME comb_sort
  RETURN_CONST None
END
CODE comb_sort(nums)
  RESUME 0
  LOAD_CONST 1.3
  STORE_FAST shrink_fact
  LOAD_GLOBAL NULL + len
  LOAD_FAST nums
  CALL 1
  STORE_FAST gaps
  LOAD_CONST True
  STORE_FAST swapped
  LOAD_CONST 0
  STORE_FAST i
  LOAD_FAST gaps
  LOAD_CONST 1
  COMPARE_OP >
  POP_JUMP_IF_TRUE L1
  LOAD_FAST swapped
  POP_JUMP_IF_FALSE L6
L1:
  LOAD_GLOBAL NULL + int
  LOAD_GLOBAL NULL + float
  LOAD_FAST gaps
  CALL 1
  LOAD_FAST shrink_fact
  BINARY_OP /
  CALL 1
  STORE_FAST gaps
  LOAD_CONST False
  STORE_FAST swapped
  LOAD_CONST 0
  STORE_FAST i
  LOAD_FAST gaps
  LOAD_FAST i
  BINARY_OP +
  LOAD_GLOBAL NULL + len
  LOAD_FAST nums
  CALL 1
  COMPARE_OP <
  POP_JUMP_IF_FALSE L4
L2:
  LOAD_FAST nums
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST nums
  LOAD_FAST i
  LOAD_FAST gaps
  BINARY_OP +
  BINARY_SUBSCR
  COMPARE_OP >
  POP_JUMP_IF_FALSE L3
  LOAD_FAST nums
  LOAD_FAST i
  LOAD_FAST gaps
  BINARY_OP +
  BINARY_SUBSCR
  LOAD_FAST nums
  LOAD_FAST i
  BINARY_SUBSCR
  SWAP 2
  LOAD_FAST nums
  LOAD_FAST i
  STORE_SUBSCR
  LOAD_FAST nums
  LOAD_FAST i
  LOAD_FAST gaps
  BINARY_OP +
  STORE_SUBSCR
  LOAD_CONST True
  STORE_FAST swapped
L3:
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST i
  LOAD_FAST gaps
  LOAD_FAST i
  BINARY_OP +
  LOAD_GLOBAL NULL + len
  LOAD_FAST nums
  CALL 1
  COMPARE_OP <
  POP_JUMP_IF_FALSE L4
  JUMP_BACKWARD L2
L4:
  LOAD_FAST gaps
  LOAD_CONST 1
  COMPARE_OP >
  POP_JUMP_IF_FALSE L5
  JUMP_BACKWARD L1
L5:
  LOAD_FAST swapped
  POP_JUMP_IF_FALSE L6
  JUMP_BACKWARD L1
L6:
  LOAD_FAST nums
  RETURN_VALUE
END

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], nums[i + gaps] = (nums[i + gaps], nums[i])
                swapped = True
            i += 1
    return nums

Prompt: Write a function to sort a list of elements using comb sort.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code dif_Square>
  MAKE_FUNCTION 0
  STORE_NAME dif_Square
  RETURN_CONST None
END
CODE dif_Square(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 4
  BINARY_OP %
  LOAD_CONST 2
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L1
  RETURN_CONST True
L1:
  RETURN_CONST False
END

def dif_Square(n):
    if n % 4 != 2:
        return True
    return False

Prompt: Write a python function to check whether the given number can be represented as difference of two squares or not.

assert dif_Square(5) == True
assert dif_Square(10) == False
assert dif_Square(15) == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_samepatterns>
  MAKE_FUNCTION 0
  STORE_NAME is_samepatterns
  RETURN_CONST None
END
CODE is_samepatterns(colors, patterns)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST colors
  CALL 1
  LOAD_GLOBAL NULL + len
  LOAD_FAST patterns
  CALL 1
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L1
  RETURN_CONST False
L1:
  BUILD_MAP 0
  STORE_FAST sdict
  LOAD_GLOBAL NULL + set
  CALL 0
  STORE_FAST pset
  LOAD_GLOBAL NULL + set
  CALL 0
  STORE_FAST sset
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST patterns
  CALL 1
  CALL 1
  GET_ITER
L2:
  FOR_ITER L4
  STORE_FAST i
  LOAD_FAST pset
  LOAD_ATTR NULL|self + add
  LOAD_FAST patterns
  LOAD_FAST i
  BINARY_SUBSCR
  CALL 1
  POP_TOP
  LOAD_FAST sset
  LOAD_ATTR NULL|self + add
  LOAD_FAST colors
  LOAD_FAST i
  BINARY_SUBSCR
  CALL 1
  POP_TOP
  LOAD_FAST patterns
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST sdict
  LOAD_ATTR NULL|self + keys
  CALL 0
  CONTAINS_OP 1
  POP_JUMP_IF_FALSE L3
  BUILD_LIST 0
  LOAD_FAST sdict
  LOAD_FAST patterns
  LOAD_FAST i
  BINARY_SUBSCR
  STORE_SUBSCR
L3:
  LOAD_FAST sdict
  LOAD_FAST patterns
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_SUBSCR
  STORE_FAST keys
  LOAD_FAST keys
  LOAD_ATTR NULL|self + append
  LOAD_FAST colors
  LOAD_FAST i
  BINARY_SUBSCR
  CALL 1
  POP_TOP
  LOAD_FAST keys
  LOAD_FAST sdict
  LOAD_FAST patterns
  LOAD_FAST i
  BINARY_SUBSCR
  STORE_SUBSCR
  JUMP_BACKWARD L2
L4:
  END_FOR
  LOAD_GLOBAL NULL + len
  LOAD_FAST pset
  CALL 1
  LOAD_GLOBAL NULL + len
  LOAD_FAST sset
  CALL 1
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L5
  RETURN_CONST False
L5:
  LOAD_FAST sdict
  LOAD_ATTR NULL|self + values
  CALL 0
  GET_ITER
L6:
  FOR_ITER L10
  STORE_FAST values
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST values
  CALL 1
  LOAD_CONST 1
  BINARY_OP -
  CALL 1
  GET_ITER
L7:
  FOR_ITER L9
  STORE_FAST i
  LOAD_FAST values
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST values
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SUBSCR
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L8
  JUMP_BACKWARD L7
L8:
  POP_TOP
  POP_TOP
  RETURN_CONST False
L9:
  END_FOR
  JUMP_BACKWARD L6
L10:
  END_FOR
  RETURN_CONST True
END

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():
            sdict[patterns[i]] = []
        keys = sdict[patterns[i]]
        keys.append(colors[i])
        sdict[patterns[i]] = keys
    if len(pset) != len(sset):
        return False
    for values in sdict.values():
        for i in range(len(values) - 1):
            if values[i] != values[i + 1]:
                return False
    return True

Prompt: Write a function to check whether it follows the sequence given in the patterns array.

assert is_samepatterns(["red","green","green"], ["a", "b", "b"])==True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_tuples>
  MAKE_FUNCTION 0
  STORE_NAME find_tuples
  RETURN_CONST None
END
CODE find_tuples(test_list, K)
  MAKE_CELL K
  RESUME 0
  LOAD_FAST test_list
  GET_ITER
  LOAD_FAST_AND_CLEAR sub
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  STORE_FAST sub
  LOAD_GLOBAL NULL + all
  LOAD_CLOSURE K
  BUILD_TUPLE 1
  LOAD_CONST <code find_tuples.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_FAST sub
  GET_ITER
  CALL 0
  CALL 1
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST sub
  LIST_APPEND 2
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  STORE_FAST res
  STORE_FAST sub
  LOAD_GLOBAL NULL + str
  LOAD_FAST res
  CALL 1
  RETURN_VALUE
L7:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST sub
  RERAISE 0
  EXC try=L1..L3 -> handler=L7 depth=2 lasti=False
  EXC try=L4..L6 -> handler=L7 depth=2 lasti=False
END
CODE find_tuples.<locals>.<genexpr>(.0)
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST ele
  LOAD_FAST ele
  LOAD_DEREF K
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

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)

Prompt: Write a function to find tuples which have all elements divisible by k from the given list of tuples.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_Squares>
  MAKE_FUNCTION 0
  STORE_NAME count_Squares
  RETURN_CONST None
END
CODE count_Squares(m, n)
  RESUME 0
  LOAD_FAST n
  LOAD_FAST m
  COMPARE_OP <
  POP_JUMP_IF_FALSE L1
  LOAD_FAST m
  STORE_FAST temp
  LOAD_FAST n
  STORE_FAST m
  LOAD_FAST temp
  STORE_FAST n
L1:
  LOAD_FAST m
  LOAD_FAST m
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP *
  LOAD_CONST 2
  LOAD_FAST m
  BINARY_OP *
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP *
  LOAD_CONST 6
  BINARY_OP /
  LOAD_FAST n
  LOAD_FAST m
  BINARY_OP -
  LOAD_FAST m
  BINARY_OP *
  LOAD_FAST m
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP *
  LOAD_CONST 2
  BINARY_OP /
  BINARY_OP +
  RETURN_VALUE
END

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

Prompt: Write a python function to count the number of squares in a rectangle.

assert count_Squares(4,3) == 20
assert count_Squares(2,2) == 5
assert count_Squares(1,1) == 1


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_With_Odd_SetBits>
  MAKE_FUNCTION 0
  STORE_NAME count_With_Odd_SetBits
  RETURN_CONST None
END
CODE count_With_Odd_SetBits(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L1
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  LOAD_CONST 2
  BINARY_OP /
  RETURN_VALUE
L1:
  LOAD_GLOBAL NULL + bin
  LOAD_FAST n
  CALL 1
  LOAD_ATTR NULL|self + count
  LOAD_CONST '1'
  CALL 1
  STORE_FAST count
  LOAD_FAST n
  LOAD_CONST 2
  BINARY_OP /
  STORE_FAST ans
  LOAD_FAST count
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L2
  LOAD_FAST ans
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST ans
L2:
  LOAD_FAST ans
  RETURN_VALUE
END

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

Prompt: Write a python function to find number of integers with odd number of set bits.

assert count_With_Odd_SetBits(5) == 3
assert count_With_Odd_SetBits(10) == 5
assert count_With_Odd_SetBits(15) == 8


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code word_len>
  MAKE_FUNCTION 0
  STORE_NAME word_len
  RETURN_CONST None
END
CODE word_len(s)
  RESUME 0
  LOAD_FAST s
  LOAD_ATTR NULL|self + split
  LOAD_CONST ' '
  CALL 1
  STORE_FAST s
  LOAD_FAST s
  GET_ITER
  FOR_ITER L2
  STORE_FAST word
  LOAD_GLOBAL NULL + len
  LOAD_FAST word
  CALL 1
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L1
  POP_TOP
  RETURN_CONST True
L1:
  POP_TOP
  RETURN_CONST False
L2:
  END_FOR
  RETURN_CONST None
END

def word_len(s):
    s = s.split(' ')
    for word in s:
        if len(word) % 2 != 0:
            return True
        else:
            return False

Prompt: Write a python function to check whether the length of the word is odd or not.

assert word_len("Hadoop") == False
assert word_len("great") == True
assert word_len("structure") == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code tetrahedral_number>
  MAKE_FUNCTION 0
  STORE_NAME tetrahedral_number
  RETURN_CONST None
END
CODE tetrahedral_number(n)
  RESUME 0
  LOAD_FAST n
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP *
  LOAD_FAST n
  LOAD_CONST 2
  BINARY_OP +
  BINARY_OP *
  LOAD_CONST 6
  BINARY_OP /
  RETURN_VALUE
END

def tetrahedral_number(n):
    return n * (n + 1) * (n + 2) / 6

Prompt: Write a function to find the nth tetrahedral number.

assert tetrahedral_number(5) == 35.0
assert tetrahedral_number(6) == 56.0
assert tetrahedral_number(7) == 84.0


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code zip_tuples>
  MAKE_FUNCTION 0
  STORE_NAME zip_tuples
  RETURN_CONST None
END
CODE zip_tuples(test_tup1, test_tup2)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST res
  LOAD_GLOBAL NULL + enumerate
  LOAD_FAST test_tup1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L2
  UNPACK_SEQUENCE 2
  STORE_FAST i
  STORE_FAST j
  LOAD_FAST res
  LOAD_ATTR NULL|self + append
  LOAD_FAST j
  LOAD_FAST test_tup2
  LOAD_FAST i
  LOAD_GLOBAL NULL + len
  LOAD_FAST test_tup2
  CALL 1
  BINARY_OP %
  BINARY_SUBSCR
  BUILD_TUPLE 2
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST res
  RETURN_VALUE
END

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

Prompt: Write a function to zip the two given tuples.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code volume_sphere>
  MAKE_FUNCTION 0
  STORE_NAME volume_sphere
  RETURN_CONST None
END
CODE volume_sphere(r)
  RESUME 0
  LOAD_CONST 1.3333333333333333
  LOAD_GLOBAL math
  LOAD_ATTR pi
  BINARY_OP *
  LOAD_FAST r
  BINARY_OP *
  LOAD_FAST r
  BINARY_OP *
  LOAD_FAST r
  BINARY_OP *
  STORE_FAST volume
  LOAD_FAST volume
  RETURN_VALUE
END

import math

def volume_sphere(r):
    volume = 4 / 3 * math.pi * r * r * r
    return volume

Prompt: Write a function to find the volume of a sphere.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_Char>
  MAKE_FUNCTION 0
  STORE_NAME get_Char
  RETURN_CONST None
END
CODE get_Char(strr)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST summ
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST strr
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST summ
  LOAD_GLOBAL NULL + ord
  LOAD_FAST strr
  LOAD_FAST i
  BINARY_SUBSCR
  CALL 1
  LOAD_GLOBAL NULL + ord
  LOAD_CONST 'a'
  CALL 1
  BINARY_OP -
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST summ
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST summ
  LOAD_CONST 26
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_GLOBAL NULL + ord
  LOAD_CONST 'z'
  CALL 1
  RETURN_VALUE
L3:
  LOAD_FAST summ
  LOAD_CONST 26
  BINARY_OP %
  STORE_FAST summ
  LOAD_GLOBAL NULL + chr
  LOAD_GLOBAL NULL + ord
  LOAD_CONST 'a'
  CALL 1
  LOAD_FAST summ
  BINARY_OP +
  LOAD_CONST 1
  BINARY_OP -
  CALL 1
  RETURN_VALUE
END

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)

Prompt: Write a python function to find the character made by adding all the characters of the given string.

assert get_Char("abc") == "f"
assert get_Char("gfg") == "t"
assert get_Char("ab") == "c"


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sequence>
  MAKE_FUNCTION 0
  STORE_NAME sequence
  RETURN_CONST None
END
CODE sequence(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L1
  LOAD_FAST n
  LOAD_CONST 2
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
L1:
  RETURN_CONST 1
L2:
  LOAD_GLOBAL NULL + sequence
  LOAD_GLOBAL NULL + sequence
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  CALL 1
  CALL 1
  LOAD_GLOBAL NULL + sequence
  LOAD_FAST n
  LOAD_GLOBAL NULL + sequence
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  CALL 1
  BINARY_OP -
  CALL 1
  BINARY_OP +
  RETURN_VALUE
END

def sequence(n):
    if n == 1 or n == 2:
        return 1
    else:
        return sequence(sequence(n - 1)) + sequence(n - sequence(n - 1))

Prompt: Write a function to find the n-th number in newman conway sequence.

assert sequence(10) == 6
assert sequence(2) == 1
assert sequence(3) == 2


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code surfacearea_sphere>
  MAKE_FUNCTION 0
  STORE_NAME surfacearea_sphere
  RETURN_CONST None
END
CODE surfacearea_sphere(r)
  RESUME 0
  LOAD_CONST 4
  LOAD_GLOBAL math
  LOAD_ATTR pi
  BINARY_OP *
  LOAD_FAST r
  BINARY_OP *
  LOAD_FAST r
  BINARY_OP *
  STORE_FAST surfacearea
  LOAD_FAST surfacearea
  RETURN_VALUE
END

import math

def surfacearea_sphere(r):
    surfacearea = 4 * math.pi * r * r
    return surfacearea

Prompt: Write a function to find the surface area of a sphere.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code centered_hexagonal_number>
  MAKE_FUNCTION 0
  STORE_NAME centered_hexagonal_number
  RETURN_CONST None
END
CODE centered_hexagonal_number(n)
  RESUME 0
  LOAD_CONST 3
  LOAD_FAST n
  BINARY_OP *
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  BINARY_OP *
  LOAD_CONST 1
  BINARY_OP +
  RETURN_VALUE
END

def centered_hexagonal_number(n):
    return 3 * n * (n - 1) + 1

Prompt: Write a function to find nth centered hexagonal number.

assert centered_hexagonal_number(10) == 271

assert centered_hexagonal_number(2) == 7

assert centered_hexagonal_number(9) == 217


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME collections
  STORE_NAME collections
  LOAD_CONST <code freq_count>
  MAKE_FUNCTION 0
  STORE_NAME freq_count
  RETURN_CONST None
END
CODE freq_count(list1)
  RESUME 0
  LOAD_GLOBAL NULL + collections
  LOAD_ATTR Counter
  LOAD_FAST list1
  CALL 1
  STORE_FAST freq_count
  LOAD_FAST freq_count
  RETURN_VALUE
END

import collections

def freq_count(list1):
    freq_count = collections.Counter(list1)
    return freq_count

Prompt: Write a function to get the frequency of the elements in a list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code len_log>
  MAKE_FUNCTION 0
  STORE_NAME len_log
  RETURN_CONST None
END
CODE len_log(list1)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST list1
  LOAD_CONST 0
  BINARY_SUBSCR
  CALL 1
  STORE_FAST max
  LOAD_FAST list1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_GLOBAL NULL + len
  LOAD_FAST i
  CALL 1
  LOAD_FAST max
  COMPARE_OP >
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_GLOBAL NULL + len
  LOAD_FAST i
  CALL 1
  STORE_FAST max
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST max
  RETURN_VALUE
END

def len_log(list1):
    max = len(list1[0])
    for i in list1:
        if len(i) > max:
            max = len(i)
    return max

Prompt: Write a python function to find the length of the longest word.

assert len_log(["python","PHP","bigdata"]) == 7

assert len_log(["small","big","tall"]) == 5


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_substring>
  MAKE_FUNCTION 0
  STORE_NAME find_substring
  RETURN_CONST None
END
CODE find_substring(str1, sub_str)
  MAKE_CELL sub_str
  RESUME 0
  LOAD_GLOBAL NULL + any
  LOAD_CLOSURE sub_str
  BUILD_TUPLE 1
  LOAD_CONST <code find_substring.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_FAST str1
  GET_ITER
  CALL 0
  CALL 1
  POP_JUMP_IF_FALSE L1
  RETURN_CONST True
L1:
  RETURN_CONST False
END
CODE find_substring.<locals>.<genexpr>(.0)
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST s
  LOAD_DEREF sub_str
  LOAD_FAST s
  CONTAINS_OP 0
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

def find_substring(str1, sub_str):
    if any((sub_str in s for s in str1)):
        return True
    return False

Prompt: Write a function to check if a substring is present in a given list of string values.

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


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_undulating>
  MAKE_FUNCTION 0
  STORE_NAME is_undulating
  RETURN_CONST None
END
CODE is_undulating(n)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST n
  CALL 1
  LOAD_CONST 2
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L1
  RETURN_CONST False
L1:
  LOAD_GLOBAL NULL + range
  LOAD_CONST 2
  LOAD_GLOBAL NULL + len
  LOAD_FAST n
  CALL 1
  CALL 2
  GET_ITER
L2:
  FOR_ITER L4
  STORE_FAST i
  LOAD_FAST n
  LOAD_FAST i
  LOAD_CONST 2
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_FAST n
  LOAD_FAST i
  BINARY_SUBSCR
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L2
L3:
  POP_TOP
  RETURN_CONST False
L4:
  END_FOR
  RETURN_CONST True
END

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

Prompt: Write a function to check whether the given number is undulating or not.

assert is_undulating("1212121") == True
assert is_undulating("1991") == False
assert is_undulating("121") == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code power>
  MAKE_FUNCTION 0
  STORE_NAME power
  RETURN_CONST None
END
CODE power(a, b)
  RESUME 0
  LOAD_FAST b
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 1
L1:
  LOAD_FAST a
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  RETURN_CONST 0
L2:
  LOAD_FAST b
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_FAST a
  RETURN_VALUE
L3:
  LOAD_FAST a
  LOAD_GLOBAL NULL + power
  LOAD_FAST a
  LOAD_FAST b
  LOAD_CONST 1
  BINARY_OP -
  CALL 2
  BINARY_OP *
  RETURN_VALUE
END

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)

Prompt: Write a function to calculate the value of 'a' to the power 'b'.

assert power(3,4) == 81
assert power(2,3) == 8
assert power(5,5) == 3125


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code Find_Min_Length>
  MAKE_FUNCTION 0
  STORE_NAME Find_Min_Length
  RETURN_CONST None
END
CODE Find_Min_Length(lst)
  RESUME 0
  LOAD_GLOBAL NULL + min
  LOAD_CONST <code Find_Min_Length.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_FAST lst
  GET_ITER
  CALL 0
  CALL 1
  STORE_FAST minLength
  LOAD_FAST minLength
  RETURN_VALUE
END
CODE Find_Min_Length.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST x
  LOAD_GLOBAL NULL + len
  LOAD_FAST x
  CALL 1
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

def Find_Min_Length(lst):
    minLength = min((len(x) for x in lst))
    return minLength

Prompt: Write a python function to find the minimum length of sublist.

assert Find_Min_Length([[1],[1,2]]) == 1


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code divisor>
  MAKE_FUNCTION 0
  STORE_NAME divisor
  RETURN_CONST None
END
CODE divisor(n)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L1:
  FOR_ITER L8
  STORE_FAST i
  LOAD_GLOBAL NULL + len
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L2:
  BUILD_LIST 0
  SWAP 2
L3:
  FOR_ITER L6
  STORE_FAST i
  LOAD_FAST n
  LOAD_FAST i
  BINARY_OP %
  POP_JUMP_IF_FALSE L5
L4:
  JUMP_BACKWARD L3
L5:
  LOAD_FAST i
  LIST_APPEND 2
  JUMP_BACKWARD L3
L6:
  END_FOR
L7:
  SWAP 2
  STORE_FAST i
  CALL 1
  STORE_FAST x
  JUMP_BACKWARD L1
L8:
  END_FOR
  LOAD_FAST_CHECK x
  RETURN_VALUE
L9:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
  EXC try=L2..L4 -> handler=L9 depth=5 lasti=False
  EXC try=L5..L7 -> handler=L9 depth=5 lasti=False
END

def divisor(n):
    for i in range(n):
        x = len([i for i in range(1, n + 1) if not n % i])
    return x

Prompt: Write a python function to find the number of divisors of a given integer.

assert divisor(15) == 4
assert divisor(12) == 6
assert divisor(9) == 3


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code frequency_lists>
  MAKE_FUNCTION 0
  STORE_NAME frequency_lists
  RETURN_CONST None
END
CODE frequency_lists(list1)
  RESUME 0
  LOAD_FAST list1
  GET_ITER
  LOAD_FAST_AND_CLEAR sublist
  LOAD_FAST_AND_CLEAR item
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  STORE_FAST sublist
  LOAD_FAST sublist
  GET_ITER
L3:
  FOR_ITER L4
  STORE_FAST item
  LOAD_FAST item
  LIST_APPEND 3
  JUMP_BACKWARD L3
L4:
  END_FOR
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  STORE_FAST list1
  STORE_FAST sublist
  STORE_FAST item
  BUILD_MAP 0
  STORE_FAST dic_data
  LOAD_FAST list1
  GET_ITER
L7:
  FOR_ITER L9
  STORE_FAST num
  LOAD_FAST num
  LOAD_FAST dic_data
  LOAD_ATTR NULL|self + keys
  CALL 0
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L8
  LOAD_FAST dic_data
  LOAD_FAST num
  COPY 2
  COPY 2
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +=
  SWAP 3
  SWAP 2
  STORE_SUBSCR
  JUMP_BACKWARD L7
L8:
  LOAD_FAST num
  STORE_FAST key
  LOAD_CONST 1
  STORE_FAST value
  LOAD_FAST value
  LOAD_FAST dic_data
  LOAD_FAST key
  STORE_SUBSCR
  JUMP_BACKWARD L7
L9:
  END_FOR
  LOAD_FAST dic_data
  RETURN_VALUE
L10:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST item
  STORE_FAST sublist
  RERAISE 0
  EXC try=L1..L6 -> handler=L10 depth=3 lasti=False
END

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

Prompt: Write a function to find frequency count of list of lists.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code multiply_num>
  MAKE_FUNCTION 0
  STORE_NAME multiply_num
  RETURN_CONST None
END
CODE multiply_num(numbers)
  RESUME 0
  LOAD_CONST 1
  STORE_FAST total
  LOAD_FAST numbers
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST x
  LOAD_FAST total
  LOAD_FAST x
  BINARY_OP *=
  STORE_FAST total
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST total
  LOAD_GLOBAL NULL + len
  LOAD_FAST numbers
  CALL 1
  BINARY_OP /
  RETURN_VALUE
END

def multiply_num(numbers):
    total = 1
    for x in numbers:
        total *= x
    return total / len(numbers)

Prompt: Write a function to multiply all the numbers in a list and divide with the length of the list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code decimal_to_binary>
  MAKE_FUNCTION 0
  STORE_NAME decimal_to_binary
  RETURN_CONST None
END
CODE decimal_to_binary(n)
  RESUME 0
  LOAD_GLOBAL NULL + bin
  LOAD_FAST n
  CALL 1
  LOAD_ATTR NULL|self + replace
  LOAD_CONST '0b'
  LOAD_CONST ''
  CALL 2
  RETURN_VALUE
END

def decimal_to_binary(n):
    return bin(n).replace('0b', '')

Prompt: Write a function to convert the given decimal number to its binary equivalent.

assert decimal_to_binary(8) == '1000'
assert decimal_to_binary(18) == '10010'
assert decimal_to_binary(7) == '111'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME sys
  STORE_NAME sys
  LOAD_CONST <code next_smallest_palindrome>
  MAKE_FUNCTION 0
  STORE_NAME next_smallest_palindrome
  RETURN_CONST None
END
CODE next_smallest_palindrome(num)
  RESUME 0
  LOAD_GLOBAL NULL + str
  LOAD_FAST num
  CALL 1
  STORE_FAST numstr
  LOAD_GLOBAL NULL + range
  LOAD_FAST num
  LOAD_CONST 1
  BINARY_OP +
  LOAD_GLOBAL sys
  LOAD_ATTR maxsize
  CALL 2
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_GLOBAL NULL + str
  LOAD_FAST i
  CALL 1
  LOAD_GLOBAL NULL + str
  LOAD_FAST i
  CALL 1
  LOAD_CONST None
  LOAD_CONST None
  LOAD_CONST -1
  BUILD_SLICE 3
  BINARY_SUBSCR
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST i
  SWAP 2
  POP_TOP
  RETURN_VALUE
L3:
  END_FOR
  RETURN_CONST None
END

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

Prompt: Write a function to find the next smallest palindrome of a specified number.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code snake_to_camel>
  MAKE_FUNCTION 0
  STORE_NAME snake_to_camel
  RETURN_CONST None
END
CODE snake_to_camel(word)
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_FAST re
  LOAD_CONST ''
  LOAD_ATTR NULL|self + join
  LOAD_CONST <code snake_to_camel.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_FAST word
  LOAD_ATTR NULL|self + split
  LOAD_CONST '_'
  CALL 1
  GET_ITER
  CALL 0
  CALL 1
  RETURN_VALUE
END
CODE snake_to_camel.<locals>.<genexpr>(.0)
  DOC '_'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L4
  STORE_FAST x
  LOAD_FAST x
  LOAD_ATTR NULL|self + capitalize
  CALL 0
  COPY 1
  POP_JUMP_IF_TRUE L3
  POP_TOP
  LOAD_CONST '_'
L3:
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L4:
  END_FOR
  RETURN_CONST None
L5:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L5 -> handler=L5 depth=0 lasti=True
END

def snake_to_camel(word):
    import re
    return ''.join((x.capitalize() or '_' for x in word.split('_')))

Prompt: Write a function to convert snake case string to camel case string.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code eulerian_num>
  MAKE_FUNCTION 0
  STORE_NAME eulerian_num
  RETURN_CONST None
END
CODE eulerian_num(n, m)
  RESUME 0
  LOAD_FAST m
  LOAD_FAST n
  COMPARE_OP >=
  POP_JUMP_IF_TRUE L1
  LOAD_FAST n
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
L1:
  RETURN_CONST 0
L2:
  LOAD_FAST m
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  RETURN_CONST 1
L3:
  LOAD_FAST n
  LOAD_FAST m
  BINARY_OP -
  LOAD_GLOBAL NULL + eulerian_num
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  LOAD_FAST m
  LOAD_CONST 1
  BINARY_OP -
  CALL 2
  BINARY_OP *
  LOAD_FAST m
  LOAD_CONST 1
  BINARY_OP +
  LOAD_GLOBAL NULL + eulerian_num
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  LOAD_FAST m
  CALL 2
  BINARY_OP *
  BINARY_OP +
  RETURN_VALUE
END

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)

Prompt: Write a function to find eulerian number a(n, m).

assert eulerian_num(3, 1) == 4
assert eulerian_num(4, 1) == 11
assert eulerian_num(5, 3) == 26


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sort_sublists>
  MAKE_FUNCTION 0
  STORE_NAME sort_sublists
  RETURN_CONST None
END
CODE sort_sublists(input_list)
  RESUME 0
  LOAD_FAST input_list
  GET_ITER
  LOAD_FAST_AND_CLEAR x
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST x
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST x
  LOAD_CONST <code sort_sublists.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST result
  STORE_FAST x
  LOAD_FAST result
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST x
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=2 lasti=False
END
CODE sort_sublists.<locals>.<lambda>(x)
  RESUME 0
  LOAD_FAST x
  LOAD_CONST 0
  BINARY_SUBSCR
  RETURN_VALUE
END

def sort_sublists(input_list):
    result = [sorted(x, key=lambda x: x[0]) for x in input_list]
    return result

Prompt: Write a function to sort each sublist of strings in a given list of lists using lambda function.

assert sort_sublists((["green", "orange"], ["black", "white"], ["white", "black", "orange"]))==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]

assert sort_sublists(([" red ","green" ],["blue "," black"],[" orange","brown"]))==[[' red ', 'green'], [' black', 'blue '], [' orange', 'brown']]

assert sort_sublists((["zilver","gold"], ["magnesium","aluminium"], ["steel", "bronze"]))==[['gold', 'zilver'],['aluminium', 'magnesium'], ['bronze', 'steel']]


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code add_lists>
  MAKE_FUNCTION 0
  STORE_NAME add_lists
  RETURN_CONST None
END
CODE add_lists(test_list, test_tup)
  RESUME 0
  LOAD_GLOBAL NULL + tuple
  LOAD_GLOBAL NULL + list
  LOAD_FAST test_tup
  CALL 1
  LOAD_FAST test_list
  BINARY_OP +
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END

def add_lists(test_list, test_tup):
    res = tuple(list(test_tup) + test_list)
    return res

Prompt: Write a function to add the given list to the given tuples.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code odd_Equivalent>
  MAKE_FUNCTION 0
  STORE_NAME odd_Equivalent
  RETURN_CONST None
END
CODE odd_Equivalent(s, n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST count
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_FAST n
  CALL 2
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST s
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST '1'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST count
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST count
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST count
  RETURN_VALUE
END

def odd_Equivalent(s, n):
    count = 0
    for i in range(0, n):
        if s[i] == '1':
            count = count + 1
    return count

Prompt: Write a python function to find the count of rotations of a binary string with odd value.

assert odd_Equivalent("011001",6) == 3
assert odd_Equivalent("11011",5) == 4
assert odd_Equivalent("1010",4) == 2


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code extract_missing>
  MAKE_FUNCTION 0
  STORE_NAME extract_missing
  RETURN_CONST None
END
CODE extract_missing(test_list, strt_val, stop_val)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST res
  LOAD_FAST test_list
  GET_ITER
L1:
  FOR_ITER L4
  STORE_FAST sub
  LOAD_FAST sub
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST strt_val
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
  LOAD_FAST res
  LOAD_ATTR NULL|self + append
  LOAD_FAST strt_val
  LOAD_FAST sub
  LOAD_CONST 0
  BINARY_SUBSCR
  BUILD_TUPLE 2
  CALL 1
  POP_TOP
  LOAD_FAST sub
  LOAD_CONST 1
  BINARY_SUBSCR
  STORE_FAST strt_val
L2:
  LOAD_FAST strt_val
  LOAD_FAST stop_val
  COMPARE_OP <
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L1
L3:
  LOAD_FAST res
  LOAD_ATTR NULL|self + append
  LOAD_FAST strt_val
  LOAD_FAST stop_val
  BUILD_TUPLE 2
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L4:
  END_FOR
  LOAD_FAST res
  RETURN_VALUE
END

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

Prompt: Write a function to extract the ranges that are missing from the given list with the given start range and end range values.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code common_in_nested_lists>
  MAKE_FUNCTION 0
  STORE_NAME common_in_nested_lists
  RETURN_CONST None
END
CODE common_in_nested_lists(nestedlist)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + set
  LOAD_ATTR intersection
  LOAD_GLOBAL NULL + map
  LOAD_GLOBAL set
  LOAD_FAST nestedlist
  CALL 2
  CALL_FUNCTION_EX 0
  CALL 1
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END

def common_in_nested_lists(nestedlist):
    result = list(set.intersection(*map(set, nestedlist)))
    return result

Prompt: Write a function to find common elements in given nested lists. * list item * list item * list item * list item


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code perimeter>
  MAKE_FUNCTION 0
  STORE_NAME perimeter
  RETURN_CONST None
END
CODE perimeter(diameter, height)
  RESUME 0
  LOAD_CONST 2
  LOAD_FAST diameter
  LOAD_FAST height
  BINARY_OP +
  BINARY_OP *
  RETURN_VALUE
END

def perimeter(diameter, height):
    return 2 * (diameter + height)

Prompt: Write a python function to find the perimeter of a cylinder.

assert perimeter(2,4) == 12
assert perimeter(1,2) == 6
assert perimeter(3,1) == 8