ReasonFLux-Coder
Collection
Coding LLMs excel at both writing code and generating unit tests.
•
9 items
•
Updated
•
6
source_file
stringclasses 4
values | task_id
int64 0
256
| prompt
stringlengths 39
252
| code
stringlengths 36
906
| test_imports
sequencelengths 0
0
| test_list
sequencelengths 3
5
| exe_method
stringclasses 1
value | test_time_limit
int64 1
1
| solutions
null | dataset
stringclasses 1
value | test_input
sequencelengths 3
5
| test_output
sequencelengths 3
5
| example_input
sequencelengths 2
2
| example_output
sequencelengths 2
2
| question
stringlengths 752
4.29k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Benchmark Questions Verification V2.ipynb | 0 | Write a python function to remove first and last occurrence of a given character from the string. | def remove_Occ(s,ch):
for i in range(len(s)):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
for i in range(len(s) - 1,-1,-1):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
return s | [] | [
"assert remove_Occ(\"hello\",\"l\") == \"heo\"",
"assert remove_Occ(\"abcda\",\"a\") == \"bcd\"",
"assert remove_Occ(\"PHP\",\"P\") == \"H\""
] | stdin | 1 | null | MBPP | [
"hello\nl\n",
"abcda\na\n",
"PHP\nP\n"
] | [
"heo\n",
"bcd\n",
"H\n"
] | [
"hello\nl\n",
"abcda\na\n"
] | [
"heo\n",
"bcd\n"
] | Original problem description:
Write a python function to remove first and last occurrence of a given character from the string.
We have its functional test sample:
assert remove_Occ("hello","l") == "heo"
assert remove_Occ("abcda","a") == "bcd"
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
hello
l
Output:
heo
Example 2:
Input:
abcda
a
Output:
bcd
|
Benchmark Questions Verification V2.ipynb | 1 | Write a function to sort a given matrix in ascending order according to the sum of its rows. | def sort_matrix(M):
result = sorted(M, key=sum)
return result | [] | [
"assert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]]",
"assert sort_matrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])==[[-2, 4, -5], [1, -1, 1], [1, 2, 3]]",
"assert sort_matrix([[5,8,9],[6,4,3],[2,1,4]])==[[2, 1, 4], [6, 4, 3], [5, 8, 9]]"
] | stdin | 1 | null | MBPP | [
"1 2 3\n2 4 5\n1 1 1\n",
"1 2 3\n-2 4 -5\n1 -1 1\n",
"5 8 9\n6 4 3\n2 1 4\n"
] | [
"1 1 1\n1 2 3\n2 4 5\n",
"-2 4 -5\n1 -1 1\n1 2 3\n",
"2 1 4\n6 4 3\n5 8 9\n"
] | [
"1 2 3\n2 4 5\n1 1 1\n",
"1 2 3\n-2 4 -5\n1 -1 1\n"
] | [
"1 1 1\n1 2 3\n2 4 5\n",
"-2 4 -5\n1 -1 1\n1 2 3\n"
] | Original problem description:
Write a function to sort a given matrix in ascending order according to the sum of its rows.
We have its functional test sample:
assert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]]
assert sort_matrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])==[[-2, 4, -5], [1, -1, 1], [1, 2, 3]]
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1 2 3
2 4 5
1 1 1
Output:
1 1 1
1 2 3
2 4 5
Example 2:
Input:
1 2 3
-2 4 -5
1 -1 1
Output:
-2 4 -5
1 -1 1
1 2 3
|
Benchmark Questions Verification V2.ipynb | 2 | Write a python function to find the volume of a triangular prism. | def find_Volume(l,b,h) :
return ((l * b * h) / 2) | [] | [
"assert find_Volume(10,8,6) == 240",
"assert find_Volume(3,2,2) == 6",
"assert find_Volume(1,2,1) == 1"
] | stdin | 1 | null | MBPP | [
"10\n8\n6\n",
"3\n2\n2\n",
"1\n2\n1\n"
] | [
"240\n",
"6\n",
"1\n"
] | [
"10\n8\n6\n",
"3\n2\n2\n"
] | [
"240\n",
"6\n"
] | Original problem description:
Write a python function to find the volume of a triangular prism.
We have its functional test sample:
assert find_Volume(10,8,6) == 240
assert find_Volume(3,2,2) == 6
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10
8
6
Output:
240
Example 2:
Input:
3
2
2
Output:
6
|
Benchmark Questions Verification V2.ipynb | 3 | Write a function to that returns true if the input string contains sequences of lowercase letters joined with an underscore and false otherwise. | import re
def text_lowercase_underscore(text):
patterns = '^[a-z]+_[a-z]+$'
if re.search(patterns, text):
return True
else:
return False | [] | [
"assert text_lowercase_underscore(\"aab_cbbbc\")==(True)",
"assert text_lowercase_underscore(\"aab_Abbbc\")==(False)",
"assert text_lowercase_underscore(\"Aaab_abbbc\")==(False)"
] | stdin | 1 | null | MBPP | [
"aab_cbbbc\n",
"aab_Abbbc\n",
"Aaab_abbbc\n"
] | [
"True\n",
"False\n",
"False\n"
] | [
"aab_cbbbc\n",
"aab_Abbbc\n"
] | [
"True\n",
"False\n"
] | Original problem description:
Write a function to that returns true if the input string contains sequences of lowercase letters joined with an underscore and false otherwise.
We have its functional test sample:
assert text_lowercase_underscore("aab_cbbbc")==(True)
assert text_lowercase_underscore("aab_Abbbc")==(False)
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
aab_cbbbc
Output:
True
Example 2:
Input:
aab_Abbbc
Output:
False
|
Benchmark Questions Verification V2.ipynb | 4 | Write a function that returns the perimeter of a square given its side length as input. | def square_perimeter(a):
perimeter=4*a
return perimeter | [] | [
"assert square_perimeter(10)==40",
"assert square_perimeter(5)==20",
"assert square_perimeter(4)==16"
] | stdin | 1 | null | MBPP | [
"10\n",
"5\n",
"4\n"
] | [
"40\n",
"20\n",
"16\n"
] | [
"10\n",
"5\n"
] | [
"40\n",
"20\n"
] | Original problem description:
Write a function that returns the perimeter of a square given its side length as input.
We have its functional test sample:
assert square_perimeter(10)==40
assert square_perimeter(5)==20
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10
Output:
40
Example 2:
Input:
5
Output:
20
|
Benchmark Questions Verification V2.ipynb | 5 | Write a function to remove characters from the first string which are present in the second string. | NO_OF_CHARS = 256
def str_to_list(string):
temp = []
for x in string:
temp.append(x)
return temp
def lst_to_string(List):
return ''.join(List)
def get_char_count_array(string):
count = [0] * NO_OF_CHARS
for i in string:
count[ord(i)] += 1
return count
def remove_dirty_chars(string, second_string):
count = get_char_count_array(second_string)
ip_ind = 0
res_ind = 0
temp = ''
str_list = str_to_list(string)
while ip_ind != len(str_list):
temp = str_list[ip_ind]
if count[ord(temp)] == 0:
str_list[res_ind] = str_list[ip_ind]
res_ind += 1
ip_ind+=1
return lst_to_string(str_list[0:res_ind]) | [] | [
"assert remove_dirty_chars(\"probasscurve\", \"pros\") == 'bacuve'",
"assert remove_dirty_chars(\"digitalindia\", \"talent\") == 'digiidi'",
"assert remove_dirty_chars(\"exoticmiles\", \"toxic\") == 'emles'"
] | stdin | 1 | null | MBPP | [
"probasscurve\npros\n",
"digitalindia\ntalent\n",
"exoticmiles\ntoxic\n"
] | [
"bacuve\n",
"digiidi\n",
"emles\n"
] | [
"probasscurve\npros\n",
"digitalindia\ntalent\n"
] | [
"bacuve\n",
"digiidi\n"
] | Original problem description:
Write a function to remove characters from the first string which are present in the second string.
We have its functional test sample:
assert remove_dirty_chars("probasscurve", "pros") == 'bacuve'
assert remove_dirty_chars("digitalindia", "talent") == 'digiidi'
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
probasscurve
pros
Output:
bacuve
Example 2:
Input:
digitalindia
talent
Output:
digiidi
|
Benchmark Questions Verification V2.ipynb | 6 | Write a function to find whether a given array of integers contains any duplicate element. | def test_duplicate(arraynums):
nums_set = set(arraynums)
return len(arraynums) != len(nums_set) | [] | [
"assert test_duplicate(([1,2,3,4,5]))==False",
"assert test_duplicate(([1,2,3,4, 4]))==True",
"assert test_duplicate([1,1,2,2,3,3,4,4,5])==True"
] | stdin | 1 | null | MBPP | [
"1 2 3 4 5\n",
"1 2 3 4 4\n",
"1 1 2 2 3 3 4 4 5\n"
] | [
"False\n",
"True\n",
"True\n"
] | [
"1 2 3 4 5\n",
"1 2 3 4 4\n"
] | [
"False\n",
"True\n"
] | Original problem description:
Write a function to find whether a given array of integers contains any duplicate element.
We have its functional test sample:
assert test_duplicate(([1,2,3,4,5]))==False
assert test_duplicate(([1,2,3,4, 4]))==True
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1 2 3 4 5
Output:
False
Example 2:
Input:
1 2 3 4 4
Output:
True
|
Benchmark Questions Verification V2.ipynb | 7 | Write a function to check if the given number is woodball or not. | def is_woodall(x):
if (x % 2 == 0):
return False
if (x == 1):
return True
x = x + 1
p = 0
while (x % 2 == 0):
x = x/2
p = p + 1
if (p == x):
return True
return False | [] | [
"assert is_woodall(383) == True",
"assert is_woodall(254) == False",
"assert is_woodall(200) == False"
] | stdin | 1 | null | MBPP | [
"383\n",
"254\n",
"200\n"
] | [
"True\n",
"False\n",
"False\n"
] | [
"383\n",
"254\n"
] | [
"True\n",
"False\n"
] | Original problem description:
Write a function to check if the given number is woodball or not.
We have its functional test sample:
assert is_woodall(383) == True
assert is_woodall(254) == False
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
383
Output:
True
Example 2:
Input:
254
Output:
False
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 8 | Write a python function to check if a given number is one less than twice its reverse. | def rev(num):
rev_num = 0
while (num > 0):
rev_num = (rev_num * 10 + num % 10)
num = num // 10
return rev_num
def check(n):
return (2 * rev(n) == n + 1) | [] | [
"assert check(70) == False",
"assert check(23) == False",
"assert check(73) == True"
] | stdin | 1 | null | MBPP | [
"70\n",
"23\n",
"73\n"
] | [
"False\n",
"False\n",
"True\n"
] | [
"70\n",
"23\n"
] | [
"False\n",
"False\n"
] | Original problem description:
Write a python function to check if a given number is one less than twice its reverse.
We have its functional test sample:
assert check(70) == False
assert check(23) == False
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
70
Output:
False
Example 2:
Input:
23
Output:
False
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 9 | Write a python function to find the largest number that can be formed with the given list of digits. | def find_Max_Num(arr) :
n = len(arr)
arr.sort(reverse = True)
num = arr[0]
for i in range(1,n) :
num = num * 10 + arr[i]
return num | [] | [
"assert find_Max_Num([1,2,3]) == 321",
"assert find_Max_Num([4,5,6,1]) == 6541",
"assert find_Max_Num([1,2,3,9]) == 9321"
] | stdin | 1 | null | MBPP | [
"1 2 3\n",
"4 5 6 1\n",
"1 2 3 9\n"
] | [
"321\n",
"6541\n",
"9321\n"
] | [
"1 2 3\n",
"4 5 6 1\n"
] | [
"321\n",
"6541\n"
] | Original problem description:
Write a python function to find the largest number that can be formed with the given list of digits.
We have its functional test sample:
assert find_Max_Num([1,2,3]) == 321
assert find_Max_Num([4,5,6,1]) == 6541
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1 2 3
Output:
321
Example 2:
Input:
4 5 6 1
Output:
6541
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 10 | Write a python function to check whether the given two integers have opposite sign or not. | def opposite_Signs(x,y):
return ((x ^ y) < 0); | [] | [
"assert opposite_Signs(1,-2) == True",
"assert opposite_Signs(3,2) == False",
"assert opposite_Signs(-10,-10) == False",
"assert opposite_Signs(-2,2) == True"
] | stdin | 1 | null | MBPP | [
"1\n-2\n",
"3\n2\n",
"-10\n-10\n",
"-2\n2\n"
] | [
"True\n",
"False\n",
"False\n",
"True\n"
] | [
"1\n-2\n",
"3\n2\n"
] | [
"True\n",
"False\n"
] | Original problem description:
Write a python function to check whether the given two integers have opposite sign or not.
We have its functional test sample:
assert opposite_Signs(1,-2) == True
assert opposite_Signs(3,2) == False
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1
-2
Output:
True
Example 2:
Input:
3
2
Output:
False
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 11 | Write a function to find the nth octagonal number. | def is_octagonal(n):
return 3 * n * n - 2 * n | [] | [
"assert is_octagonal(5) == 65",
"assert is_octagonal(10) == 280",
"assert is_octagonal(15) == 645"
] | stdin | 1 | null | MBPP | [
"5\n",
"10\n",
"15\n"
] | [
"65\n",
"280\n",
"645\n"
] | [
"5\n",
"10\n"
] | [
"65\n",
"280\n"
] | Original problem description:
Write a function to find the nth octagonal number.
We have its functional test sample:
assert is_octagonal(5) == 65
assert is_octagonal(10) == 280
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
5
Output:
65
Example 2:
Input:
10
Output:
280
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 12 | Write a python function to count the number of substrings with the sum of digits equal to their length. | from collections import defaultdict
def count_Substrings(s):
n = len(s)
count,sum = 0,0
mp = defaultdict(lambda : 0)
mp[0] += 1
for i in range(n):
sum += ord(s[i]) - ord('0')
count += mp[sum - (i + 1)]
mp[sum - (i + 1)] += 1
return count | [] | [
"assert count_Substrings('112112') == 6",
"assert count_Substrings('111') == 6",
"assert count_Substrings('1101112') == 12"
] | stdin | 1 | null | MBPP | [
"112112\n",
"111\n",
"1101112\n"
] | [
"6\n",
"6\n",
"12\n"
] | [
"112112\n",
"111\n"
] | [
"6\n",
"6\n"
] | Original problem description:
Write a python function to count the number of substrings with the sum of digits equal to their length.
We have its functional test sample:
assert count_Substrings('112112') == 6
assert count_Substrings('111') == 6
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
112112
Output:
6
Example 2:
Input:
111
Output:
6
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 13 | Write a python function to find smallest number in a list. | def smallest_num(xs):
return min(xs)
| [] | [
"assert smallest_num([10, 20, 1, 45, 99]) == 1",
"assert smallest_num([1, 2, 3]) == 1",
"assert smallest_num([45, 46, 50, 60]) == 45"
] | stdin | 1 | null | MBPP | [
"10 20 1 45 99\n",
"1 2 3\n",
"45 46 50 60\n"
] | [
"1\n",
"1\n",
"45\n"
] | [
"10 20 1 45 99\n",
"1 2 3\n"
] | [
"1\n",
"1\n"
] | Original problem description:
Write a python function to find smallest number in a list.
We have its functional test sample:
assert smallest_num([10, 20, 1, 45, 99]) == 1
assert smallest_num([1, 2, 3]) == 1
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10 20 1 45 99
Output:
1
Example 2:
Input:
1 2 3
Output:
1
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 14 | Write a function to find the maximum difference between available pairs in the given tuple list. | def max_difference(test_list):
temp = [abs(b - a) for a, b in test_list]
res = max(temp)
return (res) | [] | [
"assert max_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 7",
"assert max_difference([(4, 6), (2, 17), (9, 13), (11, 12)]) == 15",
"assert max_difference([(12, 35), (21, 27), (13, 23), (41, 22)]) == 23"
] | stdin | 1 | null | MBPP | [
"3 5\n1 7\n10 3\n1 2\n",
"4 6\n2 17\n9 13\n11 12\n",
"12 35\n21 27\n13 23\n41 22\n"
] | [
"7\n",
"15\n",
"23\n"
] | [
"3 5\n1 7\n10 3\n1 2\n",
"4 6\n2 17\n9 13\n11 12\n"
] | [
"7\n",
"15\n"
] | Original problem description:
Write a function to find the maximum difference between available pairs in the given tuple list.
We have its functional test sample:
assert max_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 7
assert max_difference([(4, 6), (2, 17), (9, 13), (11, 12)]) == 15
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
3 5
1 7
10 3
1 2
Output:
7
Example 2:
Input:
4 6
2 17
9 13
11 12
Output:
15
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 17 | Write a python function to count the number of positive numbers in a list. | def pos_count(list):
pos_count= 0
for num in list:
if num >= 0:
pos_count += 1
return pos_count | [] | [
"assert pos_count([1,-2,3,-4]) == 2",
"assert pos_count([3,4,5,-1]) == 3",
"assert pos_count([1,2,3,4]) == 4"
] | stdin | 1 | null | MBPP | [
"1 -2 3 -4\n",
"3 4 5 -1\n",
"1 2 3 4\n"
] | [
"2\n",
"3\n",
"4\n"
] | [
"1 -2 3 -4\n",
"3 4 5 -1\n"
] | [
"2\n",
"3\n"
] | Original problem description:
Write a python function to count the number of positive numbers in a list.
We have its functional test sample:
assert pos_count([1,-2,3,-4]) == 2
assert pos_count([3,4,5,-1]) == 3
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1 -2 3 -4
Output:
2
Example 2:
Input:
3 4 5 -1
Output:
3
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 18 | Write a function to find the number of ways to partition a set of Bell numbers. | def bell_number(n):
bell = [[0 for i in range(n+1)] for j in range(n+1)]
bell[0][0] = 1
for i in range(1, n+1):
bell[i][0] = bell[i-1][i-1]
for j in range(1, i+1):
bell[i][j] = bell[i-1][j-1] + bell[i][j-1]
return bell[n][0] | [] | [
"assert bell_number(2)==2",
"assert bell_number(10)==115975",
"assert bell_number(56)==6775685320645824322581483068371419745979053216268760300"
] | stdin | 1 | null | MBPP | [
"2\n",
"10\n",
"56\n"
] | [
"2\n",
"115975\n",
"6775685320645824322581483068371419745979053216268760300\n"
] | [
"2\n",
"10\n"
] | [
"2\n",
"115975\n"
] | Original problem description:
Write a function to find the number of ways to partition a set of Bell numbers.
We have its functional test sample:
assert bell_number(2)==2
assert bell_number(10)==115975
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
2
Output:
2
Example 2:
Input:
10
Output:
115975
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 19 | Write a python function to check whether the given array is monotonic or not. | def is_Monotonic(A):
return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or
all(A[i] >= A[i + 1] for i in range(len(A) - 1))) | [] | [
"assert is_Monotonic([6, 5, 4, 4]) == True",
"assert is_Monotonic([1, 2, 2, 3]) == True",
"assert is_Monotonic([1, 3, 2]) == False"
] | stdin | 1 | null | MBPP | [
"6 5 4 4\n",
"1 2 2 3\n",
"1 3 2\n"
] | [
"True\n",
"True\n",
"False\n"
] | [
"6 5 4 4\n",
"1 2 2 3\n"
] | [
"True\n",
"True\n"
] | Original problem description:
Write a python function to check whether the given array is monotonic or not.
We have its functional test sample:
assert is_Monotonic([6, 5, 4, 4]) == True
assert is_Monotonic([1, 2, 2, 3]) == True
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
6 5 4 4
Output:
True
Example 2:
Input:
1 2 2 3
Output:
True
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 20 | Write a function to check whether a list contains the given sublist or not. | def is_sublist(l, s):
sub_set = False
if s == []:
sub_set = True
elif s == l:
sub_set = True
elif len(s) > len(l):
sub_set = False
else:
for i in range(len(l)):
if l[i] == s[0]:
n = 1
while (n < len(s)) and (l[i+n] == s[n]):
n += 1
if n == len(s):
sub_set = True
return sub_set | [] | [
"assert is_sublist([2,4,3,5,7],[3,7])==False",
"assert is_sublist([2,4,3,5,7],[4,3])==True",
"assert is_sublist([2,4,3,5,7],[1,6])==False"
] | stdin | 1 | null | MBPP | [
"2 4 3 5 7\n3 7\n",
"2 4 3 5 7\n4 3\n",
"2 4 3 5 7\n1 6\n"
] | [
"False\n",
"True\n",
"False\n"
] | [
"2 4 3 5 7\n3 7\n",
"2 4 3 5 7\n4 3\n"
] | [
"False\n",
"True\n"
] | Original problem description:
Write a function to check whether a list contains the given sublist or not.
We have its functional test sample:
assert is_sublist([2,4,3,5,7],[3,7])==False
assert is_sublist([2,4,3,5,7],[4,3])==True
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
2 4 3 5 7
3 7
Output:
False
Example 2:
Input:
2 4 3 5 7
4 3
Output:
True
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 21 | Write a function to find whether all the given tuples have equal length or not. | def find_equal_tuple(Input):
k = 0 if not Input else len(Input[0])
flag = 1
for tuple in Input:
if len(tuple) != k:
flag = 0
break
return flag
def get_equal(Input):
return find_equal_tuple(Input) == 1 | [] | [
"assert get_equal([(11, 22, 33), (44, 55, 66)]) == True",
"assert get_equal([(1, 2, 3), (4, 5, 6, 7)]) == False",
"assert get_equal([(1, 2), (3, 4)]) == True"
] | stdin | 1 | null | MBPP | [
"11 22 33\n44 55 66\n",
"1 2 3\n4 5 6 7\n",
"1 2\n3 4\n"
] | [
"True\n",
"False\n",
"True\n"
] | [
"11 22 33\n44 55 66\n",
"1 2 3\n4 5 6 7\n"
] | [
"True\n",
"False\n"
] | Original problem description:
Write a function to find whether all the given tuples have equal length or not.
We have its functional test sample:
assert get_equal([(11, 22, 33), (44, 55, 66)]) == True
assert get_equal([(1, 2, 3), (4, 5, 6, 7)]) == False
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
11 22 33
44 55 66
Output:
True
Example 2:
Input:
1 2 3
4 5 6 7
Output:
False
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 22 | Write a function to sort a list of elements. | def comb_sort(nums):
shrink_fact = 1.3
gaps = len(nums)
swapped = True
i = 0
while gaps > 1 or swapped:
gaps = int(float(gaps) / shrink_fact)
swapped = False
i = 0
while gaps + i < len(nums):
if nums[i] > nums[i+gaps]:
nums[i], nums[i+gaps] = nums[i+gaps], nums[i]
swapped = True
i += 1
return nums | [] | [
"assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79]",
"assert comb_sort([41, 32, 15, 19, 22]) == [15, 19, 22, 32, 41]",
"assert comb_sort([99, 15, 13, 47]) == [13, 15, 47, 99]"
] | stdin | 1 | null | MBPP | [
"5 15 37 25 79\n",
"41 32 15 19 22\n",
"99 15 13 47\n"
] | [
"5 15 25 37 79\n",
"15 19 22 32 41\n",
"13 15 47 99\n"
] | [
"5 15 37 25 79\n",
"41 32 15 19 22\n"
] | [
"5 15 25 37 79\n",
"15 19 22 32 41\n"
] | Original problem description:
Write a function to sort a list of elements.
We have its functional test sample:
assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79]
assert comb_sort([41, 32, 15, 19, 22]) == [15, 19, 22, 32, 41]
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
5 15 37 25 79
Output:
5 15 25 37 79
Example 2:
Input:
41 32 15 19 22
Output:
15 19 22 32 41
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 23 | Write a python function to check whether the given number can be represented as the difference of two squares or not. | def dif_Square(n):
if (n % 4 != 2):
return True
return False | [] | [
"assert dif_Square(5) == True",
"assert dif_Square(10) == False",
"assert dif_Square(15) == True"
] | stdin | 1 | null | MBPP | [
"5\n",
"10\n",
"15\n"
] | [
"True\n",
"False\n",
"True\n"
] | [
"5\n",
"10\n"
] | [
"True\n",
"False\n"
] | Original problem description:
Write a python function to check whether the given number can be represented as the difference of two squares or not.
We have its functional test sample:
assert dif_Square(5) == True
assert dif_Square(10) == False
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
5
Output:
True
Example 2:
Input:
10
Output:
False
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 24 | Write a function to check whether it follows the sequence given in the patterns array. | def is_samepatterns(colors, patterns):
if len(colors) != len(patterns):
return False
sdict = {}
pset = set()
sset = set()
for i in range(len(patterns)):
pset.add(patterns[i])
sset.add(colors[i])
if patterns[i] not in sdict.keys():
sdict[patterns[i]] = []
keys = sdict[patterns[i]]
keys.append(colors[i])
sdict[patterns[i]] = keys
if len(pset) != len(sset):
return False
for values in sdict.values():
for i in range(len(values) - 1):
if values[i] != values[i+1]:
return False
return True | [] | [
"assert is_samepatterns([\"red\",\"green\",\"green\"], [\"a\", \"b\", \"b\"])==True",
"assert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\",\"b\"])==False",
"assert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\"])==False"
] | stdin | 1 | null | MBPP | [
"red green green\na b b\n",
"red green greenn\na b b\n",
"red green greenn\na b\n"
] | [
"True\n",
"False\n",
"False\n"
] | [
"red green green\na b b\n",
"red green greenn\na b b\n"
] | [
"True\n",
"False\n"
] | Original problem description:
Write a function to check whether it follows the sequence given in the patterns array.
We have its functional test sample:
assert is_samepatterns(["red","green","green"], ["a", "b", "b"])==True
assert is_samepatterns(["red","green","greenn"], ["a","b","b"])==False
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
red green green
a b b
Output:
True
Example 2:
Input:
red green greenn
a b b
Output:
False
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 26 | Write a python function to find whether a number is divisible by 11. | def is_Diff(n):
return (n % 11 == 0) | [] | [
"assert is_Diff (12345) == False",
"assert is_Diff(1212112) == True",
"assert is_Diff(1212) == False"
] | stdin | 1 | null | MBPP | [
"12345\n",
"1212112\n",
"1212\n"
] | [
"False\n",
"True\n",
"False\n"
] | [
"12345\n",
"1212112\n"
] | [
"False\n",
"True\n"
] | Original problem description:
Write a python function to find whether a number is divisible by 11.
We have its functional test sample:
assert is_Diff (12345) == False
assert is_Diff(1212112) == True
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
12345
Output:
False
Example 2:
Input:
1212112
Output:
True
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 27 | Write a python function to check whether the length of the word is odd or not. | def word_len(s):
s = s.split(' ')
for word in s:
if len(word)%2!=0:
return True
else:
return False | [] | [
"assert word_len(\"Hadoop\") == False",
"assert word_len(\"great\") == True",
"assert word_len(\"structure\") == True"
] | stdin | 1 | null | MBPP | [
"Hadoop\n",
"great\n",
"structure\n"
] | [
"False\n",
"True\n",
"True\n"
] | [
"Hadoop\n",
"great\n"
] | [
"False\n",
"True\n"
] | Original problem description:
Write a python function to check whether the length of the word is odd or not.
We have its functional test sample:
assert word_len("Hadoop") == False
assert word_len("great") == True
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
Hadoop
Output:
False
Example 2:
Input:
great
Output:
True
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 28 | Write a function to find the nth tetrahedral number. | def tetrahedral_number(n):
return (n * (n + 1) * (n + 2)) / 6 | [] | [
"assert tetrahedral_number(5) == 35",
"assert tetrahedral_number(6) == 56",
"assert tetrahedral_number(7) == 84"
] | stdin | 1 | null | MBPP | [
"5\n",
"6\n",
"7\n"
] | [
"35\n",
"56\n",
"84\n"
] | [
"5\n",
"6\n"
] | [
"35\n",
"56\n"
] | Original problem description:
Write a function to find the nth tetrahedral number.
We have its functional test sample:
assert tetrahedral_number(5) == 35
assert tetrahedral_number(6) == 56
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
5
Output:
35
Example 2:
Input:
6
Output:
56
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 30 | Write a python function to find the character made by adding the ASCII value of all the characters of the given string modulo 26. | def get_Char(strr):
summ = 0
for i in range(len(strr)):
summ += (ord(strr[i]) - ord('a') + 1)
if (summ % 26 == 0):
return ord('z')
else:
summ = summ % 26
return chr(ord('a') + summ - 1) | [] | [
"assert get_Char(\"abc\") == \"f\"",
"assert get_Char(\"gfg\") == \"t\"",
"assert get_Char(\"ab\") == \"c\""
] | stdin | 1 | null | MBPP | [
"abc\n",
"gfg\n",
"ab\n"
] | [
"f\n",
"t\n",
"c\n"
] | [
"abc\n",
"gfg\n"
] | [
"f\n",
"t\n"
] | Original problem description:
Write a python function to find the character made by adding the ASCII value of all the characters of the given string modulo 26.
We have its functional test sample:
assert get_Char("abc") == "f"
assert get_Char("gfg") == "t"
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
abc
Output:
f
Example 2:
Input:
gfg
Output:
t
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 31 | Write a function to find the nth number in the newman conway sequence. | def sequence(n):
if n == 1 or n == 2:
return 1
else:
return sequence(sequence(n-1)) + sequence(n-sequence(n-1)) | [] | [
"assert sequence(10) == 6",
"assert sequence(2) == 1",
"assert sequence(3) == 2"
] | stdin | 1 | null | MBPP | [
"10\n",
"2\n",
"3\n"
] | [
"6\n",
"1\n",
"2\n"
] | [
"10\n",
"2\n"
] | [
"6\n",
"1\n"
] | Original problem description:
Write a function to find the nth number in the newman conway sequence.
We have its functional test sample:
assert sequence(10) == 6
assert sequence(2) == 1
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10
Output:
6
Example 2:
Input:
2
Output:
1
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 33 | Write a function to find nth centered hexagonal number. | def centered_hexagonal_number(n):
return 3 * n * (n - 1) + 1 | [] | [
"assert centered_hexagonal_number(10) == 271",
"assert centered_hexagonal_number(2) == 7",
"assert centered_hexagonal_number(9) == 217"
] | stdin | 1 | null | MBPP | [
"10\n",
"2\n",
"9\n"
] | [
"271\n",
"7\n",
"217\n"
] | [
"10\n",
"2\n"
] | [
"271\n",
"7\n"
] | Original problem description:
Write a function to find nth centered hexagonal number.
We have its functional test sample:
assert centered_hexagonal_number(10) == 271
assert centered_hexagonal_number(2) == 7
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10
Output:
271
Example 2:
Input:
2
Output:
7
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 36 | Write a function to find the closest smaller number than n. | def closest_num(N):
return (N - 1) | [] | [
"assert closest_num(11) == 10",
"assert closest_num(7) == 6",
"assert closest_num(12) == 11"
] | stdin | 1 | null | MBPP | [
"11\n",
"7\n",
"12\n"
] | [
"10\n",
"6\n",
"11\n"
] | [
"11\n",
"7\n"
] | [
"10\n",
"6\n"
] | Original problem description:
Write a function to find the closest smaller number than n.
We have its functional test sample:
assert closest_num(11) == 10
assert closest_num(7) == 6
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
11
Output:
10
Example 2:
Input:
7
Output:
6
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 37 | Write a python function to find the length of the longest word. | def len_log(list1):
max=len(list1[0])
for i in list1:
if len(i)>max:
max=len(i)
return max | [] | [
"assert len_log([\"python\",\"PHP\",\"bigdata\"]) == 7",
"assert len_log([\"a\",\"ab\",\"abc\"]) == 3",
"assert len_log([\"small\",\"big\",\"tall\"]) == 5"
] | stdin | 1 | null | MBPP | [
"python PHP bigdata\n",
"a ab abc\n",
"small big tall\n"
] | [
"7\n",
"3\n",
"5\n"
] | [
"python PHP bigdata\n",
"a ab abc\n"
] | [
"7\n",
"3\n"
] | Original problem description:
Write a python function to find the length of the longest word.
We have its functional test sample:
assert len_log(["python","PHP","bigdata"]) == 7
assert len_log(["a","ab","abc"]) == 3
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
python PHP bigdata
Output:
7
Example 2:
Input:
a ab abc
Output:
3
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 38 | Write a function to check if a string is present as a substring in a given list of string values. | def find_substring(str1, sub_str):
if any(sub_str in s for s in str1):
return True
return False | [] | [
"assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ack\")==True",
"assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"abc\")==False",
"assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ange\")==True"
] | stdin | 1 | null | MBPP | [
"red black white green orange\nack\n",
"red black white green orange\nabc\n",
"red black white green orange\nange\n"
] | [
"True\n",
"False\n",
"True\n"
] | [
"red black white green orange\nack\n",
"red black white green orange\nabc\n"
] | [
"True\n",
"False\n"
] | Original problem description:
Write a function to check if a string is present as a substring in a given list of string values.
We have its functional test sample:
assert find_substring(["red", "black", "white", "green", "orange"],"ack")==True
assert find_substring(["red", "black", "white", "green", "orange"],"abc")==False
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
red black white green orange
ack
Output:
True
Example 2:
Input:
red black white green orange
abc
Output:
False
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 39 | Write a function to check whether the given number is undulating or not. | def is_undulating(n):
n = str(n)
if (len(n) <= 2):
return False
for i in range(2, len(n)):
if (n[i - 2] != n[i]):
return False
return True | [] | [
"assert is_undulating(1212121) == True",
"assert is_undulating(1991) == False",
"assert is_undulating(121) == True"
] | stdin | 1 | null | MBPP | [
"1212121\n",
"1991\n",
"121\n"
] | [
"True\n",
"False\n",
"True\n"
] | [
"1212121\n",
"1991\n"
] | [
"True\n",
"False\n"
] | Original problem description:
Write a function to check whether the given number is undulating or not.
We have its functional test sample:
assert is_undulating(1212121) == True
assert is_undulating(1991) == False
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1212121
Output:
True
Example 2:
Input:
1991
Output:
False
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 40 | Write a function to calculate the value of 'a' to the power 'b'. | def power(a,b):
if b==0:
return 1
elif a==0:
return 0
elif b==1:
return a
else:
return a*power(a,b-1) | [] | [
"assert power(3,4) == 81",
"assert power(2,3) == 8",
"assert power(5,5) == 3125"
] | stdin | 1 | null | MBPP | [
"3\n4\n",
"2\n3\n",
"5\n5\n"
] | [
"81\n",
"8\n",
"3125\n"
] | [
"3\n4\n",
"2\n3\n"
] | [
"81\n",
"8\n"
] | Original problem description:
Write a function to calculate the value of 'a' to the power 'b'.
We have its functional test sample:
assert power(3,4) == 81
assert power(2,3) == 8
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
3
4
Output:
81
Example 2:
Input:
2
3
Output:
8
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 41 | Given a list of tuples, write a function that returns the first value of the tuple with the smallest second value. | from operator import itemgetter
def index_minimum(test_list):
res = min(test_list, key = itemgetter(1))[0]
return (res) | [] | [
"assert index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]) == 'Varsha'",
"assert index_minimum([('Yash', 185), ('Dawood', 125), ('Sanya', 175)]) == 'Dawood'",
"assert index_minimum([('Sai', 345), ('Salman', 145), ('Ayesha', 96)]) == 'Ayesha'"
] | stdin | 1 | null | MBPP | [
"Rash 143\nManjeet 200\nVarsha 100\n",
"Yash 185\nDawood 125\nSanya 175\n",
"Sai 345\nSalman 145\nAyesha 96\n"
] | [
"Varsha\n",
"Dawood\n",
"Ayesha\n"
] | [
"Rash 143\nManjeet 200\nVarsha 100\n",
"Yash 185\nDawood 125\nSanya 175\n"
] | [
"Varsha\n",
"Dawood\n"
] | Original problem description:
Given a list of tuples, write a function that returns the first value of the tuple with the smallest second value.
We have its functional test sample:
assert index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]) == 'Varsha'
assert index_minimum([('Yash', 185), ('Dawood', 125), ('Sanya', 175)]) == 'Dawood'
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
Rash 143
Manjeet 200
Varsha 100
Output:
Varsha
Example 2:
Input:
Yash 185
Dawood 125
Sanya 175
Output:
Dawood
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 42 | Write a python function to find the length of the smallest list in a list of lists. | def Find_Min_Length(lst):
minLength = min(len(x) for x in lst )
return minLength | [] | [
"assert Find_Min_Length([[1],[1,2]]) == 1",
"assert Find_Min_Length([[1,2],[1,2,3],[1,2,3,4]]) == 2",
"assert Find_Min_Length([[3,3,3],[4,4,4,4]]) == 3"
] | stdin | 1 | null | MBPP | [
"1\n1 2\n",
"1 2\n1 2 3\n1 2 3 4\n",
"3 3 3\n4 4 4 4\n"
] | [
"1\n",
"2\n",
"3\n"
] | [
"1\n1 2\n",
"1 2\n1 2 3\n1 2 3 4\n"
] | [
"1\n",
"2\n"
] | Original problem description:
Write a python function to find the length of the smallest list in a list of lists.
We have its functional test sample:
assert Find_Min_Length([[1],[1,2]]) == 1
assert Find_Min_Length([[1,2],[1,2,3],[1,2,3,4]]) == 2
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1
1 2
Output:
1
Example 2:
Input:
1 2
1 2 3
1 2 3 4
Output:
2
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 43 | Write a python function to find the number of divisors of a given integer. | def divisor(n):
for i in range(n):
x = len([i for i in range(1,n+1) if not n % i])
return x | [] | [
"assert divisor(15) == 4",
"assert divisor(12) == 6",
"assert divisor(9) == 3"
] | stdin | 1 | null | MBPP | [
"15\n",
"12\n",
"9\n"
] | [
"4\n",
"6\n",
"3\n"
] | [
"15\n",
"12\n"
] | [
"4\n",
"6\n"
] | Original problem description:
Write a python function to find the number of divisors of a given integer.
We have its functional test sample:
assert divisor(15) == 4
assert divisor(12) == 6
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
15
Output:
4
Example 2:
Input:
12
Output:
6
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 46 | Write a function to convert the given decimal number to its binary equivalent, represented as a string with no leading zeros. | def decimal_to_binary(n):
return bin(n).replace("0b","") | [] | [
"assert decimal_to_binary(8) == '1000'",
"assert decimal_to_binary(18) == '10010'",
"assert decimal_to_binary(7) == '111'"
] | stdin | 1 | null | MBPP | [
"8\n",
"18\n",
"7\n"
] | [
"1000\n",
"10010\n",
"111\n"
] | [
"8\n",
"18\n"
] | [
"1000\n",
"10010\n"
] | Original problem description:
Write a function to convert the given decimal number to its binary equivalent, represented as a string with no leading zeros.
We have its functional test sample:
assert decimal_to_binary(8) == '1000'
assert decimal_to_binary(18) == '10010'
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
8
Output:
1000
Example 2:
Input:
18
Output:
10010
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 47 | Write a function to find the next smallest palindrome of a specified integer, returned as an integer. | import sys
def next_smallest_palindrome(num):
numstr = str(num)
for i in range(num+1,sys.maxsize):
if str(i) == str(i)[::-1]:
return i | [] | [
"assert next_smallest_palindrome(99)==101",
"assert next_smallest_palindrome(1221)==1331",
"assert next_smallest_palindrome(120)==121"
] | stdin | 1 | null | MBPP | [
"99\n",
"1221\n",
"120\n"
] | [
"101\n",
"1331\n",
"121\n"
] | [
"99\n",
"1221\n"
] | [
"101\n",
"1331\n"
] | Original problem description:
Write a function to find the next smallest palindrome of a specified integer, returned as an integer.
We have its functional test sample:
assert next_smallest_palindrome(99)==101
assert next_smallest_palindrome(1221)==1331
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
99
Output:
101
Example 2:
Input:
1221
Output:
1331
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 48 | Write a function to find the kth element in the given array using 1-based indexing. | def kth_element(arr, k):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] == arr[j+1], arr[j]
return arr[k-1] | [] | [
"assert kth_element([12,3,5,7,19], 2) == 3",
"assert kth_element([17,24,8,23], 3) == 8",
"assert kth_element([16,21,25,36,4], 4) == 36"
] | stdin | 1 | null | MBPP | [
"12 3 5 7 19\n2\n",
"17 24 8 23\n3\n",
"16 21 25 36 4\n4\n"
] | [
"3\n",
"8\n",
"36\n"
] | [
"12 3 5 7 19\n2\n",
"17 24 8 23\n3\n"
] | [
"3\n",
"8\n"
] | Original problem description:
Write a function to find the kth element in the given array using 1-based indexing.
We have its functional test sample:
assert kth_element([12,3,5,7,19], 2) == 3
assert kth_element([17,24,8,23], 3) == 8
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
12 3 5 7 19
2
Output:
3
Example 2:
Input:
17 24 8 23
3
Output:
8
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 49 | Write a function to convert a snake case string to camel case string. | def snake_to_camel(word):
import re
return ''.join(x.capitalize() or '_' for x in word.split('_')) | [] | [
"assert snake_to_camel('python_program')=='PythonProgram'",
"assert snake_to_camel('python_language')==('PythonLanguage')",
"assert snake_to_camel('programming_language')==('ProgrammingLanguage')"
] | stdin | 1 | null | MBPP | [
"python_program\n",
"python_language\n",
"programming_language\n"
] | [
"PythonProgram\n",
"PythonLanguage\n",
"ProgrammingLanguage\n"
] | [
"python_program\n",
"python_language\n"
] | [
"PythonProgram\n",
"PythonLanguage\n"
] | Original problem description:
Write a function to convert a snake case string to camel case string.
We have its functional test sample:
assert snake_to_camel('python_program')=='PythonProgram'
assert snake_to_camel('python_language')==('PythonLanguage')
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
python_program
Output:
PythonProgram
Example 2:
Input:
python_language
Output:
PythonLanguage
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 50 | Write a function to find the Eulerian number a(n, m). | def eulerian_num(n, m):
if (m >= n or n == 0):
return 0
if (m == 0):
return 1
return ((n - m) * eulerian_num(n - 1, m - 1) +(m + 1) * eulerian_num(n - 1, m)) | [] | [
"assert eulerian_num(3, 1) == 4",
"assert eulerian_num(4, 1) == 11",
"assert eulerian_num(5, 3) == 26"
] | stdin | 1 | null | MBPP | [
"3\n1\n",
"4\n1\n",
"5\n3\n"
] | [
"4\n",
"11\n",
"26\n"
] | [
"3\n1\n",
"4\n1\n"
] | [
"4\n",
"11\n"
] | Original problem description:
Write a function to find the Eulerian number a(n, m).
We have its functional test sample:
assert eulerian_num(3, 1) == 4
assert eulerian_num(4, 1) == 11
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
3
1
Output:
4
Example 2:
Input:
4
1
Output:
11
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 51 | Write a function to sort each sublist of strings in a given list of lists. | def sort_sublists(input_list):
result = [sorted(x, key = lambda x:x[0]) for x in input_list]
return result
| [] | [
"assert sort_sublists(([\"green\", \"orange\"], [\"black\", \"white\"], [\"white\", \"black\", \"orange\"]))==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]",
"assert sort_sublists(([\" red \",\"green\" ],[\"blue \",\" black\"],[\" orange\",\"brown\"]))==[[' red ', 'green'], [' black', 'blue '], [' orange', 'brown']]",
"assert sort_sublists(([\"zilver\",\"gold\"], [\"magnesium\",\"aluminium\"], [\"steel\", \"bronze\"]))==[['gold', 'zilver'],['aluminium', 'magnesium'], ['bronze', 'steel']]"
] | stdin | 1 | null | MBPP | [
"green orange\nblack white\nwhite black orange\n",
"red green\nblue black\n orange brown\n",
"zilver gold\nmagnesium aluminium\nsteel bronze\n"
] | [
"green orange\nblack white\nblack orange white\n",
"red green\n black blue \n orange brown\n",
"gold zilver\naluminium magnesium\nbronze steel\n"
] | [
"green orange\nblack white\nwhite black orange\n",
"red green\nblue black\n orange brown\n"
] | [
"green orange\nblack white\nblack orange white\n",
"red green\n black blue \n orange brown\n"
] | Original problem description:
Write a function to sort each sublist of strings in a given list of lists.
We have its functional test sample:
assert sort_sublists((["green", "orange"], ["black", "white"], ["white", "black", "orange"]))==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]
assert sort_sublists(([" red ","green" ],["blue "," black"],[" orange","brown"]))==[[' red ', 'green'], [' black', 'blue '], [' orange', 'brown']]
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
green orange
black white
white black orange
Output:
green orange
black white
black orange white
Example 2:
Input:
red green
blue black
orange brown
Output:
red green
black blue
orange brown
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 52 | Write a python function to count true booleans in the given list. | def count(lst):
return sum(lst) | [] | [
"assert count([True,False,True]) == 2",
"assert count([False,False]) == 0",
"assert count([True,True,True]) == 3"
] | stdin | 1 | null | MBPP | [
"True False True\n",
"False False\n",
"True True True\n"
] | [
"2\n",
"0\n",
"3\n"
] | [
"True False True\n",
"False False\n"
] | [
"2\n",
"0\n"
] | Original problem description:
Write a python function to count true booleans in the given list.
We have its functional test sample:
assert count([True,False,True]) == 2
assert count([False,False]) == 0
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
True False True
Output:
2
Example 2:
Input:
False False
Output:
0
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 53 | Write a function to append the given list to the given tuples. | def add_lists(test_list, test_tup):
res = tuple(list(test_tup) + test_list)
return (res) | [] | [
"assert add_lists([5, 6, 7], (9, 10)) == (9, 10, 5, 6, 7)",
"assert add_lists([6, 7, 8], (10, 11)) == (10, 11, 6, 7, 8)",
"assert add_lists([7, 8, 9], (11, 12)) == (11, 12, 7, 8, 9)"
] | stdin | 1 | null | MBPP | [
"5 6 7\n9 10\n",
"6 7 8\n10 11\n",
"7 8 9\n11 12\n"
] | [
"9 10 5 6 7\n",
"10 11 6 7 8\n",
"11 12 7 8 9\n"
] | [
"5 6 7\n9 10\n",
"6 7 8\n10 11\n"
] | [
"9 10 5 6 7\n",
"10 11 6 7 8\n"
] | Original problem description:
Write a function to append the given list to the given tuples.
We have its functional test sample:
assert add_lists([5, 6, 7], (9, 10)) == (9, 10, 5, 6, 7)
assert add_lists([6, 7, 8], (10, 11)) == (10, 11, 6, 7, 8)
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
5 6 7
9 10
Output:
9 10 5 6 7
Example 2:
Input:
6 7 8
10 11
Output:
10 11 6 7 8
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 54 | Write a function to merge three lists into a single sorted list. | import heapq
def merge_sorted_list(num1,num2,num3):
num1=sorted(num1)
num2=sorted(num2)
num3=sorted(num3)
result = heapq.merge(num1,num2,num3)
return list(result) | [] | [
"assert merge_sorted_list([25, 24, 15, 4, 5, 29, 110],[19, 20, 11, 56, 25, 233, 154],[24, 26, 54, 48])==[4, 5, 11, 15, 19, 20, 24, 24, 25, 25, 26, 29, 48, 54, 56, 110, 154, 233]",
"assert merge_sorted_list([1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12])==[1, 1, 2, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 11, 12]",
"assert merge_sorted_list([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1],[25, 35, 22, 85, 14, 65, 75, 25, 58],[12, 74, 9, 50, 61, 41])==[1, 2, 3, 4, 7, 8, 9, 9, 9, 10, 12, 14, 14, 18, 22, 25, 25, 35, 41, 50, 58, 61, 65, 74, 75, 85]"
] | stdin | 1 | null | MBPP | [
"25 24 15 4 5 29 110\n19 20 11 56 25 233 154\n24 26 54 48\n",
"1 3 5 6 8 9\n2 5 7 11\n1 4 7 8 12\n",
"18 14 10 9 8 7 9 3 2 4 1\n25 35 22 85 14 65 75 25 58\n12 74 9 50 61 41\n"
] | [
"4 5 11 15 19 20 24 24 25 25 26 29 48 54 56 110 154 233\n",
"1 1 2 3 4 5 5 6 7 7 8 8 9 11 12\n",
"1 2 3 4 7 8 9 9 9 10 12 14 14 18 22 25 25 35 41 50 58 61 65 74 75 85\n"
] | [
"25 24 15 4 5 29 110\n19 20 11 56 25 233 154\n24 26 54 48\n",
"1 3 5 6 8 9\n2 5 7 11\n1 4 7 8 12\n"
] | [
"4 5 11 15 19 20 24 24 25 25 26 29 48 54 56 110 154 233\n",
"1 1 2 3 4 5 5 6 7 7 8 8 9 11 12\n"
] | Original problem description:
Write a function to merge three lists into a single sorted list.
We have its functional test sample:
assert merge_sorted_list([25, 24, 15, 4, 5, 29, 110],[19, 20, 11, 56, 25, 233, 154],[24, 26, 54, 48])==[4, 5, 11, 15, 19, 20, 24, 24, 25, 25, 26, 29, 48, 54, 56, 110, 154, 233]
assert merge_sorted_list([1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12])==[1, 1, 2, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 11, 12]
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
25 24 15 4 5 29 110
19 20 11 56 25 233 154
24 26 54 48
Output:
4 5 11 15 19 20 24 24 25 25 26 29 48 54 56 110 154 233
Example 2:
Input:
1 3 5 6 8 9
2 5 7 11
1 4 7 8 12
Output:
1 1 2 3 4 5 5 6 7 7 8 8 9 11 12
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 55 | Write a python function to find the number of numbers with an odd value when rotating a binary string the given number of times. | def odd_Equivalent(s,n):
count=0
for i in range(0,n):
if (s[i] == '1'):
count = count + 1
return count | [] | [
"assert odd_Equivalent(\"011001\",6) == 3",
"assert odd_Equivalent(\"11011\",5) == 4",
"assert odd_Equivalent(\"1010\",4) == 2"
] | stdin | 1 | null | MBPP | [
"011001\n6\n",
"11011\n5\n",
"1010\n4\n"
] | [
"3\n",
"4\n",
"2\n"
] | [
"011001\n6\n",
"11011\n5\n"
] | [
"3\n",
"4\n"
] | Original problem description:
Write a python function to find the number of numbers with an odd value when rotating a binary string the given number of times.
We have its functional test sample:
assert odd_Equivalent("011001",6) == 3
assert odd_Equivalent("11011",5) == 4
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
011001
6
Output:
3
Example 2:
Input:
11011
5
Output:
4
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 56 | Write a function to find the common elements in given nested lists. | def common_in_nested_lists(nestedlist):
result = list(set.intersection(*map(set, nestedlist)))
return result | [] | [
"assert set(common_in_nested_lists([[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]]))==set([18, 12])",
"assert set(common_in_nested_lists([[12, 5, 23, 25, 45], [7, 11, 5, 23, 28], [1, 5, 8, 18, 23, 16]]))==set([5,23])",
"assert set(common_in_nested_lists([[2, 3,4, 1], [4, 5], [6,4, 8],[4, 5], [6, 8,4]]))==set([4])"
] | stdin | 1 | null | MBPP | [
"12 18 23 25 45\n7 12 18 24 28\n1 5 8 12 15 16 18\n",
"12 5 23 25 45\n7 11 5 23 28\n1 5 8 18 23 16\n",
"2 3 4 1\n4 5\n6 4 8\n4 5\n6 8 4\n"
] | [
"18 12\n",
"5 23\n",
"4\n"
] | [
"12 18 23 25 45\n7 12 18 24 28\n1 5 8 12 15 16 18\n",
"12 5 23 25 45\n7 11 5 23 28\n1 5 8 18 23 16\n"
] | [
"18 12\n",
"5 23\n"
] | Original problem description:
Write a function to find the common elements in given nested lists.
We have its functional test sample:
assert set(common_in_nested_lists([[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]]))==set([18, 12])
assert set(common_in_nested_lists([[12, 5, 23, 25, 45], [7, 11, 5, 23, 28], [1, 5, 8, 18, 23, 16]]))==set([5,23])
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
12 18 23 25 45
7 12 18 24 28
1 5 8 12 15 16 18
Output:
18 12
Example 2:
Input:
12 5 23 25 45
7 11 5 23 28
1 5 8 18 23 16
Output:
5 23
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 57 | Write a function to check if a string represents an integer or not. | def check_integer(text):
text = text.strip()
if len(text) < 1:
return None
else:
if all(text[i] in "0123456789" for i in range(len(text))):
return True
elif (text[0] in "+-") and \
all(text[i] in "0123456789" for i in range(1,len(text))):
return True
else:
return False | [] | [
"assert check_integer(\"python\")==False",
"assert check_integer(\"1\")==True",
"assert check_integer(\"12345\")==True"
] | stdin | 1 | null | MBPP | [
"python\n",
"1\n",
"12345\n"
] | [
"False\n",
"True\n",
"True\n"
] | [
"python\n",
"1\n"
] | [
"False\n",
"True\n"
] | Original problem description:
Write a function to check if a string represents an integer or not.
We have its functional test sample:
assert check_integer("python")==False
assert check_integer("1")==True
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
python
Output:
False
Example 2:
Input:
1
Output:
True
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 59 | Write a function to convert a given tuple of positive integers into a single integer. | def tuple_to_int(nums):
result = int(''.join(map(str,nums)))
return result | [] | [
"assert tuple_to_int((1,2,3))==123",
"assert tuple_to_int((4,5,6))==456",
"assert tuple_to_int((5,6,7))==567"
] | stdin | 1 | null | MBPP | [
"1\n2\n3\n",
"4\n5\n6\n",
"5\n6\n7\n"
] | [
"123\n",
"456\n",
"567\n"
] | [
"1\n2\n3\n",
"4\n5\n6\n"
] | [
"123\n",
"456\n"
] | Original problem description:
Write a function to convert a given tuple of positive integers into a single integer.
We have its functional test sample:
assert tuple_to_int((1,2,3))==123
assert tuple_to_int((4,5,6))==456
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1
2
3
Output:
123
Example 2:
Input:
4
5
6
Output:
456
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 60 | Write a function to convert all possible convertible elements in a list of lists to floats. | def list_to_float(test_list):
res = []
for tup in test_list:
temp = []
for ele in tup:
if ele.isalpha():
temp.append(ele)
else:
temp.append(float(ele))
res.append((temp[0],temp[1]))
return res | [] | [
"assert list_to_float( [(\"3\", \"4\"), (\"1\", \"26.45\"), (\"7.32\", \"8\"), (\"4\", \"8\")] ) == [(3.0, 4.0), (1.0, 26.45), (7.32, 8.0), (4.0, 8.0)]",
"assert list_to_float( [(\"4\", \"4\"), (\"2\", \"27\"), (\"4.12\", \"9\"), (\"7\", \"11\")] ) == [(4.0, 4.0), (2.0, 27.0), (4.12, 9.0), (7.0, 11.0)]",
"assert list_to_float( [(\"6\", \"78\"), (\"5\", \"26.45\"), (\"1.33\", \"4\"), (\"82\", \"13\")] ) == [(6.0, 78.0), (5.0, 26.45), (1.33, 4.0), (82.0, 13.0)]"
] | stdin | 1 | null | MBPP | [
"3 4\n1 26.45\n7.32 8\n4 8\n",
"4 4\n2 27\n4.12 9\n7 11\n",
"6 78\n5 26.45\n1.33 4\n82 13\n"
] | [
"3.0 4.0\n1.0 26.45\n7.32 8.0\n4.0 8.0\n",
"4.0 4.0\n2.0 27.0\n4.12 9.0\n7.0 11.0\n",
"6.0 78.0\n5.0 26.45\n1.33 4.0\n82.0 13.0\n"
] | [
"3 4\n1 26.45\n7.32 8\n4 8\n",
"4 4\n2 27\n4.12 9\n7 11\n"
] | [
"3.0 4.0\n1.0 26.45\n7.32 8.0\n4.0 8.0\n",
"4.0 4.0\n2.0 27.0\n4.12 9.0\n7.0 11.0\n"
] | Original problem description:
Write a function to convert all possible convertible elements in a list of lists to floats.
We have its functional test sample:
assert list_to_float( [("3", "4"), ("1", "26.45"), ("7.32", "8"), ("4", "8")] ) == [(3.0, 4.0), (1.0, 26.45), (7.32, 8.0), (4.0, 8.0)]
assert list_to_float( [("4", "4"), ("2", "27"), ("4.12", "9"), ("7", "11")] ) == [(4.0, 4.0), (2.0, 27.0), (4.12, 9.0), (7.0, 11.0)]
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
3 4
1 26.45
7.32 8
4 8
Output:
3.0 4.0
1.0 26.45
7.32 8.0
4.0 8.0
Example 2:
Input:
4 4
2 27
4.12 9
7 11
Output:
4.0 4.0
2.0 27.0
4.12 9.0
7.0 11.0
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 61 | Write a function to convert a string to a list of strings split on the space character. | def string_to_list(string):
lst = list(string.split(" "))
return lst | [] | [
"assert string_to_list(\"python programming\")==['python','programming']",
"assert string_to_list(\"lists tuples strings\")==['lists','tuples','strings']",
"assert string_to_list(\"write a program\")==['write','a','program']"
] | stdin | 1 | null | MBPP | [
"python programming\n",
"lists tuples strings\n",
"write a program\n"
] | [
"python programming\n",
"lists tuples strings\n",
"write a program\n"
] | [
"python programming\n",
"lists tuples strings\n"
] | [
"python programming\n",
"lists tuples strings\n"
] | Original problem description:
Write a function to convert a string to a list of strings split on the space character.
We have its functional test sample:
assert string_to_list("python programming")==['python','programming']
assert string_to_list("lists tuples strings")==['lists','tuples','strings']
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
python programming
Output:
python programming
Example 2:
Input:
lists tuples strings
Output:
lists tuples strings
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 62 | Write a python function to find the element that appears only once in a sorted array. | def search(arr):
n = len(arr)
XOR = 0
for i in range(n) :
XOR = XOR ^ arr[i]
return (XOR) | [] | [
"assert search([1,1,2,2,3]) == 3",
"assert search([1,1,3,3,4,4,5,5,7,7,8]) == 8",
"assert search([1,2,2,3,3,4,4]) == 1"
] | stdin | 1 | null | MBPP | [
"1 1 2 2 3\n",
"1 1 3 3 4 4 5 5 7 7 8\n",
"1 2 2 3 3 4 4\n"
] | [
"3\n",
"8\n",
"1\n"
] | [
"1 1 2 2 3\n",
"1 1 3 3 4 4 5 5 7 7 8\n"
] | [
"3\n",
"8\n"
] | Original problem description:
Write a python function to find the element that appears only once in a sorted array.
We have its functional test sample:
assert search([1,1,2,2,3]) == 3
assert search([1,1,3,3,4,4,5,5,7,7,8]) == 8
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1 1 2 2 3
Output:
3
Example 2:
Input:
1 1 3 3 4 4 5 5 7 7 8
Output:
8
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 63 | Write a function to find the maximum absolute product between numbers in pairs of tuples within a given list. | def max_product_tuple(list1):
result_max = max([abs(x * y) for x, y in list1] )
return result_max | [] | [
"assert max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==36",
"assert max_product_tuple([(10,20), (15,2), (5,10)] )==200",
"assert max_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==484"
] | stdin | 1 | null | MBPP | [
"2 7\n2 6\n1 8\n4 9\n",
"10 20\n15 2\n5 10\n",
"11 44\n10 15\n20 5\n12 9\n"
] | [
"36\n",
"200\n",
"484\n"
] | [
"2 7\n2 6\n1 8\n4 9\n",
"10 20\n15 2\n5 10\n"
] | [
"36\n",
"200\n"
] | Original problem description:
Write a function to find the maximum absolute product between numbers in pairs of tuples within a given list.
We have its functional test sample:
assert max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==36
assert max_product_tuple([(10,20), (15,2), (5,10)] )==200
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
2 7
2 6
1 8
4 9
Output:
36
Example 2:
Input:
10 20
15 2
5 10
Output:
200
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 64 | Write a function to sum all amicable numbers from 1 to a specified number. | def amicable_numbers_sum(limit):
if not isinstance(limit, int):
return "Input is not an integer!"
if limit < 1:
return "Input must be bigger than 0!"
amicables = set()
for num in range(2, limit+1):
if num in amicables:
continue
sum_fact = sum([fact for fact in range(1, num) if num % fact == 0])
sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0])
if num == sum_fact2 and num != sum_fact:
amicables.add(num)
amicables.add(sum_fact2)
return sum(amicables) | [] | [
"assert amicable_numbers_sum(999)==504",
"assert amicable_numbers_sum(9999)==31626",
"assert amicable_numbers_sum(99)==0"
] | stdin | 1 | null | MBPP | [
"999\n",
"9999\n",
"99\n"
] | [
"504\n",
"31626\n",
"0\n"
] | [
"999\n",
"9999\n"
] | [
"504\n",
"31626\n"
] | Original problem description:
Write a function to sum all amicable numbers from 1 to a specified number.
We have its functional test sample:
assert amicable_numbers_sum(999)==504
assert amicable_numbers_sum(9999)==31626
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
999
Output:
504
Example 2:
Input:
9999
Output:
31626
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 66 | Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string. | def find_length(string):
n = len(string)
current_sum = 0
max_sum = 0
for i in range(n):
current_sum += (1 if string[i] == '0' else -1)
if current_sum < 0:
current_sum = 0
max_sum = max(current_sum, max_sum)
return max_sum if max_sum else 0 | [] | [
"assert find_length(\"11000010001\") == 6",
"assert find_length(\"10111\") == 1",
"assert find_length(\"11011101100101\") == 2"
] | stdin | 1 | null | MBPP | [
"11000010001\n",
"10111\n",
"11011101100101\n"
] | [
"6\n",
"1\n",
"2\n"
] | [
"11000010001\n",
"10111\n"
] | [
"6\n",
"1\n"
] | Original problem description:
Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string.
We have its functional test sample:
assert find_length("11000010001") == 6
assert find_length("10111") == 1
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
11000010001
Output:
6
Example 2:
Input:
10111
Output:
1
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 67 | Write a python function to find the sum of common divisors of two given numbers. | def sum(a,b):
sum = 0
for i in range (1,min(a,b)):
if (a % i == 0 and b % i == 0):
sum += i
return sum | [] | [
"assert sum(10,15) == 6",
"assert sum(100,150) == 93",
"assert sum(4,6) == 3"
] | stdin | 1 | null | MBPP | [
"10\n15\n",
"100\n150\n",
"4\n6\n"
] | [
"6\n",
"93\n",
"3\n"
] | [
"10\n15\n",
"100\n150\n"
] | [
"6\n",
"93\n"
] | Original problem description:
Write a python function to find the sum of common divisors of two given numbers.
We have its functional test sample:
assert sum(10,15) == 6
assert sum(100,150) == 93
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10
15
Output:
6
Example 2:
Input:
100
150
Output:
93
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 68 | Write a function to multiply two integers. | def multiply_int(x, y):
if y < 0:
return -multiply_int(x, -y)
elif y == 0:
return 0
elif y == 1:
return x
else:
return x + multiply_int(x, y - 1) | [] | [
"assert multiply_int(10,20)==200",
"assert multiply_int(5,10)==50",
"assert multiply_int(4,8)==32"
] | stdin | 1 | null | MBPP | [
"10\n20\n",
"5\n10\n",
"4\n8\n"
] | [
"200\n",
"50\n",
"32\n"
] | [
"10\n20\n",
"5\n10\n"
] | [
"200\n",
"50\n"
] | Original problem description:
Write a function to multiply two integers.
We have its functional test sample:
assert multiply_int(10,20)==200
assert multiply_int(5,10)==50
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10
20
Output:
200
Example 2:
Input:
5
10
Output:
50
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 69 | Write a function to find words that are longer than n characters from a given list of words. | def long_words(n, str):
word_len = []
txt = str.split(" ")
for x in txt:
if len(x) > n:
word_len.append(x)
return word_len | [] | [
"assert long_words(3,\"python is a programming language\")==['python','programming','language']",
"assert long_words(2,\"writing a program\")==['writing','program']",
"assert long_words(5,\"sorting list\")==['sorting']"
] | stdin | 1 | null | MBPP | [
"3\npython is a programming language\n",
"2\nwriting a program\n",
"5\nsorting list\n"
] | [
"python programming language\n",
"writing program\n",
"sorting\n"
] | [
"3\npython is a programming language\n",
"2\nwriting a program\n"
] | [
"python programming language\n",
"writing program\n"
] | Original problem description:
Write a function to find words that are longer than n characters from a given list of words.
We have its functional test sample:
assert long_words(3,"python is a programming language")==['python','programming','language']
assert long_words(2,"writing a program")==['writing','program']
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
3
python is a programming language
Output:
python programming language
Example 2:
Input:
2
writing a program
Output:
writing program
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 70 | Write a function to calculate whether the matrix is a magic square. | def magic_square_test(my_matrix):
iSize = len(my_matrix[0])
sum_list = []
sum_list.extend([sum (lines) for lines in my_matrix])
for col in range(iSize):
sum_list.append(sum(row[col] for row in my_matrix))
result1 = 0
for i in range(0,iSize):
result1 +=my_matrix[i][i]
sum_list.append(result1)
result2 = 0
for i in range(iSize-1,-1,-1):
result2 +=my_matrix[i][i]
sum_list.append(result2)
if len(set(sum_list))>1:
return False
return True | [] | [
"assert magic_square_test([[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]])==True",
"assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 8]])==True",
"assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 7]])==False"
] | stdin | 1 | null | MBPP | [
"7 12 1 14\n2 13 8 11\n16 3 10 5\n9 6 15 4\n",
"2 7 6\n9 5 1\n4 3 8\n",
"2 7 6\n9 5 1\n4 3 7\n"
] | [
"True\n",
"True\n",
"False\n"
] | [
"7 12 1 14\n2 13 8 11\n16 3 10 5\n9 6 15 4\n",
"2 7 6\n9 5 1\n4 3 8\n"
] | [
"True\n",
"True\n"
] | Original problem description:
Write a function to calculate whether the matrix is a magic square.
We have its functional test sample:
assert magic_square_test([[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]])==True
assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 8]])==True
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
7 12 1 14
2 13 8 11
16 3 10 5
9 6 15 4
Output:
True
Example 2:
Input:
2 7 6
9 5 1
4 3 8
Output:
True
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 71 | Write a function to find the item with maximum frequency in a given list. | from collections import defaultdict
def max_occurrences(nums):
dict = defaultdict(int)
for i in nums:
dict[i] += 1
result = max(dict.items(), key=lambda x: x[1])
return result[0] | [] | [
"assert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2])==2",
"assert max_occurrences([2,3,8,4,7,9,8,7,9,15,14,10,12,13,16,18])==8",
"assert max_occurrences([10,20,20,30,40,90,80,50,30,20,50,10])==20"
] | stdin | 1 | null | MBPP | [
"2 3 8 4 7 9 8 2 6 5 1 6 1 2 3 2 4 6 9 1 2\n",
"2 3 8 4 7 9 8 7 9 15 14 10 12 13 16 18\n",
"10 20 20 30 40 90 80 50 30 20 50 10\n"
] | [
"2\n",
"8\n",
"20\n"
] | [
"2 3 8 4 7 9 8 2 6 5 1 6 1 2 3 2 4 6 9 1 2\n",
"2 3 8 4 7 9 8 7 9 15 14 10 12 13 16 18\n"
] | [
"2\n",
"8\n"
] | Original problem description:
Write a function to find the item with maximum frequency in a given list.
We have its functional test sample:
assert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2])==2
assert max_occurrences([2,3,8,4,7,9,8,7,9,15,14,10,12,13,16,18])==8
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
2 3 8 4 7 9 8 2 6 5 1 6 1 2 3 2 4 6 9 1 2
Output:
2
Example 2:
Input:
2 3 8 4 7 9 8 7 9 15 14 10 12 13 16 18
Output:
8
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 72 | Write a python function to reverse only the vowels of a given string (where y is not a vowel). | def reverse_vowels(str1):
vowels = ""
for char in str1:
if char in "aeiouAEIOU":
vowels += char
result_string = ""
for char in str1:
if char in "aeiouAEIOU":
result_string += vowels[-1]
vowels = vowels[:-1]
else:
result_string += char
return result_string | [] | [
"assert reverse_vowels(\"Python\") == \"Python\"",
"assert reverse_vowels(\"USA\") == \"ASU\"",
"assert reverse_vowels(\"ab\") == \"ab\""
] | stdin | 1 | null | MBPP | [
"Python\n",
"USA\n",
"ab\n"
] | [
"Python\n",
"ASU\n",
"ab\n"
] | [
"Python\n",
"USA\n"
] | [
"Python\n",
"ASU\n"
] | Original problem description:
Write a python function to reverse only the vowels of a given string (where y is not a vowel).
We have its functional test sample:
assert reverse_vowels("Python") == "Python"
assert reverse_vowels("USA") == "ASU"
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
Python
Output:
Python
Example 2:
Input:
USA
Output:
ASU
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 73 | Write a function to convert a tuple to a string. | def tup_string(tup1):
str = ''.join(tup1)
return str | [] | [
"assert tup_string(('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's'))==(\"exercises\")",
"assert tup_string(('p','y','t','h','o','n'))==(\"python\")",
"assert tup_string(('p','r','o','g','r','a','m'))==(\"program\")"
] | stdin | 1 | null | MBPP | [
"e\nx\ne\nr\nc\ni\ns\ne\ns\n",
"p\ny\nt\nh\no\nn\n",
"p\nr\no\ng\nr\na\nm\n"
] | [
"exercises\n",
"python\n",
"program\n"
] | [
"e\nx\ne\nr\nc\ni\ns\ne\ns\n",
"p\ny\nt\nh\no\nn\n"
] | [
"exercises\n",
"python\n"
] | Original problem description:
Write a function to convert a tuple to a string.
We have its functional test sample:
assert tup_string(('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's'))==("exercises")
assert tup_string(('p','y','t','h','o','n'))==("python")
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
e
x
e
r
c
i
s
e
s
Output:
exercises
Example 2:
Input:
p
y
t
h
o
n
Output:
python
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 74 | Write a function to calculate the sum of the negative numbers of a given list of numbers. | def sum_negativenum(nums):
sum_negativenum = list(filter(lambda nums:nums<0,nums))
return sum(sum_negativenum) | [] | [
"assert sum_negativenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==-32",
"assert sum_negativenum([10,15,-14,13,-18,12,-20])==-52",
"assert sum_negativenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==-894"
] | stdin | 1 | null | MBPP | [
"2 4 -6 -9 11 -12 14 -5 17\n",
"10 15 -14 13 -18 12 -20\n",
"19 -65 57 39 152 -639 121 44 90 -190\n"
] | [
"-32\n",
"-52\n",
"-894\n"
] | [
"2 4 -6 -9 11 -12 14 -5 17\n",
"10 15 -14 13 -18 12 -20\n"
] | [
"-32\n",
"-52\n"
] | Original problem description:
Write a function to calculate the sum of the negative numbers of a given list of numbers.
We have its functional test sample:
assert sum_negativenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==-32
assert sum_negativenum([10,15,-14,13,-18,12,-20])==-52
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
2 4 -6 -9 11 -12 14 -5 17
Output:
-32
Example 2:
Input:
10 15 -14 13 -18 12 -20
Output:
-52
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 75 | Write a function to find the nth hexagonal number. | def hexagonal_num(n):
return n*(2*n - 1) | [] | [
"assert hexagonal_num(10) == 190",
"assert hexagonal_num(5) == 45",
"assert hexagonal_num(7) == 91"
] | stdin | 1 | null | MBPP | [
"10\n",
"5\n",
"7\n"
] | [
"190\n",
"45\n",
"91\n"
] | [
"10\n",
"5\n"
] | [
"190\n",
"45\n"
] | Original problem description:
Write a function to find the nth hexagonal number.
We have its functional test sample:
assert hexagonal_num(10) == 190
assert hexagonal_num(5) == 45
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10
Output:
190
Example 2:
Input:
5
Output:
45
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 77 | Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not. | def is_Sum_Of_Powers_Of_Two(n):
if (n % 2 == 1):
return False
else:
return True | [] | [
"assert is_Sum_Of_Powers_Of_Two(10) == True",
"assert is_Sum_Of_Powers_Of_Two(7) == False",
"assert is_Sum_Of_Powers_Of_Two(14) == True"
] | stdin | 1 | null | MBPP | [
"10\n",
"7\n",
"14\n"
] | [
"True\n",
"False\n",
"True\n"
] | [
"10\n",
"7\n"
] | [
"True\n",
"False\n"
] | Original problem description:
Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.
We have its functional test sample:
assert is_Sum_Of_Powers_Of_Two(10) == True
assert is_Sum_Of_Powers_Of_Two(7) == False
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10
Output:
True
Example 2:
Input:
7
Output:
False
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 79 | Write a function to flatten the list of lists into a single set of numbers. | def extract_singly(test_list):
res = []
temp = set()
for inner in test_list:
for ele in inner:
if not ele in temp:
temp.add(ele)
res.append(ele)
return (res) | [] | [
"assert set(extract_singly([(3, 4, 5), (4, 5, 7), (1, 4)])) == set([3, 4, 5, 7, 1])",
"assert set(extract_singly([(1, 2, 3), (4, 2, 3), (7, 8)])) == set([1, 2, 3, 4, 7, 8])",
"assert set(extract_singly([(7, 8, 9), (10, 11, 12), (10, 11)])) == set([7, 8, 9, 10, 11, 12])"
] | stdin | 1 | null | MBPP | [
"3 4 5\n4 5 7\n1 4\n",
"1 2 3\n4 2 3\n7 8\n",
"7 8 9\n10 11 12\n10 11\n"
] | [
"3 4 5 7 1\n",
"1 2 3 4 7 8\n",
"7 8 9 10 11 12\n"
] | [
"3 4 5\n4 5 7\n1 4\n",
"1 2 3\n4 2 3\n7 8\n"
] | [
"3 4 5 7 1\n",
"1 2 3 4 7 8\n"
] | Original problem description:
Write a function to flatten the list of lists into a single set of numbers.
We have its functional test sample:
assert set(extract_singly([(3, 4, 5), (4, 5, 7), (1, 4)])) == set([3, 4, 5, 7, 1])
assert set(extract_singly([(1, 2, 3), (4, 2, 3), (7, 8)])) == set([1, 2, 3, 4, 7, 8])
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
3 4 5
4 5 7
1 4
Output:
3 4 5 7 1
Example 2:
Input:
1 2 3
4 2 3
7 8
Output:
1 2 3 4 7 8
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 80 | Write a function to sort a list of elements. | def pancake_sort(nums):
arr_len = len(nums)
while arr_len > 1:
mi = nums.index(max(nums[0:arr_len]))
nums = nums[mi::-1] + nums[mi+1:len(nums)]
nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)]
arr_len -= 1
return nums | [] | [
"assert pancake_sort([15, 79, 25, 38, 69]) == [15, 25, 38, 69, 79]",
"assert pancake_sort([98, 12, 54, 36, 85]) == [12, 36, 54, 85, 98]",
"assert pancake_sort([41, 42, 32, 12, 23]) == [12, 23, 32, 41, 42]"
] | stdin | 1 | null | MBPP | [
"15 79 25 38 69\n",
"98 12 54 36 85\n",
"41 42 32 12 23\n"
] | [
"15 25 38 69 79\n",
"12 36 54 85 98\n",
"12 23 32 41 42\n"
] | [
"15 79 25 38 69\n",
"98 12 54 36 85\n"
] | [
"15 25 38 69 79\n",
"12 36 54 85 98\n"
] | Original problem description:
Write a function to sort a list of elements.
We have its functional test sample:
assert pancake_sort([15, 79, 25, 38, 69]) == [15, 25, 38, 69, 79]
assert pancake_sort([98, 12, 54, 36, 85]) == [12, 36, 54, 85, 98]
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
15 79 25 38 69
Output:
15 25 38 69 79
Example 2:
Input:
98 12 54 36 85
Output:
12 36 54 85 98
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 81 | Write a function to count number items that are identical in the same position of three given lists. | def count_samepair(list1,list2,list3):
result = sum(m == n == o for m, n, o in zip(list1,list2,list3))
return result | [] | [
"assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,9],[2,1,3,1,2,6,7,9])==3",
"assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==4",
"assert count_samepair([1,2,3,4,2,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==5"
] | stdin | 1 | null | MBPP | [
"1 2 3 4 5 6 7 8\n2 2 3 1 2 6 7 9\n2 1 3 1 2 6 7 9\n",
"1 2 3 4 5 6 7 8\n2 2 3 1 2 6 7 8\n2 1 3 1 2 6 7 8\n",
"1 2 3 4 2 6 7 8\n2 2 3 1 2 6 7 8\n2 1 3 1 2 6 7 8\n"
] | [
"3\n",
"4\n",
"5\n"
] | [
"1 2 3 4 5 6 7 8\n2 2 3 1 2 6 7 9\n2 1 3 1 2 6 7 9\n",
"1 2 3 4 5 6 7 8\n2 2 3 1 2 6 7 8\n2 1 3 1 2 6 7 8\n"
] | [
"3\n",
"4\n"
] | Original problem description:
Write a function to count number items that are identical in the same position of three given lists.
We have its functional test sample:
assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,9],[2,1,3,1,2,6,7,9])==3
assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==4
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1 2 3 4 5 6 7 8
2 2 3 1 2 6 7 9
2 1 3 1 2 6 7 9
Output:
3
Example 2:
Input:
1 2 3 4 5 6 7 8
2 2 3 1 2 6 7 8
2 1 3 1 2 6 7 8
Output:
4
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 82 | Write a function to find number of lists present in the given tuple. | def find_lists(Input):
if isinstance(Input, list):
return 1
else:
return len(Input) | [] | [
"assert find_lists(([1, 2, 3, 4], [5, 6, 7, 8])) == 2",
"assert find_lists(([1, 2], [3, 4], [5, 6])) == 3",
"assert find_lists(([9, 8, 7, 6, 5, 4, 3, 2, 1])) == 1"
] | stdin | 1 | null | MBPP | [
"1 2 3 4\n5 6 7 8\n",
"1 2\n3 4\n5 6\n",
"9 8 7 6 5 4 3 2 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | [
"1 2 3 4\n5 6 7 8\n",
"1 2\n3 4\n5 6\n"
] | [
"2\n",
"3\n"
] | Original problem description:
Write a function to find number of lists present in the given tuple.
We have its functional test sample:
assert find_lists(([1, 2, 3, 4], [5, 6, 7, 8])) == 2
assert find_lists(([1, 2], [3, 4], [5, 6])) == 3
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1 2 3 4
5 6 7 8
Output:
2
Example 2:
Input:
1 2
3 4
5 6
Output:
3
|
Mike's Copy of Benchmark Questions Verification V2.ipynb | 83 | Write a python function to find the maximum difference between any two elements in a given array. | def max_Abs_Diff(arr):
n = len(arr)
minEle = arr[0]
maxEle = arr[0]
for i in range(1, n):
minEle = min(minEle,arr[i])
maxEle = max(maxEle,arr[i])
return (maxEle - minEle) | [] | [
"assert max_Abs_Diff((2,1,5,3)) == 4",
"assert max_Abs_Diff((9,3,2,5,1)) == 8",
"assert max_Abs_Diff((3,2,1)) == 2"
] | stdin | 1 | null | MBPP | [
"2\n1\n5\n3\n",
"9\n3\n2\n5\n1\n",
"3\n2\n1\n"
] | [
"4\n",
"8\n",
"2\n"
] | [
"2\n1\n5\n3\n",
"9\n3\n2\n5\n1\n"
] | [
"4\n",
"8\n"
] | Original problem description:
Write a python function to find the maximum difference between any two elements in a given array.
We have its functional test sample:
assert max_Abs_Diff((2,1,5,3)) == 4
assert max_Abs_Diff((9,3,2,5,1)) == 8
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
2
1
5
3
Output:
4
Example 2:
Input:
9
3
2
5
1
Output:
8
|
Benchmark Questions Verification V2.ipynb | 84 | Write a function that returns integers x and y that satisfy ax + by = n as a tuple, or return None if no solution exists. | def find_solution(a, b, n):
i = 0
while i * a <= n:
if (n - (i * a)) % b == 0:
return (i, (n - (i * a)) // b)
i = i + 1
return None | [] | [
"assert find_solution(2, 3, 7) == (2, 1)",
"assert find_solution(4, 2, 7) == None",
"assert find_solution(1, 13, 17) == (4, 1)"
] | stdin | 1 | null | MBPP | [
"2\n3\n7\n",
"4\n2\n7\n",
"1\n13\n17\n"
] | [
"2 1\n",
"None\n",
"4 1\n"
] | [
"2\n3\n7\n",
"4\n2\n7\n"
] | [
"2 1\n",
"None\n"
] | Original problem description:
Write a function that returns integers x and y that satisfy ax + by = n as a tuple, or return None if no solution exists.
We have its functional test sample:
assert find_solution(2, 3, 7) == (2, 1)
assert find_solution(4, 2, 7) == None
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
2
3
7
Output:
2 1
Example 2:
Input:
4
2
7
Output:
None
|
Benchmark Questions Verification V2.ipynb | 85 | Write a function to remove all elements from a given list present in another list. | def remove_elements(list1, list2):
result = [x for x in list1 if x not in list2]
return result | [] | [
"assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 4, 6, 8]) == [1, 3, 5, 7, 9, 10]",
"assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 3, 5, 7]) == [2, 4, 6, 8, 9, 10]",
"assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [5, 7]) == [1, 2, 3, 4, 6, 8, 9, 10]"
] | stdin | 1 | null | MBPP | [
"1 2 3 4 5 6 7 8 9 10\n2 4 6 8\n",
"1 2 3 4 5 6 7 8 9 10\n1 3 5 7\n",
"1 2 3 4 5 6 7 8 9 10\n5 7\n"
] | [
"1 3 5 7 9 10\n",
"2 4 6 8 9 10\n",
"1 2 3 4 6 8 9 10\n"
] | [
"1 2 3 4 5 6 7 8 9 10\n2 4 6 8\n",
"1 2 3 4 5 6 7 8 9 10\n1 3 5 7\n"
] | [
"1 3 5 7 9 10\n",
"2 4 6 8 9 10\n"
] | Original problem description:
Write a function to remove all elements from a given list present in another list.
We have its functional test sample:
assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 4, 6, 8]) == [1, 3, 5, 7, 9, 10]
assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 3, 5, 7]) == [2, 4, 6, 8, 9, 10]
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1 2 3 4 5 6 7 8 9 10
2 4 6 8
Output:
1 3 5 7 9 10
Example 2:
Input:
1 2 3 4 5 6 7 8 9 10
1 3 5 7
Output:
2 4 6 8 9 10
|
Benchmark Questions Verification V2.ipynb | 86 | Write a function to calculate the sum (n - 2*i) from i=0 to n // 2, for instance n + (n-2) + (n-4)... (until n-x =< 0). | def sum_series(n):
if n < 1:
return 0
else:
return n + sum_series(n - 2) | [] | [
"assert sum_series(6) == 12",
"assert sum_series(10) == 30",
"assert sum_series(9) == 25"
] | stdin | 1 | null | MBPP | [
"6\n",
"10\n",
"9\n"
] | [
"12\n",
"30\n",
"25\n"
] | [
"6\n",
"10\n"
] | [
"12\n",
"30\n"
] | Original problem description:
Write a function to calculate the sum (n - 2*i) from i=0 to n // 2, for instance n + (n-2) + (n-4)... (until n-x =< 0).
We have its functional test sample:
assert sum_series(6) == 12
assert sum_series(10) == 30
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
6
Output:
12
Example 2:
Input:
10
Output:
30
|
Benchmark Questions Verification V2.ipynb | 88 | Write a function to determine if the sum of the divisors of two integers are the same. | import math
def div_sum(n):
total = 1
i = 2
while i * i <= n:
if (n % i == 0):
total = (total + i + math.floor(n / i))
i += 1
return total
def are_equivalent(num1, num2):
return div_sum(num1) == div_sum(num2); | [] | [
"assert are_equivalent(36, 57) == False",
"assert are_equivalent(2, 4) == False",
"assert are_equivalent(23, 47) == True"
] | stdin | 1 | null | MBPP | [
"36\n57\n",
"2\n4\n",
"23\n47\n"
] | [
"False\n",
"False\n",
"True\n"
] | [
"36\n57\n",
"2\n4\n"
] | [
"False\n",
"False\n"
] | Original problem description:
Write a function to determine if the sum of the divisors of two integers are the same.
We have its functional test sample:
assert are_equivalent(36, 57) == False
assert are_equivalent(2, 4) == False
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
36
57
Output:
False
Example 2:
Input:
2
4
Output:
False
|
Benchmark Questions Verification V2.ipynb | 89 | Write a function to count the number of characters in a string that occur at the same position in the string as in the English alphabet (case insensitive). | def count_char_position(str1):
count_chars = 0
for i in range(len(str1)):
if ((i == ord(str1[i]) - ord('A')) or
(i == ord(str1[i]) - ord('a'))):
count_chars += 1
return count_chars | [] | [
"assert count_char_position(\"xbcefg\") == 2",
"assert count_char_position(\"ABcED\") == 3",
"assert count_char_position(\"AbgdeF\") == 5"
] | stdin | 1 | null | MBPP | [
"xbcefg\n",
"ABcED\n",
"AbgdeF\n"
] | [
"2\n",
"3\n",
"5\n"
] | [
"xbcefg\n",
"ABcED\n"
] | [
"2\n",
"3\n"
] | Original problem description:
Write a function to count the number of characters in a string that occur at the same position in the string as in the English alphabet (case insensitive).
We have its functional test sample:
assert count_char_position("xbcefg") == 2
assert count_char_position("ABcED") == 3
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
xbcefg
Output:
2
Example 2:
Input:
ABcED
Output:
3
|
Benchmark Questions Verification V2.ipynb | 90 | Write a function that counts the number of pairs of integers in a list that xor to an even number. | def find_even_pair(A):
count = 0
for i in range(0, len(A)):
for j in range(i+1, len(A)):
if ((A[i] ^ A[j]) % 2 == 0):
count += 1
return count | [] | [
"assert find_even_pair([5, 4, 7, 2, 1]) == 4",
"assert find_even_pair([7, 2, 8, 1, 0, 5, 11]) == 9",
"assert find_even_pair([1, 2, 3]) == 1"
] | stdin | 1 | null | MBPP | [
"5 4 7 2 1\n",
"7 2 8 1 0 5 11\n",
"1 2 3\n"
] | [
"4\n",
"9\n",
"1\n"
] | [
"5 4 7 2 1\n",
"7 2 8 1 0 5 11\n"
] | [
"4\n",
"9\n"
] | Original problem description:
Write a function that counts the number of pairs of integers in a list that xor to an even number.
We have its functional test sample:
assert find_even_pair([5, 4, 7, 2, 1]) == 4
assert find_even_pair([7, 2, 8, 1, 0, 5, 11]) == 9
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
5 4 7 2 1
Output:
4
Example 2:
Input:
7 2 8 1 0 5 11
Output:
9
|
Benchmark Questions Verification V2.ipynb | 91 | Write a python function to find the smallest power of 2 greater than or equal to n. | def next_power_of_2(n):
if n and not n & (n - 1):
return n
count = 0
while n != 0:
n >>= 1
count += 1
return 1 << count; | [] | [
"assert next_power_of_2(0) == 1",
"assert next_power_of_2(5) == 8",
"assert next_power_of_2(17) == 32"
] | stdin | 1 | null | MBPP | [
"0\n",
"5\n",
"17\n"
] | [
"1\n",
"8\n",
"32\n"
] | [
"0\n",
"5\n"
] | [
"1\n",
"8\n"
] | Original problem description:
Write a python function to find the smallest power of 2 greater than or equal to n.
We have its functional test sample:
assert next_power_of_2(0) == 1
assert next_power_of_2(5) == 8
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
0
Output:
1
Example 2:
Input:
5
Output:
8
|
Benchmark Questions Verification V2.ipynb | 92 | Write a function to count the number of occurrences of a number in a given list. | def frequency(a,x):
count = 0
for i in a:
if i == x:
count += 1
return count | [] | [
"assert frequency([1,2,3], 4) == 0",
"assert frequency([1,2,2,3,3,3,4], 3) == 3",
"assert frequency([0,1,2,3,1,2], 1) == 2"
] | stdin | 1 | null | MBPP | [
"1 2 3\n4\n",
"1 2 2 3 3 3 4\n3\n",
"0 1 2 3 1 2\n1\n"
] | [
"0\n",
"3\n",
"2\n"
] | [
"1 2 3\n4\n",
"1 2 2 3 3 3 4\n3\n"
] | [
"0\n",
"3\n"
] | Original problem description:
Write a function to count the number of occurrences of a number in a given list.
We have its functional test sample:
assert frequency([1,2,3], 4) == 0
assert frequency([1,2,2,3,3,3,4], 3) == 3
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1 2 3
4
Output:
0
Example 2:
Input:
1 2 2 3 3 3 4
3
Output:
3
|
Benchmark Questions Verification V2.ipynb | 93 | Write a function to find the sum of numbers in a list within a range specified by two indices. | def sum_range_list(list1, m, n):
sum_range = 0
for i in range(m, n+1, 1):
sum_range += list1[i]
return sum_range | [] | [
"assert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 8, 10) == 29",
"assert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 5, 7) == 16",
"assert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 7, 10) == 38"
] | stdin | 1 | null | MBPP | [
"2 1 5 6 8 3 4 9 10 11 8 12\n8\n10\n",
"2 1 5 6 8 3 4 9 10 11 8 12\n5\n7\n",
"2 1 5 6 8 3 4 9 10 11 8 12\n7\n10\n"
] | [
"29\n",
"16\n",
"38\n"
] | [
"2 1 5 6 8 3 4 9 10 11 8 12\n8\n10\n",
"2 1 5 6 8 3 4 9 10 11 8 12\n5\n7\n"
] | [
"29\n",
"16\n"
] | Original problem description:
Write a function to find the sum of numbers in a list within a range specified by two indices.
We have its functional test sample:
assert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 8, 10) == 29
assert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 5, 7) == 16
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
2 1 5 6 8 3 4 9 10 11 8 12
8
10
Output:
29
Example 2:
Input:
2 1 5 6 8 3 4 9 10 11 8 12
5
7
Output:
16
|
Benchmark Questions Verification V2.ipynb | 94 | Write a function to find the perimeter of a regular pentagon from the length of its sides. | import math
def perimeter_pentagon(a):
perimeter=(5*a)
return perimeter | [] | [
"assert perimeter_pentagon(5) == 25",
"assert perimeter_pentagon(10) == 50",
"assert perimeter_pentagon(15) == 75"
] | stdin | 1 | null | MBPP | [
"5\n",
"10\n",
"15\n"
] | [
"25\n",
"50\n",
"75\n"
] | [
"5\n",
"10\n"
] | [
"25\n",
"50\n"
] | Original problem description:
Write a function to find the perimeter of a regular pentagon from the length of its sides.
We have its functional test sample:
assert perimeter_pentagon(5) == 25
assert perimeter_pentagon(10) == 50
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
5
Output:
25
Example 2:
Input:
10
Output:
50
|
Benchmark Questions Verification V2.ipynb | 95 | Write a function to count the number of occurence of the string 'std' in a given string. | def count_occurance(s):
count = 0
for i in range(len(s) - 2):
if (s[i] == 's' and s[i+1] == 't' and s[i+2] == 'd'):
count = count + 1
return count | [] | [
"assert count_occurance(\"letstdlenstdporstd\") == 3",
"assert count_occurance(\"truststdsolensporsd\") == 1",
"assert count_occurance(\"makestdsostdworthit\") == 2",
"assert count_occurance(\"stds\") == 1",
"assert count_occurance(\"\") == 0"
] | stdin | 1 | null | MBPP | [
"letstdlenstdporstd\n",
"truststdsolensporsd\n",
"makestdsostdworthit\n",
"stds\n",
"\n"
] | [
"3\n",
"1\n",
"2\n",
"1\n",
"0\n"
] | [
"letstdlenstdporstd\n",
"truststdsolensporsd\n"
] | [
"3\n",
"1\n"
] | Original problem description:
Write a function to count the number of occurence of the string 'std' in a given string.
We have its functional test sample:
assert count_occurance("letstdlenstdporstd") == 3
assert count_occurance("truststdsolensporsd") == 1
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
letstdlenstdporstd
Output:
3
Example 2:
Input:
truststdsolensporsd
Output:
1
|
Benchmark Questions Verification V2.ipynb | 96 | Write a function to check if all the elements in tuple have same data type or not. | def check_type(test_tuple):
res = True
for ele in test_tuple:
if not isinstance(ele, type(test_tuple[0])):
res = False
break
return (res) | [] | [
"assert check_type((5, 6, 7, 3, 5, 6) ) == True",
"assert check_type((1, 2, \"4\") ) == False",
"assert check_type((3, 2, 1, 4, 5) ) == True"
] | stdin | 1 | null | MBPP | [
"5\n6\n7\n3\n5\n6\n",
"1\n2\n4\n",
"3\n2\n1\n4\n5\n"
] | [
"True\n",
"False\n",
"True\n"
] | [
"5\n6\n7\n3\n5\n6\n",
"1\n2\n4\n"
] | [
"True\n",
"False\n"
] | Original problem description:
Write a function to check if all the elements in tuple have same data type or not.
We have its functional test sample:
assert check_type((5, 6, 7, 3, 5, 6) ) == True
assert check_type((1, 2, "4") ) == False
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
5
6
7
3
5
6
Output:
True
Example 2:
Input:
1
2
4
Output:
False
|
Benchmark Questions Verification V2.ipynb | 97 | Write a function that takes in a sorted array, its length (n), and an element and returns whether the element is the majority element in the given sorted array. (The majority element is the element that occurs more than n/2 times.) | def is_majority(arr, n, x):
i = binary_search(arr, 0, n-1, x)
if i == -1:
return False
if ((i + n//2) <= (n -1)) and arr[i + n//2] == x:
return True
else:
return False
def binary_search(arr, low, high, x):
if high >= low:
mid = (low + high)//2
if (mid == 0 or x > arr[mid-1]) and (arr[mid] == x):
return mid
elif x > arr[mid]:
return binary_search(arr, (mid + 1), high, x)
else:
return binary_search(arr, low, (mid -1), x)
return -1 | [] | [
"assert is_majority([1, 2, 3, 3, 3, 3, 10], 7, 3) == True",
"assert is_majority([1, 1, 2, 4, 4, 4, 6, 6], 8, 4) == False",
"assert is_majority([1, 1, 1, 2, 2], 5, 1) == True",
"assert is_majority([1, 1, 2, 2], 5, 1) == False"
] | stdin | 1 | null | MBPP | [
"1 2 3 3 3 3 10\n7\n3\n",
"1 1 2 4 4 4 6 6\n8\n4\n",
"1 1 1 2 2\n5\n1\n",
"1 1 2 2\n5\n1\n"
] | [
"True\n",
"False\n",
"True\n",
"False\n"
] | [
"1 2 3 3 3 3 10\n7\n3\n",
"1 1 2 4 4 4 6 6\n8\n4\n"
] | [
"True\n",
"False\n"
] | Original problem description:
Write a function that takes in a sorted array, its length (n), and an element and returns whether the element is the majority element in the given sorted array. (The majority element is the element that occurs more than n/2 times.)
We have its functional test sample:
assert is_majority([1, 2, 3, 3, 3, 3, 10], 7, 3) == True
assert is_majority([1, 1, 2, 4, 4, 4, 6, 6], 8, 4) == False
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1 2 3 3 3 3 10
7
3
Output:
True
Example 2:
Input:
1 1 2 4 4 4 6 6
8
4
Output:
False
|
Benchmark Questions Verification V2.ipynb | 98 | Write a python function to count the number of set bits (binary digits with value 1) in a given number. | def count_Set_Bits(n):
count = 0
while (n):
count += n & 1
n >>= 1
return count | [] | [
"assert count_Set_Bits(2) == 1",
"assert count_Set_Bits(4) == 1",
"assert count_Set_Bits(6) == 2"
] | stdin | 1 | null | MBPP | [
"2\n",
"4\n",
"6\n"
] | [
"1\n",
"1\n",
"2\n"
] | [
"2\n",
"4\n"
] | [
"1\n",
"1\n"
] | Original problem description:
Write a python function to count the number of set bits (binary digits with value 1) in a given number.
We have its functional test sample:
assert count_Set_Bits(2) == 1
assert count_Set_Bits(4) == 1
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
2
Output:
1
Example 2:
Input:
4
Output:
1
|
Benchmark Questions Verification V2.ipynb | 99 | Write a python function to remove the characters which have odd index values of a given string. | def odd_values_string(str):
result = ""
for i in range(len(str)):
if i % 2 == 0:
result = result + str[i]
return result | [] | [
"assert odd_values_string('abcdef') == 'ace'",
"assert odd_values_string('python') == 'pto'",
"assert odd_values_string('data') == 'dt'",
"assert odd_values_string('lambs') == 'lms'"
] | stdin | 1 | null | MBPP | [
"abcdef\n",
"python\n",
"data\n",
"lambs\n"
] | [
"ace\n",
"pto\n",
"dt\n",
"lms\n"
] | [
"abcdef\n",
"python\n"
] | [
"ace\n",
"pto\n"
] | Original problem description:
Write a python function to remove the characters which have odd index values of a given string.
We have its functional test sample:
assert odd_values_string('abcdef') == 'ace'
assert odd_values_string('python') == 'pto'
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
abcdef
Output:
ace
Example 2:
Input:
python
Output:
pto
|
Benchmark Questions Verification V2.ipynb | 100 | Write a function to find minimum of three numbers. | def min_of_three(a,b,c):
if (a <= b) and (a <= c):
smallest = a
elif (b <= a) and (b <= c):
smallest = b
else:
smallest = c
return smallest | [] | [
"assert min_of_three(10,20,0)==0",
"assert min_of_three(19,15,18)==15",
"assert min_of_three(-10,-20,-30)==-30"
] | stdin | 1 | null | MBPP | [
"10\n20\n0\n",
"19\n15\n18\n",
"-10\n-20\n-30\n"
] | [
"0\n",
"15\n",
"-30\n"
] | [
"10\n20\n0\n",
"19\n15\n18\n"
] | [
"0\n",
"15\n"
] | Original problem description:
Write a function to find minimum of three numbers.
We have its functional test sample:
assert min_of_three(10,20,0)==0
assert min_of_three(19,15,18)==15
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10
20
0
Output:
0
Example 2:
Input:
19
15
18
Output:
15
|
Benchmark Questions Verification V2.ipynb | 101 | Write a python function to check whether all the bits are unset in the given range or not. | def all_Bits_Set_In_The_Given_Range(n,l,r):
num = (((1 << r) - 1) ^ ((1 << (l - 1)) - 1))
new_num = n & num
if (new_num == 0):
return True
return False | [] | [
"assert all_Bits_Set_In_The_Given_Range(4,1,2) == True",
"assert all_Bits_Set_In_The_Given_Range(17,2,4) == True",
"assert all_Bits_Set_In_The_Given_Range(39,4,6) == False"
] | stdin | 1 | null | MBPP | [
"4\n1\n2\n",
"17\n2\n4\n",
"39\n4\n6\n"
] | [
"True\n",
"True\n",
"False\n"
] | [
"4\n1\n2\n",
"17\n2\n4\n"
] | [
"True\n",
"True\n"
] | Original problem description:
Write a python function to check whether all the bits are unset in the given range or not.
We have its functional test sample:
assert all_Bits_Set_In_The_Given_Range(4,1,2) == True
assert all_Bits_Set_In_The_Given_Range(17,2,4) == True
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
4
1
2
Output:
True
Example 2:
Input:
17
2
4
Output:
True
|
Benchmark Questions Verification V2.ipynb | 102 | Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved. | def re_arrange_array(arr, n):
j=0
for i in range(0, n):
if (arr[i] < 0):
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
j = j + 1
return arr | [] | [
"assert re_arrange_array([-1, 2, -3, 4, 5, 6, -7, 8, 9], 9) == [-1, -3, -7, 4, 5, 6, 2, 8, 9]",
"assert re_arrange_array([12, -14, -26, 13, 15], 5) == [-14, -26, 12, 13, 15]",
"assert re_arrange_array([10, 24, 36, -42, -39, -78, 85], 7) == [-42, -39, -78, 10, 24, 36, 85]"
] | stdin | 1 | null | MBPP | [
"-1 2 -3 4 5 6 -7 8 9\n9\n",
"12 -14 -26 13 15\n5\n",
"10 24 36 -42 -39 -78 85\n7\n"
] | [
"-1 -3 -7 4 5 6 2 8 9\n",
"-14 -26 12 13 15\n",
"-42 -39 -78 10 24 36 85\n"
] | [
"-1 2 -3 4 5 6 -7 8 9\n9\n",
"12 -14 -26 13 15\n5\n"
] | [
"-1 -3 -7 4 5 6 2 8 9\n",
"-14 -26 12 13 15\n"
] | Original problem description:
Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved.
We have its functional test sample:
assert re_arrange_array([-1, 2, -3, 4, 5, 6, -7, 8, 9], 9) == [-1, -3, -7, 4, 5, 6, 2, 8, 9]
assert re_arrange_array([12, -14, -26, 13, 15], 5) == [-14, -26, 12, 13, 15]
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
-1 2 -3 4 5 6 -7 8 9
9
Output:
-1 -3 -7 4 5 6 2 8 9
Example 2:
Input:
12 -14 -26 13 15
5
Output:
-14 -26 12 13 15
|
Benchmark Questions Verification V2.ipynb | 103 | Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string. | def replace_blank(str1,char):
str2 = str1.replace(' ', char)
return str2 | [] | [
"assert replace_blank(\"hello people\",'@')==(\"hello@people\")",
"assert replace_blank(\"python program language\",'$')==(\"python$program$language\")",
"assert replace_blank(\"blank space\",\"-\")==(\"blank-space\")"
] | stdin | 1 | null | MBPP | [
"hello people\n@\n",
"python program language\n$\n",
"blank space\n-\n"
] | [
"hello@people\n",
"python$program$language\n",
"blank-space\n"
] | [
"hello people\n@\n",
"python program language\n$\n"
] | [
"hello@people\n",
"python$program$language\n"
] | Original problem description:
Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string.
We have its functional test sample:
assert replace_blank("hello people",'@')==("hello@people")
assert replace_blank("python program language",'$')==("python$program$language")
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
hello people
@
Output:
hello@people
Example 2:
Input:
python program language
$
Output:
python$program$language
|
Benchmark Questions Verification V2.ipynb | 104 | Write a function that takes in a list and an integer n and returns a list containing the n largest items from the list. | import heapq
def larg_nnum(list1,n):
largest=heapq.nlargest(n,list1)
return largest | [] | [
"assert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2))==set([100,90])",
"assert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5))==set([100,90,80,70,60])",
"assert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3))==set([100,90,80])"
] | stdin | 1 | null | MBPP | [
"10 20 50 70 90 20 50 40 60 80 100\n2\n",
"10 20 50 70 90 20 50 40 60 80 100\n5\n",
"10 20 50 70 90 20 50 40 60 80 100\n3\n"
] | [
"100 90\n",
"100 90 80 70 60\n",
"100 90 80\n"
] | [
"10 20 50 70 90 20 50 40 60 80 100\n2\n",
"10 20 50 70 90 20 50 40 60 80 100\n5\n"
] | [
"100 90\n",
"100 90 80 70 60\n"
] | Original problem description:
Write a function that takes in a list and an integer n and returns a list containing the n largest items from the list.
We have its functional test sample:
assert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2))==set([100,90])
assert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5))==set([100,90,80,70,60])
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10 20 50 70 90 20 50 40 60 80 100
2
Output:
100 90
Example 2:
Input:
10 20 50 70 90 20 50 40 60 80 100
5
Output:
100 90 80 70 60
|
Benchmark Questions Verification V2.ipynb | 106 | Write a function to find the volume of a cube given its side length. | def volume_cube(l):
volume = l * l * l
return volume | [] | [
"assert volume_cube(3)==27",
"assert volume_cube(2)==8",
"assert volume_cube(5)==125"
] | stdin | 1 | null | MBPP | [
"3\n",
"2\n",
"5\n"
] | [
"27\n",
"8\n",
"125\n"
] | [
"3\n",
"2\n"
] | [
"27\n",
"8\n"
] | Original problem description:
Write a function to find the volume of a cube given its side length.
We have its functional test sample:
assert volume_cube(3)==27
assert volume_cube(2)==8
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
3
Output:
27
Example 2:
Input:
2
Output:
8
|
Benchmark Questions Verification V2.ipynb | 107 | Write a python function to set all even bits of a given number. | def even_bit_set_number(n):
count = 0;res = 0;temp = n
while(temp > 0):
if (count % 2 == 1):
res |= (1 << count)
count+=1
temp >>= 1
return (n | res) | [] | [
"assert even_bit_set_number(10) == 10",
"assert even_bit_set_number(20) == 30",
"assert even_bit_set_number(30) == 30"
] | stdin | 1 | null | MBPP | [
"10\n",
"20\n",
"30\n"
] | [
"10\n",
"30\n",
"30\n"
] | [
"10\n",
"20\n"
] | [
"10\n",
"30\n"
] | Original problem description:
Write a python function to set all even bits of a given number.
We have its functional test sample:
assert even_bit_set_number(10) == 10
assert even_bit_set_number(20) == 30
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10
Output:
10
Example 2:
Input:
20
Output:
30
|
Benchmark Questions Verification V2.ipynb | 109 | Write a python function to count the number of non-empty substrings of a given string. | def number_of_substrings(str):
str_len = len(str);
return int(str_len * (str_len + 1) / 2); | [] | [
"assert number_of_substrings(\"abc\") == 6",
"assert number_of_substrings(\"abcd\") == 10",
"assert number_of_substrings(\"abcde\") == 15"
] | stdin | 1 | null | MBPP | [
"abc\n",
"abcd\n",
"abcde\n"
] | [
"6\n",
"10\n",
"15\n"
] | [
"abc\n",
"abcd\n"
] | [
"6\n",
"10\n"
] | Original problem description:
Write a python function to count the number of non-empty substrings of a given string.
We have its functional test sample:
assert number_of_substrings("abc") == 6
assert number_of_substrings("abcd") == 10
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
abc
Output:
6
Example 2:
Input:
abcd
Output:
10
|
Benchmark Questions Verification V2.ipynb | 110 | Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. | def get_total_number_of_sequences(m,n):
T=[[0 for i in range(n+1)] for i in range(m+1)]
for i in range(m+1):
for j in range(n+1):
if i==0 or j==0:
T[i][j]=0
elif i<j:
T[i][j]=0
elif j==1:
T[i][j]=i
else:
T[i][j]=T[i-1][j]+T[i//2][j-1]
return T[m][n] | [] | [
"assert get_total_number_of_sequences(10, 4) == 4",
"assert get_total_number_of_sequences(5, 2) == 6",
"assert get_total_number_of_sequences(16, 3) == 84"
] | stdin | 1 | null | MBPP | [
"10\n4\n",
"5\n2\n",
"16\n3\n"
] | [
"4\n",
"6\n",
"84\n"
] | [
"10\n4\n",
"5\n2\n"
] | [
"4\n",
"6\n"
] | Original problem description:
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
We have its functional test sample:
assert get_total_number_of_sequences(10, 4) == 4
assert get_total_number_of_sequences(5, 2) == 6
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
10
4
Output:
4
Example 2:
Input:
5
2
Output:
6
|
Benchmark Questions Verification V2.ipynb | 111 | Write a function that takes in two lists and replaces the last element of the first list with the elements of the second list. | def replace_list(list1,list2):
list1[-1:] = list2
replace_list=list1
return replace_list
| [] | [
"assert replace_list([1, 3, 5, 7, 9, 10],[2, 4, 6, 8])==[1, 3, 5, 7, 9, 2, 4, 6, 8]",
"assert replace_list([1,2,3,4,5],[5,6,7,8])==[1,2,3,4,5,6,7,8]",
"assert replace_list([\"red\",\"blue\",\"green\"],[\"yellow\"])==[\"red\",\"blue\",\"yellow\"]"
] | stdin | 1 | null | MBPP | [
"1 3 5 7 9 10\n2 4 6 8\n",
"1 2 3 4 5\n5 6 7 8\n",
"red blue green\nyellow\n"
] | [
"1 3 5 7 9 2 4 6 8\n",
"1 2 3 4 5 6 7 8\n",
"red blue yellow\n"
] | [
"1 3 5 7 9 10\n2 4 6 8\n",
"1 2 3 4 5\n5 6 7 8\n"
] | [
"1 3 5 7 9 2 4 6 8\n",
"1 2 3 4 5 6 7 8\n"
] | Original problem description:
Write a function that takes in two lists and replaces the last element of the first list with the elements of the second list.
We have its functional test sample:
assert replace_list([1, 3, 5, 7, 9, 10],[2, 4, 6, 8])==[1, 3, 5, 7, 9, 2, 4, 6, 8]
assert replace_list([1,2,3,4,5],[5,6,7,8])==[1,2,3,4,5,6,7,8]
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1 3 5 7 9 10
2 4 6 8
Output:
1 3 5 7 9 2 4 6 8
Example 2:
Input:
1 2 3 4 5
5 6 7 8
Output:
1 2 3 4 5 6 7 8
|
Benchmark Questions Verification V2.ipynb | 112 | Write a function to count the total number of characters in a string. | def count_charac(str1):
total = 0
for i in str1:
total = total + 1
return total | [] | [
"assert count_charac(\"python programming\")==18",
"assert count_charac(\"language\")==8",
"assert count_charac(\"words\")==5"
] | stdin | 1 | null | MBPP | [
"python programming\n",
"language\n",
"words\n"
] | [
"18\n",
"8\n",
"5\n"
] | [
"python programming\n",
"language\n"
] | [
"18\n",
"8\n"
] | Original problem description:
Write a function to count the total number of characters in a string.
We have its functional test sample:
assert count_charac("python programming")==18
assert count_charac("language")==8
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
python programming
Output:
18
Example 2:
Input:
language
Output:
8
|
Benchmark Questions Verification V2.ipynb | 113 | Write a python function to find the next perfect square greater than a given number. | import math
def next_Perfect_Square(N):
nextN = math.floor(math.sqrt(N)) + 1
return nextN * nextN | [] | [
"assert next_Perfect_Square(35) == 36",
"assert next_Perfect_Square(6) == 9",
"assert next_Perfect_Square(9) == 16"
] | stdin | 1 | null | MBPP | [
"35\n",
"6\n",
"9\n"
] | [
"36\n",
"9\n",
"16\n"
] | [
"35\n",
"6\n"
] | [
"36\n",
"9\n"
] | Original problem description:
Write a python function to find the next perfect square greater than a given number.
We have its functional test sample:
assert next_Perfect_Square(35) == 36
assert next_Perfect_Square(6) == 9
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
35
Output:
36
Example 2:
Input:
6
Output:
9
|
Benchmark Questions Verification V2.ipynb | 114 | Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. | def max_sum(arr):
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float("-Inf")
for i, j, k in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum | [] | [
"assert max_sum([1, 15, 51, 45, 33, 100, 12, 18, 9]) == 194",
"assert max_sum([80, 60, 30, 40, 20, 10]) == 210",
"assert max_sum([2, 3 ,14, 16, 21, 23, 29, 30]) == 138"
] | stdin | 1 | null | MBPP | [
"1 15 51 45 33 100 12 18 9\n",
"80 60 30 40 20 10\n",
"2 3 14 16 21 23 29 30\n"
] | [
"194\n",
"210\n",
"138\n"
] | [
"1 15 51 45 33 100 12 18 9\n",
"80 60 30 40 20 10\n"
] | [
"194\n",
"210\n"
] | Original problem description:
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
We have its functional test sample:
assert max_sum([1, 15, 51, 45, 33, 100, 12, 18, 9]) == 194
assert max_sum([80, 60, 30, 40, 20, 10]) == 210
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
1 15 51 45 33 100 12 18 9
Output:
194
Example 2:
Input:
80 60 30 40 20 10
Output:
210
|
Benchmark Questions Verification V2.ipynb | 116 | Write a function to find the length of the longest palindromic subsequence in the given string. | def lps(str):
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n+1):
for i in range(n-cl+1):
j = i+cl-1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i+1][j-1] + 2
else:
L[i][j] = max(L[i][j-1], L[i+1][j]);
return L[0][n-1] | [] | [
"assert lps(\"TENS FOR TENS\") == 5",
"assert lps(\"CARDIO FOR CARDS\") == 7",
"assert lps(\"PART OF THE JOURNEY IS PART\") == 9"
] | stdin | 1 | null | MBPP | [
"TENS FOR TENS\n",
"CARDIO FOR CARDS\n",
"PART OF THE JOURNEY IS PART\n"
] | [
"5\n",
"7\n",
"9\n"
] | [
"TENS FOR TENS\n",
"CARDIO FOR CARDS\n"
] | [
"5\n",
"7\n"
] | Original problem description:
Write a function to find the length of the longest palindromic subsequence in the given string.
We have its functional test sample:
assert lps("TENS FOR TENS") == 5
assert lps("CARDIO FOR CARDS") == 7
However, the functional I/O tests have been converted to a standard stdin/stdout format for this task. The followings are some input and output examples. Please read from stdin and write to stdout exactly as shown below.
Your solution must strictly follow these formats. For instance, many raw functional test cases contain a list like [a1, a2, a3, ...]. After conversion, these may appear as a single line of input: "a1 a2 a3 ...". You should read this line directly, without first reading the length of the list.
Example 1:
Input:
TENS FOR TENS
Output:
5
Example 2:
Input:
CARDIO FOR CARDS
Output:
7
|
We use Stdio input/output format here. For example, for the task to calculate the sum of a list, the input and output are in the following format:
input = "5\n1 2 3 4 5\n"
output = "15"
CodeContests and CodeForces are using this format, however, MBPP and part of LiveCodeBench are using functional input/output format, such like
assert sum_function([1, 2, 3, 4, 5]) == 15
In this project, we have converted the the functional format to the Stdio format to achieve consistency.
@article{wang2025cure,
title={Co-Evolving LLM Coder and Unit Tester via Reinforcement Learning},
author={Wang, Yinjie and Yang, Ling and Tian, Ye and Shen, Ke and Wang, Mengdi},
journal={arXiv preprint arXiv:2506.03136},
year={2025}
}
@article{austin2021program,
title={Program synthesis with large language models},
author={Austin, Jacob and Odena, Augustus and Nye, Maxwell and Bosma, Maarten and Michalewski, Henryk and Dohan, David and Jiang, Ellen and Cai, Carrie and Terry, Michael and Le, Quoc and others},
journal={arXiv preprint arXiv:2108.07732},
year={2021}
}