file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f2232.py
|
def f(start: int, size: int, index: int) -> int:
return (index + start) % size
assert f(2, 3, 1) == 0
|
benchmark_functions_edited/f6910.py
|
def f(s1, s2):
if len(s1) != len(s2):
raise ValueError("Sequences of unequal length")
return sum(ch1 != ch2 for ch1, ch2 in zip(s1, s2))
assert f(b'AGAT', b'ACAT') == 1
|
benchmark_functions_edited/f13299.py
|
def f(proto, filter_fn):
query = [elm for elm in proto if filter_fn(elm)]
if len(query) == 0:
raise ValueError('Could not find element')
elif len(query) > 1:
raise ValueError('Too many matches')
return query[0]
assert f(
[1, 2],
lambda elm: elm == 2) == 2
|
benchmark_functions_edited/f7105.py
|
def f(value: int) -> int:
if value > 0:
return max(1, round((value / 100) * 99))
return 0
assert f(0) == 0
|
benchmark_functions_edited/f13844.py
|
def f(n, p):
if n == 0:
return 1
if p == 1:
return 1
else:
w = 0
for i in range(0, n+1):
w += f(i, p-1)
return w
assert f(0, 8) == 1
|
benchmark_functions_edited/f3493.py
|
def f(int_type: int, offset: int) -> int:
mask = 1 << offset
return int_type | mask
assert f(0, 1) == 2
|
benchmark_functions_edited/f10444.py
|
def f(bits):
v = 0
p = 1
for b in bits:
if b:
v += p
p *= 2
return v
assert f(b'1') == 1
|
benchmark_functions_edited/f7908.py
|
def f(string):
return len(string) + 2 + string.count('"') + string.count('\\')
assert f(r'') == 2
|
benchmark_functions_edited/f13208.py
|
def f(e):
return getattr(e, 'errno', e.args[0] if e.args else None)
assert f(OSError(5, "Operation not permitted")) == 5
|
benchmark_functions_edited/f399.py
|
def f(f,c):
return(f**2+c)
assert f(0,1) == 1
|
benchmark_functions_edited/f6812.py
|
def f(individual):
y=sum(x**2 for x in individual)
return y
assert f( (-2,) ) == 4
|
benchmark_functions_edited/f11059.py
|
def f(coin):
if coin == 25:
return 10
elif coin == 10:
return 5
elif coin == 5:
return 1
assert f(5) == 1
|
benchmark_functions_edited/f9639.py
|
def f(
tz_offset
):
int_offset = int(tz_offset)
int_hours = int(int_offset / 100)
int_minutes = int(int_offset % 100)
return (int_hours * 3600) + (int_minutes * 60)
assert f(0) == 0
|
benchmark_functions_edited/f3988.py
|
def f(baskets, item):
freq = 0
for basket in baskets:
if item <= basket: freq += 1
return freq
assert f([],
1) == 0
|
benchmark_functions_edited/f9228.py
|
def f(s):
result: int = 0
final_index: int = len(s) - 1
for i, v in enumerate(s):
result += (ord(v) - 48) * (10 ** (final_index - i))
return result
assert f(str(3)) == 3
|
benchmark_functions_edited/f9432.py
|
def f(x, y):
result = 1.0
# handling negative case
if y < 0:
x = 1.0 / x
y = -y
while y:
if y & 1:
result *= x
x *= x
y >>= 1
return result
assert f(1, 2) == 1
|
benchmark_functions_edited/f2062.py
|
def f(str1, str2):
return sum(c1 != c2 for c1, c2 in zip(str1, str2))
assert f('1234', '1235') == 1
|
benchmark_functions_edited/f2675.py
|
def f(*args):
val = 0.
for arg in args:
val += arg
return val / len(args)
assert f(2, 2) == 2
|
benchmark_functions_edited/f197.py
|
def f(n):
return n * (3 * n - 1) // 2
assert f(1) == 1
|
benchmark_functions_edited/f5953.py
|
def f(numerator, denominator):
assert numerator % denominator == 0, \
'{} is not divisible by {}'.format(numerator, denominator)
return numerator // denominator
assert f(10, 2) == 5
|
benchmark_functions_edited/f13459.py
|
def f(numbers):
# Sort the list and take the middle element.
n = len(numbers)
copy = sorted(numbers[:]) # So that "numbers" keeps its original order
if n & 1: # There is an odd number of elements
return copy[n // 2]
else:
return (copy[n // 2 - 1] + copy[n // 2]) / 2.0
assert f((1,)) == 1
|
benchmark_functions_edited/f6659.py
|
def f(d:dict) -> int:
n = len(d.keys())
for k,v in d.items():
if type(v) is dict:
n += f(v)
return n
assert f({'a': {'b': 1}, 'c': {'d': {'e': 1}}}) == 5
|
benchmark_functions_edited/f3729.py
|
def f(k, num_internal_knots):
return (k+1)*2+num_internal_knots
assert f(2, 3) == 9
|
benchmark_functions_edited/f14312.py
|
def f(number):
left = 0
right = number
while left <= right:
mid = (left + right)//2
if mid * mid <= number < (mid+1)*(mid+1):
return mid
elif number < mid * mid:
right = mid
else:
left = mid + 1
pass
assert f(64) == 8
|
benchmark_functions_edited/f11336.py
|
def f(fn: float, fp: float, tp: float) -> float:
try:
calc = tp / (tp + fn + fp)
except ZeroDivisionError:
calc = 0
return calc
assert f(1, 0, 0) == 0
|
benchmark_functions_edited/f5188.py
|
def f(clock_str):
minutes, seconds = clock_str.split(":")
return float(minutes) * 60 + float(seconds)
assert f("0:00") == 0
|
benchmark_functions_edited/f2447.py
|
def f(a,b):
if a>b:
maximo=a
else:
maximo=b
return maximo
assert f(3, 3) == 3
|
benchmark_functions_edited/f2600.py
|
def f(n: int) -> int:
return n & (~(n - 1))
assert f(3) == 1
|
benchmark_functions_edited/f2958.py
|
def f(node):
return (node - 1) // 2
assert f(3) == 1
|
benchmark_functions_edited/f13667.py
|
def f(arr, t):
if not arr or t is None:
return None
low = 0
high = len(arr) - 1
while low <= high:
mid = low + ((high - low) >> 1) # or just // 2
if arr[mid] < t:
low = mid + 1
elif arr[mid] > t:
high = mid - 1
else:
return mid
return None
assert f([0, 1, 2], 1) == 1
|
benchmark_functions_edited/f12031.py
|
def f( interpolation ) :
if( ( interpolation < 0 ) or ( interpolation > 3 ) ) : raise Exception( "Invalid FUDGE interpolation value = %d" % interpolation )
return( ( 0, 3, 4, 5 )[interpolation] )
assert f( 3 ) == 5
|
benchmark_functions_edited/f3640.py
|
def f(n):
perimeter = 4*n
return perimeter
assert f(2) == 8
|
benchmark_functions_edited/f9319.py
|
def f(t):
return (t^(t+1)).bit_length()-1
assert f(8) == 0
|
benchmark_functions_edited/f649.py
|
def f(tp, fn):
return tp / (tp + fn)
assert f(0, 5) == 0
|
benchmark_functions_edited/f5142.py
|
def f(params, p):
val = params.pop(p, None)
try:
return int(val, 10)
except ValueError:
return None
assert f(
{'p': '1'},
'p'
) == 1
|
benchmark_functions_edited/f7315.py
|
def f(a):
counter = 0
for item in a:
if type(item) == tuple:
break
else:
counter += 1
return counter
assert f( ["a", "b", "c", "d", (6, 7, 8), (9, 10)] ) == 4
|
benchmark_functions_edited/f13435.py
|
def f(x):
func, args = x
return func(*args)
assert f(tuple((lambda x, y, z: x, (2, 3, 4)))) == 2
|
benchmark_functions_edited/f4568.py
|
def f(label):
if label < 2:
return 0
if label > 2:
return 1
raise ValueError("Invalid label")
assert f(3) == 1
|
benchmark_functions_edited/f7396.py
|
def f(str1, mystr, n):
start = str1.find(mystr)
while start >= 0 and n > 1:
start = str1.find(mystr, start+len(mystr))
n -=1
return start
assert f(
'hello world',
'l',
2) == 3
|
benchmark_functions_edited/f6709.py
|
def f(input):
extension = input.split('.')[-1].lower()
choice = {"bam": 0, \
"sam": 1, \
"fasta": 2, \
"fastq": 2, \
"fa": 2, \
"fq": 2}
return choice[extension]
assert f("foo.bam") == 0
|
benchmark_functions_edited/f5950.py
|
def f(commits):
print(commits)
if bool(commits):
return commits[-1].get('id')
return "no commits"
assert f([{ "id": 1 }]) == 1
|
benchmark_functions_edited/f8232.py
|
def f(number):
if int(number) != number:
return (int(number)+1)
else:
return number
assert f(1.0000) == 1
|
benchmark_functions_edited/f13185.py
|
def f(sc, response):
if not response['ok']:
return 0
users = [m['id'] for m in response['members']]
nb = 0
for user in users:
response = sc.api_call(
"users.getPresence"
)
if response['ok'] and response['presence'] == 'active':
nb += 1
return nb
assert f(
{"members": [{"presence": "away"}, {"presence": "away"}]},
{"ok": False}
) == 0
|
benchmark_functions_edited/f14070.py
|
def f(first, second):
if first == '':
return len(second)
elif second == '':
return len(first)
elif first[0] == second[0]:
return f(first[1:], second[1:])
else:
substitution = 1 + f(first[1:], second[1:])
deletion = 1 + f(first[1:], second)
insertion = 1 + f(first, second[1:])
return min(substitution, deletion, insertion)
assert f(u'', u'abc') == 3
|
benchmark_functions_edited/f7192.py
|
def f(lengths):
return (lengths[0]*lengths[1]*lengths[2])/(lengths[2]**3)
assert f( (4, 4, 4) ) == 1
|
benchmark_functions_edited/f9050.py
|
def f(words, pos, neg):
score = 0
for word in words:
if word + ' ' in pos:
score += 1
elif word + ' ' in neg:
score -= 1
return score
assert f(
["is", "a", "island", "in", "the", "desert"],
["desert", "island", "in"],
["a", "is", "the", "island"]) == 0
|
benchmark_functions_edited/f986.py
|
def f(a):
return sum(map(bool,a))
assert f( (1,1,1) ) == 3
|
benchmark_functions_edited/f14323.py
|
def f(f, x0, x1, delta=0.00001):
x_n, x_n1 = x0, x1
while True:
x_n2 = x_n1 - f(x_n1) / ((f(x_n1) - f(x_n)) / (x_n1 - x_n))
if abs(x_n2 - x_n1) < delta:
return x_n2
x_n = x_n1
x_n1 = x_n2
assert f(lambda x: x**2 - 1, 0, 1) == 1
|
benchmark_functions_edited/f11324.py
|
def f(pool, labels):
weights = [0 for _ in range(len(labels))]
for i in pool:
for label in labels:
pool_label = i[0]
distance = i[1]
if pool_label == label:
weights[label] += 1 / distance
return weights.index(max(weights))
assert f(
[(0, 1), (0, 2), (0, 3), (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3)],
[2, 1, 0]) == 0
|
benchmark_functions_edited/f4538.py
|
def f(sNeedle, aHaystack):
try:
return aHaystack.index(sNeedle)
except ValueError:
return False
assert f(10, [1, 2, 3, 4, 5, 6, 10]) == 6
|
benchmark_functions_edited/f5561.py
|
def f(input):
if type(input) == tuple or type(input) == list:
return input[0]
else:
return input
assert f((1,2,3)) == 1
|
benchmark_functions_edited/f12518.py
|
def f(s: str):
length = 0
hit = False
i = len(s) - 1
while i >= 0:
if s[i] == " " and hit == True:
return length
elif s[i] != " ":
hit = True
length += 1
i -= 1
return length
assert f(' ') == 0
|
benchmark_functions_edited/f11259.py
|
def f(facilities: list) -> int:
tot_hazard = 0
for facility in facilities:
tot_hazard += facility.total_hazard
return tot_hazard
assert f([]) == 0
|
benchmark_functions_edited/f9838.py
|
def f(current, previous):
if current == previous:
return 0
try:
return (abs(current - previous) / previous) * 100.0
except ZeroDivisionError:
# It means previous and only previous is 0.
return 100.0
assert f(0, 0) == 0
|
benchmark_functions_edited/f6886.py
|
def f(arbre):
# si l'arbre est vide
if arbre is None:
return 0
hg = f(arbre.get_ag())
hd = f(arbre.get_ad())
return max(hg, hd) + 1
assert f(None) == 0
|
benchmark_functions_edited/f4732.py
|
def f(a):
val = abs(a)
res = 0
while val:
res += 1
val >>= 1
return res
assert f(0x100) == 9
|
benchmark_functions_edited/f790.py
|
def f(iterable):
return sum(1 for _ in iterable)
assert f(range(1)) == 1
|
benchmark_functions_edited/f5764.py
|
def f(*args, **kwargs) -> int:
return sum(len(x) for x in list(args) + list(kwargs.values()))
assert f('a') == 1
|
benchmark_functions_edited/f9340.py
|
def f(y_true, y_pred):
tn = 0
for yt, yp in zip(y_true, y_pred):
if yt == 0 and yp == 0:
tn += 1
return tn
assert f(
[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]) == 5
|
benchmark_functions_edited/f334.py
|
def f(n):
return 1 - 2*(n & 1)
assert f(44) == 1
|
benchmark_functions_edited/f5708.py
|
def f(my_list, idx):
list_len = len(my_list)
if idx >= list_len or idx < 0:
return
return (my_list[idx])
assert f(
[1, 2, 3, 4],
2
) == 3
|
benchmark_functions_edited/f3593.py
|
def f(I, J, shape):
r, c = shape
return I * c + J
assert f(0, 2, (4, 6)) == 2
|
benchmark_functions_edited/f10328.py
|
def f(str, base=10,
int=int):
try:
return int(str, base)
except:
return 0
assert f(' 0b111 ', 2) == 7
|
benchmark_functions_edited/f11362.py
|
def f(x_elem):
if x_elem == 2:
return 1
if x_elem == 3:
return 2
if x_elem == 4:
return 3
return x_elem
assert f(3) == 2
|
benchmark_functions_edited/f7538.py
|
def f(name):
lines = 0
with open(name, "r") as stream:
lines = len(stream.readlines())
return lines
assert f("test_file.txt") == 1
|
benchmark_functions_edited/f3580.py
|
def f(x, p):
if 0 < x <= p:
return x/p
elif p < x < 1:
return (1-x)/(1-p)
else:
print(x)
raise ValueError
assert f(1, 1) == 1
|
benchmark_functions_edited/f5924.py
|
def findimagenumber (filename):
#split the file so that name is a string equal to OBSDATE+number
name=filename.split('/')[-1].split('.')[0]
return int(name[9:])
assert f('Data/OBSDATE0001.jpg') == 1
|
benchmark_functions_edited/f4300.py
|
def f(a: int, b: int) -> int:
return (a // 2) - (b // 2) - b % 2
assert f(10, 5) == 2
|
benchmark_functions_edited/f6511.py
|
def f(x, k):
return x & ((1 << k) - 1)
assert f(5, 2) == 1
|
benchmark_functions_edited/f14165.py
|
def f(s1, s2):
distance = 0
for c1, c2 in zip(s1, s2):
if c1 != c2:
if c1 == 'N' or c2 == 'N':
continue
else:
distance += 1
return distance
assert f('AGT', 'CCC') == 3
|
benchmark_functions_edited/f5744.py
|
def f(seq, func):
return max(seq, key=func)
assert f(range(100), lambda x: x % 7) == 6
|
benchmark_functions_edited/f10509.py
|
def f(height: int, kernel: tuple) -> int :
return (height // 2) - (kernel[0]//2)
assert f(10, (10, 10)) == 0
|
benchmark_functions_edited/f8531.py
|
def f(func_or_str, *args):
if hasattr(func_or_str, '__call__'):
return func_or_str(*args)
elif isinstance(func_or_str, str):
return func_or_str
else:
raise Exception('Positional argument 1 must be a function or a str')
assert f(lambda x, y: x, 1, 2) == 1
|
benchmark_functions_edited/f13112.py
|
def f(n):
if n < 2:
return n
return f(n - 1) + f(n - 2)
assert f(5) == 5
|
benchmark_functions_edited/f5312.py
|
def f(CI1, CI2):
if CI1[1] < CI2[0]:
return -1
elif CI2[1] < CI1[0]:
return +1
else:
return 0
assert f((1, 2), (1, 2)) == 0
|
benchmark_functions_edited/f14324.py
|
def f(node, level):
while (level > 0) and node:
level -= 1
node = node.parent
return node
assert f(0, 0) == 0
|
benchmark_functions_edited/f1857.py
|
def f(val, lower, upper):
return max(lower, min(val, upper))
assert f(2, 0, 2) == 2
|
benchmark_functions_edited/f6382.py
|
def f(sub_image):
total = 0
for row in range(3):
for col in range(3):
total += sub_image[row][col]
return total // 9
assert f(
[[0,0,0],
[0,0,0],
[0,0,0]]) == 0
|
benchmark_functions_edited/f2728.py
|
def f(num, modulo = 9):
val = num % modulo
return val if val > 0 else modulo
assert f(456) == 6
|
benchmark_functions_edited/f4532.py
|
def f(name):
return sum([ord(c) - 64 for c in list(str(name))])
assert f("B") == 2
|
benchmark_functions_edited/f8130.py
|
def f(window, *args, **kwargs):
values = [x[1] for x in window]
return sum(x0 - x1 for x0, x1 in zip(values, values[1:]) if x0 > x1)
assert f(range(10, 10)) == 0
|
benchmark_functions_edited/f7932.py
|
def f(hand):
hand_len = 0
for frequency in hand.values():
hand_len += frequency
return hand_len
assert f({}) == 0
|
benchmark_functions_edited/f3746.py
|
def f(x,y):
x = abs(x) ; y = abs(y)
while x > 0:
x, y = y % x, x
return y
assert f(1, 5) == 1
|
benchmark_functions_edited/f12291.py
|
def f(target, ranks):
for i in range(len(ranks)):
word, rank = ranks[i]
if word == target:
return i
return -1
assert f(
"banana",
[
("apple", 5),
("banana", 2),
("cherry", 10),
("dill", 8),
("eel", 4),
("fig", 9),
("grape", 3),
("ham", 6),
("ice", 7),
("kumquat", 1),
]
) == 1
|
benchmark_functions_edited/f3326.py
|
def f(lst, trunc):
return sum([lst[i] * trunc**(len(lst)-i-1) for i in range(len(lst))])
assert f((1,), 3) == 1
|
benchmark_functions_edited/f13079.py
|
def f(index):
lcsOrderToPos = {i:j for i,j in enumerate([3,4,2,1,5])}
return lcsOrderToPos[index]
assert f(**{'index': 0}) == 3
|
benchmark_functions_edited/f10364.py
|
def f(f, points, v, i, h):
#add h to just the ith element of v
w = [v_j + (h if j == i else 0) for j, v_j in enumerate(v)]
return (f(points, w[0], w[1]) - f(points, v[0], v[1])) / h
assert f(lambda points, x, y: sum([points[i][0] + points[i][1] for i in range(len(points))]), [[1, 2], [3, 4], [5, 6]], [0, 0], 1, 1e-6) == 0
|
benchmark_functions_edited/f10504.py
|
def f(number: int):
divisors = []
for n in range(1, number):
if number % n == 0:
divisors.append(n)
return sum(divisors)
assert f(3) == 1
|
benchmark_functions_edited/f13979.py
|
def f(array: list, low: int, high: int, pivot: int) -> int:
i = low
j = high
while True:
while array[i] < pivot:
i += 1
j -= 1
while pivot < array[j]:
j -= 1
if i >= j:
return i
array[i], array[j] = array[j], array[i]
i += 1
assert f(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0, 10, 9) == 8
|
benchmark_functions_edited/f12251.py
|
def f(matrix_dim: int):
tril_count = (matrix_dim ** 2 - matrix_dim) // 2 + matrix_dim
return tril_count
assert f(0) == 0
|
benchmark_functions_edited/f12456.py
|
def f(input_interval, output_interval, value):
min_to, max_to = output_interval
min_from, max_from = input_interval
mapped_value = min_to + (max_to - min_to) * ((value - min_from) / (max_from - min_from))
return mapped_value
assert f( (-5, 5), (-1, 1), 0) == 0
|
benchmark_functions_edited/f11062.py
|
def f(disk, procRates):
eta = 0;
while disk > 0:
eta += 1
for rate in procRates:
if eta % rate == 0:
disk -= 1
return eta
assert f(1, [1, 1, 1]) == 1
|
benchmark_functions_edited/f7939.py
|
def f(v1, v2, p):
dist = 0.0
for i in range(len(v1)):
dist += abs(v1[i] - v2[i]) ** p
return dist ** (1 / p)
assert f( [0, 0, 0], [0, 0, 0], 4) == 0
|
benchmark_functions_edited/f3142.py
|
def f(d, path):
if not path: return d
return f(d[path[0]], path[1:])
assert f({1: 2}, [1]) == 2
|
benchmark_functions_edited/f14542.py
|
def f(seq, ambiguous_letters, disambiguation):
n = 1
for letter in str(seq):
if letter in ambiguous_letters:
n *= len(disambiguation[letter])
return n
assert f("AAA", "N", {"N":"ACTGN"}) == 1
|
benchmark_functions_edited/f14094.py
|
def f(a, dt, k):
return dt * (a - a**3 + k)
assert f(0, 1, 2) == 2
|
benchmark_functions_edited/f8447.py
|
def f(f, Nstrips):
width = 1/Nstrips
integral = 0
for point in range(Nstrips):
height = f(point / Nstrips)
integral = integral + width * height
return integral
assert f(lambda x: 0, 3) == 0
|
benchmark_functions_edited/f14199.py
|
def f(w, q):
e = w / q
return e
assert f(0, 100) == 0
|
benchmark_functions_edited/f1572.py
|
def f(location):
print('Yup you are now dead. Must be nice')
return location
assert f(1) == 1
|
benchmark_functions_edited/f8652.py
|
def f(text, open={'(', '[', '{'}, close={')', ']', '}'}):
level = 0
for c in text:
if c in open:
level += 1
elif c in close:
level -= 1
return level
assert f(
'(())'
) == 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.