file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f6440.py | def f(n):
i = 0
j = 1
n = n - 1
# lines 1-5 creates a function'fib' to calculate the Fibonacci no of n
while n >= 0:
i, j = j, i + j
n = n - 1
return i
assert f(4) == 3 |
benchmark_functions_edited/f9710.py | def f(n: int) -> int:
f = {
n == 0: lambda n: 1,
n == 1: lambda n: 1,
n == 2: lambda n: 2,
n > 2: lambda n: f(n-1)*n
}[True]
return f(n)
assert f(0) == 1 |
benchmark_functions_edited/f2932.py | def f(temp_fahr):
temp_celsius = (temp_fahr - 32) * 5 / 9.0
return temp_celsius
assert f(32) == 0 |
benchmark_functions_edited/f8680.py | def f(x):
sum = 0
negative = False
if x < 0:
x = -x
negative = True
while x:
sum = sum * 10 + x%10
x /= 10
if sum > ((1<<31) - 1): return 0
return -sum if negative else sum
assert f(0) == 0 |
benchmark_functions_edited/f12632.py | def f(str_type):
d = {"S": 3,
"P": 5,
"D": 7,
"SP": 8}
if str_type in d:
return d[str_type]
# ord("F") = 70 and ord("Z") = 87
elif 70 <= ord(str_type) <= 87:
# ord("F") = 70 and l = 4 so ofset if 66
return 2 * (ord(str_type) - 66) + 1
else:
... |
benchmark_functions_edited/f8341.py | def f(result_set):
try:
return len(result_set)
except TypeError:
return 0
assert f(set()) == 0 |
benchmark_functions_edited/f6206.py | def f(serial: int, x: int, y: int) -> int:
rack_id = x + 10
p = rack_id * y + serial
p *= rack_id
p = (p // 100) % 10
return p - 5
assert f(39, 217, 196) == 0 |
benchmark_functions_edited/f5524.py | def f(tp: float, fn: float) -> float:
return tp / (tp + fn)
assert f(0, 1) == 0 |
benchmark_functions_edited/f3140.py | def f(input):
return len(bin(input)) - 2
assert f(5) == 3 |
benchmark_functions_edited/f1858.py | def f(lst):
if len(lst) > 0:
return sum(lst) / len(lst)
else:
return 0
assert f( [1, 2, 3, 4, 5] ) == 3 |
benchmark_functions_edited/f8629.py | def f(state, preprocessors):
for p in preprocessors:
state = p(state)
return state
assert f(1, [lambda x: x]) == 1 |
benchmark_functions_edited/f10294.py | def f(other_day, n, reference_day):
if n > 0 and other_day < reference_day:
n = n - 1
elif n <= 0 and other_day > reference_day:
n = n + 1
return n
assert f(4, 2, 1) == 2 |
benchmark_functions_edited/f7304.py | def f(point, points):
if point < points[0]:
return -1
for i in range(len(points) - 1):
if point < points[i + 1]:
return i
return len(points)
assert f(3, [1, 2, 3, 4, 5]) == 2 |
benchmark_functions_edited/f8793.py | def f(item, lst):
for cur_item in lst:
if cur_item == item:
return cur_item
return False
assert f(2, [1, 2, 3]) == 2 |
benchmark_functions_edited/f14290.py | def f(arr, key, low, high):
middle = (low+high) // 2
if low > high:
return -1 #key is not found
if arr[middle] == key:
return middle
if arr[middle] < key:
return f(arr, key, low, middle-1)
else:
return f(arr, key, middle+1, high)
assert f(sorted([1, 2, 3, 4, 5... |
benchmark_functions_edited/f806.py | def f(X, beta, t):
bc = 1 - beta ** t
return X / bc
assert f(0, 0.999, 100) == 0 |
benchmark_functions_edited/f14194.py | def f(a, b):
if a == 0: return 0
result = 1
while a > 1:
if a & 1:
if ((a-1)*(b-1) >> 2) & 1:
result = -result
a, b = b % a, a
else:
if (((b * b) - 1) >> 3) & 1:
result = -result
a >>= 1
if a == 0: return 0
... |
benchmark_functions_edited/f12642.py | def f(json_data):
total_games = 0
if 'totalGames' in json_data:
total_games = int(json_data['totalGames'])
return total_games
assert f({"totalGames": 4}) == 4 |
benchmark_functions_edited/f1955.py | def f(a, b, c):
if (a == b) & (b == c):
return 1
else:
return 0
assert f(2, 2, 1) == 0 |
benchmark_functions_edited/f8041.py | def f(byte):
if hasattr(byte, 'bit_length'):
# This is already an int
return byte
return ord(byte) if hasattr(byte, 'encode') else byte[0]
assert f(b'\x01') == 1 |
benchmark_functions_edited/f13375.py | def f(dict):
dict_keys = ['username', 'processing', 'filename']
for i in dict_keys:
if i not in dict.keys():
return 1
return 0
assert f({}) == 1 |
benchmark_functions_edited/f9326.py | def f(data):
previous = data[0]
count = 0
for value in data[1:]:
if value > previous:
count += 1
previous = value
return count
assert f(list(range(0, 2))) == 1 |
benchmark_functions_edited/f5078.py | def f(l):
max_ = None
for x in l:
if max_ is None or x > max_:
max_ = x
return max_
assert f( [1, 2, 3] ) == 3 |
benchmark_functions_edited/f8322.py | def f(swir, green):
return (green-swir) / (green+swir)
assert f(10, 10) == 0 |
benchmark_functions_edited/f13560.py | def f(p0, p1, p2):
p0x, p0y = p0
p1x, p1y = p1
p2x, p2y = p2
# logging.log(level=GEOM_ALG_INFO,
# msg=(p1x - p0x) * (p2y - p0y) - (p2x - p0x) * (p1y - p0y))
return (p1x - p0x) * (p2y - p0y) - (p2x - p0x) * (p1y - p0y)
assert f(
(1, 1),
(2, 2),
(2, 2)) == 0 |
benchmark_functions_edited/f7229.py | def f(order, phase):
n_points = len(order)
return phase ** sum(
1 for i in range(n_points) for j in range(i + 1, n_points)
if order[i] > order[j]
)
assert f(range(10), 1) == 1 |
benchmark_functions_edited/f7914.py | def f(coordinate: float, length: int) -> int:
if not (0 <= coordinate <= 1):
raise ValueError('Coordinate exceeds bounds')
return int(coordinate * length)
assert f(.5, 10) == 5 |
benchmark_functions_edited/f2267.py | def f(eff, n_gre, tr_gre, tr_seq, ti1, ti2, a1, a2):
return ti2 - ti1 - n_gre * tr_gre
assert f(1, 1, 1, 1, 1, 2, 1, 1) == 0 |
benchmark_functions_edited/f3741.py | def f(y, a, b):
return a*y + (b-a)*y
assert f(1, 0, 1) == 1 |
benchmark_functions_edited/f11902.py | def f( n_electron, n_eigs = None ):
if n_eigs is not None: return n_eigs
if n_electron > 2:
n_eigs = int(1.2 * ((0.5 * n_electron) + 5))
else:
n_eigs = n_electron
return n_eigs
assert f(2) == 2 |
benchmark_functions_edited/f8334.py | def f(results_):
if len(results_) == 0:
results = None
else:
assert len(results_) <= 1, 'throwing away results! { %r }' % (results_,)
results = results_[0]
return results
assert f([1]) == 1 |
benchmark_functions_edited/f14211.py | def f(arr):
if not arr:
return 0
if len(arr) == 1:
return 1
end =1
start = 0
max_len = 1
while end < len(arr):
if arr[end] > arr[end - 1]:
if end - start + 1 > max_len:
max_len = end - start + 1
else:
start = end
end... |
benchmark_functions_edited/f6355.py | def f(iterator):
res = 1
for i in iterator:
res *= i
return res
assert f(range(5)) == 0 |
benchmark_functions_edited/f7783.py | def f(text):
if type(text) == str:
return len(text.split(" "))
elif type(text) == list:
return len(text)
else:
raise ValueError("Text to count words for must be of type str or of type list.")
assert f( "hi there" ) == 2 |
benchmark_functions_edited/f1568.py | def f(n):
acum = 0
for i in range(n + 1):
acum += i
return acum
assert f(1) == 1 |
benchmark_functions_edited/f9354.py | def f(a):
result = 0
for index in range(len(a)):
try:
result += a[index][index]
except:
return result
return result
assert f([[1, 0], [0, 1]]) == 2 |
benchmark_functions_edited/f11348.py | def f(num_ref_data, period):
seconds = period * 60 * 60
qps = num_ref_data / seconds
return qps
assert f(0, 0.5) == 0 |
benchmark_functions_edited/f13400.py | def f(value):
check_digit=0
odd_pos=True
for char in str(value)[::-1]:
if odd_pos:
check_digit+=int(char)*3
else:
check_digit+=int(char)
odd_pos=not odd_pos #alternate
check_digit=check_digit % 10
check_digit=10-check_digit
check_digit=check_digit ... |
benchmark_functions_edited/f3917.py | def f(lst):
prod = lst[0]
for p in lst[1:]:
prod *= p
return prod
assert f(range(10)) == 0 |
benchmark_functions_edited/f7916.py | def f(w, h, bits, indexed=False):
size = (w * bits // 8 + 1) * h
if indexed:
# + 4 bytes per palette color
size += 4 * (2**bits)
return size
assert f(0, 0, 0) == 0 |
benchmark_functions_edited/f5926.py | def f(root):
if root is None:
return 0
return f(root.lesser) + f(root.greater) + 1
assert f(None) == 0 |
benchmark_functions_edited/f652.py | def f(n):
from math import floor
return int(floor(n))
assert f(1.1) == 1 |
benchmark_functions_edited/f5643.py | def f(lhs, rhs):
return len([(x, y) for x, y in zip(lhs, rhs) if x != y])
assert f( '', '') == 0 |
benchmark_functions_edited/f9056.py | def f(total_rows, row_number, previous_row_values):
return row_number + len(previous_row_values)
assert f(10, 2, [1]) == 3 |
benchmark_functions_edited/f13257.py | def f(number):
last_corner = 1
steps = 1
side = 0
while last_corner < number:
if side == 0:
steps += 2
last_corner += steps - 1
side += 1
if side == 4:
side = 0
to_middle = (steps - 1) // 2
middle = last_corner - to_middle
return to_mid... |
benchmark_functions_edited/f13694.py | def f(x):
x0, x1 = x #must provide 2 values (x0,y0)
f8 = 9 - x0 - x1
c0,c1,c2,c3 = 0,0,0,0
if x0 < 0: c0 = -100 * x0
if x1 < 0: c1 = -100 * x1
xx = (x0-3.)*(x0-3) + (x1-2.)*(x1-2)
if xx > 16: c2 = 100 * (xx-16)
if x0 * x1 > 14: c3 = 100 * (x0*x1-14.)
return max(f8,c0,c1,c2,c3)
asse... |
benchmark_functions_edited/f7660.py | def f(songs, data, replay):
if songs < 0:
return 0
keys = 0
for i in range(0, songs):
keys += int(data[(i+1)*11])
return keys
assert f(0, [11, 2, 10, 11, 11, 11, 11, 10, 11, 2, 10, 11], False) == 0 |
benchmark_functions_edited/f3231.py | def f(i, fallback=0):
# pylint: disable=broad-except
try:
return int(i)
except BaseException:
return fallback
assert f('0o10a') == 0 |
benchmark_functions_edited/f7391.py | def f(level: int) -> int:
# determined with https://www.dcode.fr/function-equation-finder
return int(((5*level**3)/3 + (45*level**2)/2 + 455*level/6))
assert f(0) == 0 |
benchmark_functions_edited/f8444.py | def f(value_list):
from math import sqrt
from math import pow
n = len(value_list)
average_value = sum(value_list) * 1.0 / n
return sqrt(sum([pow(e - average_value, 2) for e in value_list]) * 1.0 / (n - 1))
assert f([0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0 |
benchmark_functions_edited/f2533.py | def f(timeA, timeB):
if timeB < timeA:
timeB += 3600
return timeB - timeA
assert f(300, 300) == 0 |
benchmark_functions_edited/f4087.py | def f(alpha, n):
if isinstance(alpha, int):
return alpha
return int(alpha * n)
assert f(0.001, 10) == 0 |
benchmark_functions_edited/f1620.py | def f(a):
sum=0
for i in a: sum+=a[i]
return sum
assert f({'a': 3, 'b': 2, 'c': 1}) == 6 |
benchmark_functions_edited/f2089.py | def f(*args):
return sum(x is not None for x in args)
assert f(1, 2, None) == 2 |
benchmark_functions_edited/f9454.py | def f(wind):
return int(wind * 16.5)
assert f(0) == 0 |
benchmark_functions_edited/f3790.py | def f(iter):
sorted_iter = sorted(iter)
return max(sorted_iter) - min(sorted_iter)
assert f([3, 5, 4, 2, 7]) == 5 |
benchmark_functions_edited/f7320.py | def f(x):
if x <= 0:
return x
x0=x
hk=0
while 1:
hk=(pow(x0,2)-x)/(2*x0)
x0 -= hk
if hk < 0.1:
break
return int(x0)
assert f(2) == 1 |
benchmark_functions_edited/f3177.py | def f(line):
if line == None:
return 0
else:
return int( line[22:26].strip() )
assert f(None) == 0 |
benchmark_functions_edited/f12876.py | def f(custom_str):
# check integer
try:
return int(custom_str)
except ValueError:
pass
# check float
try:
return float(custom_str)
except ValueError:
pass
# check boolean
if custom_str in ["True", "False"]:
return custom_str == "True"
# Retu... |
benchmark_functions_edited/f6667.py | def f(bb):
return int.from_bytes(bb, byteorder='little', signed=False)
assert f(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') == 0 |
benchmark_functions_edited/f3188.py | def f(lhs,rhs):
return len([(x,y) for x,y in zip(lhs,rhs) if x !=y])
assert f( 'GAGCCTACTAACGGGAT', 'CATCGTAATGACGGCCT') == 7 |
benchmark_functions_edited/f11249.py | def f(dic_with_default, key):
try:
return dic_with_default[key]
except KeyError:
return dic_with_default['default']
assert f({'a': 1, 'b': 2, 'c': 3}, 'a') == 1 |
benchmark_functions_edited/f6860.py | def f(value, arg):
try:
output = int(value) * int(arg)
except:
output = value
return output
assert f(2, 3) == 6 |
benchmark_functions_edited/f11195.py | def f(fn, iterable, initializer):
it = enumerate(iterable)
value = initializer
for idx, element in it:
value = fn(value, element, idx)
return value
assert f(lambda x, y, _: x + y, [], 0) == 0 |
benchmark_functions_edited/f14169.py | def f(var):
# In TF 2, Variables themselves are not hashable, so cannot be dict keys.
# Error is "Tensor is unhashable if Tensor equality is enabled. Instead, use
# tensor.experimental_ref() as the key". For a related issue, see:
# https://github.com/tensorflow/tensorflow/issues/32139
ref_op = getattr(var, "e... |
benchmark_functions_edited/f13970.py | def f(x, a, b, A=0, B=1):
if a == b:
res = B
else:
res = (x - a) / (1. * (b - a)) * (B - A) + A
if res < A:
res = A
if res > B:
res = B
return res
assert f(0, 0, 2) == 0 |
benchmark_functions_edited/f542.py | def f(side):
return (side - 1) % 3
assert f(2) == 1 |
benchmark_functions_edited/f6971.py | def f(s):
return len(min(s.split(), key=len))
assert f("lets talk about javascript the best language") == 3 |
benchmark_functions_edited/f2936.py | def f(rp):
r0, alpha = (41.437187675742656, -0.832326251664125)
return (rp/r0)**alpha
assert f(41.437187675742656) == 1 |
benchmark_functions_edited/f12255.py | def f(value):
# Try edge case
if value is True:
return None
if value is False:
return None
# Try conversion
try:
result = int(value)
except:
result = None
# Return
return result
assert f(0) == 0 |
benchmark_functions_edited/f3357.py | def f(data_):
cpy = data_ + 1024
cpy /= 3000
return cpy
assert f(-1024) == 0 |
benchmark_functions_edited/f9218.py | def f(p1,p2,size):
x1, y1 = p1
x2, y2 = p2
ix1, iy1 = max(x1,x2), max(y1,y2)
ix2, iy2 = min(x1+size,x2+size), min(y1+size,y2+size)
iarea = abs(ix2-ix1)*abs(iy2-iy1)
if iy2 < iy1 or ix2 < ix1: iarea = 0
return iarea
assert f( (0,0), (10, 10), 0 ) == 0 |
benchmark_functions_edited/f6550.py | def f(out, f, s):
return s * (out - 1) + f
assert f(2, 1, 1) == 2 |
benchmark_functions_edited/f14422.py | def f(symbol, sentences):
freq = 0
for sentence in sentences:
for w in sentence:
for char in w:
if char == symbol:
freq += 1
return freq
assert f(u'a', [[u'a']]) == 1 |
benchmark_functions_edited/f5177.py | def f(d, *keys, default=None):
for k in keys:
if not isinstance(d, dict) or k not in d:
return default
d = d[k]
return d
assert f(
{'a': {'b': 3}}, 'a', 'b') == 3 |
benchmark_functions_edited/f3413.py | def f(xmin, xmax, ymin, ymax):
return (xmax - xmin)*(ymax - ymin)
assert f(1, 1, 1, 0) == 0 |
benchmark_functions_edited/f11320.py | def f(summary):
counts_sum = 0
for name, count in summary.items():
if name == "all":
continue # IGNORE IT.
counts_sum += count
return counts_sum
assert f(
{"a": 1, "b": 2, "c": 3, "all": 4}) == 6 |
benchmark_functions_edited/f14293.py | def f(row_data):
min_val = 0
max_val = 0
first = True
for cell in row_data.split("\t"):
if first:
min_val = int(cell)
max_val = int(cell)
first = False
else:
if min_val > int(cell):
min_val = int(cell)
if max... |
benchmark_functions_edited/f5149.py | def f(offset, alignment):
return (alignment - (offset % alignment)) % alignment
assert f(7, 2) == 1 |
benchmark_functions_edited/f10541.py | def f(maze, element):
if element == 'pony':
return int(maze['pony'][0])
elif element == 'domokun':
return int(maze['domokun'][0])
elif element == 'end-point':
return int(maze['end-point'][0])
return None
assert f(
{'pony': [1, 2],
'domokun': [5, 6],
'end-point': [3... |
benchmark_functions_edited/f8731.py | def f(func, args):
return func(*args)
assert f(lambda x, y, z: x + y + z, [1, 2, 3]) == 6 |
benchmark_functions_edited/f9580.py | def f(x, y):
return (x > y) - (x < y)
assert f(2.5, 2) == 1 |
benchmark_functions_edited/f10424.py | def f(A, B, K):
# write your code in Python 3.6
return (B // K) - ((A - 1) // K)
assert f(1, 100, 25) == 4 |
benchmark_functions_edited/f5193.py | def f(phi, A):
return A[0]*0.5*(1.+phi) + A[1]*0.5*(1.-phi)
assert f(0, (1, 1)) == 1 |
benchmark_functions_edited/f7081.py | def f(seq1: str, seq2: str) -> int:
if len(seq1) != len(seq2):
raise ValueError("length of strings are not the same")
return sum(c1 != c2 for c1, c2 in zip(seq1, seq2))
assert f(
"GGGCCGTTGGT",
"GGACCGTTGAC"
) == 3 |
benchmark_functions_edited/f9198.py | def f(ar):
count = 0
for i in range(0, len(ar), 2):
try:
a, b = ar[i], ar[i + 1]
except IndexError:
return count
if abs(a - b) == 1:
count += 1
return count
assert f([1, 2, 3, 4]) == 2 |
benchmark_functions_edited/f10481.py | def f(keys, nested_dict, default=None):
import operator
from functools import reduce
try:
return reduce(operator.getitem, keys, nested_dict)
except (KeyError, IndexError, TypeError):
return default
assert f(['a'], {'a': 1}) == 1 |
benchmark_functions_edited/f8733.py | def f(f, args):
try:
return f(*args)
except Exception:
return None
assert f(max, (1, 2, 3)) == 3 |
benchmark_functions_edited/f2073.py | def f(x, y):
if y == 0:
raise ValueError("Can;t divide by zero")
return x / y
assert f(10, 5) == 2 |
benchmark_functions_edited/f13272.py | def f(x, y):
z = ((x + y) * (x + y + 1) / 2) + y
return z
assert f(1,1) == 4 |
benchmark_functions_edited/f12229.py | def f(r: float, p: float, b: int = 1):
try:
val = (1 + b ** 2) * (p * r) / (b ** 2 * p + r)
except ZeroDivisionError:
val = 0
return val
assert f(1, 1, 2) == 1 |
benchmark_functions_edited/f12199.py | def f(results):
raw_results = results[0]
processing_result = 0
for each_qubit_measurement in raw_results:
processing_result = 2 * processing_result + each_qubit_measurement
# Convert from 0 indexed to 1 indexed
die_value = processing_result + 1
return die_value
assert f(
[
[... |
benchmark_functions_edited/f136.py | def f(x, y):
return (x + y)
assert f(1, -1) == 0 |
benchmark_functions_edited/f2191.py | def f(x):
if x == 0:
return 0.
elif x > 0:
return 1.
else:
return -1.
assert f(0) == 0 |
benchmark_functions_edited/f1747.py | def f(number: float):
if(number > 0):
return 1
else:
return -1
assert f(1.0) == 1 |
benchmark_functions_edited/f14054.py | def f(leading_spaces: str) -> int:
assert leading_spaces.strip() == ''
assert len(leading_spaces) % 4 == 0
return int(len(leading_spaces) / 4)
assert f(' ') == 4 |
benchmark_functions_edited/f2907.py | def f(text):
return int(text) if text.isdigit() else text.lower()
assert f("1") == 1 |
benchmark_functions_edited/f11047.py | def f(obj, iterable):
item = obj
for i in iterable:
item = item[i]
return item
assert f([0, 1], [1]) == 1 |
benchmark_functions_edited/f9752.py | def f(b1, b2):
return len(b1.intersection(b2))/len(b1.union(b2))
assert f({1}, set()) == 0 |
benchmark_functions_edited/f12497.py | def f(value):
value = int(value)
if value < 0:
msg = ('Invalid value [{0}]: require a whole number greater than or '
'equal to zero')
raise ValueError(msg.format(value))
else:
return value
assert f('1') == 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.