file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f6191.py
|
def f(board):
return max(val for row in board for val in row)
assert f(
[[2, 2],
[3, 1]]) == 3
|
benchmark_functions_edited/f13169.py
|
def f(seq1, seq2):
dist = 1 - len(set(seq1).intersection(set(seq2))) / len(set(seq1).union(set(seq2)))
return dist
assert f(list('abc'), list('def')) == 1
|
benchmark_functions_edited/f1970.py
|
def f(progname):
print("Usage: %s /path/to/generated/tables output.cpp " % progname)
return 1
assert f("foo") == 1
|
benchmark_functions_edited/f884.py
|
def f(u, v):
return sum([u[i]*v[i] for i in range(len(u))])
assert f( (0, 0, 2), (1, 1, 0) ) == 0
|
benchmark_functions_edited/f14315.py
|
def f(a, m):
if a < 0 or m <= a:
a = a % m
# From Ferguson and Schneier, roughly:
c, d = a, m
uc, vc, ud, vd = 1, 0, 0, 1
while c != 0:
q, c, d = divmod(d, c) + (c,)
uc, vc, ud, vd = ud - q*uc, vd - q*vc, uc, vc
# At this point, d is the GCD, and ud*a+vd*m = d.
# If d == 1, this means that ud is a inverse.
assert d == 1
if ud > 0:
return ud
else:
return ud + m
assert f(11, 13) == 6
|
benchmark_functions_edited/f1715.py
|
def f(msg):
return (msg[3] << 16) + (msg[4] << 8) + msg[5]
assert f(b'\x00\x00\x00\x00\x00\x01') == 1
|
benchmark_functions_edited/f6170.py
|
def f(l, idx, default):
try:
return l[idx]
except IndexError:
return default
assert f(range(10), 5, 'empty') == 5
|
benchmark_functions_edited/f1859.py
|
def f(vp, alpha=310, beta=0.25):
return alpha * vp**beta
assert f(0) == 0
|
benchmark_functions_edited/f14348.py
|
def f(f, a, b, n, height='left'):
h = float(b-a)/n
if height == 'left':
start = a
elif height == 'mid':
start = a + h/2.0
else: # Must be right end
start = a + h
result = 0
for i in range(n):
result += f((start) + i*h)
result *= h
return result
assert f(lambda x: 1, 0, 2, 1) == 2
|
benchmark_functions_edited/f4770.py
|
def f(b: bytes) -> int:
return int.from_bytes(b, "big")
assert f(b"\x01") == 1
|
benchmark_functions_edited/f4507.py
|
def f(data):
mode = max(data, key=data.count)
return mode
assert f([1]) == 1
|
benchmark_functions_edited/f14153.py
|
def f(intensity, interval=300):
return intensity * interval / 3600
assert f(0) == 0
|
benchmark_functions_edited/f8709.py
|
def f(func, *args, handle=lambda e: e, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
print(e)
return handle(e)
assert f(len, ["a", "b", "c"]) == 3
|
benchmark_functions_edited/f10982.py
|
def f(y_true, y_pred):
# initialize
tp = 0
for yt, yp in zip(y_true, y_pred):
if yt == 1 and yp == 1:
tp += 1
return tp
assert f(list(), list()) == 0
|
benchmark_functions_edited/f3925.py
|
def f(sp, ip, noise):
return sp / (ip + noise)
assert f(0, 5, 2) == 0
|
benchmark_functions_edited/f1465.py
|
def f(x):
try: return int(x)
except: return 0
assert f([]) == 0
|
benchmark_functions_edited/f1589.py
|
def f(l):
return len(l) if isinstance(l, list) else None
assert f([[4, 5], [6, 7]]) == 2
|
benchmark_functions_edited/f7222.py
|
def f(value: str, alphabet: str) -> int:
ret = 0
for digit in value:
ret = len(alphabet) * ret + alphabet.find(digit)
return ret
assert f(
'A',
'ABCD'
) == 0
|
benchmark_functions_edited/f1669.py
|
def f(h1, h2, joint_h):
return h1 + h2 - joint_h
assert f(0, 1, 1) == 0
|
benchmark_functions_edited/f5115.py
|
def f(x1, y1, x2, y2):
l = (x2 - x1) * (x2 - x1 ) + (y2 - y1) * (y2 - y1)
return l
assert f(0, 0, 1, 1) == 2
|
benchmark_functions_edited/f11290.py
|
def f(value, byteSize):
if byteSize == 1:
if value < 0:
return (value + 0x100)
elif byteSize == 2:
if value < 0:
return (value + 0x10000)
elif byteSize == 4:
if value < 0:
return (value + 0x100000000)
# positive (or invalid byte size)
return value
assert f(1, 8) == 1
|
benchmark_functions_edited/f9791.py
|
def f(num):
if num % 2 != 0 : return 1
factor = 0
while num % 2 == 0 :
num /= 2
factor += 1
return factor
assert f(3) == 1
|
benchmark_functions_edited/f1832.py
|
def f(a, b):
return (not a) == (not b)
assert f(-1, -1) == 1
|
benchmark_functions_edited/f7841.py
|
def f(value, alignment):
remains = value % alignment
return value - remains + (alignment if remains else 0)
assert f(1, 7) == 7
|
benchmark_functions_edited/f8630.py
|
def f(assignment):
length = len(assignment)
max = -1
for i in range(length):
if assignment[i] > max:
max = assignment[i]
return max + 1
assert f([3, 3, 3, 1]) == 4
|
benchmark_functions_edited/f8815.py
|
def f(atNum):
if atNum <= 2:
return 1
if atNum <= 10:
return 2
if atNum <= 18:
return 3
if atNum <= 36:
return 4
if atNum <= 54:
return 5
if atNum <= 86:
return 6
return 7
assert f(29) == 4
|
benchmark_functions_edited/f11875.py
|
def f(severity: str) -> int:
severity_dictionary = {
'Unknown': 0,
'Low': 1,
'Medium': 2,
'High': 3,
'Critical': 4
}
return severity_dictionary.get(severity, 0)
assert f('Unknown') == 0
|
benchmark_functions_edited/f2145.py
|
def f(n, smallest, largest):
return max(smallest, min(n, largest))
assert f(3, 2, 3) == 3
|
benchmark_functions_edited/f3909.py
|
def f(array):
count = 0
while array:
count += array[-1]
array.pop()
print(array)
return count
assert f( [1]) == 1
|
benchmark_functions_edited/f10246.py
|
def f(z, p):
degree = len(p) - len(z)
if degree < 0:
raise ValueError("Improper transfer function. "
"Must have at least as many poles as zeros.")
else:
return degree
assert f((1, 2), (3, 4)) == 0
|
benchmark_functions_edited/f9623.py
|
def f(tweet):
for member in ["ahmad", "severin", "sina", "ute", "mean"]:
if member in tweet:
return int(tweet[member])
raise KeyError("tweet-dict doesn't contain any of our names nor 'mean'")
assert f(
{"ahmad": "0", "severin": "0", "sina": "0", "ute": "0", "mean": "0"}) == 0
|
benchmark_functions_edited/f1294.py
|
def f(hex_or_dec):
return int(hex_or_dec, 0)
assert f('0b10') == 2
|
benchmark_functions_edited/f10538.py
|
def f(bits):
val = int(bits,2)
bits = len(bits)
if (val & (1 << (bits - 1))) != 0: # if sign bit is set e.g., 8bit: 128-255
val = val - (1 << bits) # compute negative value
return(val)
assert f(bin(0)) == 0
|
benchmark_functions_edited/f6606.py
|
def f(F):
return (F-32) * 5/9
assert f(32) == 0
|
benchmark_functions_edited/f7340.py
|
def f(tokens):
full_verbs = [k for k in tokens if k.full_pos.startswith('VV')]
for t in full_verbs:
t.pos_color.append('Full verbs')
return len(full_verbs)
assert f([]) == 0
|
benchmark_functions_edited/f1578.py
|
def f(ip, n):
s = (3-n) * 8
return (ip >> s) & 0xff
assert f(1, 2) == 0
|
benchmark_functions_edited/f11929.py
|
def f(lst):
max = 0
for i in range(1,len(lst)-1):
if i == len(lst)-2:
if lst[i+1] > max:
max= lst[i+1]
elif lst[i-1] < lst[i] and lst[i+1] < lst[i]:
if lst[i] > max:
max= lst[i]
return max
assert f(list()) == 0
|
benchmark_functions_edited/f14307.py
|
def f(o0, o1):
if isinstance(o1, tuple):
for _o0, _o1 in zip(o0, o1):
cmp = f(_o0, _o1)
if cmp != 0:
return cmp
return 0
else:
if o0 is None:
o0 = 2
if o1 is None:
o1 = 2
if o0 < o1:
return -1
elif o0 > o1:
return 1
return 0
assert f((None, None), (None, None)) == 0
|
benchmark_functions_edited/f12548.py
|
def f(items, target):
mid = len(items) // 2
if len(items) == 0:
return None
elif items[mid] == target:
return mid
elif items[mid] < target:
res = f(items[mid + 1:], target)
return mid + res + 1 if res is not None else None
else:
return f(items[:mid], target)
assert f(list(range(1000)), 0) == 0
|
benchmark_functions_edited/f1672.py
|
def f(x, lst):
return len(list(filter(lambda e: x == e, lst)))
assert f(1, [1, 1, 1, 1, 1]) == 5
|
benchmark_functions_edited/f5511.py
|
def f(n1, n2):
return 1 - (((n1 - n2) ** 2) / ((n1 + n2) ** 2))
assert f(1, 1) == 1
|
benchmark_functions_edited/f3397.py
|
def f(previous_result):
m = 11 * 23
return previous_result ** 2 % m
assert f(2) == 4
|
benchmark_functions_edited/f6407.py
|
def f(AUC):
try:
return 2 * AUC - 1
except TypeError:
return "None"
assert f(1) == 1
|
benchmark_functions_edited/f7771.py
|
def f(n):
n -= 1 # greater than OR EQUAL TO n
shift = 1
while (n + 1) & n: # n+1 is not a power of 2 yet
n |= n >> shift
shift *= 2
return max(4, n + 1)
assert f(6) == 8
|
benchmark_functions_edited/f7178.py
|
def f(arr: list) -> int:
no_repeats = []
for i in sorted(arr):
if arr.count(i) == 1:
no_repeats.append(i)
return (sum(no_repeats))
assert f(
[0, 0, 0, 0, 0, 0, 0, 0]) == 0
|
benchmark_functions_edited/f10359.py
|
def f(bits, bit, value):
mask = 1 << bit
return bits | mask if value else bits & ~mask
assert f(3, 3, False) == 3
|
benchmark_functions_edited/f14085.py
|
def f(y_true, y_pred):
total = len(y_true)
matches = sum(1 for yseq_true, yseq_pred in zip(y_true, y_pred) if list(yseq_true) == list(yseq_pred))
return matches / total
assert f(list('AA'), list('BB')) == 0
|
benchmark_functions_edited/f2606.py
|
def f(tiles):
accu = 0
for tile in tiles:
accu = accu + tile[2]
return accu
assert f([(1, 1, 3), (1, 1, 4), (3, 2, 2)]) == 9
|
benchmark_functions_edited/f2959.py
|
def f(orgao, splitter):
return len(orgao.split(splitter))
assert f(" ", ".") == 1
|
benchmark_functions_edited/f14408.py
|
def f(arr, n):
count_dict = dict()
majority = n // 2
for ele in arr:
if ele in count_dict:
count_dict[ele] += 1
if count_dict[ele] >= majority:
return ele
else:
count_dict[ele] = 1
return -1
assert f(
[1, 1, 1, 2, 2, 2, 1, 1, 1], 5) == 1
|
benchmark_functions_edited/f8912.py
|
def f(token, word2Idx):
if token in word2Idx:
return word2Idx[token]
elif token.lower() in word2Idx:
return word2Idx[token.lower()]
return word2Idx["UNKNOWN_TOKEN"]
assert f( "this", {"this" : 1, "is" : 2} ) == 1
|
benchmark_functions_edited/f10978.py
|
def f(x, x_min, x_max, out_min, out_max, limit=False):
r = float(x - x_min) * float(out_max - out_min) / \
float(x_max - x_min) + float(out_min)
if limit:
return sorted([out_min, r, out_max])[1]
else:
return r
assert f(100, 0, 100, -100, 0) == 0
|
benchmark_functions_edited/f6263.py
|
def a (x: int, y: float) -> int:
return 1
# Call tesnor flow here
assert f(1, 2) == 1
|
benchmark_functions_edited/f7241.py
|
def f(possible_matches):
count = 0
for score, request in possible_matches:
if score.is_exact_match():
count += 1
return count
assert f([]) == 0
|
benchmark_functions_edited/f2871.py
|
def f(a, b):
if not b:
raise ValueError("Cannot divide by zero!")
return a / b
assert f(10, 5) == 2
|
benchmark_functions_edited/f5140.py
|
def f(n: int, map={}):
if n == 1:
return 1
if n not in map:
map[n] = 1 + f(n - f(f(n - 1)))
return map[n]
assert f(9) == 5
|
benchmark_functions_edited/f2099.py
|
def f(data):
return data.real**2+data.imag**2
assert f(-3) == 9
|
benchmark_functions_edited/f4723.py
|
def f(prev, crctab, byte):
return crctab[(prev^byte)&0xff] ^ (prev>>8)
assert f(0, [1 for i in range(256)], 0) == 1
|
benchmark_functions_edited/f14013.py
|
def f(ec2_c, sg_id, port):
try:
ec2_c.f(
GroupId=sg_id.id,
IpPermissions=[{
'IpProtocol': 'tcp',
'FromPort': int(port),
'ToPort': int(port),
'IpRanges': [{'CidrIp': '0.0.0.0/0'}]
}]
)
except Exception as e:
print(e)
return 0
assert f(None,'sg-12345678', 23) == 0
|
benchmark_functions_edited/f2306.py
|
def f(base_minor, base_major, height):
return height * (base_minor + base_major) / 2
assert f(1, 1, 1) == 1
|
benchmark_functions_edited/f6587.py
|
def f(n: int) -> int:
curr: int = 1
prev: int = 1
for i in range(2, n):
prev, curr = curr, curr + prev
return curr
assert f(2) == 1
|
benchmark_functions_edited/f13351.py
|
def f(array, item):
for index, value in enumerate(array):
if item == value:
return index # found
return None
assert f(list('abc'), 'c') == 2
|
benchmark_functions_edited/f4118.py
|
def f(border, size):
i = 1
while size - border // i <= border // i: # size > 2 * (border // i)
i *= 2
return border // i
assert f(3, 4) == 1
|
benchmark_functions_edited/f5790.py
|
def f(n: int) -> int:
return n * (2 * n - 1)
assert f(1) == 1
|
benchmark_functions_edited/f4588.py
|
def f(x, y):
return ((x + y) * (x + y + 1) / 2) + y
assert f(0, 1) == 2
|
benchmark_functions_edited/f7610.py
|
def f(*args):
sum = args[0]
while any(map(lambda x: sum % x != 0, args)):
sum += args[0]
return sum
assert f(*[1,2,3]) == 6
|
benchmark_functions_edited/f2764.py
|
def f(value):
if value < 0:
return 0
return value
assert f(5) == 5
|
benchmark_functions_edited/f967.py
|
def f(func):
return func.__code__.co_argcount
assert f(lambda a: 0) == 1
|
benchmark_functions_edited/f12345.py
|
def f(t, beta):
varcope = (beta / t) ** 2
return varcope
assert f(1, 2) == 4
|
benchmark_functions_edited/f3338.py
|
def f(val, n):
return (val % 0x100000000) >> n
assert f(4, 2) == 1
|
benchmark_functions_edited/f11441.py
|
def f(arr, val):
left = 0
right = len(arr) - 1
half = (left + right) // 2
while arr[half] != val:
if val < arr[half]:
right = half - 1
else:
left = half + 1
half = (left + right) // 2
if arr[half] == val:
return half
return -1
assert f(range(10), 0) == 0
|
benchmark_functions_edited/f3287.py
|
def f(a, b):
return (a+b)*(a+b+1)/2 + b
assert f(0, 0) == 0
|
benchmark_functions_edited/f12154.py
|
def f(dir_list):
count = 0
number = 0
length = 0
for dirs in dir_list:
if length < len(dirs):
length = len(dirs)
number = count
count += 1
return number
assert f(
[
['a'],
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
]
) == 1
|
benchmark_functions_edited/f13746.py
|
def f(container_, search_element_) -> int:
position = 0
iteration = 0
while position < len(container_):
if container_[position] == search_element_:
return position
iteration += 1
position += 1
return -1
assert f(
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4
) == 4
|
benchmark_functions_edited/f7312.py
|
def f(grading, max_grade):
inverse_grading = -grading + max_grade
return (2 ** inverse_grading - 1) / (2 ** max_grade)
assert f(10, 10) == 0
|
benchmark_functions_edited/f9351.py
|
def f(s1,s2):
count = 0
start = 0
while True:
search = s1.find(s2,start)
if search == -1:
break
else:
count +=1
start = search+1
return count
assert f( "abracadabra", "abra" ) == 2
|
benchmark_functions_edited/f6798.py
|
def f(success_cost, failure_cost, p):
return p * success_cost + failure_cost * (1 - p)
assert f(1, 10, 1) == 1
|
benchmark_functions_edited/f9743.py
|
def f(i,j,n_class):
assert(i<n_class and j<n_class)
return (i)*n_class + j
assert f(0, 1, 2) == 1
|
benchmark_functions_edited/f1277.py
|
def f(iterator):
return sum(1 for _ in iterator)
assert f(iter([1, 2, 3])) == 3
|
benchmark_functions_edited/f7495.py
|
def f(parts):
ts, ms, seq = parts
return ts * 1024000 + ms * 1024 + seq
assert f((0, 0, 0)) == 0
|
benchmark_functions_edited/f2064.py
|
def f(n):
if n <= 2:
return 1
return f(n - 1) + f(n - 2)
assert f(5) == 5
|
benchmark_functions_edited/f14492.py
|
def f(mev):
joule = mev * (10 ** 6) * (1.6 * 10 ** -19)
return joule
assert f(0) == 0
|
benchmark_functions_edited/f8292.py
|
def f(values):
return sum(values)/float(len(values)) if len(values) > 0 else 0.0
assert f( [1] ) == 1
|
benchmark_functions_edited/f1685.py
|
def f(a, b):
(x1, y1) = a
(x2, y2) = b
return abs(x1 - x2) + abs(y1 - y2)
assert f( (1,1), (0,1) ) == 1
|
benchmark_functions_edited/f5934.py
|
def f(idx, vector_size):
if idx < 0: return vector_size + idx
if idx >= vector_size : return idx - vector_size
else: return idx
assert f(7, 5) == 2
|
benchmark_functions_edited/f960.py
|
def f(tpl):
return sum([v<<k for k,v in enumerate(tpl)])
assert f( (0,1,0) ) == 2
|
benchmark_functions_edited/f6411.py
|
def f(ctx, lst):
if len(lst) == 1:
return lst[0]
if len(lst) == 2:
return ctx['ap('](lst[-2], lst[-1])
return f(ctx, lst[:-2] + [f(ctx, lst[-2:])])
assert f(
{
'ap(': lambda a, b: a(b),
},
[lambda x: x + 1, 1]
) == 2
|
benchmark_functions_edited/f360.py
|
def f(v):
return (v * v)**(1/2)
assert f(1) == 1
|
benchmark_functions_edited/f9576.py
|
def f(input):
checksum = 0
for i, val in enumerate(input):
checksum += (i + 1) * int(val)
return checksum % 10
assert f("0000000000") == 0
|
benchmark_functions_edited/f10037.py
|
def f(od):
if isinstance(od, dict):
return 1 + (max(map(get_depth, od.values())) if od else 0)
return 0
assert f(0) == 0
|
benchmark_functions_edited/f7260.py
|
def f(im_name, parse_type='id'):
assert parse_type in ('id', 'cam')
if parse_type == 'id':
parsed = int(im_name[:8])
else:
parsed = int(im_name[9:13])
return parsed
assert f(
'000000000.jpg') == 0
|
benchmark_functions_edited/f4674.py
|
def f(rate, periods):
return (1 + rate) ** (1 / periods) - 1
assert f(0, 5) == 0
|
benchmark_functions_edited/f4565.py
|
def f(number):
count = 0
while number > 0:
number = number // 10
count += 1
return count
assert f(11235) == 5
|
benchmark_functions_edited/f11552.py
|
def f(Fmask, cloud_shadow, dilatation):
cloud_shadow_Fmask = cloud_shadow * Fmask
dilatation_Fmask = (dilatation - cloud_shadow) * 4
other_Mask = - (dilatation - 1)
remain_Fmask = other_Mask * Fmask
return cloud_shadow_Fmask + dilatation_Fmask + remain_Fmask
assert f(8, 0, 1) == 4
|
benchmark_functions_edited/f11860.py
|
def f(times, diffusion_coefficient, dimensions=2):
return 2 * dimensions * diffusion_coefficient * times
assert f(2, 0) == 0
|
benchmark_functions_edited/f8009.py
|
def f(bill, tip_percent):
return bill * (tip_percent / 100)
assert f(10, 40) == 4
|
benchmark_functions_edited/f1290.py
|
def f(x):
mult3=x//3
return mult3
assert f(3) == 1
|
benchmark_functions_edited/f8253.py
|
def f(Property_Area):
if Property_Area == 'Urban':
return 1
elif Property_Area == 'Rural':
return 0
else:
return 2
assert f('Random') == 2
|
benchmark_functions_edited/f12092.py
|
def f(v):
n = len(v)
sorted_v = sorted(v)
midpoint = n // 2
if n % 2 == 1:
# if odd, return the middle value
return sorted_v[midpoint]
else:
# if even, return the average of the middle values
lo = midpoint - 1
hi = midpoint
return (sorted_v[lo] + sorted_v[hi]) / 2
assert f( [1, 1, 2] ) == 1
|
benchmark_functions_edited/f2532.py
|
def f(poly):
for idx, coeff in enumerate(poly):
if coeff == 1:
return len(poly) - idx - 1
return 0
assert f((1, 2, 3, 4)) == 3
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.