file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f4408.py
|
def f(x):
if x < 0.5:
return 2*x**2
else:
return 1/2 - x*(2*x-2)
assert f(0.0) == 0
|
benchmark_functions_edited/f7689.py
|
def f(s1, s2):
assert len(s1) == len(s2)
return sum([ch1 != ch2 for ch1, ch2 in zip(s1, s2)])
assert f( 'a', 'a') == 0
|
benchmark_functions_edited/f1225.py
|
def f(a,b):
while b != 0:
q, r = divmod(a,b)
a,b = b, r
return a
assert f(2,1) == 1
|
benchmark_functions_edited/f13068.py
|
def f(obj, method_name, initial_val, *args, **kwargs):
result = initial_val
current = obj
while current is not None:
method = getattr(current, method_name, None)
if method:
result = method(result, *args, **kwargs)
current = getattr(current, "child", None)
return result
assert f(None, "init", 1) == 1
|
benchmark_functions_edited/f2876.py
|
def f(w, L):
return 1j * w * L
assert f(0.0, 1.0) == 0
|
benchmark_functions_edited/f11921.py
|
def f(bit_fields):
num_buckets, cur_bucket = 0, 0
for field in bit_fields:
if field.size + cur_bucket > 32:
num_buckets += 1
cur_bucket = 0
cur_bucket += field.size
return num_buckets + (cur_bucket > 0)
assert f(
[]) == 0
|
benchmark_functions_edited/f580.py
|
def f(value, align):
return int(int((value + align - 1) / align) * align)
assert f(1, 1) == 1
|
benchmark_functions_edited/f1371.py
|
def f(value):
return int(round((value + 1.0)*127.5))
assert f(-1.0) == 0
|
benchmark_functions_edited/f8615.py
|
def f(args):
rosen = 0
for i in range(len(args) - 1):
rosen += 10.0*((args[i]**2) - args[i + 1])**2 + (1 - args[i])**2
return rosen
assert f( (1, 1) ) == 0
|
benchmark_functions_edited/f12425.py
|
def f(rows, only_variant_to_process=True):
stay_unchanged = {row['Will stay unchanged'] for row in rows}
return sum([
int(row['Number Of Variants (submitted variants)'].replace(',', ''))
for row in rows
if not only_variant_to_process or ('no' in stay_unchanged and row['Source'] != 'DBSNP - filesystem')
])
assert f(
[
{'Will stay unchanged': 'no', 'Source': 'DBSNP - filesystem'},
]
) == 0
|
benchmark_functions_edited/f9657.py
|
def f(digit_string):
m = 0
for d in digit_string:
m = (m * 10 + int(d)) % 97
return m
assert f(u'0') == 0
|
benchmark_functions_edited/f9776.py
|
def f(*args):
print(type(args))
print("args is {}".format(args))
# *args is unpacked tuple
print("*args is ", *args)
mean = 0
for arg in args:
mean += arg
return mean / len(args)
assert f(4) == 4
|
benchmark_functions_edited/f890.py
|
def f(listed):
count = 0
for item in listed:
count += 1
return count
assert f([4]) == 1
|
benchmark_functions_edited/f12677.py
|
def f( i, j ):
if i == j:
return 1
else:
return 0
assert f( 2, 2 ) == 1
|
benchmark_functions_edited/f1466.py
|
def f(i1 : int, i2 : int):
return bin(i1 ^ i2).count("1")
assert f(1, 2) == 2
|
benchmark_functions_edited/f6474.py
|
def f(v):
if v:
try:
return int(float(v))
except:
return v
return ""
assert f("0") == 0
|
benchmark_functions_edited/f7220.py
|
def f(zamid):
s = int(zamid[-1])
return s
assert f( '922357' ) == 7
|
benchmark_functions_edited/f4817.py
|
def f(refs, refname):
for i, ref in enumerate(refs):
if ref == refname:
return i
return -1
assert f(
["A","B","C"],
"A"
) == 0
|
benchmark_functions_edited/f12866.py
|
def f(numbers):
max_value = 0
result = 0
for i in numbers:
current_value = abs(float(i))
if current_value > max_value:
max_value = current_value
result = numbers.index(i)
return result
assert f(
[10, 2, -100, -200]
) == 3
|
benchmark_functions_edited/f8626.py
|
def f(old_key: str, collection: dict) -> str:
counter = 2
new_key = old_key
while new_key in collection:
new_key = f"{old_key}{counter}"
counter += 1
return new_key
assert f(0, {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}) == 0
|
benchmark_functions_edited/f7431.py
|
def f(scale):
if scale <= 1:
return 1
elif scale <= 2:
return 2
elif scale <= 4:
return 4
else :
return 8
assert f(7) == 8
|
benchmark_functions_edited/f5994.py
|
def f(bins, x):
x = x % sum(bins)
idx = -1
while x >= 0:
x -= bins[idx]
if x >= 0:
idx += 1
return idx
assert f([1,2,3], 5) == 1
|
benchmark_functions_edited/f2003.py
|
def f(arr):
if len(arr) == 0:
return 1
return arr[0] * f(arr[1:])
assert f([1]) == 1
|
benchmark_functions_edited/f7202.py
|
def f(clues):
return sum([clue.getCount() for clue in clues])
assert f(list()) == 0
|
benchmark_functions_edited/f6529.py
|
def f(size):
if size == 2:
return 2
if size == 3:
return 4
if size == 4:
return 11
if size == 5:
return 34
assert f(2) == 2
|
benchmark_functions_edited/f12566.py
|
def f(f, *args):
if len(args) > 1:
return f(*args)
return lambda *args: f(*args)
assert f(lambda x, y, z, *args: x + y + z, 1, 2, 3) == 6
|
benchmark_functions_edited/f12757.py
|
def f(length: int, window: int) -> int:
return (window - (length % window)) % window
assert f(2, 2) == 0
|
benchmark_functions_edited/f813.py
|
def f(a0, a1, a2, a3 ,a4 , x):
return a0 + x*(a1+x*(a2+x*(a3+x*a4)))
assert f(1, 2, 3, 4, 5, 0) == 1
|
benchmark_functions_edited/f13161.py
|
def f(used_markers):
new_marker = 1
while new_marker in used_markers:
new_marker += 1
return new_marker
assert f({1, 2}) == 3
|
benchmark_functions_edited/f6932.py
|
def f(row, name):
for index, item in enumerate(row):
if item == name:
return index
return -1
pass
assert f(
['Date', 'High', 'Low', 'Open', 'Close', 'Volume'], 'Volume'
) == 5
|
benchmark_functions_edited/f10647.py
|
def f(meta, key, none_subst=dict):
ret = meta.get(key)
return ret if (ret is not None) else none_subst()
assert f({'foo': 1}, 'foo') == 1
|
benchmark_functions_edited/f4400.py
|
def f(at):
return int(at[at.find('.') + 1:])
assert f('month.1') == 1
|
benchmark_functions_edited/f10147.py
|
def f(start, end, frac):
return (end - start) * frac + start
assert f(1, 1, 0.2) == 1
|
benchmark_functions_edited/f4788.py
|
def f(n: int) -> int:
assert n > 0
r = 0
t = 1
while t < n:
t = 2 * t
r = r + 1
return r
assert f(13) == 4
|
benchmark_functions_edited/f2854.py
|
def f(runs_str, idx):
return max([len(r[idx]) for r in runs_str])
assert f(
[["a", "b", "c"], ["a", "bb", "ccc"], ["dddd", "e", ""]], 1) == 2
|
benchmark_functions_edited/f10415.py
|
def f(value, d):
if len(d) == 0:
return 0
return sum(d < value) / len(d)
assert f(5, []) == 0
|
benchmark_functions_edited/f7373.py
|
def f(f: int) -> int:
x = f-1
return 8*x**3 + 36*x**2 + 52*x + 24
assert f(0) == 0
|
benchmark_functions_edited/f4217.py
|
def f(n: int, radix_bits: int) -> int:
return (n + radix_bits - 1) // radix_bits
assert f(10, 10) == 1
|
benchmark_functions_edited/f2218.py
|
def f(nums):
i = 0
for num in nums:
i ^= num
return i
assert f(list(range(1,10))) == 1
|
benchmark_functions_edited/f3448.py
|
def f(a=0, b=1):
if a == 0 or b == 0:
c = 1
else:
c = 0
print(c)
return c
assert f(0) == 1
|
benchmark_functions_edited/f3880.py
|
def f(A, B):
while B != 0:
rem = A % B
A = B
B = rem
return A
assert f(10, 6) == 2
|
benchmark_functions_edited/f3839.py
|
def f(a, b):
a.sort(), b.sort()
return max(0, min(a[1], b[1]) - max(a[0], b[0]))
assert f(
[1, 2],
[3, 5]
) == 0
|
benchmark_functions_edited/f6589.py
|
def f(values, v):
count = 0.0
for idx, v0 in enumerate(values):
if v0 < v:
count += 1
return count / len(values)
assert f(range(10), 11) == 1
|
benchmark_functions_edited/f13495.py
|
def f(nplayers, repetitions):
return repetitions * (nplayers - 1)
assert f(2, 1) == 1
|
benchmark_functions_edited/f13790.py
|
def f(n):
# Creates variables that will become the answer
i = 0
j = 1
n = n - 1
# Keeps looping through numbers that are greater than 0
while n >= 0:
# Variables on right of'=' are calculated first, then assigned to left of '='
i, j = j, i + j
# Acts as a counter for loop, each loop n is de-incremented by 1
n = n - 1
# When loop ends, return i
return i
assert f(0) == 0
|
benchmark_functions_edited/f14234.py
|
def f(permutation):
n = 0
for i in range(len(permutation)):
if permutation[i] == i:
n += 1
return n
assert f((0, 2, 1)) == 1
|
benchmark_functions_edited/f2454.py
|
def f(x):
return x**2 + 5
assert f(1.0) == 6
|
benchmark_functions_edited/f4886.py
|
def f(context, mapping):
# just hosts documentation; should be overridden by template mapping
return 0
assert f(None, {}) == 0
|
benchmark_functions_edited/f2292.py
|
def f(ns):
result = 1
for n in ns:
result *= n
return result
assert f([1]) == 1
|
benchmark_functions_edited/f9415.py
|
def f(gwei: float) -> float:
if isinstance(gwei, str):
gwei = float(gwei)
return gwei / 1000000000000000000
assert f(0) == 0
|
benchmark_functions_edited/f11545.py
|
def f(logfile: str) -> int:
try:
with open(logfile) as file_handle:
return sum(1 for i in file_handle)
except FileNotFoundError:
return 0
assert f("/non/existing/log/file.txt") == 0
|
benchmark_functions_edited/f10934.py
|
def f(matrix):
possible_celeb = 0
for p in range(1, len(matrix)):
if (matrix[possible_celeb][p]
or not matrix[p][possible_celeb]):
possible_celeb = p
return possible_celeb
assert f([[True]]) == 0
|
benchmark_functions_edited/f13295.py
|
def f(avg_latency, std_latency, recency):
return avg_latency - (recency - std_latency)
assert f(14, 1, 14) == 1
|
benchmark_functions_edited/f5381.py
|
def f(h: dict, k: str):
try:
iter(h)
except TypeError:
return ''
else:
return h[k] if k in h else ''
assert f(
{'a': {'aa': 11, 'ab': 12}, 'b': 2},
'b'
) == 2
|
benchmark_functions_edited/f6383.py
|
def f(individual):
return sum(x**2 for x in individual)
assert f((1,)) == 1
|
benchmark_functions_edited/f7766.py
|
def f(characters):
return -1 if not characters else sum((2*i+1)**2 for i in range(len(characters)))
assert f("A") == 1
|
benchmark_functions_edited/f2845.py
|
def f(gen):
counter = 0
for _ in gen:
counter += 1
return counter
assert f(range(0)) == 0
|
benchmark_functions_edited/f11006.py
|
def f(value, types=None):
if value[0] in '\'"':
return value[1:-1]
if types is None:
types = int, float, str
for typ in types:
try:
return typ(value)
except (ValueError, TypeError, UnicodeEncodeError):
pass
return value
assert f('1', (int, str)) == 1
|
benchmark_functions_edited/f153.py
|
def f(a):
return 2*(a-0.5)
assert f(0.5) == 0
|
benchmark_functions_edited/f4600.py
|
def f(x, sigma):
x_squared = x ** 2
sigma_squared = sigma ** 2
return (sigma_squared * x_squared) / (sigma_squared + x_squared)
assert f(0, 5) == 0
|
benchmark_functions_edited/f4391.py
|
def f(boutlist):
total_time = boutlist[-1]
return total_time
assert f(range(10)) == 9
|
benchmark_functions_edited/f9194.py
|
def f(I1p, I2p):
q_cl = 45.0 * 1e-3 # W/A
return round(6. * q_cl * (I1p + I2p), 2)
assert f(0.0, 0.0) == 0
|
benchmark_functions_edited/f9662.py
|
def f(island_list):
sorted = 1;
for index in range(0, len(island_list)-1):
if island_list[index].start> island_list[index+1].start:
sorted = 0;
return sorted;
assert f([]) == 1
|
benchmark_functions_edited/f8547.py
|
def f(a, b):
if b == 0:
return a
else:
return f(b, a % b)
assert f(0, 0) == 0
|
benchmark_functions_edited/f10789.py
|
def f(year):
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
return 1
else:
return 0
else:
return 1
else:
return 0
assert f(2034) == 0
|
benchmark_functions_edited/f2416.py
|
def f(level: int, *, fanout: int) -> int:
return (fanout ** (level + 1) - 1) // (fanout - 1)
assert f(**{'level': 1, 'fanout': 2}) == 3
|
benchmark_functions_edited/f9923.py
|
def f(dictionary, key):
if key in dictionary:
value = dictionary[key]
return value
raise Exception("The config file is missing an entry with key {0}".format(key))
assert f(
{"key1": 1, "key2": 2, "key3": 3},
"key1"
) == 1
|
benchmark_functions_edited/f2948.py
|
def f(a,b):
if ((a != 0) and (b == 0)) or ((a == 0) and (b != 0)):
return 1
else:
return 0
assert f(0, 1) == 1
|
benchmark_functions_edited/f5354.py
|
def f(number):
if number not in range(1, 65):
raise ValueError("square must be between 1 and 64")
return 2 ** (number - 1)
assert f(3) == 4
|
benchmark_functions_edited/f11758.py
|
def f(cf): # pragma: no cover
if len(cf) == 1:
return cf[0]
else:
return cf[0] + 1 / f(cf[1:])
assert f([1]) == 1
|
benchmark_functions_edited/f14131.py
|
def f(xs, x1, x2):
xmin = min(x1, x2)
if xmin <= xs[0]:
return 0
elif xmin >= xs[-1]:
ll = len(xs) - 1
return ll
else:
for i, x in enumerate(xs):
if x > xmin:
ll = i - 1
return ll
ll = 0
return ll
assert f((1,), 0, 0.5) == 0
|
benchmark_functions_edited/f3570.py
|
def f(val):
if val is None:
return ''
return val
assert f(1) == 1
|
benchmark_functions_edited/f4847.py
|
def f(x, lowerIn, upperIn, lowerOut, upperOut):
y = (x - lowerIn) / (upperIn - lowerIn) * (upperOut - lowerOut) + lowerOut
return y
assert f(0, 0, 2, 1, 0) == 1
|
benchmark_functions_edited/f3812.py
|
def f(bs, count):
n = 0
while count:
n <<= 1
n |= next(bs)
count -= 1
return n
assert f(iter(range(0, 8)), 4) == 7
|
benchmark_functions_edited/f12047.py
|
def f(n, Ap, Ax):
norm = 0
for j in range(n):
s = 0
for p in range(Ap[j], Ap[j + 1]):
s += abs(Ax[p])
norm = max(norm, s)
return norm
assert f(2, [0, 2, 3], [0, 0, 0, 0, 0]) == 0
|
benchmark_functions_edited/f11936.py
|
def f(record:str, char="", digit=False):
if digit or char!="":
if digit:
n = len([k for k in record if k.isdigit()])
else:
n = len([k for k in record if k==char])
else:
raise ValueError("Please select a character")
return n
assert f(*['1234', 'a']) == 0
|
benchmark_functions_edited/f3546.py
|
def f(list_):
out = list_
while isinstance(out, list):
out = out[0]
return out
assert f([2]) == 2
|
benchmark_functions_edited/f7030.py
|
def f(adjList):
edges = {}
for id, neigh in enumerate(adjList):
for n in neigh:
edges[max(n, id), min(n, id)] = id
return len(edges)
assert f( [[], [], [], [], [0], [], [], []] ) == 1
|
benchmark_functions_edited/f5375.py
|
def f(x, y, goal, current_len):
goal_x, goal_y = goal
priority = current_len + abs(goal_x - x) + abs(goal_y - y)
return priority
assert f(0, 0, (2, 2), 0) == 4
|
benchmark_functions_edited/f9331.py
|
def f(seed_set_cascades):
combined = set()
for i in seed_set_cascades.keys():
for j in seed_set_cascades[i]:
combined = combined.union(j)
return len(combined)
assert f({}) == 0
|
benchmark_functions_edited/f1675.py
|
def f(amount):
return round(amount*.0022, 2)
assert f(0) == 0
|
benchmark_functions_edited/f8294.py
|
def f(sx, sy, ox, oy):
print((sx, sy, ox, oy))
if not (0 <= sx < ox and 0 <= sy < oy):
raise ValueError(f"{sx, sy} is not within (0, 0) and {ox, oy}!")
return sx + sy * ox
assert f(0, 0, 4, 4) == 0
|
benchmark_functions_edited/f4437.py
|
def f(name1, name2):
if name1 < name2:
return -1
else:
return 1
assert f(5, 4) == 1
|
benchmark_functions_edited/f9606.py
|
def f(nums, k):
count = 0
s = 0
for i in range(len(nums)):
s += nums[i]
if s % k == 0:
count += 1
return count
assert f([1, 2, 3], 3) == 2
|
benchmark_functions_edited/f10149.py
|
def f(values):
num = len(values)
sorted_vals = sorted(values)
midpoint = num // 2
if num % 2 == 1:
return sorted_vals[midpoint]
else:
low = midpoint - 1
high = midpoint
return (sorted_vals[low] + sorted_vals[high]) / 2
assert f([2, 3, 4]) == 3
|
benchmark_functions_edited/f3713.py
|
def f(x, b0, b1, b2, b3):
return b0 + b1 * x + b2 * x ** 2 + b3 * x ** 3
assert f(1, 0, 0, 0, 0) == 0
|
benchmark_functions_edited/f3942.py
|
def f(letter):
string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
return(string.index(letter) + 1)
assert f('A') == 1
|
benchmark_functions_edited/f53.py
|
def f(B, x):
return B*(x)
assert f(4, 1) == 4
|
benchmark_functions_edited/f3638.py
|
def f(a, b, **_):
s = 0
for t1, t2 in zip(a, b):
if t1 != t2:
s += 1
return s
assert f(
[1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 5, 6, 7, 8, 10]) == 1
|
benchmark_functions_edited/f14222.py
|
def f(start_miles, end_miles, amount_gallons):
distance = end_miles - start_miles
mpg = distance / amount_gallons
return mpg
assert f(18000, 20000, 1000) == 2
|
benchmark_functions_edited/f2838.py
|
def f(evals):
ev1, ev2, ev3 = evals
return ev1
assert f( (4,5,6) ) == 4
|
benchmark_functions_edited/f3520.py
|
def f(registers, opcodes):
return registers[opcodes[1]]
assert f(
[3, 2, 1],
[setr, 1, 2]
) == 2
|
benchmark_functions_edited/f8741.py
|
def f(tree):
if tree is None:
return 0
else:
l, v, r, b = tree
if b <= 0:
return f(l) + 1
else:
return f(r) + 1
assert f(None) == 0
|
benchmark_functions_edited/f2289.py
|
def f(bytes):
bytes = float(bytes)
megabytes = bytes / 1048576
return megabytes
assert f(0) == 0
|
benchmark_functions_edited/f10229.py
|
def f(GOP_struct):
depth_max = 0
for f in GOP_struct:
cur_coding_order = GOP_struct.get(f).get('coding_order')
if cur_coding_order > depth_max:
depth_max = cur_coding_order
return depth_max
assert f({}) == 0
|
benchmark_functions_edited/f13810.py
|
def f(a, b=98):
if not isinstance(a, int):
if isinstance(a, float):
a = int(a)
else:
raise TypeError("a must be an integer")
if not isinstance(b, int):
if isinstance(b, float):
b = int(b)
else:
raise TypeError("b must be an integer")
return a + b
assert f(-2, 2) == 0
|
benchmark_functions_edited/f5023.py
|
def f(array, value, default=None):
try:
return array.index(value)
except ValueError:
return default
assert f(('foo',), 'foo') == 0
|
benchmark_functions_edited/f14474.py
|
def f(x, x_lims, b_lims=None):
if b_lims is None:
return 0
if x < x_lims[0] or x > x_lims[1]:
return 0
else:
value = b_lims[0]
slope = (b_lims[1]-b_lims[0]) / (x_lims[1]-x_lims[0])
value += (x-x_lims[0])*slope
return value
assert f(5, [0, 10]) == 0
|
benchmark_functions_edited/f12233.py
|
def f(x1, y1, z1, x2, y2, z2, round_out=False):
import math as m
d = m.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2)
if round_out:
return round(d, round_out)
else:
return d
assert f(0, 0, 1, 0, 0, 0) == 1
|
benchmark_functions_edited/f12346.py
|
def f(x, y, max_iters):
i = 0
c = complex(x,y)
z = 0.0j
for i in range(max_iters):
z = z*z + c
if (z.real*z.real + z.imag*z.imag) >= 4:
return i
return 255
assert f(-1.5, -0.5, 40) == 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.