file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f12434.py | def f(arr, left, right, item):
if right >= left:
mid = left + (right - left) // 2
if arr[mid] == item:
return mid
if arr[mid] > item:
return f(arr, left, mid - 1, item)
return f(arr, mid + 1, right, item)
return -1
assert f(range(10), 0, 9, 3) == 3 |
benchmark_functions_edited/f12066.py | def f(coord, model_coord_range):
if coord > 360 or coord < -360:
print("** Satellite coordinate outside range -360 - 360 degrees")
return 0
value = min(range(len(model_coord_range)),
key=lambda i: abs(model_coord_range[i] - coord))
return value
assert f(0, (0, 5, 10, 15, 20, 25, 30)) == 0 |
benchmark_functions_edited/f14393.py | def f(player, cond, moves):
for case in cond:
# Player wins
if player & case in cond:
return 0
# Tie
elif len(moves) == 0:
return 1
# Neither
return 2
assert f(1, [1, 2, 4, 8, 16, 32, 64, 128], [0, 3, 5, 6, 9, 10]) == 0 |
benchmark_functions_edited/f5156.py | def f(row, delimiter, line_terminator):
line = delimiter.join(row) + line_terminator
return len(line.encode("utf-8"))
assert f(
["", "", "a"], ",", "\n"
) == 4 |
benchmark_functions_edited/f9165.py | def f(obj):
if isinstance(obj, dict):
return sorted((k, f(v)) for k, v in obj.items())
if isinstance(obj, list):
return sorted(f(x) for x in obj)
else:
return obj
assert f(1) == 1 |
benchmark_functions_edited/f14097.py | def f(indices_size, value_size):
if value_size < 1:
raise ValueError("The value assigned to tensor cannot be empty.")
if value_size > 1:
if value_size != indices_size:
raise ValueError(
"The value given to tensor does not match the index size,"
" value size:{}, indics size:{}".format(value_size, indices_size))
return value_size
assert f(2, 2) == 2 |
benchmark_functions_edited/f4082.py | def f(values):
non_nones = [x for x in values if x is not None]
return sum(non_nones) / len(non_nones)
assert f(
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
) == 1 |
benchmark_functions_edited/f14195.py | def f(clusts1, clusts2):
# sum of square set sizes
dist = sum(len(c)**2 for c in clusts1) + sum(len(c)**2 for c in clusts2) - 2*sum(
len(c1.intersection(c2))**2 for c1 in clusts1 for c2 in clusts2)
return dist
assert f(
[{1, 2}, {3, 4}],
[{3, 4}, {1, 2}]) == 0 |
benchmark_functions_edited/f1199.py | def f(x1, y1, x2, y2):
return (x2 - x1)**2 + (y2 - y1)**2
assert f(0, 0, 1, 1) == 2 |
benchmark_functions_edited/f11167.py | def f(start, stop, step):
assert step != 0
if step > 0:
assert start < stop
dim_size = (stop - start - 1) // step + 1
else:
assert stop < start
dim_size = (start - stop - 1) // (-step) + 1
return dim_size
assert f(0, 10, 15) == 1 |
benchmark_functions_edited/f495.py | def f(b):
return b[1]-b[0]
assert f( (1,10) ) == 9 |
benchmark_functions_edited/f13753.py | def f(array, search_term):
p = 0
r = len(array) - 1
while p <= r:
q = (p + r) // 2
value = array[q]
if value == search_term:
return q
elif value > search_term:
r = q - 1
else: # value < search_term
p = q + 1
return None
assert f(
[1, 3, 5, 7, 9], 7
) == 3 |
benchmark_functions_edited/f11355.py | def f(name_index, color_arr):
if name_index > len(color_arr):
color_index = name_index % len(color_arr)
else:
color_index = name_index
return color_index
assert f(2, ['red', 'blue', 'yellow']) == 2 |
benchmark_functions_edited/f5871.py | def f(iterable, condition=lambda x: True):
return next((x for x in iterable if condition(x)), None)
assert f(range(10), lambda x: x % 4 == 0) == 0 |
benchmark_functions_edited/f10912.py | def f(array: list) -> int:
overallmin = array[0]
for i in array:
is_smallest = True
for j in array:
if i > j:
is_smallest = False
if is_smallest:
overallmin = i
return overallmin
assert f([1, 2, 3, 4, 5]) == 1 |
benchmark_functions_edited/f5097.py | def f(str, classnames):
for i, id in enumerate(classnames):
if id in str:
return i
return None
assert f(
"Bear, Tiger",
["Dwarf", "Giant", "Owlbear", "Bear", "Tiger"],
) == 3 |
benchmark_functions_edited/f12216.py | def f(elements):
if len(elements)>1:
theMin=min(f(elements[0 : (len(elements)//2)]),\
f(elements[(len(elements)//2) : len(elements)]))
else:
if len(elements)==0: return 0
theMin=min(elements[0])
return theMin
assert f([[1, 2], [3, 4], [5, 6]]) == 1 |
benchmark_functions_edited/f8756.py | def f(x,y):
value_x = int(x.replace('camera_', ''))
value_y = int(y.replace('camera_', ''))
if value_x > value_y:
return 1
elif value_y > value_x:
return -1
else:
return 0
assert f('camera_0', 'camera_00') == 0 |
benchmark_functions_edited/f5058.py | def f(x):
if isinstance(x, tuple):
if x[1] == '__main__':
return 0
return x[1]
return x
assert f(('from. import _', '__main__')) == 0 |
benchmark_functions_edited/f3303.py | def f(LL):
#M: list[int]
M = []
#N:list[list[int]]
N = [[], M, [1, 2]]
M = LL[0]
N[1].append(1)
return 0
assert f([[1], [2, 3]]) == 0 |
benchmark_functions_edited/f13322.py | def f(dictionary, key, default_value):
if key in dictionary.keys():
return dictionary[key]
else:
return default_value
assert f({}, "key", 0) == 0 |
benchmark_functions_edited/f2875.py | def f(seq):
for num in seq:
if seq.count(num) % 2 != 0:
return num
assert f([5, 9, 2, 8, 7, 8, 1, 2, 3, 4]) == 5 |
benchmark_functions_edited/f13238.py | def f(value_string):
valdict = {"TRUE": 1,
"FALSE": 0,
"YES": 1,
"NO": 0}
return valdict[value_string.upper()]
assert f("FALSE") == 0 |
benchmark_functions_edited/f1041.py | def f(y, x):
return 0.5*(x + y/x)
assert f(4, 2) == 2 |
benchmark_functions_edited/f6250.py | def f(x):
if x > 0:
return 1
elif x == 0:
return 0
else:
return -1
assert f(42) == 1 |
benchmark_functions_edited/f5330.py | def f(inputs,
layers,
):
output = inputs
for layer in layers.values():
output = layer(output)
return output
assert f(1, {'layer1': lambda x: x + 1}) == 2 |
benchmark_functions_edited/f499.py | def f(input):
return 1 / 25400 * input
assert f(25400) == 1 |
benchmark_functions_edited/f6815.py | def f(A, B):
if isinstance(A, dict) and isinstance(B, dict):
return {key:f(value, B[key]) for key, value in A.items()}
else:
return A+B
assert f(1,2) == 3 |
benchmark_functions_edited/f5975.py | def f(filename, binary_data):
with open(filename, 'wb') as file:
file.write(binary_data)
return len(binary_data)
assert f('test.png', b'abc') == 3 |
benchmark_functions_edited/f7681.py | def f(matrix, mean_value):
abs_deviation = 0
for idx in range(len(matrix)):
abs_deviation += (abs(matrix[idx] - mean_value) / len(matrix))
return abs_deviation
assert f([4, 5, 6, 7], 5) == 1 |
benchmark_functions_edited/f7308.py | def f(a: int, b: int) -> int:
return f(b, a % b) if b else a
assert f(2, 4) == 2 |
benchmark_functions_edited/f12846.py | def f(pixel_top, pixel_bottom):
if pixel_top == 2:
return pixel_bottom
return pixel_top
assert f(0, 2) == 0 |
benchmark_functions_edited/f12460.py | def f(hour: int, mins: int, second: int):
hour_to_seconds = hour*60*60
mins_to_seconds = mins*60
return hour_to_seconds+mins_to_seconds+second
assert f(0, 0, 1) == 1 |
benchmark_functions_edited/f12652.py | def f(a, b):
return min(a[1], b[1]) - max(a[0], b[0])
assert f( (5, 10), (5, 15) ) == 5 |
benchmark_functions_edited/f10720.py | def f(str1, str2):
assert(len(str1)==len(str2))
str1 = str1.upper()
str2 = str2.upper()
editDist = 0
for c1, c2 in zip(str1, str2):
if c1!=c2:
editDist +=1
return editDist
assert f( "HAHA", "HAHA") == 0 |
benchmark_functions_edited/f11738.py | def f(pa, pb, pc):
detleft = (pa[0] - pc[0]) * (pb[1] - pc[1])
detright = (pa[1] - pc[1]) * (pb[0] - pc[0])
det = detleft - detright
return det
assert f( (1, 1), (0, 0), (-1, -1) ) == 0 |
benchmark_functions_edited/f10276.py | def f(cube, var):
mll_to_mol = ['po4', 'si', 'no3']
if var in mll_to_mol:
cube.data = cube.data / 1000. # Convert from ml/l to mol/m^3
if var == 'o2':
cube.data = cube.data * 44.661 / 1000. # Convert from ml/l to mol/m^3
return cube
assert f(1, 'var') == 1 |
benchmark_functions_edited/f11201.py | def f(nivel):
prendidas = 0
for fila in nivel:
for numero in fila:
if numero==1:
prendidas += 1
return prendidas
assert f( [[0, 0, 0], [0, 0, 0], [0, 0, 0]] ) == 0 |
benchmark_functions_edited/f1190.py | def f(bs):
return int.f(bs, "big")
assert f(b"\x00\x00\x01") == 1 |
benchmark_functions_edited/f4715.py | def f(n):
return int(n / 2) if n % 2 == 0 else 3*n + 1
assert f(8) == 4 |
benchmark_functions_edited/f7900.py | def f(q1, q2):
return 1.0 - abs(q1[0]*q2[0] + q1[1]*q2[1] + q1[2]*q2[2] + q1[3]*q2[3])
assert f(
(1, 0, 0, 0),
(1, 0, 0, 0)
) == 0 |
benchmark_functions_edited/f1871.py | def f(hour, minute, second):
return hour * 60 * 60 + minute * 60 + second
assert f(0, 0, 0) == 0 |
benchmark_functions_edited/f13513.py | def f(init, fin, step, annealing_steps):
if annealing_steps == 0:
return fin
assert fin > init, 'Final value should be larger than initial'
delta = fin - init
annealed = min(init + delta * step / annealing_steps, fin)
return annealed
assert f(0, 10, 0, 5) == 0 |
benchmark_functions_edited/f4748.py | def f(value, min_, max_):
value = value if value > min_ else min_
return value if value < max_ else max_
assert f(0, 3, 1) == 1 |
benchmark_functions_edited/f5135.py | def f(Xo,Hinf,Cinf,Ninf,Ginf,QH,QC,QN,QG,Nc,decay,mort,Qc,X,dt,Vc):
return(Xo + (-0.1*Xo + (decay+mort)*Nc*(Qc+X))*dt)
assert f(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) == 0 |
benchmark_functions_edited/f11976.py | def f(force, r, theta):
from math import cos, pi
moment = force * r * (1/pi - cos(theta)/2)
return moment
assert f(1000, 0, 0) == 0 |
benchmark_functions_edited/f12385.py | def f(filename, matrices):
f = open(filename, 'w')
if not f:
return 0
for mat in matrices:
for v in mat.flatten():
f.write("%f "%v)
f.write("\n")
f.close()
return 1
assert f('test_saveInstancesMatsToFile.txt', []) == 1 |
benchmark_functions_edited/f6866.py | def f(XA,beta0PNT=0):
return (5)/(9)*(520+beta0PNT)-(2600*XA)/(9)
assert f(1) == 0 |
benchmark_functions_edited/f7544.py | def f(dictionary):
size = len(dictionary.keys())
for value in dictionary.values():
size += len(value)
return size
assert f({1: [2], 3: [4, 5]}) == 5 |
benchmark_functions_edited/f8188.py | def f(obj, i):
if not isinstance(obj, list) or len(obj) == 0:
return obj
elif len(obj) == 1:
return obj[0]
elif len(obj) > i:
return obj[i]
else:
raise IndexError("failed to broadcast")
assert f([1,2], 0) == 1 |
benchmark_functions_edited/f2524.py | def f(vh, vl, r):
i = (vh-vl)/r
return i
assert f(0, 0, 2) == 0 |
benchmark_functions_edited/f2390.py | def f(iterable):
return iterable[0] if len(iterable) == 1 else iterable
assert f((0,)) == 0 |
benchmark_functions_edited/f637.py | def f(user):
return len(user["friends"])
assert f({"name": "Alice", "age": 24, "friends": []}) == 0 |
benchmark_functions_edited/f4414.py | def f(val):
total = 0
for c1, c2 in zip(val, val[1:]):
if c1 == c2:
total += 1
return total
assert f("abcd") == 0 |
benchmark_functions_edited/f10308.py | def f(i, w):
return (1/2) * i * w**2
assert f(100, 0) == 0 |
benchmark_functions_edited/f4361.py | def f(N):
return N[3] + (N[2] << 12) + (N[1] << 24) + (N[0] << 36)
assert f( (0, 0, 0, 0) ) == 0 |
benchmark_functions_edited/f9041.py | def f(dictionary, key):
total = 0
for item in dictionary:
total += item[key]
return total / len(dictionary)
assert f([{"x": 1, "y": 2}, {"x": 3, "y": 4}], "x") == 2 |
benchmark_functions_edited/f8047.py | def f(res, flg, max_x):
test = res[-1][1 if flg == "x" else 0]
if (len(str(test)) if type(test) is str else test) > max_x:
max_x = len(str(test)) if type(test) is str else test
return max_x
assert f(
[
["Name", "Age", "Breed"],
["Kitty", 4, "tabby"],
["Lucy", 7, "golden"],
["Nala", 4, "golden"],
],
"y",
0
) == 4 |
benchmark_functions_edited/f11480.py | def f(a1, a2):
m = a2[0]-a1[0]+1
n = a2[1]-a1[1]+1
return m*n
assert f(
(5, 5),
(5, 5),
) == 1 |
benchmark_functions_edited/f10134.py | def f(equation, val):
r1 = equation(val)
if r1 == None:
return None
if r1 == 0:
return 0
elif r1 != val:
return 1
elif r1 == val:
return -1
assert f(lambda x: x % 4, 8) == 0 |
benchmark_functions_edited/f6808.py | def f(l):
if len(l) == 0:
return 0
elif l[0] != 0:
return 0
else:
return 1 + f(l[1:])
assert f([1, 2, 3]) == 0 |
benchmark_functions_edited/f7160.py | def f(responses, derived):
try:
return float(responses.get('annual_child_care_expenses', 0))
except ValueError:
return 0
assert f(
{'annual_child_care_expenses': 0},
None
) == 0 |
benchmark_functions_edited/f5233.py | def f(num_list):
for i, (a, b) in enumerate(zip(num_list, num_list[1:])):
if a > b:
return i
return 'OK'
assert f([2, 1, 2]) == 0 |
benchmark_functions_edited/f3749.py | def f(_s):
try:
return int(_s.strip())
except ValueError:
return None
assert f('+3') == 3 |
benchmark_functions_edited/f1525.py | def f(n):
if n == 0 or n == 1:
return 1
return n * f(n-1)
assert f(3) == 6 |
benchmark_functions_edited/f4150.py | def f(n):
total = 0
k = 1
while k <= n:
total += pow(k, 3)
k += 1
return total
assert f(1) == 1 |
benchmark_functions_edited/f9430.py | def f(score):
if not score:
return 0
last_event = score[-1]
if last_event.time_delta is None:
return last_event.time
return last_event.time + last_event.time_delta.total_beats()
assert f(None) == 0 |
benchmark_functions_edited/f9664.py | def f(files):
if isinstance(files, list):
return files[0]
else:
return files
assert f([2, 3]) == 2 |
benchmark_functions_edited/f10791.py | def f(res, **options):
aggregate = options.get('aggregate', True)
if not aggregate:
return res
numpat = 0
for node_numpat in res.values():
numpat += node_numpat
return numpat
assert f(
{'127.0.0.1': 2, '127.0.0.2': 3},
) == 5 |
benchmark_functions_edited/f12350.py | def f(l, x):
if len(l) == 0:
return 0
else:
middle = len(l) // 2
l1 = l[:middle]
l2 = l[middle:]
if l[middle] >= x: # Element is in the first half
return f(l1, x)
else: # Element is in the second half
return middle + f(l2, x)
assert f(list(range(10)), 0) == 0 |
benchmark_functions_edited/f4481.py | def f(bin_msg):
assert len(bin_msg) > 0
cksum = 0
for b in bin_msg:
cksum += b
return cksum % 256
assert f(b"\x00") == 0 |
benchmark_functions_edited/f9633.py | def f(x, a, b):
return (x >= a)*(x <= b)
assert f(1, 1, 1) == 1 |
benchmark_functions_edited/f5849.py | def f(kernel_size, dilation, stride):
return ((stride - 1) + dilation * (kernel_size - 1)) // 2
assert f(2, 1, 1) == 0 |
benchmark_functions_edited/f9229.py | def f(d: int, n: int) -> int:
assert n > 0, n
return n * (n - 1) * d // 2
assert f(2, 3) == 6 |
benchmark_functions_edited/f9476.py | def f(ref_l, cand_l):
least_diff = abs(cand_l-ref_l[0])
best = ref_l[0]
for ref in ref_l:
if abs(cand_l-ref) < least_diff:
least_diff = abs(cand_l-ref)
best = ref
return best
assert f([3, 6, 9], 4) == 3 |
benchmark_functions_edited/f6127.py | def f(a, b):
s = 0
for i in range(a, b+1):
if i % 2 == 1:
s += i
else:
continue
return s
assert f(6, 6) == 0 |
benchmark_functions_edited/f6846.py | def f(current_nodes):
new_nodes = current_nodes - 2
if new_nodes < 3: # 3 is minimum number of CBT nodes
return 3
return new_nodes
assert f(11) == 9 |
benchmark_functions_edited/f9402.py | def f(voltage):
pressure = 4 * (voltage - 0.5) / 3
if pressure > 0:
return pressure
else:
return 0
assert f(3.5) == 4 |
benchmark_functions_edited/f5159.py | def f(left: int, right: int) -> int:
return left if left == right else 0
assert f(0, 3) == 0 |
benchmark_functions_edited/f10576.py | def f(rankine: float, ndigits: int = 2) -> float:
return round(rankine * 5 / 9, ndigits)
assert f(0, 0) == 0 |
benchmark_functions_edited/f6425.py | def f(aList, index):
return (index+1) % len(aList)
assert f(list(range(10)), 5) == 6 |
benchmark_functions_edited/f13618.py | def f(status_id, api):
try:
# print("Marking tweet with 'Like'")
api.create_favorite(id=status_id)
error = 0
except Exception: # as e:
# print(e)
# print("Marking tweet failed!")
error = 1
return error
assert f(12345, "12345") == 1 |
benchmark_functions_edited/f11994.py | def f(values):
generator = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3]
chk = 1
for value in values:
top = chk >> 25
chk = (chk & 0x1ffffff) << 5 ^ value
for i in range(5):
chk ^= generator[i] if ((top >> i) & 1) else 0
return chk
assert f([]) == 1 |
benchmark_functions_edited/f453.py | def f(x, a, b, c):
return a * x + b * x ** 2 + c
assert f(0, 0, 1, 2) == 2 |
benchmark_functions_edited/f10933.py | def f(request_params):
raw = request_params.get('ixp')
if raw is not None:
return int(raw)
else:
return raw
assert f({'ixp': 1}) == 1 |
benchmark_functions_edited/f4344.py | def f(message):
checksum = sum(ord(ch) for ch in message)
return checksum % 256
assert f(b"") == 0 |
benchmark_functions_edited/f8638.py | def f(accounts: int, account_idx: int, deploys: int) -> int:
if accounts == 0:
return 1
q, r = divmod(deploys, accounts)
return q + (1 if account_idx <= r else 0)
assert f(4, 2, 3) == 1 |
benchmark_functions_edited/f7020.py | def f(obj1, obj2):
return max(map(lambda obj: obj[0] - obj[1], zip(obj1, obj2)))
assert f(tuple(range(5)), tuple(range(5))) == 0 |
benchmark_functions_edited/f7050.py | def f(feet: float) -> float:
if not isinstance(feet, (float, int)):
return 0
return feet / 3.28084
assert f(0) == 0 |
benchmark_functions_edited/f9183.py | def f(string: str) -> int:
summation = 0
half = len(string) / 2
for i, char in enumerate(string):
if char == string[int((i + half) % len(string))]:
summation += int(char)
return summation
assert f(
'1234') == 0 |
benchmark_functions_edited/f1008.py | def f(images):
return images / 127.5 - 1
assert f(255) == 1 |
benchmark_functions_edited/f1746.py | def f(x: float) -> float:
return x if x >= 0 else 0
assert f(1) == 1 |
benchmark_functions_edited/f3521.py | def f(x, y):
return x / (x**2 + y**2)
assert f(0, 3) == 0 |
benchmark_functions_edited/f1720.py | def f(value):
if value & 0x4:
return 0xfffffff8 | value
return value
assert f(1) == 1 |
benchmark_functions_edited/f1772.py | def f(n):
answer = 0
s = str(n)
for c in s:
answer += int(c)
return answer
assert f(10) == 1 |
benchmark_functions_edited/f1721.py | def f(l):
if "%" in str(l):
return 1
else:
return 0
assert f(1) == 0 |
benchmark_functions_edited/f11873.py | def f(n, ranks):
for r in ranks:
if ranks.count(r) == n:
return r
return None
assert f(3, [1, 3, 3, 3, 5]) == 3 |
benchmark_functions_edited/f13920.py | def f(a, n):
if n == 1:
raise ValueError('The modulo cannot be equal to 1')
m_ord = 1
value = a % n
while value != 1 and m_ord < n:
value = (value * a) % n
m_ord += 1
if m_ord < n:
return m_ord
raise ValueError(f'The given integer arguments are not relative primes: {a} and {n}')
assert f(3, 4) == 2 |
benchmark_functions_edited/f7289.py | def f(a, b):
if a % 2 == 0:
return a + b % 2
else:
return a - (b+1) % 2
assert f(4, 2) == 4 |
benchmark_functions_edited/f14196.py | def f(alpha):
assert isinstance(alpha, str) and alpha
from string import ascii_lowercase
index = -1
steps = [(x, y) for x, y in enumerate(alpha[::-1])]
for step, letter in steps[::-1]:
letter_index = ascii_lowercase.index(letter)
index += (letter_index+1)*(26**step)
return index
assert f('c') == 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.