file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f10122.py | def f(array, query):
for i, value in enumerate(array):
if value == query:
return i
return -1
assert f(list(range(20)), 0) == 0 |
benchmark_functions_edited/f7572.py | def f(string):
return None if string.lower() == "none" else int(string)
assert f("1") == 1 |
benchmark_functions_edited/f13203.py | def f(observations):
return len([obs for obs in observations if obs.ignore_station == False])
assert f([]) == 0 |
benchmark_functions_edited/f12870.py | def f(p: float, i: float, n: float) -> float:
numerator = p * i * ((1 + i) ** n)
denominator = ((1 + i)**n) - 1
return numerator/denominator
assert f(0, 0.1, 1000) == 0 |
benchmark_functions_edited/f7514.py | def f(letter, scorelist):
if scorelist == []:
return 0
first = scorelist[0]
if first[0] == letter:
return first[1]
return f(letter, scorelist[1:])
assert f(
"c", [("a", 1), ("b", 2), ("c", 3)]) == 3 |
benchmark_functions_edited/f8263.py | def f(a,b,c):
if a < 0 or b < 0 or c < 0:
return 0
else:
return a*b*c
assert f(1, 2, -2) == 0 |
benchmark_functions_edited/f8864.py | def f(number):
summ = 0
p = 0
if number < 9:
return number
while number > 0:
p = number % 10
summ += p
number = number // 10
return summ
assert f(101) == 2 |
benchmark_functions_edited/f13526.py | def f(tree, level):
if tree:
if tree.level < level:
n_nodes_level = f(tree.left, level)
n_nodes_level += f(tree.right, level)
return n_nodes_level
return 1
return 0
assert f(None, 1) == 0 |
benchmark_functions_edited/f3605.py | def f(n, k):
if n == 1:
return 1
elif n == 2:
return 1
else:
return f(n-1, k) + k * f(n-2, k)
assert f(4, 2) == 5 |
benchmark_functions_edited/f6302.py | def f(n):
assert n > 0
a, b = 1, 1
for _ in range(n-1):
a, b = b, a+b
return a
assert f(1) == 1 |
benchmark_functions_edited/f5682.py | def f(number):
return len(str(number))
assert f(10000) == 5 |
benchmark_functions_edited/f4077.py | def f(point1, point2):
return (point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2
assert f([1,2],(2,4)) == 5 |
benchmark_functions_edited/f3351.py | def f(the_list):
if len(the_list) == 0:
return 0
return (sum(the_list) * 1.0) / len(the_list)
assert f([]) == 0 |
benchmark_functions_edited/f12956.py | def f(card: str):
if card in ("J", "Q", "K"):
return 10
if card == "A":
return 1
return int(card)
assert f("5") == 5 |
benchmark_functions_edited/f11117.py | def f(n):
try:
if type(n) in [int, float]:
return sum([True for d in str(n) if d.isdigit() and int(d) % 2 == 0])
else:
raise TypeError("Given input is not a supported type")
except TypeError as e:
print("Error:", str(e))
assert f(345.67) == 2 |
benchmark_functions_edited/f5815.py | def f(line):
line = line.expandtabs()
return len(line) - len(line.lstrip())
assert f('x = 1\ny = 2\n') == 0 |
benchmark_functions_edited/f13008.py | def f(x,case=1):
if case==1:
return 32*x*x*(1-x)*(1-x)
if case==2:
return 20*x*(1-x)*(0.5-x)
if case==3:
return (1-x)*(x)
if case==4:
return x**3
assert f(0.0,2)==0 |
benchmark_functions_edited/f5231.py | def f(options: dict, opt: str):
if opt in options:
return options[opt]
raise ValueError(f"Missing option '{opt}'.")
assert f(
{'a': 1, 'b': 2, 'c': 3}, 'a') == 1 |
benchmark_functions_edited/f9046.py | def f(x):
if len(x) == 1:
return x[0]
return x
assert f((0,)) == 0 |
benchmark_functions_edited/f8376.py | def f(obj, key, default=None):
try:
result = obj[key.split('.')[0]]
for k in key.split('.')[1:]:
result = result[k]
except Exception as e:
result = default
return result
assert f(
{"a": {"b": {"c": 1}}},
"a.b.c"
) == 1 |
benchmark_functions_edited/f10608.py | def f(sym_factor, rotors):
for rotor in rotors:
for tors_name, tors_dct in rotor.items():
if 'D' in tors_name:
sym_factor /= tors_dct['sym_num']
return sym_factor
assert f(1, []) == 1 |
benchmark_functions_edited/f9804.py | def f(noten):
noten.sort()
n_noten = len(noten)
if n_noten % 2 == 0:
median = round((noten[int(n_noten/2)-1] + noten[int(n_noten/2)]) / 2, 2)
else:
median = round(noten[int((n_noten-1)/2)], 2)
return median
assert f([1, 2, 3, 4, 5, 6, 7, 8, 9]) == 5 |
benchmark_functions_edited/f6438.py | def f(video_path):
try:
return int(video_path)
except ValueError:
return video_path
assert f(1) == 1 |
benchmark_functions_edited/f2692.py | def f(value):
mid = 0
end = 0
return eval(value,{"__builtins__":None},{"mid":mid,"end":end})
assert f(r"mid") == 0 |
benchmark_functions_edited/f3530.py | def f(s):
if s == 'F':
return -1
elif s == 'T':
return 1
else:
return int(s)
assert f('9') == 9 |
benchmark_functions_edited/f7889.py | def f(num1, num2):
if (num2 == 0):
return num1
return f(num2, num1 % num2)
assert f(2, 6) == 2 |
benchmark_functions_edited/f14548.py | def f(num_channels):
if num_channels < 8:
return 1
if num_channels < 32:
return 2
if num_channels < 64:
return 4
if num_channels < 128:
return 8
if num_channels < 256:
return 16
else:
return 32
assert f(32) == 4 |
benchmark_functions_edited/f3196.py | def f(offset):
return offset - 1 if offset >= 3 else offset + 1
assert f(7) == 6 |
benchmark_functions_edited/f11442.py | def f(first, second):
first_array = bytearray(first)
second_array = bytearray(second)
first_array.extend(second_array)
return len(first_array)
assert f(bytearray([1, 2, 3, 4, 5]), bytearray([4, 5, 6])) == 8 |
benchmark_functions_edited/f3103.py | def f(operator):
if operator in '+-':
return 0
elif operator in '*/':
return 1
assert f('/') == 1 |
benchmark_functions_edited/f10029.py | def f(etextno):
if not isinstance(etextno, int) or etextno <= 0:
msg = 'e-text identifiers should be strictly positive integers'
raise ValueError(msg)
return etextno
assert f(2) == 2 |
benchmark_functions_edited/f10252.py | def f(hour_spec):
prefix, start_window, end_window = hour_spec.split('_')
return int(start_window) / 100
assert f(
'h_0000_0200'
) == 0 |
benchmark_functions_edited/f11995.py | def f(lst):
return max(set(lst), key=lst.count)
assert f(
[1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5]
) == 4 |
benchmark_functions_edited/f10948.py | def f(sectors):
SECTORS_PER_SECOND = 75
remainder = sectors % SECTORS_PER_SECOND
return sectors // SECTORS_PER_SECOND + \
(1 if remainder > SECTORS_PER_SECOND // 2 else 0)
assert f(0) == 0 |
benchmark_functions_edited/f4233.py | def f(Aniso, Fluo):
return (1/3)*Fluo*(1-Aniso)
assert f(1,0) == 0 |
benchmark_functions_edited/f10854.py | def f(x, m, M):
diff = M - m
while x > M:
x = x - diff
while x < m:
x = x + diff
return x
assert f(0, 0, 0) == 0 |
benchmark_functions_edited/f12293.py | def f(condition, true_result, false_result):
if condition:
return true_result
else:
return false_result
assert f(False, 2, 3) == 3 |
benchmark_functions_edited/f13951.py | def f(from_this, get_this):
if not from_this:
return None
item = from_this
if isinstance(get_this, str):
if get_this in from_this:
item = from_this[get_this]
else:
item = None
else:
for key in get_this:
if isinstance(item, dict) and key in item:
item = item[key]
else:
return None
return item
assert f({'a': 1}, 'a') == 1 |
benchmark_functions_edited/f4227.py | def f(valeur, coup, val1, val2):
if valeur < coup:
return val1
else:
return val2
assert f(0.5, 0, 0, 0) == 0 |
benchmark_functions_edited/f2278.py | def f(p1: int, p2: int) -> int:
return (p1 - 1) * (p2 - 1)
assert f(2, 3) == 2 |
benchmark_functions_edited/f5830.py | def f(bitstring):
return sum(value * 2 ** i for i, value in enumerate(bitstring[::-1]))
assert f((0, 0)) == 0 |
benchmark_functions_edited/f14232.py | def f(z, zt, C):
return zt / (1 / 3 - C / 2 * (zt / z)**1.5)
assert f(10, 0, -1) == 0 |
benchmark_functions_edited/f112.py | def f(x, slope, intercept):
return slope*x + intercept
assert f(0, 0, 0) == 0 |
benchmark_functions_edited/f8082.py | def f(value):
try:
value = int(value)
except ValueError:
raise ValueError("Must be integer")
if value < 0:
raise ValueError("Negative value is not allowed")
return value
assert f(3) == 3 |
benchmark_functions_edited/f9278.py | def f(fn, hist, arm_id):
if arm_id is None:
return fn([reward for _, reward in hist])
else:
return fn([reward for id_, reward in hist if id_ == arm_id])
assert f(sum, [(0, 3), (1, 4)], None) == 7 |
benchmark_functions_edited/f9977.py | def f(nums):
nums.append(0)
# We could also have used the list.sort() method, which modifies a list, putting it in sorted order.
nums = sorted(nums)
return nums.index(0)
assert f([]) == 0 |
benchmark_functions_edited/f6939.py | def f(literal, n):
if literal > 0:
return literal
else:
return (- literal + n)
assert f(-1, 2) == 3 |
benchmark_functions_edited/f753.py | def f(a, b):
while b > 0:
a, b = b, a % b
return a
assert f(3, 5) == 1 |
benchmark_functions_edited/f11740.py | def f(n_list, D, dt, dim):
r = 2 * dim * D * dt * n_list
return r
assert f(1, 1, 1, 1) == 2 |
benchmark_functions_edited/f1893.py | def f(i, j, zs, kTs):
return kTs[i-1]/zs[i-1] - kTs[j-1]/zs[j-1]
assert f(1, 2, [3, 2, 1], [3, 2, 1]) == 0 |
benchmark_functions_edited/f11866.py | def f(coordinates):
try:
return coordinates[1] / coordinates[0]
except ZeroDivisionError:
return float("inf")
assert f( (1, 2) ) == 2 |
benchmark_functions_edited/f1043.py | def f(n=0):
print(f"Toys are fun, I will give you {n+1} toys!")
return n+1
assert f(3) == 4 |
benchmark_functions_edited/f2106.py | def f(str, set):
return 1 in [c in str for c in set]
assert f( "abc", {"a", "c"} ) == 1 |
benchmark_functions_edited/f771.py | def f(val):
return val >> 8 | val << 8
assert f(0) == 0 |
benchmark_functions_edited/f2697.py | def f(n):
d = 0
while n is not None:
n = n.parent
d += 1
return d
assert f(None) == 0 |
benchmark_functions_edited/f1330.py | def f(points, level):
return (2**level) * (points*0.5 + 0.5)
assert f(-1.0, 3) == 0 |
benchmark_functions_edited/f12637.py | def f(value_to_store, max_byte_width):
for byte_width in range(max_byte_width):
if 0x100 ** byte_width <= value_to_store < 0x100 ** (byte_width + 1):
return byte_width + 1
raise ValueError
assert f(1, 16) == 1 |
benchmark_functions_edited/f10357.py | def f(n, m):
return 0 if n < 0 or m < 0 else m * n
assert f(-1, 5) == 0 |
benchmark_functions_edited/f3597.py | def f(array):
if not array:
return None
return array[0]
assert f([1, 2]) == 1 |
benchmark_functions_edited/f4895.py | def f(diagonal_1, diagonal_2):
# You have to code here
# REMEMBER: Tests first!!!
area = (diagonal_1 * diagonal_2) / 2
return area
assert f(3, 4) == 6 |
benchmark_functions_edited/f6059.py | def f(result):
vals = result.values()
if len(vals) == 0:
raise ValueError("Cannot calculate average on empty dictionary.")
return sum(vals)/float(len(vals))
assert f({'a': 2}) == 2 |
benchmark_functions_edited/f5271.py | def f(kilometers: float) -> float:
# conversion factor
conv_fac = 0.621371
# calculate miles
return kilometers * conv_fac
assert f(0) == 0 |
benchmark_functions_edited/f11971.py | def f(att, desc, targ):
check_desc = att in desc
check_targ = att in targ
code_int = check_targ * 2 + check_desc - 1
return code_int
assert f(1, [0,1,2], []) == 0 |
benchmark_functions_edited/f8913.py | def f(var, varmax=1, varmin=0, flip=False, offset=0):
return (varmax - var) / (varmax - varmin) if flip else (var - varmin) / (varmax - varmin) + offset
assert f(100, 100, 10) == 1 |
benchmark_functions_edited/f3168.py | def f(x, y):
if (x<=y):
return x*y
else:
return x/y
assert f(2, 3) == 6 |
benchmark_functions_edited/f12978.py | def f(v0w, b0w, b1w, v0f, b0f, b1f, prefact, weight_b0, weight_b1):
return prefact*2*(b0w-b0f)/(b0w+b0f)
assert f(1, 2, 3, 1, 2, 3, 1, 1, 1) == 0 |
benchmark_functions_edited/f5279.py | def f(data):
n = len(data)
if n < 1:
raise ValueError('mean requires at least one data point')
return float(sum(data)) / float(n)
assert f((4, 5, 6)) == 5 |
benchmark_functions_edited/f4754.py | def f(s, i, j):
n = len(s)
k = 0
while max(i, j) + k < n and s[i + k] == s[j + k]:
k += 1
return k
assert f(list('abcdc'), 2, 4) == 1 |
benchmark_functions_edited/f14050.py | def f(nums, target):
def bs(left, right):
if left > right:
return left
else:
mid = (left + right) // 2
if nums[mid] == target:
return mid
elif nums[mid] > target:
return bs(left, mid - 1)
else:
return bs(mid + 1, right)
return bs(0, len(nums) - 1)
assert f(
[1, 3, 5, 6], 5) == 2 |
benchmark_functions_edited/f7802.py | def f(price, item):
result = '-'
if item in price:
result = price[item]
return result
assert f(
{'cpu': 1, 'ram': 2,'storage': 3, 'ip': 4, 'bandwidth': 5},
'storage') == 3 |
benchmark_functions_edited/f12115.py | def f(A):
if len(A) > 2:
det = 0
for j, val in enumerate(A[0]):
submatrix = list(map(lambda x: x[:j] + x[j + 1:], A[1:]))
det += (-1) ** j * val * f(submatrix)
return det
elif len(A) == 2:
# for 2x2 matrix
return (A[0][0] * A[1][1]) - (A[0][1] * A[1][0])
else:
# for 1x1 matrix
return A[0][0]
assert f(
[[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]]) == 0 |
benchmark_functions_edited/f5854.py | def f(position):
x, y = position
return (1.5 - x + x * y) ** 2 + (2.25 - x + x * y ** 2) ** 2 + (2.625 - x + x * y ** 3) ** 2
assert f((3, 0.5)) == 0 |
benchmark_functions_edited/f7131.py | def f(width, height):
return width + 2 * height
assert f(1, 2) == 5 |
benchmark_functions_edited/f13605.py | def f(a, b):
if a < b:
a, b = b, a
while a % b != 0:
a, b = b, a % b
return b
assert f(3, 5) == 1 |
benchmark_functions_edited/f8800.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(1901) == 0 |
benchmark_functions_edited/f5644.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)
return val
assert f(1, 2) == 1 |
benchmark_functions_edited/f12471.py | def f(n: int, first_number: int) -> int:
return (first_number + (n // 2)) % n
assert f(5, 3) == 0 |
benchmark_functions_edited/f5543.py | def f(a, b):
return (a[0] * b[0]) + (a[1] * b[1])
assert f( (5, 0), (0, 3) ) == 0 |
benchmark_functions_edited/f306.py | def f(z, rho_lam_0, w):
return rho_lam_0 * (1+z)**(3*(1+w(z)))
assert f(0, 1, lambda z: 0.2) == 1 |
benchmark_functions_edited/f893.py | def f(u,v):
if u == v:
return 0
else:
return 1
assert f(1,1) == 0 |
benchmark_functions_edited/f13528.py | def f(cases_array):
len_cases = len(cases_array)
i = 1
loop_cases = 0
while i < 15:
loop_cases = loop_cases + cases_array[len_cases - i]
i = i + 1
average_cases = round(loop_cases/14,0)
return average_cases
assert f([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) == 0 |
benchmark_functions_edited/f3503.py | def f(p1, p2):
dx = p1['x'] - p2['x']
dy = p1['y'] - p2['y']
return dx * dx + dy * dy
assert f(
{'x': 1, 'y': 1},
{'x': 2, 'y': 2}) == 2 |
benchmark_functions_edited/f1702.py | def f(lat1: float, lat2: float):
return 69 * abs(lat1 - lat2)
assert f(40.1234, 40.1234) == 0 |
benchmark_functions_edited/f5887.py | def f(s1, s2):
return abs(s1[0] - s2[0]) + abs(s1[1] - s2[1])
assert f( (10, 10), (10, 10) ) == 0 |
benchmark_functions_edited/f13492.py | def f(f):
# Generally this isn't encouraged, as skaters might be created by functools.partial and folks
# may forget to apply functools.upate_wrapper to preserve the __name__
name = f if isinstance(f,str) else f.__name__
if '_r2' in name:
return 2
elif '_r3' in name:
return 3
elif '_r1' in name:
return 1
else:
return 0
assert f( 'd0_q10000_n100_t10_b50_r3' ) == 3 |
benchmark_functions_edited/f2432.py | def f(n):
return n if n in [0, 1] else f(n - 1) + f(n - 2)
assert f(2) == 1 |
benchmark_functions_edited/f7559.py | def f(str1, str2):
return sum(a != b for a, b in zip(str1, str2))
assert f("", "") == 0 |
benchmark_functions_edited/f816.py | def f(s: str):
return int(s, 16)
assert f(b"00000000") == 0 |
benchmark_functions_edited/f10159.py | def f(bin_num):
num_trailing_zeros = 0
for ele in bin_num[::-1]:
if ele != '0':
break
num_trailing_zeros += 1
return num_trailing_zeros
assert f('000000') == 6 |
benchmark_functions_edited/f7054.py | def f(sym_factor, rotor_symms):
for symm in rotor_symms:
sym_factor /= symm
return sym_factor
assert f(2, [1, 1, 1, 1]) == 2 |
benchmark_functions_edited/f3893.py | def f(a, p):
ret = 0
ed = (p + 1) >> 1
for i in range(ed):
ret += a * i // p
return ret
assert f(2, 3) == 0 |
benchmark_functions_edited/f6044.py | def f(state):
state = state.lower()
if state == "optimal":
return 0
elif state == "degraded":
return 5
else:
return 100
assert f("degraded") == 5 |
benchmark_functions_edited/f4354.py | def f(*elements: object) -> int:
_hash = 0
for element in elements:
_hash ^= hash(element)
return _hash
assert f(3) == 3 |
benchmark_functions_edited/f10283.py | def f(captcha):
half = len(captcha) // 2
rotated = captcha[half:] + captcha[:half]
total = 0
for (a, b) in zip(captcha, rotated):
if a == b:
total += int(a)
return total
assert f("12131415") == 4 |
benchmark_functions_edited/f1319.py | def f(n: int) -> int:
return int(n ** 0.5)
assert f(2) == 1 |
benchmark_functions_edited/f11171.py | def f(l):
if isinstance(l, list):
if l:
return 1 + max(f(item) for item in l)
else:
return 1
else:
return 0
assert f([1, [2, [3, 4]]]) == 3 |
benchmark_functions_edited/f9275.py | def f(a, b):
if a < b:
a, b = b, a
if a % b == 0:
return b
q = a % b
return f(b, q)
assert f(121, 14) == 1 |
benchmark_functions_edited/f12330.py | def f(sort_data):
if sort_data[0][1] == 1:
return 1
else:
return 0
assert f( [(1,1), (0,1)] ) == 1 |
benchmark_functions_edited/f8604.py | def f(record, *args):
chrom = 'chr' + str(args[0])
start = int(args[1])
end = int(args[2])
if record['CHROM'] == chrom:
if end >= record['POS'] >= start:
return 1
else:
return 0
else:
return 0
assert f(
{'CHROM': 'chr1', 'POS': 3},
'2',
2,
4
) == 0 |
benchmark_functions_edited/f13824.py | def f(s1: str, s2: str):
m = len(s1)
n = len(s2)
tab = [[0 for _ in range(n + 1)] for _ in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0 or j == 0:
tab[i][j] = 0
elif s1[i - 1] == s2[j - 1]:
tab[i][j] = tab[i - 1][j - 1] + 1
else:
tab[i][j] = max(tab[i - 1][j], tab[i][j - 1])
return tab[m][n]
assert f(
"AGGTAB",
"GXTXAYB",
) == 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.