file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f6020.py
|
def f(x, n):
ret = 1
if n < 0:
return f(x - abs(n), abs(n)) ** (-1)
for k in range(0, n):
ret *= x + k
return ret
assert f(3, 1) == 3
|
benchmark_functions_edited/f1228.py
|
def f(val: int, bitNo: int) -> int:
return val & ~(1 << bitNo)
assert f(0, 1) == 0
|
benchmark_functions_edited/f579.py
|
def f(x):
from cmath import log
return log(x).imag
assert f(1 + 0j) == 0
|
benchmark_functions_edited/f1381.py
|
def f(pos):
return pos * pos * pos * pos
assert f(0) == 0
|
benchmark_functions_edited/f4943.py
|
def f(*args):
#init sum
sum_all= 0
#accumulate the sum
for num in args:
sum_all += num
return sum_all
assert f(1) == 1
|
benchmark_functions_edited/f1022.py
|
def f(tokens):
return int(tokens[0]) if tokens else None
assert f(['1', '2', '3', 'abc']) == 1
|
benchmark_functions_edited/f4034.py
|
def f(cdc):
nb = 1
for elt in cdc:
nb *= int(elt)
return nb
assert f( "100000000" ) == 0
|
benchmark_functions_edited/f8077.py
|
def f(path, data):
with open(path, 'wb') as handle:
return handle.write(data)
assert f(
'/tmp/file.txt',
b'\x00\xff'
) == 2
|
benchmark_functions_edited/f8340.py
|
def f(value, lower=None, upper=None):
if lower is not None:
value = max(value, lower)
if upper is not None:
value = min(value, upper)
return value
assert f(3, 5, 7) == 5
|
benchmark_functions_edited/f2236.py
|
def f(v, s):
return min([abs(v-x) for x in s])
assert f(0, {-1, 1}) == 1
|
benchmark_functions_edited/f10622.py
|
def f(_dividend: int, _divisor: int) -> int:
_q = (_dividend // _divisor)
_d = _q * _divisor
return _dividend - _d
assert f(4, 12) == 4
|
benchmark_functions_edited/f995.py
|
def f(z):
return (z - 20) / (3 * z + 1j)
assert f(20) == 0
|
benchmark_functions_edited/f7742.py
|
def f(l):
if len(l) == 1:
return l[0]
elif len(l) == 0:
return None
raise Exception('filter matched too many: {}'.format(len(l)))
assert f([1]) == 1
|
benchmark_functions_edited/f13891.py
|
def f(n):
dp = [0]*(n+1)
if n < 4:
return 1
dp[0] = 1 # If the length is 0, there is no solution which is one way
dp[1] = 1
dp[2] = 1
dp[3] = 1
for i in range(4, n+1):
dp[i] = dp[i-1] + dp[i-4]
return dp[n]
assert f(1) == 1
|
benchmark_functions_edited/f2866.py
|
def f(spd):
spdkts = spd * 1.94384449
return spdkts
assert f(0) == 0
|
benchmark_functions_edited/f2549.py
|
def f(koyo, kuwi):
inner = sum(koyo[key] * kuwi.get(key, 0.0) for key in koyo)
return inner
assert f(dict(), dict()) == 0
|
benchmark_functions_edited/f13315.py
|
def f(socks):
# build a histogram of the socks
sock_colors = {}
for sock in socks:
if sock not in sock_colors.keys():
sock_colors[sock] = 1
else:
sock_colors[sock] += 1
# count the amount of pairs
pairs = 0
for count in sock_colors.values():
pairs += count // 2
return pairs
assert f(list("abcdef")) == 0
|
benchmark_functions_edited/f12924.py
|
def f(value):
try:
return int(value)
except ValueError:
return float(value)
assert f('1') == 1
|
benchmark_functions_edited/f3350.py
|
def f(pop_size, clone_factor):
return int(pop_size * clone_factor)
assert f(100, 0.01) == 1
|
benchmark_functions_edited/f10832.py
|
def f(pos_neg, off_on, on):
return 10 * pos_neg + 5 * off_on
assert f(0, 0, 0) == 0
|
benchmark_functions_edited/f1625.py
|
def f(x):
import struct
return struct.unpack('>Q', x)[0]
assert f(b'\x00' * 7 + b'\x01') == 1
|
benchmark_functions_edited/f5986.py
|
def f(number, min, max):
if number < min:
return min
elif number > max:
return max
else:
return number
assert f(2, 0, 1) == 1
|
benchmark_functions_edited/f255.py
|
def f(n):
return sum(range(n))
assert f(0) == 0
|
benchmark_functions_edited/f1815.py
|
def f(s: str) -> int:
basic_hash = ord(s[0])
return basic_hash % 10
assert f(str(25)) == 0
|
benchmark_functions_edited/f12550.py
|
def f(risk):
_index = 0
if risk == 0.5:
_index = 1
elif risk == 1.0:
_index = 2
elif risk == 2.0:
_index = 3
return _index
assert f(1.0) == 2
|
benchmark_functions_edited/f9874.py
|
def f(dot,orb,spin):
return 4*dot+2*orb+spin
assert f(1,1,0) == 6
|
benchmark_functions_edited/f7511.py
|
def f(grade_list):
suma = 0 # Do you think 'sum' is a good var name? Run pylint to figure out!
for grade in grade_list:
suma = suma + grade
mean = suma / len(grade_list)
return mean
assert f([1, 2, 3]) == 2
|
benchmark_functions_edited/f10672.py
|
def f(my_dict, my_value):
return {value: key for key, value in my_dict.items()}[my_value]
assert f(
{1: 1, 2: 2, 3: 3},
1
) == 1
|
benchmark_functions_edited/f2271.py
|
def f(freq, grid=0.00625e12):
return (int)((freq-193.1e12)/grid)
assert f(193.1e12 + 0.00625e12) == 1
|
benchmark_functions_edited/f3308.py
|
def f(y1, y2):
x = (y1) | (y2 << 8)
if x >= 32768:
x = -(65536 - x)
return x
assert f(0x00, 0x00) == 0
|
benchmark_functions_edited/f5355.py
|
def f(s):
if not s:
return None
value = float(s)
return int(value) if value == int(value) else value
assert f(1) == 1
|
benchmark_functions_edited/f1140.py
|
def f(n):
if n < 2:
return n
return f(n-1) + f(n-2)
assert f(0) == 0
|
benchmark_functions_edited/f11014.py
|
def f(s):
s = s.strip()
word_length = 0
for c in s:
if c == ' ':
word_length = 0
else:
word_length += 1
return word_length
assert f("123 456") == 3
|
benchmark_functions_edited/f11595.py
|
def f(array, elt):
start = 0
end = len(array) - 1
while start <= end:
mid = (start + end) // 2
if elt == array[mid]:
return mid + 1
if elt < array[mid]:
end = mid - 1
else:
start = mid + 1
if start > end:
return start
assert f(range(10), 0) == 1
|
benchmark_functions_edited/f11839.py
|
def f(type_name, value):
if 'int' in type_name:
return int(value)
if 'float' in type_name:
return float(value)
if 'bool' in type_name:
return 'True' in value
if 'str' in type_name:
return value
raise ValueError("Type format not understood")
assert f(**{'type_name': 'int', 'value': '1'}) == 1
|
benchmark_functions_edited/f12952.py
|
def f(s: str):
# To prevent overconsumption of server resources, reject any
# base36 string that is longer than 13 base36 digits (13 digits
# is sufficient to base36-encode any 64-bit integer)
if len(s) > 13:
raise ValueError("Base36 input too large")
return int(s, 36)
assert f( "1" ) == 1
|
benchmark_functions_edited/f3637.py
|
def f(precision, recall):
if precision or recall:
return 2 * precision * recall / (precision + recall)
return 0
assert f(0.25, 0) == 0
|
benchmark_functions_edited/f837.py
|
def f(val):
return 10 ** (val / 20)
assert f(0) == 1
|
benchmark_functions_edited/f344.py
|
def f(seq):
return seq[-1]
assert f( (1, 2, 3) ) == 3
|
benchmark_functions_edited/f9619.py
|
def f(d, min_depth, max_depth):
# d = d.clamp(min_depth, max_depth)
return (max_depth * d - max_depth * min_depth) / ((max_depth - min_depth) * d)
assert f(1.0, 0.0, 1.0) == 1
|
benchmark_functions_edited/f10531.py
|
def f(number):
solution = 0
print(f"Opening luke number: {number}.")
if (number == 0):
solution = -1
print(f"Solution is: {solution}.")
return solution
assert f(10) == 0
|
benchmark_functions_edited/f10325.py
|
def f(arr):
dict = {}
for num in arr:
if num in dict:
dict[num] += 1
else:
dict[num] = 1
for num in dict:
if not dict[num] & 1: # bitwise check for parity.
return num
assert f(
[1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5
|
benchmark_functions_edited/f8787.py
|
def f(number):
sum_of_digits = 0
while number > 0:
last_digit = number % 10
sum_of_digits += last_digit
number = number // 10 # Removing the last_digit from the given number
return sum_of_digits
assert f(1) == 1
|
benchmark_functions_edited/f185.py
|
def f(value):
return int(value * 9525)
assert f(0) == 0
|
benchmark_functions_edited/f2387.py
|
def f(base, delta, adding):
if adding:
return base + delta
return base - delta
assert f(1, 1, True) == 2
|
benchmark_functions_edited/f1507.py
|
def f(int_bytes):
return int.from_bytes(int_bytes, 'little')
assert f(b"\x00\x00\x00\x00") == 0
|
benchmark_functions_edited/f12658.py
|
def f(x, *coefs):
# Add a warning for something potentially incorrect
if len(coefs) == 0:
raise Exception("You have not provided any polynomial coefficients.")
# Calculate using a loop
result = 0
for power,c in enumerate(coefs):
result += c * (x ** (power+1))
return result
assert f(3, 1) == 3
|
benchmark_functions_edited/f11069.py
|
def f(headers):
remain = headers.get("X-Rate-Limit-Remaining", None)
if remain is None:
remain = headers.get("X-RateLimit-Remaining", None)
if remain is None:
return 0
try:
remain = int(remain)
except ValueError:
return 0
return remain
assert f(dict()) == 0
|
benchmark_functions_edited/f4328.py
|
def f(value, current_mean, count):
summed = current_mean * count
return (summed + value)/(count + 1)
assert f(2, 2, 2) == 2
|
benchmark_functions_edited/f7159.py
|
def f(target, pos):
try:
result=int(target[pos])
return result
except IndexError:
return False
except ValueError:
return False
assert f([1, 2, 3, 4, 5, 6], 3) == 4
|
benchmark_functions_edited/f13264.py
|
def f(str_in, substr, nth):
m_slice = str_in
n = 0
m_return = None
while nth:
try:
n += m_slice.index(substr) + len(substr)
m_slice = str_in[n:]
nth -= 1
except ValueError:
break
try:
m_return = n - 1
except ValueError:
m_return = 0
return m_return
assert f(r"This is a sentence", "s", 2) == 6
|
benchmark_functions_edited/f13597.py
|
def f(x):
if x:
sorted_x = sorted(x)
n = len(x)
mid = n // 2
if n % 2 == 1:
return sorted_x[mid]
else:
return (sorted_x[mid] + sorted_x[mid-1]) / 2
else:
raise ValueError('len of x == 0')
assert f((3, 2, 1, 4, 5)) == 3
|
benchmark_functions_edited/f239.py
|
def f(x, y):
result = x + y
return result
assert f(2, 3) == 5
|
benchmark_functions_edited/f8676.py
|
def f(prec, recall):
return 2*(prec*recall)/(prec+recall) if recall and prec else 0
assert f(0, 0.5) == 0
|
benchmark_functions_edited/f1688.py
|
def f(p_mean, val, alpha=0.8):
return p_mean + (alpha * (val - p_mean))
assert f(1, 1, 0.5625) == 1
|
benchmark_functions_edited/f4107.py
|
def f(lis):
s = 0.
for i,p in enumerate(lis):
s += i*p
return s
assert f( [0.1, 0.2, 0.3, 0.4] ) == 2
|
benchmark_functions_edited/f2140.py
|
def f(x):
return x.real**2 + x.imag**2
assert f(0) == 0
|
benchmark_functions_edited/f11705.py
|
def f(segment_length):
if segment_length <= 0:
raise ValueError('segment_length must be > 0')
return segment_length / 0.485
assert f(0.485) == 1
|
benchmark_functions_edited/f1547.py
|
def f(value, model):
return int(round(value / 8.583, 0))
assert f(0.0, 0) == 0
|
benchmark_functions_edited/f3627.py
|
def f(a, b):
while b != 0:
a, b = b, a % b
return a
assert f(3, 2) == 1
|
benchmark_functions_edited/f12944.py
|
def f(input_1: float, input_2: float, *extra) -> float:
total = input_1 + input_2
for curr_num in extra:
total += curr_num
return total
assert f(*[1, 2, 3]) == 6
|
benchmark_functions_edited/f13691.py
|
def f(PPV, NPV):
return PPV+NPV-1
assert f(0,1) == 0
|
benchmark_functions_edited/f8217.py
|
def f(a, n, p, x_i):
if x_i % 3 == 2:
return a
elif x_i % 3 == 0:
return 2*a % n
elif x_i % 3 == 1:
return (a + 1) % n
else:
print("[-] Something's wrong!")
return -1
assert f(1, 10, 1, 6) == 2
|
benchmark_functions_edited/f12796.py
|
def f(Nu, Nc):
clust = 1 - ( ((Nc/Nu) - (1/Nu)) /
(1 - (1/Nu)) )
return clust
assert f(3, 3) == 0
|
benchmark_functions_edited/f5205.py
|
def f(a, b, m):
if b == 0:
return 1
temp = f(a, b >> 2, m)
temp *= 2
if b & 1 > 0:
temp *= a
temp %= m
return temp
assert f(2, 3, 5) == 4
|
benchmark_functions_edited/f8915.py
|
def f(value=None, default=None):
if value is None:
return default
else:
return value
assert f(0) == 0
|
benchmark_functions_edited/f1387.py
|
def f(s: slice, l: int):
return len(range(*s.indices(l)))
assert f(slice(None, None), 4) == 4
|
benchmark_functions_edited/f2502.py
|
def f(ival,ipos,ilen):
ones = ((1 << ilen)-1)
return ( ival & (ones << ipos) ) >> ipos
assert f(0x01, 2, 2) == 0
|
benchmark_functions_edited/f34.py
|
def f(x):
return (1./2)**x
assert f(0) == 1
|
benchmark_functions_edited/f3241.py
|
def f(val):
if val < 0:
raise ValueError("val cannot be negative.")
return val
assert f(1) == 1
|
benchmark_functions_edited/f11080.py
|
def f(s: str, offset):
while True:
while offset < len(s) and s[offset].isspace():
offset += 1
if offset >= len(s) or s[offset] != ";":
break
while offset < len(s) and s[offset] not in "\n\r":
offset += 1
return offset
assert f(r" \n ", 0) == 3
|
benchmark_functions_edited/f14294.py
|
def f(string):
n = len(string)
zero_unicode = ord('0')
def recurse(idx):
if idx == n:
return 0 # Base case
int_val = ord(string[idx]) - zero_unicode
return int_val * 10 ** (n - 1 - idx) + recurse(idx + 1)
return recurse(0)
assert f("1") == 1
|
benchmark_functions_edited/f10554.py
|
def f(current_number):
next_number = 0
if current_number == 1:
next_number = 0
elif current_number % 2 == 0:
next_number = current_number / 2
else:
next_number = (current_number * 3) + 1
return next_number
assert f(2) == 1
|
benchmark_functions_edited/f13968.py
|
def f(nums):
# Use two bit operator to save three states
m1, m2 = 0, 0
# n = 1, change in this order
# m1 0 -> 0 -> 1 -> 0
# m2 0 -> 1 -> 0 -> 0
# n = 0, remain it same
for n in nums:
tmp = m1
m1 = m1 ^ n & (m1 ^ m2)
m2 = m2 ^ n & (~tmp)
return m2
assert f(
[4, 1, 2, 1, 2]) == 4
|
benchmark_functions_edited/f6348.py
|
def f(base, index, value):
if value is None:
value = ''
base[index] = value.rstrip("\n")
return len(value) - len(base[index])
assert f([''], 0, 'a') == 0
|
benchmark_functions_edited/f11581.py
|
def f(val):
if val is None:
return 0
age = (val.year - 1972) / 32
if age < 0:
age = 0
elif age > 3:
age = 3
year = (val.year - 1972) % 32
return year + \
(val.day << 5) + \
(val.month << 10) + \
(age << 14)
return val
assert f(None) == 0
|
benchmark_functions_edited/f7278.py
|
def f(month: int) -> int:
return ((month - 1) // 3) + 1
assert f(4) == 2
|
benchmark_functions_edited/f945.py
|
def f(a,b):
c = int(a/b)
result = a - b*c
return result
assert f(6, 7) == 6
|
benchmark_functions_edited/f8345.py
|
def f(s):
hours, minutes, seconds = s.split(":")
hours = int(hours) * 3600
minutes = int(minutes) * 60
seconds = int(seconds)
return hours + minutes + seconds
assert f( "00:00:00" ) == 0
|
benchmark_functions_edited/f883.py
|
def f(m, n):
res = 1
for i in range(n):
res *= m
return res
assert f(4, 0) == 1
|
benchmark_functions_edited/f9709.py
|
def f(data):
if len(data) == 1:
return data[0]
else:
return data
assert f([1]) == 1
|
benchmark_functions_edited/f10155.py
|
def f(i_cn=0,i_cp=0):
ic = i_cn + i_cp
return ic
assert f(1, -1) == 0
|
benchmark_functions_edited/f13122.py
|
def f(n):
"*** YOUR CODE HERE ***"
print(n)
if n <= 1:
return 1
else:
if n % 2 == 0:
return f(n // 2) + 1
else:
return f(n * 3 + 1) + 1
assert f(1) == 1
|
benchmark_functions_edited/f8043.py
|
def f(x):
if x == False or x == True:
return x
return {"true": True, "false": False}.get(str(x).lower())
assert f(0) == 0
|
benchmark_functions_edited/f11344.py
|
def f(p):
count = 0
for a in range(1, p//4 + 1):
c = (a**2 + (p - a)**2)//(2*(p - a))
remainder = (a**2 + (p - a)**2) % (2*(p - a))
b = p - a - c
if (remainder == 0) and (a <= b < c):
count += 1
return(count)
assert f(5) == 0
|
benchmark_functions_edited/f7359.py
|
def f(*args, default=1):
for arg in args:
try:
return int(arg)
except ValueError:
continue
return default
assert f('1', 2, 3) == 1
|
benchmark_functions_edited/f2093.py
|
def f(y):
if y >= 0:
return 0
else:
return 1
assert f(-4) == 1
|
benchmark_functions_edited/f5878.py
|
def f(num, base=2):
return [n for n in range(32) if num < base**n][0]
assert f(9) == 4
|
benchmark_functions_edited/f3060.py
|
def f(l):
l_sort = sorted(l)
n = len(l_sort)
return (l_sort[n//2]+l_sort[(n//2)+1])/2 if n % 2 == 0 else l_sort[n//2]
assert f(list(range(15))) == 7
|
benchmark_functions_edited/f1252.py
|
def f(x: int) -> int:
return ((x >> 6) & 0x00000003) + 1
assert f(0b000000) == 1
|
benchmark_functions_edited/f3374.py
|
def f(seq, items):
for s in seq:
if not s in items:
return s
assert f([1, 2, 3, 4, 5], set([6, 7, 8, 9, 10])) == 1
|
benchmark_functions_edited/f6915.py
|
def f(x):
# Example
distribution = [1882, 3380, 5324, 6946, 8786]
x_class = 0
for i in range(len(distribution)):
if x > distribution[i]:
x_class += 1
return x_class
assert f(1882) == 0
|
benchmark_functions_edited/f12376.py
|
def f(tire_moment, tire_d, v):
omega = 2 * v / tire_d
return (omega ** 2) * tire_moment / 2
assert f(100, 0.3, 0) == 0
|
benchmark_functions_edited/f8078.py
|
def f(s, wx):
if wx == '':
return 0
# special case for blowing/drifting snow
ix = s.find(wx)
if wx == 'SN' and ix > 1:
if s[ix-2:ix] in ('BL', 'DR'):
return 0
return ix >= 0
assert f(u'BL', u'SN') == 0
|
benchmark_functions_edited/f10344.py
|
def f(kwargs, name, default_value=None, remove=True):
if remove:
value = kwargs.pop(name) if name in kwargs else default_value
else:
value = kwargs.get(name, default_value)
return value
assert f(
{"value": 5, "default_value": 10},
"value"
) == 5
|
benchmark_functions_edited/f13644.py
|
def f(x, my_min=0, my_max=1):
return min(max(x, my_min), my_max)
assert f(0, 0, 1) == 0
|
benchmark_functions_edited/f7921.py
|
def f(element_number: int, position: int) -> int:
region = (position + 1) // element_number
quartet = region % 4
output = [0, 1, 0, -1][quartet]
return output
assert f(2, 0) == 0
|
benchmark_functions_edited/f10648.py
|
def f(x1, y1, x2, y2):
return int(abs(x2 - x1) + abs(y2 - y1) + 0.5)
assert f(0, 0, 1, 2) == 3
|
benchmark_functions_edited/f3469.py
|
def f(code: str) -> int:
if isinstance(code, str):
return len(code)
return 0
assert f({'a': 1, 'b': 2}) == 0
|
benchmark_functions_edited/f14526.py
|
def f(data) -> int:
result = 0
shift = 0
while True:
byte = next(data)
result |= (byte & 0x7F) << shift
# Detect last byte:
if byte & 0x80 == 0:
break
shift += 7
return result
assert f(iter(bytes([0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00]))) == 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.