file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f12270.py
|
def f(collection, search_value):
for (index, element) in enumerate(collection):
if element == search_value:
return index
return -1
assert f(range(10), 7) == 7
|
benchmark_functions_edited/f13110.py
|
def f(line, dtype):
value = line.split("<Value>")[-1].split("</Value>")[0]
return dtype(value)
assert f(r"<Value>0</Value>\n", int) == 0
|
benchmark_functions_edited/f8736.py
|
def f(x, k): # x is the number of interest, k is the power
y = 2
while y <= x:
y = y**k
if y > x:
return y**(1/k) - 1
if y == x:
y**(1/k)
y = y**(1/k)
y += 1
assert f(6, 2) == 2
|
benchmark_functions_edited/f13106.py
|
def f(x: int, y: int = 1, *, subtract: bool = False) -> int:
return x - y if subtract else x + y
assert f(2, 2) == 4
|
benchmark_functions_edited/f10205.py
|
def f(a1, a2):
a1.sort()
a2.sort()
count = 0
a1_, a2_ = a1, a2
if len(a1) > len(a2):
a1_ = a2
a2_ = a1
for s in a1:
if not s in a2:
count += 1
return count
assert f(
[1, 2, 3, 4],
[1, 2, 3, 4],
) == 0
|
benchmark_functions_edited/f12543.py
|
def f(A):
if len(A) > 0 and A[0] > 0:
return 0
if len(A) > 0 and A[-1] < 0:
return len(A)
l = 0
h = len(A)-1
while l <= h:
mid = l + (h-l) // 2
if A[mid] > 0 and A[mid-1] < 0:
return mid
elif A[mid] > 0:
h = mid - 1
else:
l = mid + 1
assert f( [-1, 2, -3, 4] ) == 1
|
benchmark_functions_edited/f5004.py
|
def f(exc):
if isinstance(exc, SystemExit):
return exc
print("WARNING - General JbossAS warning:", exc)
return 1
assert f(Exception("foo")) == 1
|
benchmark_functions_edited/f9599.py
|
def f(*xs):
if len(xs) == 1:
xs = xs[0]
for x in xs:
if x is not None:
return x
return None
assert f({1, 2, 3}) == 1
|
benchmark_functions_edited/f6842.py
|
def f(n: int) -> int:
if not n >= 0:
raise ValueError
return 4*n**2 - 3*n
assert f(1) == 1
|
benchmark_functions_edited/f9177.py
|
def f(s):
if not s:
return 1
elif len(s) == 1:
return 1
else:
prefix = int(s[:2])
if prefix <= 26: # 2 char
return f(s[2:]) + f(s[1:])
else: # 1 char
return f(s[1:])
assert f("0") == 1
|
benchmark_functions_edited/f294.py
|
def f(y, t=0, l=1):
dydt = -l * y
return dydt
assert f(0, 0, 0) == 0
|
benchmark_functions_edited/f13036.py
|
def f(polygon):
w=0
for count in range(len(polygon)-1):
y = polygon[count+1][1] + polygon[count][1]
x = polygon[count+1][0] - polygon[count][0]
z = y * x
w += z
return abs(w/2.0)
assert f( [(0, 0), (0, 1), (1, 1), (1, 0), (0, 0), (0, 0)] ) == 1
|
benchmark_functions_edited/f11039.py
|
def f(solution):
count = 0
for v in solution.values():
if v:
count += 1
return count
assert f(
{
'a': ['b', 'c'],
'd': ['e', 'f', 'g', 'h'],
'i': ['j'],
'k': []
}) == 3
|
benchmark_functions_edited/f8102.py
|
def f(arr1, arr2):
num_diffs = 0
for i in range(len(arr1)):
num_diffs += len(set(arr1[i]) - set(arr2[i]))
return num_diffs
assert f(
['111111'],
['111111']
) == 0
|
benchmark_functions_edited/f11882.py
|
def f(l, default_value=0):
n_replaced = 0
for i in range(len(l)):
if l[i] < 0:
l[i] = default_value
n_replaced += 1
return n_replaced
assert f( [ 10, -10, -10 ], 0 ) == 2
|
benchmark_functions_edited/f10431.py
|
def f(input_list):
diamonds = 0
open_diamonds = 0
for i in input_list:
if i == '<':
open_diamonds += 1
elif i == '>':
if open_diamonds > 0:
open_diamonds -= 1
diamonds += 1
return diamonds
assert f(list("<<>>")) == 2
|
benchmark_functions_edited/f12495.py
|
def f(port):
portnum = {
'a': 0,
'b': 1,
'c': 2,
'd': 3
}
port = port.lower()
if type(port) is not str:
raise NameError('Invalid output port.')
if port not in list(portnum.keys()):
raise NameError('Invalid output port.')
return portnum[port]
assert f('C') == 2
|
benchmark_functions_edited/f5101.py
|
def f(termA, termB, termC, xVertice):
vertice = ((termA*(pow(xVertice, 2)) + (termB*xVertice) + termC))
return vertice
assert f(0, 0, 0, -1) == 0
|
benchmark_functions_edited/f14352.py
|
def f(position, string, direction):
while 0 < position < len(string):
if string[position] == '\n':
if direction < 0:
if position - 1 > 0 and string[position-1] == '\r':
return position - 1
return position
position += direction
return position
assert f(0, "a\r\n\r\n", 1) == 0
|
benchmark_functions_edited/f12799.py
|
def f(n_frames, duration, start_time):
return int((n_frames * start_time / duration) // 16)
assert f(8, 5, 1) == 0
|
benchmark_functions_edited/f10015.py
|
def f(root, default, path):
if not root:
return default
if not path:
return root
return f(root.get(path[0]), default, path[1:])
assert f({'a': 1}, 'default', ['a']) == 1
|
benchmark_functions_edited/f4989.py
|
def f(n: int) -> int:
return sum(range(0, n, 3)) + sum(range(0, n, 5)) - sum(range(0, n, 15))
assert f(2) == 0
|
benchmark_functions_edited/f2154.py
|
def f(size, block_size):
return int((size + block_size - 1) / block_size)
assert f(10, 2) == 5
|
benchmark_functions_edited/f594.py
|
def f(x, y, goal):
return abs(goal[0] - x) + abs(goal[1] - y)
assert f(1, 1, (0, 0)) == 2
|
benchmark_functions_edited/f9213.py
|
def f( k,q):
q = q-1
k = k % q
try:
for i in range(1,q):
if ((k * i) % q == 1):
return i
return 1
except Exception as e:
print("Something went wrong: ",e.__str__())
return
assert f(123456789,123456789) == 1
|
benchmark_functions_edited/f2813.py
|
def f(pos):
fos = pos - 1
return fos * fos * fos * fos * fos + 1
assert f(0) == 0
|
benchmark_functions_edited/f4420.py
|
def f(h, Xi, x):
return h ** abs(Xi - x)
assert f(1, 3, 3) == 1
|
benchmark_functions_edited/f3523.py
|
def f(pyramid, i):
res = 1
for x, row in enumerate(pyramid):
res *= row[i[x]]
return res
assert f(
[[1],
[1],
[1],
[1]],
(0, 0, 0, 0)) == 1
|
benchmark_functions_edited/f665.py
|
def f(exprstring):
return int(eval(str(exprstring)))
assert f("1 + 1") == 2
|
benchmark_functions_edited/f5116.py
|
def f(bytes_) -> int:
output = 0
for i in range(0, len(bytes_)):
output += bytes_[i] * (2**(8*i))
return output
assert f(b"") == 0
|
benchmark_functions_edited/f537.py
|
def f(x, h, l):
return (x & ((1<<(h+1))-1)) >> l
assert f(0x01, 1, 0) == 1
|
benchmark_functions_edited/f14286.py
|
def f(correct, observed):
distance = 0
for i in range(len(correct)):
if correct[i] != observed[i]:
distance += 1
return distance
assert f(list("0001000"), list("0001111")) == 3
|
benchmark_functions_edited/f10726.py
|
def f(data):
return 100 * sum([1 if p == t else 0 for p, t in data]) / len(data)
assert f(list(zip([1, 1, 1, 1], [0, 0, 0, 0]))) == 0
|
benchmark_functions_edited/f10337.py
|
def f(name):
if isinstance(name, str):
components = name.split('.')
mod = __import__('.'.join(components[0:-1]), globals(), locals(), [components[-1]] )
return getattr(mod, components[-1])
else:
return name
assert f(1) == 1
|
benchmark_functions_edited/f3051.py
|
def f(raw_value):
return int((raw_value + 1) / 2.) / 10.
assert f(0) == 0
|
benchmark_functions_edited/f5454.py
|
def f(tree) -> int:
if tree is None:
return 1
return sum(f(subtree) for subtree in tree.subregions)
assert f(None) == 1
|
benchmark_functions_edited/f1621.py
|
def f(val, lower, upper):
return max(lower, min(val, upper))
assert f(1, 0, 2) == 1
|
benchmark_functions_edited/f1074.py
|
def f(a, b, c):
total = a+b+c
return total
assert f(1, 5, 3) == 9
|
benchmark_functions_edited/f11547.py
|
def f(members):
assert isinstance(members, list)
# ex: 13cycle_1Mag1Diff|i0HQ_SIRV_1d1m|c139597/f1p0/178
try:
return sum(int(_id.split('/')[1].split('p')[0][1:]) for _id in members)
except (IndexError, ValueError):
raise ValueError("Could not get FL num from %s" % members)
assert f(
['13cycle_1Mag1Diff|i0HQ_SIRV_1d1m|c139597/f1p0/178',
'13cycle_1Mag1Diff|i0HQ_SIRV_1d1m|c139597/f1p1/293']
) == 2
|
benchmark_functions_edited/f1664.py
|
def f(val, step):
return (int(val/step)+1)/(1/step)
assert f(4, 1) == 5
|
benchmark_functions_edited/f4460.py
|
def minmax (minValue, maxValue, value):
return max(minValue, min(maxValue, value))
assert f(0, 10, -5) == 0
|
benchmark_functions_edited/f6419.py
|
def f(A, p, r):
q = p
for u in range(p, r):
if A[u] <= A[r]:
A[q],A[u] = A[u],A[q]
q += 1
A[q],A[r] = A[r],A[q]
return q
assert f(list(range(10)), 9, 9) == 9
|
benchmark_functions_edited/f12869.py
|
def f(x, y):
n = len(x) + 1
m = len(y) + 1
table = [ [0]*m for i in range(n) ]
for i in range(n):
for j in range(m):
# If either string is empty, then lcs = 0
if i == 0 or j == 0:
table[i][j] = 0
elif x[i - 1] == y[j - 1]:
table[i][j] = 1 + table[i-1][j-1]
else:
table[i][j] = max(table[i-1][j], table[i][j-1])
return table[len(x)][len(y)]
assert f( "abc", "def" ) == 0
|
benchmark_functions_edited/f1750.py
|
def f(sch1, sch2, cos2phi, sin2phi):
return - (sch2 * cos2phi - sch1 * sin2phi)
assert f(0, 0, -1, 0) == 0
|
benchmark_functions_edited/f1171.py
|
def f(readings):
return sum(readings, 0.0) / len(readings)
assert f(range(1, 2)) == 1
|
benchmark_functions_edited/f6161.py
|
def f(dictionary):
total_circles = 0
for key, array in dictionary.items():
total_circles += len(array)
return total_circles
assert f({}) == 0
|
benchmark_functions_edited/f8455.py
|
def f(cur_id, id_list):
for index, (test_id, test_re) in enumerate(id_list):
if cur_id == test_id or test_re.search(cur_id):
return index
return -1
assert f("ENST00000319564.3", [("ENST00000319564.3", None)]) == 0
|
benchmark_functions_edited/f14265.py
|
def f(row, column_1, column_2):
if row[column_1] == row[column_2]:
return 1
else:
return 0
assert f(
{'col1': 'val1', 'col2': 'val2'},
'col1',
'col2') == 0
|
benchmark_functions_edited/f13171.py
|
def f(numbers_list):
sorted_numbers_list = sorted(numbers_list) # The list 'numbers_list' is sorted in ascending order.
largest = sorted_numbers_list[-1] # The last number is the largest number in list 'sorted_numbers_list
return largest
assert f( [1, 2, 3] ) == 3
|
benchmark_functions_edited/f8116.py
|
def f(x1, x2, y1, y2, z1, z2, func):
return func(x2,y2,z2)-func(x1,y2,z2)-func(x2,y1,z2)-func(x2,y2,z1) \
-func(x1,y1,z1)+func(x1,y1,z2)+func(x1,y2,z1)+func(x2,y1,z1)
assert f(1, 3, 2, 4, 5, 6, lambda x, y, z: x + y) == 0
|
benchmark_functions_edited/f3257.py
|
def f(url):
if not url:
return 0
return url.split('?key=')[1].split('&')[0].split('#')[0]
assert f(None) == 0
|
benchmark_functions_edited/f14063.py
|
def f(d, v1, v2, v3):
if d == 1:
return v1
elif d == 2:
return v2
elif d == 3:
return v3
else:
raise ValueError("Invalid dimension: %s." % d)
assert f(2, 4, 5, 6) == 5
|
benchmark_functions_edited/f1728.py
|
def f(eqn, x):
return eqn[0] * x + eqn[1]
assert f([0, 1], 0) == 1
|
benchmark_functions_edited/f1357.py
|
def f(paramento1, paramentro2='padrao'):
# <bloco de codigo>
valor = 0
return valor
assert f(1) == 0
|
benchmark_functions_edited/f5195.py
|
def f(t_string):
num = [float(n) for n in t_string.split(':')]
return 60*num[0] + num[1] + (num[2]/60)
assert f('00:00:00') == 0
|
benchmark_functions_edited/f11989.py
|
def f(obj, attr_name, *args, **vargs):
try:
return getattr(type(obj),attr_name).fget(obj,*args,**vargs)
except AttributeError:
return getattr(obj,attr_name)
assert f(1, "real", 2, 3) == 1
|
benchmark_functions_edited/f2229.py
|
def f(i):
n = 0
while (2**n) < i:
n += 1
return n
assert f(6) == 3
|
benchmark_functions_edited/f8167.py
|
def f(character, libr):
character_label = libr.index(character)
return character_label
assert f(
'a',
['a', 'b', 'c']
) == 0
|
benchmark_functions_edited/f1499.py
|
def f(vec):
num = 0
for node in vec:
num = num * 10 + node
return num
assert f([]) == 0
|
benchmark_functions_edited/f13589.py
|
def f(r, r_c, r_e, r_a):
if r < r_c:
return -1 # should be -inf
elif r < r_a:
return 0.25 * (r - r_e) / (r_a - r_c)
else:
return 1
assert f(1.0, 0.01, 0.3, 1) == 1
|
benchmark_functions_edited/f7602.py
|
def f(theyvals, thevalue):
for i in range(0, len(theyvals)):
if theyvals[i] >= thevalue:
return i
return len(theyvals)
assert f(
[2, 3, 5, 7, 9], 7) == 3
|
benchmark_functions_edited/f7055.py
|
def f(number: int) -> int:
count = 0
while number > 1:
if number % 2:
number = number * 3 + 1 # odd
else:
number //= 2 # even
count += 1
return count
assert f(3) == 7
|
benchmark_functions_edited/f10691.py
|
def f(step, warmup_steps,
model_size, rate, decay_steps, start_step=0):
return (
model_size ** (-0.5) *
min(step ** (-0.5), step * warmup_steps**(-1.5)) *
rate ** (max(step - start_step + decay_steps, 0) // decay_steps))
assert f(1, 1, 1, 1, 2) == 1
|
benchmark_functions_edited/f5086.py
|
def f(dict, key, default=None):
if key in dict:
return dict.pop(key)
return default
assert f(dict(), 'baz', 0) == 0
|
benchmark_functions_edited/f341.py
|
def f(array):
x, *_ = array
return x
assert f(range(10)) == 0
|
benchmark_functions_edited/f4353.py
|
def f(sheeps) -> int:
count = 0
for sheep in sheeps:
if sheep:
count += 1
return count
assert f(list()) == 0
|
benchmark_functions_edited/f7218.py
|
def f(num1: int, num2: int) -> int:
if not num2:
return num1
return f(num2, num1 % num2)
assert f(3, 6) == 3
|
benchmark_functions_edited/f13095.py
|
def f(yaw):
if yaw == 0.0:
return 0.0
if yaw > 0.0:
return 360 % yaw
if yaw < 0.0:
yaw += 360
return 360 % yaw
return 0.0
assert f(0) == 0
|
benchmark_functions_edited/f4758.py
|
def f(input_list, out=0):
if len(input_list) > 0:
f(input_list[1:], out+input_list[0])
else:
return out
assert f([]) == 0
|
benchmark_functions_edited/f5426.py
|
def f(image):
try:
return image.rsplit(':', 1)[1]
except IndexError:
return 0
except AttributeError:
return 0
assert f('scratch') == 0
|
benchmark_functions_edited/f2309.py
|
def f(x):
for index, i in enumerate(x):
if i: return index
assert f([1, 2, 3, 1, 1]) == 0
|
benchmark_functions_edited/f12986.py
|
def f(k, counter=None):
assert counter, "counter must be non-empty and not `None`."
return max(filter(lambda r: counter[r] >= k, counter.keys()),
default=min(counter.keys()))
assert f(1, {1: 2, 2: 4}) == 2
|
benchmark_functions_edited/f9546.py
|
def f(lista_de_listas):
menor_lista = len(lista_de_listas[0])
for lista in lista_de_listas:
if(len(lista) < menor_lista):
menor_lista = len(lista)
return menor_lista
assert f( [[],[],[],[]] ) == 0
|
benchmark_functions_edited/f7363.py
|
def f(number):
weights = (2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9)
check = sum(w * int(n) for w, n in zip(weights, number)) % 11
return 1 if check == 10 else check
assert f("838308383882") == 4
|
benchmark_functions_edited/f5104.py
|
def f(k, maxlogL):
aic = 2 * (k - maxlogL)
return aic
assert f(1, 1) == 0
|
benchmark_functions_edited/f10327.py
|
def f(AUTOMS_NUM_PROCESSES):
if AUTOMS_NUM_PROCESSES is None:
num_processes_default = 1
else:
num_processes_default = AUTOMS_NUM_PROCESSES
return num_processes_default
assert f(2) == 2
|
benchmark_functions_edited/f3809.py
|
def f(n):
if n is None:
return 0
return 1 + max(f(n.left), f(n.right))
assert f(None) == 0
|
benchmark_functions_edited/f9519.py
|
def f(value, max_value):
value = int(value)
if value > max_value:
raise ValueError("Invalid value number: {} is too big. Max is {}.".format(value, max_value))
else:
return value
assert f(3, 3) == 3
|
benchmark_functions_edited/f8808.py
|
def f(x, a0, a1, a2, a3, a4, a5, a6):
return (
a0
+ a1 * x
+ a2 * (x ** 2)
+ a3 * (x ** 3)
+ a4 * (x ** 4)
+ a5 * (x ** 5)
+ a6 * (x ** 6)
)
assert f(1, 0, 0, 0, 0, 0, 0, 1) == 1
|
benchmark_functions_edited/f14130.py
|
def f(n: int, ind: int, command: str):
# ensure index exists in indices
if 0 <= ind < n:
return ind
else:
raise IndexError(f"Index {ind} does not exist... Run `kaos {command} list` again")
assert f(3, 2, "train") == 2
|
benchmark_functions_edited/f2592.py
|
def f(code):
try : return eval(code, globals())
except: return exec(code, globals())
assert f("2*3") == 6
|
benchmark_functions_edited/f13743.py
|
def f(filters, width_coefficient, depth_divisor):
filters *= width_coefficient
new_filters = int(filters + depth_divisor / 2) // depth_divisor * depth_divisor
new_filters = max(depth_divisor, new_filters)
# Make sure that round down does not go down by more than 10%.
if new_filters < 0.9 * filters:
new_filters += depth_divisor
return int(new_filters)
assert f(4, 1, 2) == 4
|
benchmark_functions_edited/f5564.py
|
def f(val):
if val in [12,1,2]:
return 2 # heating season
elif val in [6,7,8]:
return 0 # cooling season
else:
return 1
assert f(6) == 0
|
benchmark_functions_edited/f3991.py
|
def f(line_num):
if line_num is not None:
return line_num - 1
assert f(10) == 9
|
benchmark_functions_edited/f3823.py
|
def f(m):
i = 0
while i < 2 ** m:
i += 1
return i
assert f(0) == 1
|
benchmark_functions_edited/f5423.py
|
def f(a, b):
d = (a[0]-b[0])**2 + (a[1]-b[1])**2
return d
assert f(
[0, 0],
[0, 1]) == 1
|
benchmark_functions_edited/f7502.py
|
def f(a, b):
comp = zip(a, b)
diff = abs(len(a)-len(b))
m = sum(1 for x,y in comp if x == y)
return m - diff
assert f("abcxyz","abcdef") == 3
|
benchmark_functions_edited/f1667.py
|
def f(gen):
return sum(1 for _ in gen)
assert f(range(10, 20, 3)) == 4
|
benchmark_functions_edited/f2462.py
|
def f(t, duration, Initial, Final):
f = t / duration
return (1 - f) * Initial + f * Final
assert f(1, 1, 0, 1) == 1
|
benchmark_functions_edited/f510.py
|
def f(num):
return 0 if num is None else num
assert f(None) == 0
|
benchmark_functions_edited/f10853.py
|
def f(lst):
count = X_longest_run = 0
for outcome in lst:
if outcome == 'H':
count += 1
else:
count = 0
if count > X_longest_run:
X_longest_run = count
return X_longest_run
assert f(
['H', 'T', 'H', 'H', 'T', 'H', 'H', 'H', 'H', 'T']) == 4
|
benchmark_functions_edited/f13158.py
|
def f(seq, f):
found = None
for i, s in enumerate(seq):
if f(s):
found = i
return found
assert f("abcd", lambda x: x == "d") == 3
|
benchmark_functions_edited/f2572.py
|
def f(price,ltv,loanRatePer):
return price * ltv * loanRatePer/100.
assert f(100., 100., 0) == 0
|
benchmark_functions_edited/f7520.py
|
def f(orient):
if orient + 1 == 4:
return 0
else:
return orient + 1
assert f(0) == 1
|
benchmark_functions_edited/f10870.py
|
def f(input1: list, input2: list):
distance = 0
for i in range(len(input1)-1):
distance += pow(input1[i] - input2[i], 2)
return distance
assert f(
[1, 2, 3, 4],
[1, 2, 3, 4]) == 0
|
benchmark_functions_edited/f4309.py
|
def f(data: str) -> int:
return int(data.replace('$', '').replace(',', ''))
assert f('1$') == 1
|
benchmark_functions_edited/f7256.py
|
def f(f1, f2):
# Ensure f2 is the smallest
if f2 > f1:
f1, f2 = f2, f1
z = 0
while f2:
if f2 & 1:
z ^= f1
f1 <<= 1
f2 >>= 1
return z
assert f(0, 0) == 0
|
benchmark_functions_edited/f11626.py
|
def f(sfe_map, bp_list):
_main_part, penalty_part, sfe_part = bp_list
try:
sfe = sfe_map[sfe_part]
except KeyError:
sfe = sfe_map[penalty_part]
return sfe
assert f(
{'sfe': 1, 'penalty': 2},
['sfe', 'penalty', 'foo']) == 2
|
benchmark_functions_edited/f5732.py
|
def f(token):
if token.isnumeric():
return int(token)
try:
return float(token)
except TypeError:
return token
assert f(**{"token": "1"}) == 1
|
benchmark_functions_edited/f3858.py
|
def f(my_list=[]):
if len(my_list) == 0:
return (None)
my_list.sort()
return (my_list[-1])
assert f([1, 2, 3, 4]) == 4
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.