file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f4035.py | def f(data):
pmts = set()
for row in data:
pmts.add(row[2] + row[3] + row[4])
return len(pmts)
assert f([]) == 0 |
benchmark_functions_edited/f4316.py | def f(a, b, fraction):
return a + (b - a) * fraction
assert f(0, 0, 0.0) == 0 |
benchmark_functions_edited/f13517.py | def f(base, exponent, modulus):
# NOTE: pow() in recent versions of Python 3 does the same thing.
if modulus == 1:
return 0
result = 1
base %= modulus
while exponent:
if exponent % 2:
result = (result * base) % modulus
exponent >>= 1
base = (base ** 2) %... |
benchmark_functions_edited/f13129.py | def f(a, b, c):
a,b,c = sorted([a,b,c]) # reduce redundancy in conditions
if a + b <= c:
return 0
a2,b2,c2 = (x*x for x in (a,b,c))
if a2 + b2 == c2:
return 2
if a2 + b2 < c2:
return 3
return 1
assert f(5, 5, 3) == 1 |
benchmark_functions_edited/f11114.py | def f(obj, attr_name, callable, default, *args, **kwargs):
try:
attr = getattr(obj, attr_name)
except AttributeError:
return default
else:
return callable(attr, *args, **kwargs)
assert f(1, 'as_integer_ratio', lambda x: x, 2) == 2 |
benchmark_functions_edited/f8715.py | def f(*args):
for arg in args:
try:
if arg:
return arg
except ValueError:
if arg is not None:
return arg
return args[-1]
assert f(1, True) == 1 |
benchmark_functions_edited/f5801.py | def f(x):
return x**(-2.35)
assert f(1) == 1 |
benchmark_functions_edited/f9588.py | def f(unparsed_rep):
if ',' in unparsed_rep:
repeat = unparsed_rep.split(',')
elif unparsed_rep.isnumeric():
repeat = int(unparsed_rep)
else:
repeat = unparsed_rep
return repeat
assert f('1') == 1 |
benchmark_functions_edited/f11676.py | def f(d, i, j, interaction_only):
if interaction_only:
return int(d * i - (i**2 + 3 * i) / 2 - 1 + j)
else:
return int(d * i - (i**2 + i) / 2 + j)
assert f(1, 1, 2, True) == 0 |
benchmark_functions_edited/f1266.py | def f(x, base):
return base * round(x/base)
assert f(3, 4) == 4 |
benchmark_functions_edited/f1524.py | def f(D):
D *= -1
D += 1
return D
assert f(0) == 1 |
benchmark_functions_edited/f5942.py | def f(deck):
count = 0
for card in deck:
print(repr(card))
card_count = int(card['card_count'])
count += card_count
return count
assert f([{'card_count': 5}]) == 5 |
benchmark_functions_edited/f7806.py | def f(collection, test, default=None):
return next((c for c in collection if test(c)), default)
assert f(range(5), lambda x: x == 3) == 3 |
benchmark_functions_edited/f6061.py | def f(obj, i):
return obj[i] if hasattr(obj, "__getitem__") else obj
assert f(range(10), 4) == 4 |
benchmark_functions_edited/f1358.py | def f(a, b):
(ax, ay) = a
(bx, by) = b
return abs(ax - bx) + abs(ay - by)
assert f((0, 0), (0, 0)) == 0 |
benchmark_functions_edited/f10488.py | def f(byte, bit_num):
return (byte & (1 << bit_num)) >> bit_num
assert f(0b00000101, 1) == 0 |
benchmark_functions_edited/f12797.py | def f(value, threshold, center=0.0):
return value if abs(value - center) > threshold else center
assert f(0, 10) == 0 |
benchmark_functions_edited/f8617.py | def f(predicate, seq):
for x in seq:
if predicate(x):
return x
return None
assert f(lambda x: x == 3, [1, 2, 3]) == 3 |
benchmark_functions_edited/f12072.py | def f(open, close, level, previous_touch):
if previous_touch == 1 and open > level and close > level:
return 1
elif previous_touch == 1 and open < level and close < level:
return -1
else:
return 0
assert f(11, 13, 10, 0) == 0 |
benchmark_functions_edited/f7570.py | def f(p2, d1, p1, g):
import math
return (math.sqrt(2)*(-p1 + p2))/math.sqrt(d1*((-1 + g)*p1 + (1 + g)*p2))
assert f(1, 1, 1, 1) == 0 |
benchmark_functions_edited/f2220.py | def f(z):
# z = amp*exp(phase*i) so amp is abs(z)
return abs(z)
assert f(-5-0j) == 5 |
benchmark_functions_edited/f7620.py | def f(values, empty=0):
n, mean = 0, 0
for value in values:
n += 1
mean += (value - mean) / n
return mean if n > 0 else empty
assert f(range(17)) == 8 |
benchmark_functions_edited/f12682.py | def f(point, reg):
return (point[1] - reg(point[0]))**2
assert f([0, 1], lambda x: 0) == 1 |
benchmark_functions_edited/f9446.py | def f(x, y):
if (x < y):
return x
else:
return y
assert f(4, 5) == 4 |
benchmark_functions_edited/f3509.py | def f(n):
return (n << 1) ^ (n >> 31)
assert f(-1) == 1 |
benchmark_functions_edited/f5724.py | def f(numbers):
ret = 1
for number in numbers:
ret *= number
return ret
assert f([1, 2, 3]) == 6 |
benchmark_functions_edited/f14541.py | def f(zip_file, base_dir, file_list):
for file_path in file_list:
zip_file.write(base_dir + file_path, file_path)
return 0
assert f(None, 'a/b', []) == 0 |
benchmark_functions_edited/f12.py | def f(x):
print(x)
return x
assert f(6) == 6 |
benchmark_functions_edited/f5769.py | def f(file_lines, pattern):
return next(i for i, line in enumerate(file_lines) if pattern in line) + 1
assert f(
["a", "b", "c"],
"a"
) == 1 |
benchmark_functions_edited/f2360.py | def f(results):
return sum(1 for roll in results if roll == 6)
assert f([]) == 0 |
benchmark_functions_edited/f9126.py | def f(width: float, height: float, length: float) -> float:
return float(width * height * length)
assert f(1, 2, 4) == 8 |
benchmark_functions_edited/f4718.py | def f(node):
total = 0
while node:
total += node.value
node = node.next
return total
assert f(None) == 0 |
benchmark_functions_edited/f7425.py | def f(neighbors_target, neighbors_source):
common_neighbors = len(set(neighbors_source).intersection(set(neighbors_target)))
return common_neighbors
assert f({1, 2}, {1, 2}) == 2 |
benchmark_functions_edited/f8269.py | def f(p, seq):
try:
return next(x for x in seq if p(x))
except StopIteration:
msg = "{} doesn't contain any value satisfying the predicate."
raise ValueError(msg.format(seq))
assert f(lambda x: x % 2 == 0, [1, 2, 3, 4, 5]) == 2 |
benchmark_functions_edited/f2441.py | def f(lst: list):
return max(range(len(lst)), key=lst.__getitem__)
assert f([10, 10, 10, 10, 11, 10]) == 4 |
benchmark_functions_edited/f8785.py | def f(el,xorsize=7):
v1 = el % (2**xorsize)
v2 = (el>>xorsize) % (2**xorsize)
return v1 ^ v2
assert f(2) == 2 |
benchmark_functions_edited/f922.py | def f(i,j,ell):
D = j-i
return i + D*ell - D*(D-1)//2
assert f(5,5,0) == 5 |
benchmark_functions_edited/f643.py | def f(value):
return round(int(value) / (1000**2), 3)
assert f(1) == 0 |
benchmark_functions_edited/f8981.py | def f(x, y):
a = (1.5 - x + x * y)**2
b = (2.25 - x + x * y * y)**2
c = (2.625 - x + x * y * y * y)**2
return a + b + c
assert f(3, 0.5) == 0 |
benchmark_functions_edited/f12006.py | def f(radius: float, mean_speed: float, drpf: float = 0.01) -> float:
if mean_speed == 0:
mean_speed = 1
return drpf * radius / mean_speed
return drpf * radius / mean_speed
assert f(0, 0) == 0 |
benchmark_functions_edited/f7296.py | def f(values):
sum_values = 0
i = 0
for value in values:
if value["value"] > 0:
sum_values += value["value"]
i += 1
return round(sum_values / i, 2)
assert f(
[{"value": 1}, {"value": 1}, {"value": 1}]
) == 1 |
benchmark_functions_edited/f14546.py | def f(d, key, default):
if key in d and d[key] != -1:
return d[key]
d[key] = default
return default
assert f(dict(), 1, 2) == 2 |
benchmark_functions_edited/f13487.py | def f(x, y, max_iters, value):
i = 0
c = complex(x,y)
z = 0.0j
for i in range(max_iters):
z = z*z + c
if (z.real*z.real + z.imag*z.imag) >= 4:
value[0] = i
return 0
value[i] = 255
return 1
assert f(1, 1, 100, [0]) == 0 |
benchmark_functions_edited/f7938.py | def f(s):
letters = "aeiouAEIOU"
count = 0
for letter in s:
if letter in letters:
count += 1
return count
assert f("a") == 1 |
benchmark_functions_edited/f9801.py | def f(input):
return len(input.encode('utf-8'))
assert f("hi") == 2 |
benchmark_functions_edited/f7763.py | def f(first, second):
return len(first & second) / len(first | second)
assert f(set([]), set([1,2,3,4,5])) == 0 |
benchmark_functions_edited/f2546.py | def f(input_list):
out = 0
for i in input_list:
out += i
return out
assert f([1, 2, 3]) == 6 |
benchmark_functions_edited/f2754.py | def f(x, x0, x1, y0, y1):
y = y0*(1.-(x-x0)/(x1-x0)) + y1*(x-x0)/(x1-x0)
return y
assert f(0, 0, 1, 0, 1) == 0 |
benchmark_functions_edited/f476.py | def f(s):
return s[0].stop-s[0].start
assert f((slice(2, 3),)) == 1 |
benchmark_functions_edited/f10708.py | def f(list1, list2):
l = min(len(list1), len(list2))
for i in range(0, l):
if list1[i] != list2[i]: return i
return l
assert f(
[1, 2, 3, 4],
[1, 2, 3, 5],
) == 3 |
benchmark_functions_edited/f122.py | def f(n):
return int(n * n)
assert f(-2) == 4 |
benchmark_functions_edited/f7433.py | def f(pulse_ms, frequency = 60):
period_ms = 1.0 / frequency * 1000.0
duty_cycle = int(pulse_ms / 1000 / (period_ms / 65535.0))
return duty_cycle
assert f(0) == 0 |
benchmark_functions_edited/f13696.py | def f(t):
from multiprocessing import cpu_count
maxt = cpu_count()
if t<=0:
t = maxt
else:
t = min(t,maxt)
return t
assert f(2) == 2 |
benchmark_functions_edited/f607.py | def f(sk, c):
return (c % sk)
assert f(60, 603) == 3 |
benchmark_functions_edited/f11399.py | def f(file, newvalue):
oldvalue = 0
try:
oldvalue = file.softspace
except AttributeError:
pass
try:
file.softspace = newvalue
except (AttributeError, TypeError):
# "attribute-less object" or "read-only attributes"
pass
return oldvalue
assert f(None, 0) ==... |
benchmark_functions_edited/f471.py | def f(op, args):
return op(*args)
assert f(lambda x, y: x + y, (1, 2)) == 3 |
benchmark_functions_edited/f8101.py | def f(imgIn,imgOut,Rp=0.0):
# Rp = [0,1], ratio of propagating how much input to reconstruction
# Rp = 1/0 for maximully/minimumaly passing
average = (Rp*imgIn+(1-Rp)*imgOut)/2
return average
assert f(1, 2, 0) == 1 |
benchmark_functions_edited/f14545.py | def f(file, s, mode='w', **kwargs):
with open(file, mode, **kwargs) as f:
return f.f(s)
assert f(1, 'x') == 1 |
benchmark_functions_edited/f8504.py | def f(a, x, hi):
lo = 0
while lo < hi:
mid = (lo+hi)//2
if a[mid] < x: lo = mid+1
else: hi = mid
return lo
assert f(range(10), 9, 9) == 9 |
benchmark_functions_edited/f3584.py | def f(theta):
return (theta+1)/2
assert f(1) == 1 |
benchmark_functions_edited/f5557.py | def f(semicircles):
return (semicircles * 180 / 2**31 + 180) % 360 - 180
assert f(0) == 0 |
benchmark_functions_edited/f12564.py | def f(rotated_files):
if not rotated_files:
return 0
else:
highest_rotated_file = max(rotated_files, key=lambda x: x[1])
return highest_rotated_file[1] + 1
assert f((('hanoi_1_2017-08-24_22-03-35', 1),
('hanoi_2_2017-08-24_22-03-35', 1))) == 2 |
benchmark_functions_edited/f5680.py | def f(pressure, n_monolayer, c_const):
return (n_monolayer * c_const * pressure / (1 - pressure) / (1 - pressure + c_const * pressure))
assert f(0, 0, 0) == 0 |
benchmark_functions_edited/f10755.py | def f(match, player_num, word_index):
assert word_index < len(match["words"]), "word_index out of range of words"
assert player_num < len(match["times"]), "player_num out of range of players"
return match["times"][player_num][word_index]
assert f(
{"words": ["a", "b", "c"], "times": [[0, 100, 200, 300,... |
benchmark_functions_edited/f13957.py | def f(u, kap, eps):
return 3 * eps * kap * (1 + eps * u) ** 2
assert f(4, 0, 1) == 0 |
benchmark_functions_edited/f8959.py | def f(a, p):
if a <= p // 2:
return a
else:
return a - p
assert f(2, 7) == 2 |
benchmark_functions_edited/f11049.py | def f(n, k):
"*** YOUR CODE HERE ***"
res = 1
while k > 0:
res = res * n
n -= 1
k -= 1
return res
assert f(6, 1) == 6 |
benchmark_functions_edited/f8567.py | def f(params, default):
for param in params:
if param is not None:
return param
return default
assert f(
[None, 1, None, 3],
0,
) == 1 |
benchmark_functions_edited/f14458.py | def f(val, bits):
if isinstance(val, str):
if '0x' in val:
val = int(val, 16)
else:
val = int(val, 2)
if (val & (1 << (bits - 1))) != 0:
val = val - (1 << bits)
return val
assert f(0b00001001, 8) == 9 |
benchmark_functions_edited/f1906.py | def f(page_id, usage_id):
return (page_id << 16) | usage_id
assert f(0, 0x0001) == 1 |
benchmark_functions_edited/f12111.py | def f(f, x, epsilon = 1e-10):
x_ = x + epsilon
value = (f(x_) - f(x)) / epsilon
return value
assert f(lambda x: x**0, 2) == 0 |
benchmark_functions_edited/f4465.py | def f(binArr):
numArr = "".join(map(str,binArr))
return int(numArr,2)
assert f(
[0,0]) == 0 |
benchmark_functions_edited/f4270.py | def f(words):
try:
return len(words.split())
except:
return 0
assert f('a b c') == 3 |
benchmark_functions_edited/f8354.py | def f(a, b):
while b:
a, b = b, a % b
return a
assert f(21, 14) == 7 |
benchmark_functions_edited/f932.py | def f(array):
return 1/(array**2)
assert f(1) == 1 |
benchmark_functions_edited/f8488.py | def f(depth):
return 2 ** (depth-1)
assert f(1) == 1 |
benchmark_functions_edited/f171.py | def f(n):
return ((n ** 2) * (n + 1)) / 2
assert f(1) == 1 |
benchmark_functions_edited/f5754.py | def f(autocorrelation):
T = 1
for a in autocorrelation:
if a < 0:
return T - 1
T += 1
return T
assert f([-1.0, -2.0, 3.0]) == 0 |
benchmark_functions_edited/f11173.py | def f(sessions):
failed_validations = 0
for session in sessions:
for line in session:
if "'--staging'" in line:
break
if 'FailedChallenge' in line:
failed_validations += 1
return failed_validations
assert f([]) == 0 |
benchmark_functions_edited/f10666.py | def f(obj, attr):
try:
return getattr(obj, attr)
except AttributeError:
return None
assert f(1, "real") == 1 |
benchmark_functions_edited/f14036.py | def f(readings:list, byte_array:bytes, pointer:int):
print('[end_decoding] Decoding stopped')
return len(byte_array)
assert f([], b'\x00\x00', 0) == 2 |
benchmark_functions_edited/f1520.py | def f(num):
cnt = 0
while not (num >> cnt) & 1:
cnt += 1
#
return cnt + 1
assert f(0b10101010) == 2 |
benchmark_functions_edited/f9208.py | def f(element, branch):
if isinstance(element, dict) and len(branch) > 0:
return f(element[branch[0]], branch[1:])
else:
return element
assert f({"a": {"b": 2}}, ["a", "b"]) == 2 |
benchmark_functions_edited/f14253.py | def f(cards, query):
# time complexity: O(N)
# space complexity: O(1)
position = 0
while position < len(cards):
# check if current elem matches the query
if cards[position] == query:
return position
position += 1
# if we have reached the ... |
benchmark_functions_edited/f3651.py | def f(l, o):
index = l.index(o)
return l[index + 1]
assert f(range(10), 5) == 6 |
benchmark_functions_edited/f989.py | def f(x, y):
y += 1
print (x, y)
z = x * y
print (z)
return z
assert f(0, 0) == 0 |
benchmark_functions_edited/f13997.py | def f(nums):
if not nums or len(nums) == 0:
return 0
global_max = float("-inf")
current_max = float("-inf")
for num in nums:
current_max = max(num + current_max, num)
global_max = max(current_max, global_max)
return global_max
assert f([-2, 1]) == 1 |
benchmark_functions_edited/f12558.py | def f(y_predicted, y_true):
y = 2 * (y_predicted - y_true)
return y
assert f(6, 4) == 4 |
benchmark_functions_edited/f9967.py | def f(val, bits=32):
if (val & (1 << (bits - 1))) != 0: # if sign bit is set e.g., 8bit: 128-255
val = val - (1 << bits) # compute negative value
return val
assert f(3, 4) == 3 |
benchmark_functions_edited/f13825.py | def f(mode):
if mode in ("minor", -1):
return -1
elif mode in ("major", None, 1):
return 1
else:
raise ValueError("Unknown mode {}".format(mode))
assert f("major") == 1 |
benchmark_functions_edited/f1580.py | def f(n, d):
if n<=d/2:
return n
else:
return n-d
assert f(13, 8) == 5 |
benchmark_functions_edited/f533.py | def f(row, rows, line_width):
return (rows - row - 1)*line_width
assert f(0, 1, 1000) == 0 |
benchmark_functions_edited/f4547.py | def f(side):
squared = side**2
return squared
assert f(3) == 9 |
benchmark_functions_edited/f7447.py | def f(integer_string, cutoff=None):
ret = int(integer_string)
if ret <= 0:
raise ValueError()
if cutoff:
ret = min(ret, cutoff)
return ret
assert f(3) == 3 |
benchmark_functions_edited/f2422.py | def f(fileS):
if fileS.endswith("htm") or fileS.endswith("html"):
return 1
return 0
assert f( "other.html.tar.gz" ) == 0 |
benchmark_functions_edited/f10100.py | def compareString (a,b):
if a == b:
return 1
sa, sb = set(a), set(b)
n = len(sa.intersection(sb))
if float(len(sa) + len(sb) - n) == 0:
return 0
jacc = n / float(len(sa) + len(sb) - n)
return jacc
assert f('hello world!', 'hello wolrd!') == 1 |
benchmark_functions_edited/f4154.py | def f(hexstr):
return int(hexstr, 16)
assert f(u'0') == 0 |
benchmark_functions_edited/f1299.py | def f(t, b, c, d):
t /= d
return c * t * t + b
assert f(1, 0, 1, 1) == 1 |
benchmark_functions_edited/f1445.py | def f(t1,t2):
return sum([(t1[i]-t2[i])**2 for i in range(len(t1))])
assert f( (1, 1), (1, 1) ) == 0 |
benchmark_functions_edited/f11935.py | def f(hand):
# TO DO... <-- Remove this comment when you code this function
handLen = 0
for val in hand.values():
handLen = handLen + val
return handLen
## return sum(hand.values()) "gives same result"
assert f({'a':1}) == 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.