file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f2641.py
|
def f(chars, text, i):
while i < len(text):
if text[i] not in chars: return i
i += 1
return None
assert f(set(" "), "Hello, world!", 6) == 7
|
benchmark_functions_edited/f12211.py
|
def f(number):
if number % 3 == 0 and number % 5 == 0:
return "FizzBuzz";
elif number % 3 == 0:
return "Fizz";
elif number % 5 == 0:
return "Buzz";
else:
return number;
assert f(2) == 2
|
benchmark_functions_edited/f2972.py
|
def f(nodes):
return max(nodes) + 1
assert f({0, 1, 2, 3, 4, 5}) == 6
|
benchmark_functions_edited/f9660.py
|
def f(x):
if x != 3 and x != -2:
return (x+3)/(x**2 -x -6)
#return (16-2*x)*(30-2*x)*x
#if x<=1:
# return .5*x -3
#else:
# return 4*x+3
#return x/ (x**2+4)
#return (x+3)/(x**2 - x -6)
#if x <= 2:
# return math.sqrt(4 - x**2)
assert f(-3) == 0
|
benchmark_functions_edited/f4905.py
|
def f(recordLines):
size = 0
for line in recordLines:
size += len(line)
return size
assert f([]) == 0
|
benchmark_functions_edited/f12123.py
|
def f(element_idx, it):
try:
return it[element_idx]
except TypeError: # it is not a list
pass
for i, el in enumerate(it):
if i == element_idx:
return el
raise IndexError('Iterator does not have {} elements'.format(element_idx))
assert f(0, range(10)) == 0
|
benchmark_functions_edited/f5113.py
|
def f(p, f, a):
while not p(a):
a = f(a)
return a
assert f(lambda x: x == 3, lambda x: x + 2, 1) == 3
|
benchmark_functions_edited/f1597.py
|
def f(x, min_val, max_val):
return max(min(x,max_val),min_val)
assert f(1, 1, 3) == 1
|
benchmark_functions_edited/f3840.py
|
def f(vec):
for i in range(len(vec)):
if vec[i] is None:
return i
return -1
assert f([None, None, None]) == 0
|
benchmark_functions_edited/f9047.py
|
def f(val, bits=8):
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 # return positive value as is
assert f(1) == 1
|
benchmark_functions_edited/f246.py
|
def dg ( gxw ):
return gxw*(1-gxw)
assert f(0) == 0
|
benchmark_functions_edited/f5817.py
|
def f(marks):
absent_count = 0
for mark in marks:
if mark == 0:
absent_count += 1
return absent_count
assert f([0,0,0,0,0]) == 5
|
benchmark_functions_edited/f8290.py
|
def f(x, x_min, x_max, y_min, y_max):
x = float(x)
x_range = x_max - x_min
y_range = y_max - y_min
xy_ratio = x_range / y_range
y = ((x - x_min) / xy_ratio + y_min)
return int(y)
assert f(0, 0, 10, 0, 100) == 0
|
benchmark_functions_edited/f7049.py
|
def f(lista):
maior = max(lista)
return maior
assert f([1, 2]) == 2
|
benchmark_functions_edited/f4030.py
|
def f(val):
if abs(val) < 1e-3:
return 0
else:
return val
assert f(2) == 2
|
benchmark_functions_edited/f12135.py
|
def f(delay):
number_str_array = [c for c in delay if c.isdigit()]
number = int(''.join(number_str_array))
if delay[0] == "-":
return -number
else:
return number
assert f(str(3)) == 3
|
benchmark_functions_edited/f673.py
|
def f(bits):
return int(bits, 2)
assert f(b"00000010") == 2
|
benchmark_functions_edited/f8485.py
|
def f(my_cities, other_cities):
all_cities = list(set(my_cities + other_cities))
return 2 * len(all_cities) - len(my_cities) - len(other_cities)
assert f(
['Adelaide', 'Brisbane', 'Darwin'],
['Sydney', 'Melbourne', 'Canberra']
) == 6
|
benchmark_functions_edited/f6921.py
|
def f(num_components, num_samples, num_dimensions):
if num_components is None:
num_components = min(num_samples, num_dimensions)
return num_components
assert f(3, 5, 4) == 3
|
benchmark_functions_edited/f11993.py
|
def f(number: int) -> int:
number = abs(number)
count = 0
while True:
number = number // 10
count = count + 1
if number == 0:
break
return count
assert f(-12345) == 5
|
benchmark_functions_edited/f6950.py
|
def f(cigar_code):
if cigar_code == 254:
return 0
if cigar_code == 152:
return 1
if cigar_code == 76:
return 2
assert f(254) == 0
|
benchmark_functions_edited/f604.py
|
def f(nir, red, blue=None):
return 2.4*(nir - red) / (nir + 2.4*red + 10_000)
assert f(1, 1) == 0
|
benchmark_functions_edited/f1459.py
|
def f(l, w, h):
return min([(l * w), (w * h), (h * l)])
assert f(1000000000, 1, 1) == 1
|
benchmark_functions_edited/f1034.py
|
def f(x: float) -> float:
if x < 0:
return 0
return x
assert f(-1) == 0
|
benchmark_functions_edited/f13055.py
|
def f(x, y, marks, w, h):
for mark in marks:
x_range = range(x - int(w/2), x + int(w/2)+1)
y_range = range(y - int(h/2), y + int(h/2)+1)
for yy in y_range:
for xx in x_range:
if mark.intCenterX_r == xx and mark.intCenterY_r == yy:
return 1
return 0
assert f(0, 0, [], 0.5, 0.5) == 0
|
benchmark_functions_edited/f11546.py
|
def f(x, B=1/3., C=1/3.):
if abs(x) < 1:
return 1/6. * ((12-9*B-6*C)*abs(x)**3 + ((-18+12*B+6*C)*abs(x)**2 + (6-2*B)))
elif 1 <= abs(x) and abs(x) < 2:
return 1/6. * ((-B-6*C)*abs(x)**3 + (6*B+30*C)*abs(x)**2 + (-12*B-48*C)*abs(x) + (8*B+24*C))
else:
return 0
assert f(2.5) == 0
|
benchmark_functions_edited/f9834.py
|
def f(event, attributes):
score = 0
for attribute in attributes:
if attribute["category"] == "Network activity":
ty = attribute["type"]
if ty == "ip-src":
score += 3
return score
assert f(None, [{"category":"Network activity", "type":"ip-src"}, {"category":"Network activity", "type":"email-src"}, {"category":"Network activity", "type":"file-name"}, {"category":"Network activity", "type":"file-path"}]) == 3
|
benchmark_functions_edited/f3217.py
|
def f(val, none_val=None):
if val is None:
return none_val
else:
return int(val)
assert f(3.5) == 3
|
benchmark_functions_edited/f146.py
|
def f(x, y):
return x.__and__(y)
assert f(1, 0) == 0
|
benchmark_functions_edited/f6386.py
|
def f(x, y):
if x == 0:
if y == 0: raise ValueError("0^0")
elif x < 0:
if y != int(y): raise ValueError("non-integer power of negative")
return x ** y
assert f(-1, 2) == 1
|
benchmark_functions_edited/f4179.py
|
def f(items, default=None):
for item in items:
return item
return default
assert f(
[1, 2, 3, 4, 5], 0) == 1
|
benchmark_functions_edited/f2419.py
|
def f(x,a,b,c,d):
return (x-a)*((d-c)/(b-a))+c
assert f(1, 1, 2, 2, 3) == 2
|
benchmark_functions_edited/f5422.py
|
def f(portrait_fname):
return int(portrait_fname.split('/')[-1].split('.')[0])
assert f(
'../data/portraits/flickr/cropped/portraits/0004.jpg') == 4
|
benchmark_functions_edited/f10722.py
|
def f(t, dof):
t_squared = t * t
return t_squared / (t_squared + dof)
assert f(0, 16) == 0
|
benchmark_functions_edited/f12643.py
|
def f(n, costheta):
i, j = 0, 1
a = n[j] * costheta[i] - n[i] * costheta[j]
b = n[j] * costheta[i] + n[i] * costheta[j]
return a/b
assert f([1, 2], [-1, 0]) == 1
|
benchmark_functions_edited/f9444.py
|
def f(page_count: int) -> int:
n_batches = page_count // 100 + 1
return n_batches
assert f(10) == 1
|
benchmark_functions_edited/f3630.py
|
def f(li):
m = li[0]
for value in li:
if value > m:
m = value
return m
assert f([2, 3, 4, 5, 2]) == 5
|
benchmark_functions_edited/f9987.py
|
def f(iterable, func=lambda L: L is not None, **kwargs):
it = (el for el in iterable if func(el))
if 'default' in kwargs:
return next(it, kwargs['default'])
return next(it)
assert f(
[1, 2, 3, 4, 5],
lambda x: x % 2 == 0
) == 2
|
benchmark_functions_edited/f4290.py
|
def f(comb, value):
total = 0
for i in comb:
total = total + value[i]
return total
assert f(set([]), {}) == 0
|
benchmark_functions_edited/f1752.py
|
def f(C_mgl, A_catch):
C_kgmm = C_mgl*A_catch
return C_kgmm
assert f(0, 10000) == 0
|
benchmark_functions_edited/f2769.py
|
def latest (scores):
return scores[-1]
assert f([1, 3, 0, 7]) == 7
|
benchmark_functions_edited/f14351.py
|
def f(y, constraint_set):
constraint_keys = constraint_set['constraints']
gradient = 0
for key in constraint_keys:
current_constraint = constraint_set[key]
a_matrix = current_constraint['A']
bound_loss = current_constraint['bound_loss']
for i, _ in enumerate(a_matrix):
constraint = a_matrix[i]
gradient += 2*constraint * bound_loss[i]
return gradient
assert f(1, { 'constraints': [] }) == 0
|
benchmark_functions_edited/f12766.py
|
def f(a, b):
saved = b
x, y, u, v = 0, 1, 1, 0
while a:
q, r = b // a, b % a
m, n = x - u*q, y - v*q
b, a, x, y, u, v = a, r, u, v, m, n
return x % saved
assert f(1337, 1337) == 1
|
benchmark_functions_edited/f105.py
|
def f(data):
return data.__len__()
assert f(set([0, 'a'])) == 2
|
benchmark_functions_edited/f9523.py
|
def f(point,start,end):
check=0
for i in point:
if i == start or i == end:
check+=1
return check
assert f([1, 2, 3, 4], 0, 4) == 1
|
benchmark_functions_edited/f2025.py
|
def f(ni, agents, compcost):
return sum(compcost(ni, agent) for agent in agents) / len(agents)
assert f(0, [1,2,3,4], lambda ni, a: 1) == 1
|
benchmark_functions_edited/f3532.py
|
def f(s: int) -> int:
if (s & (s - 1) == 0) and s != 0:
return s
else:
return 0
assert f(7) == 0
|
benchmark_functions_edited/f3525.py
|
def f(f, seq):
for index, item in enumerate(seq):
if f(item):
return index
assert f(lambda x: x == 2, [2, 2, 2, 2, 2]) == 0
|
benchmark_functions_edited/f14012.py
|
def f(ivc, actual_yield, burst_height):
if ivc == 9:
return 1
else:
groundburst = 10 - ivc
if ivc == 3 or ivc == 2:
groundburst = groundburst + 1
if burst_height == 0 or actual_yield <= 100:
return groundburst
else:
return groundburst - 1
assert f(9, 0, 15) == 1
|
benchmark_functions_edited/f4262.py
|
def f(score, opponent_score):
"*** YOUR CODE HERE ***"
return 5
assert f(9999, 9999) == 5
|
benchmark_functions_edited/f11380.py
|
def f(it):
return next(iter(it), None)
assert f([3]) == 3
|
benchmark_functions_edited/f8635.py
|
def f(authors_in_paper):
#I check if there is at least 1 author otherwise the weight is 0
if len(authors_in_paper) > 0:
return 1./len(authors_in_paper)
else:
return 0
assert f(set(['a'])) == 1
|
benchmark_functions_edited/f1467.py
|
def f(x, y):
if y == 0:
raise ValueError("Can not divide by zero!")
return x / y
assert f(10, 2) == 5
|
benchmark_functions_edited/f5595.py
|
def f(a, min_, max_):
return max_ if a >= max_ else min_ if a <= min_ else a
assert f(-1, 0, 5) == 0
|
benchmark_functions_edited/f8483.py
|
def f(slayer_xp, exp):
for i in range(len(exp)):
if slayer_xp < exp[i]:
return i
if slayer_xp > exp[len(exp) - 1]:
return len(exp)
if slayer_xp == exp[i]:
return i
assert f(1000, [0, 50, 100, 200, 400, 1000]) == 5
|
benchmark_functions_edited/f9566.py
|
def f(n, memo = {}):
if n == 0 or n == 1:
return 1
try:
return memo[n]
except KeyError:
result = f(n-1, memo) + f(n-2, memo)
memo[n] = result
return result
assert f(0) == 1
|
benchmark_functions_edited/f4238.py
|
def f(seconds):
day = int(seconds)/86400
assert day < 58, 'Too many seconds, reached day %s' % day
return day
assert f(86400) == 1
|
benchmark_functions_edited/f6390.py
|
def f(a, x):
i = 0
while i < len(a) and a[i] != x:
i += 1
if i == len(a):
return None
else:
return i
assert f([1,1,1,1,1], 1) == 0
|
benchmark_functions_edited/f8313.py
|
def f(int_bytes):
x = int_bytes[0]
x |= int_bytes[1] << 8
x |= int_bytes[2] << 16
x |= int_bytes[3] << 24
return x
assert f(b"\x00\x00\x00\x00") == 0
|
benchmark_functions_edited/f11726.py
|
def f(tokens):
ntoks = 0
for tok in tokens:
if tok.isspace() or tok == ',':
continue
elif tok in ('=', '/', '$', '&'):
if ntoks > 0 and tok == '=':
ntoks -= 1
break
else:
ntoks += 1
return ntoks
assert f(['foo', '=', 'bar', ';', 'baz']) == 0
|
benchmark_functions_edited/f8387.py
|
def f(nums):
part1=0
part2=sum(nums)
for i,num in enumerate(nums): #enumerate is faster than range when using index
#to locate an element
part2-=num
if part1 == part2:
return i
part1+=num
return -1
assert f(
[1, 7, 3, 6, 5, 6]) == 3
|
benchmark_functions_edited/f13505.py
|
def f(enc_mes):
if not enc_mes or enc_mes[0] == "0":
return 0
last_char, last_two_chars = 1, 1
for i in range(1, len(enc_mes)):
last = last_char if enc_mes[i] != "0" else 0
last_two = last_two_chars if int(enc_mes[i-1:i+1]) < 27 and enc_mes[i-1] != "0" else 0
last_two_chars = last_char
last_char = last+last_two
return last_char
assert f("1234567") == 3
|
benchmark_functions_edited/f8573.py
|
def f(np_array, max_value=1, min_value=-1, x_max=255, x_min=0):
return ((np_array - x_min) / (x_max - x_min)) * (max_value - min_value) + min_value
assert f(127.5) == 0
|
benchmark_functions_edited/f4119.py
|
def f(col, row, m):
return row * m + col
assert f(1, 1, 4) == 5
|
benchmark_functions_edited/f3886.py
|
def f(prices):
return prices[-1]
assert f([5,4,3,2,1]) == 1
|
benchmark_functions_edited/f551.py
|
def f(s):
return s * (1 - s)
assert f(0) == 0
|
benchmark_functions_edited/f10016.py
|
def f(bytes_to_convert):
integer = None
for chunk in bytes_to_convert:
if not integer:
integer = chunk
else:
integer = integer << 8
integer = integer | chunk
return integer
assert f(b'\x00\x00\x00\x03') == 3
|
benchmark_functions_edited/f10353.py
|
def f(vector):
return 100*((vector[0] - vector[-1])/vector[-1])
assert f(list(range(1000))[1:2]) == 0
|
benchmark_functions_edited/f3794.py
|
def f(x,step):
from math import floor
if step == 0: return x
return floor(float(x)/float(step))*step
assert f(0,10) == 0
|
benchmark_functions_edited/f12259.py
|
def f(k, n, m):
ans = 1
while n:
if n & 1:
ans = (ans*k) % m
k = (k*k) % m
n >>= 1
return ans
assert f(2, 14, 3) == 1
|
benchmark_functions_edited/f6476.py
|
def f(t):
t1 = t*1e9%2.0
if t1<1.0:
return 0
else:
return 1.0
assert f(2.0) == 0
|
benchmark_functions_edited/f5772.py
|
def f(map):
total = 0
for key, val in map.items():
total += val
return total
assert f({'a': 2, 'b': 3, 'c': -1}) == 4
|
benchmark_functions_edited/f7385.py
|
def f(string):
length = 0
for char in string:
length = length + 2 if len(char.encode('utf8')) == 3 else length + 1
return length
assert f(u'♣') == 2
|
benchmark_functions_edited/f9994.py
|
def f(num):
flag = 1
count = 0
for i in range(num.bit_length()):
if flag & num:
count += 1
flag <<= 1
return count
assert f(0b00000000000000000000000001000000) == 1
|
benchmark_functions_edited/f12522.py
|
def f(ramp_data, start_time, end_time, value_final,
time_subarray):
value_initial = ramp_data["value"]
value_final2 = ramp_data["value_final"]
interp = (time_subarray - start_time)/(end_time - start_time)
return value_initial*(1.0 - interp) + value_final2*interp
assert f(
{"value": 2.0, "value_final": 1.0}, 0, 2, 1, 2) == 1
|
benchmark_functions_edited/f12620.py
|
def f(s, q):
return len(set(s) ^ set(q))
assert f(set([1, 2, 3]), set([2, 4])) == 3
|
benchmark_functions_edited/f2691.py
|
def f(data, index):
result = data[index]
if result > 127:
result -= 256
return result
assert f(bytes([1, 0, 0]), 0) == 1
|
benchmark_functions_edited/f1755.py
|
def f(x):
n = 2
while n < x:
n = n * 2
return n
assert f(5) == 8
|
benchmark_functions_edited/f505.py
|
def f(key):
return (key >> 16) & 0xFF
assert f(0x00000000) == 0
|
benchmark_functions_edited/f10794.py
|
def f(gray_value):
mask = gray_value >> 1
while mask != 0:
gray_value = gray_value ^ mask
mask = mask >> 1
return int(gray_value)
assert f(1) == 1
|
benchmark_functions_edited/f13273.py
|
def f(x):
try:
n = int(x)
except Exception as ex:
raise ValueError("invalid literal for f()")
if n < 0:
raise ValueError("invalid literal for f()")
return n
assert f("1") == 1
|
benchmark_functions_edited/f5325.py
|
def f( sexpr ):
pos = sexpr.find( '\n' )
if pos >= 0:
return pos + 1
return len( sexpr )
assert f( ';') == 1
|
benchmark_functions_edited/f5465.py
|
def f(a_list:list, item):
idx = len(a_list)
a_list.append(item)
return idx
assert f([0, 1], 2) == 2
|
benchmark_functions_edited/f4590.py
|
def f(bus_voltage_register):
return (bus_voltage_register >> 1) & 0x1
assert f(0b0000) == 0
|
benchmark_functions_edited/f2095.py
|
def f(g):
n = 0
while g:
n ^= g
g >>= 1
return n
assert f(0) == 0
|
benchmark_functions_edited/f8353.py
|
def f(pkt_val_1, pkt_val_2, pkt_val_3=None):
if pkt_val_3 is None:
float_val = pkt_val_1 << 8 | pkt_val_2
else:
float_val = pkt_val_1 << 16 | pkt_val_2 << 8 | pkt_val_3
return float_val/100
assert f(0, 0) == 0
|
benchmark_functions_edited/f878.py
|
def f(s1, s2):
return s1[0] * s2[1] - s1[1] * s2[0]
assert f( (2,0), (0,2) ) == 4
|
benchmark_functions_edited/f4232.py
|
def f(list=None):
list = list or []
if list:
list.reverse()
return int(''.join(list), 16)
return 0
assert f(None) == 0
|
benchmark_functions_edited/f3806.py
|
def f(str):
return sum((ord(c.lower()) * 13
for c in str), 0)
assert f(b"") == 0
|
benchmark_functions_edited/f2536.py
|
def f(*args):
return next((a for a in args if a is not None), None)
assert f(None, 2, 3) == 2
|
benchmark_functions_edited/f9706.py
|
def f(data):
data = sorted(data)
n = len(data)
if n == 0:
raise Exception('No median for an empty list')
if n%2 == 1:
return data[n//2]
else:
i = n//2
return (data[i-1] + data[i])/2
assert f([1, 3, 5, 7, 9]) == 5
|
benchmark_functions_edited/f1362.py
|
def f(k1, k2):
z = int(0.5 * (k1 + k2) * (k1 + k2 + 1) + k2)
return z
assert f(1, 0) == 1
|
benchmark_functions_edited/f12741.py
|
def f(input):
charges = {
0: 0,
"0": 0,
"+" or "+1" or "1+": 1,
"2+" or "+2": 2,
"3+" or "+3": 3,
"4+" or "+4": 4,
"5+" or "+5": 5,
"-" or "-1" or "1-": -1,
"2-" or "-2": -2,
"3-" or "-3": -3,
"4-" or "-4": -4,
"5-" or "-5": -5
}
return charges[input]
assert f("3+") == 3
|
benchmark_functions_edited/f9137.py
|
def f(number):
# Use only builtins to get this done. No control statements plz
return bin(number)[2:].count("1")
assert f(2**64) == 1
|
benchmark_functions_edited/f3776.py
|
def f(graph):
count = 0
for node in graph.keys():
count += len( graph[node] )
return count / 2
assert f( {'A':['B'], 'B':['C'], 'C':['D'], 'D':['A']} ) == 2
|
benchmark_functions_edited/f331.py
|
def f(x,y):
return max((x//2+x%2),(y//2+y%2))
assert f(0,0) == 0
|
benchmark_functions_edited/f1751.py
|
def f(layer, number):
return sum(row.count(number) for row in layer)
assert f(
[[1, 2, 3],
[2, 2, 1]],
1) == 2
|
benchmark_functions_edited/f13681.py
|
def f(nxs):
smallest = None
first_time = True
for e in nxs:
if type(e) == type([]):
val = f(e)
else:
val = e
if first_time or val < smallest:
smallest = val
first_time = False
return smallest
assert f([0, [1, 2, [1, 0]]]) == 0
|
benchmark_functions_edited/f10014.py
|
def f(x0, x, y):
return y[0] + (y[1]-y[0]) * (x0 - x[0])/(x[1] - x[0])
assert f(0, [0, 2], [0, 2]) == 0
|
benchmark_functions_edited/f383.py
|
def f(x):
try: return int(x)
except: return 0
assert f("str()") == 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.