file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f5128.py | def f(strings):
longest = 0
for string in strings:
if len(string) > longest:
longest = len(string)
return longest
assert f(['a', '', 'b']) == 1 |
benchmark_functions_edited/f8667.py | def f(stroke_count, modes):
dist = float('inf')
for mode in modes:
dist = min(dist, abs(mode - stroke_count))
return dist
assert f(1, [5, 10, 15]) == 4 |
benchmark_functions_edited/f12361.py | def f(arr: list, left: int, right: int, key: int) -> int:
if right >= left:
mid = left + (right - left) // 2
if arr[mid] == key:
return mid
if arr[mid] > key:
return f(arr, left, mid - 1, key)
else:
return f(arr, mid + 1, right, key)
return -1
... |
benchmark_functions_edited/f7554.py | def f(v,alpha,_lambda,beta):
if v>=0:
return v**alpha
else:
return -_lambda*(-v)**beta
assert f(1, 0, 1, 1) == 1 |
benchmark_functions_edited/f3042.py | def aec_value (val=None):
global _aec_value
if val is not None:
_aec_value = val
return _aec_value
assert f(4) == 4 |
benchmark_functions_edited/f10695.py | def f(string, search_val, offset = 0):
try:
return string[offset:].index(search_val) + offset
except ValueError:
return False
assert f(u"abcd", u"a", 0) == 0 |
benchmark_functions_edited/f2342.py | def f(l):
if ".php" in str(l):
return 1
else:
return 0
assert f(list('foo.txt')) == 0 |
benchmark_functions_edited/f1717.py | def bpc (val=None):
global _bpc
if val is not None:
_bpc = val
return _bpc
assert f(False) == 0 |
benchmark_functions_edited/f11267.py | def f(nums):
for i in range(0, len(nums), 2):
try:
if nums[i] != nums[i + 1]:
return nums[i]
# Consider the condition that the single num is the last one
except IndexError:
return nums[i]
assert f(list(range(1, 4))) == 1 |
benchmark_functions_edited/f11576.py | def f(increasing_list, value):
left = 0
right = len(increasing_list) - 2
while left < right:
pivot = (left + right) // 2
if increasing_list[pivot + 1] >= value:
right = pivot
else:
left = pivot + 1
return left
assert f(range(10), 0) == 0 |
benchmark_functions_edited/f3731.py | def f(a):
a = (a + 180) % 180
if a > 90:
a = a - 180
return a
assert f(0) == 0 |
benchmark_functions_edited/f11926.py | def f(a):
return next(iter(a))
assert f(range(1)) == 0 |
benchmark_functions_edited/f8051.py | def f(count, total): #-------------------------------------------------<<<
if not count or not total:
return 0
return 100 * float(count) / float(total)
assert f(2, 0) == 0 |
benchmark_functions_edited/f13378.py | def f(arr, n):
l = 0
r = n-1
res = 0
while l < r:
if arr[l] == arr[r]:
l+=1
r-=1
elif arr[l] > arr[r]:
r-=1
arr[r] += arr[r+1]
res+=1
else:
l+=1
arr[l] += arr[l-1]
res+=1
ret... |
benchmark_functions_edited/f4346.py | def f(val, base, length, new):
return (val ^ (val & ((2 ** length - 1) << base))) + (new << base)
assert f(0b0000000000000000, 0, 4, 3) == 3 |
benchmark_functions_edited/f1929.py | def f(range_1, range_2):
return min(range_1[1], range_2[1]) - max(range_1[0], range_2[0])
assert f(range(3), range(2)) == 1 |
benchmark_functions_edited/f4684.py | def f(percent_pos, max_steps):
return round((1 - percent_pos) * max_steps)
assert f(1, 100) == 0 |
benchmark_functions_edited/f13828.py | def f(x, d, div, upperbound, lowerbound=-float("inf"), precision=1e-6):
l = max(x, lowerbound)
u = upperbound
while u - l > precision:
m = (l + u) / 2
if div(x, m) > d:
u = m
else:
l = m
return (l + u) / 2
assert f(1, 1, lambda x, y: abs(x-y), 1) == 1 |
benchmark_functions_edited/f5911.py | def f(sym):
return {'H': 1, 'HE': 0,
'C': 4,
'N': 3,
'O': 2, 'S': 2,
'F': 1, 'CL': 1,
'NE': 0, 'AR': 0}[sym.upper()]
assert f('ar') == 0 |
benchmark_functions_edited/f11894.py | def f(numbers: list) -> int:
count = 0
for i, number in enumerate(numbers[:-1]):
for compare in numbers[i+1:]:
if number > compare:
count += 1
return count
assert f([12, 13, 14, 15, 16]) == 0 |
benchmark_functions_edited/f13775.py | def f(degree_root, index_left, index_right, degree_left,
degree_right):
if index_left == -1:
degree_now = degree_right
elif index_right == -1:
degree_now = degree_left
elif (abs(degree_left - degree_root) < abs(degree_right - degree_root)):
degree_now = degree_left
... |
benchmark_functions_edited/f8134.py | def f(list_input):
biggest_element = max(list_input)
idx_max = list_input.index(biggest_element)
return idx_max
assert f([0, 0]) == 0 |
benchmark_functions_edited/f9679.py | def f(n_workers, len_iterable, factor=8):
chunksize, extra = divmod(len_iterable, n_workers * factor)
if extra:
chunksize += 1
return chunksize
assert f(1, 2) == 1 |
benchmark_functions_edited/f3020.py | def f(obj, key=0, default=None):
try:
return obj[key]
except:
return default
assert f(tuple([1,2,3])) == 1 |
benchmark_functions_edited/f6661.py | def f(v1, v2):
return (v1 * v2.conjugate()).real
assert f(2, 3) == 6 |
benchmark_functions_edited/f10728.py | def f(number: float) -> int:
if abs(round(number) - number) == 0.5:
return int(2.0 * round(number / 2.0))
return int(round(number))
assert f(0.4999999999999999) == 0 |
benchmark_functions_edited/f5737.py | def f(objective_field):
if isinstance(objective_field, list):
return objective_field[0]
return objective_field
assert f(5) == 5 |
benchmark_functions_edited/f7759.py | def f(x):
x_max = 2 ** 31 - 1
x_min = -x_max
if 0 <= x < x_max:
x = str(x)
x = x[::-1]
y = int(x)
elif x_min < x < 0:
y = -f(abs(x))
else:
y = 0
if x_min < y < x_max:
return y
else:
return 0
assert f(1563847412) == 0 |
benchmark_functions_edited/f2739.py | def f(i):
if 0x80000000 & i:
return int((0xFFFFFFFF & i))
return i
assert f(1) == 1 |
benchmark_functions_edited/f6426.py | def f(x):
x = x + 1
def h(y):
return x + y
return h(6)
assert f(1) == 8 |
benchmark_functions_edited/f2471.py | def f(row):
row.sort()
top1 = row[-1]
top2 = row[-2]
return(top1-top2)
assert f(
[1, 3, 2, 4]
) == 1 |
benchmark_functions_edited/f11728.py | def f(lst: list) -> int:
if not lst:
return 0
curr, res = 0, lst[0]
for i in lst:
if curr <= 0:
curr = i
else:
curr += i
if curr > res:
res = curr
return res
assert f(
[]) == 0 |
benchmark_functions_edited/f3614.py | def f(number):
if number < 2:
return 1
else:
return f(number - 1) + f(number - 2)
assert f(4) == 5 |
benchmark_functions_edited/f8852.py | def f(dictionary, key):
values = []
for item in dictionary:
values.append(item[key])
return max(values)
assert f(
[{'a': 2, 'b': 1}, {'a': 3, 'b': 1}],
'a'
) == 3 |
benchmark_functions_edited/f3427.py | def f(plan):
if plan is None:
return float('inf')
else:
return len(plan)
assert f('plan1') == 5 |
benchmark_functions_edited/f8370.py | def f(data, i, j):
l = 0
try:
while l < 255+9 and data[i+l] == data[j+l]:
l += 1
except IndexError:
pass # terminates
return l
assert f(b"ABCDEFG", 0, -2) == 0 |
benchmark_functions_edited/f805.py | def f(a, b):
return (a ** 2 + b ** 2) ** (1 / 2)
assert f(-1, 0) == 1 |
benchmark_functions_edited/f4112.py | def f(src_ext, dst_ext):
if not src_ext == dst_ext:
return 1
return 0
assert f(2, 3) == 1 |
benchmark_functions_edited/f190.py | def f(a, b):
if a:
return a
return b
assert f(1, 2) == 1 |
benchmark_functions_edited/f5230.py | def f(e):
try:
return e.errno
except AttributeError:
return e.args[0]
assert f(OSError(2, "Permission denied")) == 2 |
benchmark_functions_edited/f2176.py | def f(groups):
return sum([x * y for x, y in zip(groups.keys(), groups.values())])
assert f(dict([(1, 2)])) == 2 |
benchmark_functions_edited/f10812.py | def f(M, N):
return N - M + 1
assert f(1, 3) == 3 |
benchmark_functions_edited/f9732.py | def f(n,r):
if (n < r):
return 0
if (n == r):
return 1
s = min(r, (n - r))
t = n
a = n-1
b = 2
while b <= s:
t = (t*a)//b
a -= 1
b += 1
return t
assert f(2, 1) == 2 |
benchmark_functions_edited/f4347.py | def f(vallist):
r = len(vallist)
A = 0
if r > 0:
for B in vallist:
A += (1.0/r) * B
return A
assert f([1,2,3,4,5]) == 3 |
benchmark_functions_edited/f6699.py | def f(line):
for i in range(len(line)):
if line[i] != "\t":
return i # i characters were "\t" before lines[i]
return None
assert f("\t ") == 1 |
benchmark_functions_edited/f10261.py | def f(n, k):
product = 1
for i in range(n - k + 1, n + 1):
product *= i
return product
assert f(3, 1) == 3 |
benchmark_functions_edited/f11476.py | def f(a, n, b):
# mod b
assert not (b == 0), "This cannot accept modulo that is == 0"
if n == 0:
return 1
if n % 2 == 1:
return (f(a, n - 1, b) * a) % b
r = f(a, n / 2, b)
return (r * r) % b
assert f(2, 2, 5) == 4 |
benchmark_functions_edited/f9807.py | def f(i, j):
if i == j:
return 1
else:
return 0
assert f(1, 3) == 0 |
benchmark_functions_edited/f10681.py | def f(n, digit):
if n ==0:
return 0
if n % 10 == digit :
return f(n//10,digit) + 1
else:
return f(n//10,digit)
assert f(55055, 5) == 4 |
benchmark_functions_edited/f7666.py | def f(*args: int) -> int:
value = 1
for i in args:
value *= i
return value
assert f(1, 2, 3) == 6 |
benchmark_functions_edited/f13458.py | def f(dataset, geneid, colors):
colorsDict = colors
try:
colorVal = colorsDict[dataset][4:-1].split(',')[1]
return int(colorVal)
except KeyError:
return 0
assert f('BL110', 'None', {}) == 0 |
benchmark_functions_edited/f6807.py | def f(meters: float) -> float:
if not isinstance(meters, (float, int)):
return 0
return meters * 3.28084
assert f(0) == 0 |
benchmark_functions_edited/f5755.py | def f(v, threshold=0, act_value=1, inact_value=0):
return act_value if v > threshold else inact_value
assert f(2) == 1 |
benchmark_functions_edited/f6727.py | def f(a,b):
check={}
check['(']=1
check['*']=2
check['/']=2
check['-']=3
check['+']=3
if check[a] <= check[b]:
return 1
else:
return 0
assert f('+','-')==1 |
benchmark_functions_edited/f2539.py | def f(X):
y = 1
for x in X:
y *= x
return y
assert f([1, 2, 3]) == 6 |
benchmark_functions_edited/f9279.py | def f(binary_data):
if not isinstance(binary_data, bytes):
raise TypeError("expected bytes, got %s" % type(binary_data))
return len(binary_data)
assert f(b"abcdef") == 6 |
benchmark_functions_edited/f12928.py | def f(number: int, exp: int, result: int = 1) -> int:
if exp < 1:
return result
else:
return f(number, exp - 1, result * number)
assert f(1, 100) == 1 |
benchmark_functions_edited/f6443.py | def f(g, delta):
tmp1 = 2*g
g2 = g.real**2 + g.imag**2
tmp2 = g2 + 1 + delta**2
return tmp1/tmp2
assert f(0, 0.5) == 0 |
benchmark_functions_edited/f11208.py | def f(y_true, y_pred):
# intialize the counter
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,1,1], [1,0,0,1,1]) == 2 |
benchmark_functions_edited/f5951.py | def f(seq):
n = len(seq)
return int(n * (n-1)/2)
assert f(list(range(4))) == 6 |
benchmark_functions_edited/f9883.py | def f(value, target):
if target:
out = value | target
else:
out = value >> 1 << 1
return out
assert f(0, 0) == 0 |
benchmark_functions_edited/f11056.py | def f(c, correction={'1': 100, '2': 70, '3': 53, '4': 40, '5': 31,
'6': 23, '7': 16, '8': 10, '9': 5}):
if c <= 0:
raise ValueError('The argument to _log10_lb should be nonnegative.')
str_c = str(c)
return 100 * len(str_c) - correction[str_c[0]]
assert f(1) == 0 |
benchmark_functions_edited/f12955.py | def f(g, s):
if not g or not s:
return 0
g = sorted(g)
s = sorted(s)
gidx = 0
sidx = 0
count = 0
while gidx < len(g) and sidx < len(s):
if g[gidx] <= s[sidx]:
count += 1
gidx += 1
sidx += 1
else:
sidx += 1
return c... |
benchmark_functions_edited/f3878.py | def f(strings):
try:
result = int(strings)
except ValueError:
result = float(strings)
return result
assert f('4') == 4 |
benchmark_functions_edited/f9295.py | def f(high, low, level, open, close):
if high > level and low < level:
if open >= close:
return -1
else:
return 1
else:
return 0
assert f(2, 1, 2, 1, 2) == 0 |
benchmark_functions_edited/f3031.py | def f(x,y,z):
return min(min(x,y),z)
assert f(3, 2, 1) == 1 |
benchmark_functions_edited/f9634.py | def f(word, letter, start):
index = start
while index < len(word):
if word[index] == letter:
return index
index = index + 1
return -1
assert f( "banana", "a", 5 ) == 5 |
benchmark_functions_edited/f1007.py | def f(number):
number_added = number + 1
return number_added
assert f(2) == 3 |
benchmark_functions_edited/f10046.py | def f(x1, y2, x2, y1):
res = (x1 - x2) * (y1 - y2)
return res
assert f(1, 1, 1, 0) == 0 |
benchmark_functions_edited/f6471.py | def f(v1, v2):
diff = v2 - v1
if diff < 0:
diff += (1<<16)
return diff
assert f(1, 2) == 1 |
benchmark_functions_edited/f1023.py | def f(data):
return max(data) - min(data)
assert f(list(range(10))) == 9 |
benchmark_functions_edited/f3441.py | def f(x: float, x_min: float, x_max: float) -> float:
return (x - x_min) / (x_max - x_min)
assert f(1, 0, 1) == 1 |
benchmark_functions_edited/f12276.py | def f(params, modes, values, current, puzzle_input):
if values[0] == 0:
if modes[1] == 0:
current = puzzle_input[params[1]]
elif modes[1] == 1:
current = params[1]
return current
assert f(1, 0, [1], 0, 1) == 0 |
benchmark_functions_edited/f1926.py | def f(c) -> int:
return c(lambda x: x + 1)(0)
assert f(lambda f: lambda x: x + 1) == 1 |
benchmark_functions_edited/f12176.py | def f(wavelength, median_z):
wavelength_red = wavelength * (1 + median_z)
return wavelength_red
assert f(1, 0) == 1 |
benchmark_functions_edited/f5393.py | def f(value, alignment=8):
if value % alignment:
return alignment - (value % alignment)
return 0
assert f(4, 2) == 0 |
benchmark_functions_edited/f13416.py | def f(sequence, test_func = None):
for item in sequence:
if test_func:
if not test_func(item):
return 0
elif not item:
return 0
return 1
assert f( (1, 2, 0) ) == 0 |
benchmark_functions_edited/f11202.py | def f(epoch: int, n_batches: int, batch_index: int) -> int:
return (epoch - 1) * n_batches + (1 + batch_index)
assert f(2, 3, 2) == 6 |
benchmark_functions_edited/f9728.py | def f(move):
try:
move = int(move)
assert move in [1, 2, 3, 4, 5, 6]
except (ValueError, AssertionError):
raise ValueError("Choose a value in [1-6]. Please try again.")
return move
assert f(4) == 4 |
benchmark_functions_edited/f11427.py | def f(n_days: int, weight1: int, weight2: int) -> int:
return max(weight1, weight2) * ((n_days + 1) // 2) + \
min(weight1, weight2) * (n_days // 2)
assert f(1, 2, 1) == 2 |
benchmark_functions_edited/f7780.py | def f(set1, set2):
size_intersection = float(len(set1.intersection(set2)))
size_smaller_set = min(float(len(set1)), float(len(set2)))
return size_intersection / size_smaller_set
assert f(set([1, 2, 3]), set([1, 2, 3])) == 1 |
benchmark_functions_edited/f2590.py | def f(a, b):
if b == 0:
raise ValueError("Zero division Error!")
return a * 1.0 / b
assert f(4, 2) == 2 |
benchmark_functions_edited/f8283.py | def f(*args):
try:
return next((arg for arg in args if arg is not None))
except StopIteration:
return None
assert f(1, None) == 1 |
benchmark_functions_edited/f2966.py | def f(poisson, young):
result = ((1+poisson)*(1-2*poisson))/(young*(1-poisson))
return result
assert f(0, 1.0) == 1 |
benchmark_functions_edited/f2402.py | def f(b, h):
area = b * h / 2
return area
assert f(3, 4) == 6 |
benchmark_functions_edited/f6592.py | def f(copy_function, obj):
obj_copy = copy_function(obj)
return obj == obj_copy and obj is not obj_copy
assert f(int, 0) == 0 |
benchmark_functions_edited/f5811.py | def f(a, b):
if a >= 0:
return a >> b
else:
return ((a + 2 ** 64) >> b)
assert f(3, 5) == 0 |
benchmark_functions_edited/f7857.py | def f(a,b,c):
d = (c[1]-a[1])*(b[0]-a[0]) - (b[1]-a[1])*(c[0]-a[0])
return 1 if d > 0 else (-1 if d < 0 else 0)
assert f( (1,1), (0,1), (2,0) ) == 1 |
benchmark_functions_edited/f7958.py | def f(callee, returnee):
callee()
return returnee
assert f(lambda: None, 2) == 2 |
benchmark_functions_edited/f12002.py | def f(args, size, partSize, zeros=False):
while True:
if size < partSize:
if True == zeros:
args.output.write(b'\x00')
else:
args.output.write(b'\xFF')
size += 1
else:
break # while loop
return size
assert f(None,... |
benchmark_functions_edited/f10525.py | def f(parser, arg):
valid_severities = {"info": 0, "warning": 1, "error": 2}
if arg.strip().lower() not in valid_severities:
parser.error("Invalid severity. Options are error, warning, or info")
else:
return valid_severities[arg.strip().lower()]
assert f(None, "error") == 2 |
benchmark_functions_edited/f1159.py | def f(version):
# XXX finish!
return version
assert f(1) == 1 |
benchmark_functions_edited/f1452.py | def f(x):
return 3*x**2 - 1
assert f(-1) == 2 |
benchmark_functions_edited/f7676.py | def f(x):
if x < 0:
return -x
elif x == 0:
return 0
else:
return x
assert f(-3) == 3 |
benchmark_functions_edited/f6097.py | def f(graph, nodes):
count = 0
for v1 in nodes:
for v2 in nodes:
if v1 != v2 and v2 not in graph[v1]:
count += 1
return count / 2
assert f(
[
[1, 2],
[0, 2],
[0, 1],
[3]
],
[0, 1, 2, 3]
) == 3 |
benchmark_functions_edited/f4198.py | def f(x, x_min, x_max):
return min(max(x, x_min), x_max)
assert f(-2, 1, 1) == 1 |
benchmark_functions_edited/f13620.py | def f(tree_map, move):
pos_x = 0
pos_y = 0
tree_count = 0
while True:
pos_x += move[0]
pos_x = pos_x % tree_map["max_x"]
pos_y += move[1]
if pos_y >= tree_map["max_y"]:
break
if (pos_x, pos_y) in tree_map:
tree_count += 1
print("for... |
benchmark_functions_edited/f11232.py | def f(value, bit_width=8):
count = 0
for _ in range(bit_width):
if value & (1 << (bit_width - 1)):
return count
count += 1
value <<= 1
return count
assert f(0b00000001) == 7 |
benchmark_functions_edited/f4809.py | def f(listy):
total = 0
for i in listy:
total += i
return total
assert f([]) == 0 |
benchmark_functions_edited/f2651.py | def f(t, start, step):
return (t - start) * step
assert f(1900, 1900, 365) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.