file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f10076.py | def f(command_str, end, start = 1):
command_int = int(command_str.strip())
if command_int >= start and command_int <= end:
return command_int
else:
raise ValueError
assert f(
'1', 10) == 1 |
benchmark_functions_edited/f11697.py | def f(grid, row, col):
rows = range(max(0, row - 1), min(len(grid) - 1, row + 1) + 1)
cols = range(max(0, col - 1), min(len(grid[0]) - 1, col + 1) + 1)
return len([1 for x in cols for y in rows
if grid[y][x] == 1 and (x, y) != (col, row)])
assert f(
[[0, 0, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0]], 2, 2) == 2 |
benchmark_functions_edited/f7776.py | def f(R, Ni):
k = sum(j << i for i, j in enumerate(Ni[::-1]))
if R & (1 << k):
return 1
else:
return 0
assert f(0, [0, 0, 0]) == 0 |
benchmark_functions_edited/f11750.py | def f(a,b):
try:
aInt = isinstance(a,int)
bInt = isinstance(b,int)
if not (aInt and bInt):
raise TypeError("Argument of GCD is not integer.")
except:
raise
else:
if a==0:
return b
if b==0:
return a
A = max(abs(a),abs(b))
B = min(abs(a),abs(b))
while B!=0:
tmp = B
B = A%B
A = tmp
return A
assert f(-2,3) == 1 |
benchmark_functions_edited/f3620.py | def f(n): #converts the incoming character into decimal
return int(n,2)
assert f(bin(2)) == 2 |
benchmark_functions_edited/f13555.py | def f(in_list):
# Deep copy of in_list
if type(in_list) is dict:
mod_list = list(in_list.values())
else:
mod_list = list(in_list)
count = 0
while mod_list:
entry = mod_list.pop()
if isinstance(entry, list):
mod_list += entry
else:
count += 1
return count
assert f([[[1, 2], [3]], 4, 5, ['hello']]) == 6 |
benchmark_functions_edited/f9197.py | def f(nums):
result = 0
if len(nums) != 0:
for number in nums:
result = result ^ number
return result
assert f(list([4, 1, 2, 1, 2])) == 4 |
benchmark_functions_edited/f11323.py | def f(train_step):
x=float(train_step)
if x==0:
return 0
x=x/5
return float(x)/(1+float(x))
assert f(float('0')) == 0 |
benchmark_functions_edited/f8166.py | def f(x):
assert len(x) > 0
if len(x) == 1:
m = str(x[0])
else:
m = str(min(map(lambda x,y:y-x, x[:-1], x[1:])))
if "." in m:
return len(m) - m.index(".") - 1
else:
return 0
assert f([10000.0, 10001.0, 10002.0, 10003.0, 10004.0, 10005.0]) == 1 |
benchmark_functions_edited/f5946.py | def f(seat_map):
occupied = 0
for state in seat_map.values():
if state == "#":
occupied += 1
return occupied
assert f(
{
(0, 0): "L",
(1, 1): "L",
(2, 2): "L",
(3, 3): "L",
(4, 4): "L",
}
) == 0 |
benchmark_functions_edited/f10865.py | def f(n):
if n <= 3:
return n
return f(n-1) + 2*f(n-2) + 3*f(n-3)
assert f(2) == 2 |
benchmark_functions_edited/f7579.py | def f(lst):
try:
return sorted(set(range(lst[0], lst[-1])) - set(lst))[0]
except:
return max(lst) + 1
assert f([0, 0, 0, 0]) == 1 |
benchmark_functions_edited/f3835.py | def f(my_list):
import operator
index, value = max(enumerate(my_list), key=operator.itemgetter(1))
return index
assert f(
[3, 4, 1, 200]) == 3 |
benchmark_functions_edited/f10391.py | def f(input_id):
if len(input_id) != 4:
# if the id input is not 4 digits
return 1
elif input_id.isdigit():
# if the input id is a number
return 0
else:
# if not a number
return 2
assert f('12345') == 1 |
benchmark_functions_edited/f10005.py | def f(n):
# Accumulator
v = 0 # call this 1/0 for today
for i in range(1,n+1):
v = v + 1.0 / i
return v
assert f(0) == 0 |
benchmark_functions_edited/f5586.py | def f(bytearr):
num_le = 0
for i in range(len(bytearr)):
num_le += bytearr[i] * pow(256, i)
return num_le
assert f(bytearray([])) == 0 |
benchmark_functions_edited/f2265.py | def f(x):
i = 0
while x > (1 << i):
i += 1
return i
assert f(16) == 4 |
benchmark_functions_edited/f9515.py | def f(buffer):
result = 0
idx = 0
byte = 0x80
while byte & 0x80:
byte = buffer[idx]
result += (byte & 0x7F) << (7 * idx)
idx += 1
return result
assert f(b"\x01") == 1 |
benchmark_functions_edited/f2066.py | def f(x, i):
return ((x << i) | ((x & 0xffffffff) >> (32 - i))) & 0xffffffff
assert f(0, 8) == 0 |
benchmark_functions_edited/f8668.py | def f(obj):
# in VBA, Null/None is equivalent to 0
if ((obj is None) or (obj == "NULL")):
return 0
else:
return int(obj)
assert f(None) == 0 |
benchmark_functions_edited/f8991.py | def f(start, end):
return sum(abs(a - b) for a, b in zip(start, end))
assert f(
(0, 1),
(1, 1)
) == 1 |
benchmark_functions_edited/f7796.py | def f(state, best_angle, angle_reward, angle_penalty):
if state[-1] == best_angle: # Reward if bill at best angle
reward = angle_reward
else:
reward = angle_penalty
return reward
assert f(
[1, 1, 1, 1, 1, 1],
0,
10,
1) == 1 |
benchmark_functions_edited/f9297.py | def best_known_date_variation (date_var_1digit):
if date_var_1digit in ['A', 'J']:
return -1
elif date_var_1digit in ['1', '2']:
return int (date_var_1digit)
else:
return 0
assert f('1') == 1 |
benchmark_functions_edited/f4955.py | def f(x, x0, x1, y0, y1):
return y0 + (x - x0) * ((y1 - y0) / (x1 - x0))
assert f(1, 0, 1, 0, 1) == 1 |
benchmark_functions_edited/f12989.py | def f(features, leak=0.2):
f1 = 0.5 * (1 + leak)
f2 = 0.5 * (1 - leak)
return f1 * features + f2 * abs(features)
assert f(2) == 2 |
benchmark_functions_edited/f8422.py | def f(boolean):
_result = 0
if boolean:
_result = 1
return _result
assert f(1234567) == 1 |
benchmark_functions_edited/f5504.py | def f(s_val):
try:
return float(s_val)
except ValueError:
return s_val
assert f('1') == 1 |
benchmark_functions_edited/f10699.py | def f(num, smallest, largest):
return max(smallest, min(num, largest))
assert f(4, 1, 3) == 3 |
benchmark_functions_edited/f5813.py | def f(town):
return town.replace(' ', '')[::2].count('O')
assert f('O O O O O O O O') == 4 |
benchmark_functions_edited/f2396.py | def f(num):
if int(num) == num:
return int(num)
else:
return num
assert f(4) == 4 |
benchmark_functions_edited/f13890.py | def f(output):
letters_to_len = dict(cf=1, bcdf=4, acf=7, abcdefg=8)
fixed_len_to_digit = {len(k): v for k, v in letters_to_len.items()}
return 1 if len(output) in fixed_len_to_digit else 0
assert f(frozenset("cf")) == 1 |
benchmark_functions_edited/f1974.py | def f(lst1,lst2):
for i in lst1:
if not i in lst2:
return 0
return 1
assert f(["hi", "hello"], []) == 0 |
benchmark_functions_edited/f11043.py | def f(iterable, predicate=lambda x: True):
return next(x for x in iterable if predicate(x))
assert f(range(10), lambda x: x > 5) == 6 |
benchmark_functions_edited/f10045.py | def f(baseline, key):
if key in baseline:
return 0 if baseline[key] is None else baseline[key]
assert f(
{'a': 1, 'b': 2, 'c': None},
'b'
) == 2 |
benchmark_functions_edited/f7189.py | def f(v1,v2):
p1 = v1 is None
p2 = v2 is None
if p1 and p2:
return None
elif p1:
return -v2
elif p2:
return v1
else:
return v1 - v2
assert f(1,None) == 1 |
benchmark_functions_edited/f2117.py | def f(x):
if x == 10:
return 7
else:
return x
assert f(7) == 7 |
benchmark_functions_edited/f13226.py | def f(item, klass, arg=None):
if not arg:
return klass(item)
kwarg = {arg: item} # kwarg dict
return klass(**kwarg)
assert f("1", int) == 1 |
benchmark_functions_edited/f131.py | def f(x):
return (3*x+2)*x+1
assert f(1) == 6 |
benchmark_functions_edited/f5460.py | def f(prices):
total = 0
for i in range(len(prices) - 1):
total += max(prices[i + 1] - prices[i], 0)
return total
assert f( [7,1,5,3,6,4] ) == 7 |
benchmark_functions_edited/f12963.py | def f(num: int) -> int:
if num == 0:
return 0
fib = [0, 1]
i = 2
# appends fib numbers until fib[-1] == num or > num
# if fib[-1] > num it means that first number of original sequnce
# data isn't belong to fib nums
while fib[-1] < num:
fib.append(fib[i - 1] + fib[i - 2])
i += 1
return fib[-1]
assert f(5) == 5 |
benchmark_functions_edited/f14117.py | def f(ra, elevation):
return (0.75 + (2 * 10 ** -5) * elevation) * ra
assert f(0, 0) == 0 |
benchmark_functions_edited/f3297.py | def f(sequence):
p= 1
for item in sequence:
p *= item
return p
assert f([1]) == 1 |
benchmark_functions_edited/f13026.py | def f(n, N):
mask = 2 ** (N) - 1
fock_rep = n ^ (n << 1)
#print(f'{n} = {n:b}: {fock_rep:04b} {mask:04b}')
return fock_rep & mask
assert f(3, 2) == 1 |
benchmark_functions_edited/f4108.py | def f(s, d):
if s is None:
return d
return s
assert f(0, 2) == 0 |
benchmark_functions_edited/f13056.py | def f(pattern: str):
count = 0
for left, right in zip(pattern[:-1], pattern[1:]):
if left != right:
count += 1
return count
assert f(
"iiiiiiiii") == 0 |
benchmark_functions_edited/f6246.py | def f(dictionary, key):
value = 0
try:
value = dictionary[str(key)]
except KeyError:
pass
return value
assert f({}, 0) == 0 |
benchmark_functions_edited/f8823.py | def f(s):
try:
return int(s)
except ValueError:
return float(s)
assert f(5) == 5 |
benchmark_functions_edited/f6052.py | def f(v1, v2):
return sum(( (abs(v[0] - v[1]) / (abs(v[0] + abs(v[1])))) for v in zip(v1, v2)))
assert f( (1.0, 1.0), (1.0, 1.0) ) == 0 |
benchmark_functions_edited/f330.py | def f(values):
return sum(values) / len(values)
assert f([1, 2, 3]) == 2 |
benchmark_functions_edited/f7643.py | def f(guess, answer):
time = 0
for i in range(0,3):
if guess[i] == answer[i]:
time+=1
return time
assert f( [2, 2, 3], [3, 2, 1]) == 1 |
benchmark_functions_edited/f11387.py | def f(string):
last_seen = {}
start = 0 # for single char inputs
max_length = 0
for i, char in enumerate(string):
if char in last_seen:
start = max(start, last_seen[char] + 1)
last_seen[char] = i
max_length = max(max_length, i - start + 1)
return max_length
assert f("ABCD") == 4 |
benchmark_functions_edited/f12847.py | def f(literal):
if(isinstance(literal, str) and literal.startswith('#')):
end = literal.find("(")
if(end == -1):
end = literal.find( " ")
if(end == -1):
end = len(literal)
return int(literal[1:end])
if(isinstance(literal, int)):
return literal
return None
assert f(7) == 7 |
benchmark_functions_edited/f12212.py | def f(nums, target):
# Simply lower_bound
count = len(nums)
first = 0
while count > 0:
half = count // 2
mid = first + half
if nums[mid] < target:
first = mid + 1
count -= half + 1
else:
count = half
return first
assert f(
[2], 1) == 0 |
benchmark_functions_edited/f11257.py | def f(x):
result = 0
while x != 0:
temp = result * 10 + x % 10
print('temp is ' + str(temp))
print(str(temp / 10))
if temp // 10 != result:
print("return")
return 0
x //= 10
print(x)
result = temp
return result
assert f(1000000000) == 1 |
benchmark_functions_edited/f14125.py | def f(die_value,
final_dice,
scorepad,
):
if die_value in range(1, 7):
return final_dice.count(die_value) * die_value
else:
return 0
assert f(1, [1, 1, 1], []) == 3 |
benchmark_functions_edited/f13770.py | def f(resources, time_in_queue=0):
return max(0, sum(resources.values()) - time_in_queue/600)
assert f(dict()) == 0 |
benchmark_functions_edited/f9808.py | def f(x1, y1, x2, y2, x, y):
px = x2 - x1
py = y2 - y1
dd = px * px + py * py
return ((x - x1) * px + (y - y1) * py) / max(1e-9, float(dd))
assert f(0, 0, 100, 100, 100, 100) == 1 |
benchmark_functions_edited/f12592.py | def f(patterns):
return len([o_m for pat in patterns for occ in pat for o_m in occ])
assert f([]) == 0 |
benchmark_functions_edited/f5529.py | def f(xycoord, dimensions):
return xycoord[0] + (dimensions[0] * xycoord[1])
assert f( (0, 0), (10, 10) ) == 0 |
benchmark_functions_edited/f354.py | def f(x):
try: return int(x)
except: return 0
assert f('0.0') == 0 |
benchmark_functions_edited/f1687.py | def f(q):
return (sum(e*e for e in q))
assert f( (1,0,0,0) ) == 1 |
benchmark_functions_edited/f7024.py | def f(s, ret = 0):
if not isinstance(s, str):
return int(s)
elif s:
if s[0] in "+-":
ts = s[1:]
else:
ts = s
if ts and all([_ in "0123456789" for _ in ts]):
return int(s)
return ret
assert f(" foo", 1) == 1 |
benchmark_functions_edited/f5302.py | def f(intensity, efficiency, surface):
lumens = intensity * surface
return lumens / (efficiency * 683)
assert f(0, 1, 1) == 0 |
benchmark_functions_edited/f9851.py | def f(mode):
if mode in ['tram', 'trolleyBus']:
return 0
elif mode in ['underground', 'metro']:
return 1
elif mode == 'rail':
return 2
elif mode in ['bus', 'coach']:
return 3
elif mode == 'ferry':
return 4
assert f('coach') == 3 |
benchmark_functions_edited/f10524.py | def f(s, l, r):
if r == l:
return 1
if r-l == 1 and s[l] == s[r]:
return 2
if r-l == 2 and s[l] == s[r]:
return 3
if s[l] == s[r]:
return f(s, l+1, r-1) + 2
return max(
f(s, l, r-1), f(s, l+1, r)
)
assert f(
'T', 0, 0
) == 1 |
benchmark_functions_edited/f13628.py | def f(cargo: str) -> int:
dinero = 0
cargo = cargo.capitalize()
if cargo == "Externo":
dinero = 50
elif cargo == "Ejecutivo":
dinero = 90
elif cargo == "Jefe":
dinero = 100
return dinero
assert f("Interno") == 0 |
benchmark_functions_edited/f5391.py | def f(numerator: int, denominator: int) -> int:
while numerator > denominator:
numerator -= denominator
return numerator
assert f(3, 2) == 1 |
benchmark_functions_edited/f1276.py | def f(sentence):
return sum(1 for c in sentence if c != ' ')
assert f(" ") == 0 |
benchmark_functions_edited/f11020.py | def f(cand_d, ref_ds):
count = 0
for m in cand_d.keys():
m_w = cand_d[m]
m_max = 0
for ref in ref_ds:
if m in ref:
m_max = max(m_max, ref[m])
m_w = min(m_w, m_max)
count += m_w
return count
assert f(dict(), [{1: 0}, {1: 0}]) == 0 |
benchmark_functions_edited/f356.py | def f(a: int, b: int) -> int:
return -(-a // b)
assert f(6, 2) == 3 |
benchmark_functions_edited/f4517.py | def f(track, muteFlag):
try:
muteFlag |= 1 << (track)
return muteFlag
except:
#bad argument
return muteFlag
assert f(2, 0) == 4 |
benchmark_functions_edited/f7925.py | def f(num_tiles):
num_partitions = max(min(num_tiles / 140, 128), 8)
return num_partitions
assert f(45) == 8 |
benchmark_functions_edited/f9269.py | def f(data):
no_of_projects = 0
for org in data.keys():
no_of_projects += len(data[org])
return no_of_projects
assert f({'a': [1, 2], 'b': [3]}) == 3 |
benchmark_functions_edited/f10626.py | def f(GaDe, GaVi, GaDiCoi):
# try/except
try:
return (GaVi/GaDe)/GaDiCoi
except Exception as e:
raise
assert f(1, 1, 1) == 1 |
benchmark_functions_edited/f9669.py | def f(myList):
voteDict = {}
for vote in myList:
if voteDict.get(vote) == None:
voteDict[vote] = 1
else:
voteDict[vote] += 1
maxVote = 0
for key, value in voteDict.items():
if value > maxVote:
maxVote = key
return maxVote
assert f( [3, 2, 3] ) == 3 |
benchmark_functions_edited/f9708.py | def f(e, m):
x1, y1, x2, y2 = 1, 0, 0, 1
a, b = e, m
while b > 0:
q, r = divmod(a, b)
xn, yn = x1 - q * x2, y1 - q * y2
a, b, x1, y1, x2, y2 = b, r, x2, y2, xn, yn
return x1 % m
assert f(0, 13) == 0 |
benchmark_functions_edited/f3568.py | def f(x):
print("DEBUG: the value of x is", x, "in the function debugsquare")
return x * x
assert f(-2) == 4 |
benchmark_functions_edited/f1534.py | def f(board):
return len([ch for ch in board if ch == 'o'])
assert f(list("o")) == 1 |
benchmark_functions_edited/f12735.py | def f(schedule_array, sample_val):
for i, each_array in enumerate(schedule_array):
if each_array[0] <= sample_val <= each_array[1]:
return i
else:
continue
assert f(
[[250, 300], [500, 550], [600, 650]],
600
) == 2 |
benchmark_functions_edited/f2637.py | def f(f, x):
h = 1e-4 # rule of thumb
return (f(x + h) - f(x - h)) / (2 * h)
assert f(lambda x: x**2, 0) == 0 |
benchmark_functions_edited/f13521.py | def f(n_processes):
from multiprocessing import cpu_count
available_processors = cpu_count()
n_processes = n_processes % (available_processors+1)
if n_processes == 0:
n_processes = 1
print('WARNING: Found n_processes = 0. Falling back to default single-threaded execution (n_processes = 1).')
return n_processes
assert f(6) == 6 |
benchmark_functions_edited/f2417.py | def f(count, a:tuple):
if len(a[0]) == len(a[1]):
return count + 1
return count
assert f(0, (tuple(), tuple())) == 1 |
benchmark_functions_edited/f9641.py | def f(limit):
return sum(x for x in range(limit) if x % 3 == 0 or x % 5 == 0)
assert f(1) == 0 |
benchmark_functions_edited/f5777.py | def f(dependencies):
return len([i for i in dependencies if not i.strip().startswith("#")])
assert f([]) == 0 |
benchmark_functions_edited/f3994.py | def f(n,B=10):
n = abs(n)
ctr = 0
while n != 0:
n //= B
ctr += 1
return ctr
assert f(101) == 3 |
benchmark_functions_edited/f2649.py | def f(individual):
return pow(individual[0], 2) + pow(individual[1], 3)
assert f( [0, 0] ) == 0 |
benchmark_functions_edited/f2608.py | def f(bits):
val = 0
for bit in bits:
val = (val << 1) | bit
return val
assert f([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0 |
benchmark_functions_edited/f5099.py | def f(op):
if op[1] == "I":
return len(op[2])
elif op[1] == "S":
return 0
elif op[1] == "D":
return -op[2]
assert f(("", "S", "AC")) == 0 |
benchmark_functions_edited/f13465.py | def f(m, n):
if m > n:
m, n = n, m
large, small = 1, 0
# a running sum for Fibbo m ~ n + 1
running = 0
# dynamically update the two variables
for i in range(n):
large, small = large + small, large
# note that (i + 1) -> small is basically mapping m -> F[m]
if m <= i + 1 <= n:
running += small
return running
assert f(3, 3) == 2 |
benchmark_functions_edited/f3102.py | def f(j, min):
if j < min:
j %= min
return j
assert f(1, 5) == 1 |
benchmark_functions_edited/f6698.py | def f(n, x):
if(n == 0):
return 1 # P0 = 1
elif(n == 1):
return x # P1 = x
else:
return (((2 * n)-1)*x * f(n-1, x)-(n-1) * f(n-2, x))/float(n)
assert f(1, 0) == 0 |
benchmark_functions_edited/f6439.py | def f(box):
if box > 1:
box -= 1
return box
assert f(0) == 0 |
benchmark_functions_edited/f12911.py | def f(a, b):
if 'priority' not in a[1] and 'priority' not in b[1]:
return 0
elif 'priority' in a[1] and 'priority' not in b[1]:
return -1
elif 'priority' in b[1] and 'priority' not in a[1]:
return +1
elif a[1]['priority'] > b[1]['priority']:
return +1
elif a[1]['priority'] == b[1]['priority']:
return 0
else:
return -1
assert f(
('A', {'priority': 2}),
('B', {'priority': 2}),
) == 0 |
benchmark_functions_edited/f3144.py | def f(n):
import math
return math.log(n, 2)
assert f(16) == 4 |
benchmark_functions_edited/f2036.py | def f(point):
return int(abs(point.real) + abs(point.imag))
assert f(3 - 5j) == 8 |
benchmark_functions_edited/f11548.py | def f(distance: float) -> int:
if distance < 2:
return 1
else:
return 0
assert f(1.99) == 1 |
benchmark_functions_edited/f4406.py | def f(content, substring):
index = content.index(substring)
return content[:index].count('\n') + 1
assert f(
"First\nSecond\nThird",
"First\nSecond\nThird"
) == 1 |
benchmark_functions_edited/f9629.py | def f(text):
if len(text.split(" ")) > 1 and len(text.split()) > 0:
return len(set(text.split())) / len(text.split())
else:
return 0
assert f("") == 0 |
benchmark_functions_edited/f10485.py | def f(x, y):
return (int(1000000000 * x) - int(1000000000 * y)) / 1000000000
assert f(0.25, 0.25) == 0 |
benchmark_functions_edited/f312.py | def f(a, b):
return int(a // b + bool(a % b))
assert f(-10.5, -5.5) == 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.