file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f436.py
|
def f(xs):
return sum(xs) / len(xs)
assert f([1, 2, 3]) == 2
|
benchmark_functions_edited/f8653.py
|
def f(n, k):
from operator import mul # or mul=lambda x,y:x*y
from fractions import Fraction
from functools import reduce
return int(reduce(mul, (Fraction(n - i, i + 1) for i in range(k)), 1))
assert f(5, 5) == 1
|
benchmark_functions_edited/f13598.py
|
def f(x, par):
c=x[0]
l=x[1]
alpha=par
u= (c**alpha)*l**(1-alpha)
return -u
assert f( (0, 10), 0.5) == 0
|
benchmark_functions_edited/f1049.py
|
def f(res):
return round(res[0] / 2)
assert f( (10, 10), ) == 5
|
benchmark_functions_edited/f1470.py
|
def f(n, s, t):
if s == t:
return (-1)**s
else:
return 0
assert f(2, 1, 3) == 0
|
benchmark_functions_edited/f3491.py
|
def f(matrixSize, rowSub, colSub):
m, n = matrixSize
return rowSub * (n-1) + colSub - 1
assert f( (2, 2), 2, 2) == 3
|
benchmark_functions_edited/f908.py
|
def f(n, i):
return int(str(n)[::-1][i])
assert f(9876, 2) == 8
|
benchmark_functions_edited/f2113.py
|
def f(lst):
for d in lst:
if d is not None:
return d
return None
assert f([None, 0, 1, 2, 3, 4, 5, None]) == 0
|
benchmark_functions_edited/f7940.py
|
def f(pos_a, pos_b):
return ((pos_a[0] - pos_b[0]) ** 2 + (pos_a[1] - pos_b[1]) ** 2) ** 0.5
assert f((0, 0), (0, 2)) == 2
|
benchmark_functions_edited/f7338.py
|
def f(n: int) -> int:
if n <= 2:
return 1
return 1 + 2 * f(n - 1)
assert f(1) == 1
|
benchmark_functions_edited/f7284.py
|
def f(x, elements, nodes):
for e, local_nodes in enumerate(elements):
if nodes[local_nodes[0]] <= x <= nodes[local_nodes[-1]]:
return e
assert f(2.5, [list(range(2)), list(range(2, 4))], [0, 1, 2, 3]) == 1
|
benchmark_functions_edited/f1017.py
|
def f(iterable):
tot = 0
for i in iterable:
tot += i
return tot
assert f((1, 2, 3)) == 6
|
benchmark_functions_edited/f10447.py
|
def f(x):
return (((x << 24) & 0xFF000000) |
((x << 8) & 0x00FF0000) |
((x >> 8) & 0x0000FF00) |
((x >> 24) & 0x000000FF))
assert f(16777216) == 1
|
benchmark_functions_edited/f11715.py
|
def f(limit: int) -> int:
return sum(filter(
lambda x: x % 3 == 0 or x % 5 == 0,
range(3, limit)))
assert f(3) == 0
|
benchmark_functions_edited/f9973.py
|
def f(x,y, function):
try:
return function(x,y)
except Exception as e:
print(f"Fix this pls {e}")
return None
assert f(1,2, lambda x, y: (x * y) + (x * y)) == 4
|
benchmark_functions_edited/f4934.py
|
def f(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
assert f(1, 3, 1, 2) == 1
|
benchmark_functions_edited/f4915.py
|
def f(hour_out, check_out):
if check_out > hour_out:
result = check_out - hour_out
else:
result = ' '
return result
assert f(8, 16) == 8
|
benchmark_functions_edited/f13803.py
|
def f(job_id):
import subprocess
try:
step_process = subprocess.Popen(('qdel', str(job_id)), shell=False, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout, stderr = step_process.communicate()
return 1
except Exception as e:
print(e)
return 0
assert f(-1234) == 0
|
benchmark_functions_edited/f11443.py
|
def f(p1, p2):
dx = p2[0] - p1[0]
dy = p2[1] - p1[1]
distance = (dx ** 2 + dy ** 2)**0.5
return distance
assert f(
[0, 0], [3, 4]
) == 5
|
benchmark_functions_edited/f54.py
|
def f(q, r):
aq = q * r
return aq
assert f(0, 0) == 0
|
benchmark_functions_edited/f7422.py
|
def f(input, default) -> object:
if not input:
return default
return input
assert f("", 0) == 0
|
benchmark_functions_edited/f12754.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, 1: 1, 2: 3}) == 0
|
benchmark_functions_edited/f8084.py
|
def f(rank):
rank = int(rank)
if rank >= 1 and rank <= 5:
return int(6 - rank)
else:
raise RuntimeError(":x: Invalid rank `"+str(rank)+"`; rank should be 1-5")
assert f(2) == 4
|
benchmark_functions_edited/f4899.py
|
def f(arg_val, default_arg_val):
if arg_val:
return arg_val
else:
return default_arg_val
assert f(3, 4) == 3
|
benchmark_functions_edited/f1476.py
|
def f(size, factor):
x = size + factor - 1
return x - (x % factor)
assert f(5, 1) == 5
|
benchmark_functions_edited/f807.py
|
def f(y):
return 8 + 4*y
assert f(-2) == 0
|
benchmark_functions_edited/f7249.py
|
def f(x):
# Intitial guess for the square root
z = x / 2.0
#Continuously improve guess
while abs(x - (z*z)) > 0.0000001:
z = z - ((z*z -x) / (2*z))
return z
assert f(0) == 0
|
benchmark_functions_edited/f4103.py
|
def f(maximum, t2):
if maximum < t2:
return t2
return maximum
assert f(1, 7) == 7
|
benchmark_functions_edited/f174.py
|
def f(value, other):
return len(value) != other
assert f((1, 2, 3), (1, 2, 4)) == 1
|
benchmark_functions_edited/f8522.py
|
def f(x: float) -> float:
if x < 0: return 0 # uniform random is never less than 0
elif x < 1 : return x # e.g. P(X <= 0.4)
else: return 1 # uniform random is always less than 1
assert f(1.0) == 1
|
benchmark_functions_edited/f5093.py
|
def f(x, y):
if x >= y:
return 1.0
else:
return 0.0
assert f(2, 2) == 1
|
benchmark_functions_edited/f3505.py
|
def f(ename, pdata=None):
if pdata is None:
return 1
else:
return pdata.get(ename, 1)
assert f(2, {0: 1, 1: 0, 2: 1}) == 1
|
benchmark_functions_edited/f7219.py
|
def f(left: int, right: int) -> int:
n_odd = (right - left) // 2
if right % 2 != 0 or left % 2 != 0:
n_odd += 1
return n_odd
assert f(3, 6) == 2
|
benchmark_functions_edited/f5466.py
|
def f(list_of_tuples):
length = 0
for tuple_item in list_of_tuples:
length += len(tuple_item)
return length
assert f([]) == 0
|
benchmark_functions_edited/f13642.py
|
def f(vector1, vector2):
jaccard = len(vector1.intersection(vector2)) / \
(len(vector1) + len(vector2) - len(vector1.intersection(vector2)))
return jaccard
assert f(set("abc"), set("abc")) == 1
|
benchmark_functions_edited/f6361.py
|
def f(duration: float, duration_: float = 0, bias_: float = 0) -> float:
return duration * duration_ + bias_
assert f(0, 1, 1) == 1
|
benchmark_functions_edited/f9560.py
|
def f(line, wanted_length=77):
lines = line.split("\n")
count = len(lines) - 1
for row in lines:
length = len(row)/wanted_length
if length < 1.0:
continue
count += int(length)
return count
assert f(
"Hello, world!\n"
"Goodbye, world!\n") == 2
|
benchmark_functions_edited/f2285.py
|
def f(a, b):
return 0 if a == b else 1 if a > b else -1 if a < b else None
assert f(2, 2.0) == 0
|
benchmark_functions_edited/f3733.py
|
def f(times):
return sum(t + 3 in times for t in times)
assert f(range(0, 30, 5)) == 0
|
benchmark_functions_edited/f11099.py
|
def f(y_true, y_pred):
# initialize counter
tp = 0
for yt, yp in zip(y_true, y_pred):
if yt == 1 and yp == 1:
tp += 1
return tp
assert f(
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
) == 0
|
benchmark_functions_edited/f11153.py
|
def f(n, a):
remainder_list = []
k = 1
while True:
r = len(remainder_list)
if r > 128:
return None
remainder = a ** k % n
if remainder in remainder_list:
return r
else:
remainder_list.append(remainder)
k += 1
assert f(5, 12) == 4
|
benchmark_functions_edited/f3576.py
|
def f(prbs):
if prbs % 2 == 0:
return prbs / 2
else:
return (prbs // 2) + 1
assert f(5) == 3
|
benchmark_functions_edited/f8631.py
|
def f(s, default):
try:
i = int(s)
if i >= 0:
return i
except (ValueError, TypeError):
pass
return default
assert f(1, 2) == 1
|
benchmark_functions_edited/f5735.py
|
def f(x):
if x[0] == "-":
ret = float("-0." + x[1:])
else:
ret = float("0." + x)
return ret
assert f("000") == 0
|
benchmark_functions_edited/f4209.py
|
def f(pt1, pt2):
return abs(pt1[0] - pt2[0]) + abs(pt1[1] - pt2[1])
assert f( (0, 0, "a"), (0, 0, "c") ) == 0
|
benchmark_functions_edited/f6267.py
|
def f(n):
return 2 * n + 1
assert f(1) == 3
|
benchmark_functions_edited/f11583.py
|
def f(n):
if n <= 1:
return n
return f(n-1) + f(n-2)
return
assert f(0) == 0
|
benchmark_functions_edited/f13187.py
|
def f(line, tab_length):
line = line.expandtabs(tab_length)
indentation = (len(line) - len(line.lstrip(" "))) // tab_length
if line.rstrip().endswith(":"):
indentation += 1
elif indentation >= 1:
if line.lstrip().startswith(("return", "pass", "raise", "yield")):
indentation -= 1
return indentation
assert f(
' return "foo" \n return "bar"', 8) == 0
|
benchmark_functions_edited/f7207.py
|
def f(a, x):
p = 0
a.reverse()
for coef in a:
p = p*x + coef
a.reverse()
return p
assert f(list(range(6)), 0) == 0
|
benchmark_functions_edited/f3062.py
|
def f(ptr: int):
if ptr < 0x8000000 or ptr > 0x9FFFFFF:
return -1
return ptr - 0x8000000
assert f(0x8000001) == 1
|
benchmark_functions_edited/f12149.py
|
def f(changepoints, thresh=5):
num_soy_cps = 0
for cp in changepoints:
if (cp.month == 1) and (cp.day <= thresh):
num_soy_cps += 1
return num_soy_cps
assert f([]) == 0
|
benchmark_functions_edited/f11721.py
|
def f(seq, items):
found = None
for s in seq:
if s in items:
found = s
return found
assert f(range(10), [3, 4, 5, 6]) == 6
|
benchmark_functions_edited/f555.py
|
def f(a, b, *others):
return max(a, b, *others)
assert f(0, 1) == 1
|
benchmark_functions_edited/f11940.py
|
def f(list1):
# moyenne
moy = sum(list1, 0.0) / len(list1)
# variance
variance = [(x - moy) ** 2 for x in list1]
variance = sum(variance, 0.0) / len(variance)
# ecart_type
deviation = variance ** 0.5
return deviation
assert f([10, 10, 10]) == 0
|
benchmark_functions_edited/f8409.py
|
def f(target):
cur = 1
if target > 1:
for i in range(0, int(target)):
if (cur >= target):
return cur
else:
cur *= 2
else:
return 1
assert f(1) == 1
|
benchmark_functions_edited/f6810.py
|
def f(point_a,point_b,point_c,w,t):
return (point_a*(1-t)**2+2*w*point_b*t*(1-t)+point_c*t**2)/((1-t)**2+2*w*t*(1-t)+t**2)
assert f(1,0,1,0,1) == 1
|
benchmark_functions_edited/f12888.py
|
def f(a, n):
t = 0
newt = 1
r = n
newr = a
while newr != 0:
quotient = int((r - (r % newr)) / newr)
tt = t
t = newt
newt = tt - quotient * newt
rr = r
r = newr
newr = rr - quotient * newr
if r > 1:
return "a is not invertible"
if t < 0:
t = t + n
return t
assert f(1, 49) == 1
|
benchmark_functions_edited/f7306.py
|
def f(lst):
ls_len = 0
if lst:
for item in lst:
ls_len += len(item)
return ls_len
assert f([[], []]) == 0
|
benchmark_functions_edited/f9745.py
|
def f(seq):
if seq is None:
return 0
return len(seq)
assert f("") == 0
|
benchmark_functions_edited/f9890.py
|
def f(base, num):
out = 0
for digit in num:
if digit >= base or digit < 0:
raise ValueError("invalid digit: %i" % digit)
out *= base
out += digit
return out
assert f(10, ()) == 0
|
benchmark_functions_edited/f5578.py
|
def f(base, exp):
if exp == 0:
return 1
else:
return base * f(base, exp-1)
assert f(3, 1) == 3
|
benchmark_functions_edited/f11139.py
|
def f(n, k):
C = [[0] * (i + 1) for i in range(n + 1)]
for i in range(n + 1):
for j in range((min(i, k) + 1)):
if j == 0 or j == i:
C[i][j] = 1
else:
C[i][j] = C[i - 1][j - 1] + C[i - 1][j]
return C[n][k]
assert f(3, 0) == 1
|
benchmark_functions_edited/f11398.py
|
def f(val, max_value, min_value):
std = (val - min_value) / (max_value - min_value)
return std
assert f(-10, 20, -10) == 0
|
benchmark_functions_edited/f7696.py
|
def f(num_1, num_2):
max_num = num_1 if num_1 > num_2 else num_2
lcm = max_num
while True:
if ((lcm % num_1 == 0) and (lcm % num_2 == 0)):
break
lcm += max_num
return lcm
assert f(2, 1) == 2
|
benchmark_functions_edited/f5006.py
|
def f(d):
string_value = d.get("uitslag", " 0- 0")
(_, v) = string_value.replace(" ", "").split("-")
return int(v)
assert f(
{"uitslag": " 0- 5"}
) == 5
|
benchmark_functions_edited/f1359.py
|
def f(n):
if n is not None:
return int(n)
return n
assert f(4.6) == 4
|
benchmark_functions_edited/f9734.py
|
def f(objectname):
private_identifier = "_"
if objectname.startswith(private_identifier):
return 0
else:
return 1
assert f("public_name") == 1
|
benchmark_functions_edited/f1714.py
|
def f(pattern, data):
return len(pattern.split(data))
assert f(r'one two three', '<page>one</page><page>two</page><page>three</page>') == 1
|
benchmark_functions_edited/f4514.py
|
def f(x, y, z):
if x <= y:
return y
return f(f(x - 1, y, z), f(y - 1, z, x), f(z - 1, x, y))
assert f(7, 1, 1) == 1
|
benchmark_functions_edited/f2575.py
|
def f(a, b):
quanta, mod = divmod(a, b)
if mod:
quanta += 1
return quanta
assert f(11, 7) == 2
|
benchmark_functions_edited/f9512.py
|
def f(V):
num_odd_runs = 0
odd = False
for t in V:
if t % 2 == 1:
if not odd:
num_odd_runs += 1
odd = True
else:
odd = False
return num_odd_runs
assert f(list(range(1))) == 0
|
benchmark_functions_edited/f10352.py
|
def f(n):
if n <= 0:
return 0
if n <= 1:
return 1
a, b = 0, 1
cont = 2
while a + b < n:
b += a
a = b - a
cont += 1
return cont
assert f(4) == 5
|
benchmark_functions_edited/f4005.py
|
def f(indifference_threshold, distance):
if distance > indifference_threshold:
return 1
else:
return 0
assert f(3, 5) == 1
|
benchmark_functions_edited/f2895.py
|
def f(y):
if isinstance(y, tuple):
return y[0]
return y
assert f((1,0)) == 1
|
benchmark_functions_edited/f1300.py
|
def f(alpha, t):
Q = alpha * t ** 2
return Q
assert f(0.5, 0) == 0
|
benchmark_functions_edited/f8679.py
|
def f(n, c):
return sum( [f(n-1-j, c) for j in range(0,c+1)]) if n>c else 2**n
assert f(2,1) == 3
|
benchmark_functions_edited/f4072.py
|
def f(va, ca, dha, dh2a, h, oh, cb):
vb = (va * (2 * ca - dha - 2 * dh2a - h + oh)) / (cb + dha + 2 * dh2a + h - oh)
return vb
assert f(0, 1, 2, 3, 4, 5, 6) == 0
|
benchmark_functions_edited/f5657.py
|
def f(a_list):
smallest = min(a_list)
a_list.remove(smallest)
return min(a_list)
assert f([10, 3, 2, 10, 5, 6]) == 3
|
benchmark_functions_edited/f14205.py
|
def f(data):
average_total_time = sum(v[10] - v[0]
for v in data.values()) / len(data.values())
average_total_queue_time = sum(
sum(v[1::2]) - sum(v[:-1:2]) for v in data.values()) / len(data.values())
return average_total_time + average_total_queue_time
assert f({(0, 0): [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}) == 0
|
benchmark_functions_edited/f6735.py
|
def f(imagine, punct):
ccx, ccy = punct
length = len(imagine[0])
width = len(imagine)
if ccx < width and ccx > -1 and ccy < length and ccy > -1:
return 1
return 0
assert f(
[[1, 1, 1, 1], [1, 2, 2, 1], [1, 2, 2, 1], [1, 1, 1, 1]], (1, 1)
) == 1
|
benchmark_functions_edited/f13177.py
|
def f(N):
a1 = (19 + 3 * 33**0.5)**(1 / 3)
a2 = (19 - 3 * 33**0.5)**(1 / 3)
b = (586 + 102 * 33**0.5)**(1 / 3)
numerator = 3 * b * (1 / 3 * (a1 + a2 + 1))**(N + 1)
denominator = b**2 - 2 * b + 4
result = round(numerator / denominator)
return result
assert f(1) == 1
|
benchmark_functions_edited/f3175.py
|
def f(val, default=None):
try:
return int(val)
except (ValueError, TypeError):
return default
assert f(5.0) == 5
|
benchmark_functions_edited/f4992.py
|
def f(v1 : float, v0 : float, t1 : float, t0 : float) -> float:
return ((v1-v0)/(t1-t0));
assert f(20, 0, 10, 0) == 2
|
benchmark_functions_edited/f11631.py
|
def f(sig_info, errors):
if 'mailing_list' not in sig_info.keys():
print('ERROR! mailing_list is a required field')
errors += 1
else:
print('Check mailing_list: PASS')
return errors
assert f(
{
"mailing_list": "https://groups.google.com/forum/#!forum/kubernetes-sig-cluster-lifecycle"
},
0
) == 0
|
benchmark_functions_edited/f3169.py
|
def f(x):
_int = int(x)
if _int < x:
return int(x + 1)
else:
return _int
assert f(1.1) == 2
|
benchmark_functions_edited/f13332.py
|
def f(maze):
ptr = 0
step = 0
while 0 <= ptr < len(maze):
offset = maze[ptr]
maze[ptr] += 1
ptr += offset
step += 1
return step
assert f(list(map(int, [0, 3, 0, 1, -3]))) == 5
|
benchmark_functions_edited/f8261.py
|
def f(x):
return round(2*float(x))/2
assert f(1.0) == 1
|
benchmark_functions_edited/f2494.py
|
def f(base, dvdby):
if isinstance(dvdby, int):
return base // dvdby
return base / dvdby
assert f(100, 30) == 3
|
benchmark_functions_edited/f6050.py
|
def f(version):
try:
if "-" in version:
return int(version.split("-", 1)[0])
except TypeError:
return version
assert f("1-1") == 1
|
benchmark_functions_edited/f11615.py
|
def f(line, spacesPerTab=4):
x = 0
nextTab = 4
for ch in line:
if ch == ' ':
x = x + 1
elif ch == '\t':
x = nextTab
nextTab = x + spacesPerTab
else:
return x
assert f(' x = 1') == 1
|
benchmark_functions_edited/f2602.py
|
def f(input,min,max,a=-1,b=1):
output = a + (input-min)*(b-a)/(max-min)
return output
assert f(1,0,1) == 1
|
benchmark_functions_edited/f12785.py
|
def f(lhs, rhs):
if lhs == rhs:
return 0
elif lhs > rhs:
return 1
else:
return -1
assert f((0, 0, 1), (0, 0, 1)) == 0
|
benchmark_functions_edited/f5431.py
|
def f(presents, counter):
return sum(
counter(present)
for present in presents
)
assert f(
['a', 'a', 'b', 'b', 'c', 'c'],
lambda x: x.count('a')
) == 2
|
benchmark_functions_edited/f1798.py
|
def f(m):
return (m[0] << 12) + (m[2] << 8) + (m[1] << 4) + m[3]
assert f( (0, 0, 0, 0) ) == 0
|
benchmark_functions_edited/f14413.py
|
def f(hand):
# MY IMPLEMENTATION
# for every key in hand dictionary
handlist = []
for letter in hand.keys():
# add letter to list as often as integer value associated with that letter
for j in range(hand[letter]):
handlist.append(letter)
# return length of hand
return len(handlist)
assert f({}) == 0
|
benchmark_functions_edited/f3738.py
|
def f(choices):
lengths = [len(choice) for choice, _ in choices]
return max(lengths)
assert f(
[
('a', 'A'),
('aa', 'AA'),
]) == 2
|
benchmark_functions_edited/f3524.py
|
def f(arr):
dup = set([x for x in arr if arr.count(x) > 1])
answer = list(dup)
return answer[0]
assert f([2,5,9,6,9,3,2,11]) == 9
|
benchmark_functions_edited/f1888.py
|
def f(condition, x, y):
if condition:
return x
else:
return y
assert f(False, 1, 0) == 0
|
benchmark_functions_edited/f5103.py
|
def f(angle):
new_angle = angle % 360
if new_angle > 180:
new_angle -= 360
return new_angle
assert f(720) == 0
|
benchmark_functions_edited/f8320.py
|
def f(filename):
from os.path import getmtime
try: return getf(filename)
except: return 0
assert f('not-existing-file') == 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.