file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f7669.py | def f(sentence):
words = sentence.split()
num_words = len(words)
if num_words == 0:
num_words = 1
return sum(len(word) for word in words) / num_words
assert f(u"") == 0 |
benchmark_functions_edited/f13916.py | def f(my_list):
if not isinstance(my_list, list):
raise TypeError("Mean: {} is not a list".format(my_list))
return sum(my_list) / len(my_list)
assert f([1]) == 1 |
benchmark_functions_edited/f566.py | def f(u, dfs_data):
return dfs_data['b_u_lookup'][u]
assert f(2, {'b_u_lookup': {1: 1, 2: 2, 3: 3, 4: 5}}) == 2 |
benchmark_functions_edited/f13657.py | def f(nums):
# Turn to find local maximum within the array.
l, r = 0, len(nums) - 1
while l < r:
m = (l + r) // 2
if nums[m] < nums[m+1]:
# Becase we want local maximum, m is excluded.
l = m + 1
else:
# Included because m might be the local maximum... |
benchmark_functions_edited/f833.py | def f(p,x):
return p[0]+p[1]*x**p[2]
assert f((1,1,1),1) == 2 |
benchmark_functions_edited/f431.py | def f(a, b, x):
return a * x + b
assert f(1, 0, 3) == 3 |
benchmark_functions_edited/f7603.py | def f(value, values):
for item in values:
if item > value:
return item
return values[0]
assert f(1, [5]) == 5 |
benchmark_functions_edited/f6853.py | def f(data: list) -> int:
return sum(sum(1 for let in set(item[0]) if item[0].count(let) == item[1]) for item in data)
assert f([("ab", 1), ("a", 2)]) == 2 |
benchmark_functions_edited/f5069.py | def f(entry):
vowel_count = 0
for vowel in "aeiou":
vowel_count += entry.count(vowel)
return vowel_count
assert f( "Alabama" ) == 3 |
benchmark_functions_edited/f11331.py | def f(word):
if word.endswith('e'):
return len(word) - 2
elif word.endswith('ess'):
return len(word) - 10
elif word.endswith('ss'):
return len(word) - 4
else:
return len(word)
assert f(u'feiou') == 5 |
benchmark_functions_edited/f1197.py | def f(x):
if x > 0.:
y = 1
else:
y = 0.
return y
assert f(5) == 1 |
benchmark_functions_edited/f8747.py | def f(seq, subseq):
pos, count = 0, 0
while True:
pos = seq.find(subseq, pos)
if pos < 0:
break
pos += 1
count += 1
return count
assert f(
"abracadabra", "abra") == 2 |
benchmark_functions_edited/f2021.py | def f(z, zmin, zrng, a_min=0):
alpha = a_min + (1-a_min)*(z-zmin)/zrng
return alpha
assert f(0, 0, 1) == 0 |
benchmark_functions_edited/f71.py | def f(*_):
return _[-1]
assert f(1, 2) == 2 |
benchmark_functions_edited/f798.py | def f(X):
mean = 4 * X * (1 - X) + X
return mean
assert f(0) == 0 |
benchmark_functions_edited/f10093.py | def f(mel):
return 700.0 * (10**(mel / 2595.0)) - 700.0
assert f(0) == 0 |
benchmark_functions_edited/f2028.py | def f(diagonal_1, diagonal_2):
area = (diagonal_1 * diagonal_2) / 2
return area
assert f(3, 4) == 6 |
benchmark_functions_edited/f11102.py | def f(UnexpectedException, target, *args, **kwargs):
try:
result = target(*args, **kwargs)
except UnexpectedException as e:
raise AssertionError("Call to %s raised %s: %s" % (target.__name__, e.__class__.__name__, e))
return result
assert f(ValueError, len, '') == 0 |
benchmark_functions_edited/f11031.py | def f(a,e,n):
if(n<1):
return -1
b=bin(e)[2:]
prod=1
current=a
for i in range(len(b)):
if(b[-i-1]=='1'):
prod *= current
prod %= n
current *= current
current %= n
return prod
assert f(2, 1, 10) == 2 |
benchmark_functions_edited/f7992.py | def f(x, a):
if x == a:
return 0
elif x < a:
return x
else:
return f(x-a, a)
assert f(7, 7) == 0 |
benchmark_functions_edited/f7743.py | def f(value_string):
valdict = {"TRUE": 1,
"FALSE": 0,
"YES": 1,
"NO": 0}
return valdict[value_string.upper()]
assert f("no") == 0 |
benchmark_functions_edited/f12492.py | def f(list, name, default=0):
for key, value in list:
if key == name:
return value
return default
assert f(
[('a', 1), ('b', 2)],
'a'
) == 1 |
benchmark_functions_edited/f11038.py | def f(p1, p2):
x1, y1 = p1
x2, y2 = p2
return abs(x1 - x2) + abs(y1 - y2)
assert f( (0,0), (0,1) ) == 1 |
benchmark_functions_edited/f8338.py | def f(coords, y0, x0, amplitude, alpha, beta=1.5):
Y,X = coords
return (amplitude*(1+((X-x0)**2+(Y-y0)**2)/alpha**2)**-beta)
assert f( (0, 0), 0, 0, 1, 1) == 1 |
benchmark_functions_edited/f3277.py | def f(first, second):
return len(list(filter(lambda x : ord(x[0])^ord(x[1]), zip(first, second))))
assert f("1", "1") == 0 |
benchmark_functions_edited/f10778.py | def f( a, b ):
return abs(a) if ( b == 0 ) else f( b, a%b )
assert f( 0, 0 ) == 0 |
benchmark_functions_edited/f11877.py | def f(a,b):
return (a[0] * b[1] - a[1] * b[0])
assert f( (1,1), (-1,-1) ) == 0 |
benchmark_functions_edited/f175.py | def f(number):
return int(number) % 11
assert f(6) == 6 |
benchmark_functions_edited/f13624.py | def f(exc):
try:
return exc.errno
except AttributeError:
try:
# e.args = (errno, reason)
if isinstance(exc.args, tuple) and len(exc.args) == 2:
return exc.args[0]
except AttributeError:
pass
return 0
assert f(ValueError(0, 'foo')) ... |
benchmark_functions_edited/f2805.py | def f(pos):
fos = pos - 1
return fos * fos * fos * (1 - pos) + 1
assert f(0) == 0 |
benchmark_functions_edited/f7366.py | def f(board, mark):
counter = 0
for line in board:
for cell in line:
if cell == mark:
counter += 1
return counter
assert f(
[
['X', 'X', 'X', 'X'],
['_', 'O', '_', '_'],
['_', '_', '_', '_'],
['O', 'O', 'O', 'O']
],
'X'
) == 4 |
benchmark_functions_edited/f11674.py | def f(x, state_num_dict=None):
if state_num_dict is None:
state_num_dict = {(0,0) : 0, (0,1) : 1, (1,0) : 2, (1,1) : 3 }
return state_num_dict[(x[0], x[1])]
assert f((1,0)) == 2 |
benchmark_functions_edited/f10631.py | def f(arr, arr2):
complete_sum = 0
for val in arr:
complete_sum += val
missing_sum = 0
for val in arr2:
missing_sum += val
return complete_sum - missing_sum
assert f(
[1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 5, 6, 7, 8, 9]
) == 0 |
benchmark_functions_edited/f5054.py | def f(item):
fuel = item // 3 - 2
if fuel < 0:
return 0
return fuel + f(fuel)
assert f(12) == 2 |
benchmark_functions_edited/f7437.py | def f(feedback_thread_analytics):
return sum(
feedback.num_open_threads for feedback in feedback_thread_analytics)
assert f([]) == 0 |
benchmark_functions_edited/f10228.py | def f(n, memo = {}):
if n == 0 or n == 1:
return 1
try:
return memo[n]
except KeyError:
result = f(n - 1, memo) + f(n - 2, memo)
memo[n] = result
return result
assert f(4) == 5 |
benchmark_functions_edited/f2006.py | def f(number, n):
return number // 10 ** n % 10
assert f(23, 1) == 2 |
benchmark_functions_edited/f2467.py | def f(x, y):
return y**2 / (x**2 + y**2)**(3/2.)
assert f(1., 0.) == 0 |
benchmark_functions_edited/f12824.py | def f(n: int) -> int:
n -= (n >> 1) & 0x5555555555555555
n = (n & 0x3333333333333333) + ((n >> 2) & 0x3333333333333333)
n = (n + (n >> 4)) & 0x0F0F0F0F0F0F0F0F
n = n + (n >> 8)
n = n + (n >> 16)
n = n + (n >> 32)
return n & 0x0000007F
assert f(0b1010) == 2 |
benchmark_functions_edited/f9514.py | def f(times):
total_time = 0
for element in times:
total_time += element
return int(total_time / len(times))
assert f([4, 5, 6, 7, 8]) == 6 |
benchmark_functions_edited/f8969.py | def f(iterable, default=None, key=None):
if key is None:
for el in iterable:
return el
else:
for key_, el in iterable:
if key == key_:
return el
return default
assert f([1, 1, 1]) == 1 |
benchmark_functions_edited/f14385.py | def f(array, start, end, item):
if end >= start:
median = (start + end) // 2
if array[median] == item:
return median
if array[median] < item:
return f(array, median+1, end, item)
return f(array, start, median-1, item)
return None
assert f(
[1, 3, 5, 7... |
benchmark_functions_edited/f7924.py | def f(A, prec=6):
if hasattr(A, '__iter__'):
return [f(el, prec=prec) for el in A]
else:
return round(A, prec)
assert f(4) == 4 |
benchmark_functions_edited/f4876.py | def f(string):
if not string:
return 0
elif string == "":
return 0
else:
return int(string)
assert f(1.0) == 1 |
benchmark_functions_edited/f11283.py | def f(num_1: float, num_2: float):
if num_1 - num_2 > 0:
return 1
elif num_1 - num_2 < 0:
return 2
else:
return 0
assert f(1.5, 2) == 2 |
benchmark_functions_edited/f9405.py | def f(red, green=0, blue=0):
try:
red, green, blue = red # see if the first var is a tuple/list
except TypeError:
pass
return (red & 0xf8) << 8 | (green & 0xfc) << 3 | blue >> 3
assert f(0, 0) == 0 |
benchmark_functions_edited/f8581.py | def f(bits, bpw):
sign_limit = 2**(bpw-1)-1
conv = (2**bpw)
value = 0
for bit in reversed(bits):
value = (value << 1) | bit
if value > sign_limit:
value -= conv
return value
assert f([1], 2) == 1 |
benchmark_functions_edited/f11438.py | def f(lst, seq):
count = 0
len_seq = len(seq)
upper_bound = len(lst) - len_seq + 1
for i in range(upper_bound):
if lst[i:i + len_seq] == seq:
count += 1
return count
assert f(
['cat', 'dog', 'dog', 'cat'], ['cat', 'dog']) == 1 |
benchmark_functions_edited/f11276.py | def f(block_size: int, i: int) -> int:
assert block_size > 0
assert i >= 0
return i // block_size
assert f(4, 14) == 3 |
benchmark_functions_edited/f3922.py | def f(item, vec):
for i in range(len(vec)):
if item == vec[i]:
return i
return -1
assert f(0, [1, 2, 0, 3, 4, 0, 0, 0]) == 2 |
benchmark_functions_edited/f10123.py | def f(student_scores):
counter = []
for _, score in enumerate(student_scores):
if score <= 40:
counter.append(score)
return len(counter)
assert f([45, 23, 52]) == 1 |
benchmark_functions_edited/f12774.py | def f(temperature, potential):
kb = 0.0019872041
# check for division by zero
if temperature != 0:
beta = 1. / (kb*temperature)
else:
beta = 1. / kb
return float(beta * potential)
assert f(0., 0) == 0 |
benchmark_functions_edited/f4374.py | def f(nums, val):
nums[:] = [num for num in nums if num != val]
return len(nums)
assert f([0, 1, 2, 2, 3, 0, 4, 2], 2) == 5 |
benchmark_functions_edited/f1267.py | def f(x, n):
# type: (int, int) -> int
return (x + (n - 1)) // n * n
assert f(4, 2) == 4 |
benchmark_functions_edited/f1168.py | def f(working_list):
return working_list[-1]
assert f(list([1, 2, 3])) == 3 |
benchmark_functions_edited/f8728.py | def f(n: int) -> int:
fact = 1
for i in range(2, n+1):
fact=fact*n
return fact
assert f(2) == 2 |
benchmark_functions_edited/f2757.py | def f(query, collection):
return len([s for s in collection if s == query])
assert f(-1, [1, 0, 2]) == 0 |
benchmark_functions_edited/f3702.py | def f(x, y):
q, r = divmod(x, y)
if r:
q += 1
return q
assert f(2, 1) == 2 |
benchmark_functions_edited/f2817.py | def f(fitness1, fitness2):
sij = fitness2 / fitness1
return sij
assert f(1, 1) == 1 |
benchmark_functions_edited/f14159.py | def f(number, primes):
prime_factors_pow = []
if number < 2:
prime_factors_pow.append(0)
for p in primes:
if p > number:
break
n = 0
while number % p == 0:
n += 1
number //= p
prime_factors_pow.append(n)
num_divisors = 1
for... |
benchmark_functions_edited/f488.py | def f(x,y):
z=x**2+y
return z
assert f(1,-1) == 0 |
benchmark_functions_edited/f6969.py | def f(x):
n = 0
s = 0
for v in x:
s += v
n += 1
return s / n
assert f(range(7)) == 3 |
benchmark_functions_edited/f13235.py | def f(j, n=None):
if type(j) is not int:
try:
j = j.__index__()
except AttributeError:
raise IndexError("Invalid index a[%r]" % (j, ))
if n is not None:
if j < 0:
j += n
if not (j >= 0 and j < n):
raise IndexError("Index out of rang... |
benchmark_functions_edited/f3008.py | def f(n: int):
k = 1
m = n / 2
while k < m:
k *= 2
return k
assert f(3) == 2 |
benchmark_functions_edited/f7969.py | def f(value, multiple_of=1):
# Mimicks the Excel "floor" function (for code stolen from occupancy calculator)
from math import floor
return int(floor(value/multiple_of))*multiple_of
assert f(5.4, 1) == 5 |
benchmark_functions_edited/f12209.py | def f(r1, r2):
assert len(r1) == len(r2)
n = 0
for i in range(len(r1)):
for j in range(i):
n += bool((r1[i] < r1[j]) ^ (r2[i] < r2[j]))
return n
assert f(range(3), range(3)) == 0 |
benchmark_functions_edited/f10396.py | def f(array, cutoff):
return sum(abs(value) for value in array if abs(value) > cutoff)
assert f(range(4), -1.0) == 6 |
benchmark_functions_edited/f5234.py | def f(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a
assert f(5) == 5 |
benchmark_functions_edited/f10459.py | def f(docstring):
lines = docstring.split("\n")
for line in lines:
if line.startswith(" "):
for t in range(len(line)):
if line[t] != " ":
return t
return 0
assert f(" a\n b\n c\n") == 2 |
benchmark_functions_edited/f11609.py | def f(a, b, visual = True):
if (a < b):
return f(b, a, visual)
# a = bq + r
if (b == 0):
return a
else:
if (visual):
print("%s = %s * %s + %s ===> %s = %s - %s * %s" %
(a, b, a // b, a % b, a % b, a, b, a // b))
return f(b, a % b, visual)
assert f(10, 1) == 1 |
benchmark_functions_edited/f1485.py | def f(number):
return sum(map(int, str(abs(number))))
assert f(42) == 6 |
benchmark_functions_edited/f5808.py | def f(s1, s2):
total = 0
for c1, c2 in zip(s1, s2):
total += sum(((ord(c1)^ord(c2)) >> i) & 1 for i in range(8))
return total
assert f(b'','') == 0 |
benchmark_functions_edited/f7237.py | def f(value: str) -> int:
return int(len(value) - value.count('\x1b') * 4.5 + value.count('\x1b[1'))
assert f('\x1b[31mxxxxxx\x1b[0m') == 6 |
benchmark_functions_edited/f6235.py | def f(library, label):
for idx, name in enumerate(library.keys()):
if name == label:
return idx
return -1
assert f(
{'sin': lambda x: None, 'cos': lambda x: None}, 'cos') == 1 |
benchmark_functions_edited/f7195.py | def f(l):
for item in l:
if item:
return item
return None
assert f([None, 1, None, 2, None]) == 1 |
benchmark_functions_edited/f2177.py | def f(x, y, board):
return board[x][y]
assert f(0, 0, [[4]]) == 4 |
benchmark_functions_edited/f13286.py | def f(base_value, max_warmup_iter, cur_step):
if max_warmup_iter <= cur_step:
return base_value
return base_value * cur_step / max_warmup_iter
assert f(1, 5, 8) == 1 |
benchmark_functions_edited/f4814.py | def f(speed):
if speed < -1:
return -1
if speed > 1:
return 1
return speed
assert f(2.5) == 1 |
benchmark_functions_edited/f5267.py | def f(n: int, k: int) -> int:
if n == 1:
return 1
return (f(n - 1, k) + k - 1) % n + 1
assert f(1, 2) == 1 |
benchmark_functions_edited/f14058.py | def f(y_true, y_pred):
y = [x for x in y_true if x > 0]
y_pred = [y_pred[i] for i in range(len(y_true)) if y_true[i] > 0]
num = len(y_pred)
sums = 0
for i in range(num):
tmp = abs(y[i] - y_pred[i]) / y[i]
sums += tmp
mape = sums * (100 / num)
return mape
assert f([0.5, 0.5, 0.5], [0.5, 0.5, 0.5]) == 0 |
benchmark_functions_edited/f13140.py | def f(tmpstr):
hash_val = 1
if tmpstr:
hash_val = 0
# pylint: disable=W0141
for ordinal in map(ord, tmpstr[::-1]):
hash_val = (
(hash_val << 6) & 0xfffffff) + ordinal + (ordinal << 14)
left_most_7 = hash_val & 0xfe00000
if left_most_7 ... |
benchmark_functions_edited/f3915.py | def f(line, character):
return sum(1 for char in line if char == character)
assert f(
"cat",
"d"
) == 0 |
benchmark_functions_edited/f4480.py | def f(text):
count = 0
if text is not None:
count += text.count('\t')
count += int(text.count(' ') / 4)
return count
assert f(' ') == 1 |
benchmark_functions_edited/f4922.py | def f(list_of_tuples, key):
return sum(1 for i, _ in list_of_tuples if i == key)
assert f(
[('a', 'b'), ('a', 'b'), ('a', 'b'), ('b', 'a')],
'a',
) == 3 |
benchmark_functions_edited/f3857.py | def f(a : int, b: int) -> int:
if b == 0:
return a
return f(b, a % b)
assert f(10, 3) == 1 |
benchmark_functions_edited/f7761.py | def f(byteData):
CRC = 0
# for j in range(0, len(str),2):
for b in byteData:
# char = int(str[j:j+2], 16)
# print(b)
CRC = CRC + b
CRC &= 0xFF
return CRC
assert f(b'') == 0 |
benchmark_functions_edited/f3785.py | def f(n_prev, filter_size, stride, padding):
return ((n_prev + 2 * padding - filter_size) // stride) + 1
assert f(8, 4, 2, 1) == 4 |
benchmark_functions_edited/f2734.py | def f(tags):
return 0 if not tags else sorted(tags, key=lambda x: x['id'])[-1][0] + 1
assert f(None) == 0 |
benchmark_functions_edited/f1660.py | def f(n):
if n is not None:
return int(float(n))
return n
assert f(1.0) == 1 |
benchmark_functions_edited/f11392.py | def f(old_min, old_max, new_min, new_max, value):
old_range = old_max - old_min
if old_range == 0:
new_value = new_min
return new_value
else:
new_range = new_max - new_min
new_value = (((value - old_min) * new_range) / old_range) + new_min
return new_value
assert f(0... |
benchmark_functions_edited/f11481.py | def f(track):
numbers = set(int(x[1]) for x in track.keys() if x.startswith('F'))
return max(numbers)
assert f(
{'F1': 1, 'F2': 2, 'F3': 3, 'F4': 4, 'F5': 5, 'F6': 6, 'F7': 7}) == 7 |
benchmark_functions_edited/f3836.py | def f( binstr ):
n = 0
while (binstr != 0):
binstr = (binstr & (binstr - 1))
n += 1
return n
assert f(0b10000000000000000000000000000000000000000000000000000000000000) == 1 |
benchmark_functions_edited/f2847.py | def f(f):
if f == int(f): return 0
return len(str(f).split('.')[-1])
assert f(123456789) == 0 |
benchmark_functions_edited/f3174.py | def f(v: str) -> int:
try:
return int(v)
except ValueError:
return -1
assert f('9') == 9 |
benchmark_functions_edited/f6941.py | def f(byte: int) -> int:
for _ in range(8):
byte = (byte >> 1) ^ 0xA001 if byte & 1 else byte >> 1
return byte
assert f(0) == 0 |
benchmark_functions_edited/f9361.py | def f(x, y):
tot = 0
consts = (1.5, 2.25, 2.625)
for i in range(1, 4):
tot += 2 * (y**i - 1) * (x * (y**i - 1) + consts[i-1])
return tot
assert f(0, 1) == 0 |
benchmark_functions_edited/f2321.py | def f(a, b):
if a % b == 0:
return b
else:
return f(b, a % b)
assert f(1, 23) == 1 |
benchmark_functions_edited/f10237.py | def f(x):
if type(x) == int:
flg = 'invalid for negative integers'
if x > 0:
return f(x - 1) * x
elif x < 0:
raise Exception(flg)
else:
return 1
else:
raise Exception('invalid for non-integers')
assert f(0) == 1 |
benchmark_functions_edited/f1423.py | def f(l, s):
return len(l) - l[-1::-1].index(s) - 1
assert f(list("abcab"), "b") == 4 |
benchmark_functions_edited/f7826.py | def f(B, t, delta, N0):
return ((B*delta*t)/(B*delta*t + 2))**N0
assert f(0, 1, 1, 1) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.