file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f8418.py
|
def f(a, b):
if a <= 0 or b <= 0:
raise ValueError('Arguments must be positive integers')
while b != 0:
tmp = b
b = a % b
a = tmp
return a
assert f(12, 8) == 4
|
benchmark_functions_edited/f12668.py
|
def f(endclasses):
return sum([e['expected cost'] for k,e in endclasses.items()])
assert f({'a': {'expected cost': 1, 'expected count': 1}}) == 1
|
benchmark_functions_edited/f8622.py
|
def f(l):
if l < 0:
raise ValueError("The side length must be >= 0.")
A = l**2
return A
assert f(0) == 0
|
benchmark_functions_edited/f9513.py
|
def f(nums):
import collections
dup_num = None
count = collections.Counter(nums)
for num in count:
if count[num] > 1:
dup_num = num
break
return dup_num
assert f([1, 2, 2, 3, 3]) == 2
|
benchmark_functions_edited/f615.py
|
def f(name):
return ' KQRBNPkqrbnp'.find(name)
assert f('K') == 1
|
benchmark_functions_edited/f9166.py
|
def f(port_num):
return (port_num >> 11) & 0xF
assert f(17) == 0
|
benchmark_functions_edited/f3492.py
|
def f(x, y):
return x[y] if y in x else ''
assert f( {'a': 1, 'b': 2}, 'b' ) == 2
|
benchmark_functions_edited/f7077.py
|
def f(value):
try:
x = float(value)
if x > 0:
return x ** (1/2)
else:
return "ERROR"
except ValueError:
return "ERROR"
assert f(16) == 4
|
benchmark_functions_edited/f6315.py
|
def f(iterable_or_dict, index, default=None):
try:
return iterable_or_dict[index]
except (IndexError, KeyError):
return default
assert f(range(10), -3, 'none') == 7
|
benchmark_functions_edited/f10654.py
|
def f(num, length, value=1):
one_count = 0
curr_length = length
while num and curr_length:
one_count += 1 & num
num >>= 1
curr_length -= 1
if value:
return one_count
else:
return length - one_count
assert f(1, 1) == 1
|
benchmark_functions_edited/f3061.py
|
def f(values):
size = len(values)
if size==0:
return ValueError
return sum(values)/float(size)
assert f(range(1,2)) == 1
|
benchmark_functions_edited/f1025.py
|
def f(term):
return len(term.split(' '))
assert f('This is another example.') == 4
|
benchmark_functions_edited/f13249.py
|
def f(left: float, right: float, x_and_y: float) -> float:
# Need to subtract `x_and_y` since it is counted twice in `left` and `right`
return left + right - x_and_y
assert f(0, 1, 0) == 1
|
benchmark_functions_edited/f4001.py
|
def f(val, place):
place_val = 2**place
return val & place_val != 0
assert f(0xFF, 2) == 1
|
benchmark_functions_edited/f10195.py
|
def f(lmax):
n3j=0
for l1 in range(lmax+1):
for l2 in range(l1+1):
for m2 in range(-l2,l2+1):
#for l3 in range(l2+1): n3j=n3j + (2*l3+1)
n3j=n3j + (l2+1)**2
return n3j
assert f(0) == 1
|
benchmark_functions_edited/f7250.py
|
def f(value, min_, max_):
width = max_ - min_
while value < min_ or value > max_:
if value < min_:
value += width
else:
value -= width
return value
assert f(15, 0, 2) == 1
|
benchmark_functions_edited/f13591.py
|
def f(s, f):
if isinstance(s, list):
return [f(_, f) for _ in s]
if isinstance(s, tuple):
return tuple([f(_, f) for _ in s])
if isinstance(s, dict):
return {f(k, f): f(v, f) for k, v in s.items()}
return f(s)
assert f(1, lambda _: 0) == 0
|
benchmark_functions_edited/f9567.py
|
def f(a: int, b: int, k: int) -> int:
count = (b - a + 1) // k
if b % k == 0:
count += 1
return count
assert f(3, 3, 3) == 1
|
benchmark_functions_edited/f12430.py
|
def f(n):
a = 0
b = 1
total = 0
if a < 0:
print("input smaller than zero")
elif n == 0:
return a
elif n == 1:
return b
else:
while total < n:
c = a + b
a = b
b = c
if b % 2 == 0:
total += b
# print(b)
return total
assert f(0) == 0
|
benchmark_functions_edited/f4611.py
|
def f(x, y=None, dx=None, dy=None):
if dx is None:
dx = 0
return dx
assert f(1, 0, 0) == 0
|
benchmark_functions_edited/f11628.py
|
def f(choices):
def length(item):
if isinstance(item, str):
value = item
else:
value = item[0]
return len(value)
return max((length(c) for c in choices))
assert f(tuple(("abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "yz", "123", "456"))) == 3
|
benchmark_functions_edited/f8284.py
|
def f(word, letter, start_index):
index = start_index
while index < len(word):
if word[index] == letter:
return index
index += 1
return -1
assert f(
"hello world",
"o",
5
) == 7
|
benchmark_functions_edited/f12442.py
|
def f(result, base_key, count):
failures = 0
base_keys = base_key.split(",")
for base_key in base_keys:
for i in range(1, count):
key = base_key.replace("[i]", str(i))
if key in result:
failures += str(result[key]).count('x')
return failures
assert f(
{'a[1]': 'x', 'b[1]': 'x', 'c[1]': 'x', 'd[1]': 'y'},
'a[i],b[i],c[i],d[i]',
5) == 0
|
benchmark_functions_edited/f4174.py
|
def f(v):
try:
v = int(v)
except ValueError as e:
v = float(v)
return v
assert f('5') == 5
|
benchmark_functions_edited/f12137.py
|
def f(arr, k):
if len(arr) < 2:
return arr
pivot = arr[0]
left = [x for x in arr[1:] if x < pivot]
right = [x for x in arr[1:] if x >= pivot]
if k <= len(left):
return f(left, k)
elif k > len(left) + 1:
return f(right, k - len(left) - 1)
else:
return pivot
assert f(list(range(1, 11)), 1) == 1
|
benchmark_functions_edited/f2894.py
|
def f(begin, end):
t = 0
for i in range(begin, end):
t += i
return t**2
assert f(1, 2) == 1
|
benchmark_functions_edited/f4441.py
|
def f(start, stop, step):
n = 0
if start < stop:
n = ((stop - start - 1) // step + 1);
return n
assert f(5, 10, 3) == 2
|
benchmark_functions_edited/f636.py
|
def f(s1, s2):
return (s1 + s2) / 2
assert f(1, 3) == 2
|
benchmark_functions_edited/f4940.py
|
def f(wealth, saturation):
return min(wealth, saturation)
assert f(100, 0) == 0
|
benchmark_functions_edited/f11119.py
|
def f(dim_size, chunks):
return (dim_size + chunks - 1) // chunks
assert f(3, 4) == 1
|
benchmark_functions_edited/f7915.py
|
def f(a, b):
c = a^b
count=0
while c:
if c&1:
count+=1
c=c>>1
return count
assert f(1, 0) == 1
|
benchmark_functions_edited/f3039.py
|
def f(value, name):
if value is None:
raise ValueError(f"`{name}` must be specified.")
return value
assert f(1, "and") == 1
|
benchmark_functions_edited/f326.py
|
def f(f, x ,y):
return f(x, y)
assert f(lambda x, y: x * y * x * y, 1, 2) == 4
|
benchmark_functions_edited/f12841.py
|
def f(data_object, sample, delta=None):
hdr = data_object['HEADER']
if delta is None:
delta = hdr['TIME']['DELTA']
start = hdr['TIME']['START']
return start + delta * sample
assert f({'HEADER': {'TIME': {'START': 2, 'DELTA': 1}}}, 1) == 3
|
benchmark_functions_edited/f14514.py
|
def f(cam_list):
cu = 0
c1 = cam_list[0]
c2 = cam_list[1]
c3 = cam_list[2]
# compare lengths
if len(c1) == len(c2) == len(c3):
cu = 0
else:
print('Not enough video File(s) are available')
cu = 1
return cu
assert f(
["190914_165846_Cam_A", "190914_165846_Cam_B", "190914_165846_Cam_C"]) == 0
|
benchmark_functions_edited/f8958.py
|
def f(num):
num = str(num).strip()
base = 10
if (num[0] == '0') & (len(num) > 1):
if num[1] == 'x':
base = 16
elif num[1] == 'b':
base = 2
else:
base = 8
return int(num, base)
assert f(0o10) == 8
|
benchmark_functions_edited/f2455.py
|
def f(number: int) -> int:
if number < 0:
return -1
else:
return 1
assert f(5) == 1
|
benchmark_functions_edited/f13805.py
|
def f(values,delimiter = " "):
enteredValues=values.split(" ")
x=0
for value in range(len(enteredValues)):
x=x+len(enteredValues[value])
return x/len(enteredValues)
assert f("One") == 3
|
benchmark_functions_edited/f11390.py
|
def f(s, breaks, matrix, memo):
b = len(breaks)
if b == 0 or s <= breaks[0]:
return s * matrix[0]
for i in range(1, b + 1):
if i == b or s <= breaks[i]:
j = (i - 1) * 2
return memo[j] + s * matrix[i] - memo[j + 1]
assert f(1, [], [1], {}) == 1
|
benchmark_functions_edited/f10582.py
|
def f(List):
sorted = 1;
for index in range(0, len(List)-1):
if List[index] > List[index + 1]:
sorted = 0;
return sorted;
assert f( [2, 1, 5, 3] ) == 0
|
benchmark_functions_edited/f11961.py
|
def f(actual_readings, predicted_readings):
square_error_total = 0.0
total_readings = len(actual_readings)
for i in range(0, total_readings):
error = predicted_readings[i] - actual_readings[i]
square_error_total += pow(error, 2)
rmse = square_error_total / float(total_readings)
return rmse
assert f(list(range(0, 10)), list(range(0, 10))) == 0
|
benchmark_functions_edited/f10478.py
|
def f(s):
strHash = 0
multiplier = 37
for c in s:
strHash = strHash * multiplier + ord(c)
#Only keep the last 64bit, since the mod base is 100
strHash = strHash % (1<<64)
return strHash % 100
assert f('') == 0
|
benchmark_functions_edited/f2201.py
|
def f(kv, key):
return int(kv.get("labs:"+str(key), 0))
assert f(dict(), 1) == 0
|
benchmark_functions_edited/f7313.py
|
def f(i, deps, data):
if i == -1:
return 0
valency = len(deps[i])
if not valency:
return 0
else:
return valency
assert f(0, [[1,2], [], [3], [4], [5]], None) == 2
|
benchmark_functions_edited/f5451.py
|
def f(n):
u = 1
v = 1
j = 2
while len(str(v)) < n:
u, v = v, u+v
j += 1
return j
assert f(1) == 2
|
benchmark_functions_edited/f13578.py
|
def f(bcdict, bc="bc.dyn"):
with open(bc, 'w') as bcf:
bcf.write("$ Generated using bc.py\n")
bcf.write('*BOUNDARY_SPC_NODE\n')
for i in bcdict:
bcf.write(f'{i},0,')
bcf.write(f'{bcdict[i]}\n')
bcf.write('*END\n')
return 0
assert f({"1": "1", "2": "2", "3": "3", "4": "4"}) == 0
|
benchmark_functions_edited/f3248.py
|
def f(text):
return int(text) if text.isdigit() else text
assert f('2') == 2
|
benchmark_functions_edited/f13265.py
|
def f(seen_doc, unseen_doc):
similarity = 0
for w,score in seen_doc.items():
if w in unseen_doc:
similarity += score * unseen_doc[w]
return similarity
assert f( {"a": 1, "b": 2, "c": 3}, {"d": 4, "e": 5, "f": 6} ) == 0
|
benchmark_functions_edited/f9915.py
|
def f(s, *args):
return s.f(*args)
assert f(u'hello', u'he', 0, 1000) == 0
|
benchmark_functions_edited/f14497.py
|
def f(data):
n = len(data)
sum1 = 0
sum2 = 0
for i in range(n):
if i > 0:
sum1 += abs(data[i-1] - data[i])
sum2 += data[i]
sum1 /= float(n - 1)
sum2 /= float(n)
return 1000.0 * sum1 / sum2
assert f( [0.1, 0.1, 0.1] ) == 0
|
benchmark_functions_edited/f6542.py
|
def f(x):
val = x
while True:
last = val
val = (val + x / val) * 0.5
if abs(val - last) < 1e-9:
break
return val
assert f(4) == 2
|
benchmark_functions_edited/f6818.py
|
def f(msb: int, lsb: int, index: int) -> int:
if lsb > msb:
return index - msb
return msb - index
assert f(2, 0, 2) == 0
|
benchmark_functions_edited/f7534.py
|
def f(val, in_list):
try:
return in_list.index(val)
except ValueError:
return -1
assert f('two', ['one', 'two', 'three']) == 1
|
benchmark_functions_edited/f7230.py
|
def f(obs):
valid_actions = obs['valid_actions']
ms1_action = len(valid_actions) - 1 # last index is always the action for MS1 scan
return ms1_action
assert f(
{'valid_actions': [0, 1, 2, 3],'ms1_intensities': [1.0, 2.0, 3.0, 4.0],
'ms1_mzs': [100, 200, 300, 400]}) == 3
|
benchmark_functions_edited/f3349.py
|
def f(num):
acc = 0
for i in range(1, num):
if num % i == 0:
acc += i
return acc
assert f(0) == 0
|
benchmark_functions_edited/f6214.py
|
def f(teststr, testchar):
count = 0
x = len(teststr) - 1
while x >= 0 and teststr[x] == testchar:
count += 1
x -= 1
return count
assert f("abcabc", "z") == 0
|
benchmark_functions_edited/f559.py
|
def f(w, num_cores):
del num_cores
return w
assert f(2, 2) == 2
|
benchmark_functions_edited/f2842.py
|
def f(pc1, pc2):
return (pc2-pc1) % 12 if pc2 >= pc1 else (pc2+12) - pc1
assert f(60, 62) == 2
|
benchmark_functions_edited/f13641.py
|
def f(index, offsets):
bottom = 0
top = len(offsets) - 1
if index > offsets[top]:
return top
while top - bottom > 1:
mid = (top + bottom) // 2
if index >= offsets[mid]:
bottom = mid
else:
top = mid
return bottom
assert f(0, [0, 3, 5]) == 0
|
benchmark_functions_edited/f4491.py
|
def f(l: list) -> int:
_l = list(l)
max1 = max(_l)
_l.remove(max1)
max2 = max(_l)
return max1 + max2
assert f([-1, 0, 1]) == 1
|
benchmark_functions_edited/f5827.py
|
def f(el1, el2):
pair = el1 + el2
return int(pair == 'AU' or
pair == 'UA' or
pair == 'GC' or
pair == 'CG')
assert f('A', 'U') == 1
|
benchmark_functions_edited/f11407.py
|
def f(a):
prod = 1
for e in a:
prod *= e
return prod
assert f(list(range(3))) == 0
|
benchmark_functions_edited/f11506.py
|
def f(commands):
horizontal_position = commands.get('forward', 0)
depth = commands.get('down', 0) - commands.get('up', 0)
result = horizontal_position * depth
return result
assert f(dict()) == 0
|
benchmark_functions_edited/f956.py
|
def f(dist, r):
return 1 if dist <= r else 0
assert f(0, 1) == 1
|
benchmark_functions_edited/f7341.py
|
def f(candidate, ideal):
fitness_score = 0
for i in range(len(ideal)):
if candidate[i] == ideal[i]:
fitness_score += 1
return fitness_score
assert f([0, 0, 0], [0, 0, 0]) == 3
|
benchmark_functions_edited/f3725.py
|
def f(arr, index, default=None):
if index >= len(arr):
return default
return arr[index]
assert f(range(3), 1, 'default') == 1
|
benchmark_functions_edited/f1048.py
|
def f(dim):
return int(dim * (dim + 1) / 2)
assert f(2) == 3
|
benchmark_functions_edited/f13800.py
|
def f(abs_val: int, max_unit: int, abs_limit: int) -> int:
inc = abs_limit / max_unit
return int(abs_val / inc)
assert f(0, 5, 5) == 0
|
benchmark_functions_edited/f8836.py
|
def f(spaces):
value = 0
for char in spaces:
value += (8 - (value % 8)) if char == '\t' else 1
return value
assert f(' ') == 6
|
benchmark_functions_edited/f8254.py
|
def f(N, n):
return int(str(N)[n])
assert f(12345, 2) == 3
|
benchmark_functions_edited/f14087.py
|
def f(val, divisor, round_up_bias=0.9):
assert 0.0 < round_up_bias < 1.0
new_val = max(divisor, int(val + divisor / 2) // divisor * divisor)
return new_val if new_val >= round_up_bias * val else new_val + divisor
assert f(5, 3) == 6
|
benchmark_functions_edited/f7721.py
|
def f(x, offset=1):
y = 0
x2 = x + x[:offset] # Lists are concatenated, but they take memory
for i in range(len(x)):
if x2[i] == x2[i+offset]:
y += int(x2[i])
return y
assert f(list('1234')) == 0
|
benchmark_functions_edited/f9724.py
|
def f(datetime_in):
try:
return int((datetime_in.month-1)/3)+1
except AttributeError:
pass
return int((datetime_in-1)/3)+1
assert f(8) == 3
|
benchmark_functions_edited/f13209.py
|
def f(n):
high = (n // 2) + 1
low = 0
while low < high:
mid = (low + high) // 2
if mid ** 3 < n:
# mid works, but higher option might work too
low = mid + 1
else:
# don't rule out this option, because mid ** 3 could be equal to n
high = mid
return low
assert f(10) == 3
|
benchmark_functions_edited/f10109.py
|
def f(dict_o_lists):
counter = 0
for entry in dict_o_lists:
counter += len(dict_o_lists[entry])
return counter
assert f( {} ) == 0
|
benchmark_functions_edited/f3586.py
|
def f(strokes):
n_points = 0
for x, y in strokes:
n_points += len(x)
return n_points
assert f(
[]
) == 0
|
benchmark_functions_edited/f12708.py
|
def f(level, maxval):
return int(level * maxval / 10)
assert f(3, 10) == 3
|
benchmark_functions_edited/f4472.py
|
def f(seq, items):
for i, s in enumerate(seq):
if s in items:
return i
assert f(range(10), {3, 5, 8}) == 3
|
benchmark_functions_edited/f1073.py
|
def f(content):
result = content['result']
return result
assert f({'result': 1}) == 1
|
benchmark_functions_edited/f7859.py
|
def f(observed, expected, N, denom):
x = float(observed - expected) / float(N)
return x / denom
assert f(0, 0, 1000, 1000) == 0
|
benchmark_functions_edited/f7739.py
|
def f(records, user):
if len(records) == 0:
return 0
initiated = sum(1 for r in records if r.direction == 'out')
return initiated / len(records)
assert f(
[],
'<EMAIL>'
) == 0
|
benchmark_functions_edited/f14072.py
|
def f(testlist, dim=0):
if isinstance(testlist, list):
if testlist == []:
return dim
dim = dim + 1
dim = f(testlist[0], dim)
return dim
else:
if dim == 0:
return -1
else:
return dim
assert f([[1]]) == 2
|
benchmark_functions_edited/f7307.py
|
def f(n, p):
if p > n:
return 0
if p > n//2:
return 1
q, m = n, 0
while q >= p:
q //= p
m += q
return m
assert f(5, 3) == 1
|
benchmark_functions_edited/f14529.py
|
def f(seq, fn):
if len(seq) == 1:
return seq[0]
best = -1
best_score = float("-inf")
for x in seq:
x_score = fn(x)
if x_score > best_score:
best, best_score = x, x_score
elif x_score == best_score:
best, best_score = 2, x_score
return best
assert f(range(4), lambda x: x * x) == 3
|
benchmark_functions_edited/f7040.py
|
def f(stems, stem_energies):
free_energy = 0.0
for stem in stems:
free_energy += stem_energies[stem]
return(free_energy)
assert f(set(['B']), {'A': 1, 'B': 2, 'C': 3}) == 2
|
benchmark_functions_edited/f5034.py
|
def f(value: float, units: str) -> float:
if units == 'english':
return value / 3.2808
else:
return value
assert f(1,'metric') == 1
|
benchmark_functions_edited/f448.py
|
def f(m):
return m['mu11']/m['mu02']
assert f( {'mu00': 2,'mu11': 0,'mu20': 3,'mu02': 2}) == 0
|
benchmark_functions_edited/f12382.py
|
def f(x):
return (((x[0]+abs(x[1]))*100)/100)/10
assert f( [0, 0, 0, 0, 0]) == 0
|
benchmark_functions_edited/f3337.py
|
def f(z):
TS=1
return TS
assert f(16) == 1
|
benchmark_functions_edited/f623.py
|
def f(a, b, t):
return (1.0 - t) * a + t * b;
assert f(0, 10, 0.5) == 5
|
benchmark_functions_edited/f11054.py
|
def f(x,p0,p1,p2):
return p0 / (1+(x/p1)**2)**p2
assert f(0,1,1,1) == 1
|
benchmark_functions_edited/f10262.py
|
def f(string):
digits = list(map(int, string))
odd_sum = sum(digits[-1::-2])
even_sum = sum([sum(divmod(2 * d, 10)) for d in digits[-2::-2]])
return (odd_sum + even_sum) % 10
assert f(list('5105105105105100')) == 0
|
benchmark_functions_edited/f13747.py
|
def f(line, allow_spaces=0):
if not line:
return 1
if allow_spaces:
return line.rstrip() == ""
return line[0] == "\n" or line[0] == "\r"
assert f('\r') == 1
|
benchmark_functions_edited/f12102.py
|
def f(bv1, bv2):
if len(bv1) != len(bv2):
raise Exception("fail: bitvectors of different length "+\
str(len(bv1))+", "+str(len(bv2)))
total = 0
for i, bit in enumerate(bv1):
if bit != bv2[i]:
total += 1
return total
assert f( [1,1,0], [1,0,1]) == 2
|
benchmark_functions_edited/f7593.py
|
def f(position) :
# Calculate the index
diag_index = (position[1] - position[0]) // 2
# Return the index
return diag_index
assert f( (1, 1) ) == 0
|
benchmark_functions_edited/f5674.py
|
def f(value, another):
# Do something with these values
# and more comment text, here.
#
if value:
return 2
# Another comment
return 1
assert f(None, None) == 1
|
benchmark_functions_edited/f2110.py
|
def f(x):
try: return int(x)
except: return 0
assert f("0") == 0
|
benchmark_functions_edited/f13715.py
|
def f(img_name):
bk = 0
#Find where the significant digit appears
prefix = img_name.split('.')[0][3:]
for idx,alpha in enumerate(prefix):
if int(alpha) == 0:
continue
else:
bk = idx
break
num = int(prefix[bk:]) - 1 #Since image names start from 1
return num
assert f(
'000000001.png') == 0
|
benchmark_functions_edited/f8426.py
|
def f(output_list):
lastindex = 0
for index, block in enumerate(output_list):
if block[0] == "inputBlock":
lastindex = index
return lastindex + 1
assert f(
[
("inputBlock", None, "foo", None),
]
) == 1
|
benchmark_functions_edited/f3132.py
|
def f(**kwargs):
ndisplay = kwargs.get("nDisplay", 10)
return ndisplay
assert f(**{"nDisplay": 1}) == 1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.