task_id
int64 | text
string | code
string | test_list
list | test_setup_code
string | challenge_test_list
list | context
string | context_id
string | context_length_tokens
int64 | code_length_chars
int64 |
|---|---|---|---|---|---|---|---|---|---|
243
|
Write a function to sort the given list based on the occurrence of first element of tuples.
|
def sort_on_occurence(lst):
dct = {}
for i, j in lst:
dct.setdefault(i, []).append(j)
return ([(i, *dict.fromkeys(j), len(j))
for i, j in dct.items()])
|
[
"assert sort_on_occurence([(1, 'Jake'), (2, 'Bob'), (1, 'Cara')]) == [(1, 'Jake', 'Cara', 2), (2, 'Bob', 1)]",
"assert sort_on_occurence([('b', 'ball'), ('a', 'arm'), ('b', 'b'), ('a', 'ant')]) == [('b', 'ball', 'b', 2), ('a', 'arm', 'ant', 2)]",
"assert sort_on_occurence([(2, 'Mark'), (3, 'Maze'), (2, 'Sara')]) == [(2, 'Mark', 'Sara', 2), (3, 'Maze', 1)]"
] |
[] |
The bedroom is north of the hallway. The kitchen is south of the hallway.
|
babilong_0k_qa4_sample_64
| 17
| 171
|
|
388
|
Write a python function to find the highest power of 2 that is less than or equal to n.
|
def highest_Power_of_2(n):
res = 0;
for i in range(n, 0, -1):
if ((i & (i - 1)) == 0):
res = i;
break;
return res;
|
[
"assert highest_Power_of_2(10) == 8",
"assert highest_Power_of_2(19) == 16",
"assert highest_Power_of_2(32) == 32"
] |
[] |
Daniel grabbed the apple there. Daniel went back to the bathroom. John journeyed to the garden. Daniel went back to the hallway. Mary moved to the bedroom. Daniel left the apple. Sandra took the football there. Sandra discarded the football there. Sandra took the football there. John travelled to the kitchen.
|
babilong_0k_qa2_sample_30
| 63
| 171
|
|
394
|
Write a function to check if given tuple is distinct or not.
|
def check_distinct(test_tup):
res = True
temp = set()
for ele in test_tup:
if ele in temp:
res = False
break
temp.add(ele)
return (res)
|
[
"assert check_distinct((1, 4, 5, 6, 1, 4)) == False",
"assert check_distinct((1, 4, 5, 6)) == True",
"assert check_distinct((2, 3, 4, 5, 6)) == True"
] |
[] |
Daniel journeyed to the bedroom. Sandra went back to the office. Daniel travelled to the garden. John went back to the bathroom. Mary travelled to the kitchen. John went to the hallway.
|
babilong_0k_qa1_sample_80
| 40
| 172
|
|
421
|
Write a function to concatenate each element of tuple by the delimiter.
|
def concatenate_tuple(test_tup):
delim = "-"
res = ''.join([str(ele) + delim for ele in test_tup])
res = res[ : len(res) - len(delim)]
return (str(res))
|
[
"assert concatenate_tuple((\"ID\", \"is\", 4, \"UTS\") ) == 'ID-is-4-UTS'",
"assert concatenate_tuple((\"QWE\", \"is\", 4, \"RTY\") ) == 'QWE-is-4-RTY'",
"assert concatenate_tuple((\"ZEN\", \"is\", 4, \"OP\") ) == 'ZEN-is-4-OP'"
] |
[] |
John journeyed to the garden. John travelled to the bathroom. Daniel went back to the garden. Daniel journeyed to the kitchen. Sandra travelled to the kitchen. Sandra moved to the hallway. Sandra travelled to the bedroom. John went back to the office.
|
babilong_0k_qa1_sample_59
| 53
| 173
|
|
101
|
Write a function to find the kth element in the given array.
|
def kth_element(arr, n, k):
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] == arr[j+1], arr[j]
return arr[k-1]
|
[
"assert kth_element([12,3,5,7,19], 5, 2) == 3",
"assert kth_element([17,24,8,23], 4, 3) == 8",
"assert kth_element([16,21,25,36,4], 5, 4) == 36"
] |
[] |
Sandra travelled to the kitchen. Daniel took the milk. Sandra moved to the bedroom. Daniel dropped the milk. Mary moved to the hallway. Mary got the milk. Daniel journeyed to the bedroom. Mary went to the bedroom. Mary left the milk. Daniel went back to the hallway. Sandra got the milk. Sandra put down the milk. Sandra picked up the milk. Sandra went to the bathroom. Sandra picked up the football. Sandra discarded the milk. Mary went back to the bathroom. Sandra grabbed the milk. Sandra put down the milk there. John went to the bathroom. John moved to the hallway. Mary took the milk. Daniel went back to the garden. Daniel journeyed to the office. Daniel journeyed to the bathroom. Mary went back to the kitchen. Mary put down the milk. Sandra put down the football there. Mary went to the hallway. Sandra went to the garden. John moved to the office. Sandra grabbed the apple. John moved to the bedroom. Sandra journeyed to the kitchen. Mary went to the garden. Daniel took the football there. Sandra journeyed to the hallway. John went to the garden. Sandra moved to the bathroom. Daniel journeyed to the hallway. Mary went back to the kitchen. Sandra put down the apple there. Sandra took the apple. Daniel moved to the kitchen. Mary grabbed the milk. Daniel left the football. Sandra left the apple. Mary grabbed the football. John travelled to the hallway. Mary went back to the bedroom. Daniel went to the office. Mary dropped the football there. Sandra got the apple. Mary put down the milk. Mary went back to the bathroom. John moved to the bathroom. Sandra put down the apple. Mary grabbed the apple. John journeyed to the kitchen. John moved to the office. Mary dropped the apple. John moved to the kitchen. Sandra grabbed the apple. Sandra went back to the kitchen. Sandra dropped the apple there. Mary journeyed to the office. Mary journeyed to the bathroom. John moved to the office. Mary went to the kitchen. John went to the garden. Mary journeyed to the office. John went to the office. Mary journeyed to the garden. Sandra picked up the apple. John journeyed to the garden. John journeyed to the kitchen. Mary journeyed to the office. John travelled to the hallway. Sandra dropped the apple. Daniel journeyed to the garden. Sandra grabbed the apple. Sandra put down the apple. Daniel travelled to the bedroom. Daniel took the milk. Daniel put down the milk there. Mary moved to the kitchen. Mary took the apple. Mary went to the bathroom. Mary moved to the kitchen. John travelled to the garden.
|
babilong_0k_qa3_sample_1
| 547
| 174
|
|
103
|
Write a function to find eulerian number a(n, m).
|
def eulerian_num(n, m):
if (m >= n or n == 0):
return 0
if (m == 0):
return 1
return ((n - m) * eulerian_num(n - 1, m - 1) +(m + 1) * eulerian_num(n - 1, m))
|
[
"assert eulerian_num(3, 1) == 4",
"assert eulerian_num(4, 1) == 11",
"assert eulerian_num(5, 3) == 26"
] |
[] |
Mary went to the office. Mary went to the kitchen. Sandra travelled to the hallway. John took the football. Mary grabbed the milk there. Mary left the milk. John grabbed the milk. Daniel went to the bedroom. Daniel went back to the kitchen. Sandra travelled to the bedroom. John dropped the football. Mary went to the hallway. John discarded the milk. Daniel went back to the bathroom. Sandra moved to the kitchen. Sandra took the football. John picked up the milk. John put down the milk. Mary moved to the office. Daniel travelled to the bedroom. John picked up the milk. John dropped the milk there. Sandra put down the football. Daniel moved to the bathroom. John grabbed the football. Mary travelled to the bathroom. John went to the bathroom. Daniel travelled to the bedroom. Daniel took the apple there. Sandra travelled to the hallway. John moved to the hallway. Mary journeyed to the bedroom. Daniel dropped the apple. Daniel travelled to the garden. Mary got the apple. John put down the football. John took the football. John moved to the bathroom. Mary left the apple. John left the football. Sandra went back to the bedroom. Mary took the apple there. John got the football. Sandra travelled to the hallway. John journeyed to the garden. Sandra went back to the kitchen. Daniel journeyed to the kitchen. John dropped the football. Mary travelled to the garden. Daniel got the milk. Mary took the football. Mary left the football. John grabbed the football. Daniel went to the bedroom. Daniel dropped the milk there. Daniel went to the office. Mary dropped the apple. John travelled to the bathroom. John moved to the garden. John took the apple. Daniel moved to the hallway. John left the apple. Sandra moved to the office. Mary travelled to the bathroom. John grabbed the apple. Mary journeyed to the hallway. Daniel went back to the garden. Daniel moved to the kitchen. Sandra went to the kitchen. John went back to the bedroom. John got the milk. Sandra moved to the bedroom. Daniel went to the bedroom. Daniel went back to the kitchen. Sandra went to the garden. Daniel went to the garden. Sandra went to the bathroom. Sandra moved to the office. John dropped the apple. Daniel journeyed to the kitchen. Mary went back to the office. John left the football there. John went to the garden. Daniel went to the office. John discarded the milk. John journeyed to the bathroom.
|
babilong_0k_qa3_sample_88
| 506
| 174
|
|
446
|
Write a python function to count the occurence of all elements of list in a tuple.
|
from collections import Counter
def count_Occurrence(tup, lst):
count = 0
for item in tup:
if item in lst:
count+= 1
return count
|
[
"assert count_Occurrence(('a', 'a', 'c', 'b', 'd'),['a', 'b'] ) == 3",
"assert count_Occurrence((1, 2, 3, 1, 4, 6, 7, 1, 4),[1, 4, 7]) == 6",
"assert count_Occurrence((1,2,3,4,5,6),[1,2]) == 2"
] |
[] |
The kitchen is south of the garden. The kitchen is north of the bedroom.
|
babilong_0k_qa4_sample_29
| 17
| 174
|
|
50
|
Write a function to find the list with minimum length using lambda function.
|
def min_length_list(input_list):
min_length = min(len(x) for x in input_list )
min_list = min(input_list, key = lambda i: len(i))
return(min_length, min_list)
|
[
"assert min_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(1, [0])",
"assert min_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(1,[1])",
"assert min_length_list([[3,4,5],[6,7,8,9],[10,11,12],[1,2]])==(2,[1,2])"
] |
[] |
Bill went back to the kitchen. Bill took the apple there. Bill passed the apple to Mary. Mary handed the apple to Fred. Fred gave the apple to Mary. Mary journeyed to the office. Mary handed the apple to Jeff. Mary got the football there. Jeff left the apple. Mary gave the football to Jeff. Mary took the apple there. Fred travelled to the hallway.
|
babilong_0k_qa5_sample_10
| 79
| 175
|
|
25
|
Write a python function to find the product of non-repeated elements in a given array.
|
def find_Product(arr,n):
arr.sort()
prod = 1
for i in range(0,n,1):
if (arr[i - 1] != arr[i]):
prod = prod * arr[i]
return prod;
|
[
"assert find_Product([1,1,2,3],4) == 6",
"assert find_Product([1,2,3,1,1],5) == 6",
"assert find_Product([1,1,4,5,6],5) == 120"
] |
[
"assert find_Product([1,1,4,5,6,5,7,1,1,3,4],11) == 2520"
] |
John went to the kitchen. Mary journeyed to the kitchen. John journeyed to the bedroom. Mary journeyed to the hallway. Mary moved to the office. Mary moved to the hallway. John picked up the football there. John went to the office. Sandra journeyed to the bedroom. John got the milk there. Sandra went back to the hallway. Sandra journeyed to the garden. Mary moved to the bedroom. Mary travelled to the bathroom. Sandra went to the kitchen. John put down the football.
|
babilong_0k_qa2_sample_58
| 104
| 176
|
|
38
|
Write a function to find the division of first even and odd number of a given list.
|
def div_even_odd(list1):
first_even = next((el for el in list1 if el%2==0),-1)
first_odd = next((el for el in list1 if el%2!=0),-1)
return (first_even/first_odd)
|
[
"assert div_even_odd([1,3,5,7,4,1,6,8])==4",
"assert div_even_odd([1,2,3,4,5,6,7,8,9,10])==2",
"assert div_even_odd([1,5,7,9,10])==10"
] |
[] |
The bathroom is south of the kitchen. The kitchen is south of the garden.
|
babilong_0k_qa4_sample_18
| 17
| 176
|
|
377
|
Write a python function to remove all occurrences of a character in a given string.
|
def remove_Char(s,c) :
counts = s.count(c)
s = list(s)
while counts :
s.remove(c)
counts -= 1
s = '' . join(s)
return (s)
|
[
"assert remove_Char(\"aba\",'a') == \"b\"",
"assert remove_Char(\"toggle\",'g') == \"tole\"",
"assert remove_Char(\"aabbc\",'b') == \"aac\""
] |
[] |
Sandra travelled to the office. Mary grabbed the football there. Mary put down the football. Daniel picked up the football there. John travelled to the garden. Mary moved to the garden. John went to the office. Mary got the milk there. Mary left the milk there. Daniel put down the football. John went to the bedroom. Mary got the milk there. Daniel journeyed to the garden. Mary discarded the milk. Mary moved to the hallway. Daniel grabbed the milk there. Daniel travelled to the office. Mary picked up the apple there. Daniel put down the milk there. Daniel got the milk there. John travelled to the office. Sandra went to the hallway. Sandra went back to the bathroom. Mary went to the garden. Daniel discarded the milk. Daniel got the milk there. Mary went to the office. John went back to the hallway. John moved to the bathroom. John went back to the hallway. Sandra journeyed to the office. Daniel dropped the milk.
|
babilong_0k_qa2_sample_97
| 199
| 176
|
|
199
|
Write a python function to find highest power of 2 less than or equal to given number.
|
def highest_Power_of_2(n):
res = 0;
for i in range(n, 0, -1):
if ((i & (i - 1)) == 0):
res = i;
break;
return res;
|
[
"assert highest_Power_of_2(10) == 8",
"assert highest_Power_of_2(19) == 16",
"assert highest_Power_of_2(32) == 32"
] |
[] |
Daniel travelled to the kitchen. Mary grabbed the milk. Daniel went back to the hallway. John moved to the kitchen. Daniel travelled to the office. John grabbed the apple. John journeyed to the garden. John dropped the apple. John moved to the hallway. Mary dropped the milk. Daniel went back to the bathroom. Mary grabbed the milk there. Mary went back to the garden. Mary went to the hallway.
|
babilong_0k_qa3_sample_61
| 85
| 177
|
|
108
|
Write a function to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm.
|
import heapq
def merge_sorted_list(num1,num2,num3):
num1=sorted(num1)
num2=sorted(num2)
num3=sorted(num3)
result = heapq.merge(num1,num2,num3)
return list(result)
|
[
"assert merge_sorted_list([25, 24, 15, 4, 5, 29, 110],[19, 20, 11, 56, 25, 233, 154],[24, 26, 54, 48])==[4, 5, 11, 15, 19, 20, 24, 24, 25, 25, 26, 29, 48, 54, 56, 110, 154, 233]",
"assert merge_sorted_list([1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12])==[1, 1, 2, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 11, 12]",
"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]"
] |
[] |
John journeyed to the hallway. John journeyed to the bedroom.
|
babilong_0k_qa1_sample_9
| 15
| 178
|
|
229
|
Write a function to re-arrange the elements of the given array so that all negative elements appear before positive ones.
|
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]"
] |
[] |
Sandra went back to the bedroom. Mary moved to the kitchen. Mary moved to the office. Daniel travelled to the office. Daniel travelled to the hallway. John went back to the hallway. Mary moved to the bathroom. Sandra journeyed to the hallway. John went to the garden. Daniel travelled to the kitchen.
|
babilong_0k_qa1_sample_53
| 65
| 179
|
|
288
|
Write a function to count array elements having modular inverse under given prime number p equal to itself.
|
def modular_inverse(arr, N, P):
current_element = 0
for i in range(0, N):
if ((arr[i] * arr[i]) % P == 1):
current_element = current_element + 1
return current_element
|
[
"assert modular_inverse([ 1, 6, 4, 5 ], 4, 7) == 2",
"assert modular_inverse([1, 3, 8, 12, 12], 5, 13) == 3",
"assert modular_inverse([2, 3, 4, 5], 4, 6) == 1"
] |
[] |
Sandra went back to the hallway. Mary got the milk. Daniel travelled to the garden. Daniel got the apple. John went back to the hallway. Mary went back to the office. Daniel journeyed to the hallway. Daniel went back to the bathroom. Daniel travelled to the hallway. Mary journeyed to the bathroom. Daniel dropped the apple. Sandra travelled to the bathroom.
|
babilong_0k_qa3_sample_76
| 77
| 180
|
|
393
|
Write a function to find the list with maximum length using lambda function.
|
def max_length_list(input_list):
max_length = max(len(x) for x in input_list )
max_list = max(input_list, key = lambda i: len(i))
return(max_length, max_list)
|
[
"assert max_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])",
"assert max_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(5,[1,2,3,4,5])",
"assert max_length_list([[3,4,5],[6,7,8,9],[10,11,12]])==(4,[6,7,8,9])"
] |
[] |
John journeyed to the garden. Sandra went to the office. Sandra moved to the hallway. Mary went to the office. Sandra picked up the milk there. Sandra dropped the milk there. Mary journeyed to the bedroom. Sandra got the milk there. John moved to the office. Sandra travelled to the garden. Mary journeyed to the kitchen. Mary took the football there. Sandra discarded the milk. Daniel moved to the hallway.
|
babilong_0k_qa2_sample_47
| 88
| 180
|
|
416
|
Write a function to find the maximum sum we can make by dividing number in three parts recursively and summing them up together for the given number.
|
MAX = 1000000
def breakSum(n):
dp = [0]*(n+1)
dp[0] = 0
dp[1] = 1
for i in range(2, n+1):
dp[i] = max(dp[int(i/2)] + dp[int(i/3)] + dp[int(i/4)], i);
return dp[n]
|
[
"assert breakSum(12) == 13",
"assert breakSum(24) == 27",
"assert breakSum(23) == 23"
] |
[] |
Sandra took the milk there. Sandra journeyed to the garden. Sandra dropped the milk there. Sandra journeyed to the bathroom. John travelled to the garden. John went to the kitchen.
|
babilong_0k_qa2_sample_19
| 40
| 180
|
|
167
|
Write a python function to find smallest power of 2 greater than or equal to n.
|
def next_Power_Of_2(n):
count = 0;
if (n and not(n & (n - 1))):
return n
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"
] |
[] |
John got the football. John discarded the football. Sandra moved to the hallway. John travelled to the garden. Daniel went back to the garden. Mary went back to the bathroom. Daniel got the milk. John went back to the hallway. Sandra journeyed to the bathroom. Daniel left the milk. Daniel picked up the milk. Daniel dropped the milk. Daniel grabbed the milk there. John went to the kitchen. Sandra journeyed to the kitchen. Daniel went to the bathroom. Daniel moved to the office. Sandra went back to the bathroom. Sandra travelled to the garden. John journeyed to the bedroom. Mary moved to the office. Daniel dropped the milk.
|
babilong_0k_qa3_sample_26
| 134
| 181
|
|
178
|
Write a function to search some literals strings in a string.
|
import re
def string_literals(patterns,text):
for pattern in patterns:
if re.search(pattern, text):
return ('Matched!')
else:
return ('Not Matched!')
|
[
"assert string_literals(['language'],'python language')==('Matched!')",
"assert string_literals(['program'],'python language')==('Not Matched!')",
"assert string_literals(['python'],'programming language')==('Not Matched!')"
] |
[] |
The bathroom is north of the office. The office is north of the kitchen.
|
babilong_0k_qa4_sample_51
| 17
| 182
|
|
186
|
Write a function to search some literals strings in a string by using regex.
|
import re
def check_literals(text, patterns):
for pattern in patterns:
if re.search(pattern, text):
return ('Matched!')
else:
return ('Not Matched!')
|
[
"assert check_literals('The quick brown fox jumps over the lazy dog.',['fox']) == 'Matched!'",
"assert check_literals('The quick brown fox jumps over the lazy dog.',['horse']) == 'Not Matched!'",
"assert check_literals('The quick brown fox jumps over the lazy dog.',['lazy']) == 'Matched!'"
] |
[] |
Daniel went to the hallway. Sandra went back to the bedroom. Sandra got the football. Sandra discarded the football there. Daniel moved to the garden. Mary went to the office. Sandra went to the kitchen. Mary took the milk there. Daniel travelled to the kitchen. Sandra journeyed to the garden. Mary took the apple. Daniel went back to the hallway. Mary travelled to the bathroom. Sandra went back to the office. Mary discarded the apple there. Mary took the apple. John journeyed to the bedroom. Mary journeyed to the kitchen. Mary went to the bedroom. Mary went back to the garden. Sandra travelled to the bedroom. John journeyed to the kitchen. Sandra took the football. John went to the garden. Mary discarded the milk there. John grabbed the milk. Mary discarded the apple. Daniel moved to the office. Sandra dropped the football. Mary travelled to the bathroom.
|
babilong_0k_qa3_sample_44
| 182
| 182
|
|
180
|
Write a function to calculate distance between two points using latitude and longitude.
|
from math import radians, sin, cos, acos
def distance_lat_long(slat,slon,elat,elon):
dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon))
return dist
|
[
"assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429",
"assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514",
"assert distance_lat_long(10,20,30,40)==6783.751974994595"
] |
[] |
Daniel moved to the bathroom. John got the football. Sandra grabbed the milk. Sandra put down the milk. Daniel journeyed to the bedroom. Sandra took the milk. Sandra put down the milk there. John put down the football. Mary travelled to the hallway. John took the football. Sandra went back to the office. Mary moved to the garden. Daniel moved to the garden. Daniel went back to the office. Sandra journeyed to the hallway. Mary went to the office. Sandra went back to the office. Sandra moved to the bathroom. John dropped the football. Sandra got the football. Sandra left the football there. Daniel moved to the bedroom. Daniel journeyed to the office. John went back to the office. Sandra got the football. Sandra discarded the football. Mary travelled to the bathroom. Mary got the football. Mary went back to the kitchen. Mary journeyed to the garden.
|
babilong_0k_qa3_sample_0
| 182
| 183
|
|
183
|
Write a function to count all the distinct pairs having a difference of k in any array.
|
def count_pairs(arr, n, k):
count=0;
for i in range(0,n):
for j in range(i+1, n):
if arr[i] - arr[j] == k or arr[j] - arr[i] == k:
count += 1
return count
|
[
"assert count_pairs([1, 5, 3, 4, 2], 5, 3) == 2",
"assert count_pairs([8, 12, 16, 4, 0, 20], 6, 4) == 5",
"assert count_pairs([2, 4, 1, 3, 4], 5, 2) == 3"
] |
[] |
Mary went to the office. John went to the garden. Mary journeyed to the bedroom. Daniel got the milk there. Daniel journeyed to the bedroom. John moved to the kitchen. Sandra went to the bathroom. Mary travelled to the office. Sandra went back to the office. Mary went to the kitchen. Mary went back to the hallway. Daniel discarded the milk. Sandra picked up the football there. Mary moved to the garden. John travelled to the garden. John travelled to the bathroom.
|
babilong_0k_qa2_sample_89
| 101
| 184
|
|
191
|
Write a function to check whether the given month name contains 30 days or not.
|
def check_monthnumber(monthname3):
if monthname3 =="April" or monthname3== "June" or monthname3== "September" or monthname3== "November":
return True
else:
return False
|
[
"assert check_monthnumber(\"February\")==False",
"assert check_monthnumber(\"June\")==True",
"assert check_monthnumber(\"April\")==True"
] |
[] |
Mary moved to the kitchen. Mary travelled to the office. Daniel grabbed the football there. Mary moved to the hallway. Sandra moved to the bedroom. Mary went back to the bedroom. John grabbed the milk there. John put down the milk. Daniel journeyed to the bathroom. Sandra journeyed to the bathroom. John got the milk there. Mary took the apple there. Mary left the apple. John journeyed to the bedroom.
|
babilong_0k_qa2_sample_2
| 88
| 184
|
|
228
|
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"
] |
[] |
Sandra travelled to the garden. John travelled to the kitchen. Mary went to the bathroom. Mary travelled to the bedroom.
|
babilong_0k_qa1_sample_99
| 26
| 184
|
|
352
|
Write a python function to check whether all the characters in a given string are unique.
|
def unique_Characters(str):
for i in range(len(str)):
for j in range(i + 1,len(str)):
if (str[i] == str[j]):
return False;
return True;
|
[
"assert unique_Characters('aba') == False",
"assert unique_Characters('abc') == True",
"assert unique_Characters('abab') == False"
] |
[] |
Fred took the football there. Jeff got the milk there. Mary travelled to the bathroom. Bill journeyed to the bathroom. Fred went to the bedroom. Bill journeyed to the garden. Fred dropped the football. Fred journeyed to the office. Mary went back to the hallway. Fred travelled to the kitchen. Jeff journeyed to the bedroom. Fred got the apple there. Jeff went to the office. Fred went back to the office. Jeff journeyed to the bedroom. Mary went to the bedroom. Jeff dropped the milk there. Mary picked up the football there. Bill moved to the kitchen. Mary gave the football to Jeff. Jeff grabbed the milk there. Jeff passed the football to Mary. Mary went back to the kitchen. Bill moved to the bathroom. Mary put down the football. Fred dropped the apple. Jeff travelled to the bathroom. Fred went to the bedroom. Jeff gave the milk to Bill. Bill gave the milk to Jeff.
|
babilong_0k_qa5_sample_59
| 192
| 185
|
|
508
|
Write a function to check if the common elements between two given lists are in the same order or not.
|
def same_order(l1, l2):
common_elements = set(l1) & set(l2)
l1 = [e for e in l1 if e in common_elements]
l2 = [e for e in l2 if e in common_elements]
return l1 == l2
|
[
"assert same_order([\"red\",\"green\",\"black\",\"orange\"],[\"red\",\"pink\",\"green\",\"white\",\"black\"])==True",
"assert same_order([\"red\",\"pink\",\"green\",\"white\",\"black\"],[\"white\",\"orange\",\"pink\",\"black\"])==False",
"assert same_order([\"red\",\"green\",\"black\",\"orange\"],[\"red\",\"pink\",\"green\",\"white\",\"black\"])==True"
] |
[] |
Sandra went back to the bathroom. Sandra journeyed to the office. Mary travelled to the hallway. Daniel went to the office. Mary journeyed to the garden. John travelled to the office. Sandra moved to the kitchen. John moved to the garden.
|
babilong_0k_qa1_sample_63
| 53
| 185
|
|
23
|
Write a python function to find the maximum sum of elements of list in a list of lists.
|
def maximum_Sum(list1):
maxi = -100000
for x in list1:
sum = 0
for y in x:
sum+= y
maxi = max(sum,maxi)
return maxi
|
[
"assert maximum_Sum([[1,2,3],[4,5,6],[10,11,12],[7,8,9]]) == 33",
"assert maximum_Sum([[0,1,1],[1,1,2],[3,2,1]]) == 6",
"assert maximum_Sum([[0,1,3],[1,2,1],[9,8,2],[0,1,0],[6,4,8]]) == 19"
] |
[
"assert maximum_Sum([[0,-1,-1],[-1,-1,-2],[-3,-2,-1]]) == -2"
] |
Mary went to the kitchen. Mary journeyed to the bedroom. Sandra travelled to the office. John went back to the hallway. Daniel grabbed the football there. Daniel left the football. Daniel got the football there. Sandra travelled to the hallway. John got the apple there. Daniel dropped the football. Mary picked up the football there. Daniel moved to the garden. Mary went back to the garden. John took the milk there. Daniel went back to the kitchen. John went to the office. Sandra went to the bedroom. Sandra went back to the bathroom. Sandra journeyed to the hallway. Mary left the football. John travelled to the bedroom. Sandra travelled to the kitchen.
|
babilong_0k_qa2_sample_67
| 137
| 186
|
|
216
|
Write a function to check if a nested list is a subset of another nested list.
|
def check_subset_list(list1, list2):
l1, l2 = list1[0], list2[0]
exist = True
for i in list2:
if i not in list1:
exist = False
return exist
|
[
"assert check_subset_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],[[12, 18, 23, 25, 45], [7, 11, 19, 24, 28], [1, 5, 8, 18, 15, 16]])==False",
"assert check_subset_list([[2, 3, 1], [4, 5], [6, 8]],[[4, 5], [6, 8]])==True",
"assert check_subset_list([['a', 'b'], ['e'], ['c', 'd']],[['g']])==False"
] |
[] |
The hallway is east of the bathroom. The bathroom is east of the kitchen.
|
babilong_0k_qa4_sample_60
| 17
| 186
|
|
483
|
Write a python function to find the first natural number whose factorial is divisible by x.
|
def first_Factorial_Divisible_Number(x):
i = 1;
fact = 1;
for i in range(1,x):
fact = fact * i
if (fact % x == 0):
break
return i
|
[
"assert first_Factorial_Divisible_Number(10) == 5",
"assert first_Factorial_Divisible_Number(15) == 5",
"assert first_Factorial_Divisible_Number(5) == 4"
] |
[] |
Mary journeyed to the kitchen. Sandra went back to the garden. Daniel moved to the kitchen. Daniel travelled to the bedroom. Mary moved to the garden. Mary travelled to the bathroom. Daniel went to the office. Sandra went to the bedroom. Mary moved to the kitchen. John went back to the office.
|
babilong_0k_qa1_sample_52
| 64
| 186
|
|
302
|
Write a python function to find the most significant bit number which is also a set bit.
|
def set_Bit_Number(n):
if (n == 0):
return 0;
msb = 0;
n = int(n / 2);
while (n > 0):
n = int(n / 2);
msb += 1;
return (1 << msb)
|
[
"assert set_Bit_Number(6) == 4",
"assert set_Bit_Number(10) == 8",
"assert set_Bit_Number(18) == 16"
] |
[] |
Bill went back to the hallway. Jeff moved to the garden. Mary journeyed to the kitchen. Bill went back to the office. Bill journeyed to the hallway. Fred journeyed to the bathroom. Fred got the apple there. Bill went back to the kitchen. Mary grabbed the milk there. Mary handed the milk to Bill.
|
babilong_0k_qa5_sample_14
| 68
| 189
|
|
64
|
Write a function to sort a list of tuples using lambda.
|
def subject_marks(subjectmarks):
#subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])
subjectmarks.sort(key = lambda x: x[1])
return subjectmarks
|
[
"assert subject_marks([('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])==[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)]",
"assert subject_marks([('Telugu',49),('Hindhi',54),('Social',33)])==([('Social',33),('Telugu',49),('Hindhi',54)])",
"assert subject_marks([('Physics',96),('Chemistry',97),('Biology',45)])==([('Biology',45),('Physics',96),('Chemistry',97)])"
] |
[] |
Daniel went to the bedroom. Daniel journeyed to the office. Daniel travelled to the bathroom. Mary went to the office.
|
babilong_0k_qa1_sample_88
| 26
| 190
|
|
431
|
Write a function that takes two lists and returns true if they have at least one common element.
|
def common_element(list1, list2):
result = False
for x in list1:
for y in list2:
if x == y:
result = True
return result
|
[
"assert common_element([1,2,3,4,5], [5,6,7,8,9])==True",
"assert common_element([1,2,3,4,5], [6,7,8,9])==None",
"assert common_element(['a','b','c'], ['d','b','e'])==True"
] |
[] |
Mary picked up the apple. John went to the garden. Sandra travelled to the office. Sandra took the milk. John went to the bedroom. Sandra went to the kitchen. John journeyed to the office. Mary left the apple. Mary travelled to the office. Sandra went to the office. Daniel went to the hallway. Sandra discarded the milk. Mary went to the bathroom. John moved to the hallway. Daniel got the football. Daniel discarded the football. Daniel grabbed the football. Mary went to the office. Mary grabbed the milk. Daniel dropped the football. Mary went to the bedroom. John got the football there. John left the football. Sandra went to the bathroom. Mary travelled to the kitchen. Mary picked up the apple there. Sandra journeyed to the bedroom. John took the football. John discarded the football. Daniel went back to the bedroom. John grabbed the football. Mary went back to the garden. Mary put down the apple. John went back to the bedroom. Daniel travelled to the kitchen. Mary dropped the milk. John left the football. Sandra got the football there.
|
babilong_0k_qa3_sample_16
| 221
| 191
|
|
78
|
Write a python function to find number of integers with odd number of set bits.
|
def count_With_Odd_SetBits(n):
if (n % 2 != 0):
return (n + 1) / 2
count = bin(n).count('1')
ans = n / 2
if (count % 2 != 0):
ans += 1
return ans
|
[
"assert count_With_Odd_SetBits(5) == 3",
"assert count_With_Odd_SetBits(10) == 5",
"assert count_With_Odd_SetBits(15) == 8"
] |
[] |
Daniel went back to the office. John went back to the office. John went back to the bathroom. John took the football. Sandra journeyed to the hallway. Sandra travelled to the bedroom. John went back to the garden. John went to the hallway. Daniel went back to the bathroom. John put down the football. John grabbed the football. Mary journeyed to the office. Mary travelled to the bedroom. Sandra went to the hallway. Daniel travelled to the hallway. Daniel picked up the apple. Daniel grabbed the milk. John dropped the football there. John journeyed to the garden. John moved to the hallway. Sandra moved to the bedroom. John took the football. Daniel discarded the apple. Daniel moved to the kitchen. Sandra travelled to the kitchen. John left the football. Mary moved to the kitchen. Daniel travelled to the office. Daniel left the milk. Mary went to the bedroom. Daniel went to the hallway. John got the football.
|
babilong_0k_qa3_sample_69
| 193
| 193
|
|
303
|
Write a python function to check whether the count of inversion of two types are same or not.
|
import sys
def solve(a,n):
mx = -sys.maxsize - 1
for j in range(1,n):
if (mx > a[j]):
return False
mx = max(mx,a[j - 1])
return True
|
[
"assert solve([1,0,2],3) == True",
"assert solve([1,2,0],3) == False",
"assert solve([1,2,1],3) == True"
] |
[] |
The kitchen is west of the bedroom. The office is east of the bedroom.
|
babilong_0k_qa4_sample_11
| 17
| 193
|
|
324
|
Write a function to extract the sum of alternate chains of tuples.
|
def sum_of_alternates(test_tuple):
sum1 = 0
sum2 = 0
for idx, ele in enumerate(test_tuple):
if idx % 2:
sum1 += ele
else:
sum2 += ele
return ((sum1),(sum2))
|
[
"assert sum_of_alternates((5, 6, 3, 6, 10, 34)) == (46, 18)",
"assert sum_of_alternates((1, 2, 3, 4, 5)) == (6, 9)",
"assert sum_of_alternates((6, 7, 8, 9, 4, 5)) == (21, 18)"
] |
[] |
Mary journeyed to the bathroom. Sandra took the milk there. John took the football there. John moved to the kitchen.
|
babilong_0k_qa2_sample_95
| 26
| 193
|
|
332
|
Write a function to count character frequency of a given string.
|
def char_frequency(str1):
dict = {}
for n in str1:
keys = dict.keys()
if n in keys:
dict[n] += 1
else:
dict[n] = 1
return dict
|
[
"assert char_frequency('python')=={'p': 1, 'y': 1, 't': 1, 'h': 1, 'o': 1, 'n': 1}",
"assert char_frequency('program')=={'p': 1, 'r': 2, 'o': 1, 'g': 1, 'a': 1, 'm': 1}",
"assert char_frequency('language')=={'l': 1, 'a': 2, 'n': 1, 'g': 2, 'u': 1, 'e': 1}"
] |
[] |
Sandra went back to the bathroom. Sandra travelled to the garden.
|
babilong_0k_qa1_sample_96
| 15
| 194
|
|
137
|
Write a function to find the ration of zeroes in an array of integers.
|
from array import array
def zero_count(nums):
n = len(nums)
n1 = 0
for x in nums:
if x == 0:
n1 += 1
else:
None
return round(n1/n,2)
|
[
"assert zero_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8])==0.15",
"assert zero_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==0.00",
"assert zero_count([2, 4, -6, -9, 11, -12, 14, -5, 17])==0.00"
] |
[] |
The kitchen is north of the garden. The bedroom is north of the kitchen.
|
babilong_0k_qa4_sample_8
| 17
| 195
|
|
462
|
Write a function to find all possible combinations of the elements of a given list.
|
def combinations_list(list1):
if len(list1) == 0:
return [[]]
result = []
for el in combinations_list(list1[1:]):
result += [el, el+[list1[0]]]
return result
|
[
"assert combinations_list(['orange', 'red', 'green', 'blue'])==[[], ['orange'], ['red'], ['red', 'orange'], ['green'], ['green', 'orange'], ['green', 'red'], ['green', 'red', 'orange'], ['blue'], ['blue', 'orange'], ['blue', 'red'], ['blue', 'red', 'orange'], ['blue', 'green'], ['blue', 'green', 'orange'], ['blue', 'green', 'red'], ['blue', 'green', 'red', 'orange']]",
"assert combinations_list(['red', 'green', 'blue', 'white', 'black', 'orange'])==[[], ['red'], ['green'], ['green', 'red'], ['blue'], ['blue', 'red'], ['blue', 'green'], ['blue', 'green', 'red'], ['white'], ['white', 'red'], ['white', 'green'], ['white', 'green', 'red'], ['white', 'blue'], ['white', 'blue', 'red'], ['white', 'blue', 'green'], ['white', 'blue', 'green', 'red'], ['black'], ['black', 'red'], ['black', 'green'], ['black', 'green', 'red'], ['black', 'blue'], ['black', 'blue', 'red'], ['black', 'blue', 'green'], ['black', 'blue', 'green', 'red'], ['black', 'white'], ['black', 'white', 'red'], ['black', 'white', 'green'], ['black', 'white', 'green', 'red'], ['black', 'white', 'blue'], ['black', 'white', 'blue', 'red'], ['black', 'white', 'blue', 'green'], ['black', 'white', 'blue', 'green', 'red'], ['orange'], ['orange', 'red'], ['orange', 'green'], ['orange', 'green', 'red'], ['orange', 'blue'], ['orange', 'blue', 'red'], ['orange', 'blue', 'green'], ['orange', 'blue', 'green', 'red'], ['orange', 'white'], ['orange', 'white', 'red'], ['orange', 'white', 'green'], ['orange', 'white', 'green', 'red'], ['orange', 'white', 'blue'], ['orange', 'white', 'blue', 'red'], ['orange', 'white', 'blue', 'green'], ['orange', 'white', 'blue', 'green', 'red'], ['orange', 'black'], ['orange', 'black', 'red'], ['orange', 'black', 'green'], ['orange', 'black', 'green', 'red'], ['orange', 'black', 'blue'], ['orange', 'black', 'blue', 'red'], ['orange', 'black', 'blue', 'green'], ['orange', 'black', 'blue', 'green', 'red'], ['orange', 'black', 'white'], ['orange', 'black', 'white', 'red'], ['orange', 'black', 'white', 'green'], ['orange', 'black', 'white', 'green', 'red'], ['orange', 'black', 'white', 'blue'], ['orange', 'black', 'white', 'blue', 'red'], ['orange', 'black', 'white', 'blue', 'green'], ['orange', 'black', 'white', 'blue', 'green', 'red']]",
"assert combinations_list(['red', 'green', 'black', 'orange'])==[[], ['red'], ['green'], ['green', 'red'], ['black'], ['black', 'red'], ['black', 'green'], ['black', 'green', 'red'], ['orange'], ['orange', 'red'], ['orange', 'green'], ['orange', 'green', 'red'], ['orange', 'black'], ['orange', 'black', 'red'], ['orange', 'black', 'green'], ['orange', 'black', 'green', 'red']]"
] |
[] |
Sandra moved to the garden. John went to the garden. Sandra went to the bathroom. Sandra went to the kitchen.
|
babilong_0k_qa1_sample_33
| 26
| 195
|
|
37
|
Write a function to sort a given mixed list of integers and strings.
|
def sort_mixed_list(mixed_list):
int_part = sorted([i for i in mixed_list if type(i) is int])
str_part = sorted([i for i in mixed_list if type(i) is str])
return int_part + str_part
|
[
"assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']",
"assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']",
"assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']"
] |
[] |
Fred moved to the garden. Jeff went back to the garden. Mary travelled to the bathroom. Fred travelled to the bathroom. Fred journeyed to the kitchen. Jeff went to the bedroom. Jeff travelled to the office. Fred took the football there. Jeff moved to the bedroom. Jeff picked up the milk there. Fred left the football. Fred travelled to the bathroom. Fred moved to the bedroom. Jeff dropped the milk. Jeff grabbed the milk there. Jeff discarded the milk there. Mary moved to the kitchen. Bill travelled to the kitchen. Fred got the milk there. Fred handed the milk to Jeff. Bill took the football there. Mary moved to the garden. Bill discarded the football. Jeff gave the milk to Fred. Jeff went to the hallway. Bill grabbed the football there. Fred discarded the milk. Fred got the milk there.
|
babilong_0k_qa5_sample_8
| 170
| 196
|
|
296
|
Write a python function to count inversions in an array.
|
def get_Inv_Count(arr,n):
inv_count = 0
for i in range(n):
for j in range(i + 1,n):
if (arr[i] > arr[j]):
inv_count += 1
return inv_count
|
[
"assert get_Inv_Count([1,20,6,4,5],5) == 5",
"assert get_Inv_Count([1,2,1],3) == 1",
"assert get_Inv_Count([1,2,5,6,1],5) == 3"
] |
[] |
John journeyed to the office. Sandra went to the kitchen. Sandra journeyed to the bedroom. Sandra travelled to the office. Daniel travelled to the bathroom. Daniel went back to the garden. Sandra got the apple. Daniel travelled to the office. Daniel picked up the milk. Daniel took the football. Sandra travelled to the bedroom. Daniel discarded the football. Daniel journeyed to the hallway. Daniel went back to the bedroom. John grabbed the football. Sandra put down the apple there. John went to the bathroom. Mary journeyed to the kitchen. Mary journeyed to the hallway. Daniel picked up the apple. Daniel discarded the milk. Sandra went to the bathroom. Sandra journeyed to the bedroom. John put down the football. Daniel picked up the milk. Sandra went to the kitchen. John took the football there. Daniel discarded the milk. Daniel journeyed to the kitchen. John put down the football. John moved to the bedroom. John picked up the milk. Daniel journeyed to the bathroom. Daniel picked up the football. John went back to the office. John travelled to the garden.
|
babilong_0k_qa3_sample_66
| 223
| 196
|
|
160
|
Write a function to find x and y that satisfies ax + by = n.
|
def solution (a, b, n):
i = 0
while i * a <= n:
if (n - (i * a)) % b == 0:
return ("x = ",i ,", y = ",
int((n - (i * a)) / b))
return 0
i = i + 1
return ("No solution")
|
[
"assert solution(2, 3, 7) == ('x = ', 2, ', y = ', 1)",
"assert solution(4, 2, 7) == 'No solution'",
"assert solution(1, 13, 17) == ('x = ', 4, ', y = ', 1)"
] |
[] |
Daniel travelled to the garden. Sandra went back to the bedroom. John travelled to the bedroom. Sandra grabbed the apple there. Daniel travelled to the kitchen. Sandra left the apple.
|
babilong_0k_qa2_sample_14
| 37
| 198
|
|
166
|
Write a python function to count the pairs with xor as an even number.
|
def find_even_Pair(A,N):
evenPair = 0
for i in range(0,N):
for j in range(i+1,N):
if ((A[i] ^ A[j]) % 2 == 0):
evenPair+=1
return evenPair;
|
[
"assert find_even_Pair([5,4,7,2,1],5) == 4",
"assert find_even_Pair([7,2,8,1,0,5,11],7) == 9",
"assert find_even_Pair([1,2,3],3) == 1"
] |
[] |
Fred travelled to the hallway. Bill grabbed the apple there. Jeff went to the bathroom. Bill discarded the apple. Mary went back to the hallway. Bill took the apple there. Jeff moved to the office. Mary journeyed to the bedroom. Jeff journeyed to the bedroom. Jeff got the football there. Jeff handed the football to Mary. Mary gave the football to Jeff. Jeff passed the football to Mary. Bill discarded the apple there. Mary passed the football to Jeff. Jeff went to the hallway. Fred went back to the garden. Fred went to the kitchen.
|
babilong_0k_qa5_sample_11
| 116
| 198
|
|
442
|
Write a function to find the ration of positive numbers in an array of integers.
|
from array import array
def positive_count(nums):
n = len(nums)
n1 = 0
for x in nums:
if x > 0:
n1 += 1
else:
None
return round(n1/n,2)
|
[
"assert positive_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8])==0.54",
"assert positive_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==0.69",
"assert positive_count([2, 4, -6, -9, 11, -12, 14, -5, 17])==0.56"
] |
[] |
Mary journeyed to the hallway. Mary travelled to the bathroom. Jeff journeyed to the office. Bill moved to the bathroom. Mary journeyed to the hallway. Mary went back to the garden. Bill travelled to the garden. Bill journeyed to the hallway. Bill went back to the kitchen. Jeff got the milk there. Mary journeyed to the bedroom. Jeff travelled to the hallway. Bill moved to the hallway. Jeff journeyed to the bedroom. Bill journeyed to the bathroom. Jeff dropped the milk. Mary got the milk there. Mary passed the milk to Jeff.
|
babilong_0k_qa5_sample_30
| 118
| 198
|
|
140
|
Write a function to extract elements that occur singly in the given tuple list.
|
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 extract_singly([(3, 4, 5), (4, 5, 7), (1, 4)]) == [3, 4, 5, 7, 1]",
"assert extract_singly([(1, 2, 3), (4, 2, 3), (7, 8)]) == [1, 2, 3, 4, 7, 8]",
"assert extract_singly([(7, 8, 9), (10, 11, 12), (10, 11)]) == [7, 8, 9, 10, 11, 12]"
] |
[] |
Sandra journeyed to the office. Sandra travelled to the bathroom. Daniel moved to the bedroom. Daniel went to the garden. Mary journeyed to the hallway. Sandra went to the office. Daniel went back to the bathroom. Mary travelled to the kitchen.
|
babilong_0k_qa1_sample_28
| 53
| 200
|
|
44
|
Write a function that matches a word at the beginning of a string.
|
import re
def text_match_string(text):
patterns = '^\w+'
if re.search(patterns, text):
return 'Found a match!'
else:
return 'Not matched!'
|
[
"assert text_match_string(\" python\")==('Not matched!')",
"assert text_match_string(\"python\")==('Found a match!')",
"assert text_match_string(\" lang\")==('Not matched!')"
] |
[
"assert text_match_string(\"foo\")==('Found a match!')"
] |
Daniel journeyed to the bedroom. Sandra journeyed to the kitchen. Daniel went to the bathroom. Daniel went to the hallway. Daniel travelled to the bathroom. Sandra went to the garden. Mary moved to the bathroom. Daniel travelled to the bedroom.
|
babilong_0k_qa1_sample_91
| 51
| 201
|
|
127
|
Write a function to multiply two integers without using the * operator in python.
|
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"
] |
[] |
Mary went to the garden. Jeff went back to the garden. Jeff grabbed the apple there. Fred moved to the office. Fred moved to the garden. Jeff passed the apple to Mary. Mary travelled to the hallway. Jeff went to the bedroom. Mary put down the apple. Jeff picked up the football there. Mary went to the bedroom. Jeff gave the football to Mary.
|
babilong_0k_qa5_sample_81
| 77
| 201
|
|
434
|
Write a function that matches a string that has an a followed by one or more b's.
|
import re
def text_match_one(text):
patterns = 'ab+?'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!')
|
[
"assert text_match_one(\"ac\")==('Not matched!')",
"assert text_match_one(\"dc\")==('Not matched!')",
"assert text_match_one(\"abba\")==('Found a match!')"
] |
[] |
Daniel moved to the bathroom. Mary took the apple there. Daniel travelled to the kitchen. Daniel took the football. John picked up the milk. Mary went back to the office. John travelled to the kitchen. Daniel dropped the football. Daniel journeyed to the garden. Daniel travelled to the bathroom. John left the milk. Daniel went back to the garden. John picked up the milk. Mary moved to the garden. John moved to the office. Sandra went to the office. Sandra went back to the bedroom. Daniel travelled to the bathroom. Mary moved to the kitchen. Daniel moved to the office. Mary journeyed to the bedroom. John went back to the hallway. Mary left the apple. John dropped the milk. Mary journeyed to the garden. Sandra got the apple. Sandra left the apple. John got the milk. John went back to the kitchen. John left the milk. John got the football there. Daniel went back to the bedroom. John took the milk. John put down the milk. John travelled to the hallway. Sandra moved to the hallway. John travelled to the bathroom. Daniel travelled to the office. Daniel went to the hallway. John dropped the football. Sandra moved to the kitchen. Mary travelled to the office.
|
babilong_0k_qa3_sample_40
| 251
| 201
|
|
455
|
Write a function to check whether the given month number contains 31 days or not.
|
def check_monthnumb_number(monthnum2):
if(monthnum2==1 or monthnum2==3 or monthnum2==5 or monthnum2==7 or monthnum2==8 or monthnum2==10 or monthnum2==12):
return True
else:
return False
|
[
"assert check_monthnumb_number(5)==True",
"assert check_monthnumb_number(2)==False",
"assert check_monthnumb_number(6)==False"
] |
[] |
Mary moved to the bathroom. Mary went to the hallway. Daniel travelled to the bedroom. Mary journeyed to the garden. John travelled to the office. Daniel travelled to the office. Mary went to the bedroom. Sandra went back to the kitchen.
|
babilong_0k_qa1_sample_36
| 51
| 201
|
|
20
|
Write a function to check if the given number is woodball or not.
|
def is_woodall(x):
if (x % 2 == 0):
return False
if (x == 1):
return True
x = x + 1
p = 0
while (x % 2 == 0):
x = x/2
p = p + 1
if (p == x):
return True
return False
|
[
"assert is_woodall(383) == True",
"assert is_woodall(254) == False",
"assert is_woodall(200) == False"
] |
[
"assert is_woodall(32212254719) == True",
"assert is_woodall(32212254718) == False",
"assert is_woodall(159) == True"
] |
Daniel went back to the kitchen. Daniel moved to the office. Daniel went back to the bedroom. John moved to the garden. Daniel travelled to the office. Mary journeyed to the garden.
|
babilong_0k_qa1_sample_44
| 40
| 202
|
|
48
|
Write a python function to set all odd bits of a given number.
|
def odd_bit_set_number(n):
count = 0;res = 0;temp = n
while temp > 0:
if count % 2 == 0:
res |= (1 << count)
count += 1
temp >>= 1
return (n | res)
|
[
"assert odd_bit_set_number(10) == 15",
"assert odd_bit_set_number(20) == 21",
"assert odd_bit_set_number(30) == 31"
] |
[] |
Bill went to the office. Mary moved to the office. Fred took the football there. Fred moved to the office. Fred put down the football. Fred went to the garden. Jeff moved to the kitchen. Mary took the football there. Jeff moved to the bathroom. Mary moved to the bedroom. Mary took the milk there. Bill journeyed to the bathroom. Fred moved to the kitchen. Fred went to the hallway. Jeff went back to the garden. Bill went back to the garden. Mary picked up the apple there. Mary moved to the hallway. Mary passed the apple to Fred. Mary went back to the bathroom. Bill moved to the bathroom. Mary put down the football. Mary went to the hallway. Jeff went back to the bedroom. Mary discarded the milk. Fred passed the apple to Mary.
|
babilong_0k_qa5_sample_34
| 164
| 202
|
|
227
|
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"
] |
[] |
Mary journeyed to the office. Sandra picked up the milk there. John went back to the kitchen. Sandra got the apple there. Mary got the football there. Mary went back to the garden. Daniel went to the bathroom. John went to the bathroom. Sandra went back to the garden. Sandra discarded the apple. Daniel went back to the bedroom. Sandra went back to the bathroom.
|
babilong_0k_qa2_sample_42
| 79
| 202
|
|
337
|
Write a function that matches a word at the end of a string, with optional punctuation.
|
import re
def text_match_word(text):
patterns = '\w+\S*$'
if re.search(patterns, text):
return 'Found a match!'
else:
return 'Not matched!'
|
[
"assert text_match_word(\"python.\")==('Found a match!')",
"assert text_match_word(\"python.\")==('Found a match!')",
"assert text_match_word(\" lang .\")==('Not matched!')"
] |
[] |
Sandra got the milk. Mary travelled to the bedroom. Mary travelled to the garden. John moved to the hallway. Sandra discarded the milk. Mary went to the hallway. Daniel went to the bedroom. Daniel travelled to the hallway. Daniel journeyed to the bathroom. Daniel moved to the garden. Mary went back to the garden. Daniel travelled to the hallway. Sandra went back to the office. Sandra moved to the bedroom. Mary went back to the hallway. Sandra moved to the office. Sandra went to the hallway. Sandra travelled to the kitchen. Sandra travelled to the bedroom. John travelled to the office. Sandra took the football. John travelled to the garden. Sandra left the football there. John travelled to the bathroom. John journeyed to the office. John journeyed to the bathroom. Sandra journeyed to the hallway. John went back to the garden. Sandra travelled to the office. Mary went to the garden. Daniel travelled to the bedroom. Mary journeyed to the office. Daniel travelled to the bathroom. Mary journeyed to the bathroom. Mary travelled to the office. Daniel travelled to the kitchen. Sandra moved to the bedroom. Mary journeyed to the bedroom. John travelled to the bedroom. Sandra journeyed to the bathroom. John took the football there. Sandra travelled to the garden. John travelled to the hallway. Daniel journeyed to the garden. Sandra travelled to the bedroom. John moved to the kitchen. John picked up the apple. Sandra went to the garden. John discarded the football. Mary went back to the office. John discarded the apple. John went to the bedroom. John moved to the bathroom. Daniel moved to the hallway. John went back to the garden. John travelled to the office. Sandra journeyed to the bedroom. Sandra moved to the hallway. Sandra moved to the office. Sandra went back to the kitchen. Daniel went back to the office. Sandra took the milk. John went back to the bathroom. John went back to the garden. Sandra dropped the milk. Sandra went to the office. John travelled to the bedroom. John journeyed to the hallway. Daniel travelled to the garden. Mary journeyed to the hallway. Sandra went to the bathroom. Daniel travelled to the hallway. Daniel journeyed to the kitchen. Daniel took the milk. Daniel picked up the football. Daniel picked up the apple. Daniel travelled to the office. John went to the bathroom. Mary moved to the office. Sandra travelled to the bedroom. Daniel left the apple there. Daniel got the apple. Mary moved to the bedroom. Sandra moved to the bathroom. Daniel dropped the apple. Sandra travelled to the hallway. John moved to the garden. Daniel moved to the garden. Sandra moved to the office. Mary went to the office. Sandra grabbed the apple. Daniel put down the milk. Mary went back to the hallway. Mary went back to the bedroom.
|
babilong_0k_qa3_sample_94
| 580
| 202
|
|
498
|
Write a python function to find gcd of two positive integers.
|
def gcd(x, y):
gcd = 1
if x % y == 0:
return y
for k in range(int(y / 2), 0, -1):
if x % k == 0 and y % k == 0:
gcd = k
break
return gcd
|
[
"assert gcd(12, 17) == 1",
"assert gcd(4,6) == 2",
"assert gcd(2,9) == 1"
] |
[] |
Sandra went back to the kitchen. Daniel went to the kitchen. Mary got the milk there. Sandra went back to the bathroom. Mary went to the hallway. Daniel moved to the bedroom. John journeyed to the hallway. Sandra journeyed to the hallway. Mary got the apple there. John went to the bathroom. Daniel moved to the hallway. Mary discarded the apple.
|
babilong_0k_qa2_sample_88
| 77
| 202
|
|
299
|
Write a function to calculate the maximum aggregate from the list of tuples.
|
from collections import defaultdict
def max_aggregate(stdata):
temp = defaultdict(int)
for name, marks in stdata:
temp[name] += marks
return max(temp.items(), key=lambda x: x[1])
|
[
"assert max_aggregate([('Juan Whelan',90),('Sabah Colley',88),('Peter Nichols',7),('Juan Whelan',122),('Sabah Colley',84)])==('Juan Whelan', 212)",
"assert max_aggregate([('Juan Whelan',50),('Sabah Colley',48),('Peter Nichols',37),('Juan Whelan',22),('Sabah Colley',14)])==('Juan Whelan', 72)",
"assert max_aggregate([('Juan Whelan',10),('Sabah Colley',20),('Peter Nichols',30),('Juan Whelan',40),('Sabah Colley',50)])==('Sabah Colley', 70)"
] |
[] |
Fred picked up the football there. Jeff travelled to the hallway. Bill went back to the kitchen. Bill went to the hallway. Fred travelled to the garden. Fred grabbed the milk there. Bill travelled to the office. Fred put down the milk there. Fred put down the football. Bill journeyed to the hallway. Fred journeyed to the kitchen. Jeff travelled to the garden. Jeff picked up the milk there. Mary went back to the office. Mary moved to the kitchen. Jeff grabbed the football there. Bill travelled to the garden. Fred went to the office. Fred went to the kitchen. Jeff dropped the milk. Jeff picked up the milk there. Jeff went to the bedroom. Jeff left the football. Jeff dropped the milk. Jeff grabbed the milk there. Jeff journeyed to the kitchen. Jeff passed the milk to Mary. Mary passed the milk to Fred. Fred discarded the milk. Jeff got the milk there. Jeff passed the milk to Mary. Bill moved to the kitchen. Jeff went back to the bedroom. Mary passed the milk to Fred.
|
babilong_0k_qa5_sample_4
| 215
| 203
|
|
145
|
Write a python function to find the maximum difference between any two elements in a given array.
|
def max_Abs_Diff(arr,n):
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) == 4",
"assert max_Abs_Diff((9,3,2,5,1),5) == 8",
"assert max_Abs_Diff((3,2,1),3) == 2"
] |
[] |
The kitchen is east of the office. The bathroom is west of the office.
|
babilong_0k_qa4_sample_74
| 17
| 204
|
|
454
|
Write a function that matches a word containing 'z'.
|
import re
def text_match_wordz(text):
patterns = '\w*z.\w*'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!')
|
[
"assert text_match_wordz(\"pythonz.\")==('Found a match!')",
"assert text_match_wordz(\"xyz.\")==('Found a match!')",
"assert text_match_wordz(\" lang .\")==('Not matched!')"
] |
[] |
The kitchen is north of the bedroom. The garden is south of the bedroom.
|
babilong_0k_qa4_sample_3
| 17
| 205
|
|
130
|
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
|
[
"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, 5)",
"assert max_occurrences([2,3,8,4,7,9,8,7,9,15,14,10,12,13,16,16,18])==(8, 2)",
"assert max_occurrences([10,20,20,30,40,90,80,50,30,20,50,10])==(20, 3)"
] |
[] |
Jeff took the apple there. Jeff went to the bathroom. Jeff picked up the football there. Jeff put down the apple. Jeff dropped the football. Fred journeyed to the office. Jeff grabbed the football there. Bill went back to the hallway. Jeff dropped the football. Jeff journeyed to the kitchen. Jeff moved to the hallway. Bill went to the kitchen. Bill went to the garden. Fred travelled to the garden. Fred moved to the kitchen. Jeff moved to the bedroom. Bill went to the bathroom. Jeff travelled to the bathroom. Mary went back to the office. Bill journeyed to the office. Bill journeyed to the bedroom. Jeff picked up the milk there. Mary travelled to the hallway. Jeff travelled to the kitchen. Jeff passed the milk to Fred. Fred passed the milk to Jeff. Jeff handed the milk to Fred. Bill went to the office. Jeff journeyed to the office. Mary went back to the office.
|
babilong_0k_qa5_sample_47
| 192
| 206
|
|
65
|
Write a function of recursion list sum.
|
def recursive_list_sum(data_list):
total = 0
for element in data_list:
if type(element) == type([]):
total = total + recursive_list_sum(element)
else:
total = total + element
return total
|
[
"assert recursive_list_sum(([1, 2, [3,4],[5,6]]))==21",
"assert recursive_list_sum(([7, 10, [15,14],[19,41]]))==106",
"assert recursive_list_sum(([10, 20, [30,40],[50,60]]))==210"
] |
[] |
Bill moved to the kitchen. Bill moved to the hallway. Jeff journeyed to the bathroom. Fred went to the office. Bill moved to the office. Fred went to the bedroom. Mary went to the hallway. Jeff went back to the garden. Fred went back to the bathroom. Jeff went back to the kitchen. Bill journeyed to the garden. Mary travelled to the bedroom. Jeff travelled to the bathroom. Jeff journeyed to the kitchen. Bill took the apple there. Bill put down the apple. Bill grabbed the apple there. Mary went to the hallway. Bill discarded the apple. Mary moved to the garden. Bill went to the hallway. Fred journeyed to the bedroom. Mary moved to the kitchen. Bill moved to the bathroom. Fred went back to the office. Mary moved to the hallway. Mary went back to the bedroom. Bill went back to the office. Jeff took the football there. Mary went back to the bathroom. Jeff went back to the hallway. Fred went back to the bathroom. Bill went to the kitchen. Jeff put down the football. Bill went to the bathroom. Jeff moved to the garden. Jeff went back to the bathroom. Bill went back to the garden. Bill journeyed to the kitchen. Fred went to the office. Mary travelled to the bedroom. Fred went back to the bathroom. Fred journeyed to the kitchen. Fred went back to the garden. Bill journeyed to the bedroom. Bill moved to the garden. Fred picked up the apple there. Mary went to the office. Fred gave the apple to Bill. Fred went to the bedroom.
|
babilong_0k_qa5_sample_45
| 322
| 207
|
|
188
|
Write a python function to check whether the given number can be represented by product of two squares or not.
|
def prod_Square(n):
for i in range(2,(n) + 1):
if (i*i < (n+1)):
for j in range(2,n + 1):
if ((i*i*j*j) == n):
return True;
return False;
|
[
"assert prod_Square(25) == False",
"assert prod_Square(30) == False",
"assert prod_Square(16) == True"
] |
[] |
Sandra moved to the kitchen. Sandra went back to the bathroom.
|
babilong_0k_qa1_sample_13
| 15
| 207
|
|
56
|
Write a python function to check if a given number is one less than twice its reverse.
|
def rev(num):
rev_num = 0
while (num > 0):
rev_num = (rev_num * 10 + num % 10)
num = num // 10
return rev_num
def check(n):
return (2 * rev(n) == n + 1)
|
[
"assert check(70) == False",
"assert check(23) == False",
"assert check(73) == True"
] |
[] |
John got the milk. Mary got the football. Mary took the apple. Mary put down the football. Mary left the apple. Sandra moved to the bedroom. John moved to the bathroom. Mary got the football. Mary moved to the bathroom. John went to the office. Mary went back to the office. Mary got the apple. Mary travelled to the bathroom. Sandra journeyed to the garden. Mary put down the apple. John went to the kitchen. John put down the milk. Daniel took the milk. Mary picked up the apple. John journeyed to the hallway. Daniel went to the garden. John travelled to the garden. John went back to the kitchen. Daniel went back to the bathroom. Daniel left the milk. Daniel picked up the milk. Sandra went to the kitchen. John went back to the office. Daniel dropped the milk. Sandra travelled to the office. John journeyed to the bedroom. John travelled to the garden. Mary got the milk. Sandra journeyed to the bedroom. Daniel went to the hallway. Sandra moved to the bathroom. Sandra journeyed to the office. John moved to the bathroom. Mary discarded the apple. Mary picked up the apple. Mary left the milk. Sandra went back to the bedroom. Mary got the milk. Mary put down the football there. John got the football. Mary put down the milk. John left the football there. Mary dropped the apple. Mary grabbed the milk. Sandra journeyed to the bathroom. Mary got the football. Mary moved to the bedroom. Daniel journeyed to the kitchen. Sandra took the apple. Sandra dropped the apple. John picked up the apple. Sandra travelled to the kitchen. John moved to the office. John dropped the apple. John took the apple. John dropped the apple. Mary put down the milk there. Mary moved to the kitchen. John picked up the apple there. John put down the apple. Sandra journeyed to the bedroom. Daniel went back to the office. Mary put down the football. Mary went back to the bedroom. John got the apple. Daniel journeyed to the hallway. John went back to the bathroom.
|
babilong_0k_qa3_sample_51
| 430
| 208
|
|
285
|
Write a function that matches a string that has an a followed by two to three 'b'.
|
import re
def text_match_two_three(text):
patterns = 'ab{2,3}'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!')
|
[
"assert text_match_two_three(\"ac\")==('Not matched!')",
"assert text_match_two_three(\"dc\")==('Not matched!')",
"assert text_match_two_three(\"abbbba\")==('Found a match!')"
] |
[] |
Jeff travelled to the garden. Jeff journeyed to the bedroom. Fred journeyed to the office. Bill went back to the office. Mary travelled to the hallway. Fred journeyed to the garden. Fred moved to the hallway. Bill moved to the hallway. Fred went back to the office. Jeff travelled to the bathroom. Mary took the apple there. Fred went back to the hallway. Mary handed the apple to Fred. Mary went back to the kitchen.
|
babilong_0k_qa5_sample_50
| 93
| 208
|
|
291
|
Write a function to find out the number of ways of painting the fence such that at most 2 adjacent posts have the same color for the given fence with n posts and k colors.
|
def count_no_of_ways(n, k):
dp = [0] * (n + 1)
total = k
mod = 1000000007
dp[1] = k
dp[2] = k * k
for i in range(3,n+1):
dp[i] = ((k - 1) * (dp[i - 1] + dp[i - 2])) % mod
return dp[n]
|
[
"assert count_no_of_ways(2, 4) == 16",
"assert count_no_of_ways(3, 2) == 6",
"assert count_no_of_ways(4, 4) == 228"
] |
[] |
Mary moved to the hallway. Mary went to the kitchen. Mary picked up the milk there. John went back to the bathroom. Mary picked up the football there. John got the apple there. Mary went to the office. Daniel travelled to the kitchen. John dropped the apple there. Mary put down the football there. Mary grabbed the football there. John took the apple there. John went back to the hallway. Mary travelled to the kitchen. John moved to the kitchen. Mary left the milk.
|
babilong_0k_qa2_sample_55
| 101
| 208
|
|
402
|
Write a function to compute the value of ncr%p.
|
def ncr_modp(n, r, p):
C = [0 for i in range(r+1)]
C[0] = 1
for i in range(1, n+1):
for j in range(min(i, r), 0, -1):
C[j] = (C[j] + C[j-1]) % p
return C[r]
|
[
"assert ncr_modp(10,2,13)==6",
"assert ncr_modp(15,12,43)==25",
"assert ncr_modp(17,9,18)==10"
] |
[] |
Sandra grabbed the milk there. John moved to the bedroom. Sandra left the milk. Mary got the apple. Mary went to the hallway. Mary put down the apple there. Sandra got the milk there. John moved to the office. Mary went back to the garden. Sandra moved to the bedroom. Mary took the football. Daniel went back to the garden. Sandra went back to the garden. Mary put down the football there. Sandra got the football. Sandra went to the bathroom. Daniel travelled to the hallway. Daniel took the apple there. Daniel went to the garden. Sandra went back to the office. John moved to the hallway. Sandra went back to the hallway. Sandra went to the bathroom. Sandra dropped the milk. Sandra got the milk. Mary went back to the office. John travelled to the bedroom. Mary moved to the hallway. Mary went to the bedroom. Daniel went to the bedroom. Mary went back to the garden. Sandra went to the kitchen. Daniel travelled to the kitchen. Daniel discarded the apple. Daniel grabbed the apple. John went to the garden. Daniel put down the apple there. Daniel got the apple. Sandra travelled to the garden. Sandra put down the football. John took the football there. John put down the football there. Sandra went back to the office. Daniel went to the bathroom. Daniel moved to the garden. Daniel dropped the apple there. Daniel travelled to the bathroom. Sandra discarded the milk.
|
babilong_0k_qa3_sample_59
| 292
| 208
|
|
417
|
Write a function to find common first element in given list of tuple.
|
def group_tuples(Input):
out = {}
for elem in Input:
try:
out[elem[0]].extend(elem[1:])
except KeyError:
out[elem[0]] = list(elem)
return [tuple(values) for values in out.values()]
|
[
"assert group_tuples([('x', 'y'), ('x', 'z'), ('w', 't')]) == [('x', 'y', 'z'), ('w', 't')]",
"assert group_tuples([('a', 'b'), ('a', 'c'), ('d', 'e')]) == [('a', 'b', 'c'), ('d', 'e')]",
"assert group_tuples([('f', 'g'), ('f', 'g'), ('h', 'i')]) == [('f', 'g', 'g'), ('h', 'i')]"
] |
[] |
Mary travelled to the office. Bill moved to the hallway. Fred travelled to the bathroom. Fred moved to the hallway. Bill went to the garden. Bill journeyed to the office. Jeff travelled to the office. Bill got the apple there. Fred went back to the bedroom. Mary went back to the garden. Fred moved to the hallway. Bill passed the apple to Jeff. Jeff handed the apple to Bill. Bill travelled to the garden.
|
babilong_0k_qa5_sample_77
| 90
| 208
|
|
235
|
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"
] |
[] |
John moved to the bedroom. Sandra journeyed to the office. Sandra moved to the kitchen. Daniel travelled to the bedroom. John went back to the office. Mary travelled to the garden. Sandra moved to the hallway. Sandra went to the garden. John went back to the kitchen. Daniel went to the office. Sandra moved to the hallway. Daniel picked up the apple there. Mary went to the bedroom. Daniel went back to the garden. Daniel left the apple. Daniel grabbed the apple there. Sandra took the football there. Daniel discarded the apple. Mary journeyed to the kitchen. Sandra journeyed to the kitchen.
|
babilong_0k_qa2_sample_15
| 126
| 209
|
|
246
|
Write a function for computing square roots using the babylonian method.
|
def babylonian_squareroot(number):
if(number == 0):
return 0;
g = number/2.0;
g2 = g + 1;
while(g != g2):
n = number/ g;
g2 = g;
g = (g + n)/2;
return g;
|
[
"assert babylonian_squareroot(10)==3.162277660168379",
"assert babylonian_squareroot(2)==1.414213562373095",
"assert babylonian_squareroot(9)==3.0"
] |
[] |
Daniel travelled to the garden. Sandra journeyed to the bedroom. Daniel journeyed to the office. Daniel travelled to the bathroom.
|
babilong_0k_qa1_sample_51
| 27
| 214
|
|
33
|
Write a python function to convert a decimal number to binary number.
|
def decimal_To_Binary(N):
B_Number = 0
cnt = 0
while (N != 0):
rem = N % 2
c = pow(10,cnt)
B_Number += rem*c
N //= 2
cnt += 1
return B_Number
|
[
"assert decimal_To_Binary(10) == 1010",
"assert decimal_To_Binary(1) == 1",
"assert decimal_To_Binary(20) == 10100"
] |
[] |
John moved to the bathroom. Sandra took the apple there. Daniel journeyed to the hallway. John journeyed to the hallway. John went to the kitchen. Sandra moved to the bedroom. Sandra went back to the garden. Sandra grabbed the football. John travelled to the office. John grabbed the milk. Daniel went back to the office. Sandra dropped the apple. Mary moved to the garden. Mary got the apple. Mary moved to the office. Daniel went back to the bedroom. Mary went back to the kitchen. Mary went to the hallway. Mary went back to the garden. Mary discarded the apple. Mary went to the bedroom. Sandra got the apple. John moved to the kitchen. Daniel went to the hallway. Mary journeyed to the bathroom. John moved to the garden. John travelled to the kitchen. John moved to the office. Mary journeyed to the garden. Daniel went to the kitchen. John left the milk there. Sandra discarded the apple.
|
babilong_0k_qa3_sample_20
| 195
| 215
|
|
362
|
Write a python function to find the item with maximum occurrences in a given list.
|
def max_occurrences(nums):
max_val = 0
result = nums[0]
for i in nums:
occu = nums.count(i)
if occu > max_val:
max_val = occu
result = i
return result
|
[
"assert max_occurrences([1,2,3,1,2,3,12,4,2]) == 2",
"assert max_occurrences([1,2,6,7,0,1,0,1,0]) == 1,0",
"assert max_occurrences([1,2,3,1,2,4,1]) == 1"
] |
[] |
The bedroom is south of the bathroom. The hallway is south of the bedroom.
|
babilong_0k_qa4_sample_24
| 17
| 216
|
|
45
|
Write a function to find the gcd of the given array elements.
|
def find_gcd(x, y):
while(y):
x, y = y, x % y
return x
def get_gcd(l):
num1 = l[0]
num2 = l[1]
gcd = find_gcd(num1, num2)
for i in range(2, len(l)):
gcd = find_gcd(gcd, l[i])
return gcd
|
[
"assert get_gcd([2, 4, 6, 8, 16]) == 2",
"assert get_gcd([1, 2, 3]) == 1",
"assert get_gcd([2, 4, 6, 8]) == 2 "
] |
[] |
Mary moved to the kitchen. Mary travelled to the hallway. Bill travelled to the garden. Fred journeyed to the bedroom. Fred went back to the office. Bill went back to the bedroom. Jeff moved to the bathroom. Bill travelled to the office. Fred travelled to the hallway. Jeff took the football there. Jeff left the football. Jeff picked up the milk there. Bill went to the kitchen. Mary journeyed to the garden. Jeff went to the office. Bill went back to the garden. Fred travelled to the bedroom. Fred went back to the hallway. Jeff left the milk. Jeff went back to the bedroom. Jeff went to the hallway. Jeff journeyed to the bedroom. Jeff journeyed to the office. Jeff picked up the milk there. Jeff journeyed to the garden. Fred went to the bedroom. Jeff passed the milk to Mary. Mary handed the milk to Bill. Bill gave the milk to Mary. Mary passed the milk to Bill. Bill gave the milk to Mary. Jeff travelled to the bedroom. Mary discarded the milk. Jeff moved to the hallway.
|
babilong_0k_qa5_sample_23
| 219
| 217
|
|
487
|
Write a function to sort a list of tuples in increasing order by the last element in each tuple.
|
def sort_tuple(tup):
lst = len(tup)
for i in range(0, lst):
for j in range(0, lst-i-1):
if (tup[j][-1] > tup[j + 1][-1]):
temp = tup[j]
tup[j]= tup[j + 1]
tup[j + 1]= temp
return tup
|
[
"assert sort_tuple([(1, 3), (3, 2), (2, 1)] ) == [(2, 1), (3, 2), (1, 3)]",
"assert sort_tuple([(2, 4), (3, 3), (1, 1)] ) == [(1, 1), (3, 3), (2, 4)]",
"assert sort_tuple([(3, 9), (6, 7), (4, 3)] ) == [(4, 3), (6, 7), (3, 9)]"
] |
[] |
Daniel travelled to the garden. Mary went to the kitchen. John travelled to the bedroom. Daniel journeyed to the hallway. Mary moved to the bathroom. John travelled to the garden. Sandra went back to the hallway. Mary travelled to the bedroom.
|
babilong_0k_qa1_sample_43
| 51
| 218
|
|
147
|
Write a function to find the maximum total path sum in the given triangle.
|
def max_path_sum(tri, m, n):
for i in range(m-1, -1, -1):
for j in range(i+1):
if (tri[i+1][j] > tri[i+1][j+1]):
tri[i][j] += tri[i+1][j]
else:
tri[i][j] += tri[i+1][j+1]
return tri[0][0]
|
[
"assert max_path_sum([[1, 0, 0], [4, 8, 0], [1, 5, 3]], 2, 2) == 14",
"assert max_path_sum([[13, 0, 0], [7, 4, 0], [2, 4, 6]], 2, 2) == 24 ",
"assert max_path_sum([[2, 0, 0], [11, 18, 0], [21, 25, 33]], 2, 2) == 53"
] |
[] |
Sandra moved to the hallway. John travelled to the office. Sandra took the milk there. Sandra put down the milk. Mary went to the bedroom. Sandra went back to the kitchen. Mary went to the kitchen. Sandra got the apple there. Sandra dropped the apple. Daniel went back to the office.
|
babilong_0k_qa2_sample_35
| 63
| 219
|
|
433
|
Write a function to check whether the entered number is greater than the elements of the given array.
|
def check_greater(arr, number):
arr.sort()
if number > arr[-1]:
return ('Yes, the entered number is greater than those in the array')
else:
return ('No, entered number is less than those in the array')
|
[
"assert check_greater([1, 2, 3, 4, 5], 4) == 'No, entered number is less than those in the array'",
"assert check_greater([2, 3, 4, 5, 6], 8) == 'Yes, the entered number is greater than those in the array'",
"assert check_greater([9, 7, 4, 8, 6, 1], 11) == 'Yes, the entered number is greater than those in the array'"
] |
[] |
The kitchen is west of the bedroom. The bedroom is west of the office.
|
babilong_0k_qa4_sample_23
| 17
| 220
|
|
16
|
Write a function to find sequences of lowercase letters joined with an underscore.
|
import re
def text_lowercase_underscore(text):
patterns = '^[a-z]+_[a-z]+$'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!')
|
[
"assert text_lowercase_underscore(\"aab_cbbbc\")==('Found a match!')",
"assert text_lowercase_underscore(\"aab_Abbbc\")==('Not matched!')",
"assert text_lowercase_underscore(\"Aaab_abbbc\")==('Not matched!')"
] |
[
"assert text_lowercase_underscore(\"aab-cbbbc\")==('Not matched!')"
] |
Mary journeyed to the garden. John went back to the garden. Mary moved to the office. John moved to the bedroom.
|
babilong_0k_qa1_sample_87
| 27
| 221
|
|
192
|
Write a python function to check whether a string has atleast one letter and one number.
|
def check_String(str):
flag_l = False
flag_n = False
for i in str:
if i.isalpha():
flag_l = True
if i.isdigit():
flag_n = True
return flag_l and flag_n
|
[
"assert check_String('thishasboth29') == True",
"assert check_String('python') == False",
"assert check_String ('string') == False"
] |
[] |
Sandra went back to the bedroom. John moved to the garden. Daniel journeyed to the hallway. Sandra travelled to the hallway.
|
babilong_0k_qa1_sample_50
| 28
| 222
|
|
215
|
Write a function to decode a run-length encoded given list.
|
def decode_list(alist):
def aux(g):
if isinstance(g, list):
return [(g[1], range(g[0]))]
else:
return [(g, [0])]
return [x for g in alist for x, R in aux(g) for i in R]
|
[
"assert decode_list([[2, 1], 2, 3, [2, 4], 5,1])==[1,1,2,3,4,4,5,1]",
"assert decode_list(['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', [2, 'l'], 'y'])==['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', 'l', 'l', 'y']",
"assert decode_list(['p', 'y', 't', 'h', 'o', 'n'])==['p', 'y', 't', 'h', 'o', 'n']"
] |
[] |
Bill went back to the kitchen. Mary got the football there. Fred went to the garden. Fred got the milk there. Mary left the football. Fred got the apple there. Fred travelled to the hallway. Bill went to the hallway. Mary journeyed to the garden. Fred gave the apple to Bill. Bill gave the apple to Fred. Fred left the milk there. Fred got the milk there. Fred gave the apple to Bill. Fred went back to the bedroom. Mary moved to the office. Bill travelled to the bathroom. Mary went to the kitchen.
|
babilong_0k_qa5_sample_35
| 114
| 222
|
|
406
|
Write a python function to find the parity of a given number.
|
def find_Parity(x):
y = x ^ (x >> 1);
y = y ^ (y >> 2);
y = y ^ (y >> 4);
y = y ^ (y >> 8);
y = y ^ (y >> 16);
if (y & 1):
return ("Odd Parity");
return ("Even Parity");
|
[
"assert find_Parity(12) == \"Even Parity\"",
"assert find_Parity(7) == \"Odd Parity\"",
"assert find_Parity(10) == \"Even Parity\""
] |
[] |
Sandra went to the garden. Daniel went to the garden. Sandra journeyed to the kitchen. John journeyed to the hallway.
|
babilong_0k_qa1_sample_30
| 28
| 222
|
|
380
|
Write a function to generate a two-dimensional array.
|
def multi_list(rownum,colnum):
multi_list = [[0 for col in range(colnum)] for row in range(rownum)]
for row in range(rownum):
for col in range(colnum):
multi_list[row][col]= row*col
return multi_list
|
[
"assert multi_list(3,4)==[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6]] ",
"assert multi_list(5,7)==[[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6], [0, 2, 4, 6, 8, 10, 12], [0, 3, 6, 9, 12, 15, 18], [0, 4, 8, 12, 16, 20, 24]]",
"assert multi_list(10,15)==[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28], [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42], [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56], [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70], [0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84], [0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98], [0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112], [0, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126]]"
] |
[] |
John went to the hallway. Mary took the apple. John took the football. Mary dropped the apple. Sandra went to the kitchen. Mary went back to the kitchen. John left the football there. John took the football. Sandra travelled to the garden. John put down the football. John got the football. Mary journeyed to the hallway. Sandra went to the office. Daniel travelled to the kitchen. John dropped the football. John got the football. John discarded the football. Mary went to the bedroom. Daniel moved to the bathroom. Mary went back to the bathroom. John picked up the football. John discarded the football. John got the football. John went to the bedroom. John put down the football there. Daniel journeyed to the kitchen. Sandra went back to the bathroom. Daniel went to the bedroom. Sandra moved to the garden. John went back to the hallway. John travelled to the office. Sandra got the apple. Daniel went to the hallway. Mary journeyed to the hallway. Sandra took the milk. Sandra journeyed to the kitchen. Daniel went back to the office. Sandra put down the apple. Daniel moved to the bedroom. John went to the garden. John travelled to the bathroom. Daniel got the football. Daniel travelled to the office. Daniel discarded the football. Sandra took the apple. Sandra discarded the apple. Daniel journeyed to the garden. John went back to the kitchen. John went back to the office. John went to the bathroom. Sandra discarded the milk. Sandra journeyed to the bedroom. Sandra journeyed to the garden. Mary went to the garden. Sandra travelled to the bathroom. Daniel travelled to the bathroom. Sandra moved to the office. Sandra travelled to the hallway. Sandra moved to the bathroom. Daniel journeyed to the office. Sandra travelled to the office. Sandra journeyed to the garden. John moved to the bedroom. Sandra journeyed to the hallway. Daniel went to the hallway. Daniel went back to the bedroom. Mary travelled to the bathroom. Mary went to the garden. Mary went to the kitchen. Mary got the milk. John travelled to the bathroom. Mary got the apple. Mary journeyed to the office. Sandra journeyed to the bathroom. John went back to the kitchen. Mary put down the milk. Mary journeyed to the garden. Mary went to the hallway. Mary journeyed to the kitchen. Sandra moved to the hallway. Mary moved to the bedroom. Daniel went to the kitchen. Mary left the apple. Daniel journeyed to the bathroom. Mary picked up the apple. Mary journeyed to the garden. John travelled to the hallway. Mary travelled to the hallway. Mary travelled to the bedroom. Sandra moved to the bedroom. Mary discarded the apple. Sandra grabbed the apple. Sandra went back to the bathroom. John journeyed to the office. John picked up the milk. Sandra went back to the kitchen. John journeyed to the kitchen. Mary journeyed to the office. Daniel journeyed to the garden. Daniel went back to the kitchen. Mary went to the hallway. Sandra went back to the bathroom. Sandra dropped the apple there. John journeyed to the office. John took the football. Mary journeyed to the bathroom.
|
babilong_0k_qa3_sample_48
| 650
| 224
|
|
509
|
Write a python function to find the average of odd numbers till a given odd number.
|
def average_Odd(n) :
if (n%2==0) :
return ("Invalid Input")
return -1
sm =0
count =0
while (n>=1) :
count=count+1
sm = sm + n
n = n-2
return sm//count
|
[
"assert average_Odd(9) == 5",
"assert average_Odd(5) == 3",
"assert average_Odd(11) == 6"
] |
[] |
Daniel journeyed to the kitchen. Sandra went back to the bathroom. Mary journeyed to the bathroom. Mary went to the hallway. Sandra went to the office. John moved to the hallway. John travelled to the kitchen. Daniel went back to the hallway. Sandra journeyed to the bedroom. John went back to the bathroom. Daniel moved to the bathroom. John went back to the bedroom. Daniel travelled to the kitchen. Mary travelled to the bedroom. Daniel travelled to the bathroom. Daniel travelled to the kitchen. Mary moved to the bathroom. Sandra went to the kitchen. Daniel travelled to the office. John journeyed to the garden. Daniel travelled to the kitchen. Daniel picked up the apple. Daniel dropped the apple. Mary moved to the garden. Sandra grabbed the apple. Sandra moved to the hallway. John went back to the bedroom. Sandra travelled to the bedroom. John moved to the office. Mary travelled to the bedroom. Sandra moved to the hallway. Sandra journeyed to the office. John travelled to the garden. Sandra discarded the apple there. Daniel grabbed the milk. Daniel travelled to the hallway. Daniel dropped the milk. Daniel took the milk. Daniel journeyed to the kitchen. Sandra got the apple. Daniel journeyed to the bedroom. Sandra moved to the bathroom.
|
babilong_0k_qa3_sample_68
| 259
| 227
|
|
158
|
Write a python function to find k number of operations required to make all elements equal.
|
def min_Ops(arr,n,k):
max1 = max(arr)
res = 0
for i in range(0,n):
if ((max1 - arr[i]) % k != 0):
return -1
else:
res += (max1 - arr[i]) / k
return int(res)
|
[
"assert min_Ops([2,2,2,2],4,3) == 0",
"assert min_Ops([4,2,6,8],4,3) == -1",
"assert min_Ops([21,33,9,45,63],5,6) == 24"
] |
[] |
Daniel went to the office. Mary took the football there. Sandra journeyed to the garden. Sandra went to the bedroom. John took the apple there. John put down the apple. Mary put down the football. John took the apple there. Mary went back to the bedroom. John put down the apple. Mary journeyed to the kitchen. Daniel moved to the garden. Sandra moved to the kitchen. Daniel picked up the milk there. John went to the hallway. John journeyed to the bedroom. Sandra picked up the apple there. Mary travelled to the bedroom. Mary went back to the bathroom. Sandra journeyed to the office. John went back to the kitchen. John moved to the garden. Sandra left the apple. Sandra took the apple there. Sandra put down the apple. John went back to the bathroom. Sandra travelled to the garden. Daniel went to the bathroom.
|
babilong_0k_qa2_sample_24
| 178
| 229
|
|
318
|
Write a python function to find the maximum volume of a cuboid with given sum of sides.
|
def max_volume (s):
maxvalue = 0
i = 1
for i in range(s - 1):
j = 1
for j in range(s):
k = s - i - j
maxvalue = max(maxvalue, i * j * k)
return maxvalue
|
[
"assert max_volume(8) == 18",
"assert max_volume(4) == 2",
"assert max_volume(1) == 0"
] |
[] |
The bathroom is west of the kitchen. The bathroom is east of the garden.
|
babilong_0k_qa4_sample_87
| 17
| 230
|
|
326
|
Write a function to get the word with most number of occurrences in the given strings list.
|
from collections import defaultdict
def most_occurrences(test_list):
temp = defaultdict(int)
for sub in test_list:
for wrd in sub.split():
temp[wrd] += 1
res = max(temp, key=temp.get)
return (str(res))
|
[
"assert most_occurrences([\"UTS is best for RTF\", \"RTF love UTS\", \"UTS is best\"] ) == 'UTS'",
"assert most_occurrences([\"Its been a great year\", \"this year is so worse\", \"this year is okay\"] ) == 'year'",
"assert most_occurrences([\"Families can be reunited\", \"people can be reunited\", \"Tasks can be achieved \"] ) == 'can'"
] |
[] |
John journeyed to the kitchen. Sandra went back to the hallway. Sandra moved to the bathroom. Daniel took the apple. Mary moved to the hallway. Sandra picked up the milk there. Mary went back to the office. Daniel travelled to the bathroom. Sandra went back to the garden. Sandra journeyed to the office. Sandra dropped the milk. Daniel discarded the apple there. John journeyed to the bathroom. Daniel took the apple. Sandra took the milk. Daniel went back to the bedroom. Daniel put down the apple. Sandra picked up the football. John moved to the garden. Mary moved to the garden. Mary moved to the hallway. Daniel picked up the apple there. Daniel put down the apple. John went back to the hallway. John travelled to the bathroom. Daniel journeyed to the bathroom. Sandra dropped the milk there. Sandra got the milk. John went back to the bedroom. John went back to the bathroom. Sandra dropped the milk. Daniel went back to the office. Mary moved to the office. Sandra discarded the football. Mary went to the garden. Daniel went to the garden. Sandra got the football. John went back to the kitchen. Mary moved to the hallway. Sandra put down the football. John went to the garden. Sandra took the milk there. John travelled to the kitchen. Sandra travelled to the hallway. Daniel went to the hallway. Sandra left the milk there. Daniel grabbed the milk. Sandra travelled to the bedroom. Mary moved to the bedroom. Mary took the apple. Daniel left the milk. Mary put down the apple there. Mary went back to the garden. Sandra got the apple. Mary travelled to the kitchen. Daniel took the milk. Daniel put down the milk there. Sandra went back to the kitchen. Daniel went back to the garden. Sandra dropped the apple. John moved to the bathroom. Mary got the apple. Daniel moved to the hallway. Daniel journeyed to the garden. Mary travelled to the hallway. Mary picked up the milk. Mary journeyed to the bedroom. Sandra moved to the garden. John travelled to the garden. Mary discarded the apple. John travelled to the office. Mary took the apple. Mary dropped the apple. Sandra went back to the kitchen. Mary grabbed the apple. Sandra journeyed to the bedroom. Daniel journeyed to the kitchen. Mary moved to the garden. John took the football. John discarded the football. Mary travelled to the hallway. Sandra went to the office. Mary moved to the bedroom. John picked up the football. Sandra moved to the bedroom. Sandra moved to the hallway. John travelled to the kitchen. Mary went back to the kitchen. Sandra went back to the bathroom. Sandra travelled to the office. Daniel went back to the bathroom. John dropped the football there. Mary travelled to the garden. Sandra journeyed to the kitchen. John got the football. Sandra moved to the garden. Daniel went to the garden. John left the football. Mary left the milk. Daniel moved to the kitchen.
|
babilong_0k_qa3_sample_77
| 606
| 230
|
|
280
|
Write a function to search an element in the given array by using sequential search.
|
def sequential_search(dlist, item):
pos = 0
found = False
while pos < len(dlist) and not found:
if dlist[pos] == item:
found = True
else:
pos = pos + 1
return found, pos
|
[
"assert sequential_search([11,23,58,31,56,77,43,12,65,19],31) == (True, 3)",
"assert sequential_search([12, 32, 45, 62, 35, 47, 44, 61],61) == (True, 7)",
"assert sequential_search([9, 10, 17, 19, 22, 39, 48, 56],48) == (True, 6)"
] |
[] |
Jeff travelled to the garden. Jeff journeyed to the bedroom. Fred journeyed to the office. Bill went back to the office. Mary travelled to the hallway. Fred journeyed to the garden. Fred moved to the hallway. Bill moved to the hallway. Fred went back to the office. Jeff travelled to the bathroom. Mary took the apple there. Fred went back to the hallway. Mary handed the apple to Fred. Mary went back to the kitchen. Fred gave the apple to Bill. Fred took the milk there.
|
babilong_0k_qa5_sample_51
| 106
| 233
|
|
165
|
Write a python function to count characters at same position in a given string (lower and uppercase characters) as in english alphabet.
|
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"
] |
[] |
Daniel picked up the apple there. Daniel dropped the apple. John moved to the bedroom. John grabbed the apple there. Daniel went to the hallway. Sandra grabbed the football there. Sandra went back to the kitchen. John left the apple.
|
babilong_0k_qa2_sample_27
| 49
| 234
|
|
320
|
Write a function to calculate the difference between the squared sum of first n natural numbers and the sum of squared first n natural numbers.
|
def sum_difference(n):
sumofsquares = 0
squareofsum = 0
for num in range(1, n+1):
sumofsquares += num * num
squareofsum += num
squareofsum = squareofsum ** 2
return squareofsum - sumofsquares
|
[
"assert sum_difference(12)==5434",
"assert sum_difference(20)==41230",
"assert sum_difference(54)==2151270"
] |
[] |
Mary grabbed the football there. Sandra travelled to the office. Sandra picked up the apple there. Sandra journeyed to the bedroom. Sandra journeyed to the kitchen. Mary travelled to the garden. John moved to the bathroom. Daniel went to the bathroom. Mary left the football. Daniel took the milk there.
|
babilong_0k_qa2_sample_25
| 63
| 234
|
|
134
|
Write a python function to check whether the last element of given array is even or odd after performing an operation p times.
|
def check_last (arr,n,p):
_sum = 0
for i in range(n):
_sum = _sum + arr[i]
if p == 1:
if _sum % 2 == 0:
return "ODD"
else:
return "EVEN"
return "EVEN"
|
[
"assert check_last([5,7,10],3,1) == \"ODD\"",
"assert check_last([2,3],2,3) == \"EVEN\"",
"assert check_last([1,2,3],3,1) == \"ODD\""
] |
[] |
The bathroom is south of the garden. The bedroom is north of the garden.
|
babilong_0k_qa4_sample_95
| 17
| 237
|
|
314
|
Write a function to find out the maximum sum such that no two chosen numbers are adjacent for the given rectangular grid of dimension 2 x n.
|
def max_sum_rectangular_grid(grid, n) :
incl = max(grid[0][0], grid[1][0])
excl = 0
for i in range(1, n) :
excl_new = max(excl, incl)
incl = excl + max(grid[0][i], grid[1][i])
excl = excl_new
return max(excl, incl)
|
[
"assert max_sum_rectangular_grid([ [1, 4, 5], [2, 0, 0 ] ], 3) == 7",
"assert max_sum_rectangular_grid([ [ 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10] ], 5) == 24",
"assert max_sum_rectangular_grid([ [7, 9, 11, 15, 19], [21, 25, 28, 31, 32] ], 5) == 81"
] |
[] |
Daniel went to the bedroom. Sandra moved to the bedroom. Daniel went to the garden. Mary moved to the hallway. John moved to the bedroom. Mary travelled to the kitchen. Daniel grabbed the milk there. Daniel discarded the milk. Daniel moved to the bedroom. Daniel journeyed to the garden. Daniel went back to the bedroom. John moved to the hallway. John got the football there. John went back to the kitchen.
|
babilong_0k_qa2_sample_79
| 87
| 237
|
|
480
|
Write a python function to find the maximum occurring character in a given string.
|
def get_max_occuring_char(str1):
ASCII_SIZE = 256
ctr = [0] * ASCII_SIZE
max = -1
ch = ''
for i in str1:
ctr[ord(i)]+=1;
for i in str1:
if max < ctr[ord(i)]:
max = ctr[ord(i)]
ch = i
return ch
|
[
"assert get_max_occuring_char(\"data\") == \"a\"",
"assert get_max_occuring_char(\"create\") == \"e\"",
"assert get_max_occuring_char(\"brilliant girl\") == \"i\""
] |
[] |
Daniel got the apple there. Daniel dropped the apple. Mary moved to the bedroom. Daniel journeyed to the hallway. Mary travelled to the hallway. Sandra moved to the bedroom. Mary went back to the bathroom. Daniel moved to the kitchen. Mary went to the kitchen. Daniel moved to the office. Mary picked up the football there. Mary put down the football. John travelled to the office. Daniel went to the bathroom. Mary got the football there. Mary discarded the football.
|
babilong_0k_qa2_sample_13
| 98
| 237
|
|
348
|
Write a function to count sequences of given length having non-negative prefix sums that can be generated by given values.
|
def bin_coff(n, r):
val = 1
if (r > (n - r)):
r = (n - r)
for i in range(0, r):
val *= (n - i)
val //= (i + 1)
return val
def find_ways(M):
n = M // 2
a = bin_coff(2 * n, n)
b = a // (n + 1)
return (b)
|
[
"assert find_ways(4) == 2",
"assert find_ways(6) == 5",
"assert find_ways(8) == 14"
] |
[] |
Jeff grabbed the football there. Jeff handed the football to Fred. Fred passed the football to Jeff. Jeff handed the football to Fred. Fred handed the football to Jeff. Jeff gave the football to Fred.
|
babilong_0k_qa5_sample_25
| 42
| 238
|
|
448
|
Write a function to calculate the sum of perrin numbers.
|
def cal_sum(n):
a = 3
b = 0
c = 2
if (n == 0):
return 3
if (n == 1):
return 3
if (n == 2):
return 5
sum = 5
while (n > 2):
d = a + b
sum = sum + d
a = b
b = c
c = d
n = n-1
return sum
|
[
"assert cal_sum(9) == 49",
"assert cal_sum(10) == 66",
"assert cal_sum(11) == 88"
] |
[] |
Mary went to the kitchen. John went back to the kitchen. Daniel went back to the hallway. Daniel went to the bathroom. Sandra travelled to the bathroom. Sandra travelled to the bedroom. Daniel went to the kitchen. Daniel moved to the office.
|
babilong_0k_qa1_sample_10
| 51
| 238
|
|
317
|
Write a function to reflect the modified run-length encoding from a list.
|
from itertools import groupby
def modified_encode(alist):
def ctr_ele(el):
if len(el)>1: return [len(el), el[0]]
else: return el[0]
return [ctr_ele(list(group)) for key, group in groupby(alist)]
|
[
"assert modified_encode([1,1,2,3,4,4,5,1])==[[2, 1], 2, 3, [2, 4], 5, 1]",
"assert modified_encode('automatically')==['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', [2, 'l'], 'y']",
"assert modified_encode('python')==['p', 'y', 't', 'h', 'o', 'n']"
] |
[] |
Sandra travelled to the kitchen. Daniel travelled to the bathroom. John went to the hallway. Sandra journeyed to the bedroom.
|
babilong_0k_qa1_sample_83
| 27
| 239
|
|
392
|
Write a function to find the maximum sum possible by using the given equation f(n) = max( (f(n/2) + f(n/3) + f(n/4) + f(n/5)), n).
|
def get_max_sum (n):
res = list()
res.append(0)
res.append(1)
i = 2
while i<n + 1:
res.append(max(i, (res[int(i / 2)]
+ res[int(i / 3)] +
res[int(i / 4)]
+ res[int(i / 5)])))
i = i + 1
return res[n]
|
[
"assert get_max_sum(60) == 106",
"assert get_max_sum(10) == 12",
"assert get_max_sum(2) == 2"
] |
[] |
John got the milk. Mary got the football. Mary took the apple. Mary put down the football. Mary left the apple. Sandra moved to the bedroom. John moved to the bathroom. Mary got the football. Mary moved to the bathroom. John went to the office. Mary went back to the office. Mary got the apple.
|
babilong_0k_qa3_sample_49
| 68
| 239
|
|
481
|
Write a function to determine if there is a subset of the given set with sum equal to the given sum.
|
def is_subset_sum(set, n, sum):
if (sum == 0):
return True
if (n == 0):
return False
if (set[n - 1] > sum):
return is_subset_sum(set, n - 1, sum)
return is_subset_sum(set, n-1, sum) or is_subset_sum(set, n-1, sum-set[n-1])
|
[
"assert is_subset_sum([3, 34, 4, 12, 5, 2], 6, 9) == True",
"assert is_subset_sum([3, 34, 4, 12, 5, 2], 6, 30) == False",
"assert is_subset_sum([3, 34, 4, 12, 5, 2], 6, 15) == True"
] |
[] |
Jeff travelled to the garden. Mary went to the garden. Mary journeyed to the kitchen. Fred picked up the milk there. Bill grabbed the football there. Mary travelled to the garden. Mary travelled to the kitchen. Jeff went to the bathroom. Bill handed the football to Mary. Jeff went to the garden.
|
babilong_0k_qa5_sample_86
| 64
| 239
|
|
489
|
Write a python function to find the frequency of the largest value in a given array.
|
def frequency_Of_Largest(n,arr):
mn = arr[0]
freq = 1
for i in range(1,n):
if (arr[i] >mn):
mn = arr[i]
freq = 1
elif (arr[i] == mn):
freq += 1
return freq
|
[
"assert frequency_Of_Largest(5,[1,2,3,4,4]) == 2",
"assert frequency_Of_Largest(3,[5,6,5]) == 1",
"assert frequency_Of_Largest(4,[2,7,7,7]) == 3"
] |
[] |
John went to the garden. John travelled to the bedroom. John took the milk there. Daniel moved to the garden. Sandra went to the hallway. John grabbed the football there. John left the football. John discarded the milk. Sandra got the apple there. Mary moved to the hallway.
|
babilong_0k_qa2_sample_68
| 59
| 239
|
|
219
|
Write a function to extract maximum and minimum k elements in the given tuple.
|
def extract_min_max(test_tup, K):
res = []
test_tup = list(test_tup)
temp = sorted(test_tup)
for idx, val in enumerate(temp):
if idx < K or idx >= len(temp) - K:
res.append(val)
res = tuple(res)
return (res)
|
[
"assert extract_min_max((5, 20, 3, 7, 6, 8), 2) == (3, 5, 8, 20)",
"assert extract_min_max((4, 5, 6, 1, 2, 7), 3) == (1, 2, 4, 5, 6, 7)",
"assert extract_min_max((2, 3, 4, 8, 9, 11, 7), 4) == (2, 3, 4, 7, 8, 9, 11)"
] |
[] |
Jeff grabbed the milk there. Mary moved to the office. Bill journeyed to the hallway. Fred journeyed to the kitchen. Jeff put down the milk. Jeff took the milk there. Bill went to the kitchen. Jeff left the milk. Mary journeyed to the bedroom. Mary took the apple there. Mary dropped the apple. Fred moved to the hallway. Fred moved to the bathroom. Fred picked up the football there. Bill travelled to the garden. Jeff journeyed to the bathroom. Fred handed the football to Jeff. Bill took the milk there. Jeff gave the football to Fred. Fred passed the football to Jeff. Jeff handed the football to Fred. Fred travelled to the bedroom. Bill went back to the hallway. Fred dropped the football. Fred went back to the bathroom. Bill put down the milk. Mary picked up the apple there. Mary put down the apple. Mary moved to the bathroom. Bill picked up the milk there. Mary journeyed to the hallway. Bill gave the milk to Mary.
|
babilong_0k_qa5_sample_54
| 205
| 240
|
|
383
|
Write a python function to toggle all odd bits of a given number.
|
def even_bit_toggle_number(n) :
res = 0; count = 0; temp = n
while(temp > 0 ) :
if (count % 2 == 0) :
res = res | (1 << count)
count = count + 1
temp >>= 1
return n ^ res
|
[
"assert even_bit_toggle_number(10) == 15",
"assert even_bit_toggle_number(20) == 1",
"assert even_bit_toggle_number(30) == 11"
] |
[] |
Sandra went back to the hallway. John travelled to the kitchen. John grabbed the apple. Daniel travelled to the hallway. John dropped the apple. Daniel went to the kitchen. John travelled to the office. Mary took the milk. Sandra journeyed to the kitchen. Mary discarded the milk. Daniel grabbed the apple. Daniel dropped the apple there. Daniel moved to the garden. Sandra went back to the bathroom. Daniel picked up the football. Mary travelled to the office. Sandra went to the garden. John went back to the garden. John travelled to the kitchen. Sandra went to the bathroom. Mary travelled to the bathroom. Daniel dropped the football there. Daniel picked up the football. Sandra got the milk. John got the apple. John moved to the hallway. Daniel discarded the football. Daniel grabbed the football. Daniel discarded the football. Daniel took the football. Mary moved to the hallway. Daniel moved to the office. Sandra travelled to the office. Sandra left the milk. John went back to the kitchen. Mary went back to the bedroom. Mary went back to the kitchen. Daniel travelled to the hallway. Sandra got the milk. Daniel discarded the football. Daniel picked up the football. Sandra moved to the bathroom. John dropped the apple. John got the apple. John journeyed to the hallway. Mary went back to the hallway. Sandra journeyed to the kitchen. John travelled to the garden. Sandra left the milk. Daniel travelled to the office. John went to the bathroom. Sandra picked up the milk. John moved to the bedroom. Sandra journeyed to the bedroom. John journeyed to the kitchen. Daniel discarded the football. Daniel went to the hallway. John moved to the bathroom. Mary travelled to the bathroom. Sandra discarded the milk there. Mary went to the hallway. Sandra went to the bathroom. Daniel travelled to the bathroom. John left the apple. Sandra took the apple there. John travelled to the bedroom. Sandra put down the apple there. John journeyed to the garden. Sandra got the apple. Mary went to the office. Daniel travelled to the bedroom. Daniel journeyed to the bathroom. Daniel went back to the garden. Sandra discarded the apple there. Sandra took the apple. Mary moved to the hallway. John went to the bedroom. John went to the hallway. Sandra went back to the kitchen. Sandra put down the apple. Daniel travelled to the bedroom. Daniel took the milk. Sandra travelled to the bathroom. John journeyed to the office. Sandra travelled to the garden. Mary moved to the kitchen. Daniel travelled to the hallway. Mary took the apple. Sandra went back to the hallway. Sandra journeyed to the garden. John picked up the football there. John put down the football. John travelled to the garden. Sandra went to the kitchen. Sandra journeyed to the garden. Mary journeyed to the garden. Sandra journeyed to the bathroom. Sandra went to the office. Daniel discarded the milk. Sandra took the football. Daniel got the milk. Sandra went to the garden. Sandra left the football. Mary left the apple. Daniel went back to the office. Daniel discarded the milk. Sandra went back to the kitchen. Mary travelled to the hallway. Daniel grabbed the milk there. Daniel put down the milk. Sandra went to the bathroom. John took the apple. John put down the apple. Daniel journeyed to the kitchen. John picked up the apple there. John put down the apple. Mary went back to the kitchen. John went back to the office. John travelled to the bedroom. Mary journeyed to the hallway. Mary went to the garden. Daniel journeyed to the bathroom. John moved to the bathroom. Mary grabbed the football. Sandra journeyed to the hallway. Mary dropped the football. Sandra travelled to the bedroom. Sandra travelled to the bathroom. Sandra went to the kitchen. Daniel moved to the bedroom. Sandra travelled to the bedroom. Mary picked up the football. Mary dropped the football there. Sandra went to the garden. Mary journeyed to the kitchen. Sandra got the apple. Daniel travelled to the garden. Sandra went back to the bathroom. Daniel picked up the football. Daniel went back to the kitchen. Daniel discarded the football. Daniel took the football. Sandra left the apple there. Daniel left the football. John got the apple there. Daniel journeyed to the garden. John went back to the garden. John travelled to the bathroom.
|
babilong_0k_qa3_sample_6
| 892
| 240
|
|
155
|
Write a python function to toggle all even bits of a given number.
|
def even_bit_toggle_number(n) :
res = 0; count = 0; temp = n
while (temp > 0) :
if (count % 2 == 1) :
res = res | (1 << count)
count = count + 1
temp >>= 1
return n ^ res
|
[
"assert even_bit_toggle_number(10) == 0",
"assert even_bit_toggle_number(20) == 30",
"assert even_bit_toggle_number(30) == 20"
] |
[] |
Mary took the milk there. Mary went back to the garden. Fred went to the office. Bill went back to the garden. Bill went back to the hallway. Fred went to the garden. Fred journeyed to the office. Bill went to the garden. Mary gave the milk to Bill. Bill gave the milk to Mary.
|
babilong_0k_qa5_sample_85
| 67
| 241
|
|
384
|
Write a python function to find the frequency of the smallest value in a given array.
|
def frequency_Of_Smallest(n,arr):
mn = arr[0]
freq = 1
for i in range(1,n):
if (arr[i] < mn):
mn = arr[i]
freq = 1
elif (arr[i] == mn):
freq += 1
return freq
|
[
"assert frequency_Of_Smallest(5,[1,2,3,4,3]) == 1",
"assert frequency_Of_Smallest(7,[3,1,2,5,6,2,3]) == 1",
"assert frequency_Of_Smallest(7,[3,3,6,3,7,4,9]) == 3"
] |
[] |
The bedroom is south of the hallway. The bathroom is north of the hallway.
|
babilong_0k_qa4_sample_33
| 17
| 241
|
|
486
|
Write a function to compute binomial probability for the given number.
|
def nCr(n, r):
if (r > n / 2):
r = n - r
answer = 1
for i in range(1, r + 1):
answer *= (n - r + i)
answer /= i
return answer
def binomial_probability(n, k, p):
return (nCr(n, k) * pow(p, k) * pow(1 - p, n - k))
|
[
"assert binomial_probability(10, 5, 1.0/3) == 0.13656454808718185",
"assert binomial_probability(11, 6, 2.0/4) == 0.2255859375",
"assert binomial_probability(12, 7, 3.0/5) == 0.227030335488"
] |
[] |
Daniel journeyed to the office. Sandra travelled to the bedroom. Daniel grabbed the football. Daniel discarded the football. Daniel grabbed the football. Daniel went back to the bathroom. Daniel discarded the football. John went to the hallway. Sandra travelled to the garden. Mary got the football there. John travelled to the kitchen. Sandra moved to the bedroom. Daniel went back to the bedroom. John took the apple. Daniel moved to the bathroom. Sandra journeyed to the bathroom. Mary went to the bedroom. Mary journeyed to the hallway. John picked up the milk. John went back to the garden. Mary dropped the football. Mary grabbed the football. Mary dropped the football. John moved to the hallway. John put down the milk. John left the apple. Mary got the apple. John picked up the milk. John moved to the office. John put down the milk. Daniel journeyed to the garden. John grabbed the milk there. Mary dropped the apple. John travelled to the hallway. Mary went back to the office. Sandra went back to the office. John went back to the bathroom. Daniel travelled to the bedroom. John went to the hallway. John grabbed the apple. John dropped the apple. Daniel journeyed to the kitchen. John left the milk. Sandra went to the garden. Daniel moved to the hallway. Daniel grabbed the apple. John grabbed the football. Daniel picked up the milk. John left the football there. Mary journeyed to the kitchen. Daniel went back to the bedroom. Sandra moved to the bedroom. John got the football. Mary journeyed to the garden. Mary went back to the bathroom. Daniel discarded the milk. Sandra picked up the milk. John went back to the office. Daniel dropped the apple. Sandra grabbed the apple. Daniel journeyed to the office. Mary travelled to the garden. John left the football. Sandra went to the garden. Sandra journeyed to the kitchen. John grabbed the football. Mary moved to the bathroom. Mary journeyed to the garden. Sandra journeyed to the garden. John journeyed to the hallway. John moved to the garden. Sandra travelled to the kitchen. Sandra went back to the office. John went to the kitchen. Sandra left the milk there. Daniel journeyed to the hallway.
|
babilong_0k_qa3_sample_89
| 458
| 241
|
|
22
|
Write a function to find the first duplicate element in a given array of integers.
|
def find_first_duplicate(nums):
num_set = set()
no_duplicate = -1
for i in range(len(nums)):
if nums[i] in num_set:
return nums[i]
else:
num_set.add(nums[i])
return no_duplicate
|
[
"assert find_first_duplicate(([1, 2, 3, 4, 4, 5]))==4",
"assert find_first_duplicate([1, 2, 3, 4])==-1",
"assert find_first_duplicate([1, 1, 2, 3, 3, 2, 2])==1"
] |
[] |
The hallway is east of the garden. The kitchen is east of the hallway.
|
babilong_0k_qa4_sample_86
| 17
| 247
|
|
256
|
Write a python function to count the number of prime numbers less than a given non-negative number.
|
def count_Primes_nums(n):
ctr = 0
for num in range(n):
if num <= 1:
continue
for i in range(2,num):
if (num % i) == 0:
break
else:
ctr += 1
return ctr
|
[
"assert count_Primes_nums(5) == 2",
"assert count_Primes_nums(10) == 4",
"assert count_Primes_nums(100) == 25"
] |
[] |
Mary picked up the football there. Mary dropped the football. Sandra journeyed to the hallway. Mary moved to the bathroom. Daniel travelled to the kitchen. Sandra journeyed to the bedroom. Daniel went back to the office. Sandra picked up the apple there. John moved to the garden. Sandra moved to the kitchen.
|
babilong_0k_qa2_sample_81
| 65
| 248
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.