file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f201.py | def f(arr):
c = len(arr)
return c
assert f([]) == 0 |
benchmark_functions_edited/f8873.py | def f(number):
# convert to numeric first, then sum individual digits
weights = (1, 2, 1, 2, 1, 2, 4, 1)
number = ''.join(str(w * int(n)) for w, n in zip(weights, number))
return sum(int(n) for n in number) % 10
assert f('123456789') == 2 |
benchmark_functions_edited/f13198.py | def f(base, value_to_pow):
while value_to_pow > base:
value_to_pow = value_to_pow - (base - 1)
return value_to_pow
assert f(2, 6) == 2 |
benchmark_functions_edited/f13796.py | def f(cipher_suite_id):
if not isinstance(cipher_suite_id, int):
raise TypeError("CipherSuite ID must be of type int.")
if not 0 <= cipher_suite_id <= 3:
raise ValueError("Invalid CipherSuite.")
return cipher_suite_id
assert f(1) == 1 |
benchmark_functions_edited/f7878.py | def f(need_ings):
return sum([ing["quantity"] for ing in need_ings])
assert f(
[
{"quantity": 1, "unit": "tablespoon"},
{"quantity": 2, "unit": "cup"}
]
) == 3 |
benchmark_functions_edited/f706.py | def f(values):
return sum(values)/len(values)
assert f([1, 2, 3, 4, 5]) == 3 |
benchmark_functions_edited/f6890.py | def f(pos):
if pos < 0.5:
return 16 * pos * pos * pos * pos * pos
fos = (2 * pos) - 2
return 0.5 * fos * fos * fos * fos * fos + 1
assert f(1) == 1 |
benchmark_functions_edited/f2392.py | def f(x:float)->float:
return max(0,x)
assert f(-2) == 0 |
benchmark_functions_edited/f999.py | def f(x,Kd,A,B):
return A + B*(x/(x + Kd))
assert f(0,10,5,10) == 5 |
benchmark_functions_edited/f8427.py | def f(x, a, b, c):
return a*x**2 + b*x + c
assert f(-1, 2, 1, 0) == 1 |
benchmark_functions_edited/f3312.py | def f(p, d, g):
import math
return math.sqrt(g*p/d)
assert f(1, 1, 1) == 1 |
benchmark_functions_edited/f2208.py | def f(l):
if "_" in str(l):
return 1
else:
return 0
assert f(21) == 0 |
benchmark_functions_edited/f1982.py | def f(tile):
return tile - 9 * (tile // 9)
assert f(19) == 1 |
benchmark_functions_edited/f14510.py | def f(val, nb):
return ((val << nb) + (val & (0xFFFFFFFF >> (32 - nb)))) & 0xFFFFFFFFFFFFFFFF
assert f(0, 1) == 0 |
benchmark_functions_edited/f6292.py | def f(follow_type: str):
assert follow_type in ['blog', 'ignore'], "invalid follow_type"
return 1 if follow_type == 'blog' else 2
assert f('ignore') == 2 |
benchmark_functions_edited/f14048.py | def f(items, predicate, d=None, c=None):
q = None
for i in items:
if q is None:
q = predicate(i)
else:
q |= predicate(i)
if d is not None:
q = d | q
if c is not None:
q = c & q
return q
assert f(range(2), lambda x: x & 1, 0) == 1 |
benchmark_functions_edited/f9061.py | def f(value):
if value in ["true", "True", "y", "Y", "yes"]:
return True
if value in ["false", "False", "n", "N", "no"]:
return False
if value.isdigit():
return int(value)
return str(value)
assert f("2") == 2 |
benchmark_functions_edited/f8088.py | def f(arr):
# this solution does not return 0 for empty array
# But it is a good reference for using list slicing
for i in range(len(arr)):
if sum(arr[i:]) == sum(arr[:i+1]):
return i
return -1
assert f([1, 2, 3, 4, 3, 2, 1]) == 3 |
benchmark_functions_edited/f12871.py | def f(letter):
counter = 0
letter = letter.lower()
for l in 'abcdefghijklmnopqrstuvwxyz':
if l == letter:
break
counter += 1
return counter
assert f("a") == 0 |
benchmark_functions_edited/f12279.py | def f(hpo_string: str) -> int:
idx = hpo_string.split('!')[0].strip()
return int(idx.split(':')[1].strip())
assert f(
'HP:0000000001'
) == 1 |
benchmark_functions_edited/f2766.py | def f(colour):
if (colour >= 0 and colour < 0xffffff):
return 1
return 0
assert f(0x0) == 1 |
benchmark_functions_edited/f1479.py | def f(b):
return (4**b - 1) // 3
assert f(0) == 0 |
benchmark_functions_edited/f8369.py | def f(g):
try:
e = g.__next__()
return e
except StopIteration:
return None
assert f(iter((i + 1 for i in range(3)))) == 1 |
benchmark_functions_edited/f1703.py | def f(s):
return 0 if not s else int(s)
assert f('0') == 0 |
benchmark_functions_edited/f6325.py | def f(n: int) -> int:
return format(n, 'b').count('1')
assert f(15) == 4 |
benchmark_functions_edited/f1584.py | def f(x, default):
return x if x is not None else default
assert f(1, 2) == 1 |
benchmark_functions_edited/f6089.py | def f(inPtA, inPtB):
ddx = inPtA[0] - inPtB[0]
ddy = inPtA[1] - inPtB[1]
ddz = inPtA[2] - inPtB[2]
return ddx*ddx + ddy*ddy + ddz*ddz
assert f( (0, 0, 0), (1, 0, 1) ) == 2 |
benchmark_functions_edited/f3976.py | def f(pre_mean, new_data, sample_size):
inc_mean = pre_mean + (new_data-pre_mean) / sample_size
return inc_mean
assert f(0, 0, 1) == 0 |
benchmark_functions_edited/f5668.py | def f(string):
for i, ch in enumerate(string):
if ch != ' ':
return i
return len(string)
assert f(' hello world') == 1 |
benchmark_functions_edited/f9038.py | def f(v):
try:
return len(str(abs(int(v))))
except Exception as inst:
print(inst.args)
return 0
assert f(-0) == 1 |
benchmark_functions_edited/f5544.py | def f(p, m):
return (1 - (1-p)**m)
assert f(0.001, 0) == 0 |
benchmark_functions_edited/f11347.py | def f(f, self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except Exception:
self.log.error('Uncaught exception in %r' % f, exc_info=True)
assert f(lambda self, a, b, c: a*b*c, None, 1, 2, 3) == 6 |
benchmark_functions_edited/f9809.py | def f(mylist: list, value):
return mylist.index(value)
assert f([1, 2, 2, 2, 3, 3, 4], 4) == 6 |
benchmark_functions_edited/f10566.py | def f(value, subjectnum):
value *= subjectnum
value %= 20201227
return value
assert f(1, 1) == 1 |
benchmark_functions_edited/f1927.py | def f(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a
assert f(1) == 1 |
benchmark_functions_edited/f1210.py | def f(a,b):
if (a != 0 and b != 0):
return 1
else:
return 0
assert f(1,1) == 1 |
benchmark_functions_edited/f14440.py | def f(p1, p2, p3):
x1, y1 = p1
x2, y2 = p2
x3, y3 = p3
return (x1*y2 + x3*y1 + x2*y3 - x3*y2 - x2*y1 - x1*y3)
assert f( (2, 4), (1, 3), (5, 1) ) == 6 |
benchmark_functions_edited/f4469.py | def f(a, b):
x1, y1 = a
x2, y2 = b
return abs(x1 - x2) + abs(y1 - y2)
assert f( (1, 1), (0, 1) ) == 1 |
benchmark_functions_edited/f7746.py | def f(r,h):
total = 0
for i in range(0,h+1):
total += r ** i
#log.debug("total: %s", total)
return total
assert f(1, 0) == 1 |
benchmark_functions_edited/f13010.py | def f(alist):
ln = len(alist)
mid = ln//2
if ln > 2:
left = f(alist[:mid])
right = f(alist[mid:])
return left if left > right else right
else:
return max(alist)
assert f([1, 2, 3, 4, 5]) == 5 |
benchmark_functions_edited/f6305.py | def f(iterable, predicate=None, default=None):
return next(filter(predicate, iterable), default)
assert f(range(10), lambda x: x % 5 == 0) == 0 |
benchmark_functions_edited/f11980.py | def f(variable: str) -> int:
if variable == "Y":
return 1
index = int(variable[1:]) if len(variable) > 1 else 1
offset = {"X": 0, "Z": 1}[variable[0]]
return index * 2 + offset
assert f("X3") == 6 |
benchmark_functions_edited/f9216.py | def f(low,high,segment_length,reverse=False):
remainder = (segment_length-(high-low)%segment_length)
if not reverse:
return high + remainder
else:
return low - remainder
assert f(2,0,1) == 1 |
benchmark_functions_edited/f5962.py | def f(a):
deciNum = 0
for i in range(len(a)):
deciNum += (int(a[i]))*2**-(i+1)
return deciNum
assert f( "0" ) == 0 |
benchmark_functions_edited/f3090.py | def f(n):
if n == 0:
return 0
else:
return n + f(n-1)
assert f(0) == 0 |
benchmark_functions_edited/f13977.py | def f(T, P):
n, m = len(T), len(P)
if m == 0:
return 0
last = {k: i for i, k in enumerate(P)}
i = k = m - 1
while i < n:
if T[i] == P[k]:
if k == 0:
return i
i -= 1
k -= 1
else:
j = last.get(T[i], -1)
i += m - min(k, j + 1)
k = m - 1
return -1
assert f(list('abracadabra'), 'bra') == 1 |
benchmark_functions_edited/f2578.py | def f(color):
return (0.2126*color[0]) + (0.7152*color[1]) + (0.0722*color[2])
assert f( (0, 0, 0) ) == 0 |
benchmark_functions_edited/f4458.py | def f(lum1: float, lum2: float) -> float:
val = (lum1 + 0.05) / (lum2 + 0.05)
return val if val >= 1 else 1 / val
assert f(0.5, 0.5) == 1 |
benchmark_functions_edited/f13027.py | def f(dims, names):
if isinstance(names, int):
return names
for i, d in enumerate(dims):
if d.lower() in names:
return i
return None
assert f(('dim', 'dim2'), ("dim", "dim2")) == 0 |
benchmark_functions_edited/f11242.py | def f(expr, X, X_subs):
i = 0
while i < len(X):
expr = expr.subs(X[i], X_subs[i])
i += 1
return expr
assert f(5, [], []) == 5 |
benchmark_functions_edited/f948.py | def f(value, align):
return int(int((value + align - 1) / align) * align)
assert f(2, 2) == 2 |
benchmark_functions_edited/f1006.py | def f(l):
return int(''.join(map(str, l)), 2)
assert f(list('101')) == 5 |
benchmark_functions_edited/f6056.py | def f(filename="", text=""):
with open(filename, 'w', encoding='utf=8') as file:
return file.write(text)
assert f("test.txt", "abc") == 3 |
benchmark_functions_edited/f6512.py | def f(x):
val = x
while True:
last = val
val = (val + x / val) * 0.5
if abs(val - last) < 1e-9:
break
return val
assert f(9) == 3 |
benchmark_functions_edited/f11120.py | def f(func, *args, **kwargs):
return func(*args, **kwargs)
assert f(pow, 2, 2) == 4 |
benchmark_functions_edited/f8307.py | def f(input_list: list) -> int:
if len(input_list) == 0:
return 0
return input_list.pop() + f(input_list)
assert f([1, 2, 3]) == 6 |
benchmark_functions_edited/f4312.py | def f(d1, d2):
d1 = set(d1)
d2 = set(d2)
return len(d1.intersection(d2)) / len(d1.union(d2))
assert f(set(), {'a'}) == 0 |
benchmark_functions_edited/f5622.py | def f(x, y) -> bool:
sum = x + y
if sum < 100:
sum = sum * 2
elif sum < 50:
sum = sum * 3
else:
sum = sum * 4
return sum
assert f(0, 0) == 0 |
benchmark_functions_edited/f8961.py | def f(a, b, c, d, e, f, g, h, i):
return a*(e*i - f*h) - b*(d*i - f*g) + c*(d*h - e*g)
assert f(3, 3, 3, 3, 3, 3, 3, 3, 3) == 0 |
benchmark_functions_edited/f7590.py | def f(d, n, c):
return c ** d % n
assert f(1, 3, 1) == 1 |
benchmark_functions_edited/f9072.py | def f(cw, e):
if cw is None:
w = 0
else:
gw = e.gw
# Overwrite style from here.
w = cw * (e.css('cw', 0) + gw) - gw
return w
assert f(None, None) == 0 |
benchmark_functions_edited/f10897.py | def f(low, high, val):
return low if val < low else (high if val > high else val)
assert f(1, 2, 3) == 2 |
benchmark_functions_edited/f92.py | def f(x,y,z):
den = x**2+z**2
return den
assert f(-2,0,0) == 4 |
benchmark_functions_edited/f1517.py | def f(seq, index_val):
try:
return seq[index_val]
except IndexError:
return None
assert f((1,2,3), 1) == 2 |
benchmark_functions_edited/f12997.py | def f(num1, num2):
try:
return float(num1) / num2
except ZeroDivisionError:
return 0
assert f(0, 1) == 0 |
benchmark_functions_edited/f9077.py | def f(r, rs, alpha, Rv, beta, deltac, offset):
numerator = 1-(r/rs)**alpha
denominator = 1+(r/Rv)**beta
return deltac*numerator/denominator +offset
assert f(0, 2, 2, 2, 2, 2, 0) == 2 |
benchmark_functions_edited/f12398.py | def f(n, coins):
min_coins = [0] * (n+1)
for i in range(1, n+1):
if i in coins:
min_coins[i] = 1
else:
possible = []
for c in coins:
if i - c > 0:
possible.append(1 + min_coins[i - c])
min_coins[i] = min(possible)
return min_coins[n]
assert f(5, [1, 5, 10, 25]) == 1 |
benchmark_functions_edited/f439.py | def f(key, left, right):
return left + right + 1
assert f(1, 2, 3) == 6 |
benchmark_functions_edited/f1769.py | def f(seed):
return None if seed is None else seed + 1
assert f(1) == 2 |
benchmark_functions_edited/f4617.py | def f(htk_time):
if type(htk_time)==type("string"):
htk_time = float(htk_time)
return htk_time / 50000.0
assert f("0") == 0 |
benchmark_functions_edited/f2207.py | def f(n):
return n*(n+1)/2
assert f(0) == 0 |
benchmark_functions_edited/f5806.py | def f(index):
return max(index % 256, 1)
assert f(256) == 1 |
benchmark_functions_edited/f3863.py | def f(value):
try:
return int(value)
except:
return value
assert f(2) == 2 |
benchmark_functions_edited/f3841.py | def f(data, key):
for item in data:
if item[0] == key:
return item[1]
raise KeyError(key)
assert f(
[('a', 0), ('b', 1)],
'a') == 0 |
benchmark_functions_edited/f2251.py | def f(input_size):
return float("{0:.2f}".format(int(input_size)/1E6))
assert f(1000000) == 1 |
benchmark_functions_edited/f12167.py | def f(t, p):
# a very simple method used as a dummy until a more elaborate approach is implemented
t_toks = t.split()
p_toks = p.split()
return len(set(t_toks).intersection(set(p_toks)))
assert f(
"this is a test",
"this is test"
) == 3 |
benchmark_functions_edited/f13587.py | def f(y, m, d):
y -= m<3
return (y + y//4 - y//100 + y//400 + ord('-bed=pen+mad.'[m]) + d) % 7
assert f(1997, 2, 6) == 4 |
benchmark_functions_edited/f2295.py | def f(string):
try:
return int(string)
except ValueError:
return float(string)
assert f(u'1') == 1 |
benchmark_functions_edited/f9581.py | def f(type):
if type == 'quoted':
return 0.6
if type == 'replied_to':
return 0.7
if type == 'retweeted':
return 0.1
# original tweet
return 1
assert f('original_tweet') == 1 |
benchmark_functions_edited/f3817.py | def f(x, threshold):
return 1. if x >= threshold else -1.
assert f(0.99999999, 0.5) == 1 |
benchmark_functions_edited/f4254.py | def f(r, eps, sig, m=12, n=6):
prefactor = (m / (m - n)) * (m / n) ** (n / (m - n))
return prefactor * eps * ((sig / r) ** m - (sig / r) ** n)
assert f(1, 1, 1) == 0 |
benchmark_functions_edited/f9695.py | def f(blocks, usage):
if blocks is None:
return 0
end = 0
for b in blocks:
if b.usage != usage:
continue
e = b.offset + b.size
if e > end:
end = e
# return the size
return end
assert f([], "input") == 0 |
benchmark_functions_edited/f2595.py | def f(n):
res = 1
while n > 1:
res = res * n
n -= 1
return res
assert f(2) == 2 |
benchmark_functions_edited/f2588.py | def f(dct, key):
if key in dct.keys():
return dct[key]
else:
return None
assert f({"a":1, "b": 2, "c": 3}, "b") == 2 |
benchmark_functions_edited/f5535.py | def f(row, column):
return sum(range(row + column - 1)) + column
assert f(2, 2) == 5 |
benchmark_functions_edited/f1948.py | def f(l):
if "#" in str(l):
return 1
else:
return 0
assert f(" ") == 0 |
benchmark_functions_edited/f277.py | def f(z):
return (z >> 1) ^ (-(z & 1))
assert f(2) == 1 |
benchmark_functions_edited/f9267.py | def f(P):
#T:tuple[list[list[int]], list[list[int]]]
T = ([[]], [[]])
#M: list[list[int]]
#N: list[list[int]]
M,N = T
#K: list[list[int]]
#L: list[list[int]]
K, L = T
K.append(P)
#side effect
M[0].append(4)
return 0
assert f( [0,1,2,3] ) == 0 |
benchmark_functions_edited/f1005.py | def f(pivot, items):
return min(items, key=lambda x: abs(x - pivot))
assert f(1, [1, 4, 10]) == 1 |
benchmark_functions_edited/f13763.py | def f(x, minimum=None, maximum=None):
if minimum is not None and x < minimum:
return minimum
elif maximum is not None and x > maximum:
return maximum
else:
return x
assert f(5, 1, 4) == 4 |
benchmark_functions_edited/f10558.py | def f(t_str: str) -> float:
rows = t_str.split('\n')[2:-1]
base = rows[-1].count(' ')
height = sum(map(lambda string: ' ' in string, rows))
return (base * height) / 2
assert f(
) == 2 |
benchmark_functions_edited/f3304.py | def f(file_names):
return int(file_names[-1].split("_v")[1].split(".tar")[0])
assert f(
["model_v0.tar", "model_v1.tar", "model_v2.tar"]) == 2 |
benchmark_functions_edited/f3755.py | def f(m, b, y):
return (y - b) / m
assert f(1, 40, 42) == 2 |
benchmark_functions_edited/f845.py | def f(x, lower, upper):
return min(max(x, lower), upper)
assert f(1, 1, 3) == 1 |
benchmark_functions_edited/f3874.py | def f(intensities, forecast_interval_mins):
return sum(map(lambda mm_h: forecast_interval_mins*(mm_h/60), intensities))
assert f([], 42) == 0 |
benchmark_functions_edited/f7670.py | def f(p, nr_steps):
nr_steps += 1
if (p <= 1):
return nr_steps
if p % 2 == 0:
return f(int(p/2), nr_steps)
else:
return f(int(3*p + 1), nr_steps)
assert f(1, 1) == 2 |
benchmark_functions_edited/f985.py | def f(k):
if k == 0:
return 1
return 2*(3**(k-1))
assert f(2) == 6 |
benchmark_functions_edited/f1454.py | def f(n):
a, b = 0, 1
for i in range(1, n + 1):
a, b = b, a + b
return b
assert f(1) == 1 |
benchmark_functions_edited/f8929.py | def f(t, x):
dx = t * x ** 2
return dx
assert f(1, 0) == 0 |
benchmark_functions_edited/f6094.py | def f(a, b):
if a >= 0:
return a - b * ((a + a + b) // (b + b))
a = -a
return -(a - b * ((a + a + b) // (b + b)))
assert f(10, 10) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.