file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f12590.py | def f(a,l,r):
p = a[l]
i = l+1
j = l+1
while j <= r:
if a[j] <= p:
temp = a[j]
a[j] = a[i]
a[i] = temp
i+=1
j+=1
else:
j+=1
temp = a[l]
a[l] = a[i-1]
a[i-1] = temp
return i-1
assert f(list(... |
benchmark_functions_edited/f6634.py | def f(samples):
seq_lengths = []
for seq in samples:
seq_lengths.append(len(seq[0]))
return max(seq_lengths)
assert f(
[
(['a', 'b', 'c', 'd', 'e'], ['f', 'g', 'h']),
(['i', 'j'], ['k', 'l','m', 'n']),
(['o'], ['p', 'q']),
]) == 5 |
benchmark_functions_edited/f3588.py | def f(coeffs, n):
total = 0
for i, c in enumerate(coeffs):
total += c * n ** i
return total
assert f([1, 2, 3, 4, 5], 0) == 1 |
benchmark_functions_edited/f36.py | def f(x, y):
z = x + y
return z
assert f(1, 2) == 3 |
benchmark_functions_edited/f1344.py | def f(a,b):
while b > 0:
a, b = b, a % b
return a
assert f(8, 21) == 1 |
benchmark_functions_edited/f14437.py | def f(A):
if len(A) < 3:
return 0
A = sorted(A)
product_A = A[0] * A[1] * A[-1]
product_B = A[-1] * A[-2] * A[-3]
max_product = max(product_A, product_B)
return max_product
assert f([1, 2]) == 0 |
benchmark_functions_edited/f4186.py | def f(x, a, b):
return a*x + b
assert f(3, 2, 1) == 7 |
benchmark_functions_edited/f10255.py | def f( P, Q ):
import math
divergence = 0
assert len(P) == len(Q)
for i in range(len(P)):
p = P[i]
q = Q[i]
assert p >= 0
assert q >= 0
if p > 0:
divergence += p * math.log( p / q )
return divergence
assert f( [ 1, 0, 1, 0, 1 ], [ 1, 0, 1, 0, 1 ] ... |
benchmark_functions_edited/f12573.py | def f(n: int, max_size: int = 100) -> int:
if n > 2:
return min(round(1.6 * n**0.56), max_size)
else:
return 1
assert f(1) == 1 |
benchmark_functions_edited/f7199.py | def f(input: str, default: int = 0) -> int:
if input == "S":
return 1
elif input == "N":
return 0
else:
return default
assert f("S") == 1 |
benchmark_functions_edited/f3616.py | def f(value1, value2, value3):
prod = value1 * value2
prod = prod * value3
return prod
assert f(3, 2, 1) == 6 |
benchmark_functions_edited/f8688.py | def f(n):
return n % 10 + (0 if n < 10 else f(n // 10))
assert f(11111) == 5 |
benchmark_functions_edited/f8887.py | def f(a):
first_d = a[0][0] + a[1][1] + a[2][2]
second_d = a[0][2] + a[1][1] + a[2][0]
return abs(first_d - second_d)
assert f(
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
) == 0 |
benchmark_functions_edited/f1155.py | def f(m):
return max(m)-min(m)
assert f(range(10)) == 9 |
benchmark_functions_edited/f2944.py | def f(nth,term_number,common_difference):
return nth-(common_difference*(term_number-1))
assert f(3, 1, 1) == 3 |
benchmark_functions_edited/f8644.py | def f(string_1, string_2):
assert len(string_1) == len(string_2)
return sum(ch1 != ch2 for ch1, ch2 in zip(string_1, string_2))
assert f('123', '321') == 2 |
benchmark_functions_edited/f4782.py | def f(x:float)->float:
if x > 0:
return 1
return 0
assert f(0.2) == 1 |
benchmark_functions_edited/f11088.py | def f(n):
sum = 0
if n > 2:
first = 1
second = 1
sum = first + second
count = 3
while count <= n:
temp = first + second
first = second
second = temp
sum += temp
count += 1
return sum
assert f(0) == 0 |
benchmark_functions_edited/f3665.py | def f(node_1, node_2):
return abs(node_1[0] - node_2[0]) + abs(node_1[1] - node_2[1])
assert f((1, 1), (1, 0)) == 1 |
benchmark_functions_edited/f13996.py | def f(answer: object) -> int:
choices = ['See only your friends', 'See your friends and their friends',
"See your friends, their friends, and your friends' friends' friends"]
if answer in choices:
return choices.index(answer) + 1
else:
return -1
assert f('See your friends, t... |
benchmark_functions_edited/f14506.py | def f(cond, arr):
for i, a in enumerate(arr):
if cond(a):
return i
return None
assert f(lambda x: x == 0, [0, 0, 0, 0]) == 0 |
benchmark_functions_edited/f10568.py | def f(x, y):
r = (x+int(y/2)) & ~(y-1)
if r > x:
r = r - y
return r
assert f(6,2) == 6 |
benchmark_functions_edited/f363.py | def f(n):
return int(n * (3 * n - 2))
assert f(1) == 1 |
benchmark_functions_edited/f12806.py | def f(x, y):
if not isinstance(x, int) or not isinstance(y, int):
raise TypeError("Input of greatest common divisor should be integer")
if y < x:
y, x = x, y
if x == 0:
raise ValueError("Input can not be zero")
z = x
while y % x != 0:
z = y % z
y = x
... |
benchmark_functions_edited/f5467.py | def f(weight, week=1, inc=5):
percents = (0.85, 0.9, 0.95)
percent = percents[week-1]
return weight / percent + inc if week == 3 else 0
assert f(100) == 0 |
benchmark_functions_edited/f13075.py | def f(number1: int, number2: int) -> int:
number_pair = (min(abs(number1), abs(number2)), max(abs(number1), abs(number2)))
while number_pair[0] > 0:
number_pair = (number_pair[1] % number_pair[0], number_pair[0])
return number_pair[1]
assert f(1, 2) == 1 |
benchmark_functions_edited/f2836.py | def f(batch_idx, ws_multiplier):
return int(batch_idx/ws_multiplier)
assert f(23, 4) == 5 |
benchmark_functions_edited/f12892.py | def f(line: str) -> int:
indent = 0
for c in line:
if c == " ":
indent += 1
elif c == "\t":
indent += 8
else:
# break on first word / non-white char
break
return indent
assert f(
" def f(line) -> int:"
) == 1 |
benchmark_functions_edited/f8348.py | def f(x, q, rq):
return int(round(1.* rq * x / q) % rq)
assert f(0, 2, 4) == 0 |
benchmark_functions_edited/f9770.py | def f(time_type, since):
if time_type == "Run" and (since & 0xffffff) == 0:
return since >> 32
else:
return since
assert f(7, 1) == 1 |
benchmark_functions_edited/f2391.py | def f(n):
if n == 0:
return 0
cnt = 0
while n % 5 == 0:
cnt += 1
n /= 5
return cnt
assert f(5) == 1 |
benchmark_functions_edited/f11919.py | def f(l,u,y,q):
if y<l:
return 2*(l-y) + q*(u-l)
elif y>u:
return 2*(y-u) + q*(u-l)
else:
return q*(u-l)
assert f(0,1,0.25,0) == 0 |
benchmark_functions_edited/f6042.py | def f(b):
# use the int.from_bytes(b, <endianness>) method
return int.from_bytes(b, "little")
assert f(b'\x03') == 3 |
benchmark_functions_edited/f4714.py | def f(t, tp, vals):
for i in range(len(tp)):
ti = tp[i]
if t>= ti:
return vals[i]
assert f(0, [0, 10], [0, 1]) == 0 |
benchmark_functions_edited/f12828.py | def f(increment,level):
return increment*level+1
assert f(2,1) == 3 |
benchmark_functions_edited/f9870.py | def f(parent_index, heap):
# Remember, this is a 1-based index.
if parent_index * 2 + 1 >= len(heap):
# There is no right child
return 0
return parent_index * 2 + 1
assert f(1, [1, 2, 3, 4]) == 3 |
benchmark_functions_edited/f1020.py | def f(n):
return sum([i*i for i in range(n+1)])
assert f(1) == 1 |
benchmark_functions_edited/f14554.py | def f(x,y):
diff = len(y['tokens'])-len(x['tokens'])
if diff != 0:
return diff
(x_conds, y_conds) = (0,0)
for cond in ('prev','next'):
if cond in x: x_conds +=len(cond)
if cond in y: y_conds +=len(cond)
for cond in ('prev_class', 'next_class'):
if cond in x: x_conds +... |
benchmark_functions_edited/f8937.py | def f(s, p):
return s + 4 * (1-p) * s + 4 * (1-p) ** 2 * s
assert f(1, 1) == 1 |
benchmark_functions_edited/f4175.py | def f(seq_length):
half_offset = int((seq_length - 1) / 2)
return seq_length - 1 - half_offset
assert f(7) == 3 |
benchmark_functions_edited/f6593.py | def f(b):
sec_dec = ""
if b != None:
sec_dec = int(str(b),2)
else:
sec_dec = "Not set yet!"
return sec_dec
assert f(10) == 2 |
benchmark_functions_edited/f7221.py | def f(degrees):
if degrees == 90:
return 4
elif degrees == 180:
return 3
elif degrees == 270:
return 7
else:
return None
assert f(90) == 4 |
benchmark_functions_edited/f4706.py | def f(self, key, default=None):
try:
return self[key]
except KeyError:
return default
assert f([1, 2, 3], 1, 5) == 2 |
benchmark_functions_edited/f14495.py | def f(a, b, c):
a = list(sorted(set(a)))
b = list(sorted(set(b)))
c = list(sorted(set(c)))
ai = bi = ci = 0
a_len, c_len = len(a), len(c)
answer = 0
while bi < len(b):
while ai < a_len and a[ai] <= b[bi]:
ai += 1
while ci < c_len and b[bi] >= c[ci]:
... |
benchmark_functions_edited/f6442.py | def f(a, b):
while b:
a, b = b, a%b
return a
assert f(3, 3) == 3 |
benchmark_functions_edited/f641.py | def f(n):
return n if n < 2 else f(n-1) + f(n-2)
assert f(0) == 0 |
benchmark_functions_edited/f7234.py | def f(I):
I_toa = I*10000
return I_toa
assert f(0) == 0 |
benchmark_functions_edited/f3475.py | def f(phi_0, m, om, N):
return (1j*m*N**2/(N**2 - om**2))*phi_0
assert f(1, 1, 1, 0) == 0 |
benchmark_functions_edited/f4099.py | def f(value):
if value < 0:
return 0
if value > 255:
return 255
return value
assert f(-1) == 0 |
benchmark_functions_edited/f8396.py | def f(row: int, col: int, map={}):
if row == 1 or col == 1:
return 1
elif (row, col) not in map:
map[(row, col)] = f(row - 1, col, map)\
+ f(row, col - 1, map)
return map[(row, col)]
assert f(**{'row': 2, 'col': 1}) == 1 |
benchmark_functions_edited/f11737.py | def f(total, x, y):
shortest = min(len(x), len(y))
if not shortest:
return 0
else:
return total / shortest
assert f(10, [], []) == 0 |
benchmark_functions_edited/f9346.py | def f(step, start_value, end_value, decay_rate,
num_steps_decay_rate):
progress = decay_rate**(step / num_steps_decay_rate)
return end_value + (start_value - end_value) * progress
assert f(0, 1, 10, 2, 100) == 1 |
benchmark_functions_edited/f5783.py | def f(n, p):
return {0: 0, p - 1: -1}.get(pow(n, (p - 1) // 2, p), 1)
assert f(28, 7) == 0 |
benchmark_functions_edited/f8910.py | def f(u, phi):
for _phi in phi:
if _phi[0] == u:
return _phi[1]
raise Exception('u couldn\' be found in the isomorphisms')
assert f(2, [(1, 2), (2, 3)]) == 3 |
benchmark_functions_edited/f6653.py | def f(set1, set2):
denominator = min(len(set1), len(set2))
if denominator > 0:
return len(set1.intersection(set2)) / denominator
else:
return denominator
assert f({1, 2, 3, 4, 5}, {3, 4, 5}) == 1 |
benchmark_functions_edited/f12609.py | def f(x, y):
if len(x) == 0 or len(y) == 0:
return 0
xx = x[:-1] # xx = sequence x without its last element
yy = y[:-1]
if x[-1] == y[-1]: # if last elements of x and y are equal
return f(xx, yy) + 1
else:
return max(f(xx, y), f(x, yy))
assert f( "kitten", "" ) ==... |
benchmark_functions_edited/f5232.py | def f(a,b):
while b:
a, b = b, a%b
return a
assert f(37,61) == 1 |
benchmark_functions_edited/f8735.py | def f(root):
if not root:
return 0
left = f(root.left)
right = f(root.right)
if abs(left-right) > 1 or left == -1 or right == -1:
return -1
return 1 + max(left, right)
assert f(None) == 0 |
benchmark_functions_edited/f11577.py | def f(obj, topidx, bottomidx):
obj = obj >> bottomidx
# Generate a bitmask to get topidx - bottomidx number bits
mask = 1
for bit in range(topidx - bottomidx):
mask = mask << 1
mask += 1
return obj & mask
assert f(0x03, 3, 3) == 0 |
benchmark_functions_edited/f168.py | def f(s):
return len(s.split())
assert f(
'Hello') == 1 |
benchmark_functions_edited/f5255.py | def f(item):
if len(item) == 1:
print(item[0]),
else:
print("."),
return 0
assert f(list("XX.OO.XX")) == 0 |
benchmark_functions_edited/f9898.py | def f(x, y):
try:
words, cnt = x.split(), 0
for w in words:
if y.find(w) >= 0:
cnt += 1
return cnt
except Exception as e:
print(f"Exception raised:\n{e}")
return 0
assert f(
"This is a foo bar sentence.", "This sentence is similar.") == 3 |
benchmark_functions_edited/f3813.py | def f(*conds):
return sum(int(bool(c)) << i for i, c in enumerate(conds))
assert f(True, True, False, False) == 3 |
benchmark_functions_edited/f10907.py | def f(s):
count = len(s)
for i in range(len(s)):
for j in range(i + 2, len(s) + 1):
cur_slice = s[i:j]
if cur_slice == cur_slice[::-1]:
count += 1
return count
assert f(
'aaa'
) == 6 |
benchmark_functions_edited/f7606.py | def f(temp):
return (temp * 5) / 9
assert f(0) == 0 |
benchmark_functions_edited/f20.py | def f(x, a, b):
return b*(x**a)
assert f(*[1, 1, 2]) == 2 |
benchmark_functions_edited/f2870.py | def f(n):
count = 0
while (n):
count += n & 1
n >>= 1
return count
assert f(7) == 3 |
benchmark_functions_edited/f1724.py | def f(value, minimum, maximum):
return max(min(value, maximum), minimum)
assert f(3, 2, 5) == 3 |
benchmark_functions_edited/f1102.py | def f(x):
try: return int(x)
except: return 0
assert f(1) == 1 |
benchmark_functions_edited/f11840.py | def f(boutlist):
if boutlist[-1] == 300:
total_bouts = len(boutlist) - 1
else:
total_bouts = len(boutlist)
return total_bouts
assert f( [ 1, 3, 7, 20, 25 ]) == 5 |
benchmark_functions_edited/f8493.py | def f(column_dict, description):
index = [value for key, value in column_dict.items() if description in key][0]
if index is None:
return
else:
return index
assert f(
{'ID': 0, 'First name': 1, 'Last name': 2},
'First name'
) == 1 |
benchmark_functions_edited/f10259.py | def f(num1, num2):
if isinstance(num1, str) or isinstance(num2, str):
return None
return (num1 + num2)
assert f(2.5, 1.5) == 4 |
benchmark_functions_edited/f11638.py | def f(seating: list) -> int:
count = 0
for i in range(len(seating)):
for j in range(len(seating[i])):
if seating[i][j] == "#":
count += 1
return count
assert f(
[
["L", ".", ".", "L", ".", ".", ".", "."],
[".", ".", ".", ".", ".", ".", ".", "."],
... |
benchmark_functions_edited/f8872.py | def f(func,x,p,np):
puse = []
y = 0
for i in range(len(p)):
puse.append(p[i])
if len(puse)%np == 0:
y += func(x, puse )
puse = []
return y
assert f(lambda x, p: p[0] * x, 0, [0, 1, 2, 3], 2) == 0 |
benchmark_functions_edited/f3325.py | def f(iterable):
try:
return next(iter(iterable))
except StopIteration:
return None
assert f(range(1, 100)) == 1 |
benchmark_functions_edited/f626.py | def f(pages):
return sum([v.value for v in p.votes].count(1) for p in pages)
assert f([]) == 0 |
benchmark_functions_edited/f4952.py | def f(arr):
lo, hi = -1, len(arr)-1
while lo < hi:
mid = lo + hi + 1 >> 1
if arr[mid]: lo = mid
else: hi = mid - 1
return lo
assert f([True, False, False]) == 0 |
benchmark_functions_edited/f7600.py | def f(x, amplitude, x_0, fwhm):
numerator = (fwhm / 2.0) ** 2
denominator = (x - x_0) ** 2 + (fwhm / 2.0) ** 2
lor = numerator / denominator
lor = amplitude * lor
return lor
assert f(0, 1, 0, 1) == 1 |
benchmark_functions_edited/f5810.py | def f(n):
if n <=2:
return 1
else:
return f(n-1) + f(n-2)
assert f(0) == 1 |
benchmark_functions_edited/f1945.py | def f(minimum, value, maximum):
return max(minimum, min(value, maximum))
assert f(0, 5, 100) == 5 |
benchmark_functions_edited/f2180.py | def f(v1, v2):
return v1[0]*v2[1] - v1[1]*v2[0]
assert f( (0, 1), (0, 1) ) == 0 |
benchmark_functions_edited/f13684.py | def f(state_edges_predicted, state_edges_actual):
total=0
for key in state_edges_predicted.keys():
#print(key)
total+=abs(state_edges_predicted[key]-state_edges_actual[key])
#print(state_edges_predicted[state])
return total/len(state_edges_predicted) #Returns weighted average err... |
benchmark_functions_edited/f12232.py | def f(obj, name, default):
value = getattr(obj, name, default)
if value:
return value
else:
return default
assert f(dict(), 'foo', 0) == 0 |
benchmark_functions_edited/f8156.py | def f(value, sub, start=None, end=None):
return value.f(sub, start, end)
assert f("a b c a b c", "b", 3) == 1 |
benchmark_functions_edited/f5143.py | def f(s0, v0, delta_t_ms):
return s0 + (v0 * delta_t_ms / 1000)
assert f(0, 3, 1000) == 3 |
benchmark_functions_edited/f6210.py | def f(x, pp, soln=0):
# https://www.myassays.com/four-parameter-logistic-regression.html
A, B, C, D = pp
return ((A - D) / (1.0 + ((x / C)**B))) + D - soln
assert f(1, (1, 1, 1, 1)) == 1 |
benchmark_functions_edited/f1532.py | def f(lst):
return max(set(lst), key=lst.count)
assert f(range(3)) == 0 |
benchmark_functions_edited/f12665.py | def f(items, pivot):
return min(items, key=lambda x: abs(x - pivot))
assert f(range(5), 4.2) == 4 |
benchmark_functions_edited/f11435.py | def f(tau,w,s):
return (1-tau)*w-s
assert f(0,1,1) == 0 |
benchmark_functions_edited/f6757.py | def f(genotypes_combinations):
product = 1
for gc in genotypes_combinations:
product *= len(gc)
return product
assert f(['a']) == 1 |
benchmark_functions_edited/f13340.py | def f(n, range1, range2):
delta1 = range1[1] - range1[0]
delta2 = range2[1] - range2[0]
return (delta2 * (n - range1[0]) / delta1) + range2[0]
assert f(200, (0, 200), (0, 1)) == 1 |
benchmark_functions_edited/f1372.py | def f(x):
return sum(abs(xi-3.)/0.1 for xi in x)
assert f([]) == 0 |
benchmark_functions_edited/f7507.py | def f(data):
# h = 0
# for c in data:
# h = (ord(c) + (31 * h)) % MAX_32_INT
# return h
return abs(hash(data))
assert f(u"") == 0 |
benchmark_functions_edited/f4438.py | def f(value: int) -> int:
if not value & 0x1:
return value >> 1
return (value >> 1) ^ (~0)
assert f(18) == 9 |
benchmark_functions_edited/f5824.py | def f(state, disk):
for p in state:
if p[0] == 'On' and p[1] == disk:
return 1 + f(state - set([p]), p[2])
return 0
assert f(set(['On', 'b', 'c']), 'a') == 0 |
benchmark_functions_edited/f7292.py | def f(temp, templist):
templist = (int(t) for t in templist if t != '')
templist = [t for t in templist if t < int(temp)]
if templist: return max(templist)
else: return None
assert f(3, '30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0'.split()) == 2 |
benchmark_functions_edited/f10602.py | def f(episodes: str) -> int:
a = 0
for ep in episodes.split(', '):
if '-' in ep:
index = ep.index('-')
a += int(ep[:index])-int(ep[index+1:])
else:
a += int(ep)
return a
assert f(
'1, 2, 3'
) == 6 |
benchmark_functions_edited/f5842.py | def f(p,q):
same = 0
for i in p:
if i in q:
same +=1
e = sum([(p[i] - q[i])**2 for i in range(same)])
return 1/(1+e**.5)
assert f(dict(),dict()) == 1 |
benchmark_functions_edited/f1577.py | def f(f, n):
if not f:
return f
else:
return f + [0]*n
assert f(0, 1) == 0 |
benchmark_functions_edited/f2263.py | def f(a):
return min(min(inner) for inner in a)
assert f(
[[0, 0], [1, 0], [2, 1], [3, 0], [4, 1], [5, 2], [6, 0], [7, 1], [8, 2]]
) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.