file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f721.py
|
def f(L):
#M : list[int]
M = L + []
M.append(2)
return 0
assert f([1, 2, 3]) == 0
|
benchmark_functions_edited/f12185.py
|
def f(coins, value):
length = len(coins)
# pylint: disable=misplaced-comparison-constant
if 0 == value:
return 1
if 0 > value:
return 0
if 0 >= length and 1 <= value:
return 0
return f(coins, value) + f(coins, value-coins[length-1])
assert f([], 10) == 0
|
benchmark_functions_edited/f1972.py
|
def f(n):
return sum(1 for d in n if int(d) != 0 and int(n) % int(d) == 0)
assert f([]) == 0
|
benchmark_functions_edited/f4528.py
|
def f(x, x0, x1, y0, y1):
return y0 + float(y1 - y0) * (float(x - x0) / float(x1 - x0))
assert f(0, 0, 100, 0, 100) == 0
|
benchmark_functions_edited/f8165.py
|
def f(a):
b = list(a) # Make a copy of a.
b.sort()
length = len(b)
if length % 2 == 1:
return b[length//2]
else:
return float(b[length//2 - 1] + b[length//2]) / 2.0
assert f([3, 1, 2, 5, 4]) == 3
|
benchmark_functions_edited/f7301.py
|
def clip (x, min, max):
if (x < min): return min
if (x > max): return max
return x
assert f(2, 3, 4) == 3
|
benchmark_functions_edited/f9305.py
|
def f(x,y,u):
cond = (x >= u)
tmp = cond * (y + u) + (1-cond) * x
output = tmp
return output
assert f(0,0,2) == 0
|
benchmark_functions_edited/f7042.py
|
def f(list, predicate):
for i, x in enumerate(list):
if predicate(x):
return i
return -1
assert f(list(range(2)), lambda x: x == 1) == 1
|
benchmark_functions_edited/f10851.py
|
def f(l, item):
for i in range(len(l)):
if item == l[i]:
return i
return -1
assert f(list("abcdefghijklmnopqrstuvwxyz"), "b") == 1
|
benchmark_functions_edited/f1131.py
|
def f(a, b):
if b == 0:
return a
return f(b, a % b)
assert f(2, 4) == 2
|
benchmark_functions_edited/f9007.py
|
def f(lon):
from math import floor
return floor((lon + 180) / 6) + 1
assert f(-179.99999999) == 1
|
benchmark_functions_edited/f2700.py
|
def f(byte, ii):
return (byte >> (7 - ii)) & 1
assert f(0b11010100, 4) == 0
|
benchmark_functions_edited/f490.py
|
def f(t):
return 1.0 - 0.1*t
assert f(0) == 1
|
benchmark_functions_edited/f12289.py
|
def f(tscores):
score = 0
for i in range(0,len(tscores)):
score += tscores[i-1]
score = score/len(tscores)
return score
assert f([1,1,1,1]) == 1
|
benchmark_functions_edited/f6168.py
|
def f(town):
return town.replace(' ', '')[::2].count('O')
assert f('~O~O~O~OP~O~OO~') == 2
|
benchmark_functions_edited/f768.py
|
def f(dic):
return dic["value"]
assert f(
{'value': 3}
) == 3
|
benchmark_functions_edited/f3774.py
|
def f(p, l):
pos = l.index(p)
if pos - 1 < 0:
return l[-1]
else:
return l[pos - 1]
assert f(3, [3, 2, 1]) == 1
|
benchmark_functions_edited/f5418.py
|
def f(numbers, as_decimal=False):
if sum([float(x) for x in numbers]) > 0:
m = (sum(numbers)) / max(len(numbers), 1)
return m
else:
return 0
assert f([1, 1]) == 1
|
benchmark_functions_edited/f507.py
|
def f(a, b):
return (a + b - 1) // b
assert f(8, 3) == 3
|
benchmark_functions_edited/f3074.py
|
def f(b, e, m):
if e == 0:
return 1
t = f(b, e / 2, m)**2 % m
if e & 1:
t = (t * b) % m
return t
assert f(2, 0, 3) == 1
|
benchmark_functions_edited/f13197.py
|
def f(l, val, after_index=None):
if after_index is None:
after_index = -1
return after_index + 1 + l[after_index+1:].index(val)
assert f(list('12345'), '4') == 3
|
benchmark_functions_edited/f12878.py
|
def f(n):
# Confirm that the parameter is a positive number
if n < 0:
num = n*-1
else:
num = n
# Base case, the first digit is compared
if num//10 == 0:
return num%10
# Compare the digits, return the biggest one
else:
return max(num%10, f(num//10))
assert f(6) == 6
|
benchmark_functions_edited/f347.py
|
def f(v):
return sum(v) / len(v)
assert f([1, 2, 3, 4, 5, 6, 7]) == 4
|
benchmark_functions_edited/f5855.py
|
def f(args):
x = args[0]
y = args[1]
return (x + 2 * y - 7) ** 2 + (2 * x + y - 5) ** 2
assert f([1.0, 3.0]) == 0
|
benchmark_functions_edited/f2676.py
|
def f(xs):
if not xs:
return None
return xs[0]
assert f(range(1)) == 0
|
benchmark_functions_edited/f2268.py
|
def f(cA, cB):
if cA == "I":
return cB
return cA
assert f(1, 1) == 1
|
benchmark_functions_edited/f6532.py
|
def f(values):
dr = 0
for i in range(len(values)-1):
for j in range(i+1,len(values)):
if values[i] > values[j]:
dr += 1
return dr
assert f(
[10, 10, 20, 30, 40]) == 0
|
benchmark_functions_edited/f12508.py
|
def f(npix):
test = npix - 1
nrings = 1
while (test - 6 * nrings) >= 0:
test -= 6 * nrings
nrings += 1
if test != 0:
raise RuntimeError(
"{} is not a valid number of pixels for a hexagonal layout".format(npix)
)
return nrings
assert f(7) == 2
|
benchmark_functions_edited/f5550.py
|
def f(obj):
try:
return obj.item()
except (ValueError, AttributeError):
return obj
assert f(3) == 3
|
benchmark_functions_edited/f6364.py
|
def f(a):
if '__len__' in dir(a):
return len(a)
else:
return 1
assert f('0') == 1
|
benchmark_functions_edited/f235.py
|
def f(x, y):
return 1 if x == y else -1
assert f(False, False) == 1
|
benchmark_functions_edited/f8761.py
|
def f(batch, input_id=None):
if isinstance(batch, dict) or isinstance(batch, list):
assert input_id is not None
return batch[input_id]
else:
return batch
assert f(0) == 0
|
benchmark_functions_edited/f9495.py
|
def f(value, bins):
for i in range(0, len(bins)):
if bins[i][0] <= value < bins[i][1]:
return i
return -1
assert f(0, [(0, 10), (10, 20), (20, 30)]) == 0
|
benchmark_functions_edited/f1447.py
|
def f(n):
return 2**(n-1).bit_length()
assert f(7) == 8
|
benchmark_functions_edited/f10385.py
|
def f(n, l):
occurences = {}
count = 0
for i in l:
if i in occurences.keys():
occurences[i] += 1
else:
occurences[i] = 1
for i in occurences.keys():
if i + n in occurences.keys():
c1 = occurences[i]
c2 = occurences[i+n]
count += c1 * c2
return count
assert f(1, [1, 3]) == 0
|
benchmark_functions_edited/f8056.py
|
def f(program, state):
if isinstance(program, tuple):
return program[0](program[1], state)
elif isinstance(program, float):
return program # numbers are self evaluating
else:
return state[program]
assert f('x', {'x': 2}) == 2
|
benchmark_functions_edited/f4342.py
|
def f(n_seats, aw2_capacity, target_density):
return (aw2_capacity - n_seats) * target_density / 4 + n_seats
assert f(2, 2, 0.3) == 2
|
benchmark_functions_edited/f6622.py
|
def f(ixs):
return sum(range(1, sum((i > 0 for i in ixs)) + 1))
assert f([]) == 0
|
benchmark_functions_edited/f13172.py
|
def f(x):
# type: (int) -> int
s = 1
while x & (x + 1) != 0:
x |= x >> s
s *= 2
return x + 1
assert f(6) == 8
|
benchmark_functions_edited/f6717.py
|
def f(condition, then_expression, else_expression):
if condition:
output = then_expression
else:
output = else_expression
return output
assert f(1 == 1 and 1 == 1, 1, 0) == 1
|
benchmark_functions_edited/f10802.py
|
def f(text_list):
max_length = 0
for text in text_list:
if len(text) > max_length:
max_length = len(text)
return max_length
assert f(['', '']) == 0
|
benchmark_functions_edited/f8757.py
|
def f(integer_string, strict=False, cutoff=None):
ret = int(integer_string)
if ret < 0 or (ret == 0 and strict):
raise ValueError()
if cutoff:
ret = min(ret, cutoff)
return ret
assert f(3) == 3
|
benchmark_functions_edited/f5768.py
|
def _singleton (x):
if isinstance (x, list):
return x[0]
return x
assert f(list(x for x in [1,2,3])) == 1
|
benchmark_functions_edited/f1058.py
|
def f(row, col):
return (row // 3) * 3 + col // 3
assert f(0, 5) == 1
|
benchmark_functions_edited/f762.py
|
def f(times, index, length):
return (index + times) % length
assert f(3, 1, 3) == 1
|
benchmark_functions_edited/f5012.py
|
def f(x):
area = x**2
return area
assert f(2) == 4
|
benchmark_functions_edited/f12961.py
|
def f(y_true, y_pred):
correct = 0
for true, pred in zip(y_true,y_pred):
if true == pred:
correct += 1
accuracy = correct/len(y_true)
return accuracy
assert f(
[0, 0, 0, 0, 1],
[0, 0, 0, 0, 1]
) == 1
|
benchmark_functions_edited/f1979.py
|
def f(x):
if isinstance(x, complex):
return x.imag
else:
return type(x)(0)
assert f(True) == 0
|
benchmark_functions_edited/f3234.py
|
def f(values):
if len(values) == 0:
return None
return sum(values) / len(values)
assert f([4, 4, 4, 4]) == 4
|
benchmark_functions_edited/f8463.py
|
def how_many (aDict):
key = aDict.keys()
val = []
for key in aDict:
aDict[key]
val = val + aDict[key]
return len(val)
assert f( {} ) == 0
|
benchmark_functions_edited/f11757.py
|
def f(x, in_min, in_max, out_min, out_max):
mapped = (x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min
if out_min <= out_max:
return max(min(mapped, out_max), out_min)
return min(max(mapped, out_max), out_min)
assert f(5, 0, 10, 0, 0) == 0
|
benchmark_functions_edited/f11664.py
|
def f(a: int, b: int, x: int, y: int) -> int:
if b <= x or a >= y:
return 0
elif x <= a <= y:
return min(b, y) - a
elif x <= b <= y:
return b - max(a, x)
elif a >= x and b <= y:
return b - a
else:
assert False
assert f(0, 2, 1, 3) == 1
|
benchmark_functions_edited/f5621.py
|
def f(x):
x = ((x + 2 / 3) % 2 * 0.5 - 0.5) * 16
return max(1 - x * x, 0)
assert f(12) == 0
|
benchmark_functions_edited/f3167.py
|
def f(scores):
return scores[-1]
assert f([-1, 0, 1]) == 1
|
benchmark_functions_edited/f60.py
|
def f():
print("Hello, world!")
return 0
assert f() == 0
|
benchmark_functions_edited/f4193.py
|
def f(n):
import math
a = math.factorial(2 * n)
b = math.factorial(n)
return a // b // b // (n + 1)
assert f(1) == 1
|
benchmark_functions_edited/f13281.py
|
def f(kcycles, element):
result = element # result defined for aesthetic and debug purposes
# Go over the Kcycle elements, applying the ones to the right first
for i in range(len(kcycles) - 1, -1, -1):
result = kcycles[i](result)
return result
assert f(
[
lambda x: x * x,
lambda x: x + 1,
],
1
) == 4
|
benchmark_functions_edited/f8742.py
|
def f(integer: int) -> int:
parity = 0
while integer:
parity = ~parity
integer = integer & (integer - 1)
return parity
assert f(20) == 0
|
benchmark_functions_edited/f8580.py
|
def f(values):
sorted_values = sorted(values)
length = len(sorted_values)
if length % 2 == 0:
return round((sorted_values[length//2-1] + sorted_values[length//2]) / 2, 1)
return sorted_values[(length-1)//2]
assert f([1, 2, 3, 4, 5]) == 3
|
benchmark_functions_edited/f6150.py
|
def f(iterable):
return next(iter(iterable or []), None)
assert f(set([1, 2, 3])) == 1
|
benchmark_functions_edited/f6911.py
|
def f(term, valid_transitions):
try:
return valid_transitions[term]
except KeyError as error:
raise KeyError(f"Indefinition , Invalid Transition: {error}.")
assert f(1, {1: 2, 2: 3, 3: 3}) == 2
|
benchmark_functions_edited/f160.py
|
def f(a, p):
return abs(p-a) ** 2
assert f(1, 0) == 1
|
benchmark_functions_edited/f7002.py
|
def f(n):
assert n >= 0 and int(n) == n, 'The number must be a positive integer only'
if n in [0, 1]:
return n
else:
return f(n-1) + f(n-2)
assert f(2) == 1
|
benchmark_functions_edited/f4675.py
|
def f(active_players):
curr_bids = 0
for player in active_players:
curr_bids += player.bid
return curr_bids
assert f([]) == 0
|
benchmark_functions_edited/f12039.py
|
def f(stringy_number):
if stringy_number.isdigit():
return int(stringy_number)
else:
raise SystemError("%s is not a number. C'mon dude." % stringy_number)
assert f("2") == 2
|
benchmark_functions_edited/f2041.py
|
def f(gt: tuple) -> int:
return None if gt == (None, None) else gt[0] + gt[1]
assert f((0, 1)) == 1
|
benchmark_functions_edited/f1989.py
|
def f(val, bits):
if val & (1 << (bits - 1)):
val = val - (1 << bits)
return val
assert f(0b0000000000000000, 16) == 0
|
benchmark_functions_edited/f3072.py
|
def f(f_in):
return (f_in - 32) * 5 / 9
assert f(32) == 0
|
benchmark_functions_edited/f7512.py
|
def f(n):
if n == 1:
return 1
else:
return n + f(n // 2)
assert f(2) == 3
|
benchmark_functions_edited/f11959.py
|
def f(row, cols, missing=-999, adjustfactor=1, countmissings=False):
nonmissingcols = [row[col] for col in cols if row[col] != missing]
return missing if len(nonmissingcols) == 0 \
else sum(nonmissingcols)/((len(cols) if countmissings else len(nonmissingcols)) * adjustfactor)
assert f(dict(zip(range(1,12),[1]*11)),range(1,12)) == 1
|
benchmark_functions_edited/f7253.py
|
def f(field):
tmp1 = (field[0].real * field[1].real + field[0].imag * field[1].imag)
tmp2 = (field[2].real * field[3].real + field[2].imag * field[3].imag)
return tmp1-tmp2
assert f(
(1, 0, 1, 0),
) == 0
|
benchmark_functions_edited/f2790.py
|
def f(x, in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
assert f(0.5, 0, 1, 0, 2) == 1
|
benchmark_functions_edited/f7683.py
|
def f(x):
if x < 15:
return 0
elif x > 42:
return 120
return 1.2 ** (x - 15)
assert f(2) == 0
|
benchmark_functions_edited/f5685.py
|
def f(label1, label2):
if (len(label1) + len(label2)) == 0:
return 0
else:
return len(label1.intersection(label2)) / (len(label1) + len(label2))
assert f(set(), set([1, 2, 3])) == 0
|
benchmark_functions_edited/f7639.py
|
def f(x, y, a, b):
ax, ay = a[0], a[1]
bx, by = b[0], b[1]
d = abs((by - ay)*x - (bx - ax)*y + bx*ay - by*ax)/ ((by - ay)**2 + (bx - ax)**2)**0.5
return d
assert f(0, 0, (1, 0), (0, 0)) == 0
|
benchmark_functions_edited/f9781.py
|
def f(n, p):
return (1-p)**(n-1) * p
assert f(5, 0) == 0
|
benchmark_functions_edited/f1079.py
|
def f(E, f, d3):
return -f[0] / (f[1] + 0.5 * d3 * f[2] + (d3**2) * f[3] / 6.)
assert f(1, (0, 1, 0, 0), 0.5) == 0
|
benchmark_functions_edited/f3329.py
|
def f(x, y):
if x <= y:
return x * y
else:
return x / y
assert f(3, 3) == 9
|
benchmark_functions_edited/f12712.py
|
def f(a, b):
if a["run"] > b["run"]:
return 1
elif a["run"] == b["run"]:
if a["lumi"] > b["lumi"]:
return 1
elif a["lumi"] == b["lumi"]:
return 0
else:
return -1
else:
return -1
assert f( {"run": 1, "lumi": 0}, {"run": 0, "lumi": 0}) == 1
|
benchmark_functions_edited/f8081.py
|
def f(DATASET: str) -> int:
if DATASET == 'MELD':
NUM_CLASSES = 7
elif DATASET == 'IEMOCAP':
NUM_CLASSES = 6
else:
raise ValueError
return NUM_CLASSES
assert f('IEMOCAP') == 6
|
benchmark_functions_edited/f2339.py
|
def f(l):
if ".asp" in str(l):
return 1
else:
return 0
assert f('.net') == 0
|
benchmark_functions_edited/f13078.py
|
def f(layers):
ret = 0
for l in range(1, len(layers)):
ret = ret + layers[l][0] * (layers[l - 1][0] + 2)
return ret
assert f(
[(1, "tanh"), (1, "tanh")]
) == 3
|
benchmark_functions_edited/f5110.py
|
def f(word):
if len(word) == 4:
return 1
else:
score = len(word)
if len(set(word)) == 7:
score += 7
return score
assert f(u"") == 0
|
benchmark_functions_edited/f4430.py
|
def f(lis, integer):
if len(lis) < integer:
return sum(lis)
return sum(x for x in lis[0:integer:])
assert f(list(range(10)), 1) == 0
|
benchmark_functions_edited/f14550.py
|
def f(x, y, n=-1):
if n == -1:
n = len(str(x))
if n == 1:
return x * y
a, b = half_split_int(x)
c, d = half_split_int(y)
ac = f(a, c, n // 2)
ad = f(a, d, n // 2)
bc = f(b, c, n // 2)
bd = f(b, d, n // 2)
return add_zeros(ac, n) + add_zeros(ad + bc, n // 2) + bd
assert f(3, 2) == 6
|
benchmark_functions_edited/f6308.py
|
def f(clip_duration: float, window_duration: float,
hop: float) -> int:
return int((clip_duration - window_duration) / hop) + 1
assert f(30, 10, 10) == 3
|
benchmark_functions_edited/f2044.py
|
def f(r: int, n: int):
return (1 - r ** n) / (1 - r)
assert f(-1, 4) == 0
|
benchmark_functions_edited/f969.py
|
def f(goal, output):
return ((goal - output) ** 2) / 2
assert f(1, 1) == 0
|
benchmark_functions_edited/f6009.py
|
def f(att: str) -> int:
return int(att[1:4])
assert f('U001') == 1
|
benchmark_functions_edited/f11744.py
|
def f(price: float, ord_val: float, limit_percent: float):
lot_size = 100 # standard lot size value
lot_value = price * lot_size * (1 + limit_percent)
quantity = ord_val / lot_value
return int(quantity)
assert f(100, 15000, 3) == 0
|
benchmark_functions_edited/f5494.py
|
def f(value, *functions, funcs=None):
if funcs:
functions = funcs
for function in functions:
value = function(value)
return value
assert f(1, lambda x: x*2) == 2
|
benchmark_functions_edited/f2423.py
|
def f(letter):
# ord of lower case 'a' is 97
return ord(letter) - 96
assert f("a") == 1
|
benchmark_functions_edited/f12885.py
|
def f(crop):
x1, y1, x2, y2 = crop
return max(0, x2 - x1) * max(0, y2 - y1)
assert f(
(1, 3, 3, 5)
) == 4
|
benchmark_functions_edited/f13103.py
|
def f(c, str_in):
return_val = str_in.find(c)
return return_val
assert f('a', 'dddabbb') == 3
|
benchmark_functions_edited/f5944.py
|
def f(elems):
nums = [a * 100 + b for a, b in zip(elems, elems[1:])]
if len(nums) == len(set(nums)):
return sum(nums)
return 0
assert f(list("111223")) == 0
|
benchmark_functions_edited/f968.py
|
def f(x):
if x <= 4:
return 1
else:
return 0
assert f(10) == 0
|
benchmark_functions_edited/f4845.py
|
def f(result):
if result == 'W':
return 3
elif result == 'D':
return 1
else:
return 0
assert f( 'D' ) == 1
|
benchmark_functions_edited/f8777.py
|
def f(a, b, i):
return a + (b-a)*i
assert f(2, 3, 0) == 2
|
benchmark_functions_edited/f599.py
|
def f(n):
return 3*n +1 |1
assert f(1) == 5
|
benchmark_functions_edited/f2743.py
|
def f(count):
if count > 0:
print("No match")
return 0
return 1
assert f(-2) == 1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.