file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f9312.py
|
def f(n):
x = 0
total = 0
while x < n:
for d in [3, 2, 1, 3, 1, 2, 3]:
x += d
if x >= n:
break
total += x
return total
assert f(0) == 0
|
benchmark_functions_edited/f12812.py
|
def f(coord_x, coord_y, grid):
try:
product = (grid[(coord_x, coord_y)] *
grid[(coord_x + 1, coord_y + 1)] *
grid[(coord_x + 2, coord_y + 2)] *
grid[(coord_x + 3, coord_y + 3)])
except KeyError:
return 0
return product
assert f(0, 2, {(0, 0): 8, (0, 1): 2, (0, 2): 2, (1, 2): 2, (2, 2): 2, (3, 2): 2}) == 0
|
benchmark_functions_edited/f1015.py
|
def f(u, dfs_data):
return dfs_data['N_prime_u_lookup'][u]
assert f(2, {
'N_prime_u_lookup': {
1: 1,
2: 1,
3: 2,
4: 5,
5: 14,
6: 42,
7: 132,
8: 429,
},
'n_u_lookup': {
1: 1,
2: 1,
3: 2,
4: 2,
5: 3,
6: 3,
7: 4,
8: 4,
},
}) == 1
|
benchmark_functions_edited/f13994.py
|
def f(s, default=0):
try:
return int(s)
except (TypeError, ValueError):
return default
assert f('FALSE') == 0
|
benchmark_functions_edited/f7416.py
|
def f(workq):
if workq is None:
return 0
sz = 0
for w in workq:
sz += w.length
return sz
assert f([]) == 0
|
benchmark_functions_edited/f4916.py
|
def f(slv):
is_hex = slv.startswith('x')
return int(slv.lstrip('x').strip('"'), 16 if is_hex else 2)
assert f("x01") == 1
|
benchmark_functions_edited/f9800.py
|
def f(birthdays):
# Compare each birthday to every other birthday:
for a in range(0, len(birthdays)):
for b in range(a + 1, len(birthdays)):
if birthdays[a] == birthdays[b]:
return birthdays[a]
assert f(
[1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6]) == 1
|
benchmark_functions_edited/f12976.py
|
def f(weekday):
weekday_map = {
'Sunday': 0,
'Monday': 1,
'Tuesday': 2,
'Wednesday': 3,
'Thursday': 4,
'Friday': 5,
'Saturday': 6
}
return weekday_map.get(weekday)
assert f('Sunday') == 0
|
benchmark_functions_edited/f43.py
|
def f(x):
return x ** (0.5)
assert f(4) == 2
|
benchmark_functions_edited/f2860.py
|
def f(repr_str):
ns = {}
exec("val = (%s)" % repr_str, ns)
return ns['val']
assert f(r"1 + 1") == 2
|
benchmark_functions_edited/f12248.py
|
def f(x):
return max([10 - (1 * 1.6 ** x), 0])
assert f(8) == 0
|
benchmark_functions_edited/f1552.py
|
def f(xs: list) -> int:
return max(range(len(xs)), key=lambda i: xs[i])
assert f([2, 1, 0]) == 0
|
benchmark_functions_edited/f2869.py
|
def f(probs):
from math import log
return sum(-x*log(x, 2) for x in probs if x !=0)
assert f( [1, 0] ) == 0
|
benchmark_functions_edited/f4489.py
|
def f(seq, op, init):
if len(seq) == 0:
return init
return op(seq[0], sum(seq[1:]))
assert f( [1], lambda x,y: x*y, 0 ) == 0
|
benchmark_functions_edited/f1803.py
|
def f(x):
try: return int(x)
except: return 0
assert f(1.9) == 1
|
benchmark_functions_edited/f8064.py
|
def f( items ):
for i, item in enumerate(items):
if item:
return i
raise ValueError
assert f( [False, True] ) == 1
|
benchmark_functions_edited/f13131.py
|
def f(sent, prune, mode, dop):
beta = 600
if prune:
if dop:
beta = 10 if mode == 'pcfg' else 20
else:
beta = 2
return beta * len(sent) ** 2
assert f(list(range(2)), True, 'pcfg', False) == 8
|
benchmark_functions_edited/f10974.py
|
def f(confidence):
if confidence is None:
return 0
assert confidence <= 1
confidence_scaled = min(1, max(0, confidence-.05))
# confidence_scaled = confidence_scaled**2 # arbitrary fudge factor
return confidence_scaled * 100
assert f(None) == 0
|
benchmark_functions_edited/f14175.py
|
def f(page_list, page):
if page not in page_list:
return None
if page_list.index(page) == len(page_list) - 1:
return None
return page_list[page_list.index(page) + 1]
assert f([1,2,3], 2) == 3
|
benchmark_functions_edited/f11327.py
|
def f(d1, d2):
if len(d1) < len(d2):
return f(d2, d1)
else:
return sum(d1.get(f, 0) * v for f, v in d2.items())
assert f(dict(), {'a': 1}) == 0
|
benchmark_functions_edited/f9265.py
|
def f(loc, procs):
rank = (loc[0]*procs[1] + loc[1])*procs[2] + loc[2]
return rank
assert f( (1,0,0), (4,1,1) ) == 1
|
benchmark_functions_edited/f1091.py
|
def f(init_lr, step, iter_num):
return step/iter_num*init_lr
assert f(2, 1, 1) == 2
|
benchmark_functions_edited/f1067.py
|
def row_major_index (i, j, N):
# Row-major storage.
return i*N+j
assert f(1, 2, 5) == 7
|
benchmark_functions_edited/f5631.py
|
def f(num):
try:
return num / abs(num)
except ZeroDivisionError:
return 0
assert f(-0) == 0
|
benchmark_functions_edited/f4286.py
|
def f(data):
count = [0]*(max(data)+1)
for i in data:
count[i] += 1
return count.index(max(count))
assert f([1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5]) == 4
|
benchmark_functions_edited/f6712.py
|
def f(startclust, offset):
rst = 0
# BEGIN wxPirs
while startclust >= 170:
startclust //= 170
rst += (startclust + 1) * offset
# END wxPirs
return rst
assert f(0, 2) == 0
|
benchmark_functions_edited/f9794.py
|
def f(seq, val):
idx = len(seq)-1
while idx >= 0:
if seq[idx] <= val:
return seq[idx]
idx -= 1
return None
assert f((1, 3, 6, 11), 3) == 3
|
benchmark_functions_edited/f10536.py
|
def f(n):
try:
if type(n) is int:
return sum([True for d in str(n) if int(d) in [2, 3, 5, 7]])
else:
raise TypeError("Given input is not a supported type")
except TypeError as e:
print("Error:", str(e))
assert f(13) == 1
|
benchmark_functions_edited/f12472.py
|
def f(vals, val):
for i in range(len(vals) + 1):
if (i == 0):
if (val >= vals[i]): return i
elif (i == len(vals)):
if (val <= vals[i - 1]): return i
else:
if (val > vals[i]): return i
return 0
assert f( [5,10], -1 ) == 2
|
benchmark_functions_edited/f6827.py
|
def f(val, bits):
if (val & (1 << (bits - 1))) != 0: # if sign bit is set e.g., 8bit: 128-255
val = val - (1 << bits) # compute negative value
return val
assert f(1, 8) == 1
|
benchmark_functions_edited/f947.py
|
def f(number):
return bin(number).count("1")
assert f(42) == 3
|
benchmark_functions_edited/f5628.py
|
def f(dictionary, keys, i):
if (len(keys) - 1) == i:
return dictionary[keys[i]]
else:
return f(dictionary[keys[i]], keys, i+1)
assert f(
{
'a': {
'b': 3
}
},
['a', 'b'],
0
) == 3
|
benchmark_functions_edited/f6038.py
|
def f(item):
if item is True:
return 'T'
elif item is False:
return 'F'
else:
return item
assert f(1) == 1
|
benchmark_functions_edited/f208.py
|
def f(x, p):
return (x*p**2)**2
assert f(1, 0) == 0
|
benchmark_functions_edited/f7112.py
|
def f(num, n):
return int(round(num / n)) * n
assert f(3, 4) == 4
|
benchmark_functions_edited/f44.py
|
def f(a):
return sum(abs(ai) for ai in a)
assert f( range(3) ) == 3
|
benchmark_functions_edited/f1013.py
|
def f(x):
return len(bin(x)) - 3
assert f(16) == 4
|
benchmark_functions_edited/f8886.py
|
def f(lst, search_term):
count=0
for num in lst:
if num == search_term:
count = count+1
return count
assert f([1, 4, 3], 4) == 1
|
benchmark_functions_edited/f2034.py
|
def f(meters):
if meters is None:
return None
return meters / 1000
assert f(2000) == 2
|
benchmark_functions_edited/f4672.py
|
def f(n):
return -((-n) // 8)
assert f(14) == 2
|
benchmark_functions_edited/f4639.py
|
def f(n):
i = 2 << (n-1)
s = str(i)
my_sum = 0
for c in s:
my_sum += int(c)
return my_sum
assert f(1) == 2
|
benchmark_functions_edited/f3454.py
|
def f(y: float, gradient: float, y_intercept: float):
return (y - y_intercept) / gradient
assert f(3, 1, 0) == 3
|
benchmark_functions_edited/f11335.py
|
def f(message):
sum1 = 0
sum2 = 0
for byte in message:
sum1 = (sum1 + byte)
sum2 = (sum1 + sum2)
sum1 %= 255
sum2 %= 255
return (sum2 << 8) | sum1
assert f(b"\x00\x00") == 0
|
benchmark_functions_edited/f13336.py
|
def f(a1: float, a2: float, a3: float, b1: float, b2: float, b3: float) -> float:
d2 = (b1 - a1) ** 2 + (b2 - a2) ** 2 + (b3 - a3) ** 2
return d2
assert f(0, 1, 0, 0, 2, 0) == 1
|
benchmark_functions_edited/f1061.py
|
def f(sprites):
return sprites["block"][0]
assert f(
{"block": [0], "coin": [1, 2, 3]}) == 0
|
benchmark_functions_edited/f13239.py
|
def f(v0w, b0w, b1w, v0f, b0f, b1f, config_string, prefact, weight_b0, weight_b1):
return prefact*2*(v0w-v0f)/(v0w+v0f)
assert f(1, 0, 0, 1, 0, 0, 'config', 1, 1, 1) == 0
|
benchmark_functions_edited/f10945.py
|
def f(item, item_set):
for key, value in item_set:
if frozenset(key) == item:
return value
assert f(frozenset({'b'}), [(frozenset({'a'}), 3), (frozenset({'b'}), 2)]) == 2
|
benchmark_functions_edited/f376.py
|
def f(text):
return text.count(". ") + 1
assert f("hello there, how are you?") == 1
|
benchmark_functions_edited/f7546.py
|
def f(s, *args):
return s.f(*args)
assert f(b'one', b'e', 2) == 1
|
benchmark_functions_edited/f2135.py
|
def f(lvl):
total_xp = int((lvl * 10) ** 1.1)
return total_xp * lvl
assert f(0) == 0
|
benchmark_functions_edited/f10452.py
|
def f(data_size: int, chunk_size: int) -> int:
return (data_size // chunk_size) + (1 if (data_size % chunk_size) > 0 else 0)
assert f(120, 40) == 3
|
benchmark_functions_edited/f1076.py
|
def f(n, deck_len, x):
return (x + n) % deck_len
assert f(2, 10, 9) == 1
|
benchmark_functions_edited/f9971.py
|
def f(p1, p2, p3):
v1 = [p2[0] - p1[0], p2[1] - p1[1]]
v2 = [p3[0] - p2[0], p3[1] - p2[1]]
return v1[0] * v2[1] - v1[1] * v2[0]
assert f( [1, 0], [0, 1], [0, 0] ) == 1
|
benchmark_functions_edited/f7060.py
|
def f(rho, phi):
return 924 * rho**12 \
- 2772 * rho**10 \
+ 3150 * rho**8 \
- 1680 * rho**6 \
+ 420 * rho**4 \
- 42 * rho**2 \
+ 1
assert f(1, 2) == 1
|
benchmark_functions_edited/f3791.py
|
def f(x, X, Y):
return (Y[1] * (x - X[0]) + Y[0] * (X[1] - x)) / (X[1] - X[0])
assert f(1, [2, 3], [4, 5]) == 3
|
benchmark_functions_edited/f7420.py
|
def f(frame):
crc = 0
for byte in frame:
crc = (crc ^ byte ^ (byte * 2 & 0xff)) & 0xff
return crc
assert f(b'') == 0
|
benchmark_functions_edited/f14187.py
|
def f(goals_home, goals_away, home_exp, away_exp, rho):
if goals_home == 0 and goals_away == 0:
return 1 - (home_exp * away_exp * rho)
elif goals_home == 0 and goals_away == 1:
return 1 + (home_exp * rho)
elif goals_home == 1 and goals_away == 0:
return 1 + (away_exp * rho)
elif goals_home == 1 and goals_away == 1:
return 1 - rho
else:
return 1.0
assert f(0, 1, 1, 1, 0) == 1
|
benchmark_functions_edited/f3952.py
|
def f(m, d, n):
value = 1
for _ in range(d):
value = (value * m) % n
return value
assert f(1, 1, 2) == 1
|
benchmark_functions_edited/f1247.py
|
def f(degrees):
return (degrees - 32) * 5/9
assert f(32) == 0
|
benchmark_functions_edited/f4551.py
|
def f(press_in):
conversion_factor = 98.0665
return int(round(press_in * conversion_factor))
assert f(0) == 0
|
benchmark_functions_edited/f3815.py
|
def f(n):
if n < 2:
raise ValueError('n must be greater than or equal to 2')
return int(n)
assert f(3) == 3
|
benchmark_functions_edited/f2489.py
|
def f(x) -> int:
if x < 0:
return -1
else:
return 1
assert f(123) == 1
|
benchmark_functions_edited/f4652.py
|
def f(args, index, default=None):
if index >= len(args):
return default
return args[index]
assert f((1,2,3), 1) == 2
|
benchmark_functions_edited/f2082.py
|
def filesize (path) :
import os
import stat
return os.stat (path) [stat.ST_SIZE]
assert filesize ('/dev/zero') == 0
|
benchmark_functions_edited/f9920.py
|
def f(before, block, idx, after):
if idx == 0:
return before
else:
prev = block[idx-1]
if type(prev) == list:
if not prev:
return f(before, block, idx-1, after)
return prev[-1]
return prev
assert f(1, [1], 0, 1) == 1
|
benchmark_functions_edited/f12058.py
|
def f(n: int) -> int:
first, sec = 0, 1
if n == 0:
return first
elif n == 1:
return sec
else:
for i in range(2, n):
temp = first
first, sec = sec, temp + sec
return sec
assert f(0) == 0
|
benchmark_functions_edited/f4117.py
|
def f(m,y,point):
a = m
b = -1
c = y
m = point[0]
n = point[1]
return abs(a*m+b*n+c)/((a)**2+(b)**2)**.5
assert f(1, 0, (0, 0)) == 0
|
benchmark_functions_edited/f9755.py
|
def f(num: int, bitSize: int):
mask = (2 ** bitSize) - 1
if num & (1 << (bitSize - 1)):
return num | ~mask
else:
return num & mask
assert f(0b0000, 1) == 0
|
benchmark_functions_edited/f10114.py
|
def f(base, exponent, modulus):
s = 1
while exponent != 0:
if exponent & 1:
s = (s * base) % modulus
exponent >>= 1
base = (base * base) % modulus
return s
assert f(3, 1000000, 5) == 1
|
benchmark_functions_edited/f8255.py
|
def f(arr):
arr.sort()
n = len(arr)
mid = int(n / 2)
return arr[mid]
assert f([2, 3, 4]) == 3
|
benchmark_functions_edited/f14030.py
|
def f(vector, starting_position, condition_fun):
position = starting_position
while(position < len(vector) and
not(condition_fun(vector[position]))):
position += 1
if(position == (len(vector) - 1) and
not(condition_fun(vector[position]))):
position = - 1
return(position)
assert f(
[0, 1, 2, 3, 4, 5, 6],
0,
lambda x: x == 1
) == 1
|
benchmark_functions_edited/f10975.py
|
def f(a, b=0, c=0):
d = a + b + c
print('Addition: ', a, ' + ', b, ' + ', c, ' = ', d)
return d
assert f(0) == 0
|
benchmark_functions_edited/f1408.py
|
def f(numbers):
return float(sum(numbers)) / max(len(numbers), 1)
assert f([0, 0, 0]) == 0
|
benchmark_functions_edited/f12906.py
|
def f(i):
if i == 0:
return 1
elif i == 1:
return 2
else:
f_minus_1 = 2
f_minus_2 = 1
for j in range(i - 2):
f_minus_2, f_minus_1 = f_minus_1, f_minus_1 + f_minus_2
return f_minus_1 + f_minus_2
assert f(2) == 3
|
benchmark_functions_edited/f3671.py
|
def f(num1, num2):
results = {
(3, 5): 8, (-2, -2): -4,
(-1, 5): 4, (3, -5): -2, (0, 5): 5}
return results.get((num1, num2))
assert f(-1, 5) == 4
|
benchmark_functions_edited/f1538.py
|
def f(m, mm, _accuracy):
value = 1
return value
assert f(1, 1, 0.9) == 1
|
benchmark_functions_edited/f183.py
|
def f(vy0, n):
return n*(2*vy0 + 1 -n) / 2
assert f(1, 1) == 1
|
benchmark_functions_edited/f5660.py
|
def f(values):
mean = sum(values) / len(values)
return mean
assert f([-10, 10]) == 0
|
benchmark_functions_edited/f4435.py
|
def f(curr_point, goal):
return abs(goal[0] - curr_point[0]) + abs(goal[1] - curr_point[1])
assert f( (3, 3), (0, 0) ) == 6
|
benchmark_functions_edited/f8885.py
|
def f(x, name):
if isinstance(x, list):
if len(x) == 1:
return x[0]
else:
raise ValueError("Only a single {} can be used with --singularity".format(name))
else:
return x
assert f([1], "x") == 1
|
benchmark_functions_edited/f13508.py
|
def f(similarity_threshold):
if similarity_threshold >= 0.7:
return 5
elif similarity_threshold >= 0.6:
return 4
elif similarity_threshold >= 0.5:
return 3
else:
return 2
assert f(0.6) == 4
|
benchmark_functions_edited/f6371.py
|
def f(input_x, input_y):
if input_x % input_y != 0:
raise ValueError("Not divisible")
return input_x // input_y
assert f(9, 3) == 3
|
benchmark_functions_edited/f12004.py
|
def f(mean, var):
return (var-mean) / mean**2
assert f(1, 2) == 1
|
benchmark_functions_edited/f5013.py
|
def f(l):
total = 0.0
for value in l:
total += value
return total / len(l)
assert f([-1, 0, 1]) == 0
|
benchmark_functions_edited/f5925.py
|
def f(word):
check = any(letter.isdigit() for letter in word)
return 1 if check else 0
assert f('') == 0
|
benchmark_functions_edited/f6784.py
|
def f(n):
result = 0
start = (n * n)-(n - 1)
end = start+n * 2
for i in range(start, end, 2):
result += i
return result
assert f(1) == 1
|
benchmark_functions_edited/f12734.py
|
def f(tween, value, b, c, d):
max_iter = 20
resolution = 0.01
iter = 1
lower = 0
upper = d
while iter < max_iter:
t = (upper - lower) / 2
if tween(t, b, c, d) - value < resolution:
return t
else:
upper = t
assert f(lambda t, b, c, d: t * t + t + b + c + d, 0, 0, 0, 0) == 0
|
benchmark_functions_edited/f7833.py
|
def f(states_importance):
avg = sum(states_importance) / len(states_importance)
return max(states_importance) - avg
assert f([0, 0, 0]) == 0
|
benchmark_functions_edited/f8480.py
|
def f(proposed, existing):
sum = 0
for p in proposed:
if p not in existing:
sum += 1
for e in existing:
if e not in proposed:
sum += 1
return sum
assert f(list(), list()) == 0
|
benchmark_functions_edited/f6530.py
|
def f(L1, L2):
result = 0.
for word1, count1 in L1:
for word2, count2 in L2:
if word1 == word2:
result += count1 * count2
return result
assert f(
[("a", 1), ("b", 1), ("c", 1)],
[("a", 1), ("b", 1), ("c", 1)]
) == 3
|
benchmark_functions_edited/f11305.py
|
def f(*args):
if len(args) == 1:
raise Exception("You have only entered a value for x, and no coefficients.")
x = args[0] # X value
coef = args[1:]
result = 0
for power, c in enumerate(coef):
result += c * (x ** (power+1))
return result
assert f(1, 0, 1) == 1
|
benchmark_functions_edited/f779.py
|
def f(adr, width):
return adr & ~((width >> 3) - 1)
assert f(0, 128) == 0
|
benchmark_functions_edited/f5636.py
|
def f(a: int, b: int) -> int:
from math import gcd
return (a // gcd(a, b)) * b
assert f(2, 3) == 6
|
benchmark_functions_edited/f1878.py
|
def f(x):
if x > 0:
x = 1
return x
assert f(30) == 1
|
benchmark_functions_edited/f12202.py
|
def f(n: float) -> float:
sign = n / abs(n)
if abs(n) > 1:
return 1 * sign
else:
return n
assert f(1.001) == 1
|
benchmark_functions_edited/f6007.py
|
def f(time):
time_list = time.split(":")
if len(time_list) >= 2:
return (int(time_list[0]) * 60) + int(time_list[1])
return 0
assert f("00:07") == 7
|
benchmark_functions_edited/f4389.py
|
def f(lines):
totalh = 0
for img in lines:
w, h = img.get_size()
totalh += h
return totalh
assert f([]) == 0
|
benchmark_functions_edited/f11826.py
|
def f(indexable, index):
try:
return indexable[index]
except IndexError:
return None
assert f(tuple(range(3)), 2) == 2
|
benchmark_functions_edited/f3098.py
|
def f(seq):
f, *args = seq
return f(*args)
assert f(
[max, [1]]
) == 1
|
benchmark_functions_edited/f3026.py
|
def f(dct, key, default):
if key not in dct:
dct[key] = default
return dct[key]
assert f(dict(), 'b', 1) == 1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.