Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME sys
  STORE_NAME sys
  LOAD_CONST <code sd_calc>
  MAKE_FUNCTION 0
  STORE_NAME sd_calc
  LOAD_CONST <code avg_calc>
  MAKE_FUNCTION 0
  STORE_NAME avg_calc
  RETURN_CONST None
END
CODE sd_calc(data)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST data
  CALL 1
  STORE_FAST n
  LOAD_FAST n
  LOAD_CONST 1
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 0.0
L1:
  LOAD_GLOBAL NULL + avg_calc
  LOAD_FAST data
  CALL 1
  LOAD_CONST 0.0
  STORE_FAST sd
  STORE_FAST mean
  LOAD_FAST data
  GET_ITER
L2:
  FOR_ITER L3
  STORE_FAST el
  LOAD_FAST sd
  LOAD_GLOBAL NULL + float
  LOAD_FAST el
  CALL 1
  LOAD_FAST mean
  BINARY_OP -
  LOAD_CONST 2
  BINARY_OP **
  BINARY_OP +=
  STORE_FAST sd
  JUMP_BACKWARD L2
L3:
  END_FOR
  LOAD_GLOBAL NULL + math
  LOAD_ATTR sqrt
  LOAD_FAST sd
  LOAD_GLOBAL NULL + float
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  CALL 1
  BINARY_OP /
  CALL 1
  STORE_FAST sd
  LOAD_FAST sd
  RETURN_VALUE
END
CODE avg_calc(ls)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST ls
  CALL 1
  LOAD_CONST 0.0
  STORE_FAST mean
  STORE_FAST n
  LOAD_FAST n
  LOAD_CONST 1
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L1
  LOAD_FAST ls
  LOAD_CONST 0
  BINARY_SUBSCR
  RETURN_VALUE
L1:
  LOAD_FAST ls
  GET_ITER
L2:
  FOR_ITER L3
  STORE_FAST el
  LOAD_FAST mean
  LOAD_GLOBAL NULL + float
  LOAD_FAST el
  CALL 1
  BINARY_OP +
  STORE_FAST mean
  JUMP_BACKWARD L2
L3:
  END_FOR
  LOAD_FAST mean
  LOAD_GLOBAL NULL + float
  LOAD_FAST n
  CALL 1
  BINARY_OP /
  STORE_FAST mean
  LOAD_FAST mean
  RETURN_VALUE
END

import math
import sys

def sd_calc(data):
    n = len(data)
    if n <= 1:
        return 0.0
    mean, sd = (avg_calc(data), 0.0)
    for el in data:
        sd += (float(el) - mean) ** 2
    sd = math.sqrt(sd / float(n - 1))
    return sd

def avg_calc(ls):
    n, mean = (len(ls), 0.0)
    if n <= 1:
        return ls[0]
    for el in ls:
        mean = mean + float(el)
    mean = mean / float(n)
    return mean

Prompt: Write a function to calculate the standard deviation.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code alternate_elements>
  MAKE_FUNCTION 0
  STORE_NAME alternate_elements
  RETURN_CONST None
END
CODE alternate_elements(list1)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST result
  LOAD_FAST list1
  LOAD_CONST None
  LOAD_CONST None
  LOAD_CONST 2
  BUILD_SLICE 3
  BINARY_SUBSCR
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST item
  LOAD_FAST result
  LOAD_ATTR NULL|self + append
  LOAD_FAST item
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST result
  RETURN_VALUE
END

def alternate_elements(list1):
    result = []
    for item in list1[::2]:
        result.append(item)
    return result

Prompt: Write a function to create a list taking alternate elements from another given list.

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

Creative Commons Attribution 4.0 International

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


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code text_match>
  MAKE_FUNCTION 0
  STORE_NAME text_match
  RETURN_CONST None
END
CODE text_match(text)
  RESUME 0
  LOAD_CONST 'ab*?'
  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(text):
    patterns = 'ab*?'
    if re.search(patterns, text):
        return 'Found a match!'
    else:
        return 'Not matched!'

Prompt: Write a function that matches a string that has an a followed by zero or more b's.

assert text_match("ac")==('Found a match!')

assert text_match("abba")==('Found a match!')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code add_dict_to_tuple>
  MAKE_FUNCTION 0
  STORE_NAME add_dict_to_tuple
  RETURN_CONST None
END
CODE add_dict_to_tuple(test_tup, test_dict)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_FAST test_tup
  CALL 1
  STORE_FAST test_tup
  LOAD_FAST test_tup
  LOAD_ATTR NULL|self + append
  LOAD_FAST test_dict
  CALL 1
  POP_TOP
  LOAD_GLOBAL NULL + tuple
  LOAD_FAST test_tup
  CALL 1
  STORE_FAST test_tup
  LOAD_FAST test_tup
  RETURN_VALUE
END

def add_dict_to_tuple(test_tup, test_dict):
    test_tup = list(test_tup)
    test_tup.append(test_dict)
    test_tup = tuple(test_tup)
    return test_tup

Prompt: Write a function to add a dictionary to the tuple.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('eq',)
  IMPORT_NAME operator
  IMPORT_FROM eq
  STORE_NAME eq
  POP_TOP
  LOAD_CONST <code count_same_pair>
  MAKE_FUNCTION 0
  STORE_NAME count_same_pair
  RETURN_CONST None
END
CODE count_same_pair(nums1, nums2)
  RESUME 0
  LOAD_GLOBAL NULL + sum
  LOAD_GLOBAL NULL + map
  LOAD_GLOBAL eq
  LOAD_FAST nums1
  LOAD_FAST nums2
  CALL 3
  CALL 1
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END

from operator import eq

def count_same_pair(nums1, nums2):
    result = sum(map(eq, nums1, nums2))
    return result

Prompt: Write a function to count the same pair in two given lists using map function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code multiply_elements>
  MAKE_FUNCTION 0
  STORE_NAME multiply_elements
  RETURN_CONST None
END
CODE multiply_elements(test_tup)
  RESUME 0
  LOAD_GLOBAL NULL + tuple
  LOAD_CONST <code multiply_elements.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_GLOBAL NULL + zip
  LOAD_FAST test_tup
  LOAD_FAST test_tup
  LOAD_CONST 1
  LOAD_CONST None
  BINARY_SLICE
  CALL 2
  GET_ITER
  CALL 0
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END
CODE multiply_elements.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST i
  STORE_FAST j
  LOAD_FAST i
  LOAD_FAST j
  BINARY_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 multiply_elements(test_tup):
    res = tuple((i * j for i, j in zip(test_tup, test_tup[1:])))
    return res

Prompt: Write a function to multiply the adjacent elements of the given tuple.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sum_list>
  MAKE_FUNCTION 0
  STORE_NAME sum_list
  RETURN_CONST None
END
CODE sum_list(lst1, lst2)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST lst1
  CALL 1
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST lst1
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST lst2
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP +
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST res_list
  STORE_FAST i
  LOAD_FAST res_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

def sum_list(lst1, lst2):
    res_list = [lst1[i] + lst2[i] for i in range(len(lst1))]
    return res_list

Prompt: Write a function to sum elements in two lists.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code add_list>
  MAKE_FUNCTION 0
  STORE_NAME add_list
  RETURN_CONST None
END
CODE add_list(nums1, nums2)
  RESUME 0
  LOAD_GLOBAL NULL + map
  LOAD_CONST <code add_list.<locals>.<lambda>>
  MAKE_FUNCTION 0
  LOAD_FAST nums1
  LOAD_FAST nums2
  CALL 3
  STORE_FAST result
  LOAD_GLOBAL NULL + list
  LOAD_FAST result
  CALL 1
  RETURN_VALUE
END
CODE add_list.<locals>.<lambda>(x, y)
  RESUME 0
  LOAD_FAST x
  LOAD_FAST y
  BINARY_OP +
  RETURN_VALUE
END

def add_list(nums1, nums2):
    result = map(lambda x, y: x + y, nums1, nums2)
    return list(result)

Prompt: Write a function to add two lists using map and lambda function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('groupby',)
  IMPORT_NAME itertools
  IMPORT_FROM groupby
  STORE_NAME groupby
  POP_TOP
  LOAD_CONST <code consecutive_duplicates>
  MAKE_FUNCTION 0
  STORE_NAME consecutive_duplicates
  RETURN_CONST None
END
CODE consecutive_duplicates(nums)
  RESUME 0
  LOAD_GLOBAL NULL + groupby
  LOAD_FAST nums
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR key
  LOAD_FAST_AND_CLEAR group
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST key
  STORE_FAST group
  LOAD_FAST key
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  SWAP 3
  STORE_FAST group
  STORE_FAST key
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST group
  STORE_FAST key
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=3 lasti=False
END

from itertools import groupby

def consecutive_duplicates(nums):
    return [key for key, group in groupby(nums)]

Prompt: Write a function to remove consecutive duplicates of a given list.

assert consecutive_duplicates(['a', 'a', 'b', 'c', 'd', 'd'])==['a', 'b', 'c', 'd']


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code lateralsurface_cone>
  MAKE_FUNCTION 0
  STORE_NAME lateralsurface_cone
  RETURN_CONST None
END
CODE lateralsurface_cone(r, h)
  RESUME 0
  LOAD_GLOBAL NULL + math
  LOAD_ATTR sqrt
  LOAD_FAST r
  LOAD_FAST r
  BINARY_OP *
  LOAD_FAST h
  LOAD_FAST h
  BINARY_OP *
  BINARY_OP +
  CALL 1
  STORE_FAST l
  LOAD_GLOBAL math
  LOAD_ATTR pi
  LOAD_FAST r
  BINARY_OP *
  LOAD_FAST l
  BINARY_OP *
  STORE_FAST LSA
  LOAD_FAST LSA
  RETURN_VALUE
END

import math

def lateralsurface_cone(r, h):
    l = math.sqrt(r * r + h * h)
    LSA = math.pi * r * l
    return LSA

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


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_first_occurrence>
  MAKE_FUNCTION 0
  STORE_NAME find_first_occurrence
  RETURN_CONST None
END
CODE find_first_occurrence(A, x)
  RESUME 0
  LOAD_CONST 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST A
  CALL 1
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST right
  STORE_FAST left
  LOAD_CONST -1
  STORE_FAST result
  LOAD_FAST left
  LOAD_FAST right
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
L1:
  LOAD_FAST left
  LOAD_FAST right
  BINARY_OP +
  LOAD_CONST 2
  BINARY_OP //
  STORE_FAST mid
  LOAD_FAST x
  LOAD_FAST A
  LOAD_FAST mid
  BINARY_SUBSCR
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST mid
  STORE_FAST result
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST right
  JUMP_FORWARD L4
L2:
  LOAD_FAST x
  LOAD_FAST A
  LOAD_FAST mid
  BINARY_SUBSCR
  COMPARE_OP <
  POP_JUMP_IF_FALSE L3
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST right
  JUMP_FORWARD L4
L3:
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST left
L4:
  LOAD_FAST left
  LOAD_FAST right
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
  JUMP_BACKWARD L1
L5:
  LOAD_FAST result
  RETURN_VALUE
END

def find_first_occurrence(A, x):
    left, right = (0, len(A) - 1)
    result = -1
    while left <= right:
        mid = (left + right) // 2
        if x == A[mid]:
            result = mid
            right = mid - 1
        elif x < A[mid]:
            right = mid - 1
        else:
            left = mid + 1
    return result

Prompt: Write a function to find the index of the first occurrence of a given number in a sorted array.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sum_Of_Subarray_Prod>
  MAKE_FUNCTION 0
  STORE_NAME sum_Of_Subarray_Prod
  RETURN_CONST None
