file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f7309.py | def f(time_of_flight):
convert_to_inches = 147
inches = time_of_flight / convert_to_inches
return inches
assert f(0) == 0 |
benchmark_functions_edited/f9825.py | def f(d: list, e: int):
return (e % len(d) + len(d)) % len(d)
assert f(range(5), -7) == 3 |
benchmark_functions_edited/f4457.py | def f(s):
pos = s.find(b"\r\n\r\n")
if pos >= 0:
pos += 4
return pos
assert f(b"\r\n\r\n\r\n") == 4 |
benchmark_functions_edited/f11389.py | def poly (*args):
if len(args) ==1:
raise Exception ("You have only entered a value for x, and no coefficents.")
x = args[0] # X value
coef = args[1:]
result = 0
for power, c in enumerate(coef):
result += c * (x ** power + 1)
return result
assert f(3, 1, 1) == 6 |
benchmark_functions_edited/f1780.py | def f(x, y):
while y != 0:
(x, y) = (y, x % y)
return x
assert f(12, 9) == 3 |
benchmark_functions_edited/f12342.py | def f(price: str) -> int:
price = price.replace("$", "").replace(",", ".")
converted_price: float = float(price) * 100
return int(converted_price)
assert f(
"$0") == 0 |
benchmark_functions_edited/f14400.py | def f(a, b):
def interleave(args):
return ''.join([x for t in zip(*args) for x in t])
return int(''.join(interleave(format(x, '016b') for x in (a, b))), base=2)
assert f(0, 0) == 0 |
benchmark_functions_edited/f2424.py | def f(value, vector):
return sum(1 for num in vector if num == value)
assert f(1, [1, 2, 3, 4]) == 1 |
benchmark_functions_edited/f13001.py | def f(x, coefficients):
point = 0
# Loop through reversed list, so that indices from enumerate match the
# actual coefficient indices
for coefficient_index, coefficient_value in enumerate(coefficients[::-1]):
point += x ** coefficient_index * coefficient_value
return point
assert f(1, [1, 0, 1]) == 2 |
benchmark_functions_edited/f3353.py | def f( s ):
if s == '': return 0
lowbit = ord(s[-1]) - ord('0')
return lowbit + 2*f( s[:-1] )
assert f( '0111' ) == 7 |
benchmark_functions_edited/f6128.py | def f(num):
if num >= 0:
return num
else:
return -num
assert f(-2) == 2 |
benchmark_functions_edited/f6968.py | def f(n: int) -> int:
assert 0 <= n <= 255
return sum(
1 for i in range(8)
if (n >> i) % 2 == 1
)
assert f(255) == 8 |
benchmark_functions_edited/f8788.py | def f(expected, actual):
return abs(actual - expected)
assert f(1, 1) == 0 |
benchmark_functions_edited/f7706.py | def f(collection, key, default=None, args=[]):
result = collection.get(key, default)
if callable(result):
return result(*args)
return result
assert f(
{'x': lambda a: a}, 'x', 2, [3]) == 3 |
benchmark_functions_edited/f12063.py | def f(n):
if (n >= 48 and n <= 57): #nums
return 1;
if (n >= 65 and n <= 90): #uppers
return 2;
if (n >= 97 and n <= 122): #lowers
return 4;
else:
return 8;
assert f(35) == 8 |
benchmark_functions_edited/f12567.py | def f(offset, align):
remain = offset % align
if remain == 0:
return offset
else:
return offset + (align - remain)
assert f(1, 1) == 1 |
benchmark_functions_edited/f5809.py | def f(vector):
utility = vector[0] * vector[1]
return utility
assert f([0, 1]) == 0 |
benchmark_functions_edited/f67.py | def f(x):
return int(x ** 0.5)
assert f(0) == 0 |
benchmark_functions_edited/f408.py | def f(x, p):
return p[1] * (x / p[2]) ** p[0]
assert f(1, (2, 2, 1)) == 2 |
benchmark_functions_edited/f13076.py | def f(indicator1, indicator2):
try:
ratio = indicator1 / indicator2
except ZeroDivisionError:
return None
else:
return ratio
assert f(10, 10) == 1 |
benchmark_functions_edited/f9102.py | def f(x: dict, y: dict):
return sum(xi * y.get(i, 0) for i, xi in min(x, y, key=len).items())
assert f(dict(), dict()) == 0 |
benchmark_functions_edited/f249.py | def add (x, y):
return (2 + 5)
assert f(2, 5) == 7 |
benchmark_functions_edited/f10434.py | def f(risk):
_index = 0
if risk == 1.0:
_index = 1
elif risk == 1.1:
_index = 2
return _index
assert f(*[0.5]) == 0 |
benchmark_functions_edited/f14395.py | def f(input_num):
if input_num > 1:
last_power = 1
for i in range(1, int(input_num)):
if 2 ** i > input_num:
return int(last_power)
elif 2 ** i == input_num:
return int(input_num)
else:
last_power = 2 ** i
else:
... |
benchmark_functions_edited/f8001.py | def f(nshell, ncomponent):
return int((nshell+2) * (nshell+1) * nshell/3 * ncomponent)
assert f(0, 2) == 0 |
benchmark_functions_edited/f9397.py | def f(arg=None, state=None):
if arg is None:
arg = 1
if (arg % 10000) == 0:
print("Running", arg)
return arg
assert f(1, 2) == 1 |
benchmark_functions_edited/f11060.py | def f(N_to_1_leverage):
return (N_to_1_leverage-1)/float(N_to_1_leverage)
assert f(1) == 0 |
benchmark_functions_edited/f14152.py | def f(line: str) -> int:
# The largest value seen so far.
largest = -1
for value in line.split():
# Remove the trailing period.
v = int(value[:-1])
# If we find a larger value, remember it.
if v > largest:
largest = v
return largest
assert f('1. 3. 2. 5. 2.')... |
benchmark_functions_edited/f6110.py | def f(unit: int, number: int) -> int:
# Gets the number to have the desired
# digit on the last unit
while unit > 0:
number //= 10
unit -= 1
return number % 10
assert f(0, 135) == 5 |
benchmark_functions_edited/f3059.py | def f(a, b):
# wikipedia.org/wiki/Greatest_common_divisor#Euclid's_algorithm
return a if b == 0 else f(b, a % b)
assert f(20, 8) == 4 |
benchmark_functions_edited/f7057.py | def f(n, d):
count = 0
res = []
for num in range(n + 1):
k = num * num
for kay in str(k):
if kay == str(d):
res.append(str(kay))
count += 1
return count
assert f(10, 9) == 2 |
benchmark_functions_edited/f13870.py | def f(n_terms):
# XXX : The n_terms is an int that corresponds to the number of
# terms in the product. For example 10000.
pi = 2
if n_terms > 0:
for n in range(1, n_terms+1):
pi *= (4*n**2)/(4*n**2 - 1)
return pi
assert f(-5) == 2 |
benchmark_functions_edited/f14215.py | def f(digit):
digit = digit % 10
if digit == 0:
digit = 10
return digit
assert f(11) == 1 |
benchmark_functions_edited/f12842.py | def f(s_id):
if isinstance(s_id, str):
return int(str(s_id).split("-")[-1])
elif isinstance(s_id, (int, float)):
return s_id
else:
raise Exception("Could not parse {} into a number".format(s_id))
assert f("mp-0000001") == 1 |
benchmark_functions_edited/f7280.py | def f(s1, s2):
if len(s1) != len(s2):
raise ValueError("Undefined for sequences of unequal length")
return sum(el1 != el2 for el1, el2 in zip(s1, s2))
assert f(b"this is a test", b"this is a test") == 0 |
benchmark_functions_edited/f10113.py | def f(state_list):
return int((len(state_list)-1)/2)
assert f( [1, 1, -1, 1] ) == 1 |
benchmark_functions_edited/f12862.py | def f(aligned_seq1, aligned_seq2):
cnt = 0
current_cnt = 0
for i in range(len(aligned_seq2) - 3):
if aligned_seq2[i] != aligned_seq1[i]:
current_cnt += 1
else:
cnt += current_cnt > 0
current_cnt = 0
return cnt
assert f(
'TATACGATTACTAGCCTC',
'TATACGATTACTAGCCTG'
) == 0 |
benchmark_functions_edited/f3931.py | def f(a, b):
if type(a) is not int or type(b) is not int:
raise TypeError("Object is not of type int")
return a + b
assert f(-2, 5) == 3 |
benchmark_functions_edited/f2427.py | def f(foreground, background, style):
return foreground + (background << 4) + style
assert f(0, 0, 2) == 2 |
benchmark_functions_edited/f13509.py | def f(nodes, allow_zero=False):
if len(nodes) == 1:
return nodes[0]
elif len(nodes) == 0 and allow_zero:
return None
else:
raise ValueError(f"Unexpected number of nodes for {nodes}. Got {len(nodes)}, expected {'zero or ' if allow_zero else ''} one")
assert f([1]) == 1 |
benchmark_functions_edited/f11629.py | def f(dhms):
components = [int(i) for i in dhms.split(':')]
pad = 4 - len(components)
if pad < 0:
raise ValueError('Too many components to match [[[DD:]HH:]MM:]SS')
components = [0] * pad + components
return sum(i * j for i, j in zip((86400, 3600, 60, 1), components))
assert f('00:00') == 0 |
benchmark_functions_edited/f13411.py | def f(schema, ref):
value = schema.get(ref[0])
if value is None:
return None
for key in ref[1].split('/')[1:]:
try:
value = value[key]
except KeyError:
raise Exception(
'Ref "{}" not found in file "{}"'.format(ref[1][1:], ref[0]),
)... |
benchmark_functions_edited/f10629.py | def f(observed, expected):
if 0 in expected:
return 0.0
return sum((_o - _e) ** 2 / _e ** 2 for _o, _e in zip(observed, expected))
assert f(
[0, 1, 2],
[1, 1, 1]
) == 2 |
benchmark_functions_edited/f3652.py | def f(d):
return (d // 10) + (d % 10)
assert f(17) == 8 |
benchmark_functions_edited/f6513.py | def f(registers, opcodes):
test_result = registers[opcodes[1]] * registers[opcodes[2]]
return test_result
assert f(
[0, 2, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1]) == 0 |
benchmark_functions_edited/f13262.py | def f(s):
_dict = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
prev, cur, res = 0, 0, 0
for i in s[::-1]:
cur = _dict[i]
if prev > cur:
res -= cur
else:
res += cur
prev = cur
return res
assert f('IV') == 4 |
benchmark_functions_edited/f14055.py | def f(data):
n = len(data)
if n < 3:
raise Exception("need at least three data points")
sum1 = 0
sum2 = 0
for i in range(n):
if i > 0 and i < (n-1):
sum1 += abs((data[i-1] + data[i] + data[i+1]) / 3 - data[i])
sum2 += data[i]
sum1 /= float(n-2)
sum2 /= float(n)
return sum1 / sum2
assert f( [1, 1, 1, 1... |
benchmark_functions_edited/f10403.py | def f(utctz):
return -1 * int(float(utctz)/100*3600)
assert f("0") == 0 |
benchmark_functions_edited/f1235.py | def f(num: int) -> int:
if num % 2 == 0:
num += 1
return int(num)
assert f(2) == 3 |
benchmark_functions_edited/f2619.py | def f(old, new):
if new > old:
return old + 1
else:
return old - 1
assert f(5, 6) == 6 |
benchmark_functions_edited/f9757.py | def f(a, b):
if a == b:
return 0
elif [a, b] == ["R", "S"] or [a, b] == ["S", "P"] or [a, b] == ["P", "R"]:
return 1
return -1
assert f("P", "P") == 0 |
benchmark_functions_edited/f9830.py | def f(inputs): # DO NOT CHANGE THIS LINE
output = inputs
return output # DO NOT CHANGE THIS LINE
assert f(1) == 1 |
benchmark_functions_edited/f12057.py | def f(layers_range, router_id):
for itr, layer_range in enumerate(layers_range):
if router_id in layer_range:
return itr
assert f(
[[0, 10], [11, 20], [21, 25]],
25) == 2 |
benchmark_functions_edited/f8563.py | def f(n):
cache = { 0: 0, 1: 1 }
def fib(n):
nonlocal cache
if n in cache:
return cache[n]
res = fib(n-1) + fib(n-2)
cache[n] = res
return res
return fib(n)
assert f(0) == 0 |
benchmark_functions_edited/f10223.py | def f(arr, target):
for idx in range(len(arr)):
if arr[idx] == target: return idx
return None
assert f([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5], 5) == 4 |
benchmark_functions_edited/f12781.py | def f(level, maxval):
return int(level * maxval / 10)
assert f(5, 10) == 5 |
benchmark_functions_edited/f5377.py | def f(t1: int, t2: int, num: int) -> int:
if num == 1:
return t1
if num == 2:
return t2
return f(num - 2, t1, t2) + f(num - 1, t1, t2)**2
assert f(1, 1, 1) == 1 |
benchmark_functions_edited/f515.py | def f(rm,rf,beta):
return rf + beta*(rm-rf)
assert f(5, 0, 1) == 5 |
benchmark_functions_edited/f8871.py | def f(name):
return sum([ord(x.lower()) - 96 for x in list(name)])
assert f('') == 0 |
benchmark_functions_edited/f10649.py | def f(fjord):
minfree = {"JI": 15, "KB":5}
try:
return minfree.pop(fjord)
except KeyError:
print("The current fjord does not have a minimum freeboard median entry - using a default value!")
return 10
assert f("KB") == 5 |
benchmark_functions_edited/f9938.py | def f(hour_in, hour_out, check_in, check_out):
if check_in > hour_in:
result = hour_out - check_in
elif check_out > hour_out:
result = check_out - hour_in
else:
result = hour_out - hour_in
return result
assert f(9, 9, 0, 7) == 0 |
benchmark_functions_edited/f8419.py | def f(board_repr):
total = 0
for row in board_repr:
for col in row:
if isinstance(col, set) and len(col) > 1:
total += len(col)
return total
assert f(
[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]) == 0 |
benchmark_functions_edited/f13190.py | def f(gene, gene_to_cds_length):
try:
transcripts = gene_to_cds_length[gene]
except KeyError:
transcripts = []
lengths = []
for transcript in transcripts:
lengths.append(transcripts[transcript]["length"])
length = round(sum(lengths) / float(len(lengths)) if len(lengths) != ... |
benchmark_functions_edited/f13032.py | def f(phi,e):
x = 0
old_x = 1
y = 1
old_y = 0
r = e
old_r = phi
while not r == 0:
q = old_r // r
old_r, r = r, old_r - q*r
old_x, x = x, old_x - q*x
old_y, y = y, old_y - q*y
d = old_y % phi
if(d < 0):
d += phi
return d
assert f(... |
benchmark_functions_edited/f14278.py | def f(phase, slope=0.04):
return 10**(-0.4 * slope * phase)
assert f(0) == 1 |
benchmark_functions_edited/f6169.py | def f(coefficients,x):
return sum(pair[1]*(x**pair[0]) for pair in enumerate(coefficients))
assert f( [ 1, 0, 0, 0 ], 0 ) == 1 |
benchmark_functions_edited/f4365.py | def f(max_step):
if max_step <= 0:
raise ValueError("`max_step` must be positive.")
return max_step
assert f(1) == 1 |
benchmark_functions_edited/f9011.py | def f(string, idx):
# "abccdefgh", 2 returns 1
initial_idx = idx
last = string[idx]
while idx+1 < len(string) and string[idx+1] == last:
idx += 1
return idx-initial_idx
assert f("abccdefgh", 1) == 0 |
benchmark_functions_edited/f7213.py | def f(n: int) -> int:
a = 0
b = 1
def step(n: int) -> int:
nonlocal a, b
if n <= 0:
return a
a, b = b, a + b
return step(n - 1)
return step(n)
assert f(4) == 3 |
benchmark_functions_edited/f7078.py | def f(n):
if n == 0:
return 0
else:
return n * f(n - 2)
assert f(8) == 0 |
benchmark_functions_edited/f1941.py | def f(doors, past_selections):
return past_selections[-1]
assert f(range(10), [9]) == 9 |
benchmark_functions_edited/f395.py | def f(V, R):
return V**2 / R
assert f(0, 2) == 0 |
benchmark_functions_edited/f6287.py | def f(order):
if order < 2:
raise ValueError("An order lower than two is not allowed.")
else:
return order
assert f(2) == 2 |
benchmark_functions_edited/f5583.py | def f(arr, val):
sorted_array = sorted(arr)
interval_length = len(sorted_array) / 4.0
return int(sorted_array.index(val) / interval_length)
assert f(range(4), 0) == 0 |
benchmark_functions_edited/f2213.py | def f(t):
if t == 0:
return 1
else:
return f(t-1)
assert f(3) == 1 |
benchmark_functions_edited/f11632.py | def f(gold, pred):
tps = 0
for p in pred:
tp = False
for word in p:
for span in gold:
if word in span:
tp = True
if tp is True:
tps += 1
return tps
assert f(
[(0, 1), (2, 3)], [(1, 2), (2, 3)]) == 2 |
benchmark_functions_edited/f14231.py | def f(initial_velocity, acceleration, time):
vel = initial_velocity + acceleration * time
return vel
assert f(0, 1, 1) == 1 |
benchmark_functions_edited/f11716.py | def f(r,p_cumsum):
i = 0
while r > p_cumsum[i] and i+1 < p_cumsum.size:
i = i + 1
return i
assert f(0., [0.2, 0.3, 0.4, 0.1]) == 0 |
benchmark_functions_edited/f10320.py | def f(instance):
if isinstance(instance, (float, int)) or instance is None:
return instance
try:
return int(instance)
except (TypeError, ValueError):
pass
try:
return float(instance)
except (TypeError, ValueError):
pass
return instance
assert f(1) == 1 |
benchmark_functions_edited/f12028.py | def f(close, low, open, high, upper):
if close > open:
top_wick = high - close
bottom_wick = open - low
else:
top_wick = high - open
bottom_wick = close - low
if upper:
return top_wick
else:
return bottom_wick
assert f(15, 5, 15, 20, True) == 5 |
benchmark_functions_edited/f5858.py | def f(*values):
for value in values:
if value is not None:
return value
return None
assert f(1, None, None) == 1 |
benchmark_functions_edited/f12801.py | def f(label, equiv):
minVal = min(equiv[label])
while label != minVal:
label = minVal
minVal = min(equiv[label])
return minVal
assert f(0, {0:[0,1], 1:[0,1], 2:[0,1]}) == 0 |
benchmark_functions_edited/f970.py | def f(a):
if a >= 0:
return 1
else:
return 0
assert f(-10 ** 100) == 0 |
benchmark_functions_edited/f12190.py | def f(sigma, R):
return sigma ** 2. * R
assert f(1, 1) == 1 |
benchmark_functions_edited/f1029.py | def f(q, N):
return int(N * q)
assert f(0.5, 10) == 5 |
benchmark_functions_edited/f8030.py | def f(node):
if node == None:
return 0
return 1 + f(node._next)
assert f(None) == 0 |
benchmark_functions_edited/f2058.py | def f(info, x, y):
return (info['z_alpha'] * x) + (info['z_beta'] * y) + info['z_gamma']
assert f(
{'z_alpha': 1, 'z_beta': 0, 'z_gamma': 0},
0, 0) == 0 |
benchmark_functions_edited/f9028.py | def f(n):
return (n**2)%(10**9 + 7)
assert f(0) == 0 |
benchmark_functions_edited/f1264.py | def f(l):
if not l:
return None
return l[-1]
assert f([4]) == 4 |
benchmark_functions_edited/f3626.py | def f(ua,ub,uc):
uavg = (ua + ub + uc)/3
return (max(ua,ub,uc) - min(ua,ub,uc))/uavg
assert f(2,2,2) == 0 |
benchmark_functions_edited/f4279.py | def f(x):
if x % 2 == 0:
return(x//2)
else:
return(3*x + 1)
assert f(8) == 4 |
benchmark_functions_edited/f6401.py | def f(last_hire_date) -> int:
return 0 if last_hire_date == 'Less than a year ago' else 1
assert f('Less than a year ago') == 0 |
benchmark_functions_edited/f2706.py | def f(key, json, func, default=None):
return func(json[key]) if key in json else default
assert f(1, {1: 2, 3: 4}, lambda x: x + 2) == 4 |
benchmark_functions_edited/f14009.py | def f(array, val):
left, right = 0, len(array)
while left <= right:
mid = (left + right) // 2
if array[mid] < val:
left = mid + 1
elif array[mid] > val:
right = mid - 1
else:
return mid
return None
assert f([1, 2, 3, 2], 2) == 1 |
benchmark_functions_edited/f7109.py | def f(generator, default=None):
if generator:
for item in generator:
return item
return default
assert f(range(1, 10, 2)) == 1 |
benchmark_functions_edited/f7262.py | def f(val, bits):
# if sign bit is set e.g., 8bit: 128-255
if (val & (1 << (bits - 1))) != 0:
# compute negative value
val = val - (1 << bits)
return val
assert f(3, 3) == 3 |
benchmark_functions_edited/f13292.py | def f(numbers):
try:
iterator = iter(numbers)
maximum = minimum = next(iterator)
except StopIteration:
maximum = minimum = 0
for number in numbers:
if number > maximum:
maximum = number
if number < minimum:
minimum = number
return max... |
benchmark_functions_edited/f274.py | def f(d):
return list(d.values())[0]
assert f( {1:1, 2:2, 3:3} ) == 1 |
benchmark_functions_edited/f4865.py | def f(f,p,pv0,e,B,R,eta):
return B*e**2*f*p*pv0**2*(-1 + f + R)
assert f(0.5, 1, 0, 1, 0, 1, 0) == 0 |
benchmark_functions_edited/f11644.py | def f(s):
#start a binary long
r=0
#for each character in the string
for c in s:
#left shift the data by 8 bits and add the integer representation of the character
r = (r<<8) + ord(c)
#return the long
return r
assert f(b"") == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.