file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f3707.py
|
def f(score1, score2):
if score1+score2 == 0:
return 0
else:
return (2*score1*score2) / (score1+score2)
assert f(0, 0) == 0
|
benchmark_functions_edited/f13778.py
|
def f(tag_name, tags_stack):
i = len(tags_stack) - 1
for item in reversed(tags_stack):
if tag_name == item[0]:
return i
i -= 1
return -1
assert f('i', [
['b', 'This is a test'],
['i', 'This is not a test'],
['p', 'This is not a test'],
]
) == 1
|
benchmark_functions_edited/f8057.py
|
def f(state):
node = state
for key in ("layers", "index"):
node = node.get(key, {})
indices = [key for key in node.keys()]
if len(indices) == 0:
return 0
else:
return max(indices) + 1
assert f(
{"index": {}}
) == 0
|
benchmark_functions_edited/f6899.py
|
def f(word, document, documents):
count = 0
for string in documents[document]:
if(word == string):
count += 1
return count
assert f("word", "otherdocument", {"document": ["word", "word", "word"], "otherdocument": ["word", "word", "word"]}) == 3
|
benchmark_functions_edited/f11592.py
|
def f(ar_prog):
# The sum of terms of arithmetic progression is:
# S = n*(a1 + an)/2
# where in our case since 1 item is missing n = len(ar_prog) +1
sum_complete = (len(ar_prog) + 1)*(ar_prog[0] + ar_prog[-1])/2
sum_current = sum(ar_prog)
return sum_complete - sum_current
assert f( [1, 3, 4] ) == 2
|
benchmark_functions_edited/f5963.py
|
def f(text, index):
last_cr = text.rfind("\n", 0, index)
if last_cr < 0:
last_cr = 0
column = (index - last_cr) + 1
return column
assert f(
"hello world",
6
) == 7
|
benchmark_functions_edited/f5307.py
|
def f(values):
n = len(values)
is_odd = n % 2
middle_idx = int((n + is_odd) / 2) - 1
return sorted(values)[middle_idx]
assert f([2]) == 2
|
benchmark_functions_edited/f6408.py
|
def f(node):
if node is None:
return 0
else:
return node.height
assert f(None) == 0
|
benchmark_functions_edited/f3439.py
|
def f(numbers):
the_sum = 0
for number in numbers:
the_sum += int(number)
return the_sum
assert f(["1", "2", "3"]) == 6
|
benchmark_functions_edited/f11379.py
|
def f(l):
first_even_n = 0
for num in l:
if num % 2 == 0:
first_even_n = num
break
if first_even_n == 0:
raise ValueError("l doesn't contain an even number")
else:
return first_even_n
assert f( [2, 3, 5] ) == 2
|
benchmark_functions_edited/f1891.py
|
def f(p_string):
return int(p_string.split('-')[0][1:])
assert f(
'D2-1600K') == 2
|
benchmark_functions_edited/f3869.py
|
def f(row):
if row == 1:
return 1
else:
return int(row - 1 + f(row-1))
assert f(2) == 2
|
benchmark_functions_edited/f5728.py
|
def f(skel):
if skel:
nBones = skel.getBoneCount()
return (2*nBones + 1)
else:
return 0
assert f(None) == 0
|
benchmark_functions_edited/f10806.py
|
def f(day):
if day < 11:
dekad = 1
elif day > 10 and day < 21:
dekad = 2
else:
dekad = 3
return dekad
assert f(30) == 3
|
benchmark_functions_edited/f14018.py
|
def f(a, m):
a = a % m
symbol = 1
while a != 0:
while a & 1 == 0:
a >>= 1
if m & 7 == 3 or m & 7 == 5:
symbol = -symbol
a, m = m, a
if a & 3 == 3 and m & 3 == 3:
symbol = -symbol
a = a % m
if m == 1:
return symbol
return 0
assert f(10, 1009) == 1
|
benchmark_functions_edited/f12945.py
|
def f(nums, target):
low = 0
high = len(nums)
while low < high:
mid = (low + high) // 2
if nums[mid] < target:
low = mid + 1
else:
high = mid
assert low == high
if low == len(nums) or nums[low] != target:
return -1
return low
assert f(
[1, 2, 3, 4, 5],
5) == 4
|
benchmark_functions_edited/f4701.py
|
def f(x, foo=None):
if foo is None:
return x
return foo(x)
assert f(1) == 1
|
benchmark_functions_edited/f9219.py
|
def f(mel):
return 700 * (10 ** (mel / 2595.0) - 1)
assert f(0) == 0
|
benchmark_functions_edited/f12601.py
|
def f(x_data, y_data):
area = 0
for i in range(len(x_data)-1):
a_x = x_data[i]
a_y = y_data[i]
b_x = x_data[i+1]
b_y = y_data[i+1]
area += (b_x - a_x) * 0.5 * (b_y + a_y)
return area
assert f(
[-1, 0, 1, 2, 3],
[2, 1, 0, -1, -2]
) == 0
|
benchmark_functions_edited/f10928.py
|
def f(lst, search_item) -> int:
for idx, item in enumerate(lst):
if item == search_item:
return idx
return -1
assert f(["Hello", "world"], "world") == 1
|
benchmark_functions_edited/f1422.py
|
def f(number):
return int(int((number) > 0) - int((number) < 0))
assert f(12345) == 1
|
benchmark_functions_edited/f3472.py
|
def f(number):
accumulator = 1
for n in range(1, number + 1):
accumulator *= n
return accumulator
assert f(1) == 1
|
benchmark_functions_edited/f14166.py
|
def f(a, b):
if a == b or b == 0:
return a
if a == 0:
return b
if not a & 1:
if not b & 1:
return f(a >> 1, b >> 1) << 1
else:
return f(a >> 1, b)
if not b & 1:
return f(a, b >> 1)
if a > b:
return f((a - b) >> 1, b)
return f((b - a) >> 1, a)
assert f(31, 15) == 1
|
benchmark_functions_edited/f750.py
|
def f(x, a, b):
return (x >= a) * (x <= b)
assert f(2, 3, 8) == 0
|
benchmark_functions_edited/f12108.py
|
def f(x, n):
a, b = n, x
ta, tb = 0, 1
while b != 0:
q = a / b
a, b = b, a % b
ta, tb = tb, ta - (q * tb)
if ta < 0:
ta += n
return ta
assert f(1, 2) == 1
|
benchmark_functions_edited/f4322.py
|
def f(bytes):
return int.from_bytes(bytes, byteorder='little', signed=True)
assert f(b'\x01\x00') == 1
|
benchmark_functions_edited/f7935.py
|
def f(json_data, key):
if key in json_data:
return json_data[key]
return None
assert f(
{"a": 1, "b": 2}, "a"
) == 1
|
benchmark_functions_edited/f3750.py
|
def f(request):
awt = 0 #request.user.HelplineUser.get_average_wait_time()
return awt
assert f(None) == 0
|
benchmark_functions_edited/f2119.py
|
def f(a, b, s):
(a1, a2), (b1, b2) = a, b
return b1 + ((s - a1) * (b2 - b1) / (a2 - a1))
assert f(
(1, 2),
(3, 4),
2
) == 4
|
benchmark_functions_edited/f10673.py
|
def f(set_one: list, set_two: list) -> int:
return len(set(set_one)) * len(set(set_two))
assert f(set(['a', 'b', 'c']), set([])) == 0
|
benchmark_functions_edited/f11296.py
|
def f(metrics):
avg = 0
valid_count = 0
for class_name in metrics.keys():
if metrics[class_name] is not None:
avg += metrics[class_name]
valid_count += 1
if valid_count > 0:
return avg / valid_count
else:
return None
assert f(
{'dog': 5, 'cat': 5, 'rabbit': 5}) == 5
|
benchmark_functions_edited/f6079.py
|
def f(x):
if 1 <= x <= 10:
return 2
if 11 <= x <= 100:
return 1
return 0
assert f(12) == 1
|
benchmark_functions_edited/f13260.py
|
def f(strand):
conversion = {'forward': 1, 'unstranded': 0.5, 'reverse': 0}
return conversion[strand]
assert f('reverse') == 0
|
benchmark_functions_edited/f13364.py
|
def f(word1, word2):
max_overlap = min(len(word1), len(word2))
max_found = 0
for size in range(1, max_overlap+1):
suffix = word1[-size:]
prefix = word2[:size]
if suffix == prefix:
max_found = size
return max_found
assert f( 'abc', 'abc' ) == 3
|
benchmark_functions_edited/f12650.py
|
def f(p, n, r={}):
q = r.get(n, None)
if q:
return q
else:
if n == 0:
return 0
else:
q = 0
for i in range(n):
q = max(q, p[i] + f(p, n - (i + 1), r))
r[n] = q
return q
assert f(
[0, 1, 5, 8, 9, 10, 17, 17, 20, 24, 30], 4) == 8
|
benchmark_functions_edited/f3866.py
|
def f(level, expertise=False):
return (((level - 1) / 4) + 2) * (1, 2)[expertise]
assert f(5) == 3
|
benchmark_functions_edited/f9559.py
|
def f(a, b, n):
d = 1
b = bin(b)[2:][::-1]
print("Binary representation of b: ", b)
lens = len(b)
for i in b:
d = (d * d) % n
if i == '1':
d = (d * a) % n
return d
assert f(100, 3, 100) == 0
|
benchmark_functions_edited/f3736.py
|
def f(arr):
score = 0
for i, val in enumerate(arr):
score += 1 if i == val else 0
return score
assert f([9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 0
|
benchmark_functions_edited/f13801.py
|
def f(nums):
if nums == None:
return 0
if len(nums) == 0:
return 0
dp = [0 for i in range(len(nums))]
dp[0] = nums[0]
for i in range(1,len(nums)):
dp[i] = max(dp[i-1]+nums[i],nums[i])
#print(dp)
return max(dp)
assert f([5]) == 5
|
benchmark_functions_edited/f12598.py
|
def f(scanner_height: int, time_step: int) -> int:
cycle_midpoint = scanner_height - 1
full_cycle = cycle_midpoint * 2
cycle_position = time_step % full_cycle
return (
cycle_position
if cycle_position <= cycle_midpoint
else full_cycle - cycle_position)
assert f(2, 19) == 1
|
benchmark_functions_edited/f12467.py
|
def f(pad, in_siz, out_siz, stride, ksize):
if pad == 'SAME':
return (out_siz - 1) * stride + ksize - in_siz
elif pad == 'VALID':
return 0
else:
return pad
assert f(0, 3, 4, 1, 1) == 0
|
benchmark_functions_edited/f5318.py
|
def f(row):
try:
rowset = set(row)
rowset.discard("")
return len(rowset)
except TypeError:
return 0
assert f([1]) == 1
|
benchmark_functions_edited/f9413.py
|
def f(object):
if not hasattr(object, '__doc__'):
raise Exception()
if object.__doc__ is None:
return 0
return int(object.__doc__.strip() != "")
assert f(None) == 0
|
benchmark_functions_edited/f4015.py
|
def f(list_numbers):
to_return = 1
for nb in list_numbers:
to_return *= nb
return to_return
assert f(
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1
|
benchmark_functions_edited/f10315.py
|
def f(list):
sorted = 1;
for index in range(0, len(list)-1):
if list[index] > list[index+1]:
sorted = 0;
return sorted;
assert f([1, 1, 1]) == 1
|
benchmark_functions_edited/f12985.py
|
def f(distribution_artefacts):
return sum([len(distribution_artefacts[tenant].keys()) for tenant in distribution_artefacts.keys()])
assert f(
{
"tenant1": {
"mediapackage1": "mp1_tenant1",
"mediapackage2": "mp2_tenant1",
"mediapackage3": "mp3_tenant1"
},
"tenant2": {
"mediapackage4": "mp4_tenant2",
"mediapackage5": "mp5_tenant2"
},
"tenant3": {
"mediapackage6": "mp6_tenant3",
"mediapackage7": "mp7_tenant3"
}
}
) == 7
|
benchmark_functions_edited/f5402.py
|
def f(bb):
width = bb[1][0] - bb[0][0]
depth = bb[1][1] - bb[0][1]
height = bb[1][2] - bb[0][2]
return width * depth * height
assert f( ((0,0,10),(10,10,10)) ) == 0
|
benchmark_functions_edited/f9684.py
|
def f(adj_l, path):
min_flow = float('inf')
for i in range(len(path) - 1):
curr = path[i]
next = path[i + 1]
min_flow = min(min_flow, adj_l[curr][next])
assert min_flow > 0, f"{min_flow}\n{path}\n{adj_l}"
return min_flow
assert f(
[[0, 3, 5, 0],
[0, 0, 2, 0],
[0, 0, 0, 2],
[0, 0, 0, 0]],
[0, 1, 2, 3]
) == 2
|
benchmark_functions_edited/f14040.py
|
def f(array: list)-> int:
l,r = 0, len(array)-1
while l<=r:
m = (l+r)//2
print(f'status: l: {l}, r: {r}, m: {m}, array_m: {array[m]}')
if array[m] == m: return m
if array[m] < m:
l = max(m+1, array[m])
else:
r = min(m-1, array[m])
raise KeyError('Not found')
assert f([0, 0]) == 0
|
benchmark_functions_edited/f9358.py
|
def f(txt):
# Medium annotation
if txt[-1] == "K":
output = int(float(txt[:-1]) * 1000)
return output
else:
return int(txt)
assert f( "0K" ) == 0
|
benchmark_functions_edited/f11855.py
|
def f(p_test, p_control):
dop = p_control - p_test
return dop
assert f(0.25, 0.25) == 0
|
benchmark_functions_edited/f7151.py
|
def f(x,y):
ccard_x = int(x['serverId'].split('/')[0])
ccard_y = int(y['serverId'].split('/')[0])
return ccard_x - ccard_y
assert f({'serverId': '1/2'}, {'serverId': '1/2'}) == 0
|
benchmark_functions_edited/f10715.py
|
def f(L, p):
if len(L)>0:
return L[int(len(L) * p)]
else:
return 0
assert f( [], 0.6) == 0
|
benchmark_functions_edited/f14359.py
|
def f(x, minimum, maximum) -> float:
if x == maximum:
return 1
return (x - minimum) / (maximum - minimum)
assert f(0, 0, 10) == 0
|
benchmark_functions_edited/f2563.py
|
def f(f, seq):
for item in seq:
if f(item):
return item
assert f(lambda x: x % 2 == 0, range(3, 10)) == 4
|
benchmark_functions_edited/f4168.py
|
def f(value):
return int(value * 100 * 1000)
assert f(0) == 0
|
benchmark_functions_edited/f4094.py
|
def f(sentence):
if "?" in sentence:
return 1
else:
return 0
assert f(
"How vexingly quick daft zebras jump!"
) == 0
|
benchmark_functions_edited/f13608.py
|
def f(array, number):
aparitions = 0
for i in range(0, len(array)):
if array[i] == number:
aparitions += 1
return aparitions
assert f([1, 2, 3, 4, 5], 6) == 0
|
benchmark_functions_edited/f2504.py
|
def f(num):
return round(num, 1) if num < 10 else int(round(num, 0))
assert f(0.999999999) == 1
|
benchmark_functions_edited/f6198.py
|
def f(a, x, lo=0, hi=None):
if hi is None: hi = len(a)
while lo < hi:
mid = (lo + hi)//2
if a[mid] <= x: lo = mid + 1
else: hi = mid
return lo
assert f(range(10), 5) == 6
|
benchmark_functions_edited/f3121.py
|
def f(x): ## a recursive function that calculates the factorial of x
if x == 1:
return 1
return x * f(x-1)
assert f(2) == 2
|
benchmark_functions_edited/f613.py
|
def f(dB):
return 10**(dB/20.)
assert f(0) == 1
|
benchmark_functions_edited/f6231.py
|
def f(my_list):
return sum(my_list) / len(my_list)
assert f( [1, 2, 3] ) == 2
|
benchmark_functions_edited/f3904.py
|
def f(number):
x = 0
while (number >> x) & 1 == 0:
x = x + 1
return x
assert f(1) == 0
|
benchmark_functions_edited/f14071.py
|
def f(value, values):
count = 0;
for val in values:
if val == value:
count = count + 1;
return count;
assert f(2, [0, 0, 0, 0]) == 0
|
benchmark_functions_edited/f6387.py
|
def f(prices):
maxCur=0
maxSoFar=0
for i in range(1,len(prices)):
maxCur+=prices[i]-prices[i-1]
maxCur=max(0,maxCur)
maxSoFar=max(maxCur,maxSoFar)
return maxSoFar
assert f( [1,1] ) == 0
|
benchmark_functions_edited/f13373.py
|
def f(bytes: float, to: str = 'm', bsize: int = 1024):
a = {'k': 1, 'm': 2, 'g': 3, 't': 4, 'p': 5, 'e': 6}
r = float(bytes)
for i in range(a[to]):
r = r / bsize
return(r)
assert f(1024, 'k') == 1
|
benchmark_functions_edited/f14379.py
|
def f(q1, q2, q3):
return 4 * q1 * q2 - (q1 + q2 - q3) ** 2
assert f(0, 0, 0) == 0
|
benchmark_functions_edited/f6101.py
|
def f(month: int):
month_quarter_map = {1: 1, 2: 1, 3: 1, 4: 2, 5: 2, 6: 2, 7: 3, 8: 3, 9: 3, 10: 4, 11: 4, 12: 4}
return month_quarter_map[month]
assert f(2) == 1
|
benchmark_functions_edited/f11123.py
|
def f(set_nodes, i):
if i != set_nodes[i]:
set_nodes[i] = f(set_nodes, set_nodes[i])
return set_nodes[i]
assert f(
{
0: 0,
1: 0,
2: 0,
3: 1,
4: 1,
5: 2,
6: 2,
7: 3,
8: 3,
9: 4,
10: 4,
11: 5,
12: 5,
13: 6,
14: 6,
15: 7,
16: 7,
},
0
) == 0
|
benchmark_functions_edited/f4634.py
|
def f(x: float) -> int:
assert x > 0
x = int(x)
if x == 0:
return 1
else:
return x
assert f(0.6) == 1
|
benchmark_functions_edited/f5474.py
|
def f(x1, x2, y1, y2, x):
if (x2 - x1 != 0):
return (((x - x1)/(x2-x1))*(y2-y1)) + y1
assert f(0, 5, 0, 3, 5) == 3
|
benchmark_functions_edited/f7051.py
|
def f(value, mean, count):
return (value - mean) / (count + 1)
assert f(1, 1, 3) == 0
|
benchmark_functions_edited/f8375.py
|
def f(op):
while not op[-1]:
# encountered bug for the following
# 00 04 31 add byte ptr [rcx + rsi], al
if len(op) == 1:
break
op.pop()
return len(op)
assert f(bytearray([0x00, 0x04, 0x31, 0x00])) == 3
|
benchmark_functions_edited/f407.py
|
def f(x, func):
return func(x).imag
assert f(0.1, lambda x: x * 0) == 0
|
benchmark_functions_edited/f872.py
|
def f(val, minval, maxval):
return max(min(maxval, val), minval)
assert f(2, 1, 2) == 2
|
benchmark_functions_edited/f422.py
|
def f(x: str) -> int:
return int(x.replace(',',''))
assert f('{0}'.format(1)) == 1
|
benchmark_functions_edited/f7607.py
|
def f(s: str) -> int:
s = s.lstrip('0')
n = int(s, 2)
mask = n >> 1
while mask != 0:
n = n ^ mask
mask = mask >> 1
return n
assert f('00000001') == 1
|
benchmark_functions_edited/f990.py
|
def f(y, t=0):
dydt = -y**3 + y
return dydt
assert f(0) == 0
|
benchmark_functions_edited/f6740.py
|
def f(n: int) -> int:
total = 0
for i in range(n):
if (i % 3 == 0) or (i % 5 == 0):
total += i
return total
assert f(1) == 0
|
benchmark_functions_edited/f11177.py
|
def f(crimeStr):
if crimeStr == "low":
crimeInt = 1
elif crimeStr == "average":
crimeInt = 2
elif crimeStr == "high":
crimeInt = 3
else:
crimeInt = 0
return crimeInt
assert f("high") == 3
|
benchmark_functions_edited/f13384.py
|
def f(x0, y0):
x = 0
y = 0
iteration = 0
max_iteration = 200
while ( x*x + y*y <= (2*2) and iteration < max_iteration ):
xtemp = x*x - y*y + x0
y = 2*x*y + y0
x = xtemp
iteration += 1
if (iteration == max_iteration):
iterations = max_iteration
else:
iterations = iteration
return(iterations)
assert f(1.5, -0.5) == 2
|
benchmark_functions_edited/f8347.py
|
def f(c):
# ignore polarity
return ord(c) & 0x07
assert f(u'\u0003') == 3
|
benchmark_functions_edited/f6621.py
|
def f(stim, color_control):
print('color control: ', color_control)
return stim * (1 - color_control)
assert f(3, 0) == 3
|
benchmark_functions_edited/f9764.py
|
def f(n, guess):
h = lambda x: (x + (n // x)) // 2
prev, curr = guess, h(guess)
iterations = 1
while abs(curr - prev) >= 1:
prev, curr = curr, h(curr)
iterations += 1
return iterations
assert f(1024, 512) == 6
|
benchmark_functions_edited/f4225.py
|
def f(it):
for i in it:
return i
assert f(set([1,2,3,4,5])) == 1
|
benchmark_functions_edited/f1609.py
|
def f(q):
try:
return q.magnitude
except:
return q
assert f(1) == 1
|
benchmark_functions_edited/f188.py
|
def f(x):
return x**2 - 2
assert f(2) == 2
|
benchmark_functions_edited/f5814.py
|
def f(N):
str_nb = str(2**N)
somme = 0
for elt in str_nb:
somme += int(elt)
return somme
assert f(0) == 1
|
benchmark_functions_edited/f9692.py
|
def f(filter_size, in_size, stride):
out_size = (in_size + (stride - 1)) // stride
return max((out_size - 1) * stride + filter_size - in_size, 0)
assert f(3, 224, 2) == 1
|
benchmark_functions_edited/f11702.py
|
def f(freq, sample_rate, dft_size):
bin_size = sample_rate / dft_size
# Modulo operation puts any frequency into the appropriate bin
# with number in [0, dft_size).
return int(round(freq / bin_size)) % dft_size
assert f(100.0, 100.0, 1) == 0
|
benchmark_functions_edited/f10684.py
|
def f(p, x):
val = 0
ii = len(p) - 1
for i in range(len(p) - 1):
val += p[i] * (x ** ii)
ii -= 1
return val + p[-1]
assert f([0], 2) == 0
|
benchmark_functions_edited/f6078.py
|
def f(lines, section=' IMPRESSION'):
for idx, line in enumerate(lines):
if line.startswith(section):
return idx
return -1
assert f([' IMPRESSION', '', '']) == 0
|
benchmark_functions_edited/f2055.py
|
def f(x, a, b):
if x < a:
return a
if x > b:
return b
return x
assert f(5, 2, 4) == 4
|
benchmark_functions_edited/f2882.py
|
def f(obj):
if hasattr(obj, "__moyapy__"):
return obj.__moyapy__()
return obj
assert f(1) == 1
|
benchmark_functions_edited/f7477.py
|
def f(lines, idx):
while True:
if not lines[idx].strip():
# found a blank line
break
else:
idx -= 1
return idx
assert f([
'def foo():',
' ',
' return 1',
], 4) == 2
|
benchmark_functions_edited/f9690.py
|
def f(lumbyte: int,
gamma: float) -> int:
return int(((lumbyte / 255) ** gamma) * 255)
assert f(0, 2) == 0
|
benchmark_functions_edited/f1234.py
|
def f(contigs):
return sum(c.n_bases for c in contigs)
assert f([]) == 0
|
benchmark_functions_edited/f13941.py
|
def f(u, v, order):
if u[1] > v[1]:
return -1
if u[1] == v[1]:
#if u[0] == v[0]:
# return 0
if order(u[0]) < order(v[0]):
return -1
return 1
assert f([('x', 0), ('y', 0)], [('x', 0), ('z', 0)], None) == 1
|
benchmark_functions_edited/f1814.py
|
def f(condition, a, b):
if condition : return a
else : return b
assert f(1 == 0, 1, 2) == 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.