END
CODE sum_Of_Subarray_Prod(arr, n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST ans
  LOAD_CONST 0
  STORE_FAST res
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST i
  LOAD_FAST i
  LOAD_CONST 0
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST 1
  LOAD_FAST res
  BINARY_OP +
  BINARY_OP *
  STORE_FAST incr
  LOAD_FAST ans
  LOAD_FAST incr
  BINARY_OP +=
  STORE_FAST ans
  LOAD_FAST incr
  STORE_FAST res
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP -=
  STORE_FAST i
  LOAD_FAST i
  LOAD_CONST 0
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST ans
  RETURN_VALUE
END

def sum_Of_Subarray_Prod(arr, n):
    ans = 0
    res = 0
    i = n - 1
    while i >= 0:
        incr = arr[i] * (1 + res)
        ans += incr
        res = incr
        i -= 1
    return ans

Prompt: Write a python function to find sum of products of all possible subarrays.

assert sum_Of_Subarray_Prod([1,2,3],3) == 20

assert sum_Of_Subarray_Prod([1,2],2) == 5

assert sum_Of_Subarray_Prod([1,2,3,4],4) == 84


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code set_middle_bits>
  MAKE_FUNCTION 0
  STORE_NAME set_middle_bits
  LOAD_CONST <code toggle_middle_bits>
  MAKE_FUNCTION 0
  STORE_NAME toggle_middle_bits
  RETURN_CONST None
END
CODE set_middle_bits(n)
  RESUME 0
  LOAD_FAST n
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP >>
  BINARY_OP |=
  STORE_FAST n
  LOAD_FAST n
  LOAD_FAST n
  LOAD_CONST 2
  BINARY_OP >>
  BINARY_OP |=
  STORE_FAST n
  LOAD_FAST n
  LOAD_FAST n
  LOAD_CONST 4
  BINARY_OP >>
  BINARY_OP |=
  STORE_FAST n
  LOAD_FAST n
  LOAD_FAST n
  LOAD_CONST 8
  BINARY_OP >>
  BINARY_OP |=
  STORE_FAST n
  LOAD_FAST n
  LOAD_FAST n
  LOAD_CONST 16
  BINARY_OP >>
  BINARY_OP |=
  STORE_FAST n
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP >>
  LOAD_CONST 1
  BINARY_OP ^
  RETURN_VALUE
END
CODE toggle_middle_bits(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 1
L1:
  LOAD_FAST n
  LOAD_GLOBAL NULL + set_middle_bits
  LOAD_FAST n
  CALL 1
  BINARY_OP ^
  RETURN_VALUE
END

def set_middle_bits(n):
    n |= n >> 1
    n |= n >> 2
    n |= n >> 4
    n |= n >> 8
    n |= n >> 16
    return n >> 1 ^ 1

def toggle_middle_bits(n):
    if n == 1:
        return 1
    return n ^ set_middle_bits(n)

Prompt: Write a python function to toggle bits of the number except the first and the last bit.

assert toggle_middle_bits(9) == 15
assert toggle_middle_bits(10) == 12
assert toggle_middle_bits(11) == 13


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME bisect
  STORE_NAME bisect
  LOAD_CONST <code left_insertion>
  MAKE_FUNCTION 0
  STORE_NAME left_insertion
  RETURN_CONST None
END
CODE left_insertion(a, x)
  RESUME 0
  LOAD_GLOBAL NULL + bisect
  LOAD_ATTR bisect_left
  LOAD_FAST a
  LOAD_FAST x
  CALL 2
  STORE_FAST i
  LOAD_FAST i
  RETURN_VALUE
END

import bisect

def left_insertion(a, x):
    i = bisect.bisect_left(a, x)
    return i

Prompt: Write a function to locate the left insertion point for a specified value in sorted order.

assert left_insertion([1,2,4,5],6)==4
assert left_insertion([1,2,4,5],3)==2
assert left_insertion([1,2,4,5],7)==4


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST '^[aeiouAEIOU][A-Za-z0-9_]*'
  STORE_NAME regex
  LOAD_CONST <code check_str>
  MAKE_FUNCTION 0
  STORE_NAME check_str
  RETURN_CONST None
END
CODE check_str(string)
  RESUME 0
  LOAD_GLOBAL NULL + re
  LOAD_ATTR search
  LOAD_GLOBAL regex
  LOAD_FAST string
  CALL 2
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'Valid'
L1:
  RETURN_CONST 'Invalid'
END

import re
regex = '^[aeiouAEIOU][A-Za-z0-9_]*'

def check_str(string):
    if re.search(regex, string):
        return 'Valid'
    else:
        return 'Invalid'

Prompt: Write a function to check whether the given string is starting with a vowel or not using regex.

assert check_str("annie") == 'Valid'
assert check_str("dawood") == 'Invalid'
assert check_str("Else") == 'Valid'


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

def geometric_sum(n):
    if n < 0:
        return 0
    else:
        return 1 / pow(2, n) + geometric_sum(n - 1)

Prompt: Write a function to calculate the geometric sum of n-1.

assert geometric_sum(7) == 1.9921875
assert geometric_sum(4) == 1.9375
assert geometric_sum(8) == 1.99609375


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code find_Index>
  MAKE_FUNCTION 0
  STORE_NAME find_Index
  RETURN_CONST None
END
CODE find_Index(n)
  RESUME 0
  LOAD_GLOBAL NULL + math
  LOAD_ATTR sqrt
  LOAD_CONST 2
  LOAD_GLOBAL NULL + math
  LOAD_ATTR pow
  LOAD_CONST 10
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  CALL 2
  BINARY_OP *
  CALL 1
  STORE_FAST x
  LOAD_GLOBAL NULL + round
  LOAD_FAST x
  CALL 1
  RETURN_VALUE
END

import math

def find_Index(n):
    x = math.sqrt(2 * math.pow(10, n - 1))
    return round(x)

Prompt: Write a python function to find the index of smallest triangular number with n digits.

assert find_Index(2) == 4
assert find_Index(3) == 14
assert find_Index(4) == 45


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code tuple_to_dict>
  MAKE_FUNCTION 0
  STORE_NAME tuple_to_dict
  RETURN_CONST None
END
CODE tuple_to_dict(test_tup)
  MAKE_CELL test_tup
  RESUME 0
  LOAD_GLOBAL NULL + dict
  LOAD_CLOSURE test_tup
  BUILD_TUPLE 1
  LOAD_CONST <code tuple_to_dict.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_GLOBAL NULL + len
  LOAD_DEREF test_tup
  CALL 1
  LOAD_CONST 2
  CALL 3
  GET_ITER
  CALL 0
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END
CODE tuple_to_dict.<locals>.<genexpr>(.0)
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST idx
  LOAD_DEREF test_tup
  LOAD_FAST idx
  LOAD_FAST idx
  LOAD_CONST 2
  BINARY_OP +
  BINARY_SLICE
  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 tuple_to_dict(test_tup):
    res = dict((test_tup[idx:idx + 2] for idx in range(0, len(test_tup), 2)))
    return res

Prompt: Write a function to convert the given tuple to a key-value dictionary using adjacent elements.


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

def all_Characters_Same(s):
    n = len(s)
    for i in range(1, n):
        if s[i] != s[0]:
            return False
    return True

Prompt: Write a python function to check whether all the characters are same or not.

assert all_Characters_Same("python") == False

assert all_Characters_Same("aaa") == True

assert all_Characters_Same("data") == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code area_tetrahedron>
  MAKE_FUNCTION 0
  STORE_NAME area_tetrahedron
  RETURN_CONST None
END
CODE area_tetrahedron(side)
  RESUME 0
  LOAD_GLOBAL NULL + math
  LOAD_ATTR sqrt
  LOAD_CONST 3
  CALL 1
  LOAD_FAST side
  LOAD_FAST side
  BINARY_OP *
  BINARY_OP *
  STORE_FAST area
  LOAD_FAST area
  RETURN_VALUE
END

import math

def area_tetrahedron(side):
    area = math.sqrt(3) * (side * side)
    return area

Prompt: Write a function to caluclate the area of a tetrahedron.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_none>
  MAKE_FUNCTION 0
  STORE_NAME check_none
  RETURN_CONST None
END
CODE check_none(test_tup)
  RESUME 0
  LOAD_GLOBAL NULL + any
  LOAD_GLOBAL NULL + map
  LOAD_CONST <code check_none.<locals>.<lambda>>
  MAKE_FUNCTION 0
  LOAD_FAST test_tup
  CALL 2
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END
CODE check_none.<locals>.<lambda>(ele)
  RESUME 0
  LOAD_FAST ele
  LOAD_CONST None
  IS_OP 0
  RETURN_VALUE
END

def check_none(test_tup):
    res = any(map(lambda ele: ele is None, test_tup))
    return res

Prompt: Write a function to check if the given tuple has any none value or not.

assert check_none((10, 4, 5, 6, None)) == True

assert check_none((7, 8, 9, 11, 14)) == False

assert check_none((1, 2, 3, 4, None)) == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sector_area>
  MAKE_FUNCTION 0
  STORE_NAME sector_area
  RETURN_CONST None
END
CODE sector_area(r, a)
  RESUME 0
  LOAD_CONST 3.142857142857143
  STORE_FAST pi
  LOAD_FAST a
  LOAD_CONST 360
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L1
  RETURN_CONST None
L1:
  LOAD_FAST pi
  LOAD_FAST r
  LOAD_CONST 2
  BINARY_OP **
  BINARY_OP *
  LOAD_FAST a
  LOAD_CONST 360
  BINARY_OP /
  BINARY_OP *
  STORE_FAST sectorarea
  LOAD_FAST sectorarea
  RETURN_VALUE
END

def sector_area(r, a):
    pi = 22 / 7
    if a >= 360:
        return None
    sectorarea = pi * r ** 2 * (a / 360)
    return sectorarea

Prompt: Write a function to find area of a sector.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sort_numeric_strings>
  MAKE_FUNCTION 0
  STORE_NAME sort_numeric_strings
  RETURN_CONST None
END
CODE sort_numeric_strings(nums_str)
  RESUME 0
  LOAD_FAST nums_str
  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 + int
  LOAD_FAST x
  CALL 1
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST result
  STORE_FAST x
  LOAD_FAST result
  LOAD_ATTR NULL|self + sort
  CALL 0
  POP_TOP
  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

def sort_numeric_strings(nums_str):
    result = [int(x) for x in nums_str]
    result.sort()
    return result

Prompt: Write a function to sort a given list of strings of numbers numerically.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_min_heap>
  MAKE_FUNCTION 0
  STORE_NAME check_min_heap
  RETURN_CONST None
END
CODE check_min_heap(arr, i)
  RESUME 0
  LOAD_CONST 2
  LOAD_FAST i
  BINARY_OP *
  LOAD_CONST 2
  BINARY_OP +
  LOAD_GLOBAL NULL + len
  LOAD_FAST arr
  CALL 1
  COMPARE_OP >
  POP_JUMP_IF_FALSE L1
  RETURN_CONST True
L1:
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_CONST 2
  LOAD_FAST i
  BINARY_OP *
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SUBSCR
  COMPARE_OP <=
  COPY 1
  POP_JUMP_IF_FALSE L2
  POP_TOP
  LOAD_GLOBAL NULL + check_min_heap
  LOAD_FAST arr
  LOAD_CONST 2
  LOAD_FAST i
  BINARY_OP *
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
L2:
  STORE_FAST left_child
  LOAD_CONST 2
  LOAD_FAST i
  BINARY_OP *
  LOAD_CONST 2
  BINARY_OP +
  LOAD_GLOBAL NULL + len
  LOAD_FAST arr
  CALL 1
  COMPARE_OP ==
  COPY 1
  POP_JUMP_IF_TRUE L3
  POP_TOP
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_CONST 2
  LOAD_FAST i
  BINARY_OP *
  LOAD_CONST 2
  BINARY_OP +
  BINARY_SUBSCR
  COMPARE_OP <=
  COPY 1
  POP_JUMP_IF_FALSE L3
  POP_TOP
  LOAD_GLOBAL NULL + check_min_heap
  LOAD_FAST arr
  LOAD_CONST 2
  LOAD_FAST i
  BINARY_OP *
  LOAD_CONST 2
  BINARY_OP +
  CALL 2
L3:
  STORE_FAST right_child
  LOAD_FAST left_child
  COPY 1
  POP_JUMP_IF_FALSE L4
  POP_TOP
  LOAD_FAST right_child
L4:
  RETURN_VALUE
END

def check_min_heap(arr, i):
    if 2 * i + 2 > len(arr):
        return True
    left_child = arr[i] <= arr[2 * i + 1] and check_min_heap(arr, 2 * i + 1)
    right_child = 2 * i + 2 == len(arr) or (arr[i] <= arr[2 * i + 2] and check_min_heap(arr, 2 * i + 2))
    return left_child and right_child

Prompt: Write a function to check if the given array represents min heap or not.

assert check_min_heap([1, 2, 3, 4, 5, 6], 0) == True

assert check_min_heap([2, 10, 4, 5, 3, 15], 0) == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code jacobsthal_num>
  MAKE_FUNCTION 0
  STORE_NAME jacobsthal_num
  RETURN_CONST None
END
CODE jacobsthal_num(n)
  RESUME 0
  LOAD_CONST 0
  BUILD_LIST 1
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP *
  STORE_FAST dp
  LOAD_CONST 0
  LOAD_FAST dp
  LOAD_CONST 0
  STORE_SUBSCR
  LOAD_CONST 1
  LOAD_FAST dp
  LOAD_CONST 1
  STORE_SUBSCR
  LOAD_GLOBAL NULL + range
  LOAD_CONST 2
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST dp
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_CONST 2
  LOAD_FAST dp
  LOAD_FAST i
  LOAD_CONST 2
  BINARY_OP -
  BINARY_SUBSCR
  BINARY_OP *
  BINARY_OP +
  LOAD_FAST dp
  LOAD_FAST i
  STORE_SUBSCR
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST dp
  LOAD_FAST n
  BINARY_SUBSCR
  RETURN_VALUE
END

def jacobsthal_num(n):
    dp = [0] * (n + 1)
    dp[0] = 0
    dp[1] = 1
    for i in range(2, n + 1):
        dp[i] = dp[i - 1] + 2 * dp[i - 2]
    return dp[n]

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

assert jacobsthal_num(5) == 11
assert jacobsthal_num(2) == 1
assert jacobsthal_num(4) == 5


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code extract_index_list>
  MAKE_FUNCTION 0
  STORE_NAME extract_index_list
  RETURN_CONST None
END
CODE extract_index_list(l1, l2, l3)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST result
  LOAD_GLOBAL NULL + zip
  LOAD_FAST l1
  LOAD_FAST l2
  LOAD_FAST l3
  CALL 3
  GET_ITER
L1:
  FOR_ITER L5
  UNPACK_SEQUENCE 3
  STORE_FAST m
  STORE_FAST n
  STORE_FAST o
  LOAD_FAST m
  LOAD_FAST n
  SWAP 2
  COPY 2
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_FAST o
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  JUMP_FORWARD L4
L3:
  POP_TOP
  JUMP_BACKWARD L1
L4:
  LOAD_FAST result
  LOAD_ATTR NULL|self + append
  LOAD_FAST m
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L5:
  END_FOR
  LOAD_FAST result
  RETURN_VALUE
END

def extract_index_list(l1, l2, l3):
    result = []
    for m, n, o in zip(l1, l2, l3):
        if m == n == o:
            result.append(m)
    return result

Prompt: Write a function to find common index elements from three lists.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code second_smallest>
  MAKE_FUNCTION 0
  STORE_NAME second_smallest
  RETURN_CONST None
END
CODE second_smallest(numbers)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST numbers
  CALL 1
  LOAD_CONST 2
  COMPARE_OP <
  POP_JUMP_IF_FALSE L1
  RETURN_CONST None
L1:
  LOAD_GLOBAL NULL + len
  LOAD_FAST numbers
  CALL 1
  LOAD_CONST 2
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST numbers
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST numbers
  LOAD_CONST 1
  BINARY_SUBSCR
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  RETURN_CONST None
L2:
  LOAD_GLOBAL NULL + set
  CALL 0
  STORE_FAST dup_items
  BUILD_LIST 0
  STORE_FAST uniq_items
  LOAD_FAST numbers
  GET_ITER
L3:
  FOR_ITER L5
  STORE_FAST x
  LOAD_FAST x
  LOAD_FAST dup_items
  CONTAINS_OP 1
  POP_JUMP_IF_TRUE L4
  JUMP_BACKWARD L3
L4:
  LOAD_FAST uniq_items
  LOAD_ATTR NULL|self + append
  LOAD_FAST x
  CALL 1
  POP_TOP
  LOAD_FAST dup_items
  LOAD_ATTR NULL|self + add
  LOAD_FAST x
  CALL 1
  POP_TOP
  JUMP_BACKWARD L3
L5:
  END_FOR
  LOAD_FAST uniq_items
  LOAD_ATTR NULL|self + sort
  CALL 0
  POP_TOP
  LOAD_FAST uniq_items
  LOAD_CONST 1
  BINARY_SUBSCR
  RETURN_VALUE
END

def second_smallest(numbers):
    if len(numbers) < 2:
        return
    if len(numbers) == 2 and numbers[0] == numbers[1]:
        return
    dup_items = set()
    uniq_items = []
    for x in numbers:
        if x not in dup_items:
            uniq_items.append(x)
            dup_items.add(x)
    uniq_items.sort()
    return uniq_items[1]

Prompt: Write a function to find the second smallest number in a list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code text_match_zero_one>
  MAKE_FUNCTION 0
  STORE_NAME text_match_zero_one
  RETURN_CONST None
END
CODE text_match_zero_one(text)
  RESUME 0
  LOAD_CONST 'ab?'
  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_zero_one(text):
    patterns = 'ab?'
    if re.search(patterns, text):
        return 'Found a match!'
    else:
        return 'Not matched!'

Prompt: Write a function that matches a string that has an a followed by zero or one 'b'.

assert text_match_zero_one("ac")==('Found a match!')

assert text_match_zero_one("abbbba")==('Found a match!')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_reverse_pairs>
  MAKE_FUNCTION 0
  STORE_NAME count_reverse_pairs
  RETURN_CONST None
END
CODE count_reverse_pairs(test_list)
  RESUME 0
  LOAD_GLOBAL NULL + sum
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST test_list
  CALL 1
  CALL 2
  GET_ITER
  LOAD_FAST_AND_CLEAR idx
  LOAD_FAST_AND_CLEAR idxn
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L7
  STORE_FAST idx
  LOAD_GLOBAL NULL + range
  LOAD_FAST idx
  LOAD_GLOBAL NULL + len
  LOAD_FAST test_list
  CALL 1
  CALL 2
  GET_ITER
L3:
  FOR_ITER L6
  STORE_FAST idxn
  LOAD_FAST test_list
  LOAD_FAST idxn
  BINARY_SUBSCR
  LOAD_GLOBAL NULL + str
  LOAD_CONST ''
  LOAD_ATTR NULL|self + join
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + reversed
  LOAD_FAST test_list
  LOAD_FAST idx
  BINARY_SUBSCR
  CALL 1
  CALL 1
  CALL 1
  CALL 1
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L5
L4:
  JUMP_BACKWARD L3
L5:
  LOAD_CONST 1
  LIST_APPEND 3
  JUMP_BACKWARD L3
L6:
  END_FOR
  JUMP_BACKWARD L2
L7:
  END_FOR
L8:
  SWAP 3
  STORE_FAST idxn
  STORE_FAST idx
  CALL 1
  STORE_FAST res
  LOAD_GLOBAL NULL + str
  LOAD_FAST res
  CALL 1
  RETURN_VALUE
L9:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST idxn
  STORE_FAST idx
  RERAISE 0
  EXC try=L1..L4 -> handler=L9 depth=5 lasti=False
  EXC try=L5..L8 -> handler=L9 depth=5 lasti=False
END

def count_reverse_pairs(test_list):
    res = sum([1 for idx in range(0, len(test_list)) for idxn in range(idx, len(test_list)) if test_list[idxn] == str(''.join(list(reversed(test_list[idx]))))])
    return str(res)

Prompt: Write a function to count the pairs of reverse strings in the given string list.

assert count_reverse_pairs(["julia", "best", "tseb", "for", "ailuj"])== '2'

assert count_reverse_pairs(["geeks", "best", "for", "skeeg"]) == '1'

assert count_reverse_pairs(["makes", "best", "sekam", "for", "rof"]) == '2'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code unique_sublists>
  MAKE_FUNCTION 0
  STORE_NAME unique_sublists
  RETURN_CONST None
END
CODE unique_sublists(list1)
  RESUME 0
  BUILD_MAP 0
  STORE_FAST result
  LOAD_FAST list1
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST l
  LOAD_FAST result
  LOAD_ATTR NULL|self + setdefault
  LOAD_GLOBAL NULL + tuple
  LOAD_FAST l
  CALL 1
  LOAD_GLOBAL NULL + list
  CALL 0
  CALL 2
  LOAD_ATTR NULL|self + append
  LOAD_CONST 1
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST result
  LOAD_ATTR NULL|self + items
  CALL 0
  GET_ITER
L3:
  FOR_ITER L4
  UNPACK_SEQUENCE 2
  STORE_FAST a
  STORE_FAST b
  LOAD_GLOBAL NULL + sum
  LOAD_FAST b
  CALL 1
  LOAD_FAST result
  LOAD_FAST a
  STORE_SUBSCR
  JUMP_BACKWARD L3
L4:
  END_FOR
  LOAD_FAST result
  RETURN_VALUE
END

def unique_sublists(list1):
    result = {}
    for l in list1:
        result.setdefault(tuple(l), list()).append(1)
    for a, b in result.items():
        result[a] = sum(b)
    return result

Prompt: Write a function to count number of unique lists within a list.

assert unique_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']])=={('green', 'orange'): 2, ('black',): 1, ('white',): 1}


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_decimal>
  MAKE_FUNCTION 0
  STORE_NAME is_decimal
  RETURN_CONST None
END
CODE is_decimal(num)
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_FAST re
  LOAD_FAST re
  LOAD_ATTR NULL|self + compile
  LOAD_CONST '^[0-9]+(\\.[0-9]{1,2})?$'
  CALL 1
  STORE_FAST dnumre
  LOAD_FAST dnumre
  LOAD_ATTR NULL|self + search
  LOAD_FAST num
  CALL 1
  STORE_FAST result
  LOAD_GLOBAL NULL + bool
  LOAD_FAST result
  CALL 1
  RETURN_VALUE
END

def is_decimal(num):
    import re
    dnumre = re.compile('^[0-9]+(\\.[0-9]{1,2})?$')
    result = dnumre.search(num)
    return bool(result)

Prompt: Write a function to check a decimal with a precision of 2.

assert is_decimal('123.11')==True
assert is_decimal('e666.86')==False
assert is_decimal('3.124587')==False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code unique_Element>
  MAKE_FUNCTION 0
  STORE_NAME unique_Element
  RETURN_CONST None
END
CODE unique_Element(arr, n)
  RESUME 0
  LOAD_GLOBAL NULL + set
  LOAD_FAST arr
  CALL 1
  STORE_FAST s
  LOAD_GLOBAL NULL + len
  LOAD_FAST s
  CALL 1
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'YES'
L1:
  RETURN_CONST 'NO'
END

def unique_Element(arr, n):
    s = set(arr)
    if len(s) == 1:
        return 'YES'
    else:
        return 'NO'

Prompt: Write a python function to check whether an array contains only one distinct element or not.

assert unique_Element([1,1,1],3) == 'YES'

assert unique_Element([1,2,1,2],4) == 'NO'

assert unique_Element([1,2,3,4,5],5) == 'NO'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code arc_length>
  MAKE_FUNCTION 0
  STORE_NAME arc_length
  RETURN_CONST None
END
CODE arc_length(d, a)
  RESUME 0
  LOAD_CONST 3.142857142857143
  STORE_FAST pi
  LOAD_FAST a
  LOAD_CONST 360
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L1
  RETURN_CONST None
L1:
  LOAD_FAST pi
  LOAD_FAST d
  BINARY_OP *
  LOAD_FAST a
  LOAD_CONST 360
  BINARY_OP /
  BINARY_OP *
  STORE_FAST arclength
  LOAD_FAST arclength
  RETURN_VALUE
END

def arc_length(d, a):
    pi = 22 / 7
    if a >= 360:
        return None
    arclength = pi * d * (a / 360)
    return arclength

Prompt: Write a function to caluclate arc length of an angle.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_monthnumber_number>
  MAKE_FUNCTION 0
  STORE_NAME check_monthnumber_number
  RETURN_CONST None
END
CODE check_monthnumber_number(monthnum3)
  RESUME 0
  LOAD_FAST monthnum3
  LOAD_CONST 4
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L1
  LOAD_FAST monthnum3
  LOAD_CONST 6
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L1
  LOAD_FAST monthnum3
  LOAD_CONST 9
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L1
  LOAD_FAST monthnum3
  LOAD_CONST 11
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
L1:
  RETURN_CONST True
L2:
  RETURN_CONST False
END

def check_monthnumber_number(monthnum3):
    if monthnum3 == 4 or monthnum3 == 6 or monthnum3 == 9 or (monthnum3 == 11):
        return True
    else:
        return False

Prompt: Write a function to check whether the given month number contains 30 days or not.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_Min_Diff>
  MAKE_FUNCTION 0
  STORE_NAME find_Min_Diff
  RETURN_CONST None
END
CODE find_Min_Diff(arr, n)
  RESUME 0
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST arr
  CALL 1
  STORE_FAST arr
  LOAD_CONST 100000000000000000000
  STORE_FAST diff
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST arr
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP -
  LOAD_FAST diff
  COMPARE_OP <
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST arr
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP -
  STORE_FAST diff
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST diff
  RETURN_VALUE
END

def find_Min_Diff(arr, n):
    arr = sorted(arr)
    diff = 10 ** 20
    for i in range(n - 1):
        if arr[i + 1] - arr[i] < diff:
            diff = arr[i + 1] - arr[i]
    return diff

Prompt: Write a python function to find the minimum difference between any two elements in a given array.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code number_ctr>
  MAKE_FUNCTION 0
  STORE_NAME number_ctr
  RETURN_CONST None
END
CODE number_ctr(str)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST number_ctr
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST str
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L4
  STORE_FAST i
  LOAD_FAST str
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST '0'
  COMPARE_OP >=
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST str
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST '9'
  COMPARE_OP <=
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L1
L3:
  LOAD_FAST number_ctr
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST number_ctr
  JUMP_BACKWARD L1
L4:
  END_FOR
  LOAD_FAST number_ctr
  RETURN_VALUE
END

def number_ctr(str):
    number_ctr = 0
    for i in range(len(str)):
        if str[i] >= '0' and str[i] <= '9':
            number_ctr += 1
    return number_ctr

Prompt: Write a python function to count numeric values in a given string.

assert number_ctr('program2bedone') == 1


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code is_polite>
  MAKE_FUNCTION 0
  STORE_NAME is_polite
  RETURN_CONST None
END
CODE is_polite(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST n
  LOAD_GLOBAL NULL + int
  LOAD_FAST n
  LOAD_GLOBAL NULL + math
  LOAD_ATTR log
  LOAD_FAST n
  LOAD_GLOBAL NULL + math
  LOAD_ATTR log
  LOAD_FAST n
  LOAD_CONST 2
  CALL 2
  BINARY_OP +
  LOAD_CONST 2
  CALL 2
  BINARY_OP +
  CALL 1
  RETURN_VALUE
END

import math

def is_polite(n):
    n = n + 1
    return int(n + math.log(n + math.log(n, 2), 2))

Prompt: Write a function to find nth polite number.

assert is_polite(7) == 11
assert is_polite(4) == 7
assert is_polite(9) == 13


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code pair_wise>
  MAKE_FUNCTION 0
  STORE_NAME pair_wise
  RETURN_CONST None
END
CODE pair_wise(l1)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST temp
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST l1
  CALL 1
  LOAD_CONST 1
  BINARY_OP -
  CALL 1
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST l1
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST l1
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SUBSCR
  STORE_FAST next_element
  STORE_FAST current_element
  LOAD_FAST current_element
  LOAD_FAST next_element
  BUILD_TUPLE 2
  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

def pair_wise(l1):
    temp = []
    for i in range(len(l1) - 1):
        current_element, next_element = (l1[i], l1[i + 1])
        x = (current_element, next_element)
        temp.append(x)
    return temp

Prompt: Write a function to iterate over all pairs of consecutive items in a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_Pairs_Count>
  MAKE_FUNCTION 0
  STORE_NAME get_Pairs_Count
  RETURN_CONST None
END
CODE get_Pairs_Count(arr, n, sum)
  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 L5
  STORE_FAST i
  LOAD_GLOBAL NULL + range
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST n
  CALL 2
  GET_ITER
L2:
  FOR_ITER L4
  STORE_FAST j
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST j
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_FAST sum
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L2
L3:
  LOAD_FAST count
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST count
  JUMP_BACKWARD L2
L4:
  END_FOR
  JUMP_BACKWARD L1
L5:
  END_FOR
  LOAD_FAST count
  RETURN_VALUE
END

def get_Pairs_Count(arr, n, sum):
    count = 0
    for i in range(0, n):
        for j in range(i + 1, n):
            if arr[i] + arr[j] == sum:
                count += 1
    return count

Prompt: Write a python function to count the number of pairs whose sum is equal to ‘sum’.

assert get_Pairs_Count([1,-2,3],3,1) == 1


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_Odd_Parity>
  MAKE_FUNCTION 0
  STORE_NAME check_Odd_Parity
  RETURN_CONST None
END
CODE check_Odd_Parity(x)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST parity
  LOAD_FAST x
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST x
  LOAD_FAST x
  LOAD_CONST 1
  BINARY_OP -
  BINARY_OP &
  STORE_FAST x
  LOAD_FAST parity
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST parity
  LOAD_FAST x
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST parity
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  RETURN_CONST True
L3:
  RETURN_CONST False
END

def check_Odd_Parity(x):
    parity = 0
    while x != 0:
        x = x & x - 1
        parity += 1
    if parity % 2 == 1:
        return True
    else:
        return False

Prompt: Write a python function to check for odd parity of a given number.

assert check_Odd_Parity(13) == True
assert check_Odd_Parity(21) == True
assert check_Odd_Parity(18) == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code Diff>
  MAKE_FUNCTION 0
  STORE_NAME Diff
  RETURN_CONST None
END
CODE Diff(li1, li2)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + set
  LOAD_FAST li1
  CALL 1
  LOAD_GLOBAL NULL + set
  LOAD_FAST li2
  CALL 1
  BINARY_OP -
  CALL 1
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + set
  LOAD_FAST li2
  CALL 1
  LOAD_GLOBAL NULL + set
  LOAD_FAST li1
  CALL 1
  BINARY_OP -
  CALL 1
  BINARY_OP +
  CALL 1
  RETURN_VALUE
END

def Diff(li1, li2):
    return list(list(set(li1) - set(li2)) + list(set(li2) - set(li1)))

Prompt: Write a python function to get the difference between two lists.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code odd_Num_Sum>
  MAKE_FUNCTION 0
  STORE_NAME odd_Num_Sum
  RETURN_CONST None
END
CODE odd_Num_Sum(n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST j
  LOAD_CONST 0
  STORE_FAST sm
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_CONST 2
  LOAD_FAST i
  BINARY_OP *
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST j
  LOAD_FAST sm
  LOAD_FAST j
  LOAD_FAST j
  BINARY_OP *
  LOAD_FAST j
  BINARY_OP *
  LOAD_FAST j
  BINARY_OP *
  BINARY_OP +
  STORE_FAST sm
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST sm
  RETURN_VALUE
END

def odd_Num_Sum(n):
    j = 0
    sm = 0
    for i in range(1, n + 1):
        j = 2 * i - 1
        sm = sm + j * j * j * j
    return sm

Prompt: Write a python function to find the sum of fourth power of first n odd natural numbers.

assert odd_Num_Sum(2) == 82
assert odd_Num_Sum(3) == 707
assert odd_Num_Sum(4) == 3108


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('deque',)
  IMPORT_NAME collections
  IMPORT_FROM deque
  STORE_NAME deque
  POP_TOP
  LOAD_CONST <code check_expression>
  MAKE_FUNCTION 0
  STORE_NAME check_expression
  RETURN_CONST None
END
CODE check_expression(exp)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST exp
  CALL 1
  LOAD_CONST 1
  BINARY_OP &
  POP_JUMP_IF_FALSE L1
  RETURN_CONST False
L1:
  LOAD_GLOBAL NULL + deque
  CALL 0
  STORE_FAST stack
  LOAD_FAST exp
  GET_ITER
L2:
  FOR_ITER L11
  STORE_FAST ch
  LOAD_FAST ch
  LOAD_CONST '('
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L3
  LOAD_FAST ch
  LOAD_CONST '{'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L3
  LOAD_FAST ch
  LOAD_CONST '['
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L4
L3:
  LOAD_FAST stack
  LOAD_ATTR NULL|self + append
  LOAD_FAST ch
  CALL 1
  POP_TOP
L4:
  LOAD_FAST ch
  LOAD_CONST ')'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L5
  LOAD_FAST ch
  LOAD_CONST '}'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L5
  LOAD_FAST ch
  LOAD_CONST ']'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L5
  JUMP_BACKWARD L2
L5:
  LOAD_FAST stack
  POP_JUMP_IF_TRUE L6
  POP_TOP
  RETURN_CONST False
L6:
  LOAD_FAST stack
  LOAD_ATTR NULL|self + pop
  CALL 0
  STORE_FAST top
  LOAD_FAST top
  LOAD_CONST '('
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L7
  LOAD_FAST ch
  LOAD_CONST ')'
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L10
L7:
  LOAD_FAST top
  LOAD_CONST '{'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L8
  LOAD_FAST ch
  LOAD_CONST '}'
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L10
L8:
  LOAD_FAST top
  LOAD_CONST '['
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L9
  JUMP_BACKWARD L2
L9:
  LOAD_FAST ch
  LOAD_CONST ']'
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L10
  JUMP_BACKWARD L2
L10:
  POP_TOP
  RETURN_CONST False
L11:
  END_FOR
  LOAD_FAST stack
  UNARY_NOT
  RETURN_VALUE
END

from collections import deque

def check_expression(exp):
    if len(exp) & 1:
        return False
    stack = deque()
    for ch in exp:
        if ch == '(' or ch == '{' or ch == '[':
            stack.append(ch)
        if ch == ')' or ch == '}' or ch == ']':
            if not stack:
                return False
            top = stack.pop()
            if top == '(' and ch != ')' or (top == '{' and ch != '}' or (top == '[' and ch != ']')):
                return False
    return not stack

Prompt: Write a function to check if the given expression is balanced or not.

assert check_expression("{()}[{}]") == True

assert check_expression("{()}[{]") == False

assert check_expression("{()}[{}][]({})") == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code remove_length>
  MAKE_FUNCTION 0
  STORE_NAME remove_length
  RETURN_CONST None
END
CODE remove_length(test_str, K)
  RESUME 0
  LOAD_FAST test_str
  LOAD_ATTR NULL|self + split
  CALL 0
  STORE_FAST temp
  LOAD_FAST temp
  GET_ITER
  LOAD_FAST_AND_CLEAR ele
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  STORE_FAST ele
  LOAD_GLOBAL NULL + len
  LOAD_FAST ele
  CALL 1
  LOAD_FAST K
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST ele
  LIST_APPEND 2
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  STORE_FAST res
  STORE_FAST ele
  LOAD_CONST ' '
  LOAD_ATTR NULL|self + join
  LOAD_FAST res
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
L7:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ele
  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_length(test_str, K):
    temp = test_str.split()
    res = [ele for ele in temp if len(ele) != K]
    res = ' '.join(res)
    return res

Prompt: Write a function to remove all the words with k length in the given string.

assert remove_length('The person is most value tet', 3) == 'person is most value'

assert remove_length('If you told me about this ok', 4) == 'If you me about ok'

assert remove_length('Forces of darkeness is come into the play', 4) == 'Forces of darkeness is the'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST '^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$'
  STORE_NAME regex
  LOAD_CONST <code check_email>
  MAKE_FUNCTION 0
  STORE_NAME check_email
  RETURN_CONST None
END
CODE check_email(email)
  RESUME 0
  LOAD_GLOBAL NULL + re
  LOAD_ATTR search
  LOAD_GLOBAL regex
  LOAD_FAST email
  CALL 2
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'Valid Email'
L1:
  RETURN_CONST 'Invalid Email'
END

import re
regex = '^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$'

def check_email(email):
    if re.search(regex, email):
        return 'Valid Email'
    else:
        return 'Invalid Email'

Prompt: Write a function to check if the string is a valid email address or not using regex.

assert check_email("ankitrai326@gmail.com") == 'Valid Email'

assert check_email("my.ownsite@ourearth.org") == 'Valid Email'

assert check_email("ankitaoie326.com") == 'Invalid Email'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code odd_position>
  MAKE_FUNCTION 0
  STORE_NAME odd_position
  RETURN_CONST None
END
CODE odd_position(nums)
  MAKE_CELL nums
  RESUME 0
  LOAD_GLOBAL NULL + all
  LOAD_CLOSURE nums
  BUILD_TUPLE 1
  LOAD_CONST <code odd_position.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_DEREF nums
  CALL 1
  CALL 1
  GET_ITER
  CALL 0
  CALL 1
  RETURN_VALUE
END
CODE odd_position.<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 nums
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST 2
  BINARY_OP %
  LOAD_FAST i
  LOAD_CONST 2
  BINARY_OP %
  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 odd_position(nums):
    return all((nums[i] % 2 == i % 2 for i in range(len(nums))))

Prompt: Write a python function to check whether every odd index contains odd numbers of a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_vowels>
  MAKE_FUNCTION 0
  STORE_NAME count_vowels
  RETURN_CONST None
END
CODE count_vowels(test_str)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST res
  BUILD_LIST 0
  LOAD_CONST ('a', 'e', 'i', 'o', 'u')
  LIST_EXTEND 1
  STORE_FAST vow_list
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_GLOBAL NULL + len
  LOAD_FAST test_str
  CALL 1
  LOAD_CONST 1
  BINARY_OP -
  CALL 2
  GET_ITER
L1:
  FOR_ITER L4
  STORE_FAST idx
  LOAD_FAST test_str
  LOAD_FAST idx
  BINARY_SUBSCR
  LOAD_FAST vow_list
  CONTAINS_OP 1
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST test_str
  LOAD_FAST idx
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_FAST vow_list
  CONTAINS_OP 0
  POP_JUMP_IF_TRUE L3
  LOAD_FAST test_str
  LOAD_FAST idx
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SUBSCR
  LOAD_FAST vow_list
  CONTAINS_OP 0
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L1
L3:
  LOAD_FAST res
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST res
  JUMP_BACKWARD L1
L4:
  END_FOR
  LOAD_FAST test_str
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST vow_list
  CONTAINS_OP 1
  POP_JUMP_IF_FALSE L5
  LOAD_FAST test_str
  LOAD_CONST 1
  BINARY_SUBSCR
  LOAD_FAST vow_list
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L5
  LOAD_FAST res
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST res
L5:
  LOAD_FAST test_str
  LOAD_CONST -1
  BINARY_SUBSCR
  LOAD_FAST vow_list
  CONTAINS_OP 1
  POP_JUMP_IF_FALSE L6
  LOAD_FAST test_str
  LOAD_CONST -2
  BINARY_SUBSCR
  LOAD_FAST vow_list
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L6
  LOAD_FAST res
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST res
L6:
  LOAD_FAST res
  RETURN_VALUE
END

def count_vowels(test_str):
    res = 0
    vow_list = ['a', 'e', 'i', 'o', 'u']
    for idx in range(1, len(test_str) - 1):
        if test_str[idx] not in vow_list and (test_str[idx - 1] in vow_list or test_str[idx + 1] in vow_list):
            res += 1
    if test_str[0] not in vow_list and test_str[1] in vow_list:
        res += 1
    if test_str[-1] not in vow_list and test_str[-2] in vow_list:
        res += 1
    return res

Prompt: Write a function to count those characters which have vowels as their neighbors in the given string.

assert count_vowels('bestinstareels') == 7

assert count_vowels('partofthejourneyistheend') == 12


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('groupby',)
  IMPORT_NAME itertools
  IMPORT_FROM groupby
  STORE_NAME groupby
  POP_TOP
  LOAD_CONST <code pack_consecutive_duplicates>
  MAKE_FUNCTION 0
  STORE_NAME pack_consecutive_duplicates
  RETURN_CONST None
END
CODE pack_consecutive_duplicates(list1)
  RESUME 0
  LOAD_GLOBAL NULL + groupby
  LOAD_FAST list1
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR key
  LOAD_FAST_AND_CLEAR group
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST key
  STORE_FAST group
  LOAD_GLOBAL NULL + list
  LOAD_FAST group
  CALL 1
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  SWAP 3
  STORE_FAST group
  STORE_FAST key
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST group
  STORE_FAST key
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=3 lasti=False
END

from itertools import groupby

def pack_consecutive_duplicates(list1):
    return [list(group) for key, group in groupby(list1)]

Prompt: Write a function to pack consecutive duplicates of a given list elements into sublists.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('combinations',)
  IMPORT_NAME itertools
  IMPORT_FROM combinations
  STORE_NAME combinations
  POP_TOP
  LOAD_CONST <code find_combinations>
  MAKE_FUNCTION 0
  STORE_NAME find_combinations
  RETURN_CONST None
END
CODE find_combinations(test_list)
  RESUME 0
  LOAD_GLOBAL NULL + combinations
  LOAD_FAST test_list
  LOAD_CONST 2
  CALL 2
  GET_ITER
  LOAD_FAST_AND_CLEAR a1
  LOAD_FAST_AND_CLEAR a2
  LOAD_FAST_AND_CLEAR b1
  LOAD_FAST_AND_CLEAR b2
  SWAP 5
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  UNPACK_SEQUENCE 2
  STORE_FAST a1
  STORE_FAST a2
  UNPACK_SEQUENCE 2
  STORE_FAST b1
  STORE_FAST b2
  LOAD_FAST b1
  LOAD_FAST a1
  BINARY_OP +
  LOAD_FAST b2
  LOAD_FAST a2
  BINARY_OP +
  BUILD_TUPLE 2
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST res
  STORE_FAST b1
  STORE_FAST a2
  STORE_FAST a1
  STORE_FAST b2
  LOAD_FAST res
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 5
  STORE_FAST b2
  STORE_FAST b1
  STORE_FAST a2
  STORE_FAST a1
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=5 lasti=False
END

from itertools import combinations

def find_combinations(test_list):
    res = [(b1 + a1, b2 + a2) for (a1, a2), (b1, b2) in combinations(test_list, 2)]
    return res

Prompt: Write a function to find the combinations of sums with tuples in the given tuple list.


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

import math

def count_Divisors(n):
    count = 0
    for i in range(1, int(math.sqrt(n)) + 2):
        if n % i == 0:
            if n // i == i:
                count = count + 1
            else:
                count = count + 2
    if count % 2 == 0:
        return 'Even'
    else:
        return 'Odd'

Prompt: Write a python function to check whether the count of divisors is even or odd.

assert count_Divisors(10) == "Even"
assert count_Divisors(100) == "Odd"
assert count_Divisors(125) == "Even"


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code Odd_Length_Sum>
  MAKE_FUNCTION 0
  STORE_NAME Odd_Length_Sum
  RETURN_CONST None
END
CODE Odd_Length_Sum(arr)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST Sum
  LOAD_GLOBAL NULL + len
  LOAD_FAST arr
  CALL 1
  STORE_FAST l
  LOAD_GLOBAL NULL + range
  LOAD_FAST l
  CALL 1
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST Sum
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST l
  LOAD_FAST i
  BINARY_OP -
  BINARY_OP *
  LOAD_CONST 1
  BINARY_OP +
  LOAD_CONST 2
  BINARY_OP //
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP *
  BINARY_OP +=
  STORE_FAST Sum
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST Sum
  RETURN_VALUE
END

def Odd_Length_Sum(arr):
    Sum = 0
    l = len(arr)
    for i in range(l):
        Sum += ((i + 1) * (l - i) + 1) // 2 * arr[i]
    return Sum

Prompt: Write a python function to find the sum of all odd length subarrays.

assert Odd_Length_Sum([1,2,4]) == 14
assert Odd_Length_Sum([1,2,1,2]) == 15
assert Odd_Length_Sum([1,7]) == 8


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code mul_even_odd>
  MAKE_FUNCTION 0
  STORE_NAME mul_even_odd
  RETURN_CONST None
END
CODE mul_even_odd(list1)
  RESUME 0
  LOAD_GLOBAL NULL + next
  LOAD_CONST <code mul_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 mul_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 mul_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 mul_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 mul_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 product of first even and odd number of a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME bisect
  STORE_NAME bisect
  LOAD_CONST <code right_insertion>
  MAKE_FUNCTION 0
  STORE_NAME right_insertion
  RETURN_CONST None
END
CODE right_insertion(a, x)
  RESUME 0
  LOAD_GLOBAL NULL + bisect
  LOAD_ATTR bisect_right
  LOAD_FAST a
  LOAD_FAST x
  CALL 2
  STORE_FAST i
  LOAD_FAST i
  RETURN_VALUE
END

import bisect

def right_insertion(a, x):
    i = bisect.bisect_right(a, x)
    return i

Prompt: Write a function to locate the right insertion point for a specified value in sorted order.

assert right_insertion([1,2,4,5],6)==4
assert right_insertion([1,2,4,5],3)==2
assert right_insertion([1,2,4,5],7)==4


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code text_match_three>
  MAKE_FUNCTION 0
  STORE_NAME text_match_three
  RETURN_CONST None
END
CODE text_match_three(text)
  RESUME 0
  LOAD_CONST 'ab{3}?'
  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_three(text):
    patterns = 'ab{3}?'
    if re.search(patterns, text):
        return 'Found a match!'
    else:
        return 'Not matched!'

Prompt: Write a function that matches a string that has an a followed by three 'b'.

assert text_match_three("abbbba")==('Found a match!')


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

def new_tuple(test_list, test_str):
    res = tuple(test_list + [test_str])
    return res

Prompt: Write a function to create a new tuple from the given string and list.

assert new_tuple(["WEB", "is"], "best") == ('WEB', 'is', 'best')

assert new_tuple(["We", "are"], "Developers") == ('We', 'are', 'Developers')

assert new_tuple(["Part", "is"], "Wrong") == ('Part', 'is', 'Wrong')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('tan', 'pi')
  IMPORT_NAME math
  IMPORT_FROM tan
  STORE_NAME tan
  IMPORT_FROM pi
  STORE_NAME pi
  POP_TOP
  LOAD_CONST <code perimeter_polygon>
  MAKE_FUNCTION 0
  STORE_NAME perimeter_polygon
  RETURN_CONST None
END
CODE perimeter_polygon(s, l)
  RESUME 0
  LOAD_FAST s
  LOAD_FAST l
  BINARY_OP *
  STORE_FAST perimeter
  LOAD_FAST perimeter
  RETURN_VALUE
END

from math import tan, pi

def perimeter_polygon(s, l):
    perimeter = s * l
    return perimeter

Prompt: Write a function to calculate the perimeter of a regular polygon.

assert perimeter_polygon(4,20)==80
assert perimeter_polygon(10,15)==150
assert perimeter_polygon(9,7)==63


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code remove_nested>
  MAKE_FUNCTION 0
  STORE_NAME remove_nested
  RETURN_CONST None
END
CODE remove_nested(test_tup)
  RESUME 0
  LOAD_GLOBAL NULL + tuple
  CALL 0
  STORE_FAST res
  LOAD_GLOBAL NULL + enumerate
  LOAD_FAST test_tup
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST count
  STORE_FAST ele
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST ele
  LOAD_GLOBAL tuple
  CALL 2
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST res
  LOAD_FAST ele
  BUILD_TUPLE 1
  BINARY_OP +
  STORE_FAST res
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST res
  RETURN_VALUE
END

def remove_nested(test_tup):
    res = tuple()
    for count, ele in enumerate(test_tup):
        if not isinstance(ele, tuple):
            res = res + (ele,)
    return res

Prompt: Write a function to remove the nested record from the given tuple.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code last>
  MAKE_FUNCTION 0
  STORE_NAME last
  RETURN_CONST None
END
CODE last(arr, x, n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST low
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST high
  LOAD_CONST -1
  STORE_FAST res
  LOAD_FAST low
  LOAD_FAST high
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
L1:
  LOAD_FAST low
  LOAD_FAST high
  BINARY_OP +
  LOAD_CONST 2
  BINARY_OP //
  STORE_FAST mid
  LOAD_FAST arr
  LOAD_FAST mid
  BINARY_SUBSCR
  LOAD_FAST x
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST high
  JUMP_FORWARD L4
L2:
  LOAD_FAST arr
  LOAD_FAST mid
  BINARY_SUBSCR
  LOAD_FAST x
  COMPARE_OP <
  POP_JUMP_IF_FALSE L3
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST low
  JUMP_FORWARD L4
L3:
  LOAD_FAST mid
  STORE_FAST res
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST low
L4:
  LOAD_FAST low
  LOAD_FAST high
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
  JUMP_BACKWARD L1
L5:
  LOAD_FAST res
  RETURN_VALUE
END

def last(arr, x, n):
    low = 0
    high = n - 1
    res = -1
    while low <= high:
        mid = (low + high) // 2
        if arr[mid] > x:
            high = mid - 1
        elif arr[mid] < x:
            low = mid + 1
        else:
            res = mid
            low = mid + 1
    return res

Prompt: Write a python function to find the last position of an element in a sorted array.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code text_starta_endb>
  MAKE_FUNCTION 0
  STORE_NAME text_starta_endb
  RETURN_CONST None
END
CODE text_starta_endb(text)
  RESUME 0
  LOAD_CONST 'a.*?b$'
  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_starta_endb(text):
    patterns = 'a.*?b$'
    if re.search(patterns, text):
        return 'Found a match!'
    else:
        return 'Not matched!'

Prompt: Write a function that matches a string that has an 'a' followed by anything, ending in 'b'.

assert text_starta_endb("aabbbb")==('Found a match!')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sum_Odd>
  MAKE_FUNCTION 0
  STORE_NAME sum_Odd
  LOAD_CONST <code sum_in_Range>
  MAKE_FUNCTION 0
  STORE_NAME sum_in_Range
  RETURN_CONST None
END
CODE sum_Odd(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  LOAD_CONST 2
  BINARY_OP //
  STORE_FAST terms
  LOAD_FAST terms
  LOAD_FAST terms
  BINARY_OP *
  STORE_FAST sum1
  LOAD_FAST sum1
  RETURN_VALUE
END
CODE sum_in_Range(l, r)
  RESUME 0
  LOAD_GLOBAL NULL + sum_Odd
  LOAD_FAST r
  CALL 1
  LOAD_GLOBAL NULL + sum_Odd
  LOAD_FAST l
  LOAD_CONST 1
  BINARY_OP -
  CALL 1
  BINARY_OP -
  RETURN_VALUE
END

def sum_Odd(n):
    terms = (n + 1) // 2
    sum1 = terms * terms
    return sum1

def sum_in_Range(l, r):
    return sum_Odd(r) - sum_Odd(l - 1)

Prompt: Write a python function to find the sum of all odd natural numbers within the range l and r.

assert sum_in_Range(2,5) == 8
assert sum_in_Range(5,7) == 12
assert sum_in_Range(7,13) == 40


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code test_three_equal>
  MAKE_FUNCTION 0
  STORE_NAME test_three_equal
  RETURN_CONST None
END
CODE test_three_equal(x, y, z)
  RESUME 0
  LOAD_GLOBAL NULL + set
  LOAD_FAST x
  LOAD_FAST y
  LOAD_FAST z
  BUILD_LIST 3
  CALL 1
  STORE_FAST result
  LOAD_GLOBAL NULL + len
  LOAD_FAST result
  CALL 1
  LOAD_CONST 3
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 0
L1:
  LOAD_CONST 4
  LOAD_GLOBAL NULL + len
  LOAD_FAST result
  CALL 1
  BINARY_OP -
  RETURN_VALUE
END

def test_three_equal(x, y, z):
    result = set([x, y, z])
    if len(result) == 3:
        return 0
    else:
        return 4 - len(result)

Prompt: Write a python function to count the number of equal numbers from three given integers.

assert test_three_equal(1,1,1) == 3
assert test_three_equal(-1,-2,-3) == 0
assert test_three_equal(1,2,2) == 2


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_Rotation>
  MAKE_FUNCTION 0
  STORE_NAME count_Rotation
  RETURN_CONST None
END
CODE count_Rotation(arr, n)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST n
  CALL 2
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP -
  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 0
END

def count_Rotation(arr, n):
    for i in range(1, n):
        if arr[i] < arr[i - 1]:
            return i
    return 0

Prompt: Write a python function to count the number of rotations required to generate a sorted array.

assert count_Rotation([4,5,1,2,3],5) == 2


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_Perfect_Square>
  MAKE_FUNCTION 0
  STORE_NAME is_Perfect_Square
  RETURN_CONST None
END
CODE is_Perfect_Square(n)
  RESUME 0
  LOAD_CONST 1
  STORE_FAST i
  LOAD_FAST i
  LOAD_FAST i
  BINARY_OP *
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L3
L1:
  LOAD_FAST n
  LOAD_FAST i
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST n
  LOAD_FAST i
  BINARY_OP /
  LOAD_FAST i
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  RETURN_CONST True
L2:
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST i
  LOAD_FAST i
  LOAD_FAST i
  BINARY_OP *
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L3
  JUMP_BACKWARD L1
L3:
  RETURN_CONST False
END

def is_Perfect_Square(n):
    i = 1
    while i * i <= n:
        if n % i == 0 and n / i == i:
            return True
        i = i + 1
    return False

Prompt: Write a python function to check whether the given number is a perfect square or not.

assert is_Perfect_Square(10) == False
assert is_Perfect_Square(36) == True
assert is_Perfect_Square(14) == False


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

def is_Product_Even(arr, n):
    for i in range(0, n):
        if arr[i] & 1 == 0:
            return True
    return False

Prompt: Write a python function to check whether the product of numbers is even or not.

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

assert is_Product_Even([1,2,1,4],4) == True

assert is_Product_Even([1,1],2) == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code max_run_uppercase>
  MAKE_FUNCTION 0
  STORE_NAME max_run_uppercase
  RETURN_CONST None
END
CODE max_run_uppercase(test_str)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST cnt
  LOAD_CONST 0
  STORE_FAST res
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST test_str
  CALL 1
  CALL 2
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST idx
  LOAD_FAST test_str
  LOAD_FAST idx
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + isupper
  CALL 0
  POP_JUMP_IF_FALSE L2
  LOAD_FAST cnt
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST cnt
  JUMP_BACKWARD L1
L2:
  LOAD_FAST cnt
  STORE_FAST res
  LOAD_CONST 0
  STORE_FAST cnt
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST test_str
  LOAD_GLOBAL NULL + len
  LOAD_FAST test_str
  CALL 1
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + isupper
  CALL 0
  POP_JUMP_IF_FALSE L4
  LOAD_FAST cnt
  STORE_FAST res
L4:
  LOAD_FAST res
  RETURN_VALUE
END

def max_run_uppercase(test_str):
    cnt = 0
    res = 0
    for idx in range(0, len(test_str)):
        if test_str[idx].isupper():
            cnt += 1
        else:
            res = cnt
            cnt = 0
    if test_str[len(test_str) - 1].isupper():
        res = cnt
    return res

Prompt: Write a function to find maximum run of uppercase characters in the given string.

assert max_run_uppercase('GeMKSForGERksISBESt') == 5

assert max_run_uppercase('PrECIOusMOVemENTSYT') == 6

assert max_run_uppercase('GooGLEFluTTER') == 4


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code first_odd>
  MAKE_FUNCTION 0
  STORE_NAME first_odd
  RETURN_CONST None
END
CODE first_odd(nums)
  RESUME 0
  LOAD_GLOBAL NULL + next
  LOAD_CONST <code first_odd.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_FAST nums
  GET_ITER
  CALL 0
  LOAD_CONST -1
  CALL 2
  STORE_FAST first_odd
  LOAD_FAST first_odd
  RETURN_VALUE
END
CODE first_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 first_odd(nums):
    first_odd = next((el for el in nums if el % 2 != 0), -1)
    return first_odd

Prompt: Write a python function to find the first odd number in a given list of numbers.

assert first_odd([1,3,5]) == 1
assert first_odd([2,4,1,3]) == 1
assert first_odd ([8,9,1]) == 9


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

def check_K(test_tup, K):
    res = False
    for ele in test_tup:
        if ele == K:
            res = True
            break
    return res

Prompt: Write a function to check if the given tuples contain the k or not.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_smaller>
  MAKE_FUNCTION 0
  STORE_NAME check_smaller
  RETURN_CONST None
END
CODE check_smaller(test_tup1, test_tup2)
  RESUME 0
  LOAD_GLOBAL NULL + all
  LOAD_CONST <code check_smaller.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_GLOBAL NULL + zip
  LOAD_FAST test_tup1
  LOAD_FAST test_tup2
  CALL 2
  GET_ITER
  CALL 0
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END
CODE check_smaller.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST x
  STORE_FAST y
  LOAD_FAST x
  LOAD_FAST y
  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 check_smaller(test_tup1, test_tup2):
    res = all((x > y for x, y in zip(test_tup1, test_tup2)))
    return res

Prompt: Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple.

assert check_smaller((1, 2, 3), (2, 3, 4)) == False

assert check_smaller((4, 5, 6), (3, 4, 5)) == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_identical>
  MAKE_FUNCTION 0
  STORE_NAME check_identical
  RETURN_CONST None
END
CODE check_identical(test_list1, test_list2)
  RESUME 0
  LOAD_FAST test_list1
  LOAD_FAST test_list2
  COMPARE_OP ==
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END

def check_identical(test_list1, test_list2):
    res = test_list1 == test_list2
    return res

Prompt: Write a function to check if two lists of tuples are identical or not.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code rombus_area>
  MAKE_FUNCTION 0
  STORE_NAME rombus_area
  RETURN_CONST None
END
CODE rombus_area(p, q)
  RESUME 0
  LOAD_FAST p
  LOAD_FAST q
  BINARY_OP *
  LOAD_CONST 2
  BINARY_OP /
  STORE_FAST area
  LOAD_FAST area
  RETURN_VALUE
END

def rombus_area(p, q):
    area = p * q / 2
    return area

Prompt: Write a function to find the area of a rombus.

assert rombus_area(10,20)==100
assert rombus_area(10,5)==25
assert rombus_area(4,2)==4


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sort_by_dnf>
  MAKE_FUNCTION 0
  STORE_NAME sort_by_dnf
  RETURN_CONST None
END
CODE sort_by_dnf(arr, n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST low
  LOAD_CONST 0
  STORE_FAST mid
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST high
  LOAD_FAST mid
  LOAD_FAST high
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
L1:
  LOAD_FAST arr
  LOAD_FAST mid
  BINARY_SUBSCR
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST arr
  LOAD_FAST mid
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST low
  BINARY_SUBSCR
  SWAP 2
  LOAD_FAST arr
  LOAD_FAST low
  STORE_SUBSCR
  LOAD_FAST arr
  LOAD_FAST mid
  STORE_SUBSCR
  LOAD_FAST low
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST low
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST mid
  JUMP_FORWARD L4
L2:
  LOAD_FAST arr
  LOAD_FAST mid
  BINARY_SUBSCR
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_FAST mid
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST mid
  JUMP_FORWARD L4
L3:
  LOAD_FAST arr
  LOAD_FAST high
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST mid
  BINARY_SUBSCR
  SWAP 2
  LOAD_FAST arr
  LOAD_FAST mid
  STORE_SUBSCR
  LOAD_FAST arr
  LOAD_FAST high
  STORE_SUBSCR
  LOAD_FAST high
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST high
L4:
  LOAD_FAST mid
  LOAD_FAST high
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
  JUMP_BACKWARD L1
L5:
  LOAD_FAST arr
  RETURN_VALUE
END

def sort_by_dnf(arr, n):
    low = 0
    mid = 0
    high = n - 1
    while mid <= high:
        if arr[mid] == 0:
            arr[low], arr[mid] = (arr[mid], arr[low])
            low = low + 1
            mid = mid + 1
        elif arr[mid] == 1:
            mid = mid + 1
        else:
            arr[mid], arr[high] = (arr[high], arr[mid])
            high = high - 1
    return arr

Prompt: Write a function to sort the given array without using any sorting algorithm. the given array consists of only 0, 1, and 2.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code clear_tuple>
  MAKE_FUNCTION 0
  STORE_NAME clear_tuple
  RETURN_CONST None
END
CODE clear_tuple(test_tup)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_FAST test_tup
  CALL 1
  STORE_FAST temp
  LOAD_FAST temp
  LOAD_ATTR NULL|self + clear
  CALL 0
  POP_TOP
  LOAD_GLOBAL NULL + tuple
  LOAD_FAST temp
  CALL 1
  STORE_FAST test_tup
  LOAD_FAST test_tup
  RETURN_VALUE
END

def clear_tuple(test_tup):
    temp = list(test_tup)
    temp.clear()
    test_tup = tuple(temp)
    return test_tup

Prompt: Write a function to clear the values of the given tuples.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code div_of_nums>
  MAKE_FUNCTION 0
  STORE_NAME div_of_nums
  RETURN_CONST None
END
CODE div_of_nums(nums, m, n)
  MAKE_CELL m
  MAKE_CELL n
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + filter
  LOAD_CLOSURE m
  LOAD_CLOSURE n
  BUILD_TUPLE 2
  LOAD_CONST <code div_of_nums.<locals>.<lambda>>
  MAKE_FUNCTION closure
  LOAD_FAST nums
  CALL 2
  CALL 1
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END
CODE div_of_nums.<locals>.<lambda>(x)
  COPY_FREE_VARS 2
  RESUME 0
  LOAD_FAST x
  LOAD_DEREF m
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  COPY 1
  POP_JUMP_IF_TRUE L1
  POP_TOP
  LOAD_FAST x
  LOAD_DEREF n
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
L1:
  RETURN_VALUE
END

def div_of_nums(nums, m, n):
    result = list(filter(lambda x: x % m == 0 or x % n == 0, nums))
    return result

Prompt: Write a function to find numbers divisible by m or n from a list of numbers using lambda function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code lower_ctr>
  MAKE_FUNCTION 0
  STORE_NAME lower_ctr
  RETURN_CONST None
END
CODE lower_ctr(str)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST lower_ctr
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST str
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L4
  STORE_FAST i
  LOAD_FAST str
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST 'a'
  COMPARE_OP >=
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST str
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST 'z'
  COMPARE_OP <=
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L1
L3:
  LOAD_FAST lower_ctr
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST lower_ctr
  JUMP_BACKWARD L1
L4:
  END_FOR
  LOAD_FAST lower_ctr
  RETURN_VALUE
END

def lower_ctr(str):
    lower_ctr = 0
    for i in range(len(str)):
        if str[i] >= 'a' and str[i] <= 'z':
            lower_ctr += 1
    return lower_ctr

Prompt: Write a python function to count lower case letters in a given string.

assert lower_ctr('abc') == 3
assert lower_ctr('string') == 6
assert lower_ctr('Python') == 5


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_duplic>
  MAKE_FUNCTION 0
  STORE_NAME count_duplic
  RETURN_CONST None
END
CODE count_duplic(lists)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST element
  BUILD_LIST 0
  STORE_FAST frequency
  LOAD_FAST lists
  POP_JUMP_IF_TRUE L1
  LOAD_FAST element
  RETURN_VALUE
L1:
  LOAD_CONST 1
  STORE_FAST running_count
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST lists
  CALL 1
  LOAD_CONST 1
  BINARY_OP -
  CALL 1
  GET_ITER
L2:
  FOR_ITER L4
  STORE_FAST i
  LOAD_FAST lists
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST lists
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SUBSCR
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_FAST running_count
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST running_count
  JUMP_BACKWARD L2
L3:
  LOAD_FAST frequency
  LOAD_ATTR NULL|self + append
  LOAD_FAST running_count
  CALL 1
  POP_TOP
  LOAD_FAST element
  LOAD_ATTR NULL|self + append
  LOAD_FAST lists
  LOAD_FAST i
  BINARY_SUBSCR
  CALL 1
  POP_TOP
  LOAD_CONST 1
  STORE_FAST running_count
  JUMP_BACKWARD L2
L4:
  END_FOR
  LOAD_FAST frequency
  LOAD_ATTR NULL|self + append
  LOAD_FAST running_count
  CALL 1
  POP_TOP
  LOAD_FAST element
  LOAD_ATTR NULL|self + append
  LOAD_FAST lists
  LOAD_FAST_CHECK i
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SUBSCR
  CALL 1
  POP_TOP
  LOAD_FAST element
  LOAD_FAST frequency
  BUILD_TUPLE 2
  RETURN_VALUE
END

def count_duplic(lists):
    element = []
    frequency = []
    if not lists:
        return element
    running_count = 1
    for i in range(len(lists) - 1):
        if lists[i] == lists[i + 1]:
            running_count += 1
        else:
            frequency.append(running_count)
            element.append(lists[i])
            running_count = 1
    frequency.append(running_count)
    element.append(lists[i + 1])
    return (element, frequency)

Prompt: Write a function to count the frequency of consecutive duplicate elements in a given list of numbers.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_monthnum_number>
  MAKE_FUNCTION 0
  STORE_NAME check_monthnum_number
  RETURN_CONST None
END
CODE check_monthnum_number(monthnum1)
  RESUME 0
  LOAD_FAST monthnum1
  LOAD_CONST 2
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST True
L1:
  RETURN_CONST False
END

def check_monthnum_number(monthnum1):
    if monthnum1 == 2:
        return True
    else:
        return False

Prompt: Write a function to check whether the given month number contains 28 days or not.

assert check_monthnum_number(2)==True
assert check_monthnum_number(1)==False
assert check_monthnum_number(3)==False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code pass_validity>
  MAKE_FUNCTION 0
  STORE_NAME pass_validity
  RETURN_CONST None
END
CODE pass_validity(p)
  RESUME 0
  LOAD_CONST True
  STORE_FAST x
  LOAD_FAST x
  POP_JUMP_IF_FALSE L8
  LOAD_GLOBAL NULL + len
  LOAD_FAST p
  CALL 1
  LOAD_CONST 6
  COMPARE_OP <
  POP_JUMP_IF_TRUE L1
  LOAD_GLOBAL NULL + len
  LOAD_FAST p
  CALL 1
  LOAD_CONST 12
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
L1:
  JUMP_FORWARD L8
L2:
  LOAD_GLOBAL NULL + re
  LOAD_ATTR search
  LOAD_CONST '[a-z]'
  LOAD_FAST p
  CALL 2
  POP_JUMP_IF_TRUE L3
  JUMP_FORWARD L8
L3:
  LOAD_GLOBAL NULL + re
  LOAD_ATTR search
  LOAD_CONST '[0-9]'
  LOAD_FAST p
  CALL 2
  POP_JUMP_IF_TRUE L4
  JUMP_FORWARD L8
L4:
  LOAD_GLOBAL NULL + re
  LOAD_ATTR search
  LOAD_CONST '[A-Z]'
  LOAD_FAST p
  CALL 2
  POP_JUMP_IF_TRUE L5
  JUMP_FORWARD L8
L5:
  LOAD_GLOBAL NULL + re
  LOAD_ATTR search
  LOAD_CONST '[$#@]'
  LOAD_FAST p
  CALL 2
  POP_JUMP_IF_TRUE L6
  JUMP_FORWARD L8
L6:
  LOAD_GLOBAL NULL + re
  LOAD_ATTR search
  LOAD_CONST '\\s'
  LOAD_FAST p
  CALL 2
  POP_JUMP_IF_FALSE L7
  JUMP_FORWARD L8
L7:
  RETURN_CONST True
L8:
  LOAD_FAST x
  POP_JUMP_IF_FALSE L9
  RETURN_CONST False
L9:
  RETURN_CONST None
END

import re

def pass_validity(p):
    x = True
    while x:
        if len(p) < 6 or len(p) > 12:
            break
        elif not re.search('[a-z]', p):
            break
        elif not re.search('[0-9]', p):
            break
        elif not re.search('[A-Z]', p):
            break
        elif not re.search('[$#@]', p):
            break
        elif re.search('\\s', p):
            break
        else:
            return True
            x = False
            break
    if x:
        return False

Prompt: Write a function to return true if the password is valid.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code check_substring>
  MAKE_FUNCTION 0
  STORE_NAME check_substring
  RETURN_CONST None
END
CODE check_substring(string, sample)
  RESUME 0
  LOAD_FAST sample
  LOAD_FAST string
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L2
  LOAD_CONST '\\A'
  LOAD_FAST sample
  BINARY_OP +
  STORE_FAST y
  LOAD_GLOBAL NULL + re
  LOAD_ATTR search
  LOAD_FAST y
  LOAD_FAST string
  CALL 2
  STORE_FAST x
  LOAD_FAST x
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'string starts with the given substring'
L1:
  RETURN_CONST 'string doesnt start with the given substring'
L2:
  RETURN_CONST 'entered string isnt a substring'
END

import re

def check_substring(string, sample):
    if sample in string:
        y = '\\A' + sample
        x = re.search(y, string)
        if x:
            return 'string starts with the given substring'
        else:
            return 'string doesnt start with the given substring'
    else:
        return 'entered string isnt a substring'

Prompt: Write a function to check if the given string starts with a substring using regex.

assert check_substring("dreams for dreams makes life fun", "makes") == 'string doesnt start with the given substring'

assert check_substring("Hi there how are you Hi alex", "Hi") == 'string starts with the given substring'

assert check_substring("Its been a long day", "been") == 'string doesnt start with the given substring'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code remove_even>
  MAKE_FUNCTION 0
  STORE_NAME remove_even
  RETURN_CONST None
END
CODE remove_even(l)
  RESUME 0
  LOAD_FAST l
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST i
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST l
  LOAD_ATTR NULL|self + remove
  LOAD_FAST i
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST l
  RETURN_VALUE
END

def remove_even(l):
    for i in l:
        if i % 2 == 0:
            l.remove(i)
    return l

Prompt: Write a python function to remove even numbers from a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code access_elements>
  MAKE_FUNCTION 0
  STORE_NAME access_elements
  RETURN_CONST None
END
CODE access_elements(nums, list_index)
  RESUME 0
  LOAD_FAST list_index
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST nums
  LOAD_FAST i
  BINARY_SUBSCR
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST result
  STORE_FAST i
  LOAD_FAST result
  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

def access_elements(nums, list_index):
    result = [nums[i] for i in list_index]
    return result

Prompt: Write a python function to access multiple elements of specified index from a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sum_column>
  MAKE_FUNCTION 0
  STORE_NAME sum_column
  RETURN_CONST None
END
CODE sum_column(list1, C)
  MAKE_CELL C
  RESUME 0
  LOAD_GLOBAL NULL + sum
  LOAD_CLOSURE C
  BUILD_TUPLE 1
  LOAD_CONST <code sum_column.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_FAST list1
  GET_ITER
  CALL 0
  CALL 1
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END
CODE sum_column.<locals>.<genexpr>(.0)
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST row
  LOAD_FAST row
  LOAD_DEREF C
  BINARY_SUBSCR
  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 sum_column(list1, C):
    result = sum((row[C] for row in list1))
    return result

Prompt: Write a function to sum a specific column of a list in a given list of lists.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_alpha_dig_spl>
  MAKE_FUNCTION 0
  STORE_NAME count_alpha_dig_spl
  RETURN_CONST None
END
CODE count_alpha_dig_spl(string)
  RESUME 0
  LOAD_CONST 0
  COPY 1
  STORE_FAST alphabets
  COPY 1
  STORE_FAST digits
  STORE_FAST special
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST string
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L4
  STORE_FAST i
  LOAD_FAST string
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + isalpha
  CALL 0
  POP_JUMP_IF_FALSE L2
  LOAD_FAST alphabets
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST alphabets
  JUMP_BACKWARD L1
L2:
  LOAD_FAST string
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + isdigit
  CALL 0
  POP_JUMP_IF_FALSE L3
  LOAD_FAST digits
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST digits
  JUMP_BACKWARD L1
L3:
  LOAD_FAST special
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST special
  JUMP_BACKWARD L1
L4:
  END_FOR
  LOAD_FAST alphabets
  LOAD_FAST digits
  LOAD_FAST special
  BUILD_TUPLE 3
  RETURN_VALUE
END

def count_alpha_dig_spl(string):
    alphabets = digits = special = 0
    for i in range(len(string)):
        if string[i].isalpha():
            alphabets = alphabets + 1
        elif string[i].isdigit():
            digits = digits + 1
        else:
            special = special + 1
    return (alphabets, digits, special)

Prompt: Write a function to count alphabets,digits and special charactes in a given string.


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 second_frequent>
  MAKE_FUNCTION 0
  STORE_NAME second_frequent
  RETURN_CONST None
END
CODE second_frequent(input)
  RESUME 0
  LOAD_GLOBAL NULL + Counter
  LOAD_FAST input
  CALL 1
  STORE_FAST dict
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST dict
  LOAD_ATTR NULL|self + values
  CALL 0
  LOAD_CONST True
  KW_NAMES ('reverse',)
  CALL 2
  STORE_FAST value
  LOAD_FAST value
  LOAD_CONST 1
  BINARY_SUBSCR
  STORE_FAST second_large
  LOAD_FAST dict
  LOAD_ATTR NULL|self + items
  CALL 0
  GET_ITER
L1:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST key
  STORE_FAST val
  LOAD_FAST val
  LOAD_FAST second_large
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST key
  SWAP 2
  POP_TOP
  RETURN_VALUE
L3:
  END_FOR
  RETURN_CONST None
END

from collections import Counter

def second_frequent(input):
    dict = Counter(input)
    value = sorted(dict.values(), reverse=True)
    second_large = value[1]
    for key, val in dict.items():
        if val == second_large:
            return key

Prompt: Write a function to find out the second most repeated (or frequent) string in the given sequence.

assert second_frequent(['aaa','bbb','ccc','bbb','aaa','aaa']) == 'bbb'

assert second_frequent(['abc','bcd','abc','bcd','bcd','bcd']) == 'abc'

assert second_frequent(['cdma','gsm','hspa','gsm','cdma','cdma']) == 'gsm'


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

def count_Pairs(arr, n):
    cnt = 0
    for i in range(n):
        for j in range(i + 1, n):
            if arr[i] == arr[j]:
                cnt += 1
    return cnt

Prompt: Write a python function to count equal element pairs from the given array.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code generate_matrix>
  MAKE_FUNCTION 0
  STORE_NAME generate_matrix
  RETURN_CONST None
END
CODE generate_matrix(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 0
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L1
  BUILD_LIST 0
  RETURN_VALUE
L1:
  LOAD_CONST 0
  BUILD_LIST 1
  LOAD_FAST n
  BINARY_OP *
  BUILD_LIST 1
  LOAD_FAST n
  BINARY_OP *
  GET_ITER
  LOAD_FAST_AND_CLEAR row
  SWAP 2
L2:
  BUILD_LIST 0
  SWAP 2
L3:
  FOR_ITER L4
  STORE_FAST row
  LOAD_FAST row
  LOAD_CONST None
  LOAD_CONST None
  BINARY_SLICE
  LIST_APPEND 2
  JUMP_BACKWARD L3
L4:
  END_FOR
L5:
  STORE_FAST matrix
  STORE_FAST row
  LOAD_CONST 0
  STORE_FAST row_st
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST row_ed
  LOAD_CONST 0
  STORE_FAST col_st
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST col_ed
  LOAD_CONST 1
  STORE_FAST current
  NOP
L6:
  LOAD_FAST current
  LOAD_FAST n
  LOAD_FAST n
  BINARY_OP *
  COMPARE_OP >
  POP_JUMP_IF_FALSE L7
  NOP
  LOAD_FAST matrix
  RETURN_VALUE
L7:
  LOAD_GLOBAL NULL + range
  LOAD_FAST col_st
  LOAD_FAST col_ed
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L8:
  FOR_ITER L9
  STORE_FAST c
  LOAD_FAST current
  LOAD_FAST matrix
  LOAD_FAST row_st
  BINARY_SUBSCR
  LOAD_FAST c
  STORE_SUBSCR
  LOAD_FAST current
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST current
  JUMP_BACKWARD L8
L9:
  END_FOR
  LOAD_FAST row_st
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST row_st
  LOAD_GLOBAL NULL + range
  LOAD_FAST row_st
  LOAD_FAST row_ed
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L10:
  FOR_ITER L11
  STORE_FAST r
  LOAD_FAST current
  LOAD_FAST matrix
  LOAD_FAST r
  BINARY_SUBSCR
  LOAD_FAST col_ed
  STORE_SUBSCR
  LOAD_FAST current
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST current
  JUMP_BACKWARD L10
L11:
  END_FOR
  LOAD_FAST col_ed
  LOAD_CONST 1
  BINARY_OP -=
  STORE_FAST col_ed
  LOAD_GLOBAL NULL + range
  LOAD_FAST col_ed
  LOAD_FAST col_st
  LOAD_CONST 1
  BINARY_OP -
  LOAD_CONST -1
  CALL 3
  GET_ITER
L12:
  FOR_ITER L13
  STORE_FAST c
  LOAD_FAST current
  LOAD_FAST matrix
  LOAD_FAST row_ed
  BINARY_SUBSCR
  LOAD_FAST c
  STORE_SUBSCR
  LOAD_FAST current
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST current
  JUMP_BACKWARD L12
L13:
  END_FOR
  LOAD_FAST row_ed
  LOAD_CONST 1
  BINARY_OP -=
  STORE_FAST row_ed
  LOAD_GLOBAL NULL + range
  LOAD_FAST row_ed
  LOAD_FAST row_st
  LOAD_CONST 1
  BINARY_OP -
  LOAD_CONST -1
  CALL 3
  GET_ITER
L14:
  FOR_ITER L15
  STORE_FAST r
  LOAD_FAST current
  LOAD_FAST matrix
  LOAD_FAST r
  BINARY_SUBSCR
  LOAD_FAST col_st
  STORE_SUBSCR
  LOAD_FAST current
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST current
  JUMP_BACKWARD L14
L15:
  END_FOR
  LOAD_FAST col_st
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST col_st
  JUMP_BACKWARD L6
L16:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST row
  RERAISE 0
  EXC try=L2..L5 -> handler=L16 depth=2 lasti=False
END

def generate_matrix(n):
    if n <= 0:
        return []
    matrix = [row[:] for row in [[0] * n] * n]
    row_st = 0
    row_ed = n - 1
    col_st = 0
    col_ed = n - 1
    current = 1
    while True:
        if current > n * n:
            break
        for c in range(col_st, col_ed + 1):
            matrix[row_st][c] = current
            current += 1
        row_st += 1
        for r in range(row_st, row_ed + 1):
            matrix[r][col_ed] = current
            current += 1
        col_ed -= 1
        for c in range(col_ed, col_st - 1, -1):
            matrix[row_ed][c] = current
            current += 1
        row_ed -= 1
        for r in range(row_ed, row_st - 1, -1):
            matrix[r][col_st] = current
            current += 1
        col_st += 1
    return matrix

Prompt: Write a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('maxsize',)
  IMPORT_NAME sys
  IMPORT_FROM maxsize
  STORE_NAME maxsize
  POP_TOP
  LOAD_CONST <code max_sub_array_sum>
  MAKE_FUNCTION 0
  STORE_NAME max_sub_array_sum
  RETURN_CONST None
END
CODE max_sub_array_sum(a, size)
  RESUME 0
  LOAD_GLOBAL maxsize
  UNARY_NEGATIVE
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST max_so_far
  LOAD_CONST 0
  STORE_FAST max_ending_here
  LOAD_CONST 0
  STORE_FAST start
  LOAD_CONST 0
  STORE_FAST end
  LOAD_CONST 0
  STORE_FAST s
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_FAST size
  CALL 2
  GET_ITER
L1:
  FOR_ITER L4
  STORE_FAST i
  LOAD_FAST max_ending_here
  LOAD_FAST a
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP +=
  STORE_FAST max_ending_here
  LOAD_FAST max_so_far
  LOAD_FAST max_ending_here
  COMPARE_OP <
  POP_JUMP_IF_FALSE L2
  LOAD_FAST max_ending_here
  STORE_FAST max_so_far
  LOAD_FAST s
  STORE_FAST start
  LOAD_FAST i
  STORE_FAST end
L2:
  LOAD_FAST max_ending_here
  LOAD_CONST 0
  COMPARE_OP <
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L1
L3:
  LOAD_CONST 0
  STORE_FAST max_ending_here
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST s
  JUMP_BACKWARD L1
L4:
  END_FOR
  LOAD_FAST end
  LOAD_FAST start
  BINARY_OP -
  LOAD_CONST 1
  BINARY_OP +
  RETURN_VALUE
END

from sys import maxsize

def max_sub_array_sum(a, size):
    max_so_far = -maxsize - 1
    max_ending_here = 0
    start = 0
    end = 0
    s = 0
    for i in range(0, size):
        max_ending_here += a[i]
        if max_so_far < max_ending_here:
            max_so_far = max_ending_here
            start = s
            end = i
        if max_ending_here < 0:
            max_ending_here = 0
            s = i + 1
    return end - start + 1

Prompt: Write a function to find length of the subarray having maximum sum.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code cube_Sum>
  MAKE_FUNCTION 0
  STORE_NAME cube_Sum
  RETURN_CONST None
END
CODE cube_Sum(n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST sum
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_FAST n
  CALL 2
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST sum
  LOAD_CONST 2
  LOAD_FAST i
  BINARY_OP *
  LOAD_CONST 1
  BINARY_OP +
  LOAD_CONST 2
  LOAD_FAST i
  BINARY_OP *
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP *
  LOAD_CONST 2
  LOAD_FAST i
  BINARY_OP *
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP *
  BINARY_OP +=
  STORE_FAST sum
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST sum
  RETURN_VALUE
END

def cube_Sum(n):
    sum = 0
    for i in range(0, n):
        sum += (2 * i + 1) * (2 * i + 1) * (2 * i + 1)
    return sum

Prompt: Write a python function to find the cube sum of first n odd natural numbers.

assert cube_Sum(2) == 28
assert cube_Sum(3) == 153
assert cube_Sum(4) == 496