Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code min_Swaps>
  MAKE_FUNCTION 0
  STORE_NAME min_Swaps
  RETURN_CONST None
END
CODE min_Swaps(s1, s2)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST c0
  LOAD_CONST 0
  STORE_FAST c1
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST s1
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L5
  STORE_FAST i
  LOAD_FAST s1
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST '0'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST s2
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST '1'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST c0
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST c0
  JUMP_BACKWARD L1
L2:
  LOAD_FAST s1
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST '1'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L1
L3:
  LOAD_FAST s2
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST '0'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L4
  JUMP_BACKWARD L1
L4:
  LOAD_FAST c1
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST c1
  JUMP_BACKWARD L1
L5:
  END_FOR
  LOAD_FAST c0
  LOAD_CONST 2
  BINARY_OP //
  LOAD_FAST c1
  LOAD_CONST 2
  BINARY_OP //
  BINARY_OP +
  STORE_FAST result
  LOAD_FAST c0
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L6
  LOAD_FAST c1
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L6
  LOAD_FAST result
  RETURN_VALUE
L6:
  LOAD_FAST c0
  LOAD_FAST c1
  BINARY_OP +
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L7
  LOAD_FAST result
  LOAD_CONST 2
  BINARY_OP +
  RETURN_VALUE
L7:
  RETURN_CONST -1
END

def min_Swaps(s1, s2):
    c0 = 0
    c1 = 0
    for i in range(len(s1)):
        if s1[i] == '0' and s2[i] == '1':
            c0 += 1
        elif s1[i] == '1' and s2[i] == '0':
            c1 += 1
    result = c0 // 2 + c1 // 2
    if c0 % 2 == 0 and c1 % 2 == 0:
        return result
    elif (c0 + c1) % 2 == 0:
        return result + 2
    else:
        return -1

Prompt: Write a python function to find minimum number swaps required to make two binary strings equal.


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

def sort_tuple(tup):
    n = len(tup)
    for i in range(n):
        for j in range(n - i - 1):
            if tup[j][0] > tup[j + 1][0]:
                tup[j], tup[j + 1] = (tup[j + 1], tup[j])
    return tup

Prompt: Write a function to sort the tuples alphabetically by the first item of each tuple.

Creative Commons Attribution 4.0 International

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


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code Check_Solution>
  MAKE_FUNCTION 0
  STORE_NAME Check_Solution
  RETURN_CONST None
END
CODE Check_Solution(a, b, c)
  RESUME 0
  LOAD_FAST b
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'Yes'
L1:
  RETURN_CONST 'No'
END

def Check_Solution(a, b, c):
    if b == 0:
        return 'Yes'
    else:
        return 'No'

Prompt: Write a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not.

assert Check_Solution(2,0,-1) == "Yes"
assert Check_Solution(1,-5,6) == "No"
assert Check_Solution(2,0,2) == "Yes"


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_inv_count>
  MAKE_FUNCTION 0
  STORE_NAME get_inv_count
  RETURN_CONST None
END
CODE get_inv_count(arr, n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST inv_count
  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 inv_count
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST inv_count
  JUMP_BACKWARD L2
L4:
  END_FOR
  JUMP_BACKWARD L1
L5:
  END_FOR
  LOAD_FAST inv_count
  RETURN_VALUE
END

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

Prompt: Write a function to count the number of inversions in the given array.


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

def get_odd_occurence(arr, arr_size):
    for i in range(0, arr_size):
        count = 0
        for j in range(0, arr_size):
            if arr[i] == arr[j]:
                count += 1
        if count % 2 != 0:
            return arr[i]
    return -1

Prompt: Write a function to find the number which occurs for odd number of times in the given array.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME heapq
  STORE_NAME heapq
  LOAD_CONST <code nth_super_ugly_number>
  MAKE_FUNCTION 0
  STORE_NAME nth_super_ugly_number
  RETURN_CONST None
END
CODE nth_super_ugly_number(n, primes)
  MAKE_CELL uglies
  RESUME 0
  LOAD_CONST 1
  BUILD_LIST 1
  STORE_DEREF uglies
  LOAD_CLOSURE uglies
  BUILD_TUPLE 1
  LOAD_CONST <code nth_super_ugly_number.<locals>.gen>
  MAKE_FUNCTION closure
  STORE_FAST gen
  LOAD_GLOBAL NULL + heapq
  LOAD_ATTR merge
  LOAD_GLOBAL NULL + map
  LOAD_FAST gen
  LOAD_FAST primes
  CALL 2
  CALL_FUNCTION_EX 0
  STORE_FAST merged
  LOAD_GLOBAL NULL + len
  LOAD_DEREF uglies
  CALL 1
  LOAD_FAST n
  COMPARE_OP <
  POP_JUMP_IF_FALSE L3
L1:
  LOAD_GLOBAL NULL + next
  LOAD_FAST merged
  CALL 1
  STORE_FAST ugly
  LOAD_FAST ugly
  LOAD_DEREF uglies
  LOAD_CONST -1
  BINARY_SUBSCR
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L2
  LOAD_DEREF uglies
  LOAD_ATTR NULL|self + append
  LOAD_FAST ugly
  CALL 1
  POP_TOP
L2:
  LOAD_GLOBAL NULL + len
  LOAD_DEREF uglies
  CALL 1
  LOAD_FAST n
  COMPARE_OP <
  POP_JUMP_IF_FALSE L3
  JUMP_BACKWARD L1
L3:
  LOAD_DEREF uglies
  LOAD_CONST -1
  BINARY_SUBSCR
  RETURN_VALUE
END
CODE nth_super_ugly_number.<locals>.gen(prime)
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_DEREF uglies
  GET_ITER
L2:
  FOR_ITER L3
  STORE_FAST ugly
  LOAD_FAST ugly
  LOAD_FAST prime
  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

import heapq

def nth_super_ugly_number(n, primes):
    uglies = [1]

    def gen(prime):
        for ugly in uglies:
            yield (ugly * prime)
    merged = heapq.merge(*map(gen, primes))
    while len(uglies) < n:
        ugly = next(merged)
        if ugly != uglies[-1]:
            uglies.append(ugly)
    return uglies[-1]

Prompt: Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code find_Digits>
  MAKE_FUNCTION 0
  STORE_NAME find_Digits
  RETURN_CONST None
END
CODE find_Digits(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 0
  COMPARE_OP <
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 0
L1:
  LOAD_FAST n
  LOAD_CONST 1
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L2
  RETURN_CONST 1
L2:
  LOAD_FAST n
  LOAD_GLOBAL NULL + math
  LOAD_ATTR log10
  LOAD_FAST n
  LOAD_GLOBAL math
  LOAD_ATTR e
  BINARY_OP /
  CALL 1
  BINARY_OP *
  LOAD_GLOBAL NULL + math
  LOAD_ATTR log10
  LOAD_CONST 2
  LOAD_GLOBAL math
  LOAD_ATTR pi
  BINARY_OP *
  LOAD_FAST n
  BINARY_OP *
  CALL 1
  LOAD_CONST 2.0
  BINARY_OP /
  BINARY_OP +
  STORE_FAST x
  LOAD_GLOBAL NULL + math
  LOAD_ATTR floor
  LOAD_FAST x
  CALL 1
  LOAD_CONST 1
  BINARY_OP +
  RETURN_VALUE
END

import math

def find_Digits(n):
    if n < 0:
        return 0
    if n <= 1:
        return 1
    x = n * math.log10(n / math.e) + math.log10(2 * math.pi * n) / 2.0
    return math.floor(x) + 1

Prompt: Write a python function to count the number of digits in factorial of a given number.

assert find_Digits(7) == 4
assert find_Digits(5) == 3
assert find_Digits(4) == 2


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code Sum>
  MAKE_FUNCTION 0
  STORE_NAME Sum
  RETURN_CONST None
END
CODE Sum(N)
  RESUME 0
  LOAD_CONST 0
  BUILD_LIST 1
  LOAD_FAST N
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP *
  STORE_FAST SumOfPrimeDivisors
  LOAD_GLOBAL NULL + range
  LOAD_CONST 2
  LOAD_FAST N
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L1:
  FOR_ITER L5
  STORE_FAST i
  LOAD_FAST SumOfPrimeDivisors
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_GLOBAL NULL + range
  LOAD_FAST i
  LOAD_FAST N
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST i
  CALL 3
  GET_ITER
L3:
  FOR_ITER L4
  STORE_FAST j
  LOAD_FAST SumOfPrimeDivisors
  LOAD_FAST j
  COPY 2
  COPY 2
  BINARY_SUBSCR
  LOAD_FAST i
  BINARY_OP +=
  SWAP 3
  SWAP 2
  STORE_SUBSCR
  JUMP_BACKWARD L3
L4:
  END_FOR
  JUMP_BACKWARD L1
L5:
  END_FOR
  LOAD_FAST SumOfPrimeDivisors
  LOAD_FAST N
  BINARY_SUBSCR
  RETURN_VALUE
END

def Sum(N):
    SumOfPrimeDivisors = [0] * (N + 1)
    for i in range(2, N + 1):
        if SumOfPrimeDivisors[i] == 0:
            for j in range(i, N + 1, i):
                SumOfPrimeDivisors[j] += i
    return SumOfPrimeDivisors[N]

Prompt: Write a python function to find sum of all prime divisors of a given number.

assert Sum(60) == 10
assert Sum(39) == 16
assert Sum(40) == 7


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_triangleexists>
  MAKE_FUNCTION 0
  STORE_NAME is_triangleexists
  RETURN_CONST None
END
CODE is_triangleexists(a, b, c)
  RESUME 0
  LOAD_FAST a
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L3
  LOAD_FAST b
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L3
  LOAD_FAST c
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L3
  LOAD_FAST a
  LOAD_FAST b
  BINARY_OP +
  LOAD_FAST c
  BINARY_OP +
  LOAD_CONST 180
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_FAST a
  LOAD_FAST b
  BINARY_OP +
  LOAD_FAST c
  COMPARE_OP >=
  POP_JUMP_IF_TRUE L1
  LOAD_FAST b
  LOAD_FAST c
  BINARY_OP +
  LOAD_FAST a
  COMPARE_OP >=
  POP_JUMP_IF_TRUE L1
  LOAD_FAST a
  LOAD_FAST c
  BINARY_OP +
  LOAD_FAST b
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L2
L1:
  RETURN_CONST True
L2:
  RETURN_CONST False
L3:
  RETURN_CONST False
END

def is_triangleexists(a, b, c):
    if a != 0 and b != 0 and (c != 0) and (a + b + c == 180):
        if a + b >= c or b + c >= a or a + c >= b:
            return True
        else:
            return False
    else:
        return False

Prompt: Write a function to check if a triangle of positive area is possible with the given angles.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code Sum_of_Inverse_Divisors>
  MAKE_FUNCTION 0
  STORE_NAME Sum_of_Inverse_Divisors
  RETURN_CONST None
END
CODE Sum_of_Inverse_Divisors(N, Sum)
  RESUME 0
  LOAD_GLOBAL NULL + float
  LOAD_FAST Sum
  CALL 1
  LOAD_CONST 1.0
  BINARY_OP *
  LOAD_GLOBAL NULL + float
  LOAD_FAST N
  CALL 1
  BINARY_OP /
  STORE_FAST ans
  LOAD_GLOBAL NULL + round
  LOAD_FAST ans
  LOAD_CONST 2
  CALL 2
  RETURN_VALUE
END

def Sum_of_Inverse_Divisors(N, Sum):
    ans = float(Sum) * 1.0 / float(N)
    return round(ans, 2)

Prompt: Write a python function to find sum of inverse of divisors.

assert Sum_of_Inverse_Divisors(6,12) == 2

assert Sum_of_Inverse_Divisors(9,13) == 1.44

assert Sum_of_Inverse_Divisors(1,4) == 4


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code remove_negs>
  MAKE_FUNCTION 0
  STORE_NAME remove_negs
  RETURN_CONST None
END
CODE remove_negs(num_list)
  RESUME 0
  LOAD_FAST num_list
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST item
  LOAD_FAST item
  LOAD_CONST 0
  COMPARE_OP <
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST num_list
  LOAD_ATTR NULL|self + remove
  LOAD_FAST item
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST num_list
  RETURN_VALUE
END

def remove_negs(num_list):
    for item in num_list:
        if item < 0:
            num_list.remove(item)
    return num_list

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


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

import math

def sum_of_odd_Factors(n):
    res = 1
    while n % 2 == 0:
        n = n // 2
    for i in range(3, int(math.sqrt(n) + 1)):
        count = 0
        curr_sum = 1
        curr_term = 1
        while n % i == 0:
            count += 1
            n = n // i
            curr_term *= i
            curr_sum += curr_term
        res *= curr_sum
    if n >= 2:
        res *= 1 + n
    return res

Prompt: Write a python function to find sum of odd factors of a number.

assert sum_of_odd_Factors(30) == 24
assert sum_of_odd_Factors(18) == 13
assert sum_of_odd_Factors(2) == 1


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME heapq
  STORE_NAME hq
  LOAD_CONST <code raw_heap>
  MAKE_FUNCTION 0
  STORE_NAME raw_heap
  RETURN_CONST None
END
CODE raw_heap(rawheap)
  RESUME 0
  LOAD_GLOBAL NULL + hq
  LOAD_ATTR heapify
  LOAD_FAST rawheap
  CALL 1
  POP_TOP
  LOAD_FAST rawheap
  RETURN_VALUE
END

import heapq as hq

def raw_heap(rawheap):
    hq.heapify(rawheap)
    return rawheap

Prompt: Write a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_Even_Parity>
  MAKE_FUNCTION 0
  STORE_NAME check_Even_Parity
  RETURN_CONST None
END
CODE check_Even_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 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  RETURN_CONST True
L3:
  RETURN_CONST False
END

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

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

assert check_Even_Parity(10) == True
assert check_Even_Parity(11) == False
assert check_Even_Parity(18) == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_list>
  MAKE_FUNCTION 0
  STORE_NAME count_list
  RETURN_CONST None
END
CODE count_list(input_list)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST input_list
  CALL 1
  LOAD_CONST 2
  BINARY_OP **
  RETURN_VALUE
END

def count_list(input_list):
    return len(input_list) ** 2

Prompt: Write a function to count number of lists in a given list of lists and square the count.


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 sub_lists>
  MAKE_FUNCTION 0
  STORE_NAME sub_lists
  RETURN_CONST None
END
CODE sub_lists(my_list)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST subs
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST my_list
  CALL 1
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L1:
  FOR_ITER L7
  STORE_FAST i
  LOAD_GLOBAL NULL + combinations
  LOAD_FAST my_list
  LOAD_FAST i
  CALL 2
  GET_ITER
  LOAD_FAST_AND_CLEAR x
  SWAP 2
L2:
  BUILD_LIST 0
  SWAP 2
L3:
  FOR_ITER L4
  STORE_FAST x
  LOAD_GLOBAL NULL + list
  LOAD_FAST x
  CALL 1
  LIST_APPEND 2
  JUMP_BACKWARD L3
L4:
  END_FOR
L5:
  STORE_FAST temp
  STORE_FAST x
  LOAD_GLOBAL NULL + len
  LOAD_FAST temp
  CALL 1
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_TRUE L6
  JUMP_BACKWARD L1
L6:
  LOAD_FAST subs
  LOAD_ATTR NULL|self + extend
  LOAD_FAST temp
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L7:
  END_FOR
  LOAD_FAST subs
  RETURN_VALUE
L8:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST x
  RERAISE 0
  EXC try=L2..L5 -> handler=L8 depth=3 lasti=False
END

from itertools import combinations

def sub_lists(my_list):
    subs = []
    for i in range(0, len(my_list) + 1):
        temp = [list(x) for x in combinations(my_list, i)]
        if len(temp) > 0:
            subs.extend(temp)
    return subs

Prompt: Write a function to generate all sublists of a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST '[a-zA-z0-9]$'
  STORE_NAME regex
  LOAD_CONST <code check_alphanumeric>
  MAKE_FUNCTION 0
  STORE_NAME check_alphanumeric
  RETURN_CONST None
END
CODE check_alphanumeric(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 'Accept'
L1:
  RETURN_CONST 'Discard'
END

import re
regex = '[a-zA-z0-9]$'

def check_alphanumeric(string):
    if re.search(regex, string):
        return 'Accept'
    else:
        return 'Discard'

Prompt: Write a function to check whether the given string is ending with only alphanumeric characters or not using regex.

assert check_alphanumeric("dawood@") == 'Discard'

assert check_alphanumeric("skdmsam326") == 'Accept'

assert check_alphanumeric("cooltricks@") == 'Discard'


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 anagram_lambda>
  MAKE_FUNCTION 0
  STORE_NAME anagram_lambda
  RETURN_CONST None
END
CODE anagram_lambda(texts, str)
  MAKE_CELL str
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + filter
  LOAD_CLOSURE str
  BUILD_TUPLE 1
  LOAD_CONST <code anagram_lambda.<locals>.<lambda>>
  MAKE_FUNCTION closure
  LOAD_FAST texts
  CALL 2
  CALL 1
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END
CODE anagram_lambda.<locals>.<lambda>(x)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_GLOBAL NULL + Counter
  LOAD_DEREF str
  CALL 1
  LOAD_GLOBAL NULL + Counter
  LOAD_FAST x
  CALL 1
  COMPARE_OP ==
  RETURN_VALUE
END

from collections import Counter

def anagram_lambda(texts, str):
    result = list(filter(lambda x: Counter(str) == Counter(x), texts))
    return result

Prompt: Write a function to find all anagrams of a string in a given list of strings using lambda function.

assert anagram_lambda(["bcda", "abce", "cbda", "cbea", "adcb"],"abcd")==['bcda', 'cbda', 'adcb']

assert anagram_lambda(["recitals"," python"], "articles" )==["recitals"]

assert anagram_lambda([" keep"," abcdef"," xyz"]," peek")==[" keep"]


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('Counter',)
  IMPORT_NAME collections
  IMPORT_FROM Counter
  STORE_NAME Counter
  POP_TOP
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code n_common_words>
  MAKE_FUNCTION 0
  STORE_NAME n_common_words
  RETURN_CONST None
END
CODE n_common_words(text, n)
  RESUME 0
  LOAD_GLOBAL NULL + re
  LOAD_ATTR findall
  LOAD_CONST '\\w+'
  LOAD_FAST text
  CALL 2
  STORE_FAST words
  LOAD_GLOBAL NULL + Counter
  LOAD_FAST words
  CALL 1
  LOAD_ATTR NULL|self + most_common
  LOAD_FAST n
  CALL 1
  STORE_FAST n_common_words
  LOAD_GLOBAL NULL + list
  LOAD_FAST n_common_words
  CALL 1
  RETURN_VALUE
END

from collections import Counter
import re

def n_common_words(text, n):
    words = re.findall('\\w+', text)
    n_common_words = Counter(words).most_common(n)
    return list(n_common_words)

Prompt: Write a function to find the occurrences of n most common words in a given text.

assert n_common_words("python is a programming language",1)==[('python', 1)]

assert n_common_words("python is a programming language",5)==[('python', 1),('is', 1), ('a', 1), ('programming', 1), ('language', 1)]


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code palindrome_lambda>
  MAKE_FUNCTION 0
  STORE_NAME palindrome_lambda
  RETURN_CONST None
END
CODE palindrome_lambda(texts)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + filter
  LOAD_CONST <code palindrome_lambda.<locals>.<lambda>>
  MAKE_FUNCTION 0
  LOAD_FAST texts
  CALL 2
  CALL 1
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END
CODE palindrome_lambda.<locals>.<lambda>(x)
  RESUME 0
  LOAD_FAST x
  LOAD_CONST ''
  LOAD_ATTR NULL|self + join
  LOAD_GLOBAL NULL + reversed
  LOAD_FAST x
  CALL 1
  CALL 1
  COMPARE_OP ==
  RETURN_VALUE
END

def palindrome_lambda(texts):
    result = list(filter(lambda x: x == ''.join(reversed(x)), texts))
    return result

Prompt: Write a function to find palindromes in a given list of strings using lambda function.

assert palindrome_lambda(["php", "res", "Python", "abcd", "Java", "aaa"])==['php', 'aaa']

assert palindrome_lambda(["abcd", "Python", "abba", "aba"])==['abba', 'aba']

assert palindrome_lambda(["abcd", "abbccbba", "abba", "aba"])==['abbccbba', 'abba', 'aba']


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code ntimes_list>
  MAKE_FUNCTION 0
  STORE_NAME ntimes_list
  RETURN_CONST None
END
CODE ntimes_list(nums, n)
  MAKE_CELL n
  RESUME 0
  LOAD_GLOBAL NULL + map
  LOAD_CLOSURE n
  BUILD_TUPLE 1
  LOAD_CONST <code ntimes_list.<locals>.<lambda>>
  MAKE_FUNCTION closure
  LOAD_FAST nums
  CALL 2
  STORE_FAST result
  LOAD_GLOBAL NULL + list
  LOAD_FAST result
  CALL 1
  RETURN_VALUE
END
CODE ntimes_list.<locals>.<lambda>(x)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_DEREF n
  LOAD_FAST x
  BINARY_OP *
  RETURN_VALUE
END

def ntimes_list(nums, n):
    result = map(lambda x: n * x, nums)
    return list(result)

Prompt: Write a function to print n-times a list using map function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_monthnumb>
  MAKE_FUNCTION 0
  STORE_NAME check_monthnumb
  RETURN_CONST None
END
CODE check_monthnumb(monthname2)
  RESUME 0
  LOAD_FAST monthname2
  LOAD_CONST 'January'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L1
  LOAD_FAST monthname2
  LOAD_CONST 'March'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L1
  LOAD_FAST monthname2
  LOAD_CONST 'May'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L1
  LOAD_FAST monthname2
  LOAD_CONST 'July'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L1
  LOAD_FAST monthname2
  LOAD_CONST 'Augest'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L1
  LOAD_FAST monthname2
  LOAD_CONST 'October'
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L1
  LOAD_FAST monthname2
  LOAD_CONST 'December'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
L1:
  RETURN_CONST True
L2:
  RETURN_CONST False
END

def check_monthnumb(monthname2):
    if monthname2 == 'January' or monthname2 == 'March' or monthname2 == 'May' or (monthname2 == 'July') or (monthname2 == 'Augest') or (monthname2 == 'October') or (monthname2 == 'December'):
        return True
    else:
        return False

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


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

def min_Num(arr, n):
    odd = 0
    for i in range(n):
        if arr[i] % 2:
            odd += 1
    if odd % 2:
        return 1
    return 2

Prompt: Write a python function to add a minimum number such that the sum of array becomes even.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code length_Of_Last_Word>
  MAKE_FUNCTION 0
  STORE_NAME length_Of_Last_Word
  RETURN_CONST None
END
CODE length_Of_Last_Word(a)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST l
  LOAD_FAST a
  LOAD_ATTR NULL|self + strip
  CALL 0
  STORE_FAST x
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST x
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST x
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST ' '
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_CONST 0
  STORE_FAST l
  JUMP_BACKWARD L1
L2:
  LOAD_FAST l
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST l
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST l
  RETURN_VALUE
END

def length_Of_Last_Word(a):
    l = 0
    x = a.strip()
    for i in range(len(x)):
        if x[i] == ' ':
            l = 0
        else:
            l += 1
    return l

Prompt: Write a python function to find the length of the last word in a given string.

assert length_Of_Last_Word("python language") == 8


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code remove_list_range>
  MAKE_FUNCTION 0
  STORE_NAME remove_list_range
  RETURN_CONST None
END
CODE remove_list_range(list1, leftrange, rigthrange)
  RESUME 0
  LOAD_FAST list1
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L7
  STORE_FAST i
  LOAD_GLOBAL NULL + min
  LOAD_FAST i
  CALL 1
  LOAD_FAST leftrange
  COMPARE_OP >=
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_GLOBAL NULL + max
  LOAD_FAST i
  CALL 1
  LOAD_FAST rigthrange
  COMPARE_OP <=
  POP_JUMP_IF_TRUE L6
L5:
  JUMP_BACKWARD L2
L6:
  LOAD_FAST i
  LIST_APPEND 2
  JUMP_BACKWARD L2
L7:
  END_FOR
L8:
  STORE_FAST result
  STORE_FAST i
  LOAD_FAST result
  RETURN_VALUE
L9:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
  EXC try=L1..L3 -> handler=L9 depth=2 lasti=False
  EXC try=L4..L5 -> handler=L9 depth=2 lasti=False
  EXC try=L6..L8 -> handler=L9 depth=2 lasti=False
END

def remove_list_range(list1, leftrange, rigthrange):
    result = [i for i in list1 if min(i) >= leftrange and max(i) <= rigthrange]
    return result

Prompt: Write a function to remove sublists from a given list of lists, which are outside a given range.


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

def sum_positivenum(nums):
    sum_positivenum = list(filter(lambda nums: nums > 0, nums))
    return sum(sum_positivenum)

Prompt: Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code are_Rotations>
  MAKE_FUNCTION 0
  STORE_NAME are_Rotations
  RETURN_CONST None
END
CODE are_Rotations(string1, string2)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST string1
  CALL 1
  STORE_FAST size1
  LOAD_GLOBAL NULL + len
  LOAD_FAST string2
  CALL 1
  STORE_FAST size2
  LOAD_CONST ''
  STORE_FAST temp
  LOAD_FAST size1
  LOAD_FAST size2
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L1
  RETURN_CONST False
L1:
  LOAD_FAST string1
  LOAD_FAST string1
  BINARY_OP +
  STORE_FAST temp
  LOAD_FAST temp
  LOAD_ATTR NULL|self + count
  LOAD_FAST string2
  CALL 1
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
  RETURN_CONST True
L2:
  RETURN_CONST False
END

def are_Rotations(string1, string2):
    size1 = len(string1)
    size2 = len(string2)
    temp = ''
    if size1 != size2:
        return False
    temp = string1 + string1
    if temp.count(string2) > 0:
        return True
    else:
        return False

Prompt: Write a python function to check whether the given strings are rotations of each other or not.

assert are_Rotations("abc","cba") == False

assert are_Rotations("abcd","cdba") == False

assert are_Rotations("abacd","cdaba") == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_subset>
  MAKE_FUNCTION 0
  STORE_NAME check_subset
  RETURN_CONST None
END
CODE check_subset(list1, list2)
  RESUME 0
  LOAD_GLOBAL NULL + all
  LOAD_GLOBAL NULL + map
  LOAD_FAST list1
  LOAD_ATTR __contains__
  LOAD_FAST list2
  CALL 2
  CALL 1
  RETURN_VALUE
END

def check_subset(list1, list2):
    return all(map(list1.__contains__, list2))

Prompt: Write a function to check if a nested list is a subset of another nested list.


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

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

Prompt: Write a function to solve the fibonacci sequence using recursion.

assert fibonacci(7) == 13
assert fibonacci(8) == 21
assert fibonacci(9) == 34


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

def check_Concat(str1, str2):
    N = len(str1)
    M = len(str2)
    if N % M != 0:
        return False
    for i in range(N):
        if str1[i] != str2[i % M]:
            return False
    return True

Prompt: Write a python function to check if the string is a concatenation of another string.

assert check_Concat("abcabcabc","abc") == True

assert check_Concat("abcab","abc") == False

assert check_Concat("aba","ab") == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sort_String>
  MAKE_FUNCTION 0
  STORE_NAME sort_String
  RETURN_CONST None
END
CODE sort_String(str)
  RESUME 0
  LOAD_CONST ''
  LOAD_ATTR NULL|self + join
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST str
  CALL 1
  CALL 1
  STORE_FAST str
  LOAD_FAST str
  RETURN_VALUE
END

def sort_String(str):
    str = ''.join(sorted(str))
    return str

Prompt: Write a python function to sort the given string.

assert sort_String("cba") == "abc"
assert sort_String("data") == "aadt"
assert sort_String("zxy") == "xyz"


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

def check_tuples(test_tuple, K):
    res = all((ele in K for ele in test_tuple))
    return res

Prompt: Write a function to check if the given tuple contains only k elements.


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


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code parallelogram_perimeter>
  MAKE_FUNCTION 0
  STORE_NAME parallelogram_perimeter
  RETURN_CONST None
END
CODE parallelogram_perimeter(b, h)
  RESUME 0
  LOAD_CONST 2
  LOAD_FAST b
  LOAD_FAST h
  BINARY_OP *
  BINARY_OP *
  STORE_FAST perimeter
  LOAD_FAST perimeter
  RETURN_VALUE
END

def parallelogram_perimeter(b, h):
    perimeter = 2 * (b * h)
    return perimeter

Prompt: Write a function to caluclate perimeter of a parallelogram.


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_FALSE 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 and x % n == 0, nums))
    return result

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


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_Isomorphic>
  MAKE_FUNCTION 0
  STORE_NAME is_Isomorphic
  RETURN_CONST None
END
CODE is_Isomorphic(str1, str2)
  RESUME 0
  BUILD_MAP 0
  STORE_FAST dict_str1
  BUILD_MAP 0
  STORE_FAST dict_str2
  LOAD_GLOBAL NULL + enumerate
  LOAD_FAST str1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L2
  UNPACK_SEQUENCE 2
  STORE_FAST i
  STORE_FAST value
  LOAD_FAST dict_str1
  LOAD_ATTR NULL|self + get
  LOAD_FAST value
  BUILD_LIST 0
  CALL 2
  LOAD_FAST i
  BUILD_LIST 1
  BINARY_OP +
  LOAD_FAST dict_str1
  LOAD_FAST value
  STORE_SUBSCR
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_GLOBAL NULL + enumerate
  LOAD_FAST str2
  CALL 1
  GET_ITER
L3:
  FOR_ITER L4
  UNPACK_SEQUENCE 2
  STORE_FAST j
  STORE_FAST value
  LOAD_FAST dict_str2
  LOAD_ATTR NULL|self + get
  LOAD_FAST value
  BUILD_LIST 0
  CALL 2
  LOAD_FAST j
  BUILD_LIST 1
  BINARY_OP +
  LOAD_FAST dict_str2
  LOAD_FAST value
  STORE_SUBSCR
  JUMP_BACKWARD L3
L4:
  END_FOR
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST dict_str1
  LOAD_ATTR NULL|self + values
  CALL 0
  CALL 1
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST dict_str2
  LOAD_ATTR NULL|self + values
  CALL 0
  CALL 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L5
  RETURN_CONST True
L5:
  RETURN_CONST False
END

def is_Isomorphic(str1, str2):
    dict_str1 = {}
    dict_str2 = {}
    for i, value in enumerate(str1):
        dict_str1[value] = dict_str1.get(value, []) + [i]
    for j, value in enumerate(str2):
        dict_str2[value] = dict_str2.get(value, []) + [j]
    if sorted(dict_str1.values()) == sorted(dict_str2.values()):
        return True
    else:
        return False

Prompt: Write a python function to check whether the two given strings are isomorphic to each other or not.

assert is_Isomorphic("paper","title") == True

assert is_Isomorphic("ab","aa") == False


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

def sum_num(numbers):
    total = 0
    for x in numbers:
        total += x
    return total / len(numbers)

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


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_odd>
  MAKE_FUNCTION 0
  STORE_NAME is_odd
  RETURN_CONST None
END
CODE is_odd(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP ^
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST True
L1:
  RETURN_CONST False
END

def is_odd(n):
    if n ^ 1 == n - 1:
        return True
    else:
        return False

Prompt: Write a python function to check whether the given number is odd or not using bitwise operator.

assert is_odd(5) == True
assert is_odd(6) == False
assert is_odd(7) == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code substract_elements>
  MAKE_FUNCTION 0
  STORE_NAME substract_elements
  RETURN_CONST None
END
CODE substract_elements(test_tup1, test_tup2)
  RESUME 0
  LOAD_GLOBAL NULL + tuple
  LOAD_CONST <code substract_elements.<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 substract_elements.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST tup1
  STORE_FAST tup2
  LOAD_GLOBAL NULL + tuple
  LOAD_CONST <code substract_elements.<locals>.<genexpr>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_GLOBAL NULL + zip
  LOAD_FAST tup1
  LOAD_FAST tup2
  CALL 2
  GET_ITER
  CALL 0
  CALL 1
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END
CODE substract_elements.<locals>.<genexpr>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST a
  STORE_FAST b
  LOAD_FAST a
  LOAD_FAST b
  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 substract_elements(test_tup1, test_tup2):
    res = tuple((tuple((a - b for a, b in zip(tup1, tup2))) for tup1, tup2 in zip(test_tup1, test_tup2)))
    return res

Prompt: Write a function to substract the elements of the given nested tuples.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code reverse_list_lists>
  MAKE_FUNCTION 0
  STORE_NAME reverse_list_lists
  RETURN_CONST None
END
CODE reverse_list_lists(lists)
  RESUME 0
  LOAD_FAST lists
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST l
  LOAD_FAST l
  LOAD_ATTR NULL|self + sort
  LOAD_CONST True
  KW_NAMES ('reverse',)
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST lists
  RETURN_VALUE
END

def reverse_list_lists(lists):
    for l in lists:
        l.sort(reverse=True)
    return lists

Prompt: Write a function to reverse each list in a given list of lists.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_Extra>
  MAKE_FUNCTION 0
  STORE_NAME find_Extra
  RETURN_CONST None
END
CODE find_Extra(arr1, arr2, 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 arr1
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr2
  LOAD_FAST i
  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
  LOAD_FAST n
  RETURN_VALUE
END

def find_Extra(arr1, arr2, n):
    for i in range(0, n):
        if arr1[i] != arr2[i]:
            return i
    return n

Prompt: Write a python function to find the index of an extra element present in one sorted array.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code same_Length>
  MAKE_FUNCTION 0
  STORE_NAME same_Length
  RETURN_CONST None
END
CODE same_Length(A, B)
  RESUME 0
  LOAD_FAST A
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
  LOAD_FAST B
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST A
  LOAD_CONST 10
  BINARY_OP /
  STORE_FAST A
  LOAD_FAST B
  LOAD_CONST 10
  BINARY_OP /
  STORE_FAST B
  LOAD_FAST A
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
  LOAD_FAST B
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST A
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_FAST B
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  RETURN_CONST True
L3:
  RETURN_CONST False
END

def same_Length(A, B):
    while A > 0 and B > 0:
        A = A / 10
        B = B / 10
    if A == 0 and B == 0:
        return True
    return False

Prompt: Write a python function to check whether the given two numbers have same number of digits or not.

assert same_Length(12,1) == False
assert same_Length(2,2) == True
assert same_Length(10,20) == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code max_sum_subseq>
  MAKE_FUNCTION 0
  STORE_NAME max_sum_subseq
  RETURN_CONST None
END
CODE max_sum_subseq(A)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST A
  CALL 1
  STORE_FAST n
  LOAD_FAST n
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_FAST A
  LOAD_CONST 0
  BINARY_SUBSCR
  RETURN_VALUE
L1:
  LOAD_CONST None
  BUILD_LIST 1
  LOAD_FAST n
  BINARY_OP *
  STORE_FAST look_up
  LOAD_FAST A
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST look_up
  LOAD_CONST 0
  STORE_SUBSCR
  LOAD_GLOBAL NULL + max
  LOAD_FAST A
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST A
  LOAD_CONST 1
  BINARY_SUBSCR
  CALL 2
  LOAD_FAST look_up
  LOAD_CONST 1
  STORE_SUBSCR
  LOAD_GLOBAL NULL + range
  LOAD_CONST 2
  LOAD_FAST n
  CALL 2
  GET_ITER
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_GLOBAL NULL + max
  LOAD_FAST look_up
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_FAST look_up
  LOAD_FAST i
  LOAD_CONST 2
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_FAST A
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP +
  CALL 2
  LOAD_FAST look_up
  LOAD_FAST i
  STORE_SUBSCR
  LOAD_GLOBAL NULL + max
  LOAD_FAST look_up
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST A
  LOAD_FAST i
  BINARY_SUBSCR
  CALL 2
  LOAD_FAST look_up
  LOAD_FAST i
  STORE_SUBSCR
  JUMP_BACKWARD L2
L3:
  END_FOR
  LOAD_FAST look_up
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  RETURN_VALUE
END

def max_sum_subseq(A):
    n = len(A)
    if n == 1:
        return A[0]
    look_up = [None] * n
    look_up[0] = A[0]
    look_up[1] = max(A[0], A[1])
    for i in range(2, n):
        look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i])
        look_up[i] = max(look_up[i], A[i])
    return look_up[n - 1]

Prompt: Write a function to find the maximum sum of subsequences of given array with no adjacent elements.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code last>
  MAKE_FUNCTION 0
  STORE_NAME last
  LOAD_CONST <code sort_list_last>
  MAKE_FUNCTION 0
  STORE_NAME sort_list_last
  RETURN_CONST None
END
CODE last(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST -1
  BINARY_SUBSCR
  RETURN_VALUE
END
CODE sort_list_last(tuples)
  RESUME 0
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST tuples
  LOAD_GLOBAL last
  KW_NAMES ('key',)
  CALL 2
  RETURN_VALUE
END

def last(n):
    return n[-1]

def sort_list_last(tuples):
    return sorted(tuples, key=last)

Prompt: Write a function to sort a list in increasing order by the last element in each tuple from a given list of non-empty tuples.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_Word_Present>
  MAKE_FUNCTION 0
  STORE_NAME is_Word_Present
  RETURN_CONST None
END
CODE is_Word_Present(sentence, word)
  RESUME 0
  LOAD_FAST sentence
  LOAD_ATTR NULL|self + split
  LOAD_CONST ' '
  CALL 1
  STORE_FAST s
  LOAD_FAST s
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST i
  LOAD_FAST word
  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_Word_Present(sentence, word):
    s = sentence.split(' ')
    for i in s:
        if i == word:
            return True
    return False

Prompt: Write a python function to check whether the word is present in a given sentence or not.

assert is_Word_Present("machine learning","machine") == True

assert is_Word_Present("easy","fun") == False

assert is_Word_Present("python language","code") == False


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 extract_elements>
  MAKE_FUNCTION 0
  STORE_NAME extract_elements
  RETURN_CONST None
END
CODE extract_elements(numbers, n)
  RESUME 0
  LOAD_GLOBAL NULL + groupby
  LOAD_FAST numbers
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  LOAD_FAST_AND_CLEAR j
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  UNPACK_SEQUENCE 2
  STORE_FAST i
  STORE_FAST j
  LOAD_GLOBAL NULL + len
  LOAD_GLOBAL NULL + list
  LOAD_FAST j
  CALL 1
  CALL 1
  LOAD_FAST n
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST i
  LIST_APPEND 2
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  STORE_FAST result
  STORE_FAST i
  STORE_FAST j
  LOAD_FAST result
  RETURN_VALUE
L7:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST j
  STORE_FAST i
  RERAISE 0
  EXC try=L1..L3 -> handler=L7 depth=3 lasti=False
  EXC try=L4..L6 -> handler=L7 depth=3 lasti=False
END

from itertools import groupby

def extract_elements(numbers, n):
    result = [i for i, j in groupby(numbers) if len(list(j)) == n]
    return result

Prompt: Write a function to extract specified number of elements from a given list, which follow each other continuously.


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

def check(arr, n):
    g = 0
    for i in range(1, n):
        if arr[i] - arr[i - 1] > 0 and g == 1:
            return False
        if arr[i] - arr[i] < 0:
            g = 1
    return True

Prompt: Write a python function to check whether an array can be sorted or not by picking only the corner elements.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code match_num>
  MAKE_FUNCTION 0
  STORE_NAME match_num
  RETURN_CONST None
END
CODE match_num(string)
  RESUME 0
  LOAD_GLOBAL NULL + re
  LOAD_ATTR compile
  LOAD_CONST '^5'
  CALL 1
  STORE_FAST text
  LOAD_FAST text
  LOAD_ATTR NULL|self + match
  LOAD_FAST string
  CALL 1
  POP_JUMP_IF_FALSE L1
  RETURN_CONST True
L1:
  RETURN_CONST False
END

import re

def match_num(string):
    text = re.compile('^5')
    if text.match(string):
        return True
    else:
        return False

Prompt: Write a function where a string will start with a specific number.

assert match_num('5-2345861')==True
assert match_num('6-2345861')==False
assert match_num('78910')==False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code smallest_multiple>
  MAKE_FUNCTION 0
  STORE_NAME smallest_multiple
  RETURN_CONST None
END
CODE smallest_multiple(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 2
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L1
  LOAD_FAST n
  RETURN_VALUE
L1:
  LOAD_FAST n
  LOAD_CONST 2
  BINARY_OP *
  STORE_FAST i
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  LOAD_CONST 1
  LOAD_CONST -1
  CALL 3
  GET_ITER
  LOAD_FAST_AND_CLEAR number
  SWAP 2
L2:
  BUILD_LIST 0
  SWAP 2
L3:
  FOR_ITER L6
  STORE_FAST number
  LOAD_FAST number
  LOAD_CONST 2
  BINARY_OP *
  LOAD_FAST n
  COMPARE_OP >
  POP_JUMP_IF_TRUE L5
L4:
  JUMP_BACKWARD L3
L5:
  LOAD_FAST number
  LIST_APPEND 2
  JUMP_BACKWARD L3
L6:
  END_FOR
L7:
  STORE_FAST factors
  STORE_FAST number
  NOP
L8:
  LOAD_FAST factors
  GET_ITER
L9:
  FOR_ITER L13
  STORE_FAST a
  LOAD_FAST i
  LOAD_FAST a
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L10
  LOAD_FAST i
  LOAD_FAST n
  BINARY_OP +=
  STORE_FAST i
  POP_TOP
  JUMP_FORWARD L14
L10:
  LOAD_FAST a
  LOAD_FAST factors
  LOAD_CONST -1
  BINARY_SUBSCR
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L11
  JUMP_BACKWARD L9
L11:
  LOAD_FAST i
  LOAD_FAST a
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L12
  JUMP_BACKWARD L9
L12:
  LOAD_FAST i
  SWAP 2
  POP_TOP
  RETURN_VALUE
L13:
  END_FOR
L14:
  JUMP_BACKWARD L8
L15:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST number
  RERAISE 0
  EXC try=L2..L4 -> handler=L15 depth=2 lasti=False
  EXC try=L5..L7 -> handler=L15 depth=2 lasti=False
END

def smallest_multiple(n):
    if n <= 2:
        return n
    i = n * 2
    factors = [number for number in range(n, 1, -1) if number * 2 > n]
    while True:
        for a in factors:
            if i % a != 0:
                i += n
                break
            if a == factors[-1] and i % a == 0:
                return i

Prompt: Write a function to find the smallest multiple of the first n numbers.

assert smallest_multiple(13)==360360
assert smallest_multiple(2)==2
assert smallest_multiple(1)==1


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 add_dict>
  MAKE_FUNCTION 0
  STORE_NAME add_dict
  RETURN_CONST None
END
CODE add_dict(d1, d2)
  RESUME 0
  LOAD_GLOBAL NULL + Counter
  LOAD_FAST d1
  CALL 1
  LOAD_GLOBAL NULL + Counter
  LOAD_FAST d2
  CALL 1
  BINARY_OP +
  STORE_FAST add_dict
  LOAD_FAST add_dict
  RETURN_VALUE
END

from collections import Counter

def add_dict(d1, d2):
    add_dict = Counter(d1) + Counter(d2)
    return add_dict

Prompt: Write a function to combine two dictionaries by adding values for common keys.


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

def count_Unset_Bits(n):
    cnt = 0
    for i in range(1, n + 1):
        temp = i
        while temp:
            if temp % 2 == 0:
                cnt += 1
            temp = temp // 2
    return cnt

Prompt: Write a python function to count the total unset bits from 1 to n.

assert count_Unset_Bits(2) == 1
assert count_Unset_Bits(5) == 4
assert count_Unset_Bits(14) == 17


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

def even_num(x):
    if x % 2 == 0:
        return True
    else:
        return False

Prompt: Write a function to return true if the given number is even else return false.

assert even_num(13.5)==False
assert even_num(0)==True
assert even_num(-9)==False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code factorial>
  MAKE_FUNCTION 0
  STORE_NAME factorial
  LOAD_CONST <code sum_of_square>
  MAKE_FUNCTION 0
  STORE_NAME sum_of_square
  RETURN_CONST None
END
CODE factorial(start, end)
  RESUME 0
  LOAD_CONST 1
  STORE_FAST res
  LOAD_GLOBAL NULL + range
  LOAD_FAST start
  LOAD_FAST end
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST res
  LOAD_FAST i
  BINARY_OP *=
  STORE_FAST res
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST res
  RETURN_VALUE
END
CODE sum_of_square(n)
  RESUME 0
  LOAD_GLOBAL NULL + int
  LOAD_GLOBAL NULL + factorial
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  LOAD_CONST 2
  LOAD_FAST n
  BINARY_OP *
  CALL 2
  LOAD_GLOBAL NULL + factorial
  LOAD_CONST 1
  LOAD_FAST n
  CALL 2
  BINARY_OP /
  CALL 1
  RETURN_VALUE
END

def factorial(start, end):
    res = 1
    for i in range(start, end + 1):
        res *= i
    return res

def sum_of_square(n):
    return int(factorial(n + 1, 2 * n) / factorial(1, n))

Prompt: Write a python function to find the sum of squares of binomial co-efficients.

assert sum_of_square(4) == 70
assert sum_of_square(5) == 252
assert sum_of_square(2) == 6


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code lucky_num>
  MAKE_FUNCTION 0
  STORE_NAME lucky_num
  RETURN_CONST None
END
CODE lucky_num(n)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_CONST -1
  LOAD_FAST n
  LOAD_FAST n
  BINARY_OP *
  LOAD_CONST 9
  BINARY_OP +
  LOAD_CONST 2
  CALL 3
  STORE_FAST List
  LOAD_CONST 2
  STORE_FAST i
  LOAD_FAST List
  LOAD_FAST i
  LOAD_CONST None
  BINARY_SLICE
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_GLOBAL NULL + sorted
  LOAD_GLOBAL NULL + set
  LOAD_FAST List
  CALL 1
  LOAD_GLOBAL NULL + set
  LOAD_FAST List
  LOAD_FAST List
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST None
  LOAD_FAST List
  LOAD_FAST i
  BINARY_SUBSCR
  BUILD_SLICE 3
  BINARY_SUBSCR
  CALL 1
  BINARY_OP -
  CALL 1
  STORE_FAST List
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST i
  LOAD_FAST List
  LOAD_FAST i
  LOAD_CONST None
  BINARY_SLICE
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST List
  LOAD_CONST 1
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SLICE
  RETURN_VALUE
END

def lucky_num(n):
    List = range(-1, n * n + 9, 2)
    i = 2
    while List[i:]:
        List = sorted(set(List) - set(List[List[i]::List[i]]))
        i += 1
    return List[1:n + 1]

Prompt: Write a function to print the first n lucky numbers.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_fixed_point>
  MAKE_FUNCTION 0
  STORE_NAME find_fixed_point
  RETURN_CONST None
END
CODE find_fixed_point(arr, n)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST i
  IS_OP 0
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST i
  SWAP 2
  POP_TOP
  RETURN_VALUE
L3:
  END_FOR
  RETURN_CONST -1
END

def find_fixed_point(arr, n):
    for i in range(n):
        if arr[i] is i:
            return i
    return -1

Prompt: Write a function to find the fixed point in the given array.


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

def previous_palindrome(num):
    for x in range(num - 1, 0, -1):
        if str(x) == str(x)[::-1]:
            return x

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

assert previous_palindrome(99)==88
assert previous_palindrome(1221)==1111
assert previous_palindrome(120)==111


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME datetime
  STORE_NAME datetime
  LOAD_CONST <code check_date>
  MAKE_FUNCTION 0
  STORE_NAME check_date
  RETURN_CONST None
END
CODE check_date(m, d, y)
  RESUME 0
  NOP
L1:
  LOAD_GLOBAL NULL + map
  LOAD_GLOBAL int
  LOAD_FAST m
  LOAD_FAST d
  LOAD_FAST y
  BUILD_TUPLE 3
  CALL 2
  UNPACK_SEQUENCE 3
  STORE_FAST m
  STORE_FAST d
  STORE_FAST y
  LOAD_GLOBAL NULL + datetime
  LOAD_ATTR date
  LOAD_FAST y
  LOAD_FAST m
  LOAD_FAST d
  CALL 3
  POP_TOP
L2:
  RETURN_CONST True
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL ValueError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L5
  POP_TOP
L4:
  POP_EXCEPT
  RETURN_CONST False
L5:
  RERAISE 0
L6:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L6 depth=1 lasti=True
  EXC try=L5..L6 -> handler=L6 depth=1 lasti=True
END

import datetime

def check_date(m, d, y):
    try:
        m, d, y = map(int, (m, d, y))
        datetime.date(y, m, d)
        return True
    except ValueError:
        return False

Prompt: Write a function to validate a gregorian date.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code end_num>
  MAKE_FUNCTION 0
  STORE_NAME end_num
  RETURN_CONST None
END
CODE end_num(string)
  RESUME 0
  LOAD_GLOBAL NULL + re
  LOAD_ATTR compile
  LOAD_CONST '.*[0-9]$'
  CALL 1
  STORE_FAST text
  LOAD_FAST text
  LOAD_ATTR NULL|self + match
  LOAD_FAST string
  CALL 1
  POP_JUMP_IF_FALSE L1
  RETURN_CONST True
L1:
  RETURN_CONST False
END

import re

def end_num(string):
    text = re.compile('.*[0-9]$')
    if text.match(string):
        return True
    else:
        return False

Prompt: Write a function to check for a number at the end of a string.

assert end_num('abcdef')==False
assert end_num('abcdef7')==True
assert end_num('abc')==False


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

def is_Two_Alter(s):
    for i in range(len(s) - 2):
        if s[i] != s[i + 2]:
            return False
    if s[0] == s[1]:
        return False
    return True

Prompt: Write a python function to check whether the given string is made up of two alternating characters or not.

assert is_Two_Alter("abab") == True
assert is_Two_Alter("aaaa") == False
assert is_Two_Alter("xyz") == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code rearrange_numbs>
  MAKE_FUNCTION 0
  STORE_NAME rearrange_numbs
  RETURN_CONST None
END
CODE rearrange_numbs(array_nums)
  RESUME 0
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST array_nums
  LOAD_CONST <code rearrange_numbs.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END
CODE rearrange_numbs.<locals>.<lambda>(i)
  RESUME 0
  LOAD_FAST i
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_CONST 0
  RETURN_VALUE
L1:
  LOAD_CONST -1
  LOAD_FAST i
  BINARY_OP /
  RETURN_VALUE
END

def rearrange_numbs(array_nums):
    result = sorted(array_nums, key=lambda i: 0 if i == 0 else -1 / i)
    return result

Prompt: Write a function to rearrange positive and negative numbers in a given array using lambda function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_triplet_array>
  MAKE_FUNCTION 0
  STORE_NAME find_triplet_array
  RETURN_CONST None
END
CODE find_triplet_array(A, arr_size, sum)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_FAST arr_size
  LOAD_CONST 2
  BINARY_OP -
  CALL 2
  GET_ITER
L1:
  FOR_ITER L7
  STORE_FAST i
  LOAD_GLOBAL NULL + range
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST arr_size
  LOAD_CONST 1
  BINARY_OP -
  CALL 2
  GET_ITER
L2:
  FOR_ITER L6
  STORE_FAST j
  LOAD_GLOBAL NULL + range
  LOAD_FAST j
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST arr_size
  CALL 2
  GET_ITER
L3:
  FOR_ITER L5
  STORE_FAST k
  LOAD_FAST A
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST A
  LOAD_FAST j
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_FAST A
  LOAD_FAST k
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_FAST sum
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L4
  JUMP_BACKWARD L3
L4:
  LOAD_FAST A
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST A
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_FAST A
  LOAD_FAST k
  BINARY_SUBSCR
  BUILD_TUPLE 3
  SWAP 2
  POP_TOP
  SWAP 2
  POP_TOP
  SWAP 2
  POP_TOP
  RETURN_VALUE
L5:
  END_FOR
  JUMP_BACKWARD L2
L6:
  END_FOR
  JUMP_BACKWARD L1
L7:
  END_FOR
  RETURN_CONST False
END

def find_triplet_array(A, arr_size, sum):
    for i in range(0, arr_size - 2):
        for j in range(i + 1, arr_size - 1):
            for k in range(j + 1, arr_size):
                if A[i] + A[j] + A[k] == sum:
                    return (A[i], A[j], A[k])
                    return True
    return False

Prompt: Write a function to find if there is a triplet in the array whose sum is equal to a given value.


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

import re

def text_uppercase_lowercase(text):
    patterns = '[A-Z]+[a-z]+$'
    if re.search(patterns, text):
        return 'Found a match!'
    else:
        return 'Not matched!'

Prompt: Write a function to find the sequences of one upper case letter followed by lower case letters.

assert text_uppercase_lowercase("AaBbGg")==('Found a match!')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code remove_tuple>
  MAKE_FUNCTION 0
  STORE_NAME remove_tuple
  RETURN_CONST None
END
CODE remove_tuple(test_list)
  RESUME 0
  LOAD_FAST test_list
  GET_ITER
  LOAD_FAST_AND_CLEAR sub
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  STORE_FAST sub
  LOAD_GLOBAL NULL + all
  LOAD_CONST <code remove_tuple.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_FAST sub
  GET_ITER
  CALL 0
  CALL 1
  POP_JUMP_IF_FALSE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST sub
  LIST_APPEND 2
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  STORE_FAST res
  STORE_FAST sub
  LOAD_GLOBAL NULL + str
  LOAD_FAST res
  CALL 1
  RETURN_VALUE
L7:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST sub
  RERAISE 0
  EXC try=L1..L3 -> handler=L7 depth=2 lasti=False
  EXC try=L4..L6 -> handler=L7 depth=2 lasti=False
END
CODE remove_tuple.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST ele
  LOAD_FAST ele
  LOAD_CONST None
  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 remove_tuple(test_list):
    res = [sub for sub in test_list if not all((ele == None for ele in sub))]
    return str(res)

Prompt: Write a function to remove all tuples with all none values in the given tuple list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code chunk_tuples>
  MAKE_FUNCTION 0
  STORE_NAME chunk_tuples
  RETURN_CONST None
END
CODE chunk_tuples(test_tup, N)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST test_tup
  CALL 1
  LOAD_FAST N
  CALL 3
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST test_tup
  LOAD_FAST i
  LOAD_FAST i
  LOAD_FAST N
  BINARY_OP +
  BINARY_SLICE
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST res
  STORE_FAST i
  LOAD_FAST res
  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 chunk_tuples(test_tup, N):
    res = [test_tup[i:i + N] for i in range(0, len(test_tup), N)]
    return res

Prompt: Write a function to perform chunking of tuples each of size n.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code max_product>
  MAKE_FUNCTION 0
  STORE_NAME max_product
  RETURN_CONST None
END
CODE max_product(arr)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST arr
  CALL 1
  STORE_FAST arr_len
  LOAD_FAST arr_len
  LOAD_CONST 2
  COMPARE_OP <
  POP_JUMP_IF_FALSE L1
  RETURN_CONST None
L1:
  LOAD_FAST arr
  LOAD_CONST 0
  BINARY_SUBSCR
  STORE_FAST x
  LOAD_FAST arr
  LOAD_CONST 1
  BINARY_SUBSCR
  STORE_FAST y
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_FAST arr_len
  CALL 2
  GET_ITER
L2:
  FOR_ITER L6
  STORE_FAST i
  LOAD_GLOBAL NULL + range
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST arr_len
  CALL 2
  GET_ITER
L3:
  FOR_ITER L5
  STORE_FAST j
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST j
  BINARY_SUBSCR
  BINARY_OP *
  LOAD_FAST x
  LOAD_FAST y
  BINARY_OP *
  COMPARE_OP >
  POP_JUMP_IF_TRUE L4
  JUMP_BACKWARD L3
L4:
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  STORE_FAST x
  LOAD_FAST arr
  LOAD_FAST j
  BINARY_SUBSCR
  STORE_FAST y
  JUMP_BACKWARD L3
L5:
  END_FOR
  JUMP_BACKWARD L2
L6:
  END_FOR
  LOAD_FAST x
  LOAD_FAST y
  BUILD_TUPLE 2
  RETURN_VALUE
END

def max_product(arr):
    arr_len = len(arr)
    if arr_len < 2:
        return None
    x = arr[0]
    y = arr[1]
    for i in range(0, arr_len):
        for j in range(i + 1, arr_len):
            if arr[i] * arr[j] > x * y:
                x = arr[i]
                y = arr[j]
    return (x, y)

Prompt: Write a function to find a pair with the highest product from a given array of integers.


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

def super_seq(X, Y, m, n):
    if not m:
        return n
    if not n:
        return m
    if X[m - 1] == Y[n - 1]:
        return 1 + super_seq(X, Y, m - 1, n - 1)
    return 1 + min(super_seq(X, Y, m - 1, n), super_seq(X, Y, m, n - 1))

Prompt: Write a function to find the length of the shortest string that has both str1 and str2 as subsequences.

assert super_seq("AGGTAB", "GXTXAYB", 6, 7) == 9

assert super_seq("feek", "eke", 4, 3) == 5

assert super_seq("PARRT", "RTA", 5, 3) == 6


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

def max_of_two(x, y):
    if x > y:
        return x
    return y

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

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


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code mutiple_tuple>
  MAKE_FUNCTION 0
  STORE_NAME mutiple_tuple
  RETURN_CONST None
END
CODE mutiple_tuple(nums)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_FAST nums
  CALL 1
  STORE_FAST temp
  LOAD_CONST 1
  STORE_FAST product
  LOAD_FAST temp
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST x
  LOAD_FAST product
  LOAD_FAST x
  BINARY_OP *=
  STORE_FAST product
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST product
  RETURN_VALUE
END

def mutiple_tuple(nums):
    temp = list(nums)
    product = 1
    for x in temp:
        product *= x
    return product

Prompt: Write a python function to calculate the product of all the numbers of a given tuple.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code change_date_format>
  MAKE_FUNCTION 0
  STORE_NAME change_date_format
  RETURN_CONST None
END
CODE change_date_format(dt)
  RESUME 0
  LOAD_GLOBAL NULL + re
  LOAD_ATTR sub
  LOAD_CONST '(\\d{4})-(\\d{1,2})-(\\d{1,2})'
  LOAD_CONST '\\3-\\2-\\1'
  LOAD_FAST dt
  CALL 3
  RETURN_VALUE
END

import re

def change_date_format(dt):
    return re.sub('(\\d{4})-(\\d{1,2})-(\\d{1,2})', '\\3-\\2-\\1', dt)
    return change_date_format(dt)

Prompt: Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code sum_series>
  MAKE_FUNCTION 0
  STORE_NAME sum_series
  RETURN_CONST None
END
CODE sum_series(number)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST total
  LOAD_GLOBAL NULL + math
  LOAD_ATTR pow
  LOAD_FAST number
  LOAD_FAST number
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP *
  LOAD_CONST 2
  BINARY_OP /
  LOAD_CONST 2
  CALL 2
  STORE_FAST total
  LOAD_FAST total
  RETURN_VALUE
END

import math

def sum_series(number):
    total = 0
    total = math.pow(number * (number + 1) / 2, 2)
    return total

Prompt: Write a function to calculate the sum of series 1³+2³+3³+….+n³.

assert sum_series(7)==784
assert sum_series(5)==225
assert sum_series(15)==14400


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

def dealnnoy_num(n, m):
    if m == 0 or n == 0:
        return 1
    return dealnnoy_num(m - 1, n) + dealnnoy_num(m - 1, n - 1) + dealnnoy_num(m, n - 1)

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

assert dealnnoy_num(3, 4) == 129
assert dealnnoy_num(3, 3) == 63
assert dealnnoy_num(4, 5) == 681


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

def series_sum(number):
    total = 0
    total = number * (number + 1) * (2 * number + 1) / 6
    return total

Prompt: Write a function to calculate the sum of series 1²+2²+3²+….+n².

assert series_sum(6)==91
assert series_sum(7)==140
assert series_sum(12)==650


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 max_char>
  MAKE_FUNCTION 0
  STORE_NAME max_char
  RETURN_CONST None
END
CODE max_char(str1)
  RESUME 0
  LOAD_GLOBAL NULL + Counter
  LOAD_FAST str1
  CALL 1
  STORE_FAST temp
  LOAD_GLOBAL NULL + max
  LOAD_FAST temp
  LOAD_FAST temp
  LOAD_ATTR get
  KW_NAMES ('key',)
  CALL 2
  STORE_FAST max_char
  LOAD_FAST max_char
  RETURN_VALUE
END

from collections import Counter

def max_char(str1):
    temp = Counter(str1)
    max_char = max(temp, key=temp.get)
    return max_char

Prompt: Write a function to count the most common character in a given string.

assert max_char("hello world")==('l')
assert max_char("hello ")==('l')
assert max_char("python pr")==('p')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sorted_models>
  MAKE_FUNCTION 0
  STORE_NAME sorted_models
  RETURN_CONST None
END
CODE sorted_models(models)
  RESUME 0
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST models
  LOAD_CONST <code sorted_models.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  STORE_FAST sorted_models
  LOAD_FAST sorted_models
  RETURN_VALUE
END
CODE sorted_models.<locals>.<lambda>(x)
  RESUME 0
  LOAD_FAST x
  LOAD_CONST 'color'
  BINARY_SUBSCR
  RETURN_VALUE
END

def sorted_models(models):
    sorted_models = sorted(models, key=lambda x: x['color'])
    return sorted_models

Prompt: Write a function to sort a list of dictionaries using lambda function.

assert sorted_models([{'make':'Nokia', 'model':216, 'color':'Black'}, {'make':'Mi Max', 'model':2, 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color':'Blue'}])==[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'Mi Max', 'model': 2, 'color': 'Gold'}]


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_elim>
  MAKE_FUNCTION 0
  STORE_NAME count_elim
  RETURN_CONST None
END
CODE count_elim(num)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST count_elim
  LOAD_FAST num
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST n
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST n
  LOAD_GLOBAL tuple
  CALL 2
  POP_JUMP_IF_FALSE L2
  POP_TOP
  LOAD_FAST count_elim
  RETURN_VALUE
L2:
  LOAD_FAST count_elim
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST count_elim
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST count_elim
  RETURN_VALUE
END

def count_elim(num):
    count_elim = 0
    for n in num:
        if isinstance(n, tuple):
            break
        count_elim += 1
    return count_elim

Prompt: Write a function to count the elements in a list until an element is a tuple.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_element>
  MAKE_FUNCTION 0
  STORE_NAME check_element
  RETURN_CONST None
END
CODE check_element(test_tup, check_list)
  RESUME 0
  LOAD_CONST False
  STORE_FAST res
  LOAD_FAST check_list
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST ele
  LOAD_FAST ele
  LOAD_FAST test_tup
  CONTAINS_OP 0
  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_element(test_tup, check_list):
    res = False
    for ele in check_list:
        if ele in test_tup:
            res = True
            break
    return res

Prompt: Write a function to check if any list element is present in the given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('merge',)
  IMPORT_NAME heapq
  IMPORT_FROM merge
  STORE_NAME merge
  POP_TOP
  LOAD_CONST <code combine_lists>
  MAKE_FUNCTION 0
  STORE_NAME combine_lists
  RETURN_CONST None
END
CODE combine_lists(num1, num2)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + merge
  LOAD_FAST num1
  LOAD_FAST num2
  CALL 2
  CALL 1
  STORE_FAST combine_lists
  LOAD_FAST combine_lists
  RETURN_VALUE
END

from heapq import merge

def combine_lists(num1, num2):
    combine_lists = list(merge(num1, num2))
    return combine_lists

Prompt: Write a function to combine two given sorted lists using heapq module.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code num_position>
  MAKE_FUNCTION 0
  STORE_NAME num_position
  RETURN_CONST None
END
CODE num_position(text)
  RESUME 0
  LOAD_GLOBAL NULL + re
  LOAD_ATTR finditer
  LOAD_CONST '\\d+'
  LOAD_FAST text
  CALL 2
  GET_ITER
  FOR_ITER L1
  STORE_FAST m
  LOAD_FAST m
  LOAD_ATTR NULL|self + start
  CALL 0
  SWAP 2
  POP_TOP
  RETURN_VALUE
L1:
  END_FOR
  RETURN_CONST None
END

import re

def num_position(text):
    for m in re.finditer('\\d+', text):
        return m.start()

Prompt: Write a function to separate and print the numbers and their position of a given string.

assert num_position("there are 70 flats in this apartment")==10

assert num_position("every adult have 32 teeth")==17

assert num_position("isha has 79 chocolates in her bag")==9


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 most_common_elem>
  MAKE_FUNCTION 0
  STORE_NAME most_common_elem
  RETURN_CONST None
END
CODE most_common_elem(s, a)
  RESUME 0
  LOAD_GLOBAL NULL + Counter
  LOAD_FAST s
  CALL 1
  LOAD_ATTR NULL|self + most_common
  LOAD_FAST a
  CALL 1
  STORE_FAST most_common_elem
  LOAD_FAST most_common_elem
  RETURN_VALUE
END

from collections import Counter

def most_common_elem(s, a):
    most_common_elem = Counter(s).most_common(a)
    return most_common_elem

Prompt: Write a function to find the most common elements and their counts of a specified text.

assert most_common_elem('lkseropewdssafsdfafkpwe',3)==[('s', 4), ('e', 3), ('f', 3)]

assert most_common_elem('lkseropewdssafsdfafkpwe',2)==[('s', 4), ('e', 3)]


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

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

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

assert len_log(["win","lose","great"]) == 3


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_item>
  MAKE_FUNCTION 0
  STORE_NAME get_item
  RETURN_CONST None
END
CODE get_item(tup1, index)
  RESUME 0
  LOAD_FAST tup1
  LOAD_FAST index
  BINARY_SUBSCR
  STORE_FAST item
  LOAD_FAST item
  RETURN_VALUE
END

def get_item(tup1, index):
    item = tup1[index]
    return item

Prompt: Write a function to get an item of a tuple.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_digs>
  MAKE_FUNCTION 0
  STORE_NAME count_digs
  LOAD_CONST <code sort_list>
  MAKE_FUNCTION 0
  STORE_NAME sort_list
  RETURN_CONST None
END
CODE count_digs(tup)
  RESUME 0
  LOAD_GLOBAL NULL + sum
  LOAD_FAST tup
  GET_ITER
  LOAD_FAST_AND_CLEAR ele
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST ele
  LOAD_GLOBAL NULL + len
  LOAD_GLOBAL NULL + str
  LOAD_FAST ele
  CALL 1
  CALL 1
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  SWAP 2
  STORE_FAST ele
  CALL 1
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ele
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=4 lasti=False
END
CODE sort_list(test_list)
  RESUME 0
  LOAD_FAST test_list
  LOAD_ATTR NULL|self + sort
  LOAD_GLOBAL count_digs
  KW_NAMES ('key',)
  CALL 1
  POP_TOP
  LOAD_GLOBAL NULL + str
  LOAD_FAST test_list
  CALL 1
  RETURN_VALUE
END

def count_digs(tup):
    return sum([len(str(ele)) for ele in tup])

def sort_list(test_list):
    test_list.sort(key=count_digs)
    return str(test_list)

Prompt: Write a function to sort the given tuple list basis the total digits in tuple.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code chinese_zodiac>
  MAKE_FUNCTION 0
  STORE_NAME chinese_zodiac
  RETURN_CONST None
END
CODE chinese_zodiac(year)
  RESUME 0
  LOAD_FAST year
  LOAD_CONST 2000
  BINARY_OP -
  LOAD_CONST 12
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_CONST 'Dragon'
  STORE_FAST sign
  LOAD_FAST sign
  RETURN_VALUE
L1:
  LOAD_FAST year
  LOAD_CONST 2000
  BINARY_OP -
  LOAD_CONST 12
  BINARY_OP %
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_CONST 'Snake'
  STORE_FAST sign
  LOAD_FAST sign
  RETURN_VALUE
L2:
  LOAD_FAST year
  LOAD_CONST 2000
  BINARY_OP -
  LOAD_CONST 12
  BINARY_OP %
  LOAD_CONST 2
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_CONST 'Horse'
  STORE_FAST sign
  LOAD_FAST sign
  RETURN_VALUE
L3:
  LOAD_FAST year
  LOAD_CONST 2000
  BINARY_OP -
  LOAD_CONST 12
  BINARY_OP %
  LOAD_CONST 3
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L4
  LOAD_CONST 'sheep'
  STORE_FAST sign
  LOAD_FAST sign
  RETURN_VALUE
L4:
  LOAD_FAST year
  LOAD_CONST 2000
  BINARY_OP -
  LOAD_CONST 12
  BINARY_OP %
  LOAD_CONST 4
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L5
  LOAD_CONST 'Monkey'
  STORE_FAST sign
  LOAD_FAST sign
  RETURN_VALUE
L5:
  LOAD_FAST year
  LOAD_CONST 2000
  BINARY_OP -
  LOAD_CONST 12
  BINARY_OP %
  LOAD_CONST 5
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L6
  LOAD_CONST 'Rooster'
  STORE_FAST sign
  LOAD_FAST sign
  RETURN_VALUE
L6:
  LOAD_FAST year
  LOAD_CONST 2000
  BINARY_OP -
  LOAD_CONST 12
  BINARY_OP %
  LOAD_CONST 6
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L7
  LOAD_CONST 'Dog'
  STORE_FAST sign
  LOAD_FAST sign
  RETURN_VALUE
L7:
  LOAD_FAST year
  LOAD_CONST 2000
  BINARY_OP -
  LOAD_CONST 12
  BINARY_OP %
  LOAD_CONST 7
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L8
  LOAD_CONST 'Pig'
  STORE_FAST sign
  LOAD_FAST sign
  RETURN_VALUE
L8:
  LOAD_FAST year
  LOAD_CONST 2000
  BINARY_OP -
  LOAD_CONST 12
  BINARY_OP %
  LOAD_CONST 8
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L9
  LOAD_CONST 'Rat'
  STORE_FAST sign
  LOAD_FAST sign
  RETURN_VALUE
L9:
  LOAD_FAST year
  LOAD_CONST 2000
  BINARY_OP -
  LOAD_CONST 12
  BINARY_OP %
  LOAD_CONST 9
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L10
  LOAD_CONST 'Ox'
  STORE_FAST sign
  LOAD_FAST sign
  RETURN_VALUE
L10:
  LOAD_FAST year
  LOAD_CONST 2000
  BINARY_OP -
  LOAD_CONST 12
  BINARY_OP %
  LOAD_CONST 10
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L11
  LOAD_CONST 'Tiger'
  STORE_FAST sign
  LOAD_FAST sign
  RETURN_VALUE
L11:
  LOAD_CONST 'Hare'
  STORE_FAST sign
  LOAD_FAST sign
  RETURN_VALUE
END

def chinese_zodiac(year):
    if (year - 2000) % 12 == 0:
        sign = 'Dragon'
    elif (year - 2000) % 12 == 1:
        sign = 'Snake'
    elif (year - 2000) % 12 == 2:
        sign = 'Horse'
    elif (year - 2000) % 12 == 3:
        sign = 'sheep'
    elif (year - 2000) % 12 == 4:
        sign = 'Monkey'
    elif (year - 2000) % 12 == 5:
        sign = 'Rooster'
    elif (year - 2000) % 12 == 6:
        sign = 'Dog'
    elif (year - 2000) % 12 == 7:
        sign = 'Pig'
    elif (year - 2000) % 12 == 8:
        sign = 'Rat'
    elif (year - 2000) % 12 == 9:
        sign = 'Ox'
    elif (year - 2000) % 12 == 10:
        sign = 'Tiger'
    else:
        sign = 'Hare'
    return sign

Prompt: Write a function to display sign of the chinese zodiac for given year.

assert chinese_zodiac(1997)==('Ox')
assert chinese_zodiac(1998)==('Tiger')
assert chinese_zodiac(1994)==('Dog')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code max_similar_indices>
  MAKE_FUNCTION 0
  STORE_NAME max_similar_indices
  RETURN_CONST None
END
CODE max_similar_indices(test_list1, test_list2)
  RESUME 0
  LOAD_GLOBAL NULL + zip
  LOAD_FAST test_list1
  LOAD_FAST test_list2
  CALL 2
  GET_ITER
  LOAD_FAST_AND_CLEAR x
  LOAD_FAST_AND_CLEAR y
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST x
  STORE_FAST y
  LOAD_GLOBAL NULL + max
  LOAD_FAST x
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST y
  LOAD_CONST 0
  BINARY_SUBSCR
  CALL 2
  LOAD_GLOBAL NULL + max
  LOAD_FAST x
  LOAD_CONST 1
  BINARY_SUBSCR
  LOAD_FAST y
  LOAD_CONST 1
  BINARY_SUBSCR
  CALL 2
  BUILD_TUPLE 2
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST res
  STORE_FAST x
  STORE_FAST y
  LOAD_FAST res
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST y
  STORE_FAST x
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=3 lasti=False
END

def max_similar_indices(test_list1, test_list2):
    res = [(max(x[0], y[0]), max(x[1], y[1])) for x, y in zip(test_list1, test_list2)]
    return res

Prompt: Write a function to find the maximum of similar indices in two lists of tuples.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code profit_amount>
  MAKE_FUNCTION 0
  STORE_NAME profit_amount
  RETURN_CONST None
END
CODE profit_amount(actual_cost, sale_amount)
  RESUME 0
  LOAD_FAST actual_cost
  LOAD_FAST sale_amount
  COMPARE_OP >
  POP_JUMP_IF_FALSE L1
  LOAD_FAST actual_cost
  LOAD_FAST sale_amount
  BINARY_OP -
  STORE_FAST amount
  LOAD_FAST amount
  RETURN_VALUE
L1:
  RETURN_CONST None
END

def profit_amount(actual_cost, sale_amount):
    if actual_cost > sale_amount:
        amount = actual_cost - sale_amount
        return amount
    else:
        return None

Prompt: Write a function that gives profit amount if the given amount has profit else return none.

assert profit_amount(1500,1200)==300
assert profit_amount(100,200)==None
assert profit_amount(2000,5000)==None


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

def is_abundant(n):
    fctrsum = sum([fctr for fctr in range(1, n) if n % fctr == 0])
    return fctrsum > n

Prompt: Write a function to find out, if the given number is abundant.

assert is_abundant(12)==True
assert is_abundant(13)==False
assert is_abundant(9)==False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code get_First_Set_Bit_Pos>
  MAKE_FUNCTION 0
  STORE_NAME get_First_Set_Bit_Pos
  RETURN_CONST None
END
CODE get_First_Set_Bit_Pos(n)
  RESUME 0
  LOAD_GLOBAL NULL + math
  LOAD_ATTR log2
  LOAD_FAST n
  LOAD_FAST n
  UNARY_NEGATIVE
  BINARY_OP &
  CALL 1
  LOAD_CONST 1
  BINARY_OP +
  RETURN_VALUE
END

import math

def get_First_Set_Bit_Pos(n):
    return math.log2(n & -n) + 1

Prompt: Write a python function to get the position of rightmost set bit.

assert get_First_Set_Bit_Pos(12) == 3
assert get_First_Set_Bit_Pos(18) == 2
assert get_First_Set_Bit_Pos(16) == 5


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code int_to_roman>
  MAKE_FUNCTION 0
  STORE_NAME int_to_roman
  RETURN_CONST None
END
CODE int_to_roman(num)
  RESUME 0
  BUILD_LIST 0
  LOAD_CONST (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
  LIST_EXTEND 1
  STORE_FAST val
  BUILD_LIST 0
  LOAD_CONST ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
  LIST_EXTEND 1
  STORE_FAST syb
  LOAD_CONST ''
  STORE_FAST roman_num
  LOAD_CONST 0
  STORE_FAST i
  LOAD_FAST num
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L4
L1:
  LOAD_GLOBAL NULL + range
  LOAD_FAST num
  LOAD_FAST val
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP //
  CALL 1
  GET_ITER
L2:
  FOR_ITER L3
  STORE_FAST _
  LOAD_FAST roman_num
  LOAD_FAST syb
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP +=
  STORE_FAST roman_num
  LOAD_FAST num
  LOAD_FAST val
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP -=
  STORE_FAST num
  JUMP_BACKWARD L2
L3:
  END_FOR
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST i
  LOAD_FAST num
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L4
  JUMP_BACKWARD L1
L4:
  LOAD_FAST roman_num
  RETURN_VALUE
END

Prompt: Write a function to convert an integer into a roman numeral.

assert int_to_roman(1)==("I")
assert int_to_roman(50)==("L")
assert int_to_roman(4)==("IV")


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

def get_noOfways(n):
    if n == 0:
        return 0
    if n == 1:
        return 1
    return get_noOfways(n - 1) + get_noOfways(n - 2)

Prompt: Write a function to solve tiling problem.

assert get_noOfways(4)==3
assert get_noOfways(3)==2
assert get_noOfways(5)==5


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code roman_to_int>
  MAKE_FUNCTION 0
  STORE_NAME roman_to_int
  RETURN_CONST None
END
CODE roman_to_int(s)
  RESUME 0
  LOAD_CONST 1
  LOAD_CONST 5
  LOAD_CONST 10
  LOAD_CONST 50
  LOAD_CONST 100
  LOAD_CONST 500
  LOAD_CONST 1000
  LOAD_CONST ('I', 'V', 'X', 'L', 'C', 'D', 'M')
  BUILD_CONST_KEY_MAP 7
  STORE_FAST rom_val
  LOAD_CONST 0
  STORE_FAST int_val
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST s
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST i
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
  LOAD_FAST rom_val
  LOAD_FAST s
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_SUBSCR
  LOAD_FAST rom_val
  LOAD_FAST s
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  BINARY_SUBSCR
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
  LOAD_FAST int_val
  LOAD_FAST rom_val
  LOAD_FAST s
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_SUBSCR
  LOAD_CONST 2
  LOAD_FAST rom_val
  LOAD_FAST s
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  BINARY_SUBSCR
  BINARY_OP *
  BINARY_OP -
  BINARY_OP +=
  STORE_FAST int_val
  JUMP_BACKWARD L1
L2:
  LOAD_FAST int_val
  LOAD_FAST rom_val
  LOAD_FAST s
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_SUBSCR
  BINARY_OP +=
  STORE_FAST int_val
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST int_val
  RETURN_VALUE
END

def roman_to_int(s):
    rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
    int_val = 0
    for i in range(len(s)):
        if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]:
            int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]]
        else:
            int_val += rom_val[s[i]]
    return int_val

Prompt: Write a function to convert a roman numeral to an integer.


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

def sum_Natural(n):
    sum = n * (n + 1)
    return int(sum)

def sum_Even(l, r):
    return sum_Natural(int(r / 2)) - sum_Natural(int((l - 1) / 2))

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

assert sum_Even(2,5) == 6
assert sum_Even(3,8) == 18
assert sum_Even(4,6) == 10


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

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

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

assert word_len("program") == False
assert word_len("solution") == True
assert word_len("data") == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code camel_to_snake>
  MAKE_FUNCTION 0
  STORE_NAME camel_to_snake
  RETURN_CONST None
END
CODE camel_to_snake(text)
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_FAST re
  LOAD_FAST re
  LOAD_ATTR NULL|self + sub
  LOAD_CONST '(.)([A-Z][a-z]+)'
  LOAD_CONST '\\1_\\2'
  LOAD_FAST text
  CALL 3
  STORE_FAST str1
  LOAD_FAST re
  LOAD_ATTR NULL|self + sub
  LOAD_CONST '([a-z0-9])([A-Z])'
  LOAD_CONST '\\1_\\2'
  LOAD_FAST str1
  CALL 3
  LOAD_ATTR NULL|self + lower
  CALL 0
  RETURN_VALUE
END

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