file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f957.py | def f(x):
return (x+180) % 360 - 180
assert f(1440) == 0 |
benchmark_functions_edited/f13724.py | def f(degree_sequence):
degree_sequence.sort()
return sum(degree_sequence[i]*10**i for i in range(len(degree_sequence)))
assert f( [1] ) == 1 |
benchmark_functions_edited/f8096.py | def f(time: str):
s = time.split(':')
seconds = float(s[2]) + float(s[1]) * 60 + float(s[0]) * 3600
return seconds
assert f('00:00:00') == 0 |
benchmark_functions_edited/f9052.py | def f(child_index):
# The root of the tree is at index position 1
# and can have no parent
if child_index == 1:
return 0
return child_index // 2
assert f(13) == 6 |
benchmark_functions_edited/f12857.py | def f(_string, symbols):
value = 0
base = len(symbols)
for i, c in enumerate(reversed(_string)):
value += symbols.index(c) * i**base
return value
assert f( '0', '0123456789' ) == 0 |
benchmark_functions_edited/f7665.py | def f(dictionary, keys, default=None):
if dictionary is None:
return default
if not keys:
return dictionary
return f(dictionary.get(keys[0]), keys[1:])
assert f(
{'x': {'y': {'z': 1}}},
['x', 'y', 'z']) == 1 |
benchmark_functions_edited/f13922.py | def f(railcar_number):
railcar_number = str( int( railcar_number) );
digit = 0
total = 0
for i in range(0, len(railcar_number), 1):
digit = int(railcar_number[i]) << (i & 1);
total += digit - (digit > 9) * 9;
#zero should be returned if the sum % 10 === 0
return 10 - (total % 10 or 10);
assert f(1439) == 9 |
benchmark_functions_edited/f13670.py | def f(e):
c = 3 * 10 ** 8
m = e / c ** 2
return m
assert f(0) == 0 |
benchmark_functions_edited/f4221.py | def f(num: float, min_num=1):
num = int(num)
if num < min_num:
return min_num
else:
return num
assert f(0.5) == 1 |
benchmark_functions_edited/f3703.py | def f(dictionary, key, default=None):
if key not in dictionary:
return default
return dictionary[key]
assert f(
{}, 'a', 0) == 0 |
benchmark_functions_edited/f5180.py | def f(routerName):
return int(routerName[1:])
assert f("a1") == 1 |
benchmark_functions_edited/f203.py | def f(ref, val):
return 100 if ref == val else 0
assert f(3, 4) == 0 |
benchmark_functions_edited/f8578.py | def f(list):
sum = 0
for value in list:
sum += value
return sum
assert f([1, 2, 3]) == 6 |
benchmark_functions_edited/f13789.py | def f(n, the_biggest):
if n == 0:
return the_biggest
else:
single_digit = n % 10
if single_digit > the_biggest:
the_biggest = single_digit
n = int((n - single_digit)/10)
return f(n, the_biggest)
assert f(12, 0) == 2 |
benchmark_functions_edited/f9231.py | def f(string: int, pos: int) -> int:
return int(string) & ~(1 << pos)
assert f(1, 2) == 1 |
benchmark_functions_edited/f4981.py | def f(k: int) -> int:
first = 0
second = 1
for _ in range(k):
first, second = second, first + second
return first
assert f(2) == 1 |
benchmark_functions_edited/f5599.py | def f(size, row, col):
return row + size*col
assert f(2, 1, 0) == 1 |
benchmark_functions_edited/f13170.py | def f(n):
# precondition
assert n >= 0, 'n must be a positive integer'
if n <= 1:
return n
else:
return f(n-1) + f(n-2)
assert f(6) == 8 |
benchmark_functions_edited/f1002.py | def f(t, r=0.01):
return 1 / (1 + r) ** t
assert f(0) == 1 |
benchmark_functions_edited/f3082.py | def f(value, key):
try:
return value[key]
except KeyError:
return ""
assert f(
{'a': 1, 'b': 2}, 'a'
) == 1 |
benchmark_functions_edited/f7718.py | def f(list1, list2):
intersection = len(list(set(list1).intersection((set(list2)))))
union = len(list1) + len(list2) - intersection
return float(intersection) / union
assert f(
['a', 'b', 'c'],
['d', 'e', 'f']
) == 0 |
benchmark_functions_edited/f2996.py | def f(a_pr_k, a, p):
return pow(a, a_pr_k) % p
assert f(6, 2, 11) == 9 |
benchmark_functions_edited/f2928.py | def f(obj, arg):
return obj[arg] if isinstance(arg, str) else arg
assert f(dict(), 1) == 1 |
benchmark_functions_edited/f7194.py | def f(seq, start_value=1):
if start_value not in seq:
return start_value
i = start_value
while i in seq:
i += 1
return i
assert f([1, 2], 3) == 3 |
benchmark_functions_edited/f6828.py | def f(n: int) -> int:
if not n >= 0:
raise ValueError
return 3*n**2 - 2*n
assert f(1) == 1 |
benchmark_functions_edited/f474.py | def f(x,n):
return x ^ ((1 << n) - 1)
assert f(5, 3) == 2 |
benchmark_functions_edited/f9060.py | def f(vp,rho):
ai = vp*rho
return (ai)
assert f(6,1) == 6 |
benchmark_functions_edited/f3108.py | def f(*keys):
for key in keys:
if key is not None:
return key
assert f(1, None, 3) == 1 |
benchmark_functions_edited/f2685.py | def f(n, N, pos):
return (n ^ (1 << (N-1-pos)))
assert f(0, 1, 0) == 1 |
benchmark_functions_edited/f9035.py | def f(value):
return 1 if value.lower() == 'true' else 0
assert f('True') == 1 |
benchmark_functions_edited/f8136.py | def f(total_value, total_activities):
if total_activities == 0:
return 0
activity_average = total_value / total_activities
return round(activity_average, 2)
assert f(10, 0) == 0 |
benchmark_functions_edited/f4813.py | def f(x, alpha, df0):
f = x
return alpha * f + df0
assert f(1, 0, 1) == 1 |
benchmark_functions_edited/f822.py | def f(x0, x1):
if x1 > x0:
return x1 - x0
else:
return 0
assert f(5, 10) == 5 |
benchmark_functions_edited/f8665.py | def f(path, value):
i = 0
if len(path) <= len(value):
for x1, x2 in zip(path, value):
if x1 == x2:
i += 1
else:
return 0
return i
assert f(list("aaa"), list("bbb")) == 0 |
benchmark_functions_edited/f12767.py | def f(month_name: str):
months = [
'january',
'february',
'march',
'april',
'may',
'june',
'july',
'august',
'september',
'october',
'november',
'december',
]
return months.index(month_name.lower())+1
assert f('june') == 6 |
benchmark_functions_edited/f13525.py | def f(expression, open_paren_index):
count = 1
for i in range(open_paren_index + 1, len(expression)):
if expression[i] == "(":
count += 1
elif expression[i] == ")":
count -= 1
if count == 0:
return i
if count < 0:
return -1
return -1
assert f(r"(()((()))))", 5) == 6 |
benchmark_functions_edited/f12528.py | def f(probs):
bias = 0
for idx in range(0, len(probs), 32):
bias -= probs[idx + 1] + probs[idx + 5] + probs[idx + 9] + probs[idx + 13]
bias += probs[idx + 18] + probs[idx + 22] + probs[idx + 26] + probs[idx + 30]
return bias / 8
assert f(list()) == 0 |
benchmark_functions_edited/f8754.py | def f( bit, byte ):
if bit < 0 or bit > 7:
print('Your bit of', bit, 'is out of range (0-7)')
print('returning 0')
return 0
return ((byte >> bit) & 0x01)
assert f(7, 0x80) == 1 |
benchmark_functions_edited/f8650.py | def f(smiles='', filename=''):
f = open(filename, 'w')
f.write(smiles)
f.close()
return 0
assert f('O=C=O', 'test.smi') == 0 |
benchmark_functions_edited/f2599.py | def f(obj, func, *args, **kwargs):
return getattr(obj, func)(*args, **kwargs)
assert f(15, 'bit_length') == 4 |
benchmark_functions_edited/f7560.py | def f(regex):
list_of_op = ["*","?","+","."]
index = -1
for i in range(len(regex)):
if(regex[i] in list_of_op):
index = i
break
return index
assert f(r"b*?b*?b") == 1 |
benchmark_functions_edited/f12503.py | def f(*values):
for value in values:
if value is not None:
return value
return None
assert f(None, None, 3) == 3 |
benchmark_functions_edited/f11650.py | def f(nb_days=4):
# 0 late : a, b, c for 0, 1, 2 consecutive absences
# 1 late : d, e, f for 0, 1, 2 consecutive absences
a, b, c, d, e, f = 1, 0, 0, 0, 0, 0
for _ in range(nb_days + 1): # 1 more iteration to have the res in d
a, b, c, d, e, f = a + b + c, a, b, a + b + c + d + e + f, d, e
return d
assert f(0) == 1 |
benchmark_functions_edited/f10947.py | def f(num_a, num_b):
num_a, num_b = max(num_a, num_b), min(num_a, num_b)
while num_b:
num_a, num_b = num_b, (num_a % num_b)
return num_a
assert f(5, 10) == 5 |
benchmark_functions_edited/f6600.py | def f(row, score_cols):
cutoffs = {'mpc':2, 'revel':.375, 'ccr':.9}
for col in score_cols:
if row[col] < cutoffs[col]:
return 0
return 1
assert f(
{
'mpc':0.125,
'revel':0.25,
'ccr':0.3
},
['mpc','revel', 'ccr']
) == 0 |
benchmark_functions_edited/f6887.py | def f(data):
text_hdr, integer_hdr, real_hdr = data['text_header'], \
data['integer_header'], data['real_header']
return 1
assert f(
{'text_header': {}, 'integer_header': {},'real_header': {'calib': 1}}) == 1 |
benchmark_functions_edited/f6787.py | def f(context, *infos):
messages = ["An error occurred when when " + context + ":"]
messages.extend(infos)
print("\n\t".join(map(str, messages)))
return 1
assert f(
"testing f()",
"An error occurred",
) == 1 |
benchmark_functions_edited/f5282.py | def f(bits: int, data: int) -> int:
return data | (data >> bits)
assert f(9, 0) == 0 |
benchmark_functions_edited/f7413.py | def f(days_birth, ranges):
age_years = -days_birth / 365
for label, max_age in enumerate(ranges):
if age_years <= max_age:
return label + 1
else:
return 0
assert f(62, [1, 10, 20]) == 1 |
benchmark_functions_edited/f8344.py | def f(res, flg, max_y):
test = res[-1][1 if flg == "y" else 0]
if (len(str(test)) if type(test) is str else test) > max_y:
max_y = len(str(test)) if type(test) is str else test
return max_y
assert f(
[[1, "a"], [2, "ab"], [3, "abc"]],
"y",
0,
) == 3 |
benchmark_functions_edited/f11927.py | def f(x, scale, offset, reverse=False):
if reverse:
return x / scale + offset
else:
return (x-offset) * scale
assert f(1, 1, 0) == 1 |
benchmark_functions_edited/f12549.py | def f(equation, val):
r1 = equation(val)
if r1 == None:
return None
r2 = equation(val - 1)
if r2 == None:
return None
if r1 == 1 and r2 == 0:
return 0
elif r1 >= 1:
return 1
else:
return -1
assert f(lambda x: 1, 1) == 1 |
benchmark_functions_edited/f11138.py | def f(*args):
# Note: some losses might be ill-defined in some scenarios (e.g. they may
# have inf/NaN gradients), in those cases we don't apply them on the total
# auxiliary loss, by setting their weights to zero.
return sum(x * w for w, x in args if w > 0)
assert f(
(0, 1),
(1, 2),
(0, 3),
(0, 4),
(0, 5)) == 2 |
benchmark_functions_edited/f2603.py | def f(objs, default=""):
if len(objs) > 0:
return objs[0]
return default
assert f([1, 2, 3]) == 1 |
benchmark_functions_edited/f3696.py | def f(field):
if field == "-":
return 0
return int(field)
assert f("3") == 3 |
benchmark_functions_edited/f5024.py | def f(coord1, coord2):
(x1, y1) = coord1
(x2, y2) = coord2
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)
assert f( (0,1), (0,2) ) == 1 |
benchmark_functions_edited/f127.py | def f(x):
return (3*x**2)
assert f(0) == 0 |
benchmark_functions_edited/f3183.py | def f(x):
from numpy import rint
x = rint(x)
try: x = int(x)
except: x = 0
return x
assert f(1.6) == 2 |
benchmark_functions_edited/f3745.py | def f(x, centre):
centre = 80
y = 1 / centre * (x - centre) ** 2
return int(y)
assert f(80, 80) == 0 |
benchmark_functions_edited/f13039.py | def f(list, value):
left, right = 0, len(list)-1
while left <= right:
mid = (left+right)//2
if list[mid] == value:
return mid #Returning the index
if list[mid] < value:
left = mid + 1
else:
right = mid - 1
return -1
assert f([1], 1) == 0 |
benchmark_functions_edited/f9029.py | def f(delivery_list):
packages_count = 0
for delivery in delivery_list:
packages_count += len(delivery.packages)
return packages_count
assert f([]) == 0 |
benchmark_functions_edited/f3404.py | def f(v1, v2):
return (sum([(v1[i]-v2[i])**2 for i in range(len(v1))])/len(v1))**(1/2)
assert f(
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]
) == 0 |
benchmark_functions_edited/f1960.py | def f(func, iterable):
return next(iter(filter(func, iterable)))
assert f(lambda x: x >= 0, [1, 2, 3]) == 1 |
benchmark_functions_edited/f10346.py | def f(char):
base = 26 # 26 letters from A to Z
digit = 0
pos = 0
for c in reversed(char):
val = ord(c) - ord('A') + 1
pos += pow(base, digit) * val
digit += 1
return pos - 1
assert f(str('B')) == 1 |
benchmark_functions_edited/f2429.py | def f(n: int) -> int:
return (n * (n - 1)) + 1
assert f(1) == 1 |
benchmark_functions_edited/f718.py | def f(x):
return (x < 0.) * -1. + (x >= 0) * 1.
assert f(42) == 1 |
benchmark_functions_edited/f1137.py | def f(a, b):
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
assert f( [1, 0, 0], [0, 1, 0] ) == 0 |
benchmark_functions_edited/f1163.py | def f(acc, elem):
return acc + int(elem[0]) if elem[0] == elem[1] else acc
assert f(0, ('a', 'b')) == 0 |
benchmark_functions_edited/f14190.py | def f(obj):
if not isinstance(obj, list):
return 1
elif obj == []:
return 0
else:
return sum([f(item) for item in obj])
assert f([]) == 0 |
benchmark_functions_edited/f3319.py | def f(recall):
return ((recall*10)//1)*10
assert f(0.01) == 0 |
benchmark_functions_edited/f6836.py | def f(value, min, max):
return round((value - min) / (max - min), 3)
assert f(2, 1, 2) == 1 |
benchmark_functions_edited/f11264.py | def f(watts):
return(watts / 745.699872)
assert f(0) == 0 |
benchmark_functions_edited/f7205.py | def f(text, pattern):
i = 0
n = 0
while i <= len(text) - len(pattern):
if text[i:i+len(pattern)] == pattern:
n = n + 1
i = i + 1
return n
assert f("a", "aaa") == 0 |
benchmark_functions_edited/f12525.py | def f(x):
# Check that x is positive
if x < 0:
print("Error negative value supplied")
return -1
else:
print("Here we go..")
# Initial guess for the square root
z = x / 2.0
# Continuously improve the guess
while abs(x -(z*z)) > 0.00001:
z = z - ((z*z) - x) / (2 * z)
return z
assert f(0) == 0 |
benchmark_functions_edited/f2981.py | def f(x):
x_zero = 0.1234
return (x - x_zero)*(x - x_zero)
assert f(0.1234) == 0 |
benchmark_functions_edited/f5125.py | def f(consensi):
return sum(cssChunk.refWindow[2] - cssChunk.refWindow[1]
for cssChunk in consensi)
assert f([]) == 0 |
benchmark_functions_edited/f7228.py | def f(data):
data = data
data.sort()
return data[len(data)-1] - data[0]
assert f([1]) == 0 |
benchmark_functions_edited/f3480.py | def f(*args):
for arg in args:
if arg is not None:
return arg
assert f(None, None, 1, None) == 1 |
benchmark_functions_edited/f9564.py | def f(values):
values = sorted(values)
if len(values) % 2:
return values[len(values) // 2]
else:
return (values[len(values) // 2 - 1] + values[len(values) // 2]) / 2
assert f([0]) == 0 |
benchmark_functions_edited/f1999.py | def f(ranking):
if len(ranking) < 1: return 0
if int(ranking[0]) >= 4: return 1
else: return 0
assert f([4]) == 1 |
benchmark_functions_edited/f9878.py | def f(n: int) -> int:
if n == 1:
return 0
x = 0
while True:
if n % 2 == 0:
n //= 2
else:
n = 3 * n + 1
x += 1
if n < 2:
break
return x
assert f(4) == 2 |
benchmark_functions_edited/f13529.py | def f(val):
if isinstance(val, int):
return val
if val is None:
return 0
# Otherwise, val must be a string, since that's the only other kind of data
# type that we can create. Strip out all non-digit characters.
new_val = "".join([c for c in val if c in map(str, list(range(10)))])
if new_val == "":
return 0
return int(new_val)
assert f(False) == 0 |
benchmark_functions_edited/f2660.py | def f(int_type, offset):
mask = 1 << offset
return int_type | mask
assert f(0, 2) == 4 |
benchmark_functions_edited/f3460.py | def f(n: int) -> int:
assert n >= 0
return 1 if n in [0, 1] else f(n - 1) + f(n - 2)
assert f(2) == 2 |
benchmark_functions_edited/f7484.py | def f(predicate, seq):
for x in seq:
if not predicate(x):
return False
return True
assert f(callable, [min, max]) == 1 |
benchmark_functions_edited/f10782.py | def f(values):
res = sum(values) / len(values)
if res == int(res):
return int(res)
return res
assert f([1]) == 1 |
benchmark_functions_edited/f12954.py | def f(a, b):
a = set(a)
b = set(b)
intersection = len(a.intersection(b))
union = len(a.union(b))
return intersection / union
assert f({'a', 'b', 'c'}, {'a', 'b', 'c'}) == 1 |
benchmark_functions_edited/f4760.py | def f(d):
return next(iter(d.values())) if isinstance(d, dict) else d[0]
assert f([1, 2]) == 1 |
benchmark_functions_edited/f2111.py | def f(x, a, b, c):
return x ** 2 + (a * x ** 2 + b * x + c) ** 2
assert f(-1, 0, 0, 0) == 1 |
benchmark_functions_edited/f4712.py | def f(a_dict: dict):
val_list = list(a_dict.values())
return max(set(val_list), key=val_list.count)
assert f(
{
'a': 2,
'b': 1,
}
) == 1 |
benchmark_functions_edited/f377.py | def f(x,kwargs):
return x if x not in kwargs else kwargs[x]
assert f(1, {}) == 1 |
benchmark_functions_edited/f10825.py | def f(counters):
used = counters['total'] - counters['free'] - \
counters['buffers'] - counters['cached']
total = counters['total']
# return used*100 / total
return used / total
assert f({'total': 1000, 'free': 1000, 'buffers': 0, 'cached': 0}) == 0 |
benchmark_functions_edited/f6227.py | def f(distance, y_max, y_min, focal_y):
px_height = y_max - y_min
person_height = distance * px_height / focal_y
return person_height
assert f(0, 0, 0, 2000) == 0 |
benchmark_functions_edited/f7407.py | def f(dataset):
return len(list(dataset.keys()))
assert f({'cat': []}) == 1 |
benchmark_functions_edited/f10143.py | def f(work):
count = 0
for entry in work:
count += len(work[entry])
return count
assert f({}) == 0 |
benchmark_functions_edited/f106.py | def f(xs, **unused_kwargs):
return xs[0] + xs[1]
assert f([3, 4]) == 7 |
benchmark_functions_edited/f10510.py | def f(mass, velocity):
return (1/2) * mass * velocity**2
assert f(10, 0) == 0 |
benchmark_functions_edited/f6090.py | def f(x: tuple, center: tuple, old_len, new_len):
first = old_len/new_len
second = (x[0] - center[0])**2 + (x[1] - center[1])**2
a = first * second
return a
assert f(
(1, 1),
(1, 1),
1,
1
) == 0 |
benchmark_functions_edited/f11106.py | def f(data: list, left: int, right: int, key: str) -> int:
while right >= left:
mid = (left + right) // 2
if data[mid] == key:
return mid
elif key < data[mid]:
right = mid - 1
else:
left = mid + 1
return -1
assert f(
["A", "B", "C", "D", "E", "F", "G", "H"], 0, 7, "A") == 0 |
benchmark_functions_edited/f10758.py | def f(*vals): # eager, bodys already evaluated when this is called
return vals[0] if len(vals) else None
assert f(4, 2, 1, 0, 20) == 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.