file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f1169.py | def f(numbers):
return float(sum(numbers)) / max(len(numbers), 1)
assert f(range(1, 4)) == 2 |
benchmark_functions_edited/f13096.py | def f(rval):
if isinstance(rval, str):
return str(rval)
elif isinstance(rval, tuple):
return tuple([f(x) for x in rval])
elif isinstance(rval, list):
return [f(x) for x in rval]
elif isinstance(rval, dict):
return { f(key):f(val) for (key, val) in rval.items()}
else:
return rval
assert f(0) == 0 |
benchmark_functions_edited/f7811.py | def f(diagName,fldLst):
if diagName in str(fldLst):
j = fldLst.index(diagName)
else:
j = -1
return j
assert f("name", ["name"]) == 0 |
benchmark_functions_edited/f10073.py | def f(number: int) -> int:
if number == 1:
return 1
elif number == 2:
return 2
total = 0
last = 0
current = 1
for _ in range(1, number):
total = last + current
last = current
current = total
return total
assert f(2) == 2 |
benchmark_functions_edited/f7873.py | def f(a, b):
_cl = (a / 255) ** ((255 - b) / 128) * 255
_ch = (a / 255) ** (128 / b) * 255
return _cl * (b < 128) + _ch * (b >= 128)
assert f(0, 1) == 0 |
benchmark_functions_edited/f5308.py | def f(value):
if value is None or value == "checkpoint":
return value
else:
return int(value)
assert f(5) == 5 |
benchmark_functions_edited/f12026.py | def f(s: str, pat: str) -> int:
for count, (c, p) in enumerate(zip(s, pat)):
if p in "*#":
return count
if c != p:
return -1
return len(s)
assert f( "ab", "a#" ) == 1 |
benchmark_functions_edited/f14171.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('A B') == 0 |
benchmark_functions_edited/f1956.py | def f(value, arg):
if value is None:
return arg
return value
assert f(None, 0) == 0 |
benchmark_functions_edited/f1845.py | def f(y):
return sum(y)/len(y)
assert f([1, 2, 3]) == 2 |
benchmark_functions_edited/f2215.py | def f(value: str) -> int:
if len(value) > 3:
raise ValueError("base25 input too large")
return int(value, 25)
assert f(b"0") == 0 |
benchmark_functions_edited/f1149.py | def f(A: dict) -> int:
return A['a'] + 1
assert f({'a': 5}) == 6 |
benchmark_functions_edited/f10917.py | def f(n1, n2):
if n1 is None and n2 is None:
return None
elif n1 is None:
return n2
elif n2 is None:
return n1
return min(n1, n2)
assert f(1, 2.2) == 1 |
benchmark_functions_edited/f9260.py | def f(x, nu, a):
yy = a * x ** nu
return yy
assert f(1, 1, 1) == 1 |
benchmark_functions_edited/f7326.py | def f(label):
if(label == 'POSITIVE'):
return 1
else:
return 0
assert f("POSITIVE") == 1 |
benchmark_functions_edited/f12166.py | def f(list_of_passports):
valid_count = 0
req_fields = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"]
for passport in list_of_passports:
valid = True
for field in req_fields:
if field not in passport:
valid = False
if valid:
valid_count += 1
return valid_count
assert f(
[
"hcl:#cfa07d eyr:2025 pid:166559648",
"iyr:2011 ecl:brn hgt:59in",
]
) == 0 |
benchmark_functions_edited/f47.py | def f(x, y):
return x * x - y * y
assert f(0, 0) == 0 |
benchmark_functions_edited/f13236.py | def f(l, exception_message):
s = set(l)
if len(s) != 1:
raise Exception(exception_message)
return l[0]
assert f([1, 1, 1], "Expected an exception, since the list is not [1].") == 1 |
benchmark_functions_edited/f12693.py | def f(air_flow: float, co2_source: float, co2_target: float) -> float:
return air_flow * (co2_source - co2_target)
assert f(0, 500, 300) == 0 |
benchmark_functions_edited/f10637.py | def f(decimal):
place, bcd = 0, 0
while decimal > 0:
nibble = decimal % 10
bcd += nibble << place
decimal /= 10
place += 4
return bcd
assert f(0) == 0 |
benchmark_functions_edited/f10418.py | def f(data):
try:
return int(data)
except ValueError:
try:
return float(data)
except ValueError:
return data
assert f(1) == 1 |
benchmark_functions_edited/f11700.py | def f(n, k):
"*** YOUR CODE HERE ***"
res = 1
if k==0:
return res
while k>0:
res *= n
n-=1
k-=1
return res
assert f(4, 1) == 4 |
benchmark_functions_edited/f8072.py | def f(day_num_string):
translation_dictionary = {'1st':1,'2nd':2,'3rd':3, '4th':4, 'last':9, 'teenth':6 }
return translation_dictionary[day_num_string]
assert f('2nd') == 2 |
benchmark_functions_edited/f3260.py | def f(in_size: int) -> int:
conv = 1024 * 1024
return in_size // conv
assert f(1) == 0 |
benchmark_functions_edited/f13352.py | def f(k, E, nu, plane_stress=False):
if plane_stress:
E = E / (1 - nu ** 2)
return k ** 2 / E
assert f(2, 1, 0.3) == 4 |
benchmark_functions_edited/f12723.py | def f(instructions):
index = 0
accumulator = 0
visited = set()
while index not in visited and index < len(instructions):
visited.add(index)
opr, val = instructions[index].split()
index = index + int(val) if opr == "jmp" else index + 1
if opr == "acc":
accumulator += int(val)
return accumulator
assert f(
.splitlines()
) == 5 |
benchmark_functions_edited/f867.py | def f(lst):
return max(abs(num) for num in lst)
assert f( [-1,-2,-3,-4,-5,-6] ) == 6 |
benchmark_functions_edited/f10410.py | def f(filename, format, num_blocks):
for block in range(1, num_blocks+1):
suffix = format % block
if filename.endswith(suffix):
return block
raise Exception("Can't find block index: %s" % filename)
assert f(r'C:\mydir\image0002.jpg', r'image%04d.jpg', 3) == 2 |
benchmark_functions_edited/f11756.py | def f(n, bit):
return int(bool((int(n) & (1 << bit)) >> bit))
assert f(5, 2) == 1 |
benchmark_functions_edited/f9557.py | def f(a, b):
b0 = b
x0, x1 = 0, 1
if b == 1:
return 1
while a > 1:
q = a // b
a, b = b, a % b
x0, x1 = x1 - q * x0, x0
if x1 < 0:
x1 += b0
return x1
assert f(9, 20) == 9 |
benchmark_functions_edited/f3195.py | def f(a, b):
if b == 0:
return a
else:
return f(b, a % b)
assert f(2, 6) == 2 |
benchmark_functions_edited/f12136.py | def choice_line (matrix):
line = 0
liste_nb_zero = list()
liste_sans_zero = list()
for line in matrix:
liste_nb_zero.append(line.count(0))
for elt in liste_nb_zero:
if elt != 0:
liste_sans_zero.append(elt)
line = liste_nb_zero.index(min(liste_sans_zero))
return line
assert f([[1, 1, 0], [1, 1, 1], [1, 1, 1]]) == 0 |
benchmark_functions_edited/f2832.py | def f(val):
return 1. if val >= 0.5 else 0.
assert f(1.0) == 1 |
benchmark_functions_edited/f10489.py | def f(cons, gamma):
import math
if not gamma == 1:
util = cons**(1-gamma)/(1-gamma)
else:
util = math.log(cons)
return util
assert f(0, 0.5) == 0 |
benchmark_functions_edited/f4115.py | def f(cell_type,cell_neighbour_types,DELTA,game,game_params):
return 1+DELTA*game(cell_type,cell_neighbour_types,*game_params)
assert f(0, [0, 0], 1, lambda x, y: 0, []) == 1 |
benchmark_functions_edited/f7745.py | def f(string, i):
return i - string.rfind('\n', 0, max(0, i))
assert f(
'abc\r\n'
'def\r\n'
'ghi', 6) == 2 |
benchmark_functions_edited/f1775.py | def f(n):
return len(str(n))
assert f(0) == 1 |
benchmark_functions_edited/f8923.py | def f(words, start, what):
i = start - 1
while i >= 0:
if words[i] == what:
return i
i -= 1
return -1
assert f(list('abc'), 2, 'a') == 0 |
benchmark_functions_edited/f10094.py | def f(a,d,lo,hi):
if d!=a[lo]:
raise Exception("d should be a[lo]")
while hi>lo:
mid=(lo+hi)//2+1
if a[mid]==d:
lo=mid
else:
hi=mid-1
if a[hi]==d:
return hi
else:
return lo
assert f( [0,1,2,3,4], 0, 0, 4 ) == 0 |
benchmark_functions_edited/f508.py | def f(a, b=0):
print(a + b)
return a + b
assert f(1, 3) == 4 |
benchmark_functions_edited/f639.py | def f(i, j):
return 3 * i + j
assert f(0, 2) == 2 |
benchmark_functions_edited/f11258.py | def f(buf):
val = 0
for i in range(len(buf) - 1, -1, -1):
val = val*256 + ord(buf[i])
return val
assert f(b'') == 0 |
benchmark_functions_edited/f14279.py | def f(keep):
if keep != 'all':
keep=int(keep)
return keep
assert f(3) == 3 |
benchmark_functions_edited/f9584.py | def f(nseg):
total_number = (nseg**2 + nseg) / 2
return int(total_number)
assert f(1) == 1 |
benchmark_functions_edited/f898.py | def f(byte):
return byte / (1024.0**2)
assert f(0) == 0 |
benchmark_functions_edited/f4284.py | def f(t, row, col, grid_dim):
s_id = (t * grid_dim[0] * grid_dim[1] + row * grid_dim[1] + col) // 1
return s_id
assert f(0, 1, 0, (1, 2)) == 2 |
benchmark_functions_edited/f6027.py | def f(attributes):
return round((attributes['sell_price'] - attributes['cost_price']) * attributes['inventory'])
assert f(
{"inventory": 1, "cost_price": 1.0, "sell_price": 2}) == 1 |
benchmark_functions_edited/f7634.py | def f(kargs):
func = kargs['func']
del kargs['func']
out = func(**kargs)
return out
assert f(
{'func': lambda a, b, c: a + b + c, 'a': 1, 'b': 2, 'c': 3}) == 6 |
benchmark_functions_edited/f13291.py | def f(box1, box2):
xmin1, ymin1, xmax1, ymax1 = box1
xmin2, ymin2, xmax2, ymax2 = box2
x_overlap = max(0, min(xmax1, xmax2) - max(xmin1, xmin2))
y_overlap = max(0, min(ymax1, ymax2) - max(ymin1, ymin2))
overlap_area = x_overlap * y_overlap
return overlap_area
assert f( [0,0,1,1], [0,0,2,2]) == 1 |
benchmark_functions_edited/f3549.py | def f(v, v0, b0, b0p):
vr = v0 / v
return (1.5 * b0 * (vr**(7 / 3) - vr**(5 / 3)) * (1 + 0.75 * (b0p - 4) * (vr**(2 / 3) - 1)))
assert f(1, 1, 1, 1) == 0 |
benchmark_functions_edited/f5642.py | def f(shard):
shard.seek(0, 2)
return shard.tell()
assert f(open('example.txt', 'wb')) == 0 |
benchmark_functions_edited/f11429.py | def f(s):
return sum([(len(v) if hasattr(v, '__len__') else 0) for v in s])
assert f({'a': 'b'}) == 1 |
benchmark_functions_edited/f4009.py | def f(n0, theta0, r, I0=1):
I = I0 / (r/theta0)**n0
return I
assert f(0.5, 10, 10) == 1 |
benchmark_functions_edited/f11149.py | def f(value, min_=0., max_=1.):
if value < min_:
return min_
elif value > max_:
return max_
else:
return value
assert f(*[-1, 0, 2]) == 0 |
benchmark_functions_edited/f147.py | def f(f, x, h):
return (f(x+h) - f(x)) / h
assert f(lambda x: 1, 0, 2) == 0 |
benchmark_functions_edited/f7185.py | def f(s1, s2):
if (s1 == s2):
return 0
if (s1 < s2):
return -1
return 1
assert f("ab", "a") == 1 |
benchmark_functions_edited/f14137.py | def f(ipynb_dict):
idx = 0
cells_list = ipynb_dict['cells']
for cell_dict in cells_list:
if cell_dict['cell_type'] != 'code':
idx += 1
continue
break
return idx
assert f(
{'cells': [
{'cell_type': 'code'},
{'cell_type': 'code'},
{'cell_type':'markdown'},
{'cell_type': 'code'},
]}
) == 0 |
benchmark_functions_edited/f66.py | def f(x):
print(x)
return x
assert f(3) == 3 |
benchmark_functions_edited/f172.py | def f(x, a, b, c):
return a*x**2 + b*x + c
assert f(1, 1, 2, 3) == 6 |
benchmark_functions_edited/f2995.py | def f(a: int, b: int):
if b == 0:
return 1
b -= 1
return a*f(a, b)
assert f(2, 2) == 4 |
benchmark_functions_edited/f10042.py | def f(norm_vals, norm_pars):
vals = norm_pars[0] + norm_vals*(norm_pars[1]-norm_pars[0])
return vals
assert f(0, [0, 100]) == 0 |
benchmark_functions_edited/f7403.py | def f(l):
l= str(l)
if len(l) < 53:
return 0
elif len(l)>=53 and len(l)<75:
return 2
else:
return 1
assert f(20) == 0 |
benchmark_functions_edited/f13838.py | def f(job_id):
import subprocess
try:
step_process = subprocess.Popen(('bkill', str(job_id)), shell=False, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout, stderr = step_process.communicate()
return 1
except Exception as e:
print(e)
return 0
assert f(1111111111) == 0 |
benchmark_functions_edited/f13144.py | def f(config, migrations, version, prior=False):
# find target
ix = None
for ix, m in enumerate(migrations):
if m['version'] == version:
return ix
if prior:
return ix
return None
assert f(None, [ {'version': '1.2.3'}, {'version': '1.2.4'} ], '1.2.3') == 0 |
benchmark_functions_edited/f12230.py | def f(V, Q, I, b):
return (V * Q) / (I * b)
assert f(0, 0, 10, 10) == 0 |
benchmark_functions_edited/f12201.py | def f(n):
if not n >= 0:
raise ValueError("n must be >= 0")
i, a, b = 0, 0, 1
while i < n:
a, b = b, a+b
i += 1
return a
assert f(0) == 0 |
benchmark_functions_edited/f13463.py | def f(
fn,
itr,
not_found=None,
nothing=(None, False),
):
for item in itr:
result = fn(item)
if result not in nothing:
return result
return not_found
assert f(lambda x: x if x % 2 else None, range(3, 10)) == 3 |
benchmark_functions_edited/f11893.py | def f( args_json ):
print('dump args json dictionary keys level 1')
for dict_key in args_json.keys():
print( 'dict_key: %s' % (dict_key))
print('dump args json dictionary keys level 2 (runs)')
for sample in args_json['samples']:
print('sample: %s' % (sample))
return( 0 )
assert f( {'samples': ['sample1','sample2','sample3' ] } ) == 0 |
benchmark_functions_edited/f14057.py | def f(nworker, taskproc, nodeprocs):
nds = (nworker * taskproc) // nodeprocs
if nds * nodeprocs < nworker * taskproc:
nds += 1
return nds
assert f(10, 1, 2) == 5 |
benchmark_functions_edited/f12374.py | def f(x, theta):
### START CODE HERE ### (approx. 1 line)
dtheta = x
### END CODE HERE ###
return dtheta
assert f(3, 3) == 3 |
benchmark_functions_edited/f900.py | def f(context, key):
return context.pop(key, None)
assert f({'a': 1}, 'a') == 1 |
benchmark_functions_edited/f11666.py | def f(kernel_size):
if type(kernel_size) is tuple:
kernel_size = kernel_size[0]
pad_size = (kernel_size-1)//2
if kernel_size%2 == 0:
padding = (pad_size, pad_size+1)
else:
padding = pad_size
return padding
assert f(7) == 3 |
benchmark_functions_edited/f12210.py | def f(phrase):
import re
key_pad = {'1ADGJMPTW': 1, 'BEHKNQUX0': 2, 'CFILORVY': 3,
'SZ234568': 4, '79': 5, '?!\W': 1}
presses = 0
for k, v in key_pad.items():
presses += v * len(''.join(
re.findall('[{}]*'.format(k), phrase.upper())
))
return presses
assert f(
'adGJHtw') == 8 |
benchmark_functions_edited/f10719.py | def f(x: int, n: int) -> int:
counter = 0
for i in range(1, n + 1):
for j in range(1, n + 1):
if i * j == x:
counter += 1
return counter
assert f(10, 4) == 0 |
benchmark_functions_edited/f3106.py | def f(s):
cs = " ".join([p.strip() for p in s.split("\n")])
return len(cs.split(" "))
assert f("hi \n there") == 2 |
benchmark_functions_edited/f14258.py | def f(pattern, text):
m = len(pattern)
n = len(text)
if m > n:
return None
skip = {}
for k in range(256):
skip[k] = m
for k in range(m - 1):
skip[pattern[k]] = m - k - 1
k = m - 1
while k < n:
j = m - 1
while j >= 0 and pattern[j] == text[k]:
j -= 1
k -= 1
if j < 0:
return k + 1
k += skip[text[k]]
return None
assert f(b"ABCD", b"ABCDE") == 0 |
benchmark_functions_edited/f6174.py | def f(tree, children_collection_name='subregions'):
if tree is None:
return 1
return max(f(subtree) for subtree
in getattr(tree, children_collection_name)) + 1
assert f(None) == 1 |
benchmark_functions_edited/f4632.py | def f(data, path):
for p in path.split('.'):
data = data[p]
return data
assert f(
{
'a': {
'b': {
'c': {
'd': {
'e': 5
}
}
}
}
}, 'a.b.c.d.e'
) == 5 |
benchmark_functions_edited/f8705.py | def f(x, y):
return x ** 2 + y ** 2
assert f(0, 0) == 0 |
benchmark_functions_edited/f7489.py | def f(value):
try:
return float(value)
except ValueError:
return value
assert f(2) == 2 |
benchmark_functions_edited/f3693.py | def f(P, K):
return (P // K) + 1
assert f(4, 3) == 2 |
benchmark_functions_edited/f9730.py | def f(dictionary, key):
# Use `get` to return `None` if not found
return dictionary.get(key)
assert f({"a":1}, "a") == 1 |
benchmark_functions_edited/f2326.py | def f(f, seq):
for item in seq:
if f(item):
return item
assert f(lambda x: x == 3, range(5)) == 3 |
benchmark_functions_edited/f10661.py | def f(config, name, default):
try:
value = config.getoption(name, default=default)
except Exception:
try:
value = config.getvalue(name)
except Exception:
return default
return value
assert f(None, 'foo', 2) == 2 |
benchmark_functions_edited/f13697.py | def f(slice_objects):
num_elements = 0
try:
for sl in slice_objects:
num_elements += (sl.stop - (sl.start + 1)) // sl.step + 1
except TypeError:
num_elements += (slice_objects.stop - (slice_objects.start + 1)) \
// slice_objects.step + 1
return num_elements
assert f(slice(1, 10, 3)) == 3 |
benchmark_functions_edited/f12195.py | def f(arr):
result = 0
for item in arr:
# all numbers repeated twice will be equal to 0 after XOR operation
# at the end, only left is the unique integer
result ^= item
return result
assert f(
[9, 3, 9, 3, 9, 7, 9]
) == 7 |
benchmark_functions_edited/f631.py | def f(num_vec):
return float(sum(num_vec)) / len(num_vec)
assert f([0, 2, 4, 6]) == 3 |
benchmark_functions_edited/f691.py | def f(nums):
avg = sum(nums) / len(nums)
return avg
assert f(
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
) == 1 |
benchmark_functions_edited/f8330.py | def f(a, b, func):
if a is not None:
return func(a, b)
return b
assert f(None, 2, lambda x, y: x * y) == 2 |
benchmark_functions_edited/f5610.py | def f(a:float,b:float) -> float:
return a / (1 / b)
assert f(1, 4) == 4 |
benchmark_functions_edited/f4799.py | def f(n: int):
if n < 0: return -n | 4
else: return n
assert f(1) == 1 |
benchmark_functions_edited/f4470.py | def f(x, dx=1, offset=0):
return int( (x - offset) / dx )
assert f(1.0) == 1 |
benchmark_functions_edited/f13466.py | def f(grid):
if grid is None:
return None
h = 0
w = 0
for row in grid:
try:
if (row.index(1) >= 0):
h = h + 1
except ValueError:
pass
for row in grid:
w = max(row.count(1), w)
return (h * 2) + (w * 2)
assert f([[0, 0]]) == 0 |
benchmark_functions_edited/f1842.py | def f(data, duration):
return data * 8/duration
assert f(0, 1) == 0 |
benchmark_functions_edited/f5253.py | def f(s, e, byte):
byte = byte>>e
return byte & [1, 3, 7, 15, 31, 63, 127, 255][s-e]
assert f(3,4,1) == 0 |
benchmark_functions_edited/f14494.py | def f(amount, coins, n):
# Base cases.
if amount < 0:
return 0
if amount == 0:
return 1
# When number of coins is 0 but there is still amount remaining.
if n <= 0 and amount > 0:
return 0
# Sum num of ways with coin n included & excluded.
n_changes = (f(amount - coins[n - 1], coins, n)
+ f(amount, coins, n - 1))
return n_changes
assert f(10, [1, 5, 10], 3) == 4 |
benchmark_functions_edited/f3826.py | def f(x1, x2, x3):
return x1 + x2 + x3 - max([x1, x2, x3]) - min([x1, x2, x3])
assert f(1, 3, 2) == 2 |
benchmark_functions_edited/f2672.py | def f(xs):
return sum(xs)/len(xs) if len(xs) > 0 else None
assert f([2]) == 2 |
benchmark_functions_edited/f2862.py | def f(km):
try:
return float(km) / 1.609344
except ValueError:
return None
assert f(0) == 0 |
benchmark_functions_edited/f10446.py | def f(path):
return min([e[3] for e in path])
assert f([(1, 2, 'a', 5), (2, 3, 'b', 7), (3, 4, 'c', 5)]) == 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.