file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f1865.py | def f(start, end, coefficient):
return start + (end - start) * coefficient
assert f(1, 2, 0) == 1 |
benchmark_functions_edited/f13799.py | def f(value, in_low, in_high, out_low, out_high):
result = None
if value <= in_low:
result = out_low
else:
if value >= in_high:
result = out_high
else:
# http://stackoverflow.com/a/5650012/574981
result = out_low + (
(out_high - ou... |
benchmark_functions_edited/f4092.py | def f(k, j):
if j > k:
k, j = j, k
return k * (k-1) // 2 + j + 1
assert f(1, 2) == 3 |
benchmark_functions_edited/f1741.py | def f(value, minval, maxval):
return min(max(value, minval), maxval)
assert f(9, 1, 4) == 4 |
benchmark_functions_edited/f7201.py | def f(starting: int, end: int) -> int:
distance = abs(starting - end)
cost = distance * (distance + 1) / 2
assert cost == int(cost), "cost must always be exact"
return int(cost)
assert f(3, 0) == 6 |
benchmark_functions_edited/f2665.py | def f(n, facts=[1, 1, 2]):
while len(facts) <= n:
facts.append(facts[-1] * len(facts))
return facts[n]
assert f(0) == 1 |
benchmark_functions_edited/f1680.py | def f(x_coord, y_coord, width):
return y_coord * width + x_coord
assert f(1, 0, 10) == 1 |
benchmark_functions_edited/f12059.py | def f(_neighbours: list, _cells: dict) -> int:
alive: int = 0
count = 0
for c in _neighbours:
if _cells[c] is not None and _cells[c]["state"] == "X":
alive += 1
return alive
assert f(
[0, 1, 2, 3],
{0: {"state": "X"}, 1: {"state": "X"}, 2: {"state": None}, 3: {"state": Non... |
benchmark_functions_edited/f13943.py | def f(it):
it = iter(it)
try:
return next(it)
except StopIteration:
return None
assert f((i**2 for i in range(2, 100))) == 4 |
benchmark_functions_edited/f4564.py | def f(A, B):
if B == 0:
return abs(A)
return f(B, A % B)
assert f(27, 6) == 3 |
benchmark_functions_edited/f979.py | def f(degree):
return int(degree) + 1
assert f(1) == 2 |
benchmark_functions_edited/f13712.py | def f(w_type, f=None):
if f is None:
# set default values
if w_type:
f = [5, 10, 50, 100]
else:
f = [25]
if w_type:
return int((f[0] + f[3]) / 2)
else:
return f[0]
assert f(0, [5]) == 5 |
benchmark_functions_edited/f11683.py | def f(STDictonary_root, count=0):
if STDictonary_root is None:
return count
else:
count += 1
count = f(STDictonary_root._left, count)
count = f(STDictonary_root._right, count)
return count
assert f(None) == 0 |
benchmark_functions_edited/f4628.py | def f(mask):
shift = 0
while mask & 0x1 == 0:
shift += 1
mask >>= 1
return shift
assert f(0x1) == 0 |
benchmark_functions_edited/f13306.py | def f(i):
result = 1 - (0.1 * i) if i < 10 else 0
result = result / 0.9
return result
assert f(100) == 0 |
benchmark_functions_edited/f6515.py | def f(bb):
return int.from_bytes(bb, byteorder='little', signed=False)
assert f(b'\x01\x00\x00\x00\x00\x00') == 1 |
benchmark_functions_edited/f4803.py | def f(attribute, default):
if attribute is None:
return default
else:
return attribute
assert f(1, 2) == 1 |
benchmark_functions_edited/f4869.py | def f(length):
cb = int((length + 3) / 4)
db = length * 4
return cb + db
assert f(1) == 5 |
benchmark_functions_edited/f6923.py | def f(n):
output = 0
i = 2
while n > 1:
while n % i == 0:
output += i
n /= i
i += 1
return output
assert f(1) == 0 |
benchmark_functions_edited/f9675.py | def f(num1, num2):
while num2 != 0:
#bitwise and for two numbers
carry = num1 & num2
# store new bitwise or for num1
num1 = num1 ^ num2
# bitwise shift carry by 1
num2 = carry << 1
return num1
assert f(2, 3) == 5 |
benchmark_functions_edited/f10153.py | def f(num):
if not isinstance(num, int):
raise TypeError("Must be a positive int")
if num == 0:
return 1
return num * f(num - 1)
assert f(0) == 1 |
benchmark_functions_edited/f3452.py | def f(
id: int, # noqa
) -> int:
return (id & 65535) >> 11
assert f(1023) == 0 |
benchmark_functions_edited/f2162.py | def f(x: int, k: int) -> int:
mask = 1 << k
return x & mask
assert f(10, 4) == 0 |
benchmark_functions_edited/f3797.py | def f(xt, xtau, a=0.2, b=0.1, n=10):
return -b*xt + a*xtau / (1+xtau**n)
assert f(0,0) == 0 |
benchmark_functions_edited/f4518.py | def f(s):
return s[:-len(s.lstrip())].count('\n')
assert f('\n hello') == 1 |
benchmark_functions_edited/f4812.py | def f(my_list):
new_list = my_list[:]
new_list.sort()
p9_value = new_list[int(len(new_list) * 0.9)]
return p9_value
assert f([1,2,3]) == 3 |
benchmark_functions_edited/f12987.py | def f(val, percentiles):
ind = len(percentiles)
for i, p in enumerate(percentiles):
if val <= p:
ind = i
break
return ind
assert f(1, [1, 2, 3, 4]) == 0 |
benchmark_functions_edited/f6765.py | def f(p0, p1, v0, v1, t0, t1, t):
s = (t-t0)/(t1-t0)
h0 = (2*s+1)*(s-1)*(s-1)
h1 = (-2*s+3)*s*s
h2 = (1-s)*(1-s)*s*(t1-t0)
h3 = (s-1)*s*s*(t1-t0)
return h0*p0 + h1*p1 + h2*v0 + h3*v1
assert f(0, 1, 1, 1, 0, 1, 0) == 0 |
benchmark_functions_edited/f10039.py | def f(s):
auth = set([a for a in s["auth"] if a])
coms = [set(c.strip("-").split("-")) for c in s["coms"]
if c and c not in ("?", "nan")]
if not coms:
return None
return len([c for c in coms if len(c.intersection(auth))])
assert f(
{"auth": ["<NAME>", "<NAME>"],
"coms": ["<... |
benchmark_functions_edited/f1521.py | def f(n):
n = int(n)
return 1<<(n-1).bit_length()
assert f(3) == 4 |
benchmark_functions_edited/f6801.py | def f(counter, depth):
remainder = counter / 2 * (depth - 1)
if remainder > depth:
return 2 * depth - remainder
return remainder
assert f(0, 4) == 0 |
benchmark_functions_edited/f10840.py | def f(coin):
if coin == 1:
return 5
elif coin == 5:
return 10
elif coin == 10:
return 25
assert f(1) == 5 |
benchmark_functions_edited/f9323.py | def f(axis, ndim):
if axis < 0:
axis += ndim
if axis < 0 or axis >= ndim:
raise IndexError("axis out of range")
return axis
assert f(3, 5) == 3 |
benchmark_functions_edited/f9929.py | def f(s):
if s.lower() == s:
return 0
elif s.upper() == s:
return 1
elif s[0].upper() == s[0]:
return 2
else:
return 3
assert f('HI') == 1 |
benchmark_functions_edited/f4498.py | def f(ts_int,ts_fract):
return ts_int + (ts_fract / 1000.0)
assert f(0,0) == 0 |
benchmark_functions_edited/f7685.py | def f(length, logprobs, alpha=0.):
modifier = (((5 + length) ** alpha) / ((5 + 1) ** alpha))
return logprobs / modifier
assert f(2, 1) == 1 |
benchmark_functions_edited/f6391.py | def f(premier_nombre, second_nombre):
total = premier_nombre + second_nombre
return total
assert f(2, -2) == 0 |
benchmark_functions_edited/f8247.py | def f(labels):
if not labels:
return 1
leaf = max(labels, key=lambda x: x.count('/'))
clean = 1
for label in labels:
if label not in leaf:
clean = 0
return clean
assert f(['/a/b', '/a/b/c']) == 1 |
benchmark_functions_edited/f1978.py | def f(timestamp, bus):
before = (timestamp // bus) * bus
return (before + bus) - timestamp
assert f(0, 1) == 1 |
benchmark_functions_edited/f8227.py | def f(entry):
weight = 500 * entry[0] ** 0.25
for i in range(3, len(entry), 2):
weight -= (entry[i] / 100.0) ** 4 * 100
return weight
assert f( [0, 0, 0, 0, 0, 0, 0, 0] ) == 0 |
benchmark_functions_edited/f11084.py | def f(p1, p2):
return (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1])
assert f([1, 2], [1, 2]) == 0 |
benchmark_functions_edited/f7080.py | def f(p1, p2):
return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]) / 65
assert f( (10, 10), (10, 10) ) == 0 |
benchmark_functions_edited/f13627.py | def f(string1, string2):
assert isinstance(string1, str)
assert isinstance(string2, str)
if string1 == string2:
return 0
minlen = min(len(string1), len(string2))
diffcount = abs(len(string1) - len(string2))
for ii in range(0,minlen):
if string1[ii] != string2[ii]:
dif... |
benchmark_functions_edited/f8550.py | def f(sta):
# 'num_ebikes_available" is not part of the GBFS spec, but it appears
# in the Divvy API response
return sta['num_bikes_available'] + sta.get('num_ebikes_available', 0)
assert f({'num_bikes_available': 1}) == 1 |
benchmark_functions_edited/f6643.py | def f(s):
for i in range(len(s)):
if s[i] not in '0123456789':
return i
return -1
assert f('a') == 0 |
benchmark_functions_edited/f9503.py | def f(obj, key):
return obj[key] if isinstance(obj, dict) else getattr(obj, key)
assert f(
{'a': 1, 'b': 2},
'a') == 1 |
benchmark_functions_edited/f14397.py | def f(arr, target):
low = 0
high = len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
assert f(list(range(10)), 4) == 4 |
benchmark_functions_edited/f13919.py | def f(job_id):
import subprocess
try:
step_process = subprocess.Popen(('condor_rm', str(job_id)), shell=False, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout, stderr = step_process.communicate()
return 1
except Exception as e:
... |
benchmark_functions_edited/f8946.py | def f(predicate, iterable, default=None):
for el in iterable:
if predicate(el):
return el
return default
assert f(lambda x: x == 2, [1, 2, 3]) == 2 |
benchmark_functions_edited/f9324.py | def f(subject, goal):
total = 0
for i in range(len(subject)):
total += abs(goal[i] - subject[i])
return total
assert f(
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5]) == 0 |
benchmark_functions_edited/f12725.py | def f(function, xmin, xmax, intervals):
dx = (xmax - xmin) / intervals
total = 0
# Perform the integration.
x = xmin
for interval in range(intervals):
# Add the area in the rectangle for this slice.
total += dx * function(x)
# Move to the next slice.
x += dx
re... |
benchmark_functions_edited/f2636.py | def f(value, minv, maxv):
return min(max(value, minv), maxv)
assert f(1, 2, 3) == 2 |
benchmark_functions_edited/f12514.py | def f(board):
INDICES = ((0,1,2,3,4,5,6,7,8,9,10,11), (11,10,9,8,7,6,5,4,3,2,1,0),
(8,9,10,11,4,5,6,7,0,1,2,3), (3,2,1,0,7,6,5,4,11,10,9,8))
return min(sum(board[i]<<(e*2) for e,i in enumerate(I)) for I in INDICES)
assert f(
(0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0... |
benchmark_functions_edited/f1736.py | def f(boolean):
if boolean == True:
return 1
return 0
assert f(None) == 0 |
benchmark_functions_edited/f2468.py | def f(sequence):
return sequence[0] if len(sequence) > 0 else None
assert f([0, 1, 2]) == 0 |
benchmark_functions_edited/f1323.py | def f(seq):
for e in seq:
if e: return e
return False
assert f(range(1, 10)) == 1 |
benchmark_functions_edited/f2156.py | def f(*xs):
for x in xs:
if x is not None: return x
return None
assert f(5, []) == 5 |
benchmark_functions_edited/f462.py | def f(x,y):
if x == y:
return 1
else:
return 0
assert f(1, 1) == 1 |
benchmark_functions_edited/f13003.py | def f(scores, lives=3):
temp_lives = lives
last = scores[0]
for i,score in enumerate(scores):
if i > 0:
if temp_lives == 0:
return i
elif score >= last:
temp_lives -= 1
last = score
else:
temp_lives =... |
benchmark_functions_edited/f2561.py | def f(lat1, lat2):
dlat = lat2 - lat1
dist = dlat * 60 * 1852
return dist
assert f(52, 52) == 0 |
benchmark_functions_edited/f11520.py | def f(text: str) -> int:
l = len(text)-1
while l:
if text[l] == "]":
return l+1
l -= 1
return 0
assert f(r'<!!!>>') == 0 |
benchmark_functions_edited/f1332.py | def f(s):
return int(s.encode('hex'),16) if len(s) else 0
assert f("") == 0 |
benchmark_functions_edited/f12130.py | def f(iterable):
vol = 1
for elem in iterable:
vol *= elem
return vol
assert f((1,2)) == 2 |
benchmark_functions_edited/f3920.py | def f(l,default=0):
if l ==[]:
return default
return max(l)
assert f([4, 3, 5, 6]) == 6 |
benchmark_functions_edited/f500.py | def f(s):
if s.isdigit():
return int(s)
return s
assert f("0") == 0 |
benchmark_functions_edited/f3393.py | def f(agent, world):
rew = 0
return rew
assert f(1, 1) == 0 |
benchmark_functions_edited/f13071.py | def f(year, month):
assert 12 >= month >= 1
return (year - 1) * 12 + month - 1
assert f(1, 1) == 0 |
benchmark_functions_edited/f9748.py | def f(my_list=[]):
if not isinstance(my_list, list) or len(my_list) == 0:
return (0)
avg = 0
size = 0
for tup in my_list:
avg += (tup[0] * tup[1])
size += tup[1]
return (avg / size)
assert f( [(1, 1), (1, 1)] ) == 1 |
benchmark_functions_edited/f9451.py | def f(events: list) -> int:
gw = list(filter(lambda x: x["is_current"] is True, events))
return gw[0]["id"] if gw else 0
assert f([]) == 0 |
benchmark_functions_edited/f3625.py | def f(n, x=0, y=1):
for i in range(n - 1):
x, y = y, x + y
return x
assert f(1, 1) == 1 |
benchmark_functions_edited/f11364.py | def f(length, block_size):
if length % block_size:
return block_size - (length % block_size)
else:
return 0
assert f(2, 5) == 3 |
benchmark_functions_edited/f11465.py | def f(value):
r = value/100000
if r>1: r=1.0
return r
assert f(123000) == 1 |
benchmark_functions_edited/f10420.py | def f(words):
max_size = 0
for word in words:
if len(word) > max_size:
max_size = len(word)
return max_size
assert f(
["This", "is", "a", "test"]) == 4 |
benchmark_functions_edited/f4552.py | def f(a, b):
while b != 0:
a, b = b, a%b
return a
assert f(3, 3) == 3 |
benchmark_functions_edited/f14046.py | def f(x1, x2, y1, y2):
x = x1 - x2
y = y1 - y2
return x * x + y * y
assert f(1, -1, -1, 1) == 8 |
benchmark_functions_edited/f4.py | def f(x):
return x + x * x
assert f(1) == 2 |
benchmark_functions_edited/f10179.py | def f(x, warmup=0.002):
if x < warmup:
return x/warmup
return max((x-1.)/(warmup-1.), 0)
assert f(0) == 0 |
benchmark_functions_edited/f11909.py | def f(arr):
n = len(arr)
s = 0
m = 0
while s < n:
st = s
c = 0
h = {}
while st < n:
if arr[st] in h:
break
else:
h[arr[st]] = 1
c += 1
st += 1
m = max(c, m)
s += 1
retu... |
benchmark_functions_edited/f6713.py | def f(num: int) -> int:
return -(num >> num.bit_length())
assert f(0) == 0 |
benchmark_functions_edited/f13107.py | def f(weight_new_set: int, weight_old_set: int) -> int:
if weight_new_set > weight_old_set:
return weight_new_set
else:
return weight_old_set
assert f(5, 3) == 5 |
benchmark_functions_edited/f7953.py | def f(s, e, speed):
return ((s[0] - e[0]) ** 2 + (s[1] - e[1]) ** 2) ** 0.5 / speed
assert f((1, 1), (1, 2), 1) == 1 |
benchmark_functions_edited/f3317.py | def f(*args):
for arg in args:
if arg is not None:
return arg
return None
assert f(1, 2, 3) == 1 |
benchmark_functions_edited/f8350.py | def f(ws, row_idx, row, fmt=None):
for col_idx in range(len(row)):
ws.write(row_idx, col_idx, row[col_idx], fmt)
row_idx += 1
return row_idx
assert f(None, 0, []) == 1 |
benchmark_functions_edited/f2531.py | def f(anno):
return sum(sum(1 for v in ann["keypoints"][2::3] if v > 0) for ann in anno)
assert f(
[
{"keypoints": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{"keypoints": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{"keypoints": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
]
) == 0 |
benchmark_functions_edited/f940.py | def f(phi, e):
for d in range(1, phi):
if d*e % phi == 1: return d
assert f(13, 2) == 7 |
benchmark_functions_edited/f7587.py | def f(doc):
soup, _ = doc
try:
pagesize = len(soup.decode_contents())
except Exception:
pagesize = 0
return float(len(soup.get_text())) / pagesize if pagesize > 0 else 0
assert f(("<html><head><title>test</title></head><body> </body></html>", "")) == 0 |
benchmark_functions_edited/f8827.py | def f(n):
p = 31
res = 0
while p >= 0:
bit = n&1
res = res + bit*(1<<p)
# 1<<p is like saying 2**p
p-=1
n=n>>1
return res
assert f(0) == 0 |
benchmark_functions_edited/f10032.py | def f(cond_fun, body_fun, init_val, maxiter):
val = init_val
for _ in range(maxiter):
cond = cond_fun(val)
if not cond:
# When condition is met, break (not jittable).
break
val = body_fun(val)
return val
assert f(lambda x: x < 5, lambda x: x + 1, 6, 1) == 6 |
benchmark_functions_edited/f13815.py | def f(team):
num_players = len(team['players'])
if num_players == 0:
# No players return 0
return 0
# calculate average height of existing players
total_height = 0
for player in team['players']:
total_height += int(player['Height (inches)'])
return total_height / num_play... |
benchmark_functions_edited/f11432.py | def f(json_data: dict) -> int:
keys = list(json_data.keys())
if not keys:
return 1
last_id = int(keys.pop())
return last_id + 1
assert f({'1': {}, '2': {}, '3': {}}) == 4 |
benchmark_functions_edited/f13793.py | def f(x, x_levels):
for i, value in enumerate(x_levels):
if i < len(x_levels) and value < x:
pass
elif x == value:
return i
else:
return i - 1
assert f(2, [0, 1, 2, 3]) == 2 |
benchmark_functions_edited/f11957.py | def f(number):
if not number:
return 32
index = 0
while (number >> index) & 1 == 0:
index += 1
return index + 1
assert f(0b1000) == 4 |
benchmark_functions_edited/f11032.py | def f(num):
if isinstance(num, str):
num = float(num)
if isinstance(num, float):
n = int(num)
if n == num:
return n
return num
assert f(1.0000000000000000000000000000001) == 1 |
benchmark_functions_edited/f8244.py | def f(n):
if n == 1:
return 1
if n == 2:
return 2
else:
return n * f(n - 2)
assert f(*[2]) == 2 |
benchmark_functions_edited/f13539.py | def f(my_string):
if not isinstance(my_string, str):
raise TypeError("only accepts strings")
special_characters = ['-', '+', '\n']
for character in special_characters:
my_string = my_string.replace(character, " ")
words = my_string.split()
return len(words)
assert f('one + two + ... |
benchmark_functions_edited/f12702.py | def f(value, in_low, in_high, out_low, out_high):
result = None
# based on http://arduino.cc/en/Reference/Map
result = ((value - in_low) * (out_high - out_low)) / \
(in_high - in_low) + out_low
# http://stackoverflow.com/a/5650012/574981
# result = out_low + \
# ((out_high - out_lo... |
benchmark_functions_edited/f8674.py | def f(value, l, u):
return min(max(value,l),u)
assert f(-1, 0, 2) == 0 |
benchmark_functions_edited/f126.py | def f(n, m):
return sum([n] * m)
assert f(2, 1) == 2 |
benchmark_functions_edited/f5653.py | def f(cond, seq):
for x in seq:
if cond(x):
return x
return None
assert f(lambda x: x % 2 == 0, [1, 2, 3]) == 2 |
benchmark_functions_edited/f9390.py | def f(radius, ordinates, z):
return radius * ordinates / (z + radius)
assert f(1, 0, 0) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.