file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f1283.py | def f(x: int, y: int) -> int:
return y * 8 + x
assert f(0, 1) == 8 |
benchmark_functions_edited/f9746.py | def f(t):
if isinstance(t, tuple) and len(t) >= 1 and callable(t[0]):
return t[0](*t[1:])
else:
return t
assert f((lambda x: x + 1, 2)) == 3 |
benchmark_functions_edited/f6596.py | def f(float_num, default=None):
if float_num is None:
return default
else:
try:
return int(float_num)
except ValueError:
return default
assert f(4.0) == 4 |
benchmark_functions_edited/f9933.py | def f(x):
if x <= 1:
return x
l, r = 0, x
while l + 1 < r:
mid = l + (r - l) // 2
if mid * mid <= x < (mid + 1) * (mid + 1):
return mid
elif mid * mid > x:
r = mid
else:
l = mid
assert f(9) == 3 |
benchmark_functions_edited/f10668.py | def f(data, crc, table):
crc = ~crc & 0xFFFFFFFF
for byte in data:
index = (crc ^ byte) & 0xFF
crc = (crc >> 8) ^ table[index]
return ~crc & 0xFFFFFFFF
assert f(b"", 0, b"") == 0 |
benchmark_functions_edited/f13389.py | def f(string):
space_count = 0
for index in range(len(string)):
character = string[-(index+1)]
if character.isspace():
space_count += 1
else:
break
return space_count / 3
assert f( 'hello world' ) == 0 |
benchmark_functions_edited/f10770.py | def f(station_loc, loc):
y0, x0 = station_loc
y1, x1 = loc
if y1 <= y0:
if x1 < x0:
quad = 1
else:
quad = 2
else:
if x1 < x0:
quad = 3
else:
quad = 4
return quad
assert f(
(1, 2), (2, 2)
) == 4 |
benchmark_functions_edited/f7137.py | def f(n):
if n <= 1:
return n
else:
return n * f(n - 2)
assert f(8) == 0 |
benchmark_functions_edited/f5394.py | def f(iterable):
it = iter(iterable)
return next(it)
assert f((0,)) == 0 |
benchmark_functions_edited/f5531.py | def f(total1, total2, intersect):
total = total1 + total2
return 2.0 * intersect / total
assert f(5, 5, 5) == 1 |
benchmark_functions_edited/f13976.py | def f(num :int, minimum :int, maximum :int) ->int:
count = 0
for i in range(minimum,maximum+1):
count += 1
if (i==num):
break
return count
assert f(100,10,10) == 1 |
benchmark_functions_edited/f5845.py | def f(x, a):
y = 2*x**2+a-1
return y
assert f(0, 1) == 0 |
benchmark_functions_edited/f4555.py | def f(name, outputs):
return next(
output['value'] for output in outputs if output['name'] == name
)
assert f(
'value',
[
{'name': 'other', 'value': 2},
{'name': 'value', 'value': 1},
]
) == 1 |
benchmark_functions_edited/f14439.py | def f(n: int, m: int) -> int:
if n <= 0 or m <= 0:
return -1
lst = list(range(n))
index = 0
while len(lst) > 1:
index += m - 1
while index > len(lst) - 1:
index -= len(lst)
val = lst[index]
lst.remove(val)
return lst[0]
assert f(9, 1) == 8 |
benchmark_functions_edited/f10313.py | def f(board_state, size=3):
diff = 0
for y in range(size):
for x in range(size):
idx = board_state[y][x] - 1
if idx != 8:
diff += abs(idx % size - x) + abs(idx // size - y)
return diff
assert f(
[[1,2,3], [4,5,6], [7,8,9]]) == 0 |
benchmark_functions_edited/f792.py | def f(a):
a = float(a)
return a / 100
assert f(0) == 0 |
benchmark_functions_edited/f1491.py | def f(x: int) -> int:
return ((x >> 8) & 0x00000003) + 1
assert f(9) == 1 |
benchmark_functions_edited/f8938.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) # compute negative value
return val # return positive value as is
assert f(1, 8) == 1 |
benchmark_functions_edited/f13379.py | def f(y):
result = 0
cur = 0 # Current digit number
while y > 0:
cur = y % 10
y = y // 10
result += cur
return result
assert f(10) == 1 |
benchmark_functions_edited/f12394.py | def f(value):
if value is None:
return None
if value == 0:
return 0
if value <= 1:
return round(value, 3)
if value <= 10:
return round(value, 2)
if value <= 100:
return round(value,1)
return int(value)
assert f(1.0001) == 1 |
benchmark_functions_edited/f10193.py | def f(n, value = 1, previous = 0):
if (n == 0 or n == 1):
return previous
if (n == 2):
return value
return f(n - 1, value + previous, value)
assert f(3, 1, 1) == 2 |
benchmark_functions_edited/f5435.py | def f(lines):
max_width = len(lines[0])
for line in lines:
if len(line) > max_width:
max_width = len(line)
return max_width
assert f(
['aa', 'aaa', 'aa', 'aaaa']
) == 4 |
benchmark_functions_edited/f800.py | def f(pair):
(value, ratio) = pair
return ratio
assert f(("", 2)) == 2 |
benchmark_functions_edited/f8023.py | def f(n, a): # sum of digits powered
numStr = str(n)
total = 0
for digit in numStr:
total += int(digit)**a
return total
assert f(1, 0) == 1 |
benchmark_functions_edited/f5826.py | def f(coords_1, coords_2):
paired_coords = zip(coords_1, coords_2)
return sum([abs(coord[0] - coord[1]) for coord in paired_coords])
assert f((3, 4), (3, 4)) == 0 |
benchmark_functions_edited/f8416.py | def f(e,L):
def indHelp(e,L,c):
if(c==len(L)):
return c
if(e==True):
return c
if(e == L[c]):
return c
return indHelp(e,L,c+1)
return indHelp(e,L,0)
assert f('a', ['a', 'b', 'c']) == 0 |
benchmark_functions_edited/f11434.py | def f(sheet_object):
rows = 0
for _, row in enumerate(sheet_object, 1):
if not all(col.value is None for col in row):
rows += 1
return rows
assert f([]) == 0 |
benchmark_functions_edited/f11057.py | def f(data):
iterable = (list, tuple, set)
if isinstance(data, iterable):
return [f(i) for i in data]
if not isinstance(data, dict):
return data
global Obj
class Obj: pass
obj = Obj()
for k, v in data.items():
setattr(obj, k, f(v))
return obj
assert f(0) == 0 |
benchmark_functions_edited/f7998.py | def f(subarr, k):
even_k = (k % 2 == 0)
if even_k:
right = k / 2
left = right - 1
return (subarr[left] + subarr[right]) / 2
else:
id = k // 2
return subarr[id]
assert f([1, 3], 1) == 1 |
benchmark_functions_edited/f11665.py | def f(count, filepath, callback, *kargs, **kwargs):
kwargs["filepath"] = filepath
callback(*kargs, **kwargs)
return count + 1
assert f(0, "foo.txt", lambda *args, filepath, **kwargs: 42) == 1 |
benchmark_functions_edited/f1063.py | def f(gt):
x = gt.split(b'|')
return int(x[0])+int(x[1])
assert f(b'1|1') == 2 |
benchmark_functions_edited/f7926.py | def f(array):
if len(array) == 0:
return 0
elif len(array) == 1:
return array[0] ** 2
return sum([x for i, x in enumerate(array) if i % 2 == 0]) * array[-1]
assert f([1, 0, 1, 0]) == 0 |
benchmark_functions_edited/f1506.py | def f(N, d):
n = N // d
return (n * (2 * d + (n - 1) * d)) // 2
assert f(2, 1) == 3 |
benchmark_functions_edited/f3395.py | def f(x, scale, power, return_components=False):
return scale*x**power
assert f(8, 1, 1) == 8 |
benchmark_functions_edited/f8233.py | def f(nums):
n_negative = 0
for num in nums:
if num < 0:
n_negative = n_negative + 1
return n_negative
assert f([-1, -2, -3, 4]) == 3 |
benchmark_functions_edited/f13566.py | def f(flares):
weights = {
'X': 100,
'M': 10,
'C': 1,
'B': 0.1,
'A': 0,
}
flare_index = 0
for f in flares:
if f == '':
continue
if f == 'C':
continue
flare_index += weights[f[0]] * float(f[1:])
flare_index = round(flare_index, 1) # prevent numerical error
return flare_index
assert f(set()) == 0 |
benchmark_functions_edited/f5241.py | def f(v, msg):
try:
return int(v)
except:
raise ValueError("Bad value: '{}'; {} ".format(v,msg) )
assert f( "2", "" ) == 2 |
benchmark_functions_edited/f6186.py | def f(s):
c = 0
for x in s:
if x == '1':
c+=1
return (c*(c-1))//2
assert f(list("110")) == 1 |
benchmark_functions_edited/f5181.py | def f(contributions):
return sum(signal for signal, orientation in contributions)
assert f(
[(1, +1)]) == 1 |
benchmark_functions_edited/f965.py | def f(x: int, y: int) -> int:
return abs(x) + abs(y)
assert f(-3, -3) == 6 |
benchmark_functions_edited/f6999.py | def f(x):
x = tuple(x)
if len(x) >= 2 and x[0] == 1:
base = x[1]
for i, xi in enumerate(x):
if base ** i != xi:
return
return base
assert f( (1, 3, 9, 27, 81, 243) ) == 3 |
benchmark_functions_edited/f13876.py | def f(num=0,show=False):
fat = 1
for i in range(num,0,-1):
if show:
print(i,end='')
if i > 1 :
print(" X ",end='',)
else:
print(f' = ',end='')
fat *= i
return fat
assert f(1, False) == 1 |
benchmark_functions_edited/f9655.py | def f(iterable):
values = sorted(iterable)
le = len(values)
assert le
if le % 2 == 1:
return values[le // 2]
else:
return (values[le // 2 - 1] + values[le // 2]) / 2
assert f([4, 5, 1, 2, 3]) == 3 |
benchmark_functions_edited/f7001.py | def f(dayinput):
lines = dayinput.split('\n')
correct = 0
for line in lines:
if len(line.split(' ')) == len(set(line.split(' '))):
correct += 1
return correct
assert f(
) == 2 |
benchmark_functions_edited/f4851.py | def f(e, g=None, l=None):
r = eval(e, g, l)
if type(r) in [int, float]:
return r
raise ValueError('r=%r' % (r))
assert f('1 + 2', {}, {}) == 3 |
benchmark_functions_edited/f9904.py | def f(nl, nL, sl, ml):
return nl * nL * sl * sl * ml * ml
assert f(1, 1, 1, 1) == 1 |
benchmark_functions_edited/f13811.py | def f(a) -> int:
count = 0
# a is of type 'dict_items'
for i, this_tuple in enumerate(a):
# key is product id, value is dictionary of product data
values = this_tuple[1]
count += values['quantity']
return count
assert f([("lemon", {"color": "yellow", "name": "lemon", "price": 1, "quantity": 3})] +
[("banana", {"color": "yellow", "name": "banana", "price": 4, "quantity": 6})]) == 9 |
benchmark_functions_edited/f754.py | def f(a, b):
if a < b :
return a
else :
return b
assert f(1, 0) == 0 |
benchmark_functions_edited/f12646.py | def f(exp1, exp2):
words1, vector1 = exp1
words2, vector2 = exp2
similarity = 0.0
for idx1, word in enumerate(words1):
# if a word is in both exp1 and exp2, similarity increased by tfidf1 * tfidf2
if word in words2:
idx2 = words2.index(word)
similarity += vector1[idx1] * vector2[idx2]
return similarity
assert f(
(['a', 'b', 'c'], [1, 1, 1]),
(['a', 'b', 'c'], [0, 0, 0])
) == 0 |
benchmark_functions_edited/f10587.py | def f(direction):
return {'Input': 0,
'Output': 1,
'input': 0,
'output': 1,
0: 0,
1: 1,
'0': 0,
'1': 1}[direction]
assert f('Input') == 0 |
benchmark_functions_edited/f3595.py | def f(velocity):
return (velocity - 1) * 2 + 1
assert f(1) == 1 |
benchmark_functions_edited/f9382.py | def f(data):
return float(sum([data[index] - data[index + 1] for index in range(len(data)-1) if data[index + 1] < data[index]]))
assert f(range(2)) == 0 |
benchmark_functions_edited/f4844.py | def f(payload):
user_id = payload.get('user_id')
return user_id
assert f({'user_id': 9}) == 9 |
benchmark_functions_edited/f8602.py | def f(low, value, high):
assert low <= high
return max(low, min(value, high))
assert f(0, 0, 3) == 0 |
benchmark_functions_edited/f119.py | def f(x):
return max(0, x)
assert f(-0.33333) == 0 |
benchmark_functions_edited/f233.py | def f(a):
if a > 3:
return 1
return a
assert f(2) == 2 |
benchmark_functions_edited/f4509.py | def f(w, x, y, z):
return (w << 24) | (x << 16) | (y << 8) | z
assert f(0, 0, 0, 0) == 0 |
benchmark_functions_edited/f9991.py | def f(o, default=False, *values):
for val in values:
if val in o:
return o[val]
return default
assert f(
{
"a": 0,
"b": 1,
"c": 2,
"d": 3,
"e": 4,
"f": 5,
},
False,
"a",
"h",
"l",
"o",
) == 0 |
benchmark_functions_edited/f6631.py | def f(row, minimum, maximum):
count = 0
for n in row:
if minimum <= n <= maximum:
count = count + 1
return count
assert f(
[1, 3, 5, 7],
2,
5
) == 2 |
benchmark_functions_edited/f7235.py | def f(value: bytearray) -> int:
return value[0] & 0x80
assert f(bytearray([0x00, 0x80, 0x00])) == 0 |
benchmark_functions_edited/f10470.py | def f(iterator, default=None):
last = default
for member in iterator:
last = member
return last
assert f(iter([1, 2, 3, 4, 5, 6])) == 6 |
benchmark_functions_edited/f14303.py | def f(string, tab_size=4):
indent = 0
for c in string:
if c == ' ':
indent += 1
elif c == '\t':
indent += tab_size
else:
break
return indent
assert f(
'if a:\n b\n c\n d') == 0 |
benchmark_functions_edited/f10232.py | def f(old, new):
return (new - old)/old
assert f(1, 1) == 0 |
benchmark_functions_edited/f7330.py | def f(i):
if i >= 1:
return 1
else:
return 0
assert f(1) == 1 |
benchmark_functions_edited/f252.py | def f(f_x, y):
return 2 * (f_x - y)
assert f(1000000, 1000000) == 0 |
benchmark_functions_edited/f10484.py | def f(r, R_min, depth=1., p12=12, p6=6):
return depth * ((R_min / r)**p12 - 2 * (R_min / r)**p6)
assert f(1, 2, 2, 2, 1) == 0 |
benchmark_functions_edited/f6933.py | def f(AUC):
try:
return 2 * AUC - 1
except Exception:
return "None"
assert f(1) == 1 |
benchmark_functions_edited/f13570.py | def lsb (target, data):
s1 = str(target)
s2 = str(data)
# check if data can't insert in target
if len(s2)>len(s1):
return target
# lenght of data to insert
n = len(s2)
# slice a target
s1 = s1[:-n]
return s1+s2
assert f(0, 100000000) == 0 |
benchmark_functions_edited/f3447.py | def f(fm, f0):
return (fm - f0) / fm
assert f(5, 5) == 0 |
benchmark_functions_edited/f7303.py | def f(x, x0, x1):
if x > x1:
return x1
elif x < x0:
return x0
else:
return x
assert f(0, 0, 1) == 0 |
benchmark_functions_edited/f10075.py | def f(seq_tuple):
(seq_min, seq_max) = seq_tuple
if None in (seq_min, seq_max) or 0 in (seq_min, seq_max):
return None
# Seq wrap-around
diff = seq_max - seq_min
if diff < 0:
diff += 2 ** 32
return diff
assert f( (2 ** 32 - 1, 2 ** 32 - 1) ) == 0 |
benchmark_functions_edited/f6900.py | def f(pl: list) -> int:
if not isinstance(pl, list):
return 0
level = 0
for item in pl:
level = max(level, f(item))
return level + 1
assert f([]) == 1 |
benchmark_functions_edited/f13880.py | def f(line):
pre = "" # previous character
count = 1
max = 0
for i in line:
print(i)
if i == pre:
count += 1
else:
count = 1
if max < count:
max = count
# print("max = " + str(max))
pre = i
# print("final max = " + str(max))
return max
assert f( 'bbb') == 3 |
benchmark_functions_edited/f14338.py | def f(a, b, c):
i = j = k = 0
while i < len(a) and j < len(b) and k < len(c):
x, y, z = a[i], b[j], c[k]
if x == y == z:
return x
m = max(x, y, z)
if x < m:
i += 1
if y < m:
j += 1
if z < m:
k += 1
return -1
assert f(
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[2, 2, 2, 2, 2]
) == 2 |
benchmark_functions_edited/f1420.py | def f(value, min_, max_):
return max(min_, min(max_, value))
assert f(0, 1, 10) == 1 |
benchmark_functions_edited/f2065.py | def f(n: int) -> int:
return sum(int(d) for d in str(n))
assert f(1) == 1 |
benchmark_functions_edited/f7976.py | def f(test, obj, msg=None):
if (callable(test) and not test(obj)) or not test:
raise AssertionError(msg)
return obj
assert f(1, 2, "msg") == 2 |
benchmark_functions_edited/f13077.py | def f(v, divisor, min_value=None):
if min_value is None:
min_value = divisor
new_v = max(min_value, int(v + divisor / 2) // divisor * divisor)
# Make sure that round down does not go down by more than 10%.
if new_v < 0.9 * v:
new_v += divisor
return new_v
assert f(3, 8) == 8 |
benchmark_functions_edited/f13181.py | def f(target_actor_id, actors_id, predicted_weights):
try:
target_idx = actors_id.index(target_actor_id)
except:
raise Exception('Actor id {} is not found in the graph'.format(target_actor_id))
return predicted_weights[target_idx]
assert f(3, [1,2,3], [1,2,3]) == 3 |
benchmark_functions_edited/f8147.py | def f(gpuRank,rank):
if rank < 2:
return gpuRank
elif rank < 4:
return list() #gpuRank
elif rank < 6:
return list()
elif rank < 8:
return list()
assert f(0,0) == 0 |
benchmark_functions_edited/f12570.py | def f(x_param: int) -> int:
tot = 0
while x_param:
tot += 1
x_param &= x_param - 1
return tot
assert f(4097) == 2 |
benchmark_functions_edited/f6618.py | def f(value1, value2, value3):
max_value = value1
if value2 > max_value:
max_value = value2
if value3 > max_value:
max_value = value3
return max_value
assert f(1, 2, 3) == 3 |
benchmark_functions_edited/f2900.py | def f(n, x_av, y_av, sum_x2, sum_xy):
return (sum_xy - n*x_av*y_av) / (sum_x2 - n*x_av**2)
assert f(3, 3, 3, 1, 1) == 1 |
benchmark_functions_edited/f8649.py | def f(s1, s2):
hamm_diff = 0; len_diff = 0
if len(s1) != len(s2):
len_diff = abs(len(s1) - len(s2))
for char1, char2 in zip(s1, s2):
if char1 != char2:
hamm_diff += 1
return hamm_diff + len_diff
assert f("abc", "def") == 3 |
benchmark_functions_edited/f13530.py | def f(T_M, T_E, C_Pm, i_m, P_m, s, x):
Q_AB = 10**-3 * ((T_M - T_E) * C_Pm + i_m) * (P_m * (s / 2) * x)
return Q_AB
assert f(0, 0, 1, 0, 0, 1, 1) == 0 |
benchmark_functions_edited/f8585.py | def f(X, Y, angle):
import numpy as np
theta = np.radians(angle % 360)
Z = np.abs(np.cos(theta) * X - np.sin(theta) *
Y) + np.abs(np.sin(theta) * X + np.cos(theta) * Y)
return Z
assert f(-1, 0, 90) == 1 |
benchmark_functions_edited/f4050.py | def f(nums):
s = 0
for n in nums:
s ^= n
return s
assert f([0]) == 0 |
benchmark_functions_edited/f12239.py | def f(scorefct, cand_in_com):
return sum(scorefct(i + 1) for i in range(cand_in_com))
assert f(lambda i: 1 / i, 1) == 1 |
benchmark_functions_edited/f3859.py | def f(board, player):
count = 0
count = [count + f.count(player) for f in board]
return sum(count)
assert f(
[['X', 'O', 'X'],
['O', 'X', 'X'],
['X', 'O', 'X']], 'X') == 6 |
benchmark_functions_edited/f13577.py | def f(path_length, frequency_lookup):
if path_length < 10000:
return frequency_lookup['under_10km']
elif 10000 <= path_length < 20000:
return frequency_lookup['under_20km']
elif 20000 <= path_length < 45000:
return frequency_lookup['under_45km']
else:
print('Path_length outside dist range: {}'.format(path_length))
assert f(1000, {'under_10km': 1, 'under_20km': 2}) == 1 |
benchmark_functions_edited/f8187.py | def f(keys, dict):
if not keys:
raise ValueError("Expected at least one key, got {0}".format(keys))
current_value = dict
for key in keys:
current_value = current_value[key]
return current_value
assert f(('a',), {'a': 1}) == 1 |
benchmark_functions_edited/f7942.py | def f(number):
factorial = 1
for permutation in range(1, number + 1):
factorial *= permutation
answer = sum(list(map(int, str(factorial))))
return answer
assert f(1) == 1 |
benchmark_functions_edited/f11210.py | def f(signatures):
if len(signatures) == 0:
return 0
elif len(signatures) == 1:
return signatures[0]
else:
return max(signatures)
assert f([]) == 0 |
benchmark_functions_edited/f5968.py | def f(ch, charset):
try:
return charset.index(ch)
except ValueError:
raise ValueError('base62: Invalid character (%s)' % ch)
assert f(b'3', b'0123456789') == 3 |
benchmark_functions_edited/f8117.py | def f(protect_status):
rtn_value = 0
if 'yes' in protect_status.lower():
rtn_value = 1
return rtn_value
assert f('yes') == 1 |
benchmark_functions_edited/f7094.py | def f(matrix, a, b, swap, da=0, db=0):
# pylint: disable=invalid-name
# pylint: disable=too-many-arguments
a, b = swap(a, b)
return matrix[a + da][b + db]
assert f(
[
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
],
1, 1, lambda a, b: (a, b),
) == 5 |
benchmark_functions_edited/f1349.py | def f(r):
return max(r) - min(r)
assert f(range(0, 1)) == 0 |
benchmark_functions_edited/f14129.py | def f(tipo) -> int:
tipo_ = 3
# subtipo_ = None
if tipo in ["int", "uint", "serial"]:
tipo_ = 16
elif tipo in ["string", "stringlist", "pixmap", "counter"]:
tipo_ = 3
elif tipo in ["double"]:
tipo_ = 19
elif tipo in ["bool", "unlock"]:
tipo_ = 18
elif tipo in ["date"]:
tipo_ = 26
elif tipo in ["time"]:
tipo_ = 27
return tipo_
assert f("stringlist") == 3 |
benchmark_functions_edited/f1487.py | def f(N):
ct = 1
while N >= 2:
ct = ct + 1
N = N ** 0.5
return ct
assert f(16) == 4 |
benchmark_functions_edited/f11623.py | def f(p, max_time=3600000): # by default 1 h (in ms)
if p["result.totalTimeSystem"] == "3600.0":
v = 3600000 # convert to ms (error in logging)
else:
v = int(float(p["result.totalTimeSystem"]))
return max_time if v > max_time else v
assert f(
{"result.totalTimeSystem": "0.0"}) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.