file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f9162.py | def f(iterable, pred=None, default=None):
return next(filter(pred, iterable), default)
assert f(range(1, 5)) == 1 |
benchmark_functions_edited/f12064.py | def f(grid):
m, n = len(grid), len(grid[0])
def dfs(i, j):
if 0 <= i < m and 0 <= j < n and grid[i][j]:
grid[i][j] = 0
return 1 + dfs(i - 1, j) + dfs(i, j + 1) + dfs(i + 1, j) + dfs(i, j - 1)
return 0
areas = [dfs(i, j) for i in range(m) for j in range(n) if grid[i][j]]
return max(areas) if areas else 0
assert f([[]]) == 0 |
benchmark_functions_edited/f10784.py | def f(value, default):
return value if value is not None else default
assert f(5, 10) == 5 |
benchmark_functions_edited/f2751.py | def f(value):
count = 0
while value:
value &= value - 1
count += 1
return count
assert f(0) == 0 |
benchmark_functions_edited/f12370.py | def f(todo1, todo2):
return int(todo1['points']) + int(todo2['points'])
assert f(
{'name': 'Example 1', 'body': 'This is a test task', 'points': '3'},
{'name': 'Task 2', 'body': 'Yet another example task', 'points': '3'}) == 6 |
benchmark_functions_edited/f5699.py | def f(choice, choices):
for choice_tuple in choices:
if choice == choice_tuple[1]:
return choice_tuple[0] - 1
assert f(2, [(1, 1), (2, 2)]) == 1 |
benchmark_functions_edited/f12603.py | def f(n):
dp_table = [1, 1]
# the indices of the array = sequence value of the Fibonacci number
for input in range(2, n):
dp_table.append(dp_table[input - 1] + dp_table[input - 2])
return dp_table[n - 1]
assert f(1) == 1 |
benchmark_functions_edited/f11658.py | def f(*iterable):
return next((item for item in iterable if item is not None), None)
assert f(1, 2) == 1 |
benchmark_functions_edited/f7549.py | def f(z, x, beta):
return 3 * (4* z**2 - beta**2 * x**2) / 4 / beta**2 / (1+x)
assert f(1, 2, 1) == 0 |
benchmark_functions_edited/f5379.py | def f(func, index, *args, **kwargs):
return func(*args, **kwargs)[index]
assert f(list, 0, [0, 1]) == 0 |
benchmark_functions_edited/f10468.py | def f(inList):
if len(inList) == 1:
return inList[0]
if len(inList) == 0:
return 0.
if not len(inList) % 2:
return (inList[len(inList) // 2] + inList[len(inList) // 2 - 1]) / 2.0
return inList[len(inList) // 2]
assert f(sorted([])) == 0 |
benchmark_functions_edited/f10593.py | def f(L):
for e in L:
if e%2 == 0:
return e
else:
e = e
raise ValueError('The provided list does not contain an even number')
return None
assert f( [2, 4, 6] ) == 2 |
benchmark_functions_edited/f7059.py | def f(value: float) -> int:
value_str = str(value)
if "." not in value_str:
return 0
else:
_, buf = value_str.split(".")
return len(buf)
assert f(12) == 0 |
benchmark_functions_edited/f6516.py | def f(lhs, rhs, rules):
for rule in rules:
if len(rule[1])==1 and rule[0]==lhs and rhs==rule[1][0]:
return rule[2]
return 0
assert f(0,2,[['0', ['1'], 1]]) == 0 |
benchmark_functions_edited/f6857.py | def f(arg_ranges):
from functools import reduce
import operator
return reduce(operator.mul, [len(r) for r in arg_ranges], 1)
assert f( [ [1,2,3] ] ) == 3 |
benchmark_functions_edited/f11004.py | def f(test_video_quality):
try:
test_video_quality = str(test_video_quality[:-1])
test_video_quality = int(test_video_quality)
return test_video_quality
except:
return 0
assert f("p") == 0 |
benchmark_functions_edited/f12359.py | def f(input_list):
if not isinstance(input_list, (list, tuple)):
return 0
if len(input_list) == 0:
return 1
return 1 + max(map(list_depth_count, input_list))
assert f({"a": 1, "b": 2, "c": 3}) == 0 |
benchmark_functions_edited/f2704.py | def f(num_list):
product = 1
for num in num_list:
product *= num
return product
assert f([]) == 1 |
benchmark_functions_edited/f5669.py | def f(s):
if not s or s.endswith(('\n', '\r')):
return 0
return len(s.splitlines()[-1])
assert f("") == 0 |
benchmark_functions_edited/f6106.py | def f(char):
if char in ('.', '-'):
return 0
if char in ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'):
return 1
return 2
assert f('0') == 1 |
benchmark_functions_edited/f6025.py | def f(s, c, count = 1):
for i in range(len(s)):
if s[i] == c:
count = count - 1
if count == 0:
return i
assert f('hello', 'l', 1) == 2 |
benchmark_functions_edited/f285.py | def f(num):
return int(round(num))
assert f(-0.5) == 0 |
benchmark_functions_edited/f2858.py | def f(lower: int, value: int, upper: int) -> int:
return min(max(value, lower), upper)
assert f(1, 2, 2) == 2 |
benchmark_functions_edited/f650.py | def f(position, roll):
return position + (roll * 2)
assert f(1, 2) == 5 |
benchmark_functions_edited/f6002.py | def f(base_minor, base_major, height):
# You have to code here
# REMEMBER: Tests first!!!
area = ((base_minor + base_major) / 2) * height
return area
assert f(1, 2, 4) == 6 |
benchmark_functions_edited/f9020.py | def f(nth_nmb: int) -> int:
cache = {0: 0, 1: 1}
def fib(_n):
return _n if _n in cache else fib(_n - 1) + fib(_n - 2)
return fib(nth_nmb)
assert f(0) == 0 |
benchmark_functions_edited/f3226.py | def f(p_1,p_2):
return ((p_1[0]-p_2[0])**2.0 + (p_1[1]-p_2[1])**2.0 + (p_1[2]-p_2[2])**2.0)**(1.0/2.0)
assert f(
[0, 0, 0], [0, 0, 0]) == 0 |
benchmark_functions_edited/f6763.py | def f(list_val, init_value=0):
curr_value = init_value
for value in list_val:
curr_value = curr_value ^ value
return curr_value
assert f([1, 0, 1, 1, 1, 1, 0, 1], 1) == 1 |
benchmark_functions_edited/f12489.py | def f(items, x):
for i in range(len(items)):
if x == items[i]:
return i
return None
assert f([1, 3, 2], 1) == 0 |
benchmark_functions_edited/f7506.py | def f(n, k):
u = n
s = n + 1
while u < s:
s = u
t = (k - 1) * s + n // pow(s, k - 1)
u = t // k
return s
assert f(27, 3) == 3 |
benchmark_functions_edited/f2910.py | def f(beta, gamma, prob_symptoms, rho):
Qs = prob_symptoms
return beta / gamma * (Qs + (1 - Qs) * rho)
assert f(1, 1, 1, 1) == 1 |
benchmark_functions_edited/f5721.py | def f(m,e,n):
return(pow(m,e,n))
assert f(5, 3, 11) == 4 |
benchmark_functions_edited/f3633.py | def f(x, x1, y1, x2, y2):
return (y1 - y2) / (x1 - x2) * x + (y2 * x1 - x2 * y1) / (x1 - x2)
assert f(3, 1, 2, 3, 4) == 4 |
benchmark_functions_edited/f11370.py | def f( nAWS, year ):
x = year - 1
if nAWS <= 1:
return max(0, x) # + 0.1*random.random())
elif nAWS == 2:
c = 0.25
m = (1-c)/1
elif nAWS == 3:
c = 1
m = (2.1-c)/2
else:
c = 2
m = (3.1-c)/4
return max(0, m*x+c)
assert f( 2, 6 ) == 4 |
benchmark_functions_edited/f5937.py | def f(total_size, page_size):
quotient, remainder = total_size / page_size, total_size % page_size
total_page = quotient + min(1, remainder)
return total_page
assert f(100, 50) == 2 |
benchmark_functions_edited/f7282.py | def f(a,b):
check={}
check['(']=3
check['^']=2
check['*']=2
check['/']=2
check['-']=1
check['+']=1
if check[a] <= check[b]:
return 1
else:
return 0
assert f(
"(", "+"
) == 0 |
benchmark_functions_edited/f6895.py | def f(n):
if n == 0: # T(0) = 1
return 1
x = f(n//2) # T(n) = 1+T(n/2)
if n%2 == 0:
return x*x
return 2*x*x
assert f(1) == 2 |
benchmark_functions_edited/f5770.py | def f(a: int, b: int, c: int) -> int:
x = a - b
y = b - c
z = a - c
if x * y > 0:
return b
if x * z > 0:
return c
return a
assert f(1, 2, 3) == 2 |
benchmark_functions_edited/f11765.py | def f(time_, samplerate):
sample = int(time_ * samplerate)
return sample
assert f(0.0, 13) == 0 |
benchmark_functions_edited/f9940.py | def f(n):
if n < 2:
return n
return f(n - 1) + f(n - 2)
assert f(2) == 1 |
benchmark_functions_edited/f1763.py | def f(m,e,N): # return m^e mod N
return pow(m,e,N)
assert f(2, 3, 5) == 3 |
benchmark_functions_edited/f9237.py | def f(s):
if len(s) != 4:
return 0
a = ord(s[0]) << 24
b = ord(s[1]) << 16
c = ord(s[2]) << 8
l = s[3]
d = ord(l)
if l.isdigit():
d = d - ord("0")
return a + b + c + d
assert f("123") == 0 |
benchmark_functions_edited/f4495.py | def f(bytes):
result = 0
for b in bytes:
result = result * 256 + int(b)
return result
assert f(b'') == 0 |
benchmark_functions_edited/f9266.py | def f(x, y, xarr, yarr):
dx = abs(xarr - x)
dy = abs(yarr - y)
return (dx*dx + dy*dy) ** 0.5
assert f(1, 1, 1, 0) == 1 |
benchmark_functions_edited/f5236.py | def f(fn, *decorators):
for decorator in reversed(decorators):
fn = decorator(fn)
return fn
assert f(1) == 1 |
benchmark_functions_edited/f2228.py | def f(lis):
res = 0
for x in lis:
res += len(x)
return res
assert f(list("")) == 0 |
benchmark_functions_edited/f2945.py | def f( s ):
result = 0
for c in s: result = 256 * result + c
return result
assert f(b'\x00\x00\x00\x00') == 0 |
benchmark_functions_edited/f3023.py | def f(data_list, default=None):
if len(data_list) > 0:
return data_list[0]
else:
return default
assert f([1, 2, 3], 'default') == 1 |
benchmark_functions_edited/f1376.py | def f(x):
try:
return int(x)
except Exception:
return len(x)
assert f(3.14) == 3 |
benchmark_functions_edited/f1957.py | def f(x):
ret = 0
while x & 1 == 0:
x >>= 1
ret += 1
return ret
assert f(1025) == 0 |
benchmark_functions_edited/f7757.py | def f(input):
window = lambda i, list : list[i] + list[i+1] + list[i+2]
return sum(1 if window(i, input) < window(i+1, input) else 0 for i in range(len(input)-3))
assert f([1, 2, 3]) == 0 |
benchmark_functions_edited/f3958.py | def f(data: bytes) -> int:
chars = data.hex()
return int(chars)
assert f(b"\x03") == 3 |
benchmark_functions_edited/f13358.py | def f(seq):
sseq = sorted(seq)
length = len(seq)
if length % 2 == 1:
return sseq[int((length - 1) / 2)]
else:
return (sseq[int((length - 1) / 2)] + sseq[int(length / 2)]) / 2
assert f((1, 4, 5, 7, 9)) == 5 |
benchmark_functions_edited/f2648.py | def f(lomb_model, i):
return lomb_model['freq_fits'][i-1]['freq']
assert f({'freq_fits': [{'freq': 1}, {'freq': 2}, {'freq': 3}]}, 2) == 2 |
benchmark_functions_edited/f6864.py | def f(L, K):
def dotHelp(L, K, accum):
if (L == [] or K == []):
return accum
return dotHelp(L[1:], K[1:], accum+L[0]*K[0])
return dotHelp(L, K, 0)
assert f([0], [0]) == 0 |
benchmark_functions_edited/f1204.py | def f(start, end):
return (end-start)*1000
assert f(5, 5) == 0 |
benchmark_functions_edited/f7099.py | def f(value):
str_value = str(value)
if value >= 0:
str_reverse = str_value[::-1]
else:
str_reverse = "-" + str_value[:0:-1]
return int(str_reverse)
assert f(0) == 0 |
benchmark_functions_edited/f307.py | def f(V, a, b, c):
return a * V**2 + b * V + c
assert f(0, 1, 0, 0) == 0 |
benchmark_functions_edited/f13347.py | def f(key, number_of_buckets, max_key_length=32):
raw_string_key = str(key)
string_key = raw_string_key[:min(max_key_length, len(raw_string_key))]
the_hash = 0
for character_index, character in enumerate(string_key):
the_hash += ord(character) + character_index
return the_hash % number_of_buckets
assert f(3, 3) == 0 |
benchmark_functions_edited/f2760.py | def f(style):
return {'o': 0, 'x': 80, '*': -80, '^': 120}[style]
assert f('o') == 0 |
benchmark_functions_edited/f2247.py | def f(num_timeseries):
return (num_timeseries * (num_timeseries - 1)) / 2
assert f(0) == 0 |
benchmark_functions_edited/f4305.py | def f(bits):
return bits / (8 * 1024 * 1024)
assert f(0) == 0 |
benchmark_functions_edited/f7934.py | def f(p1, p2):
return (pow(abs(p1[0] - p2[0]), 2) + pow(abs(p1[1] - p2[1]), 2)) ** 0.5 / 65
assert f( (37.868123, -122.263424), (37.868123, -122.263424) ) == 0 |
benchmark_functions_edited/f1932.py | def f(FN, TN, TP, FP):
acc = 1.0 * (TP + TN) / (TP + TN + FP + FN)
return acc
assert f(1,0,0,1) == 0 |
benchmark_functions_edited/f10616.py | def f(n, largest_num):
n = abs(n)
a = n % 10
if n / 10 == 0 and n % 10 == 0:
return largest_num
else:
if a > largest_num:
largest_num = a
return f(n//10, largest_num)
assert f(123456789, 0) == 9 |
benchmark_functions_edited/f13445.py | def f(n: int, p: int, is_odd: bool) -> int:
n %= p
y = pow(n, (p + 1) // 4, p)
y_odd = bool(y & 0x01)
if y_odd != is_odd:
y = p - y
assert (y * y) % p == n
return y
assert f(1, 29, 1) == 1 |
benchmark_functions_edited/f14098.py | def f(effect_or_preset, tensor, shape, time, speed):
if callable(effect_or_preset):
return effect_or_preset(tensor=tensor, shape=shape, time=time, speed=speed)
else: # Is a Preset. Unroll me.
for e_or_p in effect_or_preset.post_effects:
tensor = f(e_or_p, tensor, shape, time, speed)
return tensor
assert f(
lambda **_: 1, 1, 2, 3, 4) == 1 |
benchmark_functions_edited/f8296.py | def f(array:list, x:int, n:int=0):
if n == len(array):
return -1
if array[n] == x:
return n
return f(array,x,n+1)
assert f([1,2,3,4,5],5) == 4 |
benchmark_functions_edited/f13380.py | def f(seq1, seq2):
alnlen = len(seq1)
identical = 0
for i in range(0, len(seq1)):
if seq1[i].isalpha() and seq2[i].isalpha() and seq1[i] == seq2[i]:
identical += 1
pid = identical/alnlen
return pid
assert f("ACGT", "GGCC") == 0 |
benchmark_functions_edited/f9721.py | def f(qty, box_capacity=6):
return int(qty / box_capacity) + 1
assert f(32) == 6 |
benchmark_functions_edited/f7798.py | def f(dividendList, divisor):
multNum = 0
for dividend in dividendList:
if dividend % divisor == 0:
multNum += 1
return multNum
assert f(range(10), 3) == 4 |
benchmark_functions_edited/f9553.py | def f(left_hash, right_hash):
if len(left_hash) != len(right_hash):
raise ValueError('Hamming distance requires two strings of equal length')
return sum(map(lambda x: 0 if x[0] == x[1] else 1, zip(left_hash, right_hash)))
assert f(
'0000000000000000000000000000000000000000000000000000000000000000',
'0000000000000000000000000000000000000000000000000000000000000000',
) == 0 |
benchmark_functions_edited/f793.py | def f(x):
try:
return int(x=='male')
except:
return -1
assert f('Female')==0 |
benchmark_functions_edited/f836.py | def f(iterator):
return sum(1 for _ in iterator)
assert f(iter([1, 2, 3, 4, 5])) == 5 |
benchmark_functions_edited/f10103.py | def f(coefs, p):
A, B, C = coefs
return A * p.real + B * p.imag + C
assert f((2, 3, 1), complex(0, 0)) == 1 |
benchmark_functions_edited/f100.py | def f(x, y, z=0):
return x + y + z
assert f(1, 2, 3) == 6 |
benchmark_functions_edited/f2911.py | def f(range_list):
r_s=0
for r in range_list:
r_s+= r[1]- r[0]
return r_s
assert f( [(1, 2), (3, 4)] ) == 2 |
benchmark_functions_edited/f6569.py | def f(x):
if x > 0:
return x
else:
return -x
assert f(0.0) == 0 |
benchmark_functions_edited/f5437.py | def f(count, token):
old_value = count[token]
count[token] -= min(count[token], 1)
return min(old_value, 1)
assert f(
{'a': 1, 'b': 2, 'c': 1, 'd': 0, 'e': 3, 'f': 5}, 'a') == 1 |
benchmark_functions_edited/f9076.py | def f(d):
return next(iter(d.keys()))
assert f({i: i for i in range(10)}) == 0 |
benchmark_functions_edited/f10269.py | def f(number, round_to):
return int(round(((number - int(number)) * 100) / round_to) * round_to)
assert f(15, -100) == 0 |
benchmark_functions_edited/f8601.py | def f(miles_per_min):
kilos_per_day =miles_per_min*1.609*24*60
return kilos_per_day
assert f(0) == 0 |
benchmark_functions_edited/f981.py | def f(x, p_y):
v_y = p_y - x
return v_y
assert f(0, 0) == 0 |
benchmark_functions_edited/f13716.py | def f(x):
if x is not None:
try:
x = int(x)
except ValueError:
raise ValueError(
"'stata_check_log_lines' must be a nonzero and nonnegative integer, "
f"but it is '{x}'."
)
if x <= 0:
raise ValueError("'stata_check_log_lines' must be greater than zero.")
return x
assert f("1") == 1 |
benchmark_functions_edited/f10118.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(4) == 5 |
benchmark_functions_edited/f4563.py | def f(get, default, highest):
if get and get.isdigit() and int(get) in range(highest):
return int(get)
return default
assert f(0, 0, 5) == 0 |
benchmark_functions_edited/f14204.py | def f(lowerBound: int, upperBound: int, targetLetter: str, password: str) -> int:
validSoFar: bool = True
letterCount: int = 0
for char in password:
if char == targetLetter:
letterCount += 1
if letterCount > upperBound:
validSoFar = False
break
return 1 if validSoFar and letterCount >= lowerBound else 0
assert f(1, 3, "a", "abcde") == 1 |
benchmark_functions_edited/f3150.py | def f(lst):
assert len(lst) > 0,"List must contain something"
return sum(lst)/len(lst)
assert f([0, 1, 2, 3, 4]) == 2 |
benchmark_functions_edited/f1961.py | def f(x):
return x.index(max(x))
assert f([1, 2, 3, 4, 5, 6]) == 5 |
benchmark_functions_edited/f73.py | def f(x):
return 1 * (x > 0)
assert f(1000) == 1 |
benchmark_functions_edited/f6285.py | def f(f_x,y_true,margin=1):
return max(0,margin-y_true*f_x)
assert f(1,0) == 1 |
benchmark_functions_edited/f8632.py | def f(state):
if state == 'green':
retval = 0
elif state == 'yellow':
retval = 1
elif state == 'red':
retval = 2
else:
retval = 3 # fail
return retval
assert f(*['yellow']) == 1 |
benchmark_functions_edited/f8868.py | def f(row, field):
return row.index(field)
assert f(
["field1", "field2", "field3"], "field1"
) == 0 |
benchmark_functions_edited/f1345.py | def f(sequence):
return (len(sequence) - 1) // 2
assert f(range(17)) == 8 |
benchmark_functions_edited/f3200.py | def f(x: float):
return 1.0 if x >= 0 else 0.0
assert f(-0.5) == 0 |
benchmark_functions_edited/f14363.py | def f(pixel_index, block_size, rows_cols):
return block_size if (pixel_index + block_size) < rows_cols else rows_cols - pixel_index
assert f(0, 5, 10) == 5 |
benchmark_functions_edited/f9353.py | def f(x: int) -> int:
assert x >= 0
z = 0
if x > 3:
z = x
y = x // 2 + 1
while y < z:
z = y
y = (x // y + y) // 2
elif x != 0:
z = 1
return z
assert f(99) == 9 |
benchmark_functions_edited/f8917.py | def f(_value):
values = [1, 0]
if _value not in values:
if _value.lower() == "white":
return True
elif _value.lower() == "black":
return False
else:
return _value
assert f("Black") == 0 |
benchmark_functions_edited/f5667.py | def f(inlist):
ss = 0
for item in inlist:
ss = ss + item * item
return ss
assert f([]) == 0 |
benchmark_functions_edited/f14544.py | def f(tri_list):
acc, a, b, c = 0, [], [], []
for line in tri_list:
coords = list(map(int, (line.split())))
for i, triangle in enumerate((a, b, c)):
triangle.append(coords[i])
if len(a) == 3:
for triangle in (a, b, c):
triangle.sort()
if triangle[0] + triangle[1] > triangle[2]:
acc += 1
a, b, c = [], [], []
return acc
assert f([
'1 2 3',
'3 2 1',
'4 4 4',
]) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.