file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f332.py | def f(x1, y1, x2, y2):
return (y2-y1)/(x2-x1)
assert f(1, 100, 100, 100) == 0 |
benchmark_functions_edited/f12258.py | def f(oneword,t):
head = 0
tail = len(t)-1
while head <= tail:
if oneword > t[(head + tail)/2]:
head = (head + tail)/2+1
elif oneword < t[(head + tail)/2]:
tail = (head + tail)/2-1
else:
#print (head + tail)/2
return (head + tail)/2
... |
benchmark_functions_edited/f6177.py | def f(value):
output = 0
while value > 0:
value >>= 1
output += 1
return output
assert f(0x0) == 0 |
benchmark_functions_edited/f9769.py | def f(int_type, offset, value):
if value == 1:
mask = 1 << offset
return(int_type | mask)
if value == 0:
mask = ~(1 << offset)
return(int_type & mask)
assert f(1, 0, 1) == 1 |
benchmark_functions_edited/f799.py | def f(mask):
return bin(mask).count("1")
assert f(0b10101100) == 4 |
benchmark_functions_edited/f5258.py | def f(distancia):
numero = (distancia - 5) % 8
if numero in [1, 2, 3]:
return numero
else:
return None
assert f(40) == 3 |
benchmark_functions_edited/f11521.py | def f(from_x, from_y, to_x, to_y):
# return abs(from_x - to_x) + abs(from_y - to_y) # manhattan
return ((from_x - to_x) ** 2 + (from_y - to_y) ** 2) ** 0.5
assert f(0, 0, 0, 0) == 0 |
benchmark_functions_edited/f10767.py | def f(n):
res = [0, 1]
for i in range(n-1):
res.append(res[i] + res[i+1])
return res[n]
assert f(5) == 5 |
benchmark_functions_edited/f8908.py | def f(inputList):
assert(len(inputList) > 0)
index = 0
minVal = inputList[0]
for i, val in enumerate(inputList[1:]):
if val < minVal:
minVal = val
index = i + 1
return index
assert f( [100000] ) == 0 |
benchmark_functions_edited/f12311.py | def f(x, y):
assert isinstance(x, (int, float)), 'x needs to be an integer or float'
assert isinstance(y, (int, float)), 'y needs to be an integer or float'
return x - y
assert f(10, 5) == 5 |
benchmark_functions_edited/f10302.py | def f(a_dictionary):
win_n = 0
winner = None
if type(a_dictionary) is dict:
for (key, value) in a_dictionary.items():
if value > win_n:
win_n = value
winner = key
return winner
assert f(dict(zip(range(1, 6), range(1, 6, 2)))) == 3 |
benchmark_functions_edited/f11376.py | def f(record):
if record['ds_max_flo'] and not record['ds_max_flo'] == 'None':
if float(record['ds_max_flo']) > 300:
return 1
if float(record['ds_max_flo']) > 100:
return 2
if float(record['ds_max_flo']) > 10:
return 3
return 4
assert f(
{'ds_max_... |
benchmark_functions_edited/f10938.py | def f(target):
steps = 0
while target != 0:
steps += 1
if target % 2 == 1:
target -= 1
else:
target /= 2
return steps
assert f(0) == 0 |
benchmark_functions_edited/f2562.py | def f(gpus):
gpus = [gpus] if isinstance(gpus, int) else list(gpus)
return len(gpus)
assert f([0, 1]) == 2 |
benchmark_functions_edited/f7730.py | def f(last, unvisited, D):
near = unvisited[0]
min_dist = D[last, near]
for i in unvisited[1:]:
if D[last,i] < min_dist:
near = i
min_dist = D[last, near]
return near
assert f(0, (1, 2), {(0, 1): 0.5, (0, 2): 1.0, (1, 2): 10}) == 1 |
benchmark_functions_edited/f8698.py | def f(string, substring, n):
location = string.index(substring)
while n > 1:
location = string.index(substring, location+len(substring))
n -= 1
return location
assert f(
"123123123",
"23",
1) == 1 |
benchmark_functions_edited/f13496.py | def f(uP, gam):
return uP ** (-1.0 / gam)
assert f(1, 1) == 1 |
benchmark_functions_edited/f11422.py | def f(alist: list, b: int) -> int:
p = 0
ret = 0
for n in alist[::-1]:
ret += n * b ** p
p += 1
return ret
assert f( [0, 0, 0, 0, 0], 3 ) == 0 |
benchmark_functions_edited/f13109.py | def f(list_, value):
found = None
for index, val in enumerate(list_):
if val == value:
found = index
if found is None:
raise ValueError("{} is not in list {}".format(value, list_))
return found
assert f(list("hello"), "e") == 1 |
benchmark_functions_edited/f5146.py | def f(x: float) -> int:
if isinstance(x, str):
x = float(x)
if x is None:
return 0
else:
return int(x)
assert f('0') == 0 |
benchmark_functions_edited/f7290.py | def f(x: str) -> int:
return int(x, 2)
assert f('0111') == 7 |
benchmark_functions_edited/f13607.py | def f(u, v, O):
if u[1] > v[1]:
return -1
if u[1] == v[1]:
#if u[0] == v[0]:
# return 0
if O(u[0]) < O(v[0]):
return -1
return 1
assert f( (1,1), (0,2), lambda x: -x ) == 1 |
benchmark_functions_edited/f21.py | def f(v):
return v/abs(v)
assert f(3) == 1 |
benchmark_functions_edited/f13511.py | def f(array, element, low):
if array[low]==element:
return low
if low==len(array)-1:
return None
return f(array, element, low+1)
assert f(range(10), 2, 0) == 2 |
benchmark_functions_edited/f10868.py | def f(seq):
counter = {}
for item in seq:
if item in counter:
counter[item] += 1
else:
counter[item] = 1
for item in counter:
if counter[item] % 2 != 0:
return item
assert f(
[20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5]
) == 5 |
benchmark_functions_edited/f13563.py | def f(obj: dict, key1: str, key2: str, default_value=None):
if key1 in obj and obj[key1] is not None:
return obj[key1]
else:
if key2 in obj and obj[key2] is not None:
return obj[key2]
return default_value
assert f(
{"key1": 1, "key2": 2, "key3": 3}, "key1", "key4", 0
) == 1 |
benchmark_functions_edited/f412.py | def f(f, *args, **kwargs):
return f(*args, **kwargs)
assert f(lambda a=1, b=2: a+b, 1) == 3 |
benchmark_functions_edited/f3753.py | def f(a, b):
if (b == 0):
return a
else:
return f(b, a % b)
assert f(123, 23) == 1 |
benchmark_functions_edited/f1151.py | def f(data):
return sum(data) / len(data)
assert f([1, 3, 5, 7, 9]) == 5 |
benchmark_functions_edited/f13201.py | def f(a, x, lo=0, hi=None, getter=0):
if lo < 0:
raise ValueError("lo must be non-negative")
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo + hi) // 2
if a[mid][getter] < x:
lo = mid + 1
else:
hi = mid
return lo
assert f([(1, 'a')], 2... |
benchmark_functions_edited/f7986.py | def f(X, A, B):
return A * X + B
assert f(1, 2, 1) == 3 |
benchmark_functions_edited/f7028.py | def f(string: str) -> int:
return len(string) - len(string.lstrip(" "))
assert f(
" hello \tworld"
) == 2 |
benchmark_functions_edited/f6578.py | def f(w,rho):
return w/(2+rho)
assert f(0, 1) == 0 |
benchmark_functions_edited/f6075.py | def f(list):
return sum(list) / float(len(list))
assert f(list([1])) == 1 |
benchmark_functions_edited/f7138.py | def f(c):
if len(c) == 2: # pragma: no cover
high, low = [ord(p) for p in c]
ordinal = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000
else:
ordinal = ord(c)
return ordinal
assert f(u'\u0000') == 0 |
benchmark_functions_edited/f2843.py | def f(x0, y0, x1, y1):
return (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)
assert f(3, 4, 3, 4) == 0 |
benchmark_functions_edited/f4965.py | def f(data):
n = len(data)
try:
return [float(sum(l))/len(l) for l in zip(*data)]
except TypeError:
return sum(data)/n
assert f([1]) == 1 |
benchmark_functions_edited/f564.py | def f(d, i):
return (i-1)//d
assert f(5, 12) == 2 |
benchmark_functions_edited/f14028.py | def f(data):
from math import log as ln
def p(n, N):
if n is 0:
return 0
else:
return (float(n)/N) * ln(float(n)/N)
N = sum(data.values())
return -sum(p(n, N) for n in data.values() if n is not 0)
assert f( {'a': 100, 'b': 0} ) == 0 |
benchmark_functions_edited/f4283.py | def f(number):
sum_value = 0
for item in str(number):
sum_value += int(item)
return sum_value
assert f(123) == 6 |
benchmark_functions_edited/f5704.py | def f(collection):
sum_of_collections = 0
for numbers in collection:
sum_of_collections += numbers
return sum_of_collections
assert f([1, 2, 3]) == 6 |
benchmark_functions_edited/f1638.py | def f(a, b):
j = a & b
q = j | b
m = a ^ q
return m
assert f(6, 7) == 1 |
benchmark_functions_edited/f7132.py | def f(a,b):
while b:
a, b = b, a%b
return a
assert f(3, 3) == 3 |
benchmark_functions_edited/f3424.py | def f(an_object):
return len(an_object) if hasattr(an_object, "__len__") else 0
assert f(set()) == 0 |
benchmark_functions_edited/f4862.py | def f(data, ops=None):
if ops is None:
ops = []
for op in ops:
data = op(data)
if data is None:
return None
return data
assert f(1, [lambda x: x + 1, lambda x: x if x > 0 else None]) == 2 |
benchmark_functions_edited/f14073.py | def f(n, steps):
if n == 0:
return 1
nums = [0] * (n + 1)
nums[0] = 1
for i in range(1, n + 1):
total = 0
for j in steps:
if i - j >= 0:
total += nums[i - j]
nums[i] = total
return nums[n]
assert f(2, {1, 2}) == 2 |
benchmark_functions_edited/f6802.py | def f(a, h):
print("Value of a:", a)
print("Value of h:", h)
return a+h
assert f(2, 3) == 5 |
benchmark_functions_edited/f3396.py | def f(x):
return x*(1.0-x)
assert f(1) == 0 |
benchmark_functions_edited/f4063.py | def f(a, b):
m = min(a, b)
for i in range(m, 0, -1):
if a % i == 0 and b % i == 0:
return i
return 1
assert f(11, 1) == 1 |
benchmark_functions_edited/f268.py | def f(zo):
return (-1)**zo
assert f(12) == 1 |
benchmark_functions_edited/f4006.py | def f(ri, rj):
return sum([min(a, b) for a, b in zip(ri["color_hist"], rj["color_hist"])])
assert f(
{"color_hist": [1, 1, 1, 1, 1, 1]}, {"color_hist": [1, 1, 1, 1, 1, 1]}
) == 6 |
benchmark_functions_edited/f8074.py | def f(array, item):
# loop over all array values until item is found
for index, value in enumerate(array):
if item == value:
return index # found
return None
assert f(list(range(100)), 0) == 0 |
benchmark_functions_edited/f5805.py | def f(device):
if 'level' in device:
level = int((int(device['level']) / 100) * 255)
return level
else:
return 0
assert f(
{'level': 0, 'brightness': 25}) == 0 |
benchmark_functions_edited/f5688.py | def f(field):
if field in ('bm', 'bg', 'bs'):
return 0
else:
return None
assert f('bs') == 0 |
benchmark_functions_edited/f5134.py | def f(val):
if val == 1:
return True
elif val == 0:
return False
else:
return val
assert f(2) == 2 |
benchmark_functions_edited/f23.py | def f(a, b):
return a + b;
assert f(4, 5) == 9 |
benchmark_functions_edited/f14244.py | def f(x):
argmax_ = None
max_ = None
for (nItem, item) in enumerate(x):
if (argmax_ is None) or (item > max_):
argmax_ = nItem
max_ = item
return argmax_
assert f(iter([1, 3, 2, 0])) == 1 |
benchmark_functions_edited/f5558.py | def f(a, b):
# return math.sqrt((a[0] - b[0])**2 + (a[1]- b[1])**2)
return max(abs(a[0] - b[0]), abs(a[1] - b[1]))
assert f( (3, 4), (3, 4) ) == 0 |
benchmark_functions_edited/f12966.py | def f(cart_value: int, limit: int = 1000) -> float:
if cart_value < limit:
return limit - cart_value
return 0
assert f(1000) == 0 |
benchmark_functions_edited/f10185.py | def f(p1, p2, p3):
# Compute the z-coordinate of the vectorial product p1p2 x p2p3
z = (p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0]- p1[0])
return 0 if z == 0 else int(z / abs(z))
assert f( (1, 0), (0, 1), (1, 0) ) == 0 |
benchmark_functions_edited/f12516.py | def f(index: int, size: int) -> int:
assert index < 0 # noqa: S101
index += size
if index < 0:
raise IndexError("lazysequence index out of range")
return index
assert f(-2, 4) == 2 |
benchmark_functions_edited/f5821.py | def f(args, options, default=None):
for opt in options:
if args.get(opt, None):
return args[opt]
return default
assert f(dict(), ["x", "y"], 2) == 2 |
benchmark_functions_edited/f1193.py | def f(v):
return float(v) if v != '.' else None
assert f(1) == 1 |
benchmark_functions_edited/f4349.py | def f(section, name):
try:
return int(section[name])
except (ValueError, TypeError, KeyError):
return 0
assert f(None, None) == 0 |
benchmark_functions_edited/f14490.py | def f(base, global_pos):
return ((global_pos - base) & ~1) + base
assert f(2, 3) == 2 |
benchmark_functions_edited/f13086.py | def f(depths: list):
increases = 0
previous = None
for depth in depths:
depth = int(depth)
if previous and depth > previous:
increases += 1
previous = depth
return increases
assert f([100, 100, 100]) == 0 |
benchmark_functions_edited/f4804.py | def f(v1, v2):
return max((abs(v[0] - v[1]) for v in zip(v1, v2)))
assert f((1, -1), (1, -1)) == 0 |
benchmark_functions_edited/f10730.py | def f(c, p):
# NOTE: only difference between 32 & 64 bit permutations
# is that len(p)==8 for 32 bit, and len(p)==16 for 64 bit.
out = 0
for r in p:
out |= r[c&0xf]
c >>= 4
return out
assert f(0, [[0]]) == 0 |
benchmark_functions_edited/f6082.py | def f(val, listOfVals):
try:
index = listOfVals.index(val)
except ValueError:
index = -1
return index
assert f(2, [2, 3, 5]) == 0 |
benchmark_functions_edited/f5604.py | def f(card, hands):
holder = -1
for player_num, hand in enumerate(hands):
if card in hand:
holder = player_num
return holder
assert f(5, [[1, 2, 3], [2, 3, 5], [3, 4, 5]]) == 2 |
benchmark_functions_edited/f5164.py | def f(r, delta):
return (abs(r) <= delta) * r ** 2 / 2 + (abs(r) > delta) * delta * (abs(r) - delta / 2)
assert f(0, 1) == 0 |
benchmark_functions_edited/f6639.py | def f(i, length, default):
if i is None:
i = default
elif i < 0:
i += length
return min(max(i,0),length)
assert f(0, 0, 0) == 0 |
benchmark_functions_edited/f420.py | def f(x):
return max(0, x)
assert f(1.0) == 1 |
benchmark_functions_edited/f1434.py | def f(low, high):
return (high + low) // 2
assert f(1, 4) == 2 |
benchmark_functions_edited/f4802.py | def f(label1, label2):
return (len(label1.union(label2)) - len(label1.intersection(label2)))/len(label1.union(label2))
assert f({1}, {1}) == 0 |
benchmark_functions_edited/f6324.py | def f(k, R, T):
return (k * R * T) ** 0.5
assert f(1, 1, 1) == 1 |
benchmark_functions_edited/f3598.py | def f(pulse_length, samples_per_record):
return 1 + (pulse_length - 1) // samples_per_record
assert f(1234, 1233) == 2 |
benchmark_functions_edited/f12792.py | def f(l, pred):
length = len(l)
index = length
for i in range(length):
if pred(l[i]):
index = i
break
return index
assert f(list(range(3)), lambda x: x % 2 == 0) == 0 |
benchmark_functions_edited/f4162.py | def f(val, high, low):
return (val >> low) & ((1 << (high - low + 1)) - 1)
assert f(1, 2, 2) == 0 |
benchmark_functions_edited/f8882.py | def f(timestamp):
return timestamp - (timestamp % 60)
assert f(5) == 0 |
benchmark_functions_edited/f11451.py | def f(E, E0):
return 16.2009 * (((E - E0)/1000) ** 0.5)
assert f(12000, 12000) == 0 |
benchmark_functions_edited/f9442.py | def f(value):
try:
return int(value)
except ValueError:
assert False, 'value %s cannot be converted to float' % str(value)
assert f(1.0) == 1 |
benchmark_functions_edited/f1636.py | def f(x):
res = 0
for v in x:
res += len(v)
return res
assert f([(1, 2, 3, 4)]) == 4 |
benchmark_functions_edited/f12281.py | def f(value, step, increase=False):
return ((int(value * 100000000) - int(value * 100000000) % int(
float(step) * 100000000)) / 100000000)+(float(step) if increase else 0)
assert f(2, 1) == 2 |
benchmark_functions_edited/f3834.py | def f(inch):
cm = inch * 2.54
return cm
assert f(0) == 0 |
benchmark_functions_edited/f1540.py | def f(agent, world):
rew = 0
return rew
assert f(1, 3) == 0 |
benchmark_functions_edited/f11754.py | def f(num1, num2):
if num1 > num2:
smaller = num2
else:
smaller = num1
for i in range(1, smaller + 1):
if ((num1 % i == 0) and (num2 % i == 0)):
return i
assert f(6, 1) == 1 |
benchmark_functions_edited/f2196.py | def f(this_matrix) -> int:
(this_n, _) = max(this_matrix)
return this_n
assert f(
[(0, 0), (4, 0), (0, 4), (1, 4), (2, 4), (3, 4), (4, 4)]) == 4 |
benchmark_functions_edited/f13812.py | def f(*numbers):
if len(numbers) == 2:
a, b = numbers
while b:
a, b = b, a % b
return a
elif len(numbers) < 2:
raise TypeError(
'gcd expected at least 2 arguments, got ' + str(len(numbers)))
else:
val = numbers[0]
for i in numbers[1:]:
... |
benchmark_functions_edited/f9211.py | def f(pressure_str):
pressure = int(pressure_str)
if pressure <= 1008:
pressure_coeff = 3
elif pressure >= 1023:
pressure_coeff = 1
else:
pressure_coeff = 2
return pressure_coeff
assert f("1023") == 1 |
benchmark_functions_edited/f6873.py | def f(n):
return int(n, 2)
assert f('1001') == 9 |
benchmark_functions_edited/f1951.py | def f(a, b, c):
return 0.5 * ((b[0]-a[0])*(c[1]-a[1]) - (c[0]-a[0])*(b[1]-a[1]))
assert f(
(0,0), (0,1), (0,2)
) == 0 |
benchmark_functions_edited/f1164.py | def f(a, b):
return (a[0]-b[0])**2 + (a[1]-b[1])**2
assert f( (-1,-1), (-1,-1) ) == 0 |
benchmark_functions_edited/f7441.py | def f(p_temp, h_temp):
# pylint: disable=unused-argument
return p_temp
assert f(1, 1) == 1 |
benchmark_functions_edited/f9741.py | def f(step, total, ceiling=0.5):
return min(1, (step/ceiling) / total)
assert f(0, 100, 0.3) == 0 |
benchmark_functions_edited/f1065.py | def f(x, y):
return 1 * x * 1 * 1 + 1 * 0 * 1 + 0 + y * 1
assert f(0, 0) == 0 |
benchmark_functions_edited/f12193.py | def f(accounts: int, deploys: int) -> int:
return (deploys if accounts == 0 else accounts) + 1
assert f(2, 1) == 3 |
benchmark_functions_edited/f10350.py | def f(s):
if type(s) in (list, tuple, set, frozenset):
return 6
if type(s) is dict:
return 5
if hasattr(s, 'validate'):
return 4
if issubclass(type(s), type):
return 3
if callable(s):
return 2
else:
return 1
assert f(list) == 3 |
benchmark_functions_edited/f7073.py | def f(bin_num):
return int(bin_num, 2)
assert f(bin(3)) == 3 |
benchmark_functions_edited/f4654.py | def f(f, v):
f(v)
return v
assert f(lambda x: x + 1, 0) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.