file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f6692.py | def f(a1, a2):
if a1 > a2:
return 1
elif a1 < a2:
return 2
else:
return 0
assert f(100, 99) == 1 |
benchmark_functions_edited/f10209.py | def f(scores, query):
DEFAULT_WEIGHT = 0
total = 0
for feature in scores.keys():
if feature in query:
total += scores[feature] * query[feature]
else:
total += scores[feature] * DEFAULT_WEIGHT
return total
assert f(
{"python": 10, "ruby": 3}, {"python": 0, ... |
benchmark_functions_edited/f14068.py | def f(cls):
if cls in ['float64', 'int64', 'uint64']:
n_byte = 8
elif cls in ['float32', 'int32', 'uint32']:
n_byte = 4
elif cls in ['bool', 'str', 'int8', 'uint8']:
n_byte = 1
else:
raise TypeError('invalid data type')
return n_byte
assert f('bool') == 1 |
benchmark_functions_edited/f8858.py | def f(x, index):
if index is None:
return x
if hasattr(x, "index"):
x.index = index
return x
assert f(2, 0) == 2 |
benchmark_functions_edited/f10013.py | def f(s):
t = str(s)
for c in t:
if c not in '-.0123456789':
return -1
if '.' not in t:
return 0
while '.' in t:
try:
t = t[1:]
except:
pass
return len(t)
assert f(123456.789) == 3 |
benchmark_functions_edited/f14118.py | def f(values):
max_places = 0
for i, value in enumerate(values):
if value is None:
continue
places = value.normalize().as_tuple().exponent * -1
if places > max_places:
max_places = places
return max_places
assert f([None, None, None]) == 0 |
benchmark_functions_edited/f2906.py | def f(question_str):
return int(question_str.lstrip("q"))
assert f("q+1") == 1 |
benchmark_functions_edited/f7800.py | def f(value: str) -> int:
if all(map(lambda x: x.isupper(), value)):
return 1
elif all(map(lambda x: x.islower(), value)):
return 0
return -1
assert f("a") == 0 |
benchmark_functions_edited/f2788.py | def f(x, a0, a1, a2, a3, a4):
return a0 + a1 * x + a2 * (x ** 2) + a3 * (x ** 3) + a4 * (x ** 4)
assert f(0, 1, 2, 3, 4, 5) == 1 |
benchmark_functions_edited/f6811.py | def f(ro, Po, crit_press, v, E, rp, Pi):
return (ro*(1+v)/E)*(2*(1-v)*(Po-crit_press)*(rp/ro)**2-(1-2*v)*(Po-Pi))
assert f(1, 1, 1, 1, 1, 1, 1) == 0 |
benchmark_functions_edited/f14322.py | def f(x, scale_factor, num_levels=255):
assert num_levels % 2
x = x / ((num_levels - 1) / 2)
x = x * scale_factor
return x
assert f(0, 1000) == 0 |
benchmark_functions_edited/f1829.py | def f(lst: list):
return max(set(lst), key=lst.count)
assert f([5, 5, 5]) == 5 |
benchmark_functions_edited/f8810.py | def f(a, b):
if a % b == 0:
return b
return f(b, a % b)
assert f(2, 10) == 2 |
benchmark_functions_edited/f4513.py | def f(cov, offsets_3p):
return offsets_3p[0] * cov + offsets_3p[1]
assert f(0, (1, 2)) == 2 |
benchmark_functions_edited/f14515.py | def f(map_size: int, lod: int) -> int:
if lod == 0:
return 4
if lod == 1 or map_size <= 1024:
return 8
if lod == 2 or map_size <= 2048:
return 16
return 32
assert f(8192, 1) == 8 |
benchmark_functions_edited/f12169.py | def f(x, y):
assert(isinstance(x, int))
assert(isinstance(y, int))
assert(0 <= x < 100)
assert(0 <= y < 100)
return x + y
assert f(0, 5) == 5 |
benchmark_functions_edited/f6803.py | def f(score, opponent_score):
# BEGIN PROBLEM 12
"*** REPLACE THIS LINE ***"
""
return 4
# END PROBLEM 12
assert f(1, 0) == 4 |
benchmark_functions_edited/f7713.py | def f(d):
try:
v=list(d.values())
k=list(d.keys())
return k[v.index(max(v))]
except:
return 9999
assert f( {1:100} ) == 1 |
benchmark_functions_edited/f11287.py | def f(check_list):
column_width = 0
for item in check_list:
if len(str(item)) > column_width:
column_width = len(str(item))
return column_width
assert f(range(1, 5)) == 1 |
benchmark_functions_edited/f4665.py | def f(numlist):
count = 0
for num in numlist:
if num % 2 == 1:
count += 1
return count
assert f(list()) == 0 |
benchmark_functions_edited/f4387.py | def f(value):
return float(value) / (100 * 1000)
assert f(0) == 0 |
benchmark_functions_edited/f2626.py | def f(mm_value):
if mm_value == 'None':
return None
return float(mm_value) / 1000
assert f(1000) == 1 |
benchmark_functions_edited/f4871.py | def f(x,y, def_value=0):
try:
return x/y
except:
return def_value
assert f(0,1) == 0 |
benchmark_functions_edited/f12021.py | def f(scale, search_note):
for i, note in enumerate(scale):
# Deal with situations where we have a list of enharmonic
# equivalents, as well as just a single note as and str.
if type(note) == list:
if search_note in note:
return i
elif type(note) == str:
if search_note == note:
return i
assert f... |
benchmark_functions_edited/f10921.py | def f(position, limit, buffer):
if position < 0 - buffer:
return limit + buffer
elif position > limit + buffer:
return -buffer
else:
return position
assert f(0, 100, 20) == 0 |
benchmark_functions_edited/f10437.py | def f(fn: float, fp: float, tp: float) -> float:
try:
calc = tp / (tp + fn + fp)
except ZeroDivisionError:
calc = 0
return calc
assert f(0.0, 0.0, 0.0) == 0 |
benchmark_functions_edited/f4293.py | def f(passW):
count = 0
for i in passW:
if(i.isupper()):
count+=1
return count
assert f("123456") == 0 |
benchmark_functions_edited/f10033.py | def f(x1, y2, x2, y1):
res = (x1 - x2)*(y1 - y2)
return res
assert f(1, 3, 2, 3) == 0 |
benchmark_functions_edited/f10235.py | def f(d, key_name):
for name, value in d.items():
if name.lower() == key_name.lower():
return value
return None
assert f(
{'foo': 1, 'bar': 2, 'baz': 3}, 'FOO') == 1 |
benchmark_functions_edited/f6538.py | def f(a, b):
if a > b:
return f(b, a)
if a < 0:
return f(0-a, b)
if a == 0:
return b
return f(b % a, a)
assert f(10, 5) == 5 |
benchmark_functions_edited/f953.py | def f(a, b):
result = a + b
return result
assert f(9, 0) == 9 |
benchmark_functions_edited/f12615.py | def f(host):
if host.strip() == '':
return 0
else:
raw_parts = host.strip().split('.')
parts = [p for p in raw_parts if p != '']
return len(parts)
assert f(**{'host': 'facebook.com'}) == 2 |
benchmark_functions_edited/f3542.py | def f(v0, v1, t):
return v0 + ((v1 - v0) * t)
assert f(1, 5, 0) == 1 |
benchmark_functions_edited/f8684.py | def f(x):
return 0 if x <= 0.5 else 1
assert f(0) == 0 |
benchmark_functions_edited/f5520.py | def f(Education):
if Education == 'Graduate':
return 1
else:
return 0
assert f(2) == 0 |
benchmark_functions_edited/f12808.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 = x * 0
for power,c in enumerate(coefs):
result += c * (x ** (power+1))
return result
... |
benchmark_functions_edited/f11900.py | def f(x, y, max_iters):
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:
return i
return max_iters
assert f(-1, -1, 100) == 2 |
benchmark_functions_edited/f1919.py | def f(ni, nf):
#ni, nf = node objects
return 1.0
assert f(3, 0) == 1 |
benchmark_functions_edited/f10099.py | def f(x):
# check if input value is negative or positive
if x < 0:
return print("Factorials do not exist for negative numbers.")
else:
y = 1
for i in range(1, x + 1):
y = y * i
return y
assert f(0) == 1 |
benchmark_functions_edited/f1508.py | def f(p):
return (299.0 * p[0] + 587.0 * p[1] + 114.0 * p[2]) / 1000.0
assert f((1, 1, 1)) == 1 |
benchmark_functions_edited/f1342.py | def f(Array):
X = min(Array)+ (max(Array)-min(Array))/2
return X
assert f( [ 1, 2, 3, 4, 5 ] ) == 3 |
benchmark_functions_edited/f7854.py | def f(arr):
lo, hi = 0, len(arr)
while lo < hi:
mid = lo + hi >> 1
if arr[mid]: hi = mid
else: lo = mid + 1
return lo
assert f([0, 0, 1, 1]) == 2 |
benchmark_functions_edited/f13152.py | def f(radius, inside, n):
area = 4 * radius # area of square surrounding circle
result = area * (inside/n)
return result
assert f(1, 1, 1) == 4 |
benchmark_functions_edited/f7021.py | def f(lhs, rhs):
if lhs == None:
if rhs == None:
return 0
else:
return -1
else:
if rhs == None:
return 1
else:
return (lhs > rhs) - (lhs < rhs)
assert f(1, 1) == 0 |
benchmark_functions_edited/f1243.py | def f(data):
return len(data["traceEvents"])
assert f(
{'traceEvents': [
{'cat': 'cat1', 'name': 'name1'},
{'cat': 'cat2', 'name': 'name2'},
]}
) == 2 |
benchmark_functions_edited/f2322.py | def f(numerator, denominator):
return numerator/denominator if denominator else 0
assert f(10, 0) == 0 |
benchmark_functions_edited/f9548.py | def f(m: int, n: int) -> float:
res = 1.0
i = abs(n)
while i:
if i & 1:
res *= m
m *= m
i = i >> 1
if n < 0:
return 1.0 / res
return int(res)
assert f(2, 3) == 8 |
benchmark_functions_edited/f13104.py | def f(v: float, min_clip: float, max_clip: float):
# Clip value
if v > max_clip:
v = max_clip
if v < min_clip:
v = min_clip
return v
assert f(0, 2, 3) == 2 |
benchmark_functions_edited/f7674.py | def f(p, q):
# Iterateive Version is faster and uses much less stack space
while q != 0:
if p < q: (p,q) = (q,p)
(p,q) = (q, p % q)
return p
assert f(12, 9) == 3 |
benchmark_functions_edited/f925.py | def f(t1, t2, w1, w2, decay_factor):
return w1 * w2 * decay_factor
assert f(1, 0, 0, 1, 1) == 0 |
benchmark_functions_edited/f6871.py | def f(x: int) -> int:
num_bits = 0
while (x != 0):
x = x >> 1
num_bits += 1
return max(num_bits, 1)
assert f(255) == 8 |
benchmark_functions_edited/f9303.py | def f(arr):
a, b = set(arr)
return a if arr.count(a) == 1 else b
assert f( [1,1,1,3,3] ) == 3 |
benchmark_functions_edited/f3700.py | def f(coroutine):
if hasattr(coroutine, '__await__'):
return coroutine.__await__()
else:
return coroutine
assert f(f(f(1))) == 1 |
benchmark_functions_edited/f4728.py | def f(s):
rv = None
try:
rv = int(s)
except ValueError:
rv = int(float(s))
return rv
assert f(1.0) == 1 |
benchmark_functions_edited/f8392.py | def f(string):
message = 0
messageCount = len(string) - 1
for letter in string:
message += (256**messageCount) * ord(letter)
messageCount -= 1
return message
assert f(u"") == 0 |
benchmark_functions_edited/f4324.py | def f(a, b, A, B, C):
return A/3*(b**3 - a**3) + B/2*(b**2 - a**2) + C*(b - a)
assert f(0, 0, 1, 1, 1) == 0 |
benchmark_functions_edited/f2276.py | def f(box):
if box is None:
return 0
x0, y0, x1, y1 = box
return (x1 - x0) * (y1 - y0)
assert f((0, 0, 0, 0)) == 0 |
benchmark_functions_edited/f1295.py | def f(wavlen, plslp, const):
return const*wavlen**plslp
assert f(1, 2, 1) == 1 |
benchmark_functions_edited/f7450.py | def f(x, eqn):
m, b = eqn
return (m * x) + b
assert f(1, (1, 0)) == 1 |
benchmark_functions_edited/f14472.py | def f(obj, attr, *args, **kwargs):
op = getattr(obj, attr, None)
if callable(op):
return op(*args, **kwargs)
assert f(1, "from_bytes", b"\x00\x01", "big") == 1 |
benchmark_functions_edited/f417.py | def f(n, i=0):
if n / 2 < 1:
return i
return f(n/2, i+1)
assert f(4) == 2 |
benchmark_functions_edited/f9013.py | def f(A):
if not A:
return None
if len(A) == 1:
return A[0]
x = A[0]
for i in range(1, len(A)):
x ^= A[i]
return x
assert f([2, 2]) == 0 |
benchmark_functions_edited/f12779.py | def f(json_input, keys_path):
if not isinstance(json_input, dict):
return ""
keys = keys_path.split(".")
try:
value = json_input[keys[0]]
for key in keys[1:]:
value = value[key]
return value
except KeyError:
return ""
assert f({"a": {"b": {"c": 3}}}, ... |
benchmark_functions_edited/f3995.py | def f(k, n):
if (n % 2) == 0:
return((k + 3) % 255)
else:
return((k + 5) % 255)
assert f(1, 2) == 4 |
benchmark_functions_edited/f835.py | def f(x, g):
x = x[0]
g[0] = 2*x
return x**2
assert f([2], [0]) == 4 |
benchmark_functions_edited/f12565.py | def f(predicate, when_true_fn, value):
if predicate(value):
return when_true_fn(value)
return value
assert f(lambda x: x == 10, lambda x: x, 5) == 5 |
benchmark_functions_edited/f7886.py | def f(string):
counts = dict()
words = string.split()
for word in words:
if word in counts:
counts[word] += 1
else:
counts[word] = 1
return len(counts)
assert f(u"apple apple apple") == 1 |
benchmark_functions_edited/f11972.py | def f(num1, num2):
if num1 > num2:
bigger = num1
else:
bigger = num2
while True:
if bigger % num1 == 0 and bigger % num2 == 0:
return bigger
bigger += 1
assert f(1, 9) == 9 |
benchmark_functions_edited/f5948.py | def f(settings):
return len(settings['keyframes']) - 1 + settings['render']['loop']
assert f(
{ 'keyframes': [
{ 'frame': 0, 'pos': [0, 0, 0], 'rot': [0, 0, 0, 1] },
{ 'frame': 1, 'pos': [0, 0, 0], 'rot': [0, 0, 0, 1] },
],
'render': { 'loop': 1 },
}
) == 2 |
benchmark_functions_edited/f7009.py | def f(a=(0, 0, 0), b=(0, 0, 0)):
assert len(a) == len(b)
ax, ay, az = a
bx, by, bz = b
return max(abs(ax - bx), abs(ay - by), abs(az - bz))
assert f(
(0, 0, 0),
(-1, 0, -1)
) == 1 |
benchmark_functions_edited/f2297.py | def f(l):
return 2*l + 1
assert f(1) == 3 |
benchmark_functions_edited/f9528.py | def f(s1, s2, m, n):
if m == 0 or n == 0:
return 0
elif s1[m - 1] == s2[n - 1]:
return 1 + f(s1, s2, m - 1, n - 1)
else:
return max(
f(s1, s2, m - 1, n),
f(s1, s2, m, n - 1)
)
assert f(
'abc',
'abc',
3,
3
) == 3 |
benchmark_functions_edited/f558.py | def f(dim, q):
return len(q) - (dim + 2)
assert f(2, [1, 2, 3, 4, 5, 6]) == 2 |
benchmark_functions_edited/f11384.py | def f(name):
ENGLISH_NAMES = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December']
try:
return ENGLISH_NAMES.index(name) + 1
except ValueError:
return None
assert f('January') == 1 |
benchmark_functions_edited/f11852.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(0, 0, 100, 0, 100) == 0 |
benchmark_functions_edited/f5030.py | def f(base_minor, base_major, height):
# You have to code here
# REMEMBER: Tests first!!!
return ((base_minor + base_major)*height)/2
assert f(1, 5, 2) == 6 |
benchmark_functions_edited/f8900.py | def f(seq, fn):
best = seq[0]; best_score = fn(best)
for x in seq:
x_score = fn(x)
if x_score > best_score:
best, best_score = x, x_score
return best
assert f(range(10), lambda x: x ** 2) == 9 |
benchmark_functions_edited/f2214.py | def f(value):
return max(1, round((value / 255) * 6))
assert f(255) == 6 |
benchmark_functions_edited/f10786.py | def f(v, arr):
array_center = len(arr) // 2
i = arr.index(v)
return abs(array_center - i)
assert f(3, [3]) == 0 |
benchmark_functions_edited/f3535.py | def f(val):
return (val * 2) - 1
assert f(.5) == 0 |
benchmark_functions_edited/f8695.py | def f(list_substrings, big_string):
for ind, substr in enumerate(list_substrings):
if big_string.find(substr) != -1:
return ind
return list_substrings.index("Uncategorized")
assert f(
["apples", "oranges", "bananas"], "apples and oranges"
) == 0 |
benchmark_functions_edited/f9182.py | def f(obj):
try:
return int(obj) if obj else obj
except ValueError:
return 0
assert f('I am a string') == 0 |
benchmark_functions_edited/f503.py | def f(x):
return ((x - 1) / 8 - 0.5) * 2
assert f(9) == 1 |
benchmark_functions_edited/f4299.py | def f(lower, upper, body_fun, init_val):
val = init_val
for i in range(lower, upper):
val = body_fun(i, val)
return val
assert f(1, 4, lambda i, val: val + 2, 1) == 7 |
benchmark_functions_edited/f11537.py | def f(current_avg: float, new_value: float, total_count: int) -> float:
new_average = float(current_avg)
new_average -= new_average / total_count
new_average += new_value / total_count
return new_average
assert f(2, 5, 3) == 3 |
benchmark_functions_edited/f14288.py | def f(coord, im_height_or_width=512):
return int(coord * im_height_or_width)
assert f(0.0) == 0 |
benchmark_functions_edited/f11791.py | def f(str_one, str_two):
len_one = len(str_one)
len_two = len(str_two)
if len_one != len_two:
raise ValueError("Strings have different lengths.")
mismatches = 0
for i in range(len_one):
if str_one[i] != str_two[i]:
mismatches += 1
return mismatches
assert f(b"GC", ... |
benchmark_functions_edited/f9472.py | def f(n):
if n == 0: # base cases
return 0
elif n == 1:
return 1
else: # general case
return (f(n-1) + f(n-2)) # use recursion
assert f(0) == 0 |
benchmark_functions_edited/f4371.py | def f(unit, tile):
return abs(tile['x'] - unit['x']) + abs(tile['y'] - unit['y'])
assert f(
{'x': 2, 'y': 0},
{'x': 1, 'y': 0}
) == 1 |
benchmark_functions_edited/f1255.py | def f(b):
return 0 if b==0 else (1 if b&1==1 else 0) + f(b>>1)
assert f(29) == 4 |
benchmark_functions_edited/f4633.py | def f(l:list):
if l == []:
return 0
else:
l.pop()
return 1 + f(l)
assert f([]) == 0 |
benchmark_functions_edited/f1771.py | def f(x):
if x < 0:
return -1
if x > 0:
return 1
return 0
assert f(2.5) == 1 |
benchmark_functions_edited/f14368.py | def f(n: int) -> int:
if not isinstance(n, int):
raise TypeError('Parameter n must an integer')
if n < 0:
raise ValueError('Parameter n must be non-negative')
if n == 0:
return 0
if n == 1:
return 1
return f(n - 1) + f(n - 2)
assert f(5) == 5 |
benchmark_functions_edited/f11.py | def f(z):
return z[0] * 1.3
assert f([0, 1]) == 0 |
benchmark_functions_edited/f13440.py | def f(severity: int) -> int:
if 1 <= severity <= 30:
demisto_severity = 1
elif 31 <= severity <= 70:
demisto_severity = 2
elif 71 <= severity <= 100:
demisto_severity = 3
else:
demisto_severity = 0
return demisto_severity
assert f(40) == 2 |
benchmark_functions_edited/f12268.py | def f(dictionary, element):
dictionary.setdefault(element, 0)
dictionary[element] += 1
return dictionary[element]
assert f(dict(), 2) == 1 |
benchmark_functions_edited/f9927.py | def f(W, z, wav):
F = W**2/(z*wav)
return F
assert f(1, 1, 1) == 1 |
benchmark_functions_edited/f13046.py | def f(text_string, char_set):
idx = 0
for this_char in text_string:
if this_char in char_set:
idx = idx + 1
else:
break
return idx
assert f('banana', set('asdf')) == 0 |
benchmark_functions_edited/f9589.py | def f(n):
if (n == 1 or n == 0):
return 1 # Base Case
elif (n > 1):
return f(n-1)*n
assert f(0) == 1 |
benchmark_functions_edited/f9341.py | def f(counts,player):
remaining = 0
player_info = {"w": "wW@","b":"bB$"}
for each in player_info["w" if player=="b" else "b"]:
if each in counts.keys():
remaining+=counts[each]
return remaining
assert f( {"wW@": 0, "bB$": 0}, "b") == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.