file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f2067.py
|
def f(x, n):
if x>n: y=n
else: y=x
return y
assert f(0, 1) == 0
|
benchmark_functions_edited/f1830.py
|
def f(hk, size, i):
return int(hk + 0.5 + i*i*0.5) % size
assert f(1, 5, 2) == 3
|
benchmark_functions_edited/f13034.py
|
def f(self, index):
if index == 0 and self.magnet_0:
return self.H2 * self.W1
return 0
assert f(None, None) == 0
|
benchmark_functions_edited/f6775.py
|
def f(n):
if n == 1:
return 1
cycle, rem = divmod(n - 1, 4)
adjustment = cycle * 3 - 2
result = (pow(2, cycle * 4 - 2) + pow(2, adjustment)) * pow(2, rem)
return result
assert f(2) == 1
|
benchmark_functions_edited/f3770.py
|
def distLInf (a, b):
return max (abs (a[0] - b[0]), abs (a[1] - b[1]))
assert f( (0,1), (0,0) ) == 1
|
benchmark_functions_edited/f5533.py
|
def f(a, b, c, d):
f = b * d
g = d / c
q = a + f
m = q + g
h = m - q
j = h % g
return j
assert f(0, 1, 1, 1) == 0
|
benchmark_functions_edited/f10670.py
|
def f(props):
res = 0
for k, v in props.items():
if k in ['margin-left', 'text-indent']:
try:
res += float(v.replace('in', ''))
except:
pass
return res
assert f(dict()) == 0
|
benchmark_functions_edited/f9793.py
|
def f(lst, item):
try:
return lst.index(item)
except ValueError:
lst.append(item)
return len(lst) - 1
assert f( [ "a" ], "a" ) == 0
|
benchmark_functions_edited/f2671.py
|
def f(x, y):
return (x ** 2 - y ** 2)
assert f(5, 5) == 0
|
benchmark_functions_edited/f14088.py
|
def f(strand_a, strand_b):
if len(strand_a) != len(strand_b):
raise ValueError("Strands must be of equal length.")
distance = 0
for i, _ in enumerate(strand_a):
if strand_a[i] != strand_b[i]:
distance += 1
return distance
assert f("GGGCCGTTGGT", "GGACCGTTGAC") == 3
|
benchmark_functions_edited/f9654.py
|
def f(n):
if n <= 0:
return -1
i = j = 1
for _ in range(n - 1):
i, j = j, i + j
return i
assert f(5) == 5
|
benchmark_functions_edited/f8381.py
|
def f( a, x, lo = 0 ):
hi = len( a )
while lo < hi:
mid = ( lo + hi ) // 2
if x < a[ mid ][ 0 ]:
hi = mid
else:
lo = mid + 1
return lo
assert f( [(0,0),(1,1),(2,2)], 0.5 ) == 1
|
benchmark_functions_edited/f10667.py
|
def f(str_len):
if str_len == 0:
return 0
elif str_len == 1:
return 2
elif str_len % 255 in (0, 1):
return (str_len / 255) * 2 + str_len + (str_len % 255)
else:
return ((str_len / 255) + 1) * 2 + str_len
assert f(0) == 0
|
benchmark_functions_edited/f7017.py
|
def f(a, b):
return -(-a // b)
assert f(3, 3) == 1
|
benchmark_functions_edited/f3186.py
|
def f(au):
return au * 1.495978707 * 10**11
assert f(0) == 0
|
benchmark_functions_edited/f4521.py
|
def f(data):
n = len(data)
if n < 1:
raise ValueError('mean requires at least one data point')
return sum(data)/n
assert f([1, 2, 3, 4, 5]) == 3
|
benchmark_functions_edited/f9399.py
|
def f(flags):
# 96 = 0b1100000, bits 6 to 7
return (flags & 96) >> 5
assert f(63) == 1
|
benchmark_functions_edited/f13464.py
|
def f(predictions,targets):
number_of_false_positives = 0
if len(predictions) == 0:
return 0
for prediction in predictions:
if prediction not in targets:
number_of_false_positives += 1
return number_of_false_positives/len(predictions)
assert f(["CCO"], ["CCO"]) == 0
|
benchmark_functions_edited/f10956.py
|
def f(x_elem):
if x_elem == 4:
return 2
if x_elem == 5:
return 1
if x_elem == 6:
return 3
return 4
assert f(4) == 2
|
benchmark_functions_edited/f6522.py
|
def f(val):
literals = {"null":None, "true":True, "false":False}
v = val.lower()
return v in literals and literals[v] or float(v)
assert f("1") == 1
|
benchmark_functions_edited/f8045.py
|
def f(n):
x = 1.0
x = x - (x * x - n) / (2.0 * x)
x = x - (x * x - n) / (2.0 * x)
x = x - (x * x - n) / (2.0 * x)
return x
assert f(1) == 1
|
benchmark_functions_edited/f10846.py
|
def f(items, target):
low = 0
high = len(items) - 1
while low <= high:
mid = (low + high)
guess = items[mid]
if guess == target:
return mid
if guess > target:
high = mid - 1
else:
low = mid + 1
return None
assert f(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10) == 9
|
benchmark_functions_edited/f143.py
|
def f(pages):
return sum(p.rating for p in pages)
assert f(frozenset()) == 0
|
benchmark_functions_edited/f10926.py
|
def f(value: int) -> float:
fifty_three_ones = 0xFFFFFFFFFFFFFFFF >> (64 - 53)
fifty_three_zeros = float(1 << 53)
return (value & fifty_three_ones) / fifty_three_zeros
assert f(0x00000000000000000000000000000000) == 0
|
benchmark_functions_edited/f1954.py
|
def f(mps):
if mps is None:
return None
return mps / 0.51444
assert f(0) == 0
|
benchmark_functions_edited/f8977.py
|
def f(a: int,
b: int) -> int:
if a % b == 0:
return b
return f(b, a % b)
assert f(54, 24) == 6
|
benchmark_functions_edited/f5337.py
|
def f(n):
num = 0
nn = list(n)
nn.reverse()
for j in range(len(nn)):
if nn[j]==0:
continue
num = num+2**j
return num
assert f("1") == 1
|
benchmark_functions_edited/f13514.py
|
def f(L, V, rho_V, rho_L):
return L/V*(rho_V/rho_L)**0.5
assert f(1, 1, 2, 2) == 1
|
benchmark_functions_edited/f1874.py
|
def stopband_atten_to_dev (atten_db):
return 10**(-atten_db/20)
assert f(0) == 1
|
benchmark_functions_edited/f2469.py
|
def f(speed, base=5):
return int(base * round(float(speed)/base))
assert f(0) == 0
|
benchmark_functions_edited/f4794.py
|
def f(input):
y = []
ins = input.split('\n')
for x in input.split('\n'):
y.append(int(x))
return sum(y)
assert f("+1\n-1") == 0
|
benchmark_functions_edited/f6539.py
|
def f(r, g, b, grayscale=False):
if grayscale:
return 0.2126*r + 0.7152*g + 0.0722*b
else:
return 0.267*r + 0.642*g + 0.091*b
assert f(0, 0, 0) == 0
|
benchmark_functions_edited/f12266.py
|
def f(searching_list, target):
for i in range(0, len(searching_list)):
if searching_list[i] == target:
return i
return None
assert f([1, 3, 4, 6, 7], 6) == 3
|
benchmark_functions_edited/f516.py
|
def f(x, y):
while y:
x, y = y, x % y
return x
assert f(9, 12) == 3
|
benchmark_functions_edited/f6544.py
|
def f(seq):
increases = 0
for i in range(1, len(seq)):
if seq[i] > seq[i-1]:
increases += 1
return increases
assert f([3, 4, 5]) == 2
|
benchmark_functions_edited/f14311.py
|
def f(nums):
if nums == None:
return 0
if len(nums) == 0:
return 0
max_sum = nums[0]
curr_sum = nums[0]
for i in range(1, len(nums)):
curr_sum = max(curr_sum + nums[i], nums[i])
max_sum = max(curr_sum, max_sum)
return max_sum
assert f([0, 0]) == 0
|
benchmark_functions_edited/f2359.py
|
def f(db, key):
value = db.f(key)
if value is None:
return None
return value
assert f({'a': 1, 'b': 2}, 'a') == 1
|
benchmark_functions_edited/f8318.py
|
def f(val):
# Return answer ..
return 86400 * (val - 25569)
assert f(25569) == 0
|
benchmark_functions_edited/f4236.py
|
def f(value):
if type(value) is str:
return int(value)
else:
return value
assert f('5') == 5
|
benchmark_functions_edited/f5249.py
|
def f(a, b, m):
# a^(2b) = (a^b)^2
# a^(2b+1) = a * (a^b)^2
if b==0:
return 1
return ((a if b%2==1 else 1) * f(a, b//2, m)**2) % m
assert f(2, 1, 7) == 2
|
benchmark_functions_edited/f10828.py
|
def f(array, low, high):
mid = (low + high) // 2
if mid == low:
return array[low]
if array[mid] > array[high]:
return f(array, mid + 1, high)
return f(array, low, mid)
assert f(list(range(10000000)), 0, 9999999) == 0
|
benchmark_functions_edited/f661.py
|
def f(x, y):
return x if x <= y else y
assert f(1, 1) == 1
|
benchmark_functions_edited/f11450.py
|
def f(x, theta):
J = x * theta
return J
assert f(3, 1) == 3
|
benchmark_functions_edited/f251.py
|
def f(x):
dx = x[1] - x[0]
return dx
assert f([0, 1]) == 1
|
benchmark_functions_edited/f4332.py
|
def f(v0):
g = 9.81
return v0**2/(2*g)
assert f(0) == 0
|
benchmark_functions_edited/f13834.py
|
def f(start_orientation: int, wanted_orientation: int) -> int:
length = abs(wanted_orientation - start_orientation)
assert 0 <= length <= 3
return length if length < 3 else 1
assert f(3, 1) == 2
|
benchmark_functions_edited/f3438.py
|
def f(rgb: bool) -> int:
if rgb:
return 3
else:
return 1
assert f(True) == 3
|
benchmark_functions_edited/f9964.py
|
def f(x, a):
if x == a:
return 0
elif x < a:
return x
else:
return f(x-a, a)
assert f(1002, 1000) == 2
|
benchmark_functions_edited/f3151.py
|
def f(nums, val):
for i in range(nums.count(val)):
nums.remove(val)
return len(nums)
assert f([1, 1, 3, 3, 3], 1) == 3
|
benchmark_functions_edited/f8740.py
|
def f(cval, spec, sint):
if cval == spec: return sint
else: return int(cval)
assert f('1', '1', 1) == 1
|
benchmark_functions_edited/f7628.py
|
def f(x, y=None):
if not x > 0:
raise ValueError("Transformation only accepts positive values.")
else:
return x
assert f(5) == 5
|
benchmark_functions_edited/f6585.py
|
def f(strand):
strand_dict = {'+': 1,
'-': -1,
'1': 1,
'-1': -1,
'.': 1}
return strand_dict[strand]
assert f(
'+') == 1
|
benchmark_functions_edited/f12454.py
|
def f(answer, correct_answer):
#how many are correct
overlap = answer & correct_answer
ncorrect = len(overlap)
#how many are wrong
wrong = answer - correct_answer
nwrong = len(wrong)
#how many correct are missing
missing = correct_answer - answer
nmissing = len(missing)
nmistakes = nwrong + nmissing
return(nmistakes)
assert f(set([1,2,3]), set([1,2,3])) == 0
|
benchmark_functions_edited/f9003.py
|
def f(b, a, j, i, no):
bj = b*no + j
ai = a*no + i
if bj > ai:
baji = bj*(bj+1)//2 + ai
else:
baji = ai*(ai+1)//2 + bj
return baji
assert f(1, 1, 1, 1, 2) == 9
|
benchmark_functions_edited/f5209.py
|
def f(combo, attempt):
grade = 0
for i, j in zip(combo, attempt):
if i == j:
grade += 1
return grade
assert f(list('XYZ'), list('ABZ')) == 1
|
benchmark_functions_edited/f4727.py
|
def f(dout, cache):
tanh_x = cache
return (1 - tanh_x ** 2) * dout
assert f(1, 0) == 1
|
benchmark_functions_edited/f12323.py
|
def f(token_number: str) -> int:
return int(token_number) - 1
assert f("3") == 2
|
benchmark_functions_edited/f1705.py
|
def f(collection):
size = len(collection)
return size
assert f(set()) == 0
|
benchmark_functions_edited/f13426.py
|
def f(x1,x2,f1,f2):
m = f1 / (f2 - f1)
return x1 - m * (x2 - x1)
assert f(0,10,0,-1)==0
|
benchmark_functions_edited/f4583.py
|
def f(lives, current):
if lives == 3:
return 1
if lives > 3 or lives < 2:
return 0
return current
assert f(3, 0) == 1
|
benchmark_functions_edited/f5184.py
|
def f(geoJson):
return len(geoJson["features"])
assert f({"features": [1, 2, 3, {"geometry": {"coordinates": [[1, 2], [3, 4]]}}]}) == 4
|
benchmark_functions_edited/f10050.py
|
def f(bit: int, fill: bool = False) -> int:
mask = (1 << bit)
return (((mask - 1) << 1) | 1) if fill else mask
assert f(0, False) == 1
|
benchmark_functions_edited/f10777.py
|
def f(digits):
answer = 0
prev = 1
cur = 1
while len(str(prev)) < digits:
answer += 1
next_term = prev + cur
prev = cur
cur = next_term
answer += 1
return answer
assert f(1) == 1
|
benchmark_functions_edited/f9188.py
|
def f(string):
if "." in string:
return float(string)
return int(string)
assert f("2") == 2
|
benchmark_functions_edited/f1952.py
|
def f(shape) :
size=1
for d in shape : size*=d
return size
assert f( [1, 2, 2] ) == 4
|
benchmark_functions_edited/f2753.py
|
def f(value, arg):
try:
return float(value) * float(arg)
except ValueError:
pass
return ""
assert f(0, 1) == 0
|
benchmark_functions_edited/f496.py
|
def f(number, index):
return (number >> index) & 1
assert f(0b000100, 1) == 0
|
benchmark_functions_edited/f9595.py
|
def f(immediate):
if not isinstance(immediate, str):
raise TypeError('Immediate must be a String object.')
if immediate.startswith("0x"):
return int(immediate, 16)
else:
return int(immediate)
assert f("1") == 1
|
benchmark_functions_edited/f7991.py
|
def f(fixed_point_val: int, precision: int) -> int:
if (precision >= 0):
mask = (1 << precision) - 1
return fixed_point_val & mask
return 0
assert f(6, 1) == 0
|
benchmark_functions_edited/f10807.py
|
def f(precision: float, recall: float):
if precision + recall == 0:
return 0
return 2 * ((precision * recall) / (precision + recall))
assert f(0.5, 0) == 0
|
benchmark_functions_edited/f10161.py
|
def f(words, idx):
try:
return words.index('"' + idx + '"')
except ValueError:
return words.index(idx)
assert f(
['"word1"', "word2", "word3"],
"word3"
) == 2
|
benchmark_functions_edited/f12979.py
|
def f(arr: list) -> int:
i, j = 0, len(arr) - 1
total: int = 0
while i < j:
if arr[i] == arr[j]:
i += 1
j -= 1
continue
elif arr[i] < arr[j]:
i += 1
arr[i] += arr[i - 1]
else:
j -= 1
arr[j] += arr[j + 1]
total += 1
return total
assert f([4, 7, 9]) == 2
|
benchmark_functions_edited/f1834.py
|
def f(i,j,k,NX,NY,NZ):
index = i+j*NX+k*NX*NY
return index
assert f(0,1,1,1,1,1) == 2
|
benchmark_functions_edited/f9037.py
|
def f(pos, lst):
h = 0
t = len(lst) - 1
mid = int((h + t) / 2)
ans = -1
while not h > t:
if pos >= lst[mid]:
ans = mid
h = mid + 1
else:
t = mid - 1
mid = int((h + t) / 2)
return ans
assert f(4, [1, 2, 2, 3]) == 3
|
benchmark_functions_edited/f3046.py
|
def f(a, b):
if b == 0:
raise ZeroDivisionError()
return a/b
assert f(1, 1) == 1
|
benchmark_functions_edited/f2107.py
|
def f(m, n):
if n == 0:
return m
else:
return f(n, m % n)
assert f(36, 20) == 4
|
benchmark_functions_edited/f9535.py
|
def f(norm, forward):
if norm is None:
return 0 if forward else 2
if norm == 'ortho':
return 1
raise ValueError(
"Invalid norm value {}, should be None or \"ortho\".".format(norm))
assert f("ortho", True) == 1
|
benchmark_functions_edited/f14220.py
|
def surface_margin_deph (A_approx_deph, A_real_deph):
return (A_approx_deph - A_real_deph) * 100 / A_approx_deph
assert f(0.25, 0.25) == 0
|
benchmark_functions_edited/f6938.py
|
def f(x0, y0, x1, y1, x):
try:
y = (y0 * (x1 - x) + y1 * (x - x0)) / (x1 - x0)
except ZeroDivisionError as e:
print(x1,x0)
raise e
return y
assert f(1, 2, 3, 4, 3) == 4
|
benchmark_functions_edited/f6704.py
|
def f(offer_type):
if offer_type == "bogo":
return 0
elif offer_type == "informational":
return 1
elif offer_type == "discount":
return 2
else:
return 3
assert f("discount") == 2
|
benchmark_functions_edited/f4855.py
|
def f(s1: str, s2: str) -> int:
return sum(c1 == c2 for c1, c2 in zip(s1, s2))
assert f(
"h",
"ho") == 1
|
benchmark_functions_edited/f7758.py
|
def f(order: int) -> int:
if not isinstance(order, int):
raise TypeError("`order` must be an integer.")
if order <= 0:
raise ValueError("`order` must be greater than zero.")
return order
assert f(2) == 2
|
benchmark_functions_edited/f10091.py
|
def f(H, DRE = 2500):
p=1/0.241
dV=(H/2.00)**p
MER=dV*DRE
return MER
assert f(0, 2500) == 0
|
benchmark_functions_edited/f11488.py
|
def f(sig_info, errors):
if 'description' not in sig_info.keys():
print('ERROR! description is a required field')
errors += 1
else:
print('Check description: PASS')
return errors
assert f(dict(), 1) == 2
|
benchmark_functions_edited/f6326.py
|
def f(x, y, size=3):
return (x*size) + y
assert f(2, 0) == 6
|
benchmark_functions_edited/f8177.py
|
def f(n: int) -> int:
p = 1
def mul(a, b):
result = 0
for _ in range(b):
result += a
return result
while mul(p, p) <= n < mul(p+1, p+1):
p += 1
return p
assert f(2) == 2
|
benchmark_functions_edited/f8435.py
|
def f(predicate, seq):
for x in seq:
px = predicate(x)
if px:
return px
return False
assert f(callable, []) == 0
|
benchmark_functions_edited/f6045.py
|
def f(filename="", text=""):
chars = 0
with open(filename, mode="a", encoding="utf-8") as f:
chars += f.write(text)
f.close()
return chars
assert f("empty.txt", "b") == 1
|
benchmark_functions_edited/f4882.py
|
def f(at_bats, hits) -> float:
return round(hits / at_bats, 3) if at_bats else 0.0
assert f(22, 0) == 0
|
benchmark_functions_edited/f1984.py
|
def f(value):
log_val = 0
while value != 0:
value >>= 1
log_val += 1
return log_val
assert f(9) == 4
|
benchmark_functions_edited/f10901.py
|
def f(point1, point2):
return max(abs(point1[0] - point2[0]), abs(point1[1] - point2[1]))
assert f(
[1, 2], [1, 1]
) == 1
|
benchmark_functions_edited/f3643.py
|
def f(p, x):
return (p[0] * x) + p[1]
assert f((1, 1), 0) == 1
|
benchmark_functions_edited/f4124.py
|
def f(point1, point2):
return (point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2
assert f((2, 4), (2, 4)) == 0
|
benchmark_functions_edited/f3996.py
|
def f(value, arg):
if arg is None:
return 0
elif arg is 0:
return 0
else:
return value / arg
assert f(4, None) == 0
|
benchmark_functions_edited/f11672.py
|
def f(v):
return int(float(v))
assert f("1.1") == 1
|
benchmark_functions_edited/f2521.py
|
def f(number: int, max_value: int, min_value: int) -> int:
return max(min(number, max_value), min_value)
assert f(3, 1, 2) == 2
|
benchmark_functions_edited/f13284.py
|
def f(x: int, shift: int, n_bits: int) -> int:
mask = (1 << n_bits) - 1 # Trick to create a ones mask of n bits
x_base = x >> shift
return x_base | (x << (n_bits - shift) & mask)
assert f(3, 2, 2) == 3
|
benchmark_functions_edited/f4743.py
|
def f(x,param):
n_param = len(param)
y = 0
for i in range(n_param):
y += param[i] * x**i
return y
assert f(1,[1,2,3]) == 6
|
benchmark_functions_edited/f8752.py
|
def f(target, l):
minVal = l[0]
minIdx = 0
for i, e in enumerate(l):
if abs(target - minVal) > abs(target - e):
minVal = e
minIdx = i
return minIdx
assert f(90, [10, 14, 4, 90, 5, 9, 1]) == 3
|
benchmark_functions_edited/f2951.py
|
def f(val):
n = 0
while val:
if val & 1:
n += 1
val >>= 1
return n
assert f(34) == 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.