file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f4218.py | def f(p1,p2):
(x1,y1)=p1
(x2,y2)=p2
return abs(x1-x2)+abs(y1-y2)
assert f( (1,1), (0,0) ) == 2 |
benchmark_functions_edited/f2530.py | def f(open, close):
if close - open < 0:
return 0
else:
return 1
assert f(0, 0) == 1 |
benchmark_functions_edited/f3358.py | def f(int_type):
count = 0
while(int_type):
int_type &= int_type - 1
count += 1
return(count)
assert f(0b00011111) == 5 |
benchmark_functions_edited/f9006.py | def f(src: str, lineno: int) -> int:
assert lineno >= 1
pos = 0
for _ in range(lineno - 1):
pos = src.find('\n', pos) + 1
return pos
assert f(
"aaa\nbb\nc",
2
) == 4 |
benchmark_functions_edited/f12399.py | def f(value, in_min, in_max, out_min, out_max):
return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
assert f(0, 0, 100, 0, 100) == 0 |
benchmark_functions_edited/f2225.py | def f(nn):
sum = 0
while nn > 0:
sum = sum + nn
nn -= 1
return sum
assert f(1) == 1 |
benchmark_functions_edited/f9189.py | def f(arr):
try:
tolist = arr.tolist
except AttributeError:
return arr
return tolist()
assert f(1) == 1 |
benchmark_functions_edited/f10919.py | def f(filepath):
if '1D' in filepath:
return 1
elif '2D' in filepath:
return 2
elif '3D' in filepath:
return 3
elif '4D' in filepath:
return 4
else:
raise ValueError('cant parse dim from string %s' % filepath)
assert f(r'image_FLOAT_3D.nii.gz') == 3 |
benchmark_functions_edited/f3714.py | def f(val,min,max):
if val < min:
return min
elif val > max:
return max
return val
assert f(0, 1, 2) == 1 |
benchmark_functions_edited/f10936.py | def f(dna1, dna2):
distance = 0
for i in range(len(dna1)):
if dna1[i] != dna2[i]:
distance += 1
return distance
assert f( "CATCGTAATGACGGCCT", "CATCGTAATGACGGCCT" ) == 0 |
benchmark_functions_edited/f7258.py | def f(lista):
if len(lista) == 0:
return 0
return lista[0] + f(lista[1:])
assert f([1000, -1000]) == 0 |
benchmark_functions_edited/f13452.py | def f(fSize):
if fSize < 1024:
return 1
elif fSize < 16384:
return 2
elif fSize < 32768:
return 3
elif fSize < 65536:
return 4
elif fSize < 131072:
return 5
elif fSize < 262144:
return 6
elif fSize < 524288:
return 7
elif fSize < 10... |
benchmark_functions_edited/f14106.py | def f(obj):
try:
return len(obj)
except (AttributeError, TypeError):
try:
get_hint = type(obj).__length_hint__
except AttributeError:
return None
try:
hint = get_hint(obj)
except TypeError:
return None
if hint is Not... |
benchmark_functions_edited/f6385.py | def f(nums):
idx = 0
total = 0
while idx < len(nums):
total += nums[idx]
idx += 1
return total
assert f(list()) == 0 |
benchmark_functions_edited/f4768.py | def f(n):
bits = 0 if n == 0 else 1
while n > 1:
bits += n % 2
n //= 2
return bits
assert f(28) == 3 |
benchmark_functions_edited/f11968.py | def f(part):
count = 0
for character in part['NAME']:
if character.isdigit():
count += 1
if count == 0:
return 0
else:
return int(''.join(character for character
in part['NAME'] if character.isdigit()))
assert f(
{'NAME': 'Millenium Fa... |
benchmark_functions_edited/f12604.py | def f(color_component):
i = color_component / 255
if i <= 0.03928:
return i / 12.92
else:
return ((i + 0.055) / 1.055) ** 2.4
assert f(255) == 1 |
benchmark_functions_edited/f220.py | def f(inputs):
return int(inputs/3)-2
assert f(14) == 2 |
benchmark_functions_edited/f484.py | def f(nth):
return nth * (nth + 1) / 2
assert f(1) == 1 |
benchmark_functions_edited/f13301.py | def f(initial_velocity, acceleration, time):
dist = initial_velocity * time + 0.5 * (acceleration * time ** 2)
return dist
assert f(1, 2, 2) == 6 |
benchmark_functions_edited/f2035.py | def f(str1: str, str2: str) -> int:
return len(set(str1) & set(str2))
assert f('aab', 'aba') == 2 |
benchmark_functions_edited/f2298.py | def f(x, a, b):
if a > b:
return None
return min(max(x, a), b)
assert f(-1, 0, 5) == 0 |
benchmark_functions_edited/f2967.py | def f(status):
status_map = {
'running': 1,
'stopped': 0}
return status_map[status]
assert f('stopped') == 0 |
benchmark_functions_edited/f4409.py | def f(a, b):
distance = 0
for x, y in zip(a, b):
distance += (x - y)
return distance
assert f(
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 3]
) == 2 |
benchmark_functions_edited/f6755.py | def f(secs_left):
if secs_left <= 900:
return 4
if secs_left <= 1800:
return 3
if secs_left <= 2700:
return 2
return 1
assert f(840) == 4 |
benchmark_functions_edited/f10653.py | def f(x):
assert type(x) is int, "`x` should be of type `int`"
assert 0 <= x, "`x` should be >= 0"
size = 0
while True:
x >>= 8
size += 1
if x == 0:
return size
assert f(0x100000000) == 5 |
benchmark_functions_edited/f7144.py | def f(odds):
return odds / (1 + odds)
assert f(0) == 0 |
benchmark_functions_edited/f8623.py | def count_uppers (val):
return sum(1 for c in val if c.isupper())
assert f(
'H'
) == 1 |
benchmark_functions_edited/f11884.py | def f(prefix, arr):
# This code was chosen for its elegance not its efficiency.
return len([elt for elt in arr if elt.startswith(prefix)])
assert f("", ["", "abc", "abd"]) == 3 |
benchmark_functions_edited/f1806.py | def f(number: int, i: int):
return (number & (0xff << (i * 8))) >> (i * 8)
assert f(65536, 1) == 0 |
benchmark_functions_edited/f8862.py | def f(update, close, guess=1, max_updates=100):
k = 0
while not close(guess) and k < max_updates:
guess = update(guess)
k = k + 1
return guess
assert f(lambda x: x + 1, lambda x: x == 5, 5) == 5 |
benchmark_functions_edited/f12097.py | def f(raw_value, default=0):
try:
return int(float(raw_value))
except (ValueError, TypeError):
return default
assert f("0") == 0 |
benchmark_functions_edited/f10896.py | def f(a, b, m):
res = 0
while b != 0:
if b & 1:
res ^= a
a <<= 1
b >>= 1
if a >= 256:
a ^= m
return res
assert f(0, 0, 17) == 0 |
benchmark_functions_edited/f430.py | def f(byte):
return byte / 1024 ** 2
assert f(0) == 0 |
benchmark_functions_edited/f6248.py | def f(value):
if value < 0:
return -value
return value
assert f(5) == 5 |
benchmark_functions_edited/f2806.py | def f(error: Exception, result: float) -> float:
print("Warning:", error)
return result
assert f(ValueError("foo"), 0) == 0 |
benchmark_functions_edited/f4208.py | def f(func, valid, s):
x = func(s)
if valid(x):
return x
raise ValueError(f"{s} is not valid.")
assert f(int, lambda x: isinstance(x, int), "1") == 1 |
benchmark_functions_edited/f1706.py | def f(val):
try:
return int(val)
except ValueError:
return 0
assert f("1") == 1 |
benchmark_functions_edited/f1781.py | def f(x, y):
while y != 0:
(x, y) = (y, x % y)
return x
assert f(13, 17) == 1 |
benchmark_functions_edited/f9551.py | def f(a,findLoc=False):
maxVal = a[0]
maxLoc = 0
for i in range(1,len(a)):
if a[i] > maxVal:
maxVal = a[i]
maxLoc = i
if findLoc == True:
return maxVal, maxLoc
return maxVal
assert f( [0, 1, 2, 3] ) == 3 |
benchmark_functions_edited/f11113.py | def f(v0, v1, blend=.5):
vector = v1 - v0
vector *= blend
vector += v0
return vector
assert f(1, 2, 0) == 1 |
benchmark_functions_edited/f2565.py | def f(mmap, position):
return mmap.find(b"\n", position + 1)
assert f(b"ATCG\n", 1) == 4 |
benchmark_functions_edited/f2542.py | def f(number):
truncated = str(number)[:-1]
if truncated:
return int(truncated)
assert f(12) == 1 |
benchmark_functions_edited/f10686.py | def f(integers):
odds = set()
for i in integers: # O(N)
if i in odds:
odds.remove(i) # O(1)
else:
odds.add(i) # O(1)
return odds.pop() if len(odds) else None
assert f({1}) == 1 |
benchmark_functions_edited/f2331.py | def f(a,b):
if a < b:
return -1
elif a > b:
return 1
else:
return 0
assert f(2, 1) == 1 |
benchmark_functions_edited/f11457.py | def f(x: float, constant: float) -> float:
if constant <= 0:
raise ValueError('Squash constant must be greater than zero.')
if 0 > x >= 1:
raise ValueError('Undo squash can only be performed on a value in [0, 1).')
return (x * constant) / (1 - x)
assert f(0, 0.5) == 0 |
benchmark_functions_edited/f2716.py | def f(number, lower, upper):
return max(min(number, upper), lower)
assert f(3, 1, 2) == 2 |
benchmark_functions_edited/f7012.py | def f( term_rankings ):
m = 0
for ranking in term_rankings:
if m == 0:
m = len(ranking)
else:
m = min( len(ranking), m )
return m
assert f( [ [0,1,2,3,4], [0,1,2,3,4], [5,6,7,8,9] ] ) == 5 |
benchmark_functions_edited/f14008.py | def f(arr):
n = len(arr)
v = [-1 for i in range(256)]
m = 1
clen = 1
v[ord(arr[0])] = 0
for i in range(1, n):
lastIndex = v[ord(arr[i])]
if lastIndex == -1 or i-clen > lastIndex:
clen+=1
else:
m = max(m, clen)
clen = i - l... |
benchmark_functions_edited/f3275.py | def f(old, new, seconds):
delta = new - old
if delta < 0:
delta = new
return delta / seconds
assert f(10, 10, 1) == 0 |
benchmark_functions_edited/f5931.py | def f(row):
counter = 0
for element in row:
if element != float(0):
return counter
counter += 1
return counter
assert f([float(0), 1, float(0)]) == 1 |
benchmark_functions_edited/f11908.py | def f(n):
fibs = [1, 1]
for i in range(2, n+1):
fibs.append(fibs[i-1] + fibs[i-2])
return fibs[n]
assert f(1) == 1 |
benchmark_functions_edited/f9758.py | def f(text, default=0):
try:
return int(text)
except (ValueError, TypeError):
return default
assert f("moo") == 0 |
benchmark_functions_edited/f4987.py | def f(x, y, z):
x0 = 8
y0 = 8
z0 = 8
r = 4
return r * r - ((x - x0) * (x - x0) + (y - y0) * (y - y0) + (z - z0) * (z - z0))
assert f(10, 10, 10) == 4 |
benchmark_functions_edited/f14241.py | def f(collection, limit, marker):
return collection[limit - 1]['id']
assert f(
[{'id': 1}, {'id': 2}, {'id': 3}, {'id': 4}, {'id': 5}],
5,
4) == 5 |
benchmark_functions_edited/f12312.py | def f(color_value):
a = 0.055
if color_value <= 0.0031308:
return color_value * 12.92
return (1 + a) * pow(color_value, 1 / 2.4) - a
assert f(0) == 0 |
benchmark_functions_edited/f362.py | def f(torr):
return torr * 101325.0 / 760.0
assert f(0) == 0 |
benchmark_functions_edited/f2472.py | def f(arms, N):
return N * (sum(arms) / len(arms))
assert f([10, 20, 30, 40], 0) == 0 |
benchmark_functions_edited/f14355.py | def f(d, list_of_keys):
dct = d
for i, k in enumerate(list_of_keys):
assert (
k in dct
), f"Key {k} is not in dictionary after seeing {i+1} keys from {list_of_keys}"
dct = dct[k]
return dct
assert f(
{"a": {"b": {"c": 1}}}, ["a", "b", "c"]
) == 1 |
benchmark_functions_edited/f1600.py | def f(p1, p2):
return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
assert f( (0, 0), (1, 1) ) == 2 |
benchmark_functions_edited/f14443.py | def f(maxA,maxB):
if maxA is None and maxB is None:
maxderiv = None
elif maxA is None:
maxderiv = maxB
elif maxB is None:
maxderiv = maxA
else:
maxderiv = min(maxA,maxB)
return maxderiv
assert f(None,0) == 0 |
benchmark_functions_edited/f4422.py | def f(collection, condition):
return next((element for element in collection if condition(element)), None)
assert f([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], lambda x: x > 4) == 5 |
benchmark_functions_edited/f7380.py | def f(x, l, r):
minimum, maximum = min(l, r), max(l, r)
res = x
res = min(res, maximum)
res = max(res, minimum)
return res
assert f(0, 0, 0) == 0 |
benchmark_functions_edited/f7217.py | def f(body_response):
return len(body_response['flavors'])
assert f({'flavors': []}) == 0 |
benchmark_functions_edited/f9150.py | def f(back_height):
ver = int(back_height/300+0.5)
if ver == 0:
ver += 1
elif ver > 39:
ver = 39
return ver
assert f(150) == 1 |
benchmark_functions_edited/f9480.py | def f(distribution):
return sum(distribution) / len(distribution)
assert f([1, 2, 3, 4, 5]) == 3 |
benchmark_functions_edited/f375.py | def f(value, arg):
return float(value) + float(arg)
assert f(4, 5) == 9 |
benchmark_functions_edited/f7977.py | def f(gamma, sup, tau):
return sup*(tau)**-gamma
assert f(0, 0, 1) == 0 |
benchmark_functions_edited/f7792.py | def f( lst):
min_idx = 0
for i in range(1, len(lst)):
if lst[i]['start'] < lst[min_idx]['start']:
min_idx = i
return min_idx
assert f( [{'start': 1, 'end': 10}, {'start': 11, 'end': 12}, {'start': 3, 'end': 8}] ) == 0 |
benchmark_functions_edited/f74.py | def f(x):
return x[0] + x[1]
assert f((3, 4)) == 7 |
benchmark_functions_edited/f9677.py | def f(x,a,b):
return a+b*x
assert f(0,0,1) == 0 |
benchmark_functions_edited/f7085.py | def f(score):
if not score:
return 0
dbot_score = 1
if score >= 95:
dbot_score = 3
elif score >= 75:
dbot_score = 2
return dbot_score
assert f(50) == 1 |
benchmark_functions_edited/f759.py | def f(x, y):
for _ in range(1, 10, 3):
x = x + 1
return x + y
assert f(1, 3) == 7 |
benchmark_functions_edited/f10822.py | def f(s1, s2):
if len(s1) != len(s2):
return 1
diff_count = 0
for c1, c2, in zip(s1, s2):
if c1 != c2:
diff_count += 1
return diff_count
assert f("abc", "abc") == 0 |
benchmark_functions_edited/f14470.py | def f(dct, loc):
if loc == "":
return dict
else:
locs = loc.split(".")
d = dct
for ll in locs:
try:
d = d[ll]
except KeyError:
raise KeyError(f"loc {loc} does not exist in dict {dct}")
return d
assert f(
{"foo"... |
benchmark_functions_edited/f486.py | def f(x):
return (x + 1) / 2
assert f(-1) == 0 |
benchmark_functions_edited/f3756.py | def f(val, update_interval=None):
tmp = 1
if update_interval:
tmp = 1/update_interval
return (val / 1024 / 1024) * tmp
assert f(1024*1024) == 1 |
benchmark_functions_edited/f5907.py | def f(dividend: int, divisor: int):
return (divisor - (dividend % divisor)) % divisor
assert f(5, 4) == 3 |
benchmark_functions_edited/f2985.py | def f(a, b):
return sum([int(i != j) for i, j in zip(a, b)])
assert f(b'karolin', b'kathrin') == 3 |
benchmark_functions_edited/f2926.py | def f(strg):
sum = 0
for i in strg[:3]:
sum += int(i)
if sum == 0:
sum = 1
return sum
assert f("123") == 6 |
benchmark_functions_edited/f5985.py | def f(l):
l= str(l)
if l.count('-')<=3:
return 0
elif l.count('-')>3 and l.count('-')<=5:
return 2
else:
return 1
assert f(10) == 0 |
benchmark_functions_edited/f6155.py | def f(x, p):
if x % p == 0:
raise ZeroDivisionError("Impossible inverse")
return pow(x, p-2, p)
assert f(5, 7) == 3 |
benchmark_functions_edited/f7765.py | def f(dic, output_init=1):
output = output_init
for key, value in dic.items():
output *= sp.Symbol(key)**value
return output
assert f(dict()) == 1 |
benchmark_functions_edited/f4993.py | def f(n: int) -> int:
return (1 if n == 1 else
3 if n == 2 else
6 * f(n - 1) - f(n - 2) - 2)
assert f(2) == 3 |
benchmark_functions_edited/f276.py | def f(w):
return (w == -1 and [20] or [w])[0]
assert f(0) == 0 |
benchmark_functions_edited/f5990.py | def f(current, rampup_length):
assert current >= 0 and rampup_length >= 0
if current >= rampup_length:
return 1.0
else:
return current / rampup_length
assert f(1000, 1000) == 1 |
benchmark_functions_edited/f3081.py | def f(i,j,qi,qj):
return int((i * qj) + j)
assert f(2,0,2,3) == 6 |
benchmark_functions_edited/f3848.py | def f(x):
parity = 0
while x:
parity += x & 1
x >>= 1
return parity % 2
assert f(1000) == 0 |
benchmark_functions_edited/f8031.py | def f(num):
if num == 0:
return 0
elif num <=2:
return 1
else:
return f(num-1) + f(num-2)
assert f(6) == 8 |
benchmark_functions_edited/f9067.py | def f(arr):
total = 0
count = 0
for x in arr:
if x is not None and x != 0:
total, count = total + x, count + 1
count = 1 if count == 0 else count
return round(total / count, 2)
assert f([]) == 0 |
benchmark_functions_edited/f1461.py | def f(a, b):
while b:
a, b = b, a % b
return a
assert f(2, 4) == 2 |
benchmark_functions_edited/f4025.py | def f(value):
result = None
try:
result = int(value)
except:
pass
return result
assert f("5") == 5 |
benchmark_functions_edited/f8772.py | def f(num,divisor):
return num - (num%divisor)
assert f(5, 3) == 3 |
benchmark_functions_edited/f11388.py | def f(original, default, maximum):
# If "original" comes from command line, it may be a string
try:
value = int(original)
except ValueError:
value = 0
# Check bounds
if value < default:
value = default
if value > maximum:
value = maximum
return value
assert f... |
benchmark_functions_edited/f4335.py | def f(k):
if(k>0):
result = k + f(k-1)
# print(result)
else:
result = 0
return result
assert f(2) == 3 |
benchmark_functions_edited/f10635.py | def f(msg: dict) -> int:
accounts = 0
print(f"DEBUG --- check_account msg parameter {msg}")
if msg != "":
accounts = len(msg[0])
return accounts
assert f(
[["111111111111", ["GroupA", "GroupB"], "AccountA"],
["222222222222", ["GroupA", "GroupB"], "AccountB"],
["3333333333333", ["Gr... |
benchmark_functions_edited/f3201.py | def f(thrust, shaft_power, velocity):
return thrust * velocity / shaft_power
assert f(0, 1000, 0) == 0 |
benchmark_functions_edited/f629.py | def f(Psi_1, Psi_2, dof):
comac = 1
return comac
assert f(1, 3, 2) == 1 |
benchmark_functions_edited/f12009.py | def f(p1, p2):
return (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2
assert f( (0,0), (0,0) ) == 0 |
benchmark_functions_edited/f2405.py | def f(x, a=0.0, b=0.0, c=0.0):
return a * x**2 + b * x + c
assert f(10) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.