file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f5022.py
|
def f(z):
for i, zi in enumerate(z):
if zi > 0:
return i + 1
else:
return None
assert f([1, 0, 0, 0]) == 1
|
benchmark_functions_edited/f6994.py
|
def f(numbers):
m1, m2 = float('inf'), float('inf')
for x in numbers:
if x <= m1:
m1, m2 = x, m1
elif x < m2:
m2 = x
return m2
assert f(list(range(100))) == 1
|
benchmark_functions_edited/f151.py
|
def f(ccdid, qid):
return 4*(ccdid - 1) + qid - 1
assert f(1, 3) == 2
|
benchmark_functions_edited/f11182.py
|
def f(e, e0, v0, e1, v1):
if e < e0:
return v0
elif e < e1:
return v0 + (v1-v0)*(e-e0)/(e1-e0)
else:
return v1
assert f(1, 0, 1, 1, 0) == 0
|
benchmark_functions_edited/f14427.py
|
def f(b, n, m):
a = 1
while n: # n is represented as a 2's complement number
if n & 1: # test the lowest bit of n
a = (a * b) % m
b = (b * b) % m
n //= 2 # right shift 1 bit
return a
assert f(1, 1, 2) == 1
|
benchmark_functions_edited/f5995.py
|
def f(parameter_list, code_list, i):
if parameter_list[0] != 0:
i = parameter_list[1]
return i
assert f( [1, 0, 2000], [], 0) == 0
|
benchmark_functions_edited/f7141.py
|
def f(n):
nd = 1
base = 10
while 1:
if n // base == 0:
break
else:
base *= 10
nd += 1
return nd
assert f(100) == 3
|
benchmark_functions_edited/f59.py
|
def f(n):
return 2 * n - 2
assert f(4) == 6
|
benchmark_functions_edited/f8778.py
|
def f(value):
return sum(c.isdigit() for c in str(value))
assert f(2.0) == 2
|
benchmark_functions_edited/f8216.py
|
def f(score):
if score >= 0 and score < 0.3333333333:
return 0
elif score >= 0.3333333333 and score < 0.6666666666:
return 1
else:
return 2
assert f(0.5) == 1
|
benchmark_functions_edited/f9410.py
|
def f(qc, ar, u2):
# qt the cone tip resistance corrected for unequal end area effects, eq 2.3
qt = qc + ((1 - ar) * u2)
return qt
assert f(1, 0.01, 0) == 1
|
benchmark_functions_edited/f12087.py
|
def f(number: int) -> int:
return 1 if number in (0, 1) else number * f(number - 1)
assert f(2) == 2
|
benchmark_functions_edited/f10514.py
|
def f(x, n):
if n == 0:
return 1
else:
partial = f(x, n // 2) # rely on truncated division
result = partial * partial
if n % 2 == 1: # if n odd, include extra factor of x
result *= x
return result
assert f(5, 0) == 1
|
benchmark_functions_edited/f13869.py
|
def f(dct, key, lazy_val_func, *args, **kwargs):
try:
val = dct[key]
except KeyError:
val = lazy_val_func(*args, **kwargs)
dct[key] = val
return val
assert f(dict(), 'a', lambda x: 5, 1) == 5
|
benchmark_functions_edited/f14419.py
|
def f(n):
if not isinstance(n, int):
raise TypeError('n should be an integer larger than 1.')
return None
if not n > 1:
raise ValueError('n should be an integer larger than 1.')
return None
result = 0
while (n != 1):
result += 1
if (n & 1 == 1):
n = 3 * n + 1
else:
n //= 2
return result
assert f(8) == 3
|
benchmark_functions_edited/f178.py
|
def f(LL):
(LL + [])[0].append(1)
return 0
assert f(
[[1], [2]]
) == 0
|
benchmark_functions_edited/f6035.py
|
def f(data_dict, key_list):
item = data_dict.copy()
for k in key_list:
item = item[k]
return item
assert f(
{
'outer': {
'inner': {
'key': 8
}
}
},
['outer', 'inner', 'key']
) == 8
|
benchmark_functions_edited/f10487.py
|
def f(name: str, alphabet: list):
result = 0
for char in name:
result += alphabet.index(char) + 1
return result
assert f(
"A",
["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
"V", "W", "X", "Y", "Z"]) == 1
|
benchmark_functions_edited/f14108.py
|
def f(input_string):
if input_string.strip() in {"1", "2", "3", "4", "5", "6"}:
return int(input_string)
else:
print("Please enter a number from 1 to 6.")
raise SystemExit(1)
assert f("6") == 6
|
benchmark_functions_edited/f3389.py
|
def f(n):
return (n << 1) ^ (n >> 31)
assert f(-2) == 3
|
benchmark_functions_edited/f9788.py
|
def f(headways):
if not headways:
return 0
frequency = sum([1 / headway for headway in headways])
return 1 / frequency
assert f([]) == 0
|
benchmark_functions_edited/f391.py
|
def f(val, low=0, hi=127):
return 127 * val / 255
assert f(0x00) == 0
|
benchmark_functions_edited/f9621.py
|
def f(firewall: dict) -> int:
i = 0
while True:
s = any(True for layer, depth in firewall.items()
if not (layer+i) % (2*depth-2))
if not s:
return i
i += 1
assert f({}) == 0
|
benchmark_functions_edited/f6160.py
|
def f(z):
depth = 0
for _, v in z.items():
if type(v) is list or type(v) is tuple:
depth = max(depth, len(v))
return depth
assert f({None: [None]}) == 1
|
benchmark_functions_edited/f2983.py
|
def f(n):
try: return int(n)
except (ValueError, TypeError): return 0
assert f('123xabc') == 0
|
benchmark_functions_edited/f10607.py
|
def f(data_dict, key):
data = data_dict.get(key)
data_score = data.get('total', 0) if data else 0
return data_score
assert f(dict(), 'foo') == 0
|
benchmark_functions_edited/f3514.py
|
def f(severity):
if severity <= 4:
return severity
return 4
assert f(9) == 4
|
benchmark_functions_edited/f4131.py
|
def f(our_percentage):
return 100**(0.5 - our_percentage) * (1 - our_percentage) * 2
assert f(1.0) == 0
|
benchmark_functions_edited/f8552.py
|
def f(list, index):
return list[index] if index < len(list) else None
assert f(range(4), -1) == 3
|
benchmark_functions_edited/f1208.py
|
def f(f, q):
return int(round(f / q) * q)
assert f(1, 1) == 1
|
benchmark_functions_edited/f5872.py
|
def f(dictionary, key):
if dictionary is None:
return None
return dictionary.get(str(key))
assert f({'item1': 5}, 'item1') == 5
|
benchmark_functions_edited/f13787.py
|
def f(first, second):
first = list(map(int, first.split('.')))
second = list(map(int, second.split('.')))
for i in range(3):
diff = first[i] - second[i]
if diff != 0:
return diff
return 0
assert f( '1.0.1', '1.0.1' ) == 0
|
benchmark_functions_edited/f8851.py
|
def f(x0, x1, a, b, c, d):
return a * (x1 - x0) \
+ b * (x1**2 - x0**2) / 2.0 \
+ c * (x1**3 - x0**3) / 3.0 \
+ d * (x1**4 - x0**4) / 4.0
assert f(1, 2, 0, 0, 0, 0) == 0
|
benchmark_functions_edited/f14378.py
|
def f(a, b):
def interleave(args):
return ''.join([x for t in zip(*args) for x in t])
return int(''.join(interleave(format(x, '016b') for x in (a, b))), base=2)
assert f(0, 1) == 1
|
benchmark_functions_edited/f962.py
|
def f(x, y):
return abs(x - y)
assert f(99, 100) == 1
|
benchmark_functions_edited/f8221.py
|
def f(pos1, pos2):
return sum(abs(a - b) for a, b in zip(pos1, pos2))
assert f( (0,0), (0,0) ) == 0
|
benchmark_functions_edited/f14350.py
|
def f(corpus):
maxid = -1
for document in corpus:
if document:
maxid = max(maxid, max(fieldid for fieldid, _ in document))
return maxid
assert f(iter([[(0, 1)], []])) == 0
|
benchmark_functions_edited/f11433.py
|
def f(text, signs):
positions = [text.find(sign) for sign in signs if text.find(sign) != -1]
if positions:
return min(positions)
else:
return -1
assert f(
"Hello, World!",
["H", "e", "l", "o"]
) == 0
|
benchmark_functions_edited/f597.py
|
def f(n,m):
c=1
for i in range(m):
c*=n+i+1
return c
assert f(0,0) == 1
|
benchmark_functions_edited/f9465.py
|
def f(abs_pos, ex_num, rel_starts):
if len(rel_starts) == 1:
return abs_pos
ex_num_0 = int(ex_num) - 1
rel_pos_uncorr = abs_pos - rel_starts[ex_num_0]
rel_pos = rel_pos_uncorr if rel_pos_uncorr >= 0 else 0
return rel_pos
assert f(1, 1, [0, 5]) == 1
|
benchmark_functions_edited/f5947.py
|
def f(hand):
leng = sum(hand.values())
return leng
assert f({}) == 0
|
benchmark_functions_edited/f8361.py
|
def f(captcha):
solution = 0
prev_digit = captcha[-1]
for digit in captcha:
if prev_digit == digit:
solution += int(digit)
prev_digit = digit
return solution
assert f(
"91212129") == 9
|
benchmark_functions_edited/f4226.py
|
def f(obj, key_path):
return f(obj[key_path[0]], key_path[1:]) if key_path else obj
assert f(
{'a': {'b': [{'c': {'d': 4}}]}},
['a', 'b', 0, 'c', 'd']) == 4
|
benchmark_functions_edited/f5804.py
|
def f(seq, index, default=None, func=lambda x: x):
try:
return func(seq[index])
except IndexError:
return default
assert f((1,), 1, 0, int) == 0
|
benchmark_functions_edited/f7944.py
|
def f(obj, keys):
if isinstance(keys, str):
keys = keys.split('.')
for key in keys:
if not obj or key not in obj:
return None
obj = obj[key]
return obj
assert f(
{'a': {'b': 1}},
'a.b'
) == 1
|
benchmark_functions_edited/f4978.py
|
def f(fps, arrs):
return min([fp for fp in fps if not arrs[fp] is None], key=lambda fp: arrs.get(fp)[0][0])
assert f(
[1, 2, 3, 4],
{
1: None,
2: None,
3: ((9, 16), (20, 21)),
4: ((20, 21),)
}
) == 3
|
benchmark_functions_edited/f1328.py
|
def f(a, lamda):
return a / (1 + 2.0 * lamda)
assert f(0, 0) == 0
|
benchmark_functions_edited/f9847.py
|
def f(base, exp):
output = 1
while exp > 0:
if exp % 2 == 1:
output *= base
base *= base
exp //= 2
return output
assert f(3, 1) == 3
|
benchmark_functions_edited/f346.py
|
def f(b):
return 0 if b == 0 else (1 if b == 1 else -1)
assert f(0) == 0
|
benchmark_functions_edited/f2587.py
|
def f(num):
return int(round(num))
assert f(1.1) == 1
|
benchmark_functions_edited/f8848.py
|
def f(v):
if v > 0xFFFFFFFF:
return f(v >> 32) + f(v & 0xFFFFFFFF)
# HACKMEM 169
y = (v >> 1) & 0xDB6DB6DB
y = v - y - ((y >> 1) & 0xDB6DB6DB)
return (((y + (y >> 3)) & 0xC71C71C7) % 0x3F)
assert f(21) == 3
|
benchmark_functions_edited/f5500.py
|
def f(im, y, fns):
for fn in fns:
#pdb.set_trace()
im, y =fn(im, y)
return im if y is None else (im, y)
assert f(1, None, [lambda x,y: (x,y)]) == 1
|
benchmark_functions_edited/f7402.py
|
def f(i0, j0, i1, j1):
return ((i0 - i1) ** 2) + ((j0 - j1) ** 2)
assert f(1, 2, 2, 3) == 2
|
benchmark_functions_edited/f1217.py
|
def f(path, content):
with open(path, 'a') as _file:
return _file.f(content)
assert f('my_file.txt', 'abc') == 3
|
benchmark_functions_edited/f2448.py
|
def f(key, value):
# ====>
# <====
return value
assert f(6, 1) == 1
|
benchmark_functions_edited/f10880.py
|
def f(value, idx):
for k, v in idx.items():
if v == value:
return k
assert f(5, {1: 5, 2: 5}) == 1
|
benchmark_functions_edited/f7777.py
|
def f(number):
weights = (8, 7, 6, 5, 4, 3, 2, 10, 1)
return sum(w * int(n) for w, n in zip(weights, number)) % 97
assert f('') == 0
|
benchmark_functions_edited/f8526.py
|
def f(value):
if value is None:
return 0
elif isinstance(value, float):
return int(value * 100)
else:
return int(value)
assert f(0.00) == 0
|
benchmark_functions_edited/f1563.py
|
def f(v):
v = int(v)
if v <= 0:
raise ValueError('Non-positive int')
return v
assert f(1) == 1
|
benchmark_functions_edited/f7299.py
|
def f(part_status):
return len([c for c in part_status if c=='1'])
assert f("110") == 2
|
benchmark_functions_edited/f8556.py
|
def f(valores_acumulados):
for val in valores_acumulados:
if val == 3:
return 1
return 0
assert f( [ 1, 2, 1, 1, 1, 1, 1 ] ) == 0
|
benchmark_functions_edited/f7044.py
|
def f(agents_row_a, agents_row_b):
length = (((agents_row_a[0] - agents_row_b[0])**2) +
((agents_row_a[1] - agents_row_b[1])**2))**0.5
return(length)
assert f( (3, 4), (0, 0) ) == 5
|
benchmark_functions_edited/f5580.py
|
def f(object_, points):
return next(coords for coords, maybe_this_object in points if maybe_this_object == object_)
assert f('y', [(1, 'x'), (2, 'y')]) == 2
|
benchmark_functions_edited/f12156.py
|
def f(batch):
size = 0
for mutation in batch:
size += len(mutation['key'])
if 'values' in mutation:
for value in mutation['values'].values():
size += len(value)
return size
assert f(
[
{'key': b'a'},
],
) == 1
|
benchmark_functions_edited/f3086.py
|
def f(p1, p2):
return ((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2 + (p1[2] - p2[2])**2)**0.5
assert f((1, 2, 3), (1, 2, 3)) == 0
|
benchmark_functions_edited/f245.py
|
def f(x, m, c):
return (m*x) + c
assert f(3, 2, 1) == 7
|
benchmark_functions_edited/f5473.py
|
def f(checker, value, context):
converted = checker(value, context)
if converted is None:
return value
return converted
assert f(lambda value, context: 1, str, 'context') == 1
|
benchmark_functions_edited/f4384.py
|
def f(num):
n = float(num)
if -32767 <= n <= 32767:
return int(n)
else:
raise ValueError("Out of range in Int (%s)" % n)
assert f("1.1") == 1
|
benchmark_functions_edited/f1192.py
|
def f(tws):
if tws > 25:
return 1
else:
return 0
assert f(20) == 0
|
benchmark_functions_edited/f14415.py
|
def f(flags):
# subtype flag : bits 10 to 12
return (flags & 3584) >> 9
assert f(0b11111110000000000000000000000000) == 0
|
benchmark_functions_edited/f10383.py
|
def f(list, num, default=None):
if num < len(list):
return list[num]
return default
assert f(list(range(10)), 2) == 2
|
benchmark_functions_edited/f289.py
|
def f(a):
if a > 3:
return 0
return 3 * a
assert f(1) == 3
|
benchmark_functions_edited/f12908.py
|
def f(slope, intercept, value):
return slope * float(value) + intercept
assert f(1, 3, 2) == 5
|
benchmark_functions_edited/f12510.py
|
def f(geoawi):
if geoawi == 0:
return 0
elif 1 <= geoawi <= 7:
return 1
elif geoawi == 8:
return 88
else:
raise KeyError('geoawi: %s' % geoawi)
assert f(3) == 1
|
benchmark_functions_edited/f3888.py
|
def f(conf_mtx):
[tp, fp], [fn, tn] = conf_mtx
a = tp + fn
return fn / a if a > 0 else 0
assert f( [[0,0],[0,0]] ) == 0
|
benchmark_functions_edited/f4431.py
|
def f(value: float) -> int:
return 0 if value < 0.0 else 100 if value > 100.0 else int(value)
assert f(-1.0) == 0
|
benchmark_functions_edited/f1966.py
|
def f(items):
if len(items) == 1:
return items[0]
return items[0] + f(items[1:])
assert f([1]) == 1
|
benchmark_functions_edited/f8195.py
|
def f(seq1, seq2):
if len(seq1) != len(seq2):
raise ValueError("Undefined for sequences of unequal length.")
return sum(bp1 != bp2 for bp1, bp2 in zip(seq1, seq2))
assert f(str(range(5)), str(range(6))) == 1
|
benchmark_functions_edited/f11964.py
|
def f(nums, lo, hi):
pivot = nums[hi]
i = lo
for j in range(lo, hi):
if nums[j] < pivot:
nums[i], nums[j] = nums[j], nums[i]
i += 1
nums[i], nums[hi] = nums[hi], nums[i]
return i
assert f(list(range(10)), 0, 9) == 9
|
benchmark_functions_edited/f6675.py
|
def f(Jp, J):
if Jp == J - 1:
return 1
elif Jp == J:
return 1 / (J + 1)
elif Jp == J + 1:
return -J / (J + 1)
else:
raise ValueError("Invalid input for function `la`")
assert f(0, 0) == 1
|
benchmark_functions_edited/f11368.py
|
def f(freq):
if 2412000000 <= freq <= 2472000000:
return 1 + int((freq - 2412000000) / (5 * 1000000))
if freq == 2484000000:
return 14
if 5035000000 <= freq <= 5825000000:
return 7 + int((freq - 5035000000) / (5 * 1000000))
return None
assert f(2412000000.25) == 1
|
benchmark_functions_edited/f9337.py
|
def f(street):
points = 0
for chip in street:
# print(chip[0])
points += chip[0]
return points
assert f(
[(0, 'A'), (0, 'K'), (0, 'Q'), (0, 'J'), (0, '10'), (0, '9'), (0, '8'), (0, '7'), (0, '6')]) == 0
|
benchmark_functions_edited/f2100.py
|
def f( x ):
if( x >= 0 ):
return 1
else:
return -1
assert f(5.12) == 1
|
benchmark_functions_edited/f3677.py
|
def f(y):
print("Inside func_b")
return y
assert f(1) == 1
|
benchmark_functions_edited/f10268.py
|
def f(common_tracks, homography_inliers):
outliers = common_tracks - homography_inliers
outlier_ratio = float(outliers) / common_tracks
if outlier_ratio > 0.3:
return common_tracks
else:
return 0
assert f(10, 100) == 0
|
benchmark_functions_edited/f380.py
|
def f(x):
#y : int
y = 1
#a : int
a = x + 1
return y
assert f(5) == 1
|
benchmark_functions_edited/f13554.py
|
def f(cell_state):
if type(cell_state) is tuple:
cell_state = cell_state[-1]
if hasattr(cell_state, "h"):
hidden_state = cell_state.h
else:
hidden_state = cell_state
return hidden_state
assert f(1) == 1
|
benchmark_functions_edited/f13527.py
|
def f(max_bits, num):
rev_num = 0
for i in range(0, (max_bits + 1) // 2):
high_shift = max_bits - i - 1
low_shift = i
low_bit = (num & (1 << low_shift)) >> low_shift
high_bit = (num & (1 << high_shift)) >> high_shift
rev_num |= low_bit << high_shift
rev_num |= high_bit << low_shift
return rev_num
assert f(6, 0) == 0
|
benchmark_functions_edited/f5731.py
|
def f(m):
n = 1
while (m + n/2) / n >= 10:
n*= 10
while (m + n/2) / n >= 5:
n*= 5
rm = m - (m/n)*n
return ((m+rm)/n)*n
assert f(4) == 4
|
benchmark_functions_edited/f115.py
|
def f(n1, n2):
return (int(n1) + int(n2)) % 2
assert f(0, 1) == 1
|
benchmark_functions_edited/f11946.py
|
def f(axis):
if isinstance(axis, str):
return ['x', 'y', 'z', 'a', 'b', 'c', 'u', 'v', 'w', 'all'].index(axis.lower())
return axis
assert f('u') == 6
|
benchmark_functions_edited/f6761.py
|
def f(nb_devices:int, d: int) -> int:
return nb_devices * d * 32
assert f(0, 0) == 0
|
benchmark_functions_edited/f10169.py
|
def f(n, compare):
if n == 0:
return compare
else:
if n % 10 > compare:
compare = n % 10
n = n // 10
return f(n, compare)
assert f(0, 1) == 1
|
benchmark_functions_edited/f13923.py
|
def f(As, RmS, FmGM):
# Tensile strength
FmS = RmS * As
#
#if FmS > FmGM :
# print('FmS [{}] > FmGM [{}] --> Fail'.format(FmS, FmGM ))
#else:
# print('FmS [{}] < FmGM [{}] --> Ok'.format(FmS, FmGM ))
#
return FmS
#
assert f(1, 2, 3) == 2
|
benchmark_functions_edited/f606.py
|
def f(i, j):
return 1 if i == j else 0
assert f(4, 1) == 0
|
benchmark_functions_edited/f3220.py
|
def f(n):
i = 0
j = 1
n = n - 1
while n >= 0:
i, j = j, i + j
n = n - 1
return i
assert f(4) == 3
|
benchmark_functions_edited/f8454.py
|
def f(x, y):
if x > 100 or x < 0 or y > 100 or y < 0:
raise ValueError("Passed in value out of bounds")
return x + y
assert f(2, 3) == 5
|
benchmark_functions_edited/f4707.py
|
def f(angles):
return (angles % 360 + 180) % 360 - 180
assert f(360) == 0
|
benchmark_functions_edited/f5406.py
|
def f(time1, time2):
time = min(time1, time2)
if time == 0:
return max(time1, time2) # if no time yet --> set the highest
return time
assert f(2, 2) == 2
|
benchmark_functions_edited/f11160.py
|
def f(x, *args):
fun = args[0]
more_args = args[1:] if len(args) > 1 else ()
return fun(x, *more_args)
assert f(1, lambda x, y: x + y, 1) == 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.