file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f2026.py
|
def f(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1]) + abs(a[2] - b[2])
assert f([0, 0, 0], [1, 0, 1]) == 2
|
benchmark_functions_edited/f9782.py
|
def f(n: int) -> int:
if n <= 1:
return n
fib0 = 0
fib1 = 1
for i in range(2, n + 1):
fib0, fib1 = fib1, fib0 + fib1
return fib1
assert f(3) == 2
|
benchmark_functions_edited/f465.py
|
def f(time, slope, offset):
return slope * time + offset
assert f(2, 2, 1) == 5
|
benchmark_functions_edited/f10464.py
|
def f(a, b):
if a >= b:
return a * a + a + b
return a + b * b
assert f(1, 2) == 5
|
benchmark_functions_edited/f2717.py
|
def f(a, b):
return sum([abs(i - j) ** 2 for (i, j) in zip(a, b)]) / len(a)
assert f(list(range(0, 10)), list(range(0, 10))) == 0
|
benchmark_functions_edited/f11913.py
|
def f(lh_arg, rh_arg, neg=False):
if rh_arg is not None and neg:
rh_arg = -rh_arg
if lh_arg is None and rh_arg is None:
return None
elif lh_arg is None:
return rh_arg
elif rh_arg is None:
return lh_arg
else:
return lh_arg + rh_arg
assert f(1, 2, 0) == 3
|
benchmark_functions_edited/f12225.py
|
def f(trg, pred):
trg_length = len(trg.split(' '))
pred_length = len(pred.split(' '))
return abs(trg_length - pred_length)
assert f("", "") == 0
|
benchmark_functions_edited/f12671.py
|
def f(ary):
dct = {}
for value in ary:
if value in dct:
dct[value]+=1
else:
dct[value] =1
return max(dct, key=lambda k: dct[k])
assert f((1, 1)) == 1
|
benchmark_functions_edited/f4234.py
|
def f(vfp: int) -> int:
address_mask = 0xFFFFFFFFFFFF
return vfp >> 16 & address_mask
assert f(0) == 0
|
benchmark_functions_edited/f10557.py
|
def f(record):
return record[0] * 3 + record[1]
assert f([0,0,1]) == 0
|
benchmark_functions_edited/f1368.py
|
def f(a, b):
return sum(i * j for i, j in zip(a, b))
assert f((2, 0), (0, 3)) == 0
|
benchmark_functions_edited/f7988.py
|
def f(x):
# loop until you get the leading digit
while x >= 10:
x //= 10
return x
assert f(39463.19874) == 3
|
benchmark_functions_edited/f2050.py
|
def f(char, grid):
return sum(line.count(char) for line in grid)
assert f('z', ['ho', 'o ', 'ho']) == 0
|
benchmark_functions_edited/f9289.py
|
def f(stack, index=0):
x = stack.pop(index)
stack.append(x)
return x
assert f(list(range(5)), 1) == 1
|
benchmark_functions_edited/f9287.py
|
def f(a):
if hasattr(a, "__int__"):
return int(a)
if hasattr(a, "__index__"):
return a.__index__()
assert f(0.0+1e-10) == 0
|
benchmark_functions_edited/f8025.py
|
def f(arr):
if not isinstance(arr, list):
return 'Use only list with numbers for this function'
if not len(arr):
return None
m = arr[0]
for i in arr:
m = i if i > m else m
return m
assert f([-1, 0, 1]) == 1
|
benchmark_functions_edited/f10949.py
|
def f(birth_year: int, year_to_compare: int) -> int:
age = year_to_compare - birth_year
return age
assert f(2000, 2001) == 1
|
benchmark_functions_edited/f1492.py
|
def f(pick):
return pick[1][1]
assert f(('B', ('C', 2))) == 2
|
benchmark_functions_edited/f6535.py
|
def f(string_1, string_2):
return sum(ele_x != ele_y for ele_x, ele_y in zip(string_1, string_2))
assert f(u"a", u"b") == 1
|
benchmark_functions_edited/f8328.py
|
def f(initial_investment, cflow):
year = 0
amount = 0 #Total money
while amount < initial_investment:
amount += cflow[year]
year += 1
if year == len(cflow):
return 'Infeasible'
return year
assert f(0, [2]) == 0
|
benchmark_functions_edited/f12553.py
|
def f(distance, interval):
trace = round(distance / interval)
return(trace)
assert f(2,2) == 1
|
benchmark_functions_edited/f2833.py
|
def f(n):
assert(n >= 0)
if n <= 1:
return n
return f(n - 1) + f(n - 2)
assert f(2) == 1
|
benchmark_functions_edited/f9176.py
|
def f(a, b):
count = 0
for el in a:
if el in b:
count += 1
return count
assert f(list('abcd'), list('abcde')) == 4
|
benchmark_functions_edited/f8408.py
|
def f(underlying, strike, gearing=1.0):
return gearing * max(strike - underlying, 0)
assert f(10, 10) == 0
|
benchmark_functions_edited/f7180.py
|
def f(number, min_, max_):
if min_ is not None and number < min_:
return min_
if max_ is not None and number > max_:
return max_
return number
assert f(3, None, None) == 3
|
benchmark_functions_edited/f6327.py
|
def f(base, index, value):
if value is None:
value = ''
base[index] = value.rstrip("\n")
return len(value) - len(base[index])
assert f(list("abc"), 0, "abc\r") == 0
|
benchmark_functions_edited/f14164.py
|
def f(p, q, r):
# We use Sarrus' Rule to calculate the determinant
# (could also use the Numeric package...)
sum1 = q[0]*r[1] + p[0]*q[1] + r[0]*p[1]
sum2 = q[0]*p[1] + r[0]*q[1] + p[0]*r[1]
return sum1 - sum2
assert f( (0,0), (1,0), (2,0) ) == 0
|
benchmark_functions_edited/f8712.py
|
def f(rule):
total = len(rule.get("tokens"))
for _ in ("prev_classes", "prev_tokens", "next_tokens", "next_classes"):
val = rule.get(_)
if val:
total += len(val)
return total
assert f(
{
"tokens": ["a", "b", "c"]
}
) == 3
|
benchmark_functions_edited/f7679.py
|
def f(seq, val):
for v in seq:
if v >= val:
return v
return None
assert f(tuple(list(range(10))), 1) == 1
|
benchmark_functions_edited/f13248.py
|
def f(key,*dicts):
r = None
for d in dicts:
try:
r = d[key]
break
except KeyError:
continue
if r is None:
raise KeyError("Could not find key {0} in any of the dictionaries supplied!".format(key))
return r
assert f(2, {1: 1}, {2: 2}) == 2
|
benchmark_functions_edited/f10044.py
|
def f(x):
num = 0
scale = 1
for i in range(len(x)-1, -1, -1):
num = num + (ord(x[i])*scale)
scale = scale*256
return num
assert f(b"") == 0
|
benchmark_functions_edited/f13305.py
|
def f(number, base=1):
return number - (number % base)
assert f(7, 4) == 4
|
benchmark_functions_edited/f6524.py
|
def f(n: int) -> int:
assert n >= 1
a, b = 1, 1
for _ in range(n):
a, b = b, a + b
return a
assert f(1) == 1
|
benchmark_functions_edited/f3084.py
|
def f(line):
return sum((int(c) if c.isdigit() else c == '-') for c in line[0:68]) % 10
assert f(
"1 25544U 98067A 19334.92855895 .00001014 00000-0 12052-3 0 9996",
) == 6
|
benchmark_functions_edited/f4311.py
|
def f(y1, y2, x1, x2):
if x2-x1 == 0:
slope = 0
else:
slope = (y2 - y1) / (x2 - x1)
return slope
assert f(1, 2, 1, 2) == 1
|
benchmark_functions_edited/f7244.py
|
def f(col, mean, std):
return (col - mean)/std
assert f(11, 11, 1) == 0
|
benchmark_functions_edited/f4201.py
|
def f(k, n, a, b):
if (n % 2) == 0:
return((k + a) % 255)
else:
return((k + b) % 255)
assert f(3, 3, 1, 1) == 4
|
benchmark_functions_edited/f12307.py
|
def f(m, n):
while m != n:
if m > n:
m -= n
else:
n -= m
return m
assert f(1, 7) == 1
|
benchmark_functions_edited/f5283.py
|
def f(*args):
for a in args:
if a is not None: return a
return None
assert f(1, None) == 1
|
benchmark_functions_edited/f5122.py
|
def f(a, b):
while b:
a, b = b, a % b
return a
assert f(3, 4) == 1
|
benchmark_functions_edited/f9577.py
|
def f(f, clip, *a, **k):
newclip = f(clip, *a, **k)
if hasattr(newclip, 'audio') and (newclip.audio != None):
newclip.audio = f(newclip.audio, *a, **k)
return newclip
assert f(lambda a, b: a*b, 1, 3) == 3
|
benchmark_functions_edited/f2096.py
|
def f(x, y):
return (x * x) + (y * y)
assert f(1, 2) == 5
|
benchmark_functions_edited/f11453.py
|
def f(val):
try:
return int(val)
except ValueError:
if len(val) == 0:
return 0
else:
raise ValueError("Cannot convert to integer: {}".format(val))
assert f(False) == 0
|
benchmark_functions_edited/f14407.py
|
def f(box1, box2):
x1, y1, w1, h1 = box1
x2, y2, w2, h2 = box2
xl1, yl1, xr1, yr1 = x1, y1, x1 + w1, y1 + h1
xl2, yl2, xr2, yr2 = x2, y2, x2 + w2, y2 + h2
overlap_w = max(min(xr1, xr2) - max(xl1, xl2), 0)
overlap_h = max(min(yr1, yr2) - max(yl1, yl2), 0)
return overlap_w * overlap_h / (w1 * h1 + w2 * h2 - overlap_w * overlap_h)
assert f(
[0, 0, 2, 2],
[0, 0, 2, 2]) == 1
|
benchmark_functions_edited/f9040.py
|
def f(usage, rate):
usage = float(usage) / rate
if usage < 1:
usage = round(usage, 1)
else:
usage = int(round(usage, 0))
return usage
assert f(10, 5) == 2
|
benchmark_functions_edited/f11606.py
|
def f(value, align):
if value % align != 0:
return value + align - (value % align)
else:
return value
assert f(3, 1) == 3
|
benchmark_functions_edited/f13631.py
|
def f(
n_tokens: int, min_n_steps: int = 3, max_n_steps: int = 20, max_tokens: int = 500
) -> int:
token_ratio = 1 - (min(n_tokens, max_tokens) / max_tokens)
return int(min_n_steps + round(token_ratio * (max_n_steps - min_n_steps), 0))
assert f(200, 3, 5) == 4
|
benchmark_functions_edited/f2868.py
|
def f(A, r, g, t):
return((A/r) * (1 - 1/((1+r)**t)))
assert f(100, 0.1, 1, 0) == 0
|
benchmark_functions_edited/f6974.py
|
def f(prob):
return prob / (1 - prob)
assert f(0.5) == 1
|
benchmark_functions_edited/f6929.py
|
def f(c):
cols = {'chrom': 0, 'start': 1, 'end': 2, 'gene_name': 3,
'score': 4, 'strand': 5, 'frame': 6, 'feature': 7,
'source': 8}
return cols.get(c, 9)
assert f('transcript') == 9
|
benchmark_functions_edited/f12802.py
|
def f(V_max, rho_max, rho):
return V_max*rho*(1-rho/rho_max)
assert f(1, 1, 0) == 0
|
benchmark_functions_edited/f11779.py
|
def f(score1,score2,score3,score4,score5):
sum_of_all_five_scores = score1 + score2 + score3 + score4 + score5
min_score = min(score1,score2,score3,score4,score5)
max_score = max(score1,score2,score3,score4,score5)
return sum_of_all_five_scores - min_score - max_score
assert f(0, 0, 0, 0, 0) == 0
|
benchmark_functions_edited/f5062.py
|
def f(num, modulo = 9):
# return the remainder if it is more than zero, else return the modulo
return num % modulo or modulo
assert f(19) == 1
|
benchmark_functions_edited/f3045.py
|
def f(a, b):
res = a * b
return res
assert f(0, 0) == 0
|
benchmark_functions_edited/f7245.py
|
def f(x):
if x == 'Government':
return 1
elif x == 'Private':
return 2
elif x == 'Self-employed':
return 3
else:
return 0
assert f("Government") == 1
|
benchmark_functions_edited/f4979.py
|
def f(data):
return data['totalSize']
assert f(
{'totalSize': 0}
) == 0
|
benchmark_functions_edited/f7035.py
|
def f(f, x0, h):
df = (f(x0+h)-2*f(x0)+f(x0-h))/(h*h)
return df
assert f(lambda x: -x, 3, -10) == 0
|
benchmark_functions_edited/f10609.py
|
def f(ordered_bow, hate_grams):
score = 0
ordered_bow = list(ordered_bow)
bow_counted = {gram: ordered_bow.count(gram) for gram in ordered_bow}
for term in hate_grams:
token = bow_counted.get(term)
score += token if token != None else 0
return score
assert f(('a', 0), ['a']) == 1
|
benchmark_functions_edited/f406.py
|
def f(x, mean, std):
return x * std + mean
assert f(0, 1, 1) == 1
|
benchmark_functions_edited/f10696.py
|
def f( x, a, b ):
return a + b*x
assert f( 1, 2, 3 ) == 5
|
benchmark_functions_edited/f10267.py
|
def f(lines):
floor = 0
for index, b in enumerate(lines[0]):
if b == "(":
floor += 1
elif b == ")":
floor -= 1
else:
raise Exception
if floor < 0:
return index + 1
assert f(
['()())']) == 5
|
benchmark_functions_edited/f13393.py
|
def f(x, xi):
assert x >= xi[0] and x <= xi[-1], ValueError(
'x=%g not in [%g,%g]' % (x, xi[0], xi[-1])
)
for i in range(len(xi) - 1):
if xi[i] <= x and x <= xi[i + 1]:
return i
assert f(50.0, [25.0, 75.0]) == 0
|
benchmark_functions_edited/f14331.py
|
def f(value):
if type(value) is not float:
try:
value = float(value)
except ValueError:
return 0
if float(value) <= 10:
return float(value/10)*100
return 100
assert f(0) == 0
|
benchmark_functions_edited/f10748.py
|
def f(B):
Mp = B + (1 / 3) * B ** 3
return Mp
assert f(0) == 0
|
benchmark_functions_edited/f5316.py
|
def f(p, q):
while q != 0:
if p < q: (p,q) = (q,p)
(p,q) = (q, p % q)
return p
assert f(1, 1) == 1
|
benchmark_functions_edited/f1869.py
|
def f(x, s):
return (x-s/2)*(x>s) - (x+s/2)*(-x>s) + ((x**2)/(2*s))*(x<=s and -x<=s)
assert f(0, 1) == 0
|
benchmark_functions_edited/f6986.py
|
def f(line: bytes) -> int:
try:
return int(line.strip(b'{}'))
except ValueError as _:
return int(line[line.rfind(b'{')+1:-1])
assert f(b'{0}') == 0
|
benchmark_functions_edited/f12676.py
|
def f(*args):
if args[2] == 0:
return args[0]
else:
return (args[1] / args[2])
assert f(1, 3, 3) == 1
|
benchmark_functions_edited/f4202.py
|
def f(n):
i = 0
j = 1
n = n - 1
while n >= 0:
i, j = j, i + j # i = j; j = i + j
n = n - 1
return i
assert f(5) == 5
|
benchmark_functions_edited/f2235.py
|
def f(t, v):
# x(t) = (-1/2)t^2 + (1/2 + vx)t
return -1/2 * t**2 + (1/2 + v) * t
assert f(0, 1) == 0
|
benchmark_functions_edited/f13723.py
|
def f(contacts, number):
while number<1 or number>len(contacts):
print()
print("Please enter a number from 1 to ", len(contacts))
number = int(input("Number: "))
return number
assert f(
[
"<NAME>",
"<NAME>",
"<NAME>",
"<NAME>",
"<NAME>",
],
1,
) == 1
|
benchmark_functions_edited/f5185.py
|
def f(x, m, b):
return m * x + b
assert f(2, 1, 0) == 2
|
benchmark_functions_edited/f2564.py
|
def f(n):
count = 0
while n > 0:
count = count + 1
n = n & (n - 1)
return count
assert f(0b000000000000000000000001000000) == 1
|
benchmark_functions_edited/f9143.py
|
def f(list):
soma=0
if len(list)>0:
for pos, item in enumerate(list):
if pos%2==0:
soma=soma+item
mult=soma*list[-1]
return mult
else:
return 0
assert f(list()) == 0
|
benchmark_functions_edited/f6567.py
|
def f(name):
try:
location = len(name) - "".join(reversed(name)).index(".")
index = int(name[location:])
except Exception:
index = 0
return index
assert f( "Cylinder" ) == 0
|
benchmark_functions_edited/f13345.py
|
def f(value: int) -> int:
if value <= 0x3F:
return 1
elif value <= 0x3FFF:
return 2
elif value <= 0x3FFFFFFF:
return 4
elif value <= 0x3FFFFFFFFFFFFFFF:
return 8
else:
raise ValueError("Integer is too big for a variable-length integer")
assert f(0x0000000000000100) == 2
|
benchmark_functions_edited/f12127.py
|
def f(x):
try:
return int(x)
except ValueError:
try:
return float(x)
except ValueError:
raise ValueError('invalid literal for f(): \'{}\''.format(x))
assert f(0) == 0
|
benchmark_functions_edited/f4272.py
|
def f(field):
if field == '' or field == []:
return None
else:
return field
assert f(5) == 5
|
benchmark_functions_edited/f13050.py
|
def f(num1, num2):
if num1 > num2:
smaller = num2
else:
smaller = num1
for i in range(1, smaller + 1):
if ((num1 % i == 0) and (num2 % i == 0)):
return i
assert f(7, 8) == 1
|
benchmark_functions_edited/f7108.py
|
def f(data_obj, factor=1):
decimal_places = -int(f'{factor:e}'.split('e')[-1])
return round(int.from_bytes(data_obj, "little", signed=True) * factor, decimal_places)
assert f(b'\x00\x00\x00\x00', 0) == 0
|
benchmark_functions_edited/f295.py
|
def f(m, g, M):
return m + M*g
assert f(0, 0, 4) == 0
|
benchmark_functions_edited/f8708.py
|
def f(binary):
decimal = 0
index = 0
while binary > 0:
last = binary % 10
binary = binary / 10
decimal += (last * (2 ** index))
index += 1
return decimal
assert f(0) == 0
|
benchmark_functions_edited/f14327.py
|
def f(h, w, diagonal=0):
if diagonal >= 0:
return max(min(h, w - diagonal), 0)
else:
return max(min(w, h + diagonal), 0)
assert f(3, 4) == 3
|
benchmark_functions_edited/f6684.py
|
def f(rsp: bytes):
for line in rsp.decode().split("\r\n"):
ss = line.split()
if ss[0].strip() == "Session:":
return int(ss[1].split(";")[0].strip())
assert f(b"Session: 1 ") == 1
|
benchmark_functions_edited/f4466.py
|
def f(i):
import codecs
return int(codecs.encode(i, 'hex'), 16)
assert f(b'\x09') == 9
|
benchmark_functions_edited/f9250.py
|
def f(captcha):
prev = captcha[0]
captcha += prev
total = 0
for c in captcha[1:]:
curr = int(c)
if curr == prev:
total += curr
prev = curr
return total
assert f(
"91212129"
) == 9
|
benchmark_functions_edited/f5081.py
|
def f(cube):
L = [1] * cube
for i in range(cube):
for j in range(i):
L[j] = L[j] + L[j - 1]
L[i] = 2 * L[i - 1]
return L[cube - 1]
assert f(2) == 6
|
benchmark_functions_edited/f1788.py
|
def f(x):
return x**4 + 4**x
assert f(0) == 1
|
benchmark_functions_edited/f1205.py
|
def f(veos, vpos, eos, pos):
return (veos - vpos) / (eos - pos)
assert f(1, 1, 2, 1) == 0
|
benchmark_functions_edited/f12612.py
|
def f(new_aux: float, close: float):
if new_aux:
return round(new_aux * close, 8)
return 0.0
assert f(10, 0) == 0
|
benchmark_functions_edited/f6678.py
|
def f(arg):
if arg > 0:
return arg
else:
return 0
assert f(1) == 1
|
benchmark_functions_edited/f2534.py
|
def f(n: int) -> int:
r = 0
t = 1
while t < n:
t = 2 * t
r = r + 1
return r
assert f(13) == 4
|
benchmark_functions_edited/f13544.py
|
def f(position):
if position == 0 or position == 1:
return position
else:
return f(position - 1) + f(position - 2)
return -1
assert f(4) == 3
|
benchmark_functions_edited/f11270.py
|
def f(value, key):
values = [r.get(key, 0) if hasattr(r, 'get') else getattr(r, key, 0) for r in value]
return max(values)
assert f([{'a': 1}], 'a') == 1
|
benchmark_functions_edited/f10588.py
|
def f(cloth: list) -> int:
area = 0
for row in cloth:
for col in row:
area += (len(col) >= 2)
return area
assert f(
[[[]]]) == 0
|
benchmark_functions_edited/f7457.py
|
def asymmetry (A,B,C):
return (2.*B - A - C)/(A - C)
assert f(3,2,1) == 0
|
benchmark_functions_edited/f9969.py
|
def f(text):
try:
retval = float(text)
except ValueError:
retval = text
return retval
assert f(3) == 3
|
benchmark_functions_edited/f6575.py
|
def f(n):
if n <= 0:
return 1
result = 0
for i in range(1, 200):
result += f(n - i)
return result
assert f(0) == 1
|
benchmark_functions_edited/f10890.py
|
def f(text):
text_formatted = text.split(" ")
length_of_text = len(text_formatted)
return length_of_text
assert f("a") == 1
|
benchmark_functions_edited/f6670.py
|
def f(s):
try:
return float(s)
except ValueError:
return 0
assert f('-1.0.0') == 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.