file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f5738.py
|
def f(a, b):
if a % b == 0:
return b
return f(b, a % b)
assert f(10, 2) == 2
|
benchmark_functions_edited/f9450.py
|
def f(a, m):
if a <= m // 2:
return a
return a - m
assert f(1, 3) == 1
|
benchmark_functions_edited/f4642.py
|
def f(x, f, *fs):
for f in [f, *fs]:
f(x)
return x
assert f(1, lambda x: x) == 1
|
benchmark_functions_edited/f3437.py
|
def f(window, *args, **kwargs):
return float(sum(w[1] for w in window))
assert f((), 0, 0, 0, 0, 0) == 0
|
benchmark_functions_edited/f9468.py
|
def f(N):
num = 0
while(N>0):
if (N & 1) == 1:
num += 1
N = N >> 1
return num
assert f(30) == 4
|
benchmark_functions_edited/f9276.py
|
def f(n, T):
if T[n]:
return T[n]
if n <= 1:
T[n] = n
else:
T[n] = f(n - 1, T) + f(n - 2, T)
return T[n]
assert f(4, [0] * 10) == 3
|
benchmark_functions_edited/f13804.py
|
def f(joule):
kwh = joule / (3.6 ** 10 ** -19)
return kwh
assert f(0) == 0
|
benchmark_functions_edited/f3732.py
|
def f(x):
if isinstance(x, float) and x.is_integer():
return int(x)
return x
assert f(1.0) == 1
|
benchmark_functions_edited/f7458.py
|
def f(tri, a, b):
for v in tri:
if v != a and v != b:
return v
return None
assert f( (2, 0, 1), 0, 2 ) == 1
|
benchmark_functions_edited/f12719.py
|
def f(name: str, value: str) -> int:
if int(value) not in [0, 1]:
raise AssertionError(
"Expected 0 or 1 for {}, but got `{}`".format(name, value))
return int(value) == 1
assert f(
"assert_bool", "1") == 1
|
benchmark_functions_edited/f9573.py
|
def f(item):
if not item:
return item
return {
"type": "type" in item and item["type"],
"key": "key" in item and item["key"],
"props": "props" in item and item["props"],
"dom": "dom" in item and item["dom"] and True,
}
assert f(0) == 0
|
benchmark_functions_edited/f263.py
|
def f(f, fo, m):
return 1./(1+(f/fo)**m)
assert f(0, 1, 1) == 1
|
benchmark_functions_edited/f13381.py
|
def f(permutation, j):
for i, pi in enumerate(permutation):
if pi == j:
return i
raise ValueError("f({}, {}) failed.".format(permutation, j))
assert f(list(range(3)), 2) == 2
|
benchmark_functions_edited/f504.py
|
def f(base, height):
return (base*height)/2
assert f(2, 2) == 2
|
benchmark_functions_edited/f9282.py
|
def f(word1, word2):
assert len(word1) == len(word2)
count = 0
for c1, c2 in zip(word1, word2):
if c1 != c2:
count += 1
return count
assert f(
'a', 'a') == 0
|
benchmark_functions_edited/f2941.py
|
def f(x, lowerlimit, upperlimit):
if x < lowerlimit:
x = lowerlimit
if x > upperlimit:
x = upperlimit
return x
assert f(1, 0, 2) == 1
|
benchmark_functions_edited/f6664.py
|
def f(p, ptied = None):
if (ptied == None): return p
for i in range(len(ptied)):
if ptied[i] == '': continue
cmd = 'p[' + str(i) + '] = ' + ptied[i]
exec(cmd)
return p
assert f(1, '') == 1
|
benchmark_functions_edited/f13848.py
|
def f(h1, h2):
str_class = ""
if h1 == 0 and h2 == 0:
str_class = 0
elif h1 == 0 and h2 == 1:
str_class = 1
elif h1 == 1 and h2 == 0:
str_class = 2
elif h1 == 1 and h2 == 1:
str_class = 3
return str_class
assert f(0, 0) == 0
|
benchmark_functions_edited/f5176.py
|
def f(l:list):
if len(l) == 0:
return 0
else:
i = l.pop()
return i + f(l)
assert f([0, -1, 3]) == 2
|
benchmark_functions_edited/f1509.py
|
def f(value):
if isinstance(value, str):
return ord(value)
return value
assert f(chr(1)) == 1
|
benchmark_functions_edited/f12303.py
|
def f(category: str) -> int:
# Currently implementing art and journals only.
type_ids = {
"art": 1,
"journal": 1
}
return type_ids.get(category, 0)
assert f("art") == 1
|
benchmark_functions_edited/f2152.py
|
def f(option):
return len(option) if isinstance(option, list) else 1
assert f(["a", "b", "c"]) == 3
|
benchmark_functions_edited/f2261.py
|
def f(v1, v2):
return sum([i * j for i, j in zip(v1, v2)])
assert f([0, 0, 0], [4, 5, 6]) == 0
|
benchmark_functions_edited/f288.py
|
def f(b, h):
return 1 / 12. * b * h ** 3
assert f(0, 1) == 0
|
benchmark_functions_edited/f14186.py
|
def f(distance, threshold, coefficient):
assert distance >= 0 and threshold > 0 and coefficient < 0
constant = -threshold * coefficient
return max(distance * coefficient + constant, 0)
assert f(10, 10, -1) == 0
|
benchmark_functions_edited/f7972.py
|
def f(x: int, y: int) -> int:
result = x + y
return(len(str(result)))
assert f(9, 99) == 3
|
benchmark_functions_edited/f3415.py
|
def f(lis1):
if not lis1:
return 0
else:
return 1
assert f([1]) == 1
|
benchmark_functions_edited/f1986.py
|
def f(a, b):
return (a[0] - b[0])**2 + (a[1] - b[1])**2
assert f( (1, 1), (2, 2) ) == 2
|
benchmark_functions_edited/f3656.py
|
def f(sol, d):
if not d: return 0
return sum( d[n] for n in sol )
assert f( [1,2,3], {1:2, 2:1, 3:3} ) == 6
|
benchmark_functions_edited/f11166.py
|
def f(query_seq, q_seq):
q_seq = q_seq.replace("-", "")
q_start = query_seq.find(q_seq)
q_stop = q_start + len(q_seq) - 1
return(q_stop)
assert f( "AAA", "AAA") == 2
|
benchmark_functions_edited/f9348.py
|
def f(trace: list, prefix_length: int):
if prefix_length < len(trace):
next_event = trace[prefix_length]
name = next_event['concept:name']
return name
else:
return 0
assert f(list(range(10)), 10) == 0
|
benchmark_functions_edited/f4545.py
|
def f(n):
if not n:
return 0
t = 0
while not n & 1:
n >>= 1
t += 1
return t
assert f(0x80000001) == 0
|
benchmark_functions_edited/f588.py
|
def f(n):
if n == 0:
return 1
return n * f(n - 1)
assert f(1) == 1
|
benchmark_functions_edited/f6133.py
|
def f(n: int) -> int:
return sum([i for i in range(1, n+1)])**2 - sum([i**2 for i in range(1, n+1)])
assert f(0) == 0
|
benchmark_functions_edited/f1618.py
|
def f(x, i: int, times_two=False):
mult = 2 if times_two else 1
return mult*x**i
assert f(2, 3) == 8
|
benchmark_functions_edited/f11151.py
|
def f(some_list, current_index):
try:
return some_list[int(current_index) + 1]
except:
pass
assert f(list(range(10)), 1) == 2
|
benchmark_functions_edited/f12032.py
|
def f(budget: float, denomination: int) -> int:
return int(budget / denomination)
assert f(1, 1) == 1
|
benchmark_functions_edited/f10939.py
|
def f(n: int) -> int:
if n == 0:
return 0
if n == 1:
return 1
f_n2, f_n1 = 1, 1
for _ in range(3, n+1):
f_n2, f_n1 = f_n1, f_n2+f_n1
return f_n1
assert f(0) == 0
|
benchmark_functions_edited/f13995.py
|
def f(test):
# IMPLEMENT THIS FUNCTION
x=0
while True:
if test(x):
return x
if test(-1*x):
return -1*x
x+=1
return x
assert f(lambda x: x%47==0) == 0
|
benchmark_functions_edited/f3067.py
|
def f(limit):
return sum([i ** 2 for i in range(limit+1)])
assert f(1) == 1
|
benchmark_functions_edited/f7439.py
|
def f(f1, f2, *a, **k):
return f2(f1(*a, **k))
assert f(str, int, 2) == 2
|
benchmark_functions_edited/f13671.py
|
def f(l_in: int, padding: int, dilation: int, kernel: int, stride: int) -> int:
return (l_in + 2 * padding - dilation * (kernel - 1) - 1) // stride + 1
assert f(3, 1, 1, 1, 1) == 5
|
benchmark_functions_edited/f5228.py
|
def f(context, obj):
if hasattr(obj, "__moyacontext__"):
return obj.__moyacontext__(context)
return obj
assert f(None, 1) == 1
|
benchmark_functions_edited/f1846.py
|
def f(v, lo, hi):
return lo if v < lo else (hi if v > hi else v)
assert f(3, 2, 3) == 3
|
benchmark_functions_edited/f14182.py
|
def f(ticket):
if "STON" in ticket:
return 0
elif "C.A." in ticket or "CA" in ticket:
return 1
elif "SOTON" in ticket:
return 2
elif "F.C." in ticket:
return 3
elif "A/" in ticket:
return 4
elif "SC" in ticket:
return 5
elif "PC" in ticket:
return 6
elif "S.O." in ticket:
return 7
return 8
assert f('S.O. 23434') == 7
|
benchmark_functions_edited/f14017.py
|
def f(a, i, j, k):
ai, aj, ak = a[i], a[j], a[k]
med_val = ai + aj + ak - max(ai, aj, ak) - min(ai, aj, ak)
if ai == med_val:
return i
elif aj == med_val:
return j
return k
assert f(range(10), 0, 5, 7) == 5
|
benchmark_functions_edited/f4266.py
|
def f(value):
try:
return int(value)
except:
return 0
assert f(True) == 1
|
benchmark_functions_edited/f11865.py
|
def f(a, b):
c = a * b # It is a good practice to always allocate calculated value to a local variable instead of chaining to return or another function
return c
assert f(1, 0) == 0
|
benchmark_functions_edited/f12200.py
|
def f(a, b):
assert a>0 and b>0
if a<=b:
return a
for k in range(0, a-b+1):
bh = b + k
if bh>1 and a % bh == 0:
return bh
bh = b - k
if bh>1 and a % bh == 0:
return bh
return a
assert f(5, 20) == 5
|
benchmark_functions_edited/f7430.py
|
def f(x1: float, x3: float, y1: float, y2: float, y3: float):
return (y2 - y3) / (y1 - y3) * (x1 - x3) + x3
assert f(1, 1, 1, 2, 3) == 1
|
benchmark_functions_edited/f9665.py
|
def f(a_c1, a_c2):
return 2 if a_c1[-1] == a_c2[-1] else -3
assert f(
"dependent",
"independent"
) == 2
|
benchmark_functions_edited/f8941.py
|
def f(a, fa, fpa, b, fb):
D = fa
C = fpa
db = b - a
B = (fb - D - C * db) / (db ** 2)
xmin = a - C / (2. * B)
return xmin
assert f(0, 1, 0, 1, 2) == 0
|
benchmark_functions_edited/f6751.py
|
def f(wire_coords, point):
dist = 0
for coord in wire_coords:
dist += 1
if coord == point:
break
return dist
assert f([(0, 0), (0, 1), (0, 2)], (0, 3)) == 3
|
benchmark_functions_edited/f7239.py
|
def f(value, exception = ValueError):
newvalue = int(value) #The exception may get raised here by the int function if needed
if newvalue < 0:
raise exception
return newvalue
assert f(0.7) == 0
|
benchmark_functions_edited/f468.py
|
def f(x):
return x.real**2 + x.imag**2
assert f(-1j) == 1
|
benchmark_functions_edited/f5525.py
|
def f(a, b):
if b == 0:
return a
else:
return f(b, a % b)
assert f(10, 3) == 1
|
benchmark_functions_edited/f12306.py
|
def f(min, max, v):
if min > max:
raise RuntimeError("Min value (%f) larger than max (%f)" % (min, max))
if v < min: # V below range: return min
return min
elif v < max: # v within range: return v
return v
else: # v above range: return max
return max
assert f(2, 4, 5) == 4
|
benchmark_functions_edited/f10873.py
|
def f(n):
# create a list for dynamic progamming
dp = [x for x in range(n+1)]
current = 2
while current ** 2 <= n:
for i in range(current**2, n+1):
dp[i] = min(dp[i], dp[i-current**2]+1)
current += 1
return dp[-1]
assert f(27) == 3
|
benchmark_functions_edited/f3820.py
|
def f(line):
for i in range(4):
if line[i] != '#':
return i
return 3
assert f(
'## this is a heading ##'
) == 2
|
benchmark_functions_edited/f3501.py
|
def f(n: int, k: int) -> int:
ntok = 1
for t in range(min(k, n - k)):
ntok = ntok * (n - t) // (t + 1)
return ntok
assert f(4, 4) == 1
|
benchmark_functions_edited/f4926.py
|
def f(pos, list_):
fuel = [(abs(pos - i)*(abs(pos-i)+1))/2 for i in list_]
return sum(fuel)
assert f(1, [2]) == 1
|
benchmark_functions_edited/f7389.py
|
def f(data):
return 10**(data/10.)
assert f(0) == 1
|
benchmark_functions_edited/f8980.py
|
def f(number):
special_non_primes = [0, 1, 2]
if number in special_non_primes[:2]:
return 2
elif number == special_non_primes[-1]:
return 3
return all([number % i for i in range(2, number)])
assert f(2) == 3
|
benchmark_functions_edited/f9631.py
|
def f(line):
return int(line.strip().split('\t')[1])
assert f(
"sys_write\t2") == 2
|
benchmark_functions_edited/f12595.py
|
def f(s):
if s == "":
return 0
else:
return f(s[1:]) + 1
assert f( '123456789' ) == 9
|
benchmark_functions_edited/f4080.py
|
def f(array):
import numpy as np
array=np.array(array)
result= np.std(array)
return result
assert f([1, 1, 1, 1]) == 0
|
benchmark_functions_edited/f1263.py
|
def f(x, y):
return -(-x // y)
assert f(0, 2) == 0
|
benchmark_functions_edited/f14469.py
|
def f(int_method):
#Pick integrator
if int_method.lower() == 'rk4_c':
int_method_c= 1
elif int_method.lower() == 'rk6_c':
int_method_c= 2
elif int_method.lower() == 'symplec4_c':
int_method_c= 3
elif int_method.lower() == 'symplec6_c':
int_method_c= 4
elif int_method.lower() == 'dopr54_c':
int_method_c= 5
else:
int_method_c= 0
return int_method_c
assert f('Symplec4') == 0
|
benchmark_functions_edited/f6788.py
|
def f(traj):
num = traj.split(".")[0].split("_")[-1]
return int(num)
assert f("3.pdb") == 3
|
benchmark_functions_edited/f5689.py
|
def f(value):
return int(round(value / (1024.0 * 1024.0), 0))
assert f(1024 * 1024) == 1
|
benchmark_functions_edited/f9591.py
|
def f(n: int) -> int:
assert n >= 0, 'n must not be negative!'
return int(n * (n + 1) / 2)
assert f(3) == 6
|
benchmark_functions_edited/f5751.py
|
def f(data: bytes, offset: int) -> int:
return int.from_bytes(data[offset:offset + 2], byteorder="big", signed=False)
assert f(b'\x00\x00', 0) == 0
|
benchmark_functions_edited/f6481.py
|
def f(iterable):
try:
return max(iterable)
except ValueError:
return 0
assert f((i for i in range(10))) == 9
|
benchmark_functions_edited/f2395.py
|
def f(y, z, x0, y0, z0, ax, ay, az):
return ax * (((y - y0) / ay)**2 + ((z - z0) / az)**2) + x0
assert f(0, 0, 0, 0, 0, 2, 1, 1) == 0
|
benchmark_functions_edited/f627.py
|
def f(x, i):
return (x >> i) & 1 != 0
assert f(0x1, 7) == 0
|
benchmark_functions_edited/f7788.py
|
def f(limit):
return (limit * (limit + 1)) // 2 if limit >= 0 else 0
assert f(0.5) == 0
|
benchmark_functions_edited/f6350.py
|
def f(n: int) -> int:
if n == 0:
return 1
f = 1
for i in range(2, n):
f = f*i
return f
assert f(0) == 1
|
benchmark_functions_edited/f8746.py
|
def f(i, n):
mask = 2**(n-1)
count = 1
for k in range(n):
if (mask & i) > 0:
count += 1
mask >>= 1
else:
break
return min(count, n)
assert f(1, 1) == 1
|
benchmark_functions_edited/f2586.py
|
def f(passed, default):
return passed if passed is not None else default
assert f(5, 7) == 5
|
benchmark_functions_edited/f13931.py
|
def f(gender_1: str, gender_2: str):
if gender_1 == gender_2:
return 0
elif gender_1 is None or gender_2 is None:
return 0
elif gender_1 == "" or gender_2 == "":
return 0
else:
return -1
assert f("F", "") == 0
|
benchmark_functions_edited/f10645.py
|
def f(input_list):
try:
n = input_list.Count
except:
n = len(input_list)
return n
assert f( ["a", "b", "c", "d", "e", "f", "g"] ) == 7
|
benchmark_functions_edited/f10102.py
|
def f(adapters):
jolt1 = 0
jolt3 = 0
for i in range(len(adapters) - 1):
diff = adapters[i+1] - adapters[i]
if diff == 1:
jolt1 += 1
if diff == 3:
jolt3 += 1
print(f"Found {jolt1} jolt1 and {jolt3} jolt3")
return jolt1 * jolt3
assert f(sorted([3,2,1])) == 0
|
benchmark_functions_edited/f1050.py
|
def f(u, v):
return sum(uu * vv for uu, vv in zip(u, v))
assert f((), ()) == 0
|
benchmark_functions_edited/f5189.py
|
def f(num: int) -> int:
if num < 0:
return 32
count: int = 0
while num > 0:
num >>= 1 # Removes one bit from integer
count += 1
return count
assert f(14) == 4
|
benchmark_functions_edited/f12582.py
|
def f(bus_stop_osm_id, bus_stop_osm_ids, start):
bus_stop_index = -1
for i in range(start, len(bus_stop_osm_ids)):
if bus_stop_osm_ids[i] == bus_stop_osm_id:
bus_stop_index = i
break
return bus_stop_index
assert f(3, [1, 3, 5, 7], 0) == 1
|
benchmark_functions_edited/f14296.py
|
def f(batch):
if isinstance(batch, tuple):
return f(batch[0])
else:
if isinstance(batch, list):
return len(batch)
else:
return batch.shape[0]
assert f([(1, 2, 3), (4, 5, 6)]) == 2
|
benchmark_functions_edited/f9775.py
|
def f(FP, neg):
if neg == 0:
return 0
else:
return FP / neg
assert f(5, 1) == 5
|
benchmark_functions_edited/f10380.py
|
def f(sell_order, buy_order):
sell_units = sell_order['volume_remain']
buy_units = buy_order['volume_remain']
return min(sell_units, buy_units)
assert f(
{'volume_remain': 0},
{'volume_remain': 30}
) == 0
|
benchmark_functions_edited/f7124.py
|
def f(number):
if number is None or number == 0:
return 0
number = int(number)
return '{:20,}'.format(number)
assert f(None) == 0
|
benchmark_functions_edited/f2569.py
|
def f(recons_func, **kwargs):
return recons_func(**kwargs)
assert f(lambda: 3) == 3
|
benchmark_functions_edited/f8080.py
|
def f(a, b, n):
c = 0
d = 1
for bi in bin(b)[2:]:
c = 2 * c
d = (d * d) % n
if bi == '1':
c += 1
d = (d * a) % n
return d
assert f(1, 2, 3) == 1
|
benchmark_functions_edited/f10903.py
|
def f(loci, **kwargs):
# Locus of the Joint 'pin"
tip_locus = tuple(x[0] for x in loci)[0]
return (tip_locus[0] - 3) ** 2 + tip_locus[1] ** 2
assert f(list(zip(
[(0, 0), (1, 0), (2, 0), (3, 0)],
[(2, 1), (1, 2), (0, 3), (1, 4)]
))) == 9
|
benchmark_functions_edited/f14555.py
|
def f(seq, target):
head, tail = 0, len(seq) - 1
while head <= tail:
# for cython, use
# mid = head + ((tail - head) / 2)
mid = (head + tail) >> 1
num = seq[mid]
if num == target:
return mid
elif num < target:
head = mid + 1
else:
tail = mid - 1
assert f([1], 1) == 0
|
benchmark_functions_edited/f6819.py
|
def f(x: float, a: float, b: float) -> float:
if a >= b:
raise ValueError("Incorrect interval ends.")
y = (x - a) % (b - a)
return y + b if y < 0 else y + a
assert f(2, 0, 1) == 0
|
benchmark_functions_edited/f13065.py
|
def f(input_list, item):
# Find mid index.
first = 0
last = len(input_list) - 1
while first <= last:
mid_ix = (first + last) // 2
if input_list[mid_ix] == item:
return mid_ix
elif input_list[mid_ix] < item:
first = mid_ix + 1
else:
last = mid_ix - 1
return None
assert f(
[1, 3, 5, 7, 9],
9
) == 4
|
benchmark_functions_edited/f12732.py
|
def f(knot=-1, knotvector=(), tol=0.001):
# Find and return the multiplicity of the input knot in the given knot vector
mult = 0 # initial multiplicity
# Loop through the knot vector
for kv in knotvector:
# Float equality should be checked w.r.t a tolerance value
if abs(knot - kv) <= tol:
mult += 1
return mult
assert f(0, [0.0, 1.0, 2.0, 3.0, 4.0]) == 1
|
benchmark_functions_edited/f14295.py
|
def f(iterable, default=False, pred=None):
# f([a, b, c], x) --> a or b or c or x
# f([a, b], x, f) --> a if f(a) else b if f(b) else x
iterable_internal = iter(filter(pred, iterable))
return next(iterable_internal, default)
assert f([1, 2, 3], 10, lambda x: x < 3) == 1
|
benchmark_functions_edited/f14444.py
|
def f(ek, m):
import math
v = math.sqrt((2 * ek) / m)
return v
assert f(0, 1) == 0
|
benchmark_functions_edited/f7153.py
|
def f(date):
return 0 if date.split('/')[0] == '2010' else int(date.split('/')[1])
assert f('2010/01/01') == 0
|
benchmark_functions_edited/f5836.py
|
def f(cache, key, fcn, force=False):
if cache is None:
cache = {}
if force or (key not in cache):
cache[key] = fcn()
return cache[key]
assert f({1: 1}, 1, lambda: 2) == 1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.