file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f11385.py
|
def f(items, max_width=30):
max_item_width = max(map(len, items))
return min(max_width, max_item_width)
assert f(
["foo", "asdf", "beep boop"], 5
) == 5
|
benchmark_functions_edited/f582.py
|
def f(rooms):
return sum(id for id, name, checksum in rooms)
assert f([]) == 0
|
benchmark_functions_edited/f8663.py
|
def f(token, word2Idx):
if token in word2Idx:
return word2Idx[token]
elif token.lower() in word2Idx:
return word2Idx[token.lower()]
return word2Idx["UNKNOWN"]
assert f('a', {'a':0, 'b':1}) == 0
|
benchmark_functions_edited/f6541.py
|
def f(first, second):
if first is None:
return second
elif second is None:
return first
else:
return min(first, second)
assert f(1, 0) == 0
|
benchmark_functions_edited/f2730.py
|
def f(a, b):
return ((a[0] - b[0])**2 + (a[1] - b[1])**2)
assert f( (0,1), (0,0) ) == 1
|
benchmark_functions_edited/f10605.py
|
def f(A):
def rmax(lo, hi):
if lo == hi: return A[lo]
mid = (lo+hi) // 2
L = rmax(lo, mid)
R = rmax(mid+1, hi)
return max(L, R)
return rmax(0, len(A)-1)
assert f([1, 3, 2]) == 3
|
benchmark_functions_edited/f8879.py
|
def f(vec, poly):
return vec ** 2 * poly[0] + vec * poly[1] + poly[2]
assert f(1, [0, 2, 1]) == 3
|
benchmark_functions_edited/f2712.py
|
def f(dic: dict, keys: list) -> dict:
for key in keys:
dic = dic[key]
return dic
assert f(
{"foo": {"bar": [1, 2, 3]}},
["foo", "bar", 2]
) == 3
|
benchmark_functions_edited/f6173.py
|
def f(metrics: list) -> int:
if metrics:
return sum(item["class"][0] == "greater-value" for item in metrics)
else:
return 0
assert f(
[
{"class": ["greater-value"], "value": [10]},
{"class": ["greater-value"], "value": [10]},
{"class": ["greater-value"], "value": [20]},
]
) == 3
|
benchmark_functions_edited/f5687.py
|
def f(d, Re):
alpha = (0.031395 / (d*10**-3)) * (Re**0.8)
return alpha
assert f(2,0) == 0
|
benchmark_functions_edited/f1811.py
|
def f(decod):
if decod:
return decod[0]
return 0
assert f([2, 3, 4]) == 2
|
benchmark_functions_edited/f4605.py
|
def f(n_frames, block_length):
return n_frames - block_length + 1
assert f(1, 2) == 0
|
benchmark_functions_edited/f9637.py
|
def f(fps):
if 1 <= fps <= 1000:
global frameDelay
frameDelay = round(1000 / fps)
else:
return 1
assert f(-100) == 1
|
benchmark_functions_edited/f6269.py
|
def f(value, existing_list, key):
for i, dic in enumerate(existing_list):
if dic[key] == value:
return i
return None
assert f(1, [{'a': 1}, {'b': 2}], 'a') == 0
|
benchmark_functions_edited/f808.py
|
def f(a, b):
c = a - b + 1
return c
assert f(10, 4) == 7
|
benchmark_functions_edited/f10215.py
|
def f(matches):
if matches[0] != -1:
return 0
num = 1
while matches[num] == -1:
num += 1
return num
assert f([-1, -1, 0, 1, 2]) == 2
|
benchmark_functions_edited/f6669.py
|
def f(elem1,
elem2):
ret = None
return max([abs(x - y)
for x in elem1
for y in elem2])
assert f(range(1, 5),
range(1, 6)) == 4
|
benchmark_functions_edited/f5409.py
|
def f(img, u, v, n):
s = 0
for i in range(-n, n+1):
for j in range(-n, n+1):
s += img[u+i][v+j]
return float(s)/(2*n+1)**2
assert f(
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0]], 1, 1, 0) == 0
|
benchmark_functions_edited/f9014.py
|
def f(x,a,b):
return a*x**3 + b
assert f(0,4,5) == 5
|
benchmark_functions_edited/f13401.py
|
def f(s, m):
# note, I *think* it's possible to have unicode chars in
# a twitter handle. That makes it a bit interesting.
# We don't handle unicode yet, just ASCII
total = 0
for ch in s:
# no non-printable ASCII chars, including space
# but we want "!" to represent an increment of 1, hence 32 below
total = (total + ord(ch)-32) % m
return total
assert f( 'abc', 7) == 2
|
benchmark_functions_edited/f86.py
|
def f(x):
return int(round(x))
assert f(1.1) == 1
|
benchmark_functions_edited/f13216.py
|
def f(n_persons=0, emission_rate=0, internal_source=0, time=0):
e = n_persons * emission_rate + internal_source
return e
assert f(0, 1) == 0
|
benchmark_functions_edited/f5876.py
|
def f(data, index):
try:
return data[index]
except IndexError:
return None
assert f(list(range(1,10)), 0) == 1
|
benchmark_functions_edited/f13243.py
|
def f(total_items, dir_items):
for index in range(total_items - 1, -1, -1):
list_item = dir_items[index][1]
if list_item.getVideoInfoTag().getPlayCount() != 0:
# Last watched item
return index + 1
if float(list_item.getProperty('ResumeTime')) != 0:
# Last partial watched item
return index
return 0
assert f(0, [3]) == 0
|
benchmark_functions_edited/f8694.py
|
def f(tokens):
word_lengths = [len(word) for word in tokens]
return sum(word_lengths) / len(word_lengths)
assert f(["test"]) == 4
|
benchmark_functions_edited/f12172.py
|
def f(a: int, b: int, c: int = 3) -> int:
return a + b * c
assert f(1, 2) == 7
|
benchmark_functions_edited/f6139.py
|
def f(stats):
k = len(stats)
n = sum(s[0] for s in stats) # total number of pulls
return n % k
assert f( [[10,20,30]] * 5 ) == 0
|
benchmark_functions_edited/f8934.py
|
def f(args):
rosen = 0
for i in range(len(args ) -1):
rosen += 10.0 *((args[i]**2 ) -args[ i +1] )** 2 +( 1 -args[i] )**2
return rosen
assert f( (1,1)) == 0
|
benchmark_functions_edited/f5584.py
|
def f(val):
result = 0
while val > 1:
result = result + 1
val = val / 10
if result:
return result
return 1
assert f(10000) == 4
|
benchmark_functions_edited/f357.py
|
def f(out, target):
return (target - out) ** 2
assert f(2, 4) == 4
|
benchmark_functions_edited/f1713.py
|
def f(level):
return int((level * 255) / 100)
assert f(-0.1) == 0
|
benchmark_functions_edited/f2164.py
|
def f(k, n):
return n + (k - 2) * n * (n - 1) // 2
assert f(3, 0) == 0
|
benchmark_functions_edited/f6086.py
|
def f(a, b):
return b if a is None else a
assert f(None, 1) == 1
|
benchmark_functions_edited/f3966.py
|
def f(line):
expline = line.expandtabs()
return len(expline) - len(expline.lstrip())
assert f(r" foo bar") == 8
|
benchmark_functions_edited/f2780.py
|
def f(l, e):
try:
return l.index(e)
except:
return len(l)
assert f([], 10000000000000000000000) == 0
|
benchmark_functions_edited/f2192.py
|
def f(x, a, b):
return a * x + b
assert f(1, 1, 2) == 3
|
benchmark_functions_edited/f10935.py
|
def f(hypseg, reflist):
hbeg, hend = hypseg[0], hypseg[2]
times = []
for [rlbl, rseg] in reflist:
b = max(hbeg, rseg[0])
e = min(hend, rseg[2])
times.append(e - b)
return times.index(max(times))
assert f(
(1200, 1250, 1300),
[
('car', (200, 300, 400)),
('person', (1200, 1250, 1300)),
('car', (300, 400, 500)),
('person', (1300, 1350, 1400))
]
) == 1
|
benchmark_functions_edited/f13092.py
|
def f(grp):
# grp is a group of tokens.
# Compute whatever necessary.
return len(grp)
assert f(
[
["abc", "abd"],
["aab", "aba"],
["bcd", "bdc"]
]
) == 3
|
benchmark_functions_edited/f7188.py
|
def f(labels, classes):
sorted_labels = sorted(list(classes))
return [sorted_labels.index(item) for item in labels] if isinstance(labels, list) else sorted_labels.index(labels)
assert f('a', ['a', 'b', 'c']) == 0
|
benchmark_functions_edited/f3202.py
|
def f(name):
return int(name.split("_t0")[-1].split("_")[0])
assert f(
"video_t002_f000200_f000300.mp4") == 2
|
benchmark_functions_edited/f2166.py
|
def f(x, base=10):
return int(base * round(float(x)/base))
assert f(0.5) == 0
|
benchmark_functions_edited/f2400.py
|
def f(paths):
return sum(len(path.rewards) for path in paths)
assert f([]) == 0
|
benchmark_functions_edited/f1585.py
|
def f(*args):
return sum(1 if a else 0 for a in args)
assert f(False, False, False) == 0
|
benchmark_functions_edited/f470.py
|
def f(x, y):
return abs(x - y)
assert f(4, 5) == 1
|
benchmark_functions_edited/f13553.py
|
def f(outputs): # outputs []*wire.TxOut) (serializeSize int) {
serializeSize = 0
for txOut in outputs:
serializeSize += txOut.serializeSize()
return serializeSize
assert f([]) == 0
|
benchmark_functions_edited/f10581.py
|
def f(s: int, n: int) -> int:
heptagon = (n ** 2 * (s - 2) - n * (s - 4)) / 2
return int(heptagon)
assert f(-1, 0) == 0
|
benchmark_functions_edited/f1239.py
|
def f(session, *args):
msg = ' '.join(args) if args else ''
print(msg)
return 0
assert f(None, 'This is a test') == 0
|
benchmark_functions_edited/f988.py
|
def f(Om, z):
return ((Om) * (1 + z)**3. + (1 - Om))**0.5
assert f(1, 0) == 1
|
benchmark_functions_edited/f8691.py
|
def f(value):
try:
return int(value)
except ValueError:
return 0
assert f('abc') == 0
|
benchmark_functions_edited/f5906.py
|
def f(L):
L = list(L)
if not (len(L) == 1):
raise ValueError(F"Expected an iterable of length 1, got {len(L)}.")
return L[0]
assert f([1]) == 1
|
benchmark_functions_edited/f9975.py
|
def f(p,x,y,yerr,function):
#print "p is",type(p),"of length",len(p)
#print "x is",type(x),"of length",len(x)
#print "y is",type(y),"of length",len(y)
fit = function(x,p)
#print "fit is",type(fit),"of length",len(fit)
return (y - function(x,p))/yerr**2
assert f(1,1,1,1,lambda x,p: x) == 0
|
benchmark_functions_edited/f13612.py
|
def f(month):
codes = ('F','G','H','J','K','M','N','Q','U','V','X','Z')
if isinstance(month,int):
return codes[month-1]
elif isinstance(month,str):
return codes.index(month)+1
else:
raise ValueError('Function accepts int or str')
assert f(f(4)) == 4
|
benchmark_functions_edited/f2069.py
|
def f(definition):
return len(definition.split())
assert f('1 2 3 4') == 4
|
benchmark_functions_edited/f10908.py
|
def f(dementia_status):
if dementia_status == 'Nondemented':
return 0
elif dementia_status == 'Intact':
return 0
else:
return 1
assert f('Mild-Demented') == 1
|
benchmark_functions_edited/f13138.py
|
def f(digits):
answer = max(
number * number_2
for number in range(10 ** digits - 1, 10 ** digits // 10 - 1, -1)
for number_2 in range(10 ** digits - 1, 10 ** digits // 10 - 1, -1)
if str(number * number_2) == str((number * number_2))[::-1]
)
return answer
assert f(1) == 9
|
benchmark_functions_edited/f8039.py
|
def f(val, in_min, in_max, out_min, out_max):
return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
assert f(2, 0, 2, 2, 3) == 3
|
benchmark_functions_edited/f4204.py
|
def f(value, align):
return int(int((value + align - 1) / align) * align)
assert f(1, 5) == 5
|
benchmark_functions_edited/f10206.py
|
def f(value: int, size: int):
return value + (size - value % size) % size
assert f(5, 8) == 8
|
benchmark_functions_edited/f5820.py
|
def f(width, kernel, slide):
res = (width - kernel) / slide + 1
pad = (width - res) / 2
return pad
assert f(16, 5, 1) == 2
|
benchmark_functions_edited/f10289.py
|
def f(page_number, page_range):
try:
return page_range[page_number]
except IndexError:
return page_range[0]
assert f(2, [1,2,3]) == 3
|
benchmark_functions_edited/f1602.py
|
def f(s, i, N):
return s ^ (1 << i | 1 << ((i+1) % N))
assert f(0, 1, 2) == 3
|
benchmark_functions_edited/f11760.py
|
def f(year, starting_year):
return int(year)-int(starting_year)
assert f(1956, 1956) == 0
|
benchmark_functions_edited/f4573.py
|
def f(first, second):
return max(int(first), int(second))
assert f(-1, 1) == 1
|
benchmark_functions_edited/f8682.py
|
def f(chunks, pos):
pos = pos + 1
while pos < len(chunks)-1:
if chunks[pos][0] != 0x100 and chunks[pos][0] != 0x102:
# This is not a block
return pos
else:
pos = pos + 1
return pos
assert f(
[
(0x100, b''),
(0x100, b''),
(0x100, b''),
(0x102, b''),
(0x100, b''),
(0x102, b''),
(0x100, b'')
],
0
) == 6
|
benchmark_functions_edited/f3478.py
|
def f(value, value_min, value_max):
return 2 * ((value - value_min) / (value_max - value_min)) - 1
assert f(1, 0, 1) == 1
|
benchmark_functions_edited/f12977.py
|
def f( u_stencil ):
uim2, uim1, ui, uip1, uip2 = u_stencil
return uim2/30 - (13*uim1)/60 + 47*(ui/60) + 9*(uip1/20) - uip2/20
assert f( (1, 1, 1, 1, 1) ) == 1
|
benchmark_functions_edited/f8258.py
|
def f(string1, string2):
count = 0
#for each char in string1, check if it's in string2
for char in string1:
if char in string2:
count += 1
return count
assert f(
"abcde", "a") == 1
|
benchmark_functions_edited/f6789.py
|
def f(stepsDict):
c = 0
for s in stepsDict:
if stepsDict[s].complete:
c += 1
return c
assert f({}) == 0
|
benchmark_functions_edited/f5587.py
|
def f(a, x):
for i, each in enumerate(a):
if each == x:
return i
else:
return None
assert f([1, 1, 1, 1, 1, 1, 1], 1) == 0
|
benchmark_functions_edited/f1528.py
|
def f(v):
return (pow(sum(e*e for e in v), 0.5))
assert f( (0, 0, 0) ) == 0
|
benchmark_functions_edited/f1455.py
|
def f(min_val, val, max_val):
return min(max(val, min_val), max_val)
assert f(3, -1, 3) == 3
|
benchmark_functions_edited/f5071.py
|
def f(blob_size, a, b):
dist = (a/blob_size) + b
return dist
assert f(1, 1, 1) == 2
|
benchmark_functions_edited/f8669.py
|
def f(a, b, alpha):
return alpha * a + (1 - alpha) * b
assert f(10, 5, 0) == 5
|
benchmark_functions_edited/f9774.py
|
def f(Dependents):
if Dependents == '0':
return 0
elif Dependents == '1':
return 1
elif Dependents == '2':
return 2
else:
return 3
assert f(8) == 3
|
benchmark_functions_edited/f10131.py
|
def f(nums):
even_sum, odd_sum = 0, 0
for i in range(len(nums)):
if i % 2 == 0:
even_sum = max(even_sum + nums[i], odd_sum)
else:
odd_sum = max(even_sum, odd_sum + nums[i])
return max(even_sum, odd_sum)
assert f([2, 1, 1, 2]) == 4
|
benchmark_functions_edited/f5073.py
|
def f(s):
if s == '0':
return 0
if s.startswith('"h'):
return int(s[2:-1],16)
return int(s)
assert f("1") == 1
|
benchmark_functions_edited/f7964.py
|
def f(this: list, that: list):
count = 0
for i in range(3):
for j in range(3):
if this[i][j] != that[i][j]:
count += 1
return count
assert f(
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]],
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
) == 0
|
benchmark_functions_edited/f12424.py
|
def get_min (matrix, support_minimal):
ligne_rayee = support_minimal['ligne']
colonne_rayee = support_minimal['colonne']
nb = list()
for y, y_elt in enumerate(matrix):
for x, x_elt in enumerate(y_elt):
if x not in colonne_rayee and y not in ligne_rayee:
nb.append(x_elt)
return min(nb)
assert f(
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]],
{'ligne': [], 'colonne': [0, 2]}
) == 2
|
benchmark_functions_edited/f11133.py
|
def f(s, enc, cc):
if cc == -1:
return -1
s = s.encode('UTF-32LE')
clen = cc * 4
if clen > len(s):
raise IndexError
return len(s[:clen].decode('UTF-32LE').encode(enc))
assert f(u'\u0001\u0002\u0003\u0004\u0005\u0006\u0007', 'UTF-16LE', 3) == 6
|
benchmark_functions_edited/f4145.py
|
def f(theta):
if theta > 180 or theta < -180:
theta = theta % 180
return theta
assert f(-360) == 0
|
benchmark_functions_edited/f4527.py
|
def f(x):
s = 1
for i in range(2, x // 2 + 1):
if x % i == 0:
s += i
return s
assert f(11) == 1
|
benchmark_functions_edited/f2151.py
|
def f(sint, default):
try:
return int(sint)
except ValueError:
return default
assert f("1", 1) == 1
|
benchmark_functions_edited/f5284.py
|
def f(inp, padding, kernel, stride):
numerator = inp + (2*padding) - kernel
return int((numerator/stride) + 1)
assert f(10, 0, 3, 2) == 4
|
benchmark_functions_edited/f12667.py
|
def f(model_lines):
last_ter = 0
for index, line in enumerate(model_lines[::-1]):
if line[:3] == "TER":
last_ter = len(model_lines) - index - 1
break
return last_ter
assert f([]) == 0
|
benchmark_functions_edited/f3295.py
|
def f(x, y):
return 2 * x * y / (x**2 + y**2)**2
assert f(0, 1) == 0
|
benchmark_functions_edited/f7731.py
|
def f(obj, key):
try:
return obj.f(key)
except KeyError:
return None
assert f(
{'a': 1, 'b': 2},
'b'
) == 2
|
benchmark_functions_edited/f13887.py
|
def f(halite, dis, t, collect_rate=0.25, regen_rate=0.02):
if dis >= t:
return 0
else:
# Halite will regenerate before ship arrives
new_halite = halite * (1 + regen_rate) ** max(0, dis - 1)
# Ship costs (dis) rounds to arrive destination, uses (t - dis) rounds to collect halite
return new_halite * (1 - (1 - collect_rate) ** (t - dis))
assert f(100, 2, 1) == 0
|
benchmark_functions_edited/f9019.py
|
def f(n):
# *** YOUR CODE HERE ***
return n
assert f(1) == 1
|
benchmark_functions_edited/f9803.py
|
def f(u,v):
x1,y1 = u
x2,y2 = v
return abs(x1-x2) + abs(y1-y2)
assert f((-1,-1), (2,2)) == 6
|
benchmark_functions_edited/f6153.py
|
def f(obj):
try:
it = iter(obj)
next(it)
return next(it)
except TypeError:
return obj
except StopIteration:
return
assert f((i for i in [1, 2, 3, 4])) == 2
|
benchmark_functions_edited/f1692.py
|
def f(a1, a2):
return (a1[0] - a2[0])**2 + (a1[1] - a2[1])**2
assert f(
(0, 1), (0, 1)
) == 0
|
benchmark_functions_edited/f8825.py
|
def f(string, index):
ret = 0
i = index
end = len(string) - 1
while (i < end) and (string[i + 1] == string[i]):
i += 1
ret += 1
return ret
assert f(
'ababababab',
0
) == 0
|
benchmark_functions_edited/f290.py
|
def f(ether):
return int(ether * 10**18)
assert f(1e-18) == 1
|
benchmark_functions_edited/f12998.py
|
def f(lines, line_index):
while line_index < len(lines):
if lines[line_index].strip().startswith('/*'):
# Only return this marker if the comment goes beyond this line
if lines[line_index].strip().find('*/', 2) < 0:
return line_index
line_index += 1
return len(lines)
assert f(
["// foo", "/* bar", "baz", "*/ bogus;"], 3) == 4
|
benchmark_functions_edited/f6152.py
|
def f(a, b, show_lower=True):
op_display = "plus" if show_lower else "PLUS"
print("{} {} {} = {}".format(a, op_display, b, a + b))
return a + b
assert f(*[2, 3, False]) == 5
|
benchmark_functions_edited/f12418.py
|
def f(id):
try:
id2 = int(id)
except Exception:
id2 = id
return id2
assert f(0) == 0
|
benchmark_functions_edited/f4877.py
|
def f(n):
# The number of possible links is just the triangle number for
# n-1.
return int(n*(n-1)/2)
assert f(4) == 6
|
benchmark_functions_edited/f6448.py
|
def f(m, l, lmin, lmax):
if m <= lmin:
return l + (1+lmax)*m-lmin*(1+m)
else:
return (2*l-(1+lmin)*lmin+(2*lmax-m+1) * m)//2
assert f(2, 1, 0, 1) == 2
|
benchmark_functions_edited/f1271.py
|
def f(v):
return ((v[0] + v[3]) - (v[1] + v[2])) / float(v[6])
assert f( [5, 5, 5, 5, 5, 5, 10]) == 0
|
benchmark_functions_edited/f7452.py
|
def f(x, a, alpha):
return a * x ** alpha
assert f(2, 1, 1) == 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.