file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f14319.py
|
def f(xs, x1, x2):
xmax = max(x1, x2)
if xmax >= xs[-1]:
return len(xs) - 1
elif xmax <= xs[0]:
ul = 0
return ul
else:
for i, x in enumerate(xs):
if not x < xmax:
ul = i
return ul
ul = len(xs) - 1
return ul
assert f(range(10), 1, 3) == 3
|
benchmark_functions_edited/f3801.py
|
def f(x: int) -> int:
if x <= 2:
return 1
r1, r2 = f(x - 1), f(x - 2)
ret = r1 + r2
return ret
assert f(-1) == 1
|
benchmark_functions_edited/f9238.py
|
def f(cxs):
def count_pairs(items):
n = len(items)
return int(n*(n-1)/2)
return sum([count_pairs(c[1]) for c in cxs])
assert f( [("a", set([1])), ("b", set([2])), ("c", set([3])), ("d", set([4])), ("e", set([5]))] ) == 0
|
benchmark_functions_edited/f8643.py
|
def f(L):
counter = 0
for i in L:
if i > 0:
counter += 1
else:
continue
return counter
assert f( [-1, -2, -3, -4] ) == 0
|
benchmark_functions_edited/f6519.py
|
def f(x, df_low, f1, n):
f = x
return df_low * (1/(f-f1))**n
assert f(0.5, 1, 0.0, 0) == 1
|
benchmark_functions_edited/f10852.py
|
def f(pattern, supports):
max_support = -1
for item in pattern:
max_support = max(max_support, supports[item])
return max_support
assert f(
[1, 4, 4, 4, 4, 2, 4, 4], {1: 3, 4: 6, 2: 4, 10: 2, 7: 2}) == 6
|
benchmark_functions_edited/f3126.py
|
def f(p=0):
res = p / 2
return res
assert f(10) == 5
|
benchmark_functions_edited/f10575.py
|
def f(predicate, iterable):
return sum(map(predicate, iterable))
assert f(lambda x: x > 0, [1, 2, -3, 4]) == 3
|
benchmark_functions_edited/f5823.py
|
def f(am):
return (((abs(am) + 2) * (abs(am) + 1)) >> 1)
assert f(2) == 6
|
benchmark_functions_edited/f1365.py
|
def f(op):
return int(round(op * 4096.0))
assert f(0.0009765625) == 4
|
benchmark_functions_edited/f2042.py
|
def f(big_number):
return (1 + 1/big_number) ** big_number
assert f(1) == 2
|
benchmark_functions_edited/f12851.py
|
def f(word: str, partitions: int) -> int:
a = ord('a')
z = ord('z')
value = ord(word[0].lower())
if partitions > 1 and a <= value <= z:
pos = value - a
return int(pos * (partitions - 1) / (z - a + 1)) + 1
# Catch-all for numbers, symbols and diacritics.
return 0
assert f('test', 2) == 1
|
benchmark_functions_edited/f6451.py
|
def f(items: dict) -> int:
_number = [item.number for item in items.values()]
try:
return max(_number)
except ValueError:
return 0
assert f({}) == 0
|
benchmark_functions_edited/f2283.py
|
def f(args_tuple):
function, args = args_tuple
return function(*args)
assert f(
(lambda x, y, z: x + y + z, (0, 0, 1,),)
) == 1
|
benchmark_functions_edited/f10140.py
|
def f(array, item):
for i in range(len(array)):
if array[i] == item:
return i
return -1
assert f([1, 3, 5, 7], 3) == 1
|
benchmark_functions_edited/f3207.py
|
def f(s):
return len(s.split(" "))
assert f(
"There are 12 words in this sentence."
) == 7
|
benchmark_functions_edited/f3271.py
|
def f(row):
return sum([" " in i for i in row if isinstance(i, str)])
assert f([]) == 0
|
benchmark_functions_edited/f6794.py
|
def f(n, m):
r = 1
for i in range(n, n+m):
r *= i
return r
assert f(1, 2) == 2
|
benchmark_functions_edited/f8671.py
|
def f(obj, keys, default=None):
for key in keys:
val = obj.get(key)
if val is not None:
return val
return default
assert f(dict(), ['b', 'c'], 4) == 4
|
benchmark_functions_edited/f3467.py
|
def f(k, l):
assert l >= 0
return k**l
assert f(3, 0) == 1
|
benchmark_functions_edited/f3294.py
|
def f(values):
return sum(values) / len(values)
assert f([-1, 1]) == 0
|
benchmark_functions_edited/f6861.py
|
def f(novice_status):
if novice_status is 0: return "varsity"
if novice_status is 1: return "novice"
return novice_status
assert f(2) == 2
|
benchmark_functions_edited/f339.py
|
def f(value, arg):
return int(value) * int(arg)
assert f(2, 0) == 0
|
benchmark_functions_edited/f13839.py
|
def f(x, y):
x, y = abs(x), abs(y)
steps = 0
while x != 0 or y != 0:
if y > x:
y -= 2
steps += 1
elif y < x:
x -= 2
steps += 2
else:
x -= 1
y -= 1
steps += 1
return steps
assert f(0, 8) == 4
|
benchmark_functions_edited/f12709.py
|
def f(n, x):
# When n is smaller than 1, stop comparing
if n < 1:
return x
else:
# take last digit of n
digit = n % 10
# take off last digit of n
n = int(n / 10)
# Compare each digit of n
if digit > x:
x = digit
return f(n, x)
assert f(10000, 0) == 1
|
benchmark_functions_edited/f4657.py
|
def f(n: int) -> int:
if n < 10:
return n
return (f(sum(map(int, str(n)))))
assert f(16) == 7
|
benchmark_functions_edited/f141.py
|
def f(val, idx: int) -> int:
return 1&(val>>idx)
assert f(0, 4) == 0
|
benchmark_functions_edited/f99.py
|
def f(f):
return len(f)-1
assert f( [1, 0, 1] ) == 2
|
benchmark_functions_edited/f5749.py
|
def f(first_vector, second_vector):
return sum([first_vector[i]*second_vector[i] for i in range(len(first_vector))])
assert f(
[0, 0, 0, 0, 0],
[1, 0, 1, 0, 1]) == 0
|
benchmark_functions_edited/f8817.py
|
def f(number):
multipliers = []
n = 0
while n < number:
if n % 3 == 0 or n % 5 == 0:
multipliers.append(n)
n += 1
return sum(multipliers)
assert f(4) == 3
|
benchmark_functions_edited/f3394.py
|
def f(i, p):
return i - 1 if not p(i) else f(i+1, p)
assert f(4, lambda n: n**2 < 16) == 3
|
benchmark_functions_edited/f1097.py
|
def f(a, b):
return 0.5 * (a - b)**2
assert f(-1, -1) == 0
|
benchmark_functions_edited/f700.py
|
def f(a, b, c):
return a * b * c
assert f(1, 1, 0) == 0
|
benchmark_functions_edited/f3222.py
|
def f(bbox):
[x1, y1, x2, y2] = bbox
return (y2 - y1) / (x2 - x1)
assert f(
[10, 10, 20, 20]
) == 1
|
benchmark_functions_edited/f6556.py
|
def f(val, n):
try:
if val & 2**n:
return 1
else:
return 0
except TypeError:
return -1
assert f(12, 1) == 0
|
benchmark_functions_edited/f1280.py
|
def f(lst):
if(lst == []):
return 0
return 1 + f(lst[1:])
assert f(list()) == 0
|
benchmark_functions_edited/f8262.py
|
def f(cards):
if sum(cards)==21 and len(cards)==2:
return 0
if 11 in cards and sum(cards)>21:
cards.remove(11)
cards.append(1)
return sum(cards)
assert f( [1, 2, 3] ) == 6
|
benchmark_functions_edited/f8326.py
|
def f(dna, nucleotide):
return dna.count(nucleotide)
assert f(
'ATCGGC', 'A') == 1
|
benchmark_functions_edited/f3944.py
|
def f(mass):
out = 0
fuel = mass // 3 - 2
while fuel > 0:
out += fuel
fuel = fuel // 3 - 2
return out
assert f(12) == 2
|
benchmark_functions_edited/f4840.py
|
def f(limit, maximum):
return 2.0 * maximum - limit
assert f(-1, 2) == 5
|
benchmark_functions_edited/f5217.py
|
def f(num1, num2):
result = num1 + num2
return result
assert f(2, 2) == 4
|
benchmark_functions_edited/f4002.py
|
def f(seconds: int) -> int:
if seconds < 60:
return seconds
return seconds % 60
assert f(61) == 1
|
benchmark_functions_edited/f11223.py
|
def f(d, key):
return d.get(key)
assert f(
{'a': 2, 'b': 2}, 'a') == 2
|
benchmark_functions_edited/f12292.py
|
def f(r, sy, sx):
return r * (sy / sx)
assert f(0, 5, 1) == 0
|
benchmark_functions_edited/f1595.py
|
def f(x_func, T, y0, g):
return x_func(T) * (g - y0)
assert f(lambda T: 2**T, 2, 1, 3) == 8
|
benchmark_functions_edited/f13515.py
|
def f(*args, **kwargs):
report, func, *args = args
if not callable(func):
func = getattr(report, func)
try:
return func(*args, **kwargs)
except Exception as ex:
msg = f"{type(ex).__name__}: {ex}"
report.log_error(msg, code=ex)
return None
assert f(None, len, []) == 0
|
benchmark_functions_edited/f3113.py
|
def f(n, r):
return n * (r**2)
assert f(2, 2) == 8
|
benchmark_functions_edited/f10401.py
|
def f(*args):
for b, e in args:
if b:
return e
assert f(
(True, 2),
(False, 3),
) == 2
|
benchmark_functions_edited/f3125.py
|
def f(ls, val, n):
return [i for i, x in enumerate(ls) if x == val][n - 1]
assert f("1234", "4", 1) == 3
|
benchmark_functions_edited/f3010.py
|
def f(func, arg):
try:
return func(arg)
except:
return None
assert f(int, '1') == 1
|
benchmark_functions_edited/f5019.py
|
def f(lane_id, road_lane_set):
for i, lane_set in enumerate(road_lane_set):
if lane_id in lane_set:
return i
return -1
assert f(1, [[1, 2, 3], [7, 8, 9], [4, 5, 6]]) == 0
|
benchmark_functions_edited/f11749.py
|
def f(node):
if node is None:
return 0
else:
left_height = f(node.left)
right_height = f(node.right)
if left_height > right_height:
return left_height+1
else:
return right_height+1
assert f(None) == 0
|
benchmark_functions_edited/f13471.py
|
def f(density_soil, vs_soil, density_rock, vs_rock):
impedance = density_soil * vs_soil / (density_rock * vs_rock)
return impedance
assert f(2000, 2000, 2000, 1000) == 2
|
benchmark_functions_edited/f1901.py
|
def f(a, order):
return a ^ (1 << order)
assert f(5, 2) == 1
|
benchmark_functions_edited/f1089.py
|
def f(iterable):
tot = 0
for i in iterable:
tot += i
return tot
assert f(range(3)) == 3
|
benchmark_functions_edited/f10665.py
|
def f(x,y):
x_num = int(x[0].split('_')[1])
y_num = int(y[0].split('_')[1])
if x_num > y_num:
return 1
elif x_num < y_num:
return -1
else:
return 0
assert f(
('a_2', {'a':'b'}),
('a_1', {'a':'b'})
) == 1
|
benchmark_functions_edited/f7436.py
|
def f(character: str) -> int:
if character.islower():
return ord(character) - ord("a")
else:
return ord(character) - ord("A")
assert f("A") == 0
|
benchmark_functions_edited/f6368.py
|
def f(a, n):
lm, hm = 1, 0
low, high = a % n, n
while low > 1:
r = high / low
nm, new = hm - lm * r, high - low * r
lm, low, hm, high = nm, new, lm, low
return lm % n
assert f(1, 10) == 1
|
benchmark_functions_edited/f5635.py
|
def f(val):
if type(val) == int and 0 <= val < 2**32:
return val
else:
raise ValueError("0 <= random seed < 2^32 is the correct range")
assert f(1) == 1
|
benchmark_functions_edited/f10413.py
|
def f(x: float, constant: float) -> float:
if constant <= 0:
raise ValueError('Squash constant must be greater than zero.')
if x < 0:
raise ValueError('Squash can only be performed on a positive value.')
return x / (x + constant)
assert f(0.0, 1) == 0
|
benchmark_functions_edited/f6271.py
|
def f(obj):
if len(obj) == 1:
return obj[0]
else:
return obj
assert f([3]) == 3
|
benchmark_functions_edited/f8865.py
|
def f(n, desired_rows=20):
if n < desired_rows:
return 1
j = int(n / desired_rows)
return round(j, -len(str(j)) + 1)
assert f(13) == 1
|
benchmark_functions_edited/f3451.py
|
def f(string, char):
i = 0
while i < len(string) and string[i] == char:
i += 1
return i
assert f(
"aaa",
"a",
) == 3
|
benchmark_functions_edited/f6883.py
|
def f(vectorA, vectorB):
result = 0
for i in range(0, len(vectorA)):
result += vectorA[i] * vectorB[i]
return result
assert f( [1,0,0], [0,1,0] ) == 0
|
benchmark_functions_edited/f4021.py
|
def f(coeffs, n):
total = 0
for i, c in enumerate(coeffs):
total += c * n ** i
return total
assert f((), 10) == 0
|
benchmark_functions_edited/f14178.py
|
def f(op, op1, op2):
#checks what operator is being used and returns the result
if op == "^":
return op1 ^ op2
elif op == "*":
return op1 * op2
elif op == "/":
if op2 == 0:
#raises an error when divided by zero
raise ValueError('Cannot divide by zero')
return op1 / op2
elif op == "+":
return op1 + op2
else:
return op1 - op2
assert f( "*", 2, 2 ) == 4
|
benchmark_functions_edited/f6289.py
|
def f(database):
num_tuning_entries = 0
for section in database["sections"]:
num_tuning_entries += len(section["results"])
return num_tuning_entries
assert f({"sections": [{"results": []}]}) == 0
|
benchmark_functions_edited/f8753.py
|
def f(s1: str, s2: str) -> int:
for (i, (c1, c2)) in enumerate(zip(s1, s2)):
if c1 != c2:
return i
return min(len(s1), len(s2))
assert f(
"foo",
"bar") == 0
|
benchmark_functions_edited/f14402.py
|
def f(is_np, is_seq=False):
if is_np:
# in case of sequence (is_seq == True): (S, F)
# in case of sample: (F)
return 0 + is_seq
else:
# in case of sequence: (B, S, F)
# in case of sample: (B, F)
return 1 + is_seq
assert f(False) == 1
|
benchmark_functions_edited/f7956.py
|
def f(lines):
for i,line in enumerate(lines):
if line.startswith("#include"):
return i
return 0
assert f(
["#include <algorithm>", "int main() {", " return 0;", "}", "int main() {", " return 0;", "}"]) == 0
|
benchmark_functions_edited/f5654.py
|
def f(x, y):
x, y = max(x, y), min(x, y)
if y==0:
return x
return f(y, x%y)
assert f(2, 4) == 2
|
benchmark_functions_edited/f10611.py
|
def f(A):
if len(A) == 0:
return 0
if len(A) == 1:
return A[0]
a = max(A)
b = min(A)
a_index = A.index(a)
b_index = A.index(b)
if a_index > b_index:
return a - b
else:
return b - a
assert f([1, 2, 2, 3]) == 2
|
benchmark_functions_edited/f8276.py
|
def f(v):
try:
return int(v)
except (ValueError, TypeError):
pass
try:
return float(v)
except (ValueError, TypeError):
pass
return v
assert f(5) == 5
|
benchmark_functions_edited/f12942.py
|
def f(shape):
assert len(shape) == 2
return 2 * (shape[0] - 2) + 2 * (shape[1] - 2) + 4
assert f(
(2, 2)) == 4
|
benchmark_functions_edited/f475.py
|
def f(r, u):
return -r if u < 0 else r
assert f(1, 1) == 1
|
benchmark_functions_edited/f6647.py
|
def f(s: str):
try:
nr = int(s)
except (ValueError, TypeError):
nr = 0
return nr
assert f('10a') == 0
|
benchmark_functions_edited/f657.py
|
def f(T, r):
return 0 * T + r
assert f(1, 2) == 2
|
benchmark_functions_edited/f12179.py
|
def f(a, b):
# Base case
if b == 0:
return a
# Recursive case
return f(b, a % b)
assert f(9, 18) == 9
|
benchmark_functions_edited/f9574.py
|
def f(Mh_r: float, t_r: float, n: float) -> float:
return t_r - Mh_r / n
assert f(10, 10, 1) == 0
|
benchmark_functions_edited/f14079.py
|
def f(artifacts_dict: dict, name: str = "rst_files") -> int:
return max([r["id"] for r in artifacts_dict["artifacts"] if r["name"] == name])
assert f(
{"artifacts": [{"id": 1, "name": "other_files"}, {"id": 2, "name": "rst_files"}]}
) == 2
|
benchmark_functions_edited/f11206.py
|
def f(start, stop, step):
assert(step != 0)
assert(start is not None and stop is not None and step is not None)
if step > 0 and start < stop:
return 1 + (stop - 1 - start) // step
elif step < 0 and start > stop:
return 1 + (start - 1 - stop) // -step
else:
return 0
assert f(1, 5, 2) == 2
|
benchmark_functions_edited/f12452.py
|
def f(line, pos=0, tag="tu"):
tag1 = f"<{tag} ".encode()
tag2 = f"<{tag}>".encode()
try:
pos1 = line.index(tag1, pos)
except ValueError:
pos1 = -1
try:
pos2 = line.index(tag2, pos)
except ValueError:
pos2 = -1
if pos1 > -1 and pos2 > -1:
return min(pos1, pos2)
return max(pos1, pos2)
assert f(b"<tu>") == 0
|
benchmark_functions_edited/f200.py
|
def f(masa_num):
return (masa_num - 1) // 2
assert f(3) == 1
|
benchmark_functions_edited/f9841.py
|
def f(label, labels):
if label.isdigit():
return int(label)
if label in labels:
return labels.index(label)
assert f('b', ['a', 'b', 'c', 'd']) == 1
|
benchmark_functions_edited/f46.py
|
def f(a,b):
return (a+b)%2
assert f(0,0) == 0
|
benchmark_functions_edited/f13253.py
|
def f(schedule):
Cj = 0
sum_Cj = 0
for job in schedule:
Cj += job.processing
sum_Cj += Cj
return sum_Cj
assert f([]) == 0
|
benchmark_functions_edited/f5007.py
|
def f(val, mini, maxi):
return max(mini, min(maxi, val))
assert f(1, 1, 3) == 1
|
benchmark_functions_edited/f13949.py
|
def f(seq, pred=lambda x: x):
ret = 0
for x in seq:
if pred(x):
ret += 1
return ret
assert f(
["a", "", "c"]
) == 2
|
benchmark_functions_edited/f6527.py
|
def f(arr):
sorted_array = sorted(arr)
return min(abs(x - y) for x, y in zip(sorted_array, sorted_array[1:]))
assert f([1, 2]) == 1
|
benchmark_functions_edited/f13018.py
|
def f(lang, word):
if lang == 'en':
cnt = len(''.join(" x"[c in"aeiouy"]for c in(word[:-1]if'e' == word[-1]else word)).split())
else:
cnt = len(''.join(" x"[c in"aeiou"]for c in(word[:-1]if'e' == word[-1]else word)).split())
return cnt
assert f('en', 'flying') == 1
|
benchmark_functions_edited/f82.py
|
def f(x, y):
return abs(x["par"] - y["par"])
assert f(
{"par": 3},
{"par": 2},
) == 1
|
benchmark_functions_edited/f8555.py
|
def f(n):
T = [0 for _ in range(n + 1)]
T[0] = 1
T[1] = 1
for k in range(2, n + 1):
T[k] = k * T[k - 1]
return T[n]
assert f(2) == 2
|
benchmark_functions_edited/f12552.py
|
def f(version):
if version is None:
return 1
return int(version.split('.')[0])
assert f('1') == 1
|
benchmark_functions_edited/f2300.py
|
def f(seq):
return float(sum(seq))/len(seq) if len(seq) > 0 else float('nan')
assert f([1, 2, 3, 4, 5]) == 3
|
benchmark_functions_edited/f14537.py
|
def f(directions):
floor = 0
for step in directions:
floor += {"(": 1, ")": -1}[step]
return floor
assert f("(()(()(") == 3
|
benchmark_functions_edited/f7625.py
|
def f(day):
days = ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"]
return days.index(day.upper())
assert f("friday") == 4
|
benchmark_functions_edited/f11194.py
|
def f(num_lst):
return sum(num_lst) / len(num_lst)
assert f([1,2,3]) == 2
|
benchmark_functions_edited/f13192.py
|
def f(t_ticks, q_ticks):
j = t_ticks // q_ticks
return int(min(abs(t_ticks - q_ticks * j), abs(t_ticks - q_ticks * (j + 1))))
assert f(0, 5) == 0
|
benchmark_functions_edited/f14064.py
|
def f(c_min, temp_hot_in, temp_cold_in):
return c_min*(temp_hot_in-temp_cold_in)
assert f(0, 120.0, 30) == 0
|
benchmark_functions_edited/f14045.py
|
def f(hit_limit):
return ((20 - hit_limit) / 3) * 2
assert f(11) == 6
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.