file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f10234.py | def f(freq, n_rows):
if n_rows == 0:
raise ValueError("The rows supposed not to be zero")
return freq / n_rows
assert f(0, 4) == 0 |
benchmark_functions_edited/f12930.py | def f(s):
list = []
max_size = 0
i = 0
while i < len(s):
if not s[i] in list:
list.append(s[i])
else:
max_size = max(max_size, len(list))
list = list[list.index(s[i]) + 1:]
list.append(s[i])
i += 1
max_size = max(max_size, len(list))
return max_size
assert f( " ") == 1 |
benchmark_functions_edited/f13734.py | def f(hfi: float) -> int:
if hfi < 500:
return 1
if hfi < 1000:
return 2
if hfi < 2000:
return 3
if hfi < 4000:
return 4
return 5
assert f(500) == 2 |
benchmark_functions_edited/f7948.py | def f(c1: int, c2: int, c3: int) -> int:
if c1 >= c2:
if c2 >= c3:
return 1
else:
return 2
else:
if c2 <= c3:
return 3
else:
return 4
assert f(3, 1, 2) == 2 |
benchmark_functions_edited/f5833.py | def f(n):
if n == 1:
return 1
return n * f(n - 1)
assert f(3) == 6 |
benchmark_functions_edited/f7473.py | def f(n):
# *** YOUR CODE HERE ***
return n
assert f(1) == 1 |
benchmark_functions_edited/f6551.py | def f(U, T_g, T_d, RTI):
dT_d_dt = U ** (1 / 2) * (T_g - T_d) / RTI
return dT_d_dt
assert f(1, 1, 1, 1) == 0 |
benchmark_functions_edited/f4891.py | def f(nda, obj):
for i in range(0, len(nda)):
if(nda[i] == obj):
return i;
return -1;
assert f( (1, 2, 3), 2) == 1 |
benchmark_functions_edited/f7754.py | def f(index, valid_min, valid_max):
if index >= valid_max:
index = index - valid_max
if index < valid_min:
index = index + valid_max
return index
assert f(4, 0, 4) == 0 |
benchmark_functions_edited/f4000.py | def f(d):
return (0 if not isinstance(d, dict) or len(d) == 0 else
1 + max(f(v) for v in d.values()))
assert f(5) == 0 |
benchmark_functions_edited/f2799.py | def f(a, b):
while a != 0:
a, b = b % a, a
return b
assert f(150, 5) == 5 |
benchmark_functions_edited/f2349.py | def f(itself=0, phillips=0, gamma=0, i=0, pi=0, zphi=1):
a = itself * phillips * pi**zphi + (gamma-1) * i
return a
assert f(1, 1, 1, 1) == 0 |
benchmark_functions_edited/f5873.py | def f(file_name):
try:
with open(file_name) as f:
last_id = int(f.read())
return last_id
except IOError:
return 0
assert f(10) == 0 |
benchmark_functions_edited/f9818.py | def f(a):
n = len(a)
i = 0
while i < n:
j = a[i]
while 0 < j <= n and a[j-1] != j:
a[j-1], j = j, a[j-1]
i += 1
for i, x in enumerate(a):
if x != i+1:
return i+1
assert f(
[3, 4, -1, 1]) == 2 |
benchmark_functions_edited/f13438.py | def f(number):
set_bits_count = 0
while number:
set_bits_count += number & 1
number = number >> 1
return set_bits_count
assert f(3) == 2 |
benchmark_functions_edited/f1031.py | def f(n, minn, maxn):
return min(max(n, minn), maxn)
assert f(0, 2, 3) == 2 |
benchmark_functions_edited/f10310.py | def f(observation, reward, done, info):
if observation[0] >= 0.5:
reward += 100
elif observation[0] >= 0.25:
reward += 20
elif observation[0] >= 0.1:
reward += 10
return reward
assert f(
[0, 0], 0, False, {'other': 'info'}) == 0 |
benchmark_functions_edited/f6221.py | def f(n):
if n == 0:
return 0
elif n == 1:
return 1
return f(n-1) + f(n-2)
assert f(2) == 1 |
benchmark_functions_edited/f13755.py | def f(s1: str, s2: str) -> int:
table = [[0] * (len(s2) + 1) for _ in range(2)]
for x in s1:
for j, y in enumerate(s2, start=1):
if x == y:
table[1][j] = table[0][j - 1] + 1
elif table[1][j - 1] > table[0][j]:
table[1][j] = table[1][j - 1]
else:
table[1][j] = table[0][j]
return table[-1][-1]
assert f(b'ab', b'b') == 1 |
benchmark_functions_edited/f3709.py | def f(num):
if num >= 0:
return num
else:
return -num
assert f(-0) == 0 |
benchmark_functions_edited/f404.py | def f(ii):
return (2*ii+1)
assert f(1) == 3 |
benchmark_functions_edited/f6456.py | def f(LnL, k):
return 2*k-2*LnL
assert f(100, 100) == 0 |
benchmark_functions_edited/f11077.py | def f(action, a, b):
print(f'{action}ing a = {a} and b = {b}')
if action == 'add':
return a + b
elif action == 'subtract':
return a - b
elif action == 'multiply':
return a * b
elif action == 'divide':
return a / b
assert f('divide', 10, 10) == 1 |
benchmark_functions_edited/f4746.py | def f(letter):
letter = letter.upper()
score = ord(letter) - ord('A') + 1
return score
assert f('A') == 1 |
benchmark_functions_edited/f6671.py | def f(digits):
if type(digits) == type(""):
s = digits
else:
s = str(digits)
total = 0
for c in s:
total += int(c)
return total
assert f(123) == 6 |
benchmark_functions_edited/f11172.py | def f(graph, start):
total_bags = 0
queue = [(start, 1)]
while len(queue):
at, multiplier = queue.pop()
total_bags += multiplier
for next in graph[at].keys():
queue.append((next, multiplier * graph[at][next]))
return total_bags - 1
assert f(
{'faded blue': {}, 'dotted black': {}},
'faded blue'
) == 0 |
benchmark_functions_edited/f3735.py | def f(x, a, b, c):
return a * x ** 2 + b * x + c
assert f(0, 0, 0, 0) == 0 |
benchmark_functions_edited/f12119.py | def f(arr):
max_now = 0
max_next = 0
for i in arr:
max_next += i
max_now = max(max_next, max_now)
max_next = max(0, max_next)
return max_now
assert f([1, 2, 3, -1]) == 6 |
benchmark_functions_edited/f2750.py | def f(letter):
return ord(letter) - 97
assert f("a") == 0 |
benchmark_functions_edited/f2399.py | def f(text: str) -> int:
return len(text) - text.count(" ")
assert f("abc") == 3 |
benchmark_functions_edited/f7467.py | def f(root):
if not root:
return 0
left = f(root.left)
right = f(root.right)
if left > right:
return left + 1
else:
return right + 1
assert f(None) == 0 |
benchmark_functions_edited/f9510.py | def f(n):
try:
return float(n)
except ValueError:
raise ValueError("{0} is not a valid nodata value".format(n))
assert f('1') == 1 |
benchmark_functions_edited/f3953.py | def f(metadata):
if 'warnings' in metadata:
return len(metadata['warnings'])
return ''
assert f({'warnings': ['a', 'b']}) == 2 |
benchmark_functions_edited/f6053.py | def f(vals, freqs=None):
if freqs is None:
return sum(vals)/float(len(vals))
else:
return sum([v*i for v, i in zip(vals, freqs)])/sum(freqs)
assert f([1, 2, 3]) == 2 |
benchmark_functions_edited/f648.py | def f(match_to, compounds):
return (match_to + 1) ** (1 / compounds) - 1
assert f(1, 1) == 1 |
benchmark_functions_edited/f3145.py | def f(string: str):
try:
return string.upper()
except AttributeError:
return string
assert f(0) == 0 |
benchmark_functions_edited/f12584.py | def f(x):
"*** YOUR CODE HERE ***"
sum = 0
while x > 0:
sum += x % 10
x = x // 10
return sum
assert f(123) == 6 |
benchmark_functions_edited/f10439.py | def f(errors, func, *args, **kwargs):
try:
return func(*args, **kwargs)
except errors:
pass
assert f(TypeError, int, '1') == 1 |
benchmark_functions_edited/f2237.py | def f(numbers):
return sum([i ** 2 for i in numbers]) if len(numbers) > 0 else 0
assert f([0, 0, 1, 1]) == 2 |
benchmark_functions_edited/f6205.py | def f(a, b, c):
if a == 0:
raise ValueError("a is 0! [y = ax^2 + bx + c , a != 0]")
delta = b**2 - 4*a*c
return delta
assert f(2, -2, 0) == 4 |
benchmark_functions_edited/f3129.py | def f(array):
if len(array) == 1:
return array[0]
else:
return array[0] + f(array[1:])
assert f([1, 2, 3]) == 6 |
benchmark_functions_edited/f10125.py | def f(a):
word_list = a.split()
l_count = 0
for word in word_list:
if "l" in word:
l_count += 1
return l_count
assert f( '' ) == 0 |
benchmark_functions_edited/f14347.py | def f(houses, heaters):
import bisect
heaters.sort()
dis=[]
for h in houses:
i = bisect.bisect(heaters, h)
if i==0:
dis.append(heaters[0]-h)
if i==len(heaters):
dis.append(heaters[-1]-h)
else:
disr = heaters[i]-h
disl = h-heaters[i-1]
dis.append(min(disr, disl))
return min(dis)
assert f([1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6]) == 0 |
benchmark_functions_edited/f8783.py | def f(z, theta = -2):
return (z**(1 + theta)/(1 + theta))
assert f(0, 2) == 0 |
benchmark_functions_edited/f297.py | def f(n:int, a: int, b: int) -> int:
return n * n + a * n + b
assert f(0, 1, 2) == 2 |
benchmark_functions_edited/f10760.py | def f(coord_x, coord_y, grid):
try:
product = (grid[(coord_x, coord_y)] * grid[(coord_x, coord_y + 1)] *
grid[(coord_x, coord_y + 2)] * grid[(coord_x, coord_y + 3)])
except KeyError:
return 0
return product
assert f(0, 0, {
(0, 0): 1,
(0, 1): 2,
}) == 0 |
benchmark_functions_edited/f6112.py | def f(x):
epsilon = pow(1, -9)
if x >= 0 and x <= epsilon:
return 0
if x < 0 and -x <= epsilon:
return 0
return x
assert f(-0.00000000001) == 0 |
benchmark_functions_edited/f2568.py | def f(bin):
return sum(value*2**position for position, value in enumerate(reversed(bin)))
assert f( [0, 1] ) == 1 |
benchmark_functions_edited/f1917.py | def f(screen, wanted):
return list(screen.values()).count(wanted)
assert f(
{'a': 10, 'b': 20, 'c': 30}, 'd') == 0 |
benchmark_functions_edited/f1513.py | def f(number: int) -> int:
return max(1, number)
assert f(0.34) == 1 |
benchmark_functions_edited/f11783.py | def f(arr: list, k: int) -> int:
n = len(arr)
arr.append(k)
i = 0
while arr[i] != k:
i += 1
if i < n:
return i
else:
return -1
assert f([0], 0) == 0 |
benchmark_functions_edited/f5641.py | def f(n) -> int:
return int(n / 3)
assert f(5) == 1 |
benchmark_functions_edited/f10783.py | def f(size, kernel_size, stride):
return (size - (kernel_size - 1) - 1) // stride + 1
assert f(3, 1, 1) == 3 |
benchmark_functions_edited/f2736.py | def f(val, in_list):
try:
return in_list.index(val)
except ValueError:
return -1
assert f('a', ['b', 'a', 'c']) == 1 |
benchmark_functions_edited/f12557.py | def f(str_: str) -> int:
last_two_str = str_[-2:]
matches = list(
filter(
lambda x: x == last_two_str,
[
str_[i:i+2] for i in range(len(str_[:-2]))
]
)
)
return len(matches)
assert f(
"a"
) == 0 |
benchmark_functions_edited/f211.py | def f(valueList):
return sum(valueList) / float(len(valueList))
assert f( [1, 3, 5, 7, 9] ) == 5 |
benchmark_functions_edited/f12883.py | def f(i, string):
assert string[i] == '"'
i += 1
while string[i] != '"':
if string[i:i+2] == r'\"':
i += 2
else:
i += 1
if i >= len(string):
raise Exception(f'Could not parse {string}.')
return i
assert f(0, '"abc"def') == 4 |
benchmark_functions_edited/f5589.py | def f(p_str):
l_int = 0
try:
l_int = int(p_str, 16)
except:
l_int = 0
return l_int
assert f(b'00') == 0 |
benchmark_functions_edited/f8704.py | def f(current_index, id_):
if id_ in current_index:
idx = current_index[id_]
else:
idx = len(current_index)
current_index[id_] = idx
return idx
assert f(
{
"0000000000000000000000000000000000000000": 0,
"00000000000000000000000000000000000000001": 1
},
"000000000000000000000000000000000000000"
) == 2 |
benchmark_functions_edited/f5522.py | def f(x):
total = 0
for i in range(x + 1):
total += i
return total
assert f(1) == 1 |
benchmark_functions_edited/f8106.py | def f(key, env_keys):
if key in env_keys:
return env_keys[key]()
raise KeyError("No %s configuration found" % key)
assert f(2, {2: lambda: 2}) == 2 |
benchmark_functions_edited/f9852.py | def f(n):
GOLDEN_RATIO = (1 + 5**0.5) / 2
return int((GOLDEN_RATIO**n - (-GOLDEN_RATIO)**(-n)) / (5**0.5))
assert f(1) == 1 |
benchmark_functions_edited/f7300.py | def RK4 (model, v, dt):
k1 = model(v)
k2 = model(v + dt*k1/2.)
k3 = model(v + dt*k2/2.)
k4 = model(v + dt*k3)
return v + (1./6.)*dt*(k1 + 2*k2 + 2*k3 + k4)
assert f(lambda v: v, 0, 1) == 0 |
benchmark_functions_edited/f10241.py | def f(code):
return {
'Stub': 0,
'Start': 1,
'C': 2,
'B': 3,
'GA': 4,
'FA': 5,
}[code]
assert f('GA') == 4 |
benchmark_functions_edited/f9171.py | def f(user1, user2):
# Any verified user is ranked higher
if user1["is_verified"] and not user2["is_verified"]:
return -1
if user2["is_verified"] and not user1["is_verified"]:
return 1
return 0
assert f(
{
"display_name": "B",
"is_verified": False,
},
{
"display_name": "A",
"is_verified": True,
},
) == 1 |
benchmark_functions_edited/f7675.py | def f(array, item):
# loop over all array values until item is found
for index, value in enumerate(array):
if item == value:
return index # found
return None
assert f([3, 4, 1, 4, 9], 3) == 0 |
benchmark_functions_edited/f841.py | def f(byte):
return byte / (1024.0 ** 2)
assert f(0) == 0 |
benchmark_functions_edited/f10572.py | def f(*iterables):
result = 0
for iterable in iterables:
if iterable is not None:
result += sum(1 for element in iterable if element != 0)
return result
assert f([1, 2, 3]) == 3 |
benchmark_functions_edited/f9271.py | def f(first, second):
if first is possibly_equal or second is possibly_equal:
return possibly_equal #Propagate the possibilities
return first == second
assert f(1, 1.0) == 1 |
benchmark_functions_edited/f12372.py | def f(molecular_weight, slogp, num_rotatable_bonds):
n = 0
if molecular_weight < 250 or molecular_weight > 350:
n += 1
if slogp > 3.5:
n += 1
if num_rotatable_bonds > 7:
n += 1
return n
assert f(200, 4.0, 3) == 2 |
benchmark_functions_edited/f11363.py | def f(number):
i = 2
while i * i < number:
while number % i == 0:
number = number / i
i += 1
return number
assert f(5) == 5 |
benchmark_functions_edited/f13942.py | def f(input_bytes_1, input_bytes_2):
hamming_distance = 0
for b1, b2 in zip(input_bytes_1, input_bytes_2):
difference = b1 ^ b2
# Count the number of differences ('1's) and add to the hamming distance
hamming_distance += sum([1 for bit in bin(difference) if bit == '1'])
return hamming_distance
assert f(b"this is a test", b"this is a test") == 0 |
benchmark_functions_edited/f4450.py | def f(items):
if len(items) == 1:
return items[0]
prev_max = f(items[1:])
return prev_max if prev_max > items[0] else items[0]
assert f([1]) == 1 |
benchmark_functions_edited/f9091.py | def f(prev_emo, current_emo):
if prev_emo == current_emo:
return 0
elif current_emo > prev_emo:
return 1
elif current_emo < prev_emo:
return -1
assert f(0, 0) == 0 |
benchmark_functions_edited/f1837.py | def f(r):
return int(r.get("wedGelijk", 0))
assert f({}) == 0 |
benchmark_functions_edited/f2543.py | def f(seconds: int) -> int:
return seconds // (60 * 60 * 24 * 365)
assert f(31536000) == 1 |
benchmark_functions_edited/f7428.py | def f(i):
count = 0
while i:
i &= i - 1
count += 1
return count
assert f(0b10001) == 2 |
benchmark_functions_edited/f7719.py | def f(x, init, k):
for _ in range(k):
init = 0.5*init*(3 - x*init*init)
return init * x
assert f(0, 1, 4) == 0 |
benchmark_functions_edited/f14082.py | def f(d=0.0, u=2.0, s=1.0, h=1.0):
d = float(d)
u = float(u)
s = float(s)
m = (u - 2 * s + d)
if m == 0:
return h
if d <= s:
return h
else:
b = (h * (u - s)) / m
return b
assert f(0, 2, 1, 1) == 1 |
benchmark_functions_edited/f4970.py | def f(x, y):
if x > y:
return 1
elif x < y:
return -1
else:
return 0
assert f('b', 'b') == 0 |
benchmark_functions_edited/f11818.py | def f(idx, value, n):
### STUDENT CODE GOES HERE ###
if not value:
return 0
cur_row_idx = idx // n + 1
cur_col_idx = idx % n + 1
goal_row_idx = value // n + 1
goal_col_idx = value % n + 1
return abs(cur_row_idx - goal_row_idx) + abs(cur_col_idx - goal_col_idx)
assert f(0, 1, 1) == 1 |
benchmark_functions_edited/f13678.py | def f(hexvalue):
vlength = len(hexvalue)
if vlength >= 3:
temp = round(int.from_bytes(hexvalue[2:4], "little", signed=False) * 0.01, 2)
humi = round(int.from_bytes(hexvalue[6:8], "little", signed=False) * 0.01, 2)
print("Temperature:", temp, "Humidity:", humi)
return 1
print("MsgLength:", vlength, "HexValue:", hexvalue.hex())
return None
assert f(b"01010203040506070809") == 1 |
benchmark_functions_edited/f8998.py | def f(l):
if isinstance(l, list):
return f(l[0])
else:
return l
assert f([1, None]) == 1 |
benchmark_functions_edited/f1113.py | def f(first, second, ratio):
return first * (1 - ratio) + second * ratio
assert f(1, 1, 0.5) == 1 |
benchmark_functions_edited/f6328.py | def f(val, n):
return (val % 0x100000000) >> n
assert f(2, 10) == 0 |
benchmark_functions_edited/f1586.py | def f(dateData):
return dateData / 60 / 60
assert f(3600) == 1 |
benchmark_functions_edited/f13149.py | def f(metric_fn, prediction, ground_truths):
scores_for_ground_truths = []
for ground_truth in ground_truths:
score = metric_fn(prediction, ground_truth)
scores_for_ground_truths.append(score)
return max(scores_for_ground_truths)
assert f(lambda p, a: 0, 2, [1, 2, 3]) == 0 |
benchmark_functions_edited/f4699.py | def f(l):
lg = len(l)
if lg > 0:
return sum(l) / lg
else:
return sum(l)
assert f(list()) == 0 |
benchmark_functions_edited/f2723.py | def f(vec1,vec2):
return vec1[0]*vec2[0]-vec1[1]*vec2[1]-vec1[2]*vec2[2]-vec1[3]*vec2[3]
assert f( (0,0,0,0), (1,2,3,4) ) == 0 |
benchmark_functions_edited/f5884.py | def f( op, A ):
if type(A) is list:
return [ f( op, a ) for a in A ]
else:
return op( A )
assert f( lambda x: 2*x, 3 ) == 6 |
benchmark_functions_edited/f8530.py | def f(total_number, step_size):
return (total_number - 1) // step_size + 1
assert f(10, 6) == 2 |
benchmark_functions_edited/f12936.py | def f(n):
if abs(n) < 10:
return n
if n < 0:
n = n * -1
counts = [0] * 10
while n != 0:
digit = n % 10
counts[digit] += 1
n = n // 10
max_val = max(counts)
return max([i for i, j in enumerate(counts) if j == max_val])
assert f(10) == 1 |
benchmark_functions_edited/f9357.py | def f(a,b,m=1):
a1 = a%m
p = 1
while b > 0:
if b%2 ==1:
p *= a1
p = p%m
b /= 2
a1 = (a1 * a1)%m
return p
assert f(5, 3, 2) == 1 |
benchmark_functions_edited/f2343.py | def f(x):
if x < 0:
return -1
elif x > 0:
return 1
else:
return 0
assert f(False) == 0 |
benchmark_functions_edited/f10150.py | def f(value: str) -> int:
try:
float_number = float(value)
except ValueError:
return 0
else:
if float_number.is_integer():
return 2
return 1
assert f(1.1) == 1 |
benchmark_functions_edited/f13556.py | def f(random_edge, max_edge, vertex_degree):
threshold = min(random_edge, abs(max_edge - vertex_degree))
return threshold
assert f(3, 10, 1) == 3 |
benchmark_functions_edited/f7034.py | def f(x, y):
return sum(_x * _y for _x, _y in zip(x, y))
assert f([1], [2]) == 2 |
benchmark_functions_edited/f12556.py | def f(text: str, sep: str='/') -> int:
segments = [p for p in text.split(sep) if p]
return len(segments) - len(set(segments))
assert f(
"/foo/"
) == 0 |
benchmark_functions_edited/f14151.py | def f(x):
#Initialisations
digit_sum = 0
x = abs(x)
while x >= 10:
digit = x % 10 #Gives the smallest digit of `x`
digit_sum += digit
x = x//10
#`x` < 10:
digit_sum += x
return digit_sum
assert f(1) == 1 |
benchmark_functions_edited/f10445.py | def f(user_input):
try:
return eval(user_input.replace('^', "**"))
except:
return 'Please check your syntax'
assert f('1.5 - 1.5') == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.