file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f13227.py
|
def f(prod, react):
RFE = sum(prod) - sum(react)
return RFE
assert f(
[0, 1, 2, 3],
[0, 1, 2, 3]) == 0
|
benchmark_functions_edited/f10178.py
|
def f(n, big):
n = abs(n)
if n == 0:
return big
else:
# check the last digit of a number
if big < int(n % 10):
big = int(n % 10)
# check the rest of the digits
return f(n/10, big)
assert f(20, 0) == 2
|
benchmark_functions_edited/f3842.py
|
def f(obj):
if obj == []:
return 1
elif isinstance(obj, list):
return 1 + max([f(x) for x in obj])
else:
return 0
assert f([1, [2, [3, [4, []]]]]) == 5
|
benchmark_functions_edited/f4947.py
|
def f(value, dice):
points = 0
for die in dice:
if die == value:
points += value
return points
assert f(5, [1, 1, 2]) == 0
|
benchmark_functions_edited/f14090.py
|
def f(i):
# 1 byte?
if ((i & 0x00000000FF) == i):
return 1
# 2 bytes?
if ((i & 0x000000FFFF) == i):
return 2
# 4 bytes?
if ((i & 0x00FFFFFFFF) == i):
return 4
# Lets go with 8 bytes.
return 8
assert f(0x00000000) == 1
|
benchmark_functions_edited/f2551.py
|
def f(mass, velocity):
return 0.5 * mass * velocity ** 2
assert f(0, 0) == 0
|
benchmark_functions_edited/f1570.py
|
def f(n):
res = 0
for i in range(n+1):
res += i
return res
assert f(2) == 3
|
benchmark_functions_edited/f9765.py
|
def f(group):
return len(list(group.values())[0])
assert f(
{"0" : [1, 2, 3, 4, 5, 6], "1" : [7, 8, 9, 10, 11, 12]}) == 6
|
benchmark_functions_edited/f8377.py
|
def f(n):
T = [None] * (n + 1)
T[0] = 0
T[1] = 1
for n in range(2, n + 1):
T[n] = T[n - 1] + T[n - 2]
return T[n]
assert f(2) == 1
|
benchmark_functions_edited/f492.py
|
def f(val, bitNo):
return (val >> bitNo) & 1
assert f(64, 6) == 1
|
benchmark_functions_edited/f2703.py
|
def f(file_path, new_contents):
with open(file_path, "wb") as f:
return f.f(new_contents)
assert f("a.txt", b"") == 0
|
benchmark_functions_edited/f63.py
|
def f(x):
ret = 3 * x * x * x
return ret
assert f(1) == 3
|
benchmark_functions_edited/f10839.py
|
def f(i, j, n_total_atoms):
if i > j:
i, j = j, i
return i * n_total_atoms - i * (i + 1) // 2 + j - i - 1
assert f(0, 1, 1) == 0
|
benchmark_functions_edited/f14535.py
|
def f(data, mean, std):
if isinstance(data, list):
return [(x - mean) / std for x in data]
return (data - mean) / std
assert f(5, 5, 5) == 0
|
benchmark_functions_edited/f1062.py
|
def f(bit64, index):
bit = (int(bit64) >> index) & 1
return bit
assert f(64, 0) == 0
|
benchmark_functions_edited/f13360.py
|
def f(x, n, mod):
if n == 1:
return 1 % mod
elif n % 2 == 0:
return ((pow(x, n // 2, mod) + 1) * f(x, n // 2, mod)) % mod
else:
return (pow(x, n - 1, mod) + f(x, n - 1, mod)) % mod
assert f(3, 1, 100) == 1
|
benchmark_functions_edited/f11769.py
|
def f(status_list, index):
previous_percentage = 0
for status in status_list[:index]:
previous_percentage += status.status_percentage
return previous_percentage
assert f(
[], 0
) == 0
|
benchmark_functions_edited/f7212.py
|
def f(value):
# Make sure a low but non-zero value is not rounded down to zero
if 0 < value < 3:
return 1
return int(max(0, min(100, ((value * 100.0) / 255.0))))
assert f(3) == 1
|
benchmark_functions_edited/f3759.py
|
def f(func, iteratee):
for value in iteratee:
if func(value):
return value
return None
assert f(lambda x: x == 3, [2, 3, 4]) == 3
|
benchmark_functions_edited/f5269.py
|
def f(path, tree):
pathsum = 0
for i, row in enumerate(tree):
pathsum += row[path[i]]
return pathsum
assert f(
[0, 0],
[[1]]
) == 1
|
benchmark_functions_edited/f2797.py
|
def f(i1, i2):
idum1 = max(i1, i2)
idum2 = min(i1, i2)
lin = idum2 + idum1 * (idum1 - 1) / 2
return lin
assert f(0, 0) == 0
|
benchmark_functions_edited/f5458.py
|
def f(a, b):
#YOUR CODE HERE
if b == 0:
return a
else:
return f(b, a % b)
assert f(3, 12) == 3
|
benchmark_functions_edited/f8468.py
|
def f(arr):
count = 0
pairs = [arr[i:i + 2] for i in range(0, len(arr), 2)]
for pair in pairs:
if len(pair) == 2:
if abs(pair[0] - pair[1]) == 1:
count += 1
return count
assert f(list(range(0, 10))) == 5
|
benchmark_functions_edited/f8213.py
|
def f(string):
if int(string) > 0:
return int(string)
else:
raise RuntimeError("Integer must be positive.")
assert f(1) == 1
|
benchmark_functions_edited/f4857.py
|
def f(bib):
print("There are", len(bib), "articles referenced.")
return len(bib)
assert f({"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6}) == 6
|
benchmark_functions_edited/f14479.py
|
def f(v, in_speed=None, out_speed=None, bandwidth=None, **kwargs):
value = v // 1000000
if bandwidth:
return value * 100 // (bandwidth // 1000)
if in_speed:
return value * 100 // (in_speed // 1000)
if out_speed:
return value * 100 // (out_speed // 1000)
return v
assert f(0) == 0
|
benchmark_functions_edited/f9318.py
|
def f(n):
# factorial of nums less 5 doesn't end with 0
if n < 5:
return 0
# example: n = 11
# n % 5 = 1 => n - 1 = 10 => 10 // 5 = 2
reminder = n % 5
result = (n - reminder) // 5
return result
assert f(10) == 2
|
benchmark_functions_edited/f2679.py
|
def f(puzzle):
return len([i for i, v in enumerate(puzzle) if v != i+1 and v != len(puzzle)])
assert f(
[1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0
|
benchmark_functions_edited/f14528.py
|
def f(tn, fp, fn, tp):
sen = tp / (tp + fn)
return sen
assert f(1, 1, 1, 0) == 0
|
benchmark_functions_edited/f9615.py
|
def f(n) -> int:
if not isinstance(n, int):
raise TypeError(f'Invalid n: not an integer {n}')
count = 1
while (int(n / 10)) != 0:
count += 1
n = int(n / 10)
return count
assert f(1) == 1
|
benchmark_functions_edited/f6178.py
|
def f(numbers):
cummulator = 1
for i in numbers:
cummulator *= i
return cummulator
assert f(list(range(1, 3))) == 2
|
benchmark_functions_edited/f12443.py
|
def f(value, value_type, default_value=None):
try:
return value_type(value)
except ValueError:
return default_value
assert f(1, int, -1) == 1
|
benchmark_functions_edited/f10441.py
|
def f(x1, x2):
steps = abs(x1-x2)
return steps*(steps+1)/2
assert f(1, 3) == 3
|
benchmark_functions_edited/f4152.py
|
def f(days: int) -> int:
return int(days * 24 * 60 * 60 * 1000)
assert f(0) == 0
|
benchmark_functions_edited/f232.py
|
def f(items):
return items[len(items)-1]
assert f(range(10)) == 9
|
benchmark_functions_edited/f9893.py
|
def f(array, item, index=0):
if index >= len(array): # index is out of bound
return None # not found
elif array[index] == item:
return index # found
else:
return f(array, item, index + 1)
assert f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2) == 1
|
benchmark_functions_edited/f9302.py
|
def f(num, den, p):
mod_inverse = pow(den, p - 2, p) # modular version of 1/den
return num * mod_inverse
assert f(1, 2, 3) == 2
|
benchmark_functions_edited/f13101.py
|
def f(context):
try:
return context['user']
except KeyError:
pass
try:
request = context['request']
return request.user
except (KeyError, AttributeError):
pass
return None
assert f({'user': 3}) == 3
|
benchmark_functions_edited/f1438.py
|
def f(i):
if i < 0:
return 0
else:
return i
assert f(0) == 0
|
benchmark_functions_edited/f3405.py
|
def f(rgb):
r, g, b = rgb[0], rgb[1], rgb[2]
gray = 0.2989 * r + 0.5870 * g + 0.1140 * b
return int(gray/16)
assert f( (3, 3, 3) ) == 0
|
benchmark_functions_edited/f1526.py
|
def f(x, lowest, highest):
return max(lowest, min(x, highest))
assert f(5, 2, 5) == 5
|
benchmark_functions_edited/f2601.py
|
def f(a, b, c, d):
if (a == b) & (b == c) & (c == d):
return 1
else:
return 0
assert f(0, 1, 1, 1) == 0
|
benchmark_functions_edited/f5655.py
|
def f(sentiment):
if sentiment < 0:
return -1
elif sentiment > 0:
return 1
else:
return 0
assert f(3.0) == 1
|
benchmark_functions_edited/f4436.py
|
def f(rec, tru):
return len(rec & tru)/len(rec) if len(rec) != 0 else 0
assert f({"a"}, set()) == 0
|
benchmark_functions_edited/f8942.py
|
def f(n):
i, count = 1, 0
while i <= n:
if n % i == 0:
count += 1
i += 1
return count
assert f(0) == 0
|
benchmark_functions_edited/f13054.py
|
def f(wt: str, off: str) -> int:
wtl = len(wt)
offl = len(off)
assert (wtl == offl), "The lengths wt and off differ: wt = {}, off = {}".format(str(wtl), str(offl))
return wtl
assert f("a", "a") == 1
|
benchmark_functions_edited/f6697.py
|
def f(number):
if number > 0:
return 1
if number < 0:
return -1
return 0
assert f(3.0e10) == 1
|
benchmark_functions_edited/f7174.py
|
def f():
# noqa: D207
print("Hello, world!")
return 0
assert f(
# noqa: D207
) == 0
|
benchmark_functions_edited/f9857.py
|
def f(t: str) -> int:
n = [int(x) for x in t.split(":")]
n[0] = n[0] * 60 * 60
n[1] = n[1] * 60
return sum(n)
assert f("00:00:01") == 1
|
benchmark_functions_edited/f8610.py
|
def f(fname):
if not fname.endswith(".log.txt") or "-" not in fname:
return
try:
return int(fname[:-8].split("-")[-1])
except ValueError:
return
assert f("service-20200101-123456-000.log.txt") == 0
|
benchmark_functions_edited/f2518.py
|
def f(cell1, cell2):
return ((cell1[0] - cell2[0])**2 + (cell1[1] - cell2[1])**2)**0.5
assert f((0, 0), (0, -1)) == 1
|
benchmark_functions_edited/f4494.py
|
def f(x, m, b):
return m * x + b
assert f(10, 1, -1) == 9
|
benchmark_functions_edited/f5694.py
|
def f(_str):
return int(_str) if _str.isdigit() else _str
assert f('0') == 0
|
benchmark_functions_edited/f10801.py
|
def f(*values):
for v in values:
if v is not None:
return v
return None
assert f(1, None, 3, None, 5) == 1
|
benchmark_functions_edited/f6095.py
|
def f(n):
if n < 3:
return 1
else:
print("{0} = {1} + {2}".format(n, n - 1, n - 2))
return f(n - 1) + f(n - 2)
assert f(6) == 8
|
benchmark_functions_edited/f13757.py
|
def f(letter):
if letter == 'a' or \
letter == 'A':
return 0
elif letter == 'c' or \
letter == 'C':
return 1
elif letter == 't' or \
letter == 'T':
return 2
elif letter == 'g' or \
letter == 'G':
return 3
else:
return -1
assert f('c') == 1
|
benchmark_functions_edited/f5681.py
|
def f(num):
fat = 1
if num == 0:
return fat
for i in range(1,num+1,1):
fat *= i # fat = fat * i
return fat
assert f(2) == 2
|
benchmark_functions_edited/f13978.py
|
def f( aRegMask ):
numBits = 0;
aBinStr = '{0:32b}'.format(int( aRegMask, 16 )).strip().rstrip( "0" )
while len( aBinStr ):
aBinCh = aBinStr[-1]
aBinStr = aBinStr[0:-1]
if aBinCh == '1':
numBits += 1
else:
break
return ((2**numBits) - 1) # return max value field can contain
assert f( '0x00000001' ) == 1
|
benchmark_functions_edited/f13858.py
|
def f(n, r):
if 0 <= r <= n:
#initializing two variables as 1
ntok = 1
rtok = 1
#we use the formula nCr = n!/(n-r)!r!
for t in range(1, min(r, n - r) + 1):
ntok *= n
rtok *= t
n -= 1
return ntok // rtok
else:
return 0
assert f(1, 0) == 1
|
benchmark_functions_edited/f3825.py
|
def f(wave_height, wavelength, water_depth):
return wave_height * wavelength ** 2 / water_depth ** 3
assert f(0, 5, 2) == 0
|
benchmark_functions_edited/f7133.py
|
def f(i,n,t):
if i < 0 or i > n:
return 0
elif n == 0:
return 1
return (1-t) * f(i,n-1,t) + t * f(i-1,n-1,t)
assert f(0, 0, 0.5) == 1
|
benchmark_functions_edited/f13137.py
|
def f(tab, lo, hi):
while lo < hi:
mid = lo + (hi - lo) // 2
if tab[mid]:
hi = mid
else:
lo = mid + 1
return lo
assert f(
[True, True, False],
0, 1) == 0
|
benchmark_functions_edited/f1395.py
|
def f(file):
return int('dsc180a-wi20-public' in file)
assert f(
'/users/home/dsc180a-wi20-public/data/001/001/001/0000000000000001/0000000000000003.txt') == 1
|
benchmark_functions_edited/f11353.py
|
def f(scale_factor: float, ngates: int) -> int:
return int(round(ngates * (scale_factor - 1.0) / 2.0))
assert f(1.5, 6) == 2
|
benchmark_functions_edited/f13472.py
|
def f(_needle, _haystack, _strict=False):
if not _needle in _haystack.values():
return False
for k, v in _haystack.items():
if v == _needle:
return k
return False
assert f('green', {0: 'blue', 1:'red', 2: 'green', 3:'red'}) == 2
|
benchmark_functions_edited/f2366.py
|
def f(boolean_value):
if boolean_value:
return 1
return 0
assert f(-1) == 1
|
benchmark_functions_edited/f13148.py
|
def f(a: int, b: int) -> int:
x0, x1, y0, y1 = 1, 0, 0, 1
oa, ob = a, b
while b != 0:
q = a // b
a, b = b, a % b
x0, x1 = x1, x0 - q * x1
y0, y1 = y1, y0 - q * y1
if x0 < 0:
x0 += ob
if y0 < 0:
y0 += oa
# when a and b are not relatively prime
if a != 1 or (oa * x0) % ob != 1:
return -1
return x0
assert f(1, 2**123) == 1
|
benchmark_functions_edited/f2020.py
|
def f(arg0, args1="name", *args, **kwargs):
f_var = arg0 + 1
return f_var
assert f(0) == 1
|
benchmark_functions_edited/f13905.py
|
def _gr_remove_ ( graph , remove ) :
old_len = len ( graph )
removed = []
for point in graph :
if remove ( *graph [ point ] ) :
removed.append ( point )
ir = 0
for i in removed :
d = graph.RemovePoint ( i - ir )
if 0 <= d : ir += 1
return len ( graph ) - old_len
assert f( { (0,0):"a", (1,0):"b", (2,0):"c" }, lambda s:False ) == 0
|
benchmark_functions_edited/f2369.py
|
def distance_pronoun_antecedent (pair) :
return pair[3]-pair[2]
assert f(('<NAME>', '<NAME>', 1, 3)) == 2
|
benchmark_functions_edited/f7909.py
|
def f(accs):
valid = [acc for acc in accs if acc]
if len(valid) == 0:
return None
ret = valid[0]
for v in valid[1:]:
ret += v
return ret
assert f([None, None, 3, None]) == 3
|
benchmark_functions_edited/f4449.py
|
def f(word: str) -> int:
return min(3, max(len(word) // 2, 1))
assert f('a') == 1
|
benchmark_functions_edited/f7902.py
|
def f(valStr):
val = int(valStr[:-1])
if valStr[-1] in ("S", "W"):
val = -val
return val
assert f( "0E" ) == 0
|
benchmark_functions_edited/f756.py
|
def f(vals):
return sum([v for v in vals])/len(vals)
assert f([0]) == 0
|
benchmark_functions_edited/f6753.py
|
def f(sentence, vocab_to_int):
unk_count = 0
for word in sentence:
if word == vocab_to_int["<UNK>"]:
unk_count += 1
return unk_count
assert f(
["batman", "batman", "<UNK>"],
{"<UNK>": 1, "i": 2, "am": 3, "batman": 4, "robin": 5, "joker": 6},
) == 0
|
benchmark_functions_edited/f6477.py
|
def f(number) -> int:
rev = 0
while number > 0:
d = number % 10
rev = rev*10+d
number //= 10
return rev
assert f(10) == 1
|
benchmark_functions_edited/f6188.py
|
def f(row, prediction_col_name='predictions', answer_col_name='answer'):
if bool(set(row[answer_col_name]) & set(row[prediction_col_name])):
return 1
else: return 0
assert f(
{'predictions': ['A', 'B'], 'answer': []}) == 0
|
benchmark_functions_edited/f4086.py
|
def f(s):
try:
return s.iloc[0]
except AttributeError:
return s
assert f(1) == 1
|
benchmark_functions_edited/f7837.py
|
def f(kernel_size: int, dilation: int):
return (kernel_size - 1) * dilation + 1 if kernel_size % 2 == 1 else kernel_size * dilation
assert f(5, 1) == 5
|
benchmark_functions_edited/f140.py
|
def f(data):
data = data.split()
return len(data)
assert f('123') == 1
|
benchmark_functions_edited/f202.py
|
def f(val, lo, hi):
return val * (hi - lo) + lo
assert f(0, 0, 10) == 0
|
benchmark_functions_edited/f13998.py
|
def f(p: float, q: float, hedgeRatio: float) -> float:
return (p - hedgeRatio * q)
assert f(10, 10, 1.0) == 0
|
benchmark_functions_edited/f93.py
|
def f(i, j):
return 1 if i == j else 0
assert f(3, 3) == 1
|
benchmark_functions_edited/f3650.py
|
def f(arg1, arg2='default', *args, **kwargs):
local_variable = arg1 * 2
return local_variable
assert f(1) == 2
|
benchmark_functions_edited/f11403.py
|
def f(s):
lowerS = s.lower()
vowels = ['a', 'e', 'i', 'o', 'u']
ctr = 0
for ch in lowerS:
if ch in vowels:
ctr += 1
print ('There are {} vowels in: "{}"'.format(ctr, s))
print ()
return ctr
assert f(
'c') == 0
|
benchmark_functions_edited/f590.py
|
def f(n, a, b, c):
fn = n / a + n**2 / b + n**3 / c
return fn
assert f(0, 2, 3, 4) == 0
|
benchmark_functions_edited/f12180.py
|
def f(iterable):
return sum(1 << i for i, obj in enumerate(iterable) if obj)
assert f(range(0)) == 0
|
benchmark_functions_edited/f13972.py
|
def f(a: list, b: list) -> int:
l: int = len(a)
hash_table: dict = {a[0] - b[0]: 0}
length: int = 0
for i in range(1, l):
a[i] += a[i - 1]
b[i] += b[i - 1]
diff = a[i] - b[i]
if diff == 0:
length = i + 1
elif diff in hash_table:
length = max(length, i - hash_table[diff])
else:
hash_table[diff] = i
return length
assert f([2, 1, 2, 3, 4], [3, 1, 2, 4, 1]) == 2
|
benchmark_functions_edited/f13296.py
|
def f(A):
# initialise array to record the sums of the elements in the array
sum = [0] * len(A)
sum[0] = A[0]
# populate sums
for i in range(1, len(A)):
sum[i] = A[i] + sum[i - 1]
# get a list of solutions for valid values of N
solutions = [abs(sum[-1] - 2 * sum[i])
for i in range(0, len(A) - 1)]
# return smallest value found
return min(solutions)
assert f(
[1, 1, 1, 1]) == 0
|
benchmark_functions_edited/f14023.py
|
def f(n, x, ans):
digit = pow(10, x) # numbers of digit
# base case: finish examining all the digits
if n // digit == 0:
return ans
else:
number = n // digit - n // (digit * 10) * 10 # extract the number we want to examine
if number > ans:
ans = number
return f(n, x + 1, ans)
assert f(10, 1, 1) == 1
|
benchmark_functions_edited/f8675.py
|
def f(xp: int, yp: int, zp: int, option: str) -> int:
options_map = {'x': xp, 'y': yp, 'z': zp, '-x': -xp, '-y': -yp, '-z': -zp}
return options_map[option]
assert f(4, 3, 2, 'y') == 3
|
benchmark_functions_edited/f5662.py
|
def f(z, cs):
s = cs[-1]
for c in reversed(cs[:-1]):
s *= z
s += c
return s
assert f(0, [1, 0, 2]) == 1
|
benchmark_functions_edited/f13738.py
|
def f(az1: float, az2: float) -> float:
diff = (az2 - az1) % 360
return diff
assert f(10, 10) == 0
|
benchmark_functions_edited/f5620.py
|
def f(a, b):
if a >= b:
return a
elif a < b:
return b
else:
print('Something weird happened')
return 0
assert f(6, 5) == 6
|
benchmark_functions_edited/f12393.py
|
def f(ch):
if ch is None:
return None
if len(ch) == 1:
return ord(ch)
if ch[0:2] in ("0x", "\\x"):
ch = ch[2:]
if not ch:
raise ValueError("Empty char")
if len(ch) > 2:
raise ValueError("Char can be only a char letter or hex")
return int(ch, 16)
assert f("0x00") == 0
|
benchmark_functions_edited/f10089.py
|
def f(current_parentheses_count: int, token_text: str) -> int:
if token_text in "([{": # nosec
return current_parentheses_count + 1
elif token_text in "}])": # nosec
return current_parentheses_count - 1
return current_parentheses_count
assert f(1, "}") == 0
|
benchmark_functions_edited/f12826.py
|
def f(x,y,cov):
return round((cov / (x * y)),2)
assert f(1, 1, 1) == 1
|
benchmark_functions_edited/f12463.py
|
def f(events):
if not events: # no events means no housecalls
print('No upcoming events found.')
return 0
count = 0
for event in events:
name = event['summary'].lower()
if ('house' in name) and ('call' in name):
count += 1 # increment # housecalls
return count
assert f([]) == 0
|
benchmark_functions_edited/f11998.py
|
def f(line):
# your code here
for l in range(len(line), 0, -1):
for i in range(0, len(line)-l):
sub = line[i:i + l]
if line[i+l:].count(sub)>0:
return len(sub)
elif len(sub) == 1:return 0
return 0
assert f(
'abc') == 0
|
benchmark_functions_edited/f817.py
|
def f(n: int, add: int, mod: int) -> int:
return (n + add) % mod
assert f(3, -1, 10) == 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.