file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f13635.py
|
def f(atom,big_table):
n = 0
bonds_per_pair = len(big_table[0])/len(big_table)
while atom > bonds_per_pair:
atom -= bonds_per_pair
n += 1
# n is the index of atom in the original atom list
# atom is now the index of the unit cell the atom came from
return n
assert f(2, [[1, 2], [3, 4]]) == 1
|
benchmark_functions_edited/f8759.py
|
def f(l):
if not isinstance(l, (list, tuple)):
return 0
if not isinstance(l[-1], (list, tuple)):
return 1
else:
return 1 + f(l[-1])
assert f([3]) == 1
|
benchmark_functions_edited/f2433.py
|
def f(a, b):
return a*b/(a+b)**2/(a+b+1)
assert f(0, 1) == 0
|
benchmark_functions_edited/f11246.py
|
def f(items, ruleKey, ruleValue):
count = 0
ruleDict = {
"type": 0,
"color": 1,
"name": 2
}
for i in items:
if i[ruleDict[ruleKey]] == ruleValue:
count += 1
return count
assert f(
[["phone", "blue", "pixel"], ["computer", "silver", "lenovo"], ["phone", "gold", "iphone"]], "type", "phone") == 2
|
benchmark_functions_edited/f12476.py
|
def f(func,*args,**kwargs):
# suppressing printing for now. this decorator is for demo only
if 0: print('status called "%s" with: args=%s, kwargs=%s'%(
func.__name__,str(args),str(kwargs)))
return func(*args,**kwargs)
assert f(lambda x:x+1,5) == 6
|
benchmark_functions_edited/f7233.py
|
def f(x):
MAX_LEN = 64
bin_str = '{:08b}'.format(x)
remaining = MAX_LEN - len(bin_str)
full_str = bin_str[::-1] + ('0' * remaining)
return int(full_str, 2)
assert f(9223372036854775808) == 1
|
benchmark_functions_edited/f6299.py
|
def f(name):
cnt = 0
for ch in name:
if ch == '_':
cnt += 1
return cnt
assert f('___') == 3
|
benchmark_functions_edited/f11161.py
|
def f(a_coordinates, b_coordinates):
x_diff = abs(a_coordinates[0] - b_coordinates[0])
y_diff = abs(a_coordinates[1] - b_coordinates[1])
z_diff = abs(a_coordinates[2] - b_coordinates[2])
return x_diff + y_diff + z_diff
assert f( (1,2,3), (4,5,6) ) == 9
|
benchmark_functions_edited/f3508.py
|
def f(a, b):
if a < b:
return a
return b
assert f(1, 2) == 1
|
benchmark_functions_edited/f8312.py
|
def f(binary_string: str) -> int:
if isinstance(binary_string, str):
return int(binary_string, 2)
elif isinstance(binary_string, list):
return int(''.join(binary_string), 2)
assert f('00110') == 6
|
benchmark_functions_edited/f9395.py
|
def f(key: str) -> int:
hash, index = 0, 0
index = 0
for letter in key:
hash += (index + 1) * ord(letter)
index += 1
return hash
assert f("") == 0
|
benchmark_functions_edited/f9109.py
|
def f(string, base=0):
try:
maybe = int(string, base=base)
except:
raise ValueError
if abs(maybe) != maybe:
raise ValueError
return maybe
assert f("1") == 1
|
benchmark_functions_edited/f9392.py
|
def f(d, e):
return (e % len(d) + len(d)) % len(d)
assert f(range(4), 7) == 3
|
benchmark_functions_edited/f10475.py
|
def f(bi,p,bigrams):
(w1,w2)=bi
return bigrams[w1][w2]*p
assert f( ('B','C'), 1, {'B': {'C': 1}}) == 1
|
benchmark_functions_edited/f5495.py
|
def f(prio):
return {"urgmust": 1, "must": 2, "high": 3, "medium": 4, "low": 5}.get(prio, 5)
assert f("low") == 5
|
benchmark_functions_edited/f6608.py
|
def f(gobal_coord, start, end, strand):
# swap if strands disagree
if strand == 1:
return gobal_coord - start
else:
return end - gobal_coord
assert f(100, 10, 100, 0) == 0
|
benchmark_functions_edited/f6652.py
|
def f(va,vb,vc,vag,vbg,vcg,ia,ib,ic,Zload,a):
return (1/2)*((-(ia-(va/Zload))/a).conjugate()*vag+(-(ib-(vb/Zload))/a).conjugate()*vbg+(-(ic-(vc/Zload))/a).conjugate()*vcg)
assert f(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1) == 0
|
benchmark_functions_edited/f4720.py
|
def f(chspec, idx):
irlen = 0
for (i, d) in enumerate(chspec):
if i < idx:
irlen += d[0]
return irlen
assert f(
[(1,10),(2,20),(3,30)],
0
) == 0
|
benchmark_functions_edited/f9720.py
|
def f(weight, distance):
m_d = weight
# v_d is in m/s
v_d = 5.70 * (m_d ** 0.16)
# convert to m
L_d = distance * 1000
# convert to hours
temp_time = L_d / v_d / 60 / 60
E_v = 300 / 4.184
E_f = m_d * E_v * temp_time
return E_f
assert f(125, 0) == 0
|
benchmark_functions_edited/f14362.py
|
def f(op_name, symbolic_fn, args):
try:
return symbolic_fn(*args)
except TypeError as e:
# Handle the specific case where we didn't successfully dispatch
# to symbolic_fn. Otherwise, the backtrace will have the clues
# you need.
e.args = ("{} (occurred when translating {})".format(e.args[0], op_name), )
raise
assert f(
'mul', lambda a, b: a * b, [2, 3]) == 6
|
benchmark_functions_edited/f10311.py
|
def f(speaker_lists):
flat_speaker_list = [speaker for speaker_list in speaker_lists for speaker in speaker_list]
speaker_set = set(flat_speaker_list)
speaker_set.discard("[SPL]")
speaker_set.discard("-")
return max(1, len(speaker_set))
assert f(
[["[SPL]", "Speaker1", "Speaker2"], ["Speaker1", "[SPL]", "Speaker3"]]
) == 3
|
benchmark_functions_edited/f9204.py
|
def f(num, edge, out_degree, in_degree):
out_d, in_d = [0]*num, [0]*num
for e in edge:
out_d[e[0]] = 1
in_d[e[-1]] = 1
if out_d == out_degree and in_d == in_degree:
return 1
else:
return 0
assert f(4, [[0, 1], [0, 2], [0, 3], [0, 0]], [1, 1, 1, 1], [1, 1, 0, 1]) == 0
|
benchmark_functions_edited/f1297.py
|
def binary_string_to_int (s) :
return int (s, 2)
assert f("00") == 0
|
benchmark_functions_edited/f5861.py
|
def f(value):
return (value - 32) / 1.8
assert f(32) == 0
|
benchmark_functions_edited/f1382.py
|
def f(x):
return int(x, 2)
assert f("1") == 1
|
benchmark_functions_edited/f13004.py
|
def f(x, y):
result = 0
for i, x_i in enumerate(x):
result = result + x_i * y[i]
return result
assert f((1,), (1,)) == 1
|
benchmark_functions_edited/f9555.py
|
def f(A, B):
if len(A) == len(B):
return len([i for i in range(len(A)) if A[i] == B[i]])
return None
assert f(
"AAAAA", "AAAAA") == 5
|
benchmark_functions_edited/f924.py
|
def f(f, x, h):
return (-3*f(x) + 4*f(x+h) - f(x+2*h)) / (2*h)
assert f(lambda x: x**2, 1, 1) == 2
|
benchmark_functions_edited/f9310.py
|
def f(score, buckets, low=1, high=5):
if not buckets or len(buckets) < 2:
return None
step = (high - low) / (len(buckets) - 1)
for i, (_, _, upper) in enumerate(buckets):
if score <= upper:
return low + i * step
return high
assert f(1, [(1, 1, 10), (10, 10, 20)]) == 1
|
benchmark_functions_edited/f2744.py
|
def f(n: int) -> int:
return (n + 1) // 2
assert f(12) == 6
|
benchmark_functions_edited/f3613.py
|
def f(present):
volume = 1
for side in present:
volume *= side
return volume
assert f([1]) == 1
|
benchmark_functions_edited/f11093.py
|
def f(array):
majority_elt = None
count = 0
for elt in array:
if elt != majority_elt:
if count == 0:
majority_elt = elt
count = 1
else:
count -= 1
else:
count += 1
return majority_elt
assert f([1, 2, 1, 2, 1, 2]) == 1
|
benchmark_functions_edited/f5838.py
|
def f(n: int) -> int:
return n * (n + 1) // 2
assert f(3) == 6
|
benchmark_functions_edited/f214.py
|
def f(el, m):
return el * (el + 1) + m
assert f(0, 1) == 1
|
benchmark_functions_edited/f7810.py
|
def f(numbers):
total = 0
for number in numbers:
try:
total = total + float(number)
except (ValueError, TypeError):
pass
return total
assert f((1, 2, 3)) == 6
|
benchmark_functions_edited/f13971.py
|
def f(text1: str, text2: str) -> int:
dp = [[0 for _ in range(len(text2) + 1)] for _ in range(len(text1) + 1)]
for i in range(len(text1)):
for j in range(len(text2)):
if text1[i] == text2[j]:
dp[i + 1][j + 1] = dp[i][j] + 1
else:
dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
return dp[-1][-1]
assert f(
'abcde',
'abcde'
) == 5
|
benchmark_functions_edited/f678.py
|
def f(a, b):
return (b[0] - a[0]) ** 2 + (b[1] - a[1]) ** 2
assert f((-1, -1), (0, 0)) == 2
|
benchmark_functions_edited/f12589.py
|
def f(val, attr):
try:
return getattr(val, str(attr))
except AttributeError:
return val[str(attr)]
assert f(1, "imag") == 0
|
benchmark_functions_edited/f8246.py
|
def f(free_text):
num_numeric_words = len(
[free_text for free_text in free_text.split() if free_text.isdigit()]
)
return num_numeric_words
assert f("12 3") == 2
|
benchmark_functions_edited/f12905.py
|
def f(n):
powList = []
for i in range(2, n + 1):
for j in range(2, n + 1):
powList.append(pow(i, j))
powList.sort()
numDistinct = 1
index = 1
while index < len(powList):
if powList[index] != powList[index - 1]:
numDistinct += 1
index += 1
return numDistinct
assert f(2) == 1
|
benchmark_functions_edited/f13431.py
|
def f(array):
array_sum = 0
max_sum = float("-inf")
for num in array:
array_sum += num
if array_sum > max_sum:
max_sum = array_sum
return max_sum
assert f( [1, 3, -2, 5, -2, -1]) == 7
|
benchmark_functions_edited/f3341.py
|
def f(arr, x):
for i in range(len(arr)):
if arr[i][0] == x[0]:
return i
return -1
assert f(
[(1, 0), (0, 1), (2, 3), (0, 2), (5, 4)], (5, 4)
) == 4
|
benchmark_functions_edited/f1260.py
|
def f(gl):
return -int(gl*10)
assert f(0) == 0
|
benchmark_functions_edited/f4656.py
|
def f(a: int, b: int) -> int:
return a ^ ((a ^ b) & -(a < b))
assert f(5, 5) == 5
|
benchmark_functions_edited/f6124.py
|
def f(val):
if val < 1 or type(val) != int:
raise ValueError("value passed must be a positive integer")
else:
return val
assert f(3) == 3
|
benchmark_functions_edited/f11843.py
|
def f(word, letter):
new = word.lower()
return new.count(letter)
assert f(
'Hello World', 'h'
) == 1
|
benchmark_functions_edited/f11402.py
|
def f(N):
if (N < 0): return -1 # Invalid range.
fibp, fib = 0, 1
if (N == fibp): return (fibp)
while(N > 1):
N, fibp, fib = (N - 1), fib, (fibp + fib)
return (fib)
assert f(5) == 5
|
benchmark_functions_edited/f1677.py
|
def f(strng: str) -> int:
return sum(c.islower() for c in strng)
assert f('abc') == 3
|
benchmark_functions_edited/f10297.py
|
def f(min, max, temp):
tp = (temp-min)/(max-min)
if tp > 1:
tp = 1
if tp < 0:
tp = 0
return tp
assert f(10, 20, 20.1) == 1
|
benchmark_functions_edited/f12610.py
|
def f(count1, count2):
if count1 == 'unknown' or count2 == 'unknown':
assert(count1 == 'unknown' and count2 == 'unknown')
return 'unknown'
assert(type(count1) == int and type(count2) == int)
return count1 + count2
assert f(1, 1) == 2
|
benchmark_functions_edited/f10129.py
|
def f(error, sl):
return (error - sl) ** 2
assert f(0.0002, 0.0002) == 0
|
benchmark_functions_edited/f10168.py
|
def f(l,n):
best = -1
best_i = -1
for i in range(len(l)):
if l[i] < n:
if n - l[i] < n - best:
best_i = i
best = l[i]
return best_i
assert f( [1,2,3,4,5,6], 7) == 5
|
benchmark_functions_edited/f3442.py
|
def f(lis, predicate):
return next((item for item in lis if predicate(item)), None)
assert f(range(10), lambda x: x == 5) == 5
|
benchmark_functions_edited/f14255.py
|
def f(pair1, pair2, x):
a = (pair2[1] - pair1[1])/(pair2[0] - pair1[0])
b = (pair1[1]*pair2[0] - pair1[0]*pair2[1])/(pair2[0] - pair1[0])
y = a*x+b
return y
assert f( [-1,2], [3,4], -1) == 2
|
benchmark_functions_edited/f10020.py
|
def f(limit, ubound=100):
assert limit is not None, 'limit must be provided'
limit = int(limit)
assert limit > 0, "limit must be positive"
assert limit <= ubound, "limit exceeds max (%d > %d)" % (limit, ubound)
return limit
assert f(5) == 5
|
benchmark_functions_edited/f1615.py
|
def f(*args):
for v in args[0]:
if v is not None:
return v
assert f((1, 2), (1, 2), (1, 2)) == 1
|
benchmark_functions_edited/f1975.py
|
def f(byt):
return int((byt * 100.0) / 255.0)
assert f(1) == 0
|
benchmark_functions_edited/f9819.py
|
def f(func):
while True:
returned_value = func()
if returned_value == None:
continue
else:
break
return returned_value
assert f(lambda: 3) == 3
|
benchmark_functions_edited/f14259.py
|
def f(pressure, R_od, t_wall):
return (pressure * R_od / t_wall)
assert f(1, 1, 1) == 1
|
benchmark_functions_edited/f14280.py
|
def f(ins_set):
acc = 0
executed = set()
i = 0
while i < len(ins_set):
if i in executed:
break
executed.add(i)
if ins_set[i][0] == "acc":
acc += ins_set[i][1]
i += ins_set[i][1] if ins_set[i][0] == "jmp" else 1
return acc
assert f( [("nop", 0), ("acc", 1), ("jmp", 4)] ) == 1
|
benchmark_functions_edited/f5025.py
|
def f(s):
hr, minute, sec = [float(x) for x in s.split(':')]
total_seconds = hr*3600 + minute*60 + sec
return total_seconds
assert f('00:00:00') == 0
|
benchmark_functions_edited/f544.py
|
def f(k, alpha=-11.0 / 3, fknee=1):
return (k / fknee) ** alpha
assert f(1) == 1
|
benchmark_functions_edited/f6012.py
|
def f(env_observation, info):
info_frame = info.get('frame')
if info_frame is not None:
return info_frame
return env_observation
assert f(0, {}) == 0
|
benchmark_functions_edited/f1559.py
|
def f(version_string):
major = int(version_string.split(".")[0])
return major
assert f("1.0000000000002") == 1
|
benchmark_functions_edited/f7186.py
|
def f(upperLimit):
squares = [x**2 for x in range(1,upperLimit+1)]
return sum(squares)
assert f(1) == 1
|
benchmark_functions_edited/f6070.py
|
def f(R, k, read_len):
return (4 ** k -1) * ( R * (read_len - k + 1) - (read_len - k) ) / (4 ** k + read_len - k - (R *(read_len - k +1)))
assert f(1, 2, 1) == 1
|
benchmark_functions_edited/f8828.py
|
def f(seq):
return sum(i is None for i in seq)
assert f((1, None, 3)) == 1
|
benchmark_functions_edited/f12013.py
|
def f(d, path):
if not isinstance(path, list):
raise LookupError("The path needs to be a list")
for step in path:
try:
d = d[step]
except KeyError:
return None
return d
assert f({'a': 1}, ['a']) == 1
|
benchmark_functions_edited/f622.py
|
def f(x, a, b, c, d, e):
return a + b*x + c*x*x + d*x*x*x
assert f(1, 0, 0, 0, 0, 0) == 0
|
benchmark_functions_edited/f11097.py
|
def f(text, word):
total_words = len(text)
word_in_text = text.count(word)
try:
return float(word_in_text) / float(total_words)
except ZeroDivisionError:
return 0
assert f(["hello:"], "hello:") == 1
|
benchmark_functions_edited/f982.py
|
def f(v, w):
return sum(v_i * w_i
for v_i, w_i in zip(v, w))
assert f( (1, -1), (1, 1)) == 0
|
benchmark_functions_edited/f749.py
|
def f(a,b,x):
return 1.0-(1.0-x**a)**b
assert f(2,1,1.0) == 1
|
benchmark_functions_edited/f2382.py
|
def f(ival, ipos, ilen):
ones = ((1 << ilen)-1)
return (ival & (ones << ipos)) >> ipos
assert f(0b0011, 0, 4) == 3
|
benchmark_functions_edited/f13580.py
|
def f(word, word2id_dict, OOV="<oov>"):
for each in (word, word.lower(), word.capitalize(), word.upper()):
if each in word2id_dict:
return word2id_dict[each]
return word2id_dict[OOV]
assert f(u"hello", {"hello": 0, "goodbye": 1}) == 0
|
benchmark_functions_edited/f13857.py
|
def f(start_miles, end_miles, amount_gallons):
mpg = abs(end_miles - start_miles) / amount_gallons
return mpg
assert f(100, 50, 10) == 5
|
benchmark_functions_edited/f11428.py
|
def f(c, tweets):
tp = 0
fp = 0
for tweet in tweets:
if c in tweet['predictions']:
if c in tweet['tags']:
tp+=1
else:
fp+=1
if(tp+fp == 0):
return float('nan')
else:
return tp/(tp+fp)
assert f(0, [{'predictions':[0],'tags':[0]}]) == 1
|
benchmark_functions_edited/f7782.py
|
def f(num):
if num.find("0x") != -1:
return int(num, 16)
else:
return int(num)
assert f("0x0001") == 1
|
benchmark_functions_edited/f4627.py
|
def f(key, key2Idx):
if key in key2Idx:
return key2Idx[key]
return key2Idx["UNKNOWN_TOKEN"]
assert f("the", {"the": 0, "UNKNOWN_TOKEN": 1}) == 0
|
benchmark_functions_edited/f6970.py
|
def f(testgen):
return len([ t[0](*t[1:]) for t in testgen() ])
assert f(lambda: [ (lambda x: x, (1,)),
(lambda x: x, (2,)),
(lambda x: x, (3,)),
(lambda x: x, (4,)) ]) == 4
|
benchmark_functions_edited/f12588.py
|
def f(i,j,k,nx,ny):
cell = (nx*j+i)+k*nx*ny
return cell
assert f(0,1,0,3,3) == 3
|
benchmark_functions_edited/f65.py
|
def f(pair):
y = pair[1]
return y
assert f((0, 0)) == 0
|
benchmark_functions_edited/f11766.py
|
def f(n, odd_term, even_term):
if n == 1:
return odd_term(1)
return (odd_term(n) if n % 2 == 1 else even_term(n)) + f(n - 1, odd_term, even_term)
assert f(2, lambda x: 1, lambda x: 0) == 1
|
benchmark_functions_edited/f1315.py
|
def f(target, bit):
return target | (1 << bit)
assert f(0, 2) == 4
|
benchmark_functions_edited/f2054.py
|
def f(x: int, y: int, a: int, b: int) -> float:
return ((x - a) ** 2 + (y - b) ** 2) ** .5
assert f(-3, 4, 0, 0) == 5
|
benchmark_functions_edited/f5900.py
|
def f( g, n=None ):
if n is None:
print(( ' Triples: '+str(len(g)) ))
else:
print(( ' Triples: +'+str(len(g)-n) ))
return len(g)
assert f( {(1,2), (2,3), (2,4)} ) == 3
|
benchmark_functions_edited/f7930.py
|
def f(files_list):
ret = 0
if len(files_list) > 0:
filename_lengths = [len(x) for x in files_list]
max_len = max(filename_lengths)
ret = max_len
return ret
assert f([]) == 0
|
benchmark_functions_edited/f11061.py
|
def f(seq):
if not seq:
raise ValueError("Input must be non-empty string")
g = seq.count("G")
c = seq.count("C")
return (g + c) / len(seq)
assert f('d') == 0
|
benchmark_functions_edited/f4572.py
|
def f(code):
return (code >> 5) & 0x7
assert f(2) == 0
|
benchmark_functions_edited/f7565.py
|
def f(s1, s2):
if len(s1) != len(s2):
raise ValueError("Undefined for sequences of unequal length")
return sum(ch1 != ch2 for ch1, ch2 in zip(s1, s2))
assert f("ACGTACGT", "ACGTACGT") == 0
|
benchmark_functions_edited/f8870.py
|
def f(x, rho, penalty):
lmbda = penalty / rho
return (x - lmbda) * (x >= lmbda) + (x + lmbda) * (x <= -lmbda)
assert f(3, 1, 1) == 2
|
benchmark_functions_edited/f3479.py
|
def f(s):
try:
return int(s or '0')
except ValueError:
return 0
assert f("") == 0
|
benchmark_functions_edited/f8664.py
|
def f(theta, cangle, jmf):
t1 = jmf(theta + cangle/2)**2
t2 = jmf(theta - cangle/2)**2
return t1 - t2
assert f(1, 1, lambda theta: 0) == 0
|
benchmark_functions_edited/f14019.py
|
def f(form):
level = 0
maxlevel = 0
for ch in form:
if(ch == '('):
level += 1
if(level > maxlevel):
maxlevel = level
elif(ch == ')'):
level -= 1
return maxlevel
assert f(
"()((()))()") == 3
|
benchmark_functions_edited/f1483.py
|
def f(a, b):
return 1. * len(a & b) / len(a | b)
assert f({1}, {1}) == 1
|
benchmark_functions_edited/f12100.py
|
def f(source: str, offset: int) -> int:
return source.encode("utf-8")[0:offset].count("\n".encode("utf-8")) + 1
assert f(
140
) == 6
|
benchmark_functions_edited/f13105.py
|
def f(x, percentile):
if x:
p_idx = int(percentile * len(x))
return sorted(x)[p_idx]
else:
raise ValueError('len of x == 0')
assert f((1,2,3), 0) == 1
|
benchmark_functions_edited/f10388.py
|
def f(heading_last, heading_current):
r = heading_current - heading_last + 180
return (r % 360) - 180
assert f(100, 100) == 0
|
benchmark_functions_edited/f8092.py
|
def f(binary_number: str) -> int:
# This feels like cheating.
# return int(binary_number, 2)
return sum(
int(digit) * (2 ** power) for power, digit in enumerate(binary_number[::-1])
)
assert f(
"0000000000000000000000000000000000000000000000000000000000000000"
) == 0
|
benchmark_functions_edited/f11593.py
|
def f(array: list) -> int:
lenght = len(array)
max_sum = array[0]
for start in range(lenght):
for end in range(start, lenght):
current_sum = sum(array[start : end + 1])
if current_sum > max_sum:
max_sum = current_sum
return max_sum
assert f([-1, 1, -2]) == 1
|
benchmark_functions_edited/f11652.py
|
def f(tword,codetree):
pos = 0
while True:
s = tword[pos]
if s not in codetree:
return 0
elif pos==len(tword)-1:
return 1
else:
pos += 1
codetree = codetree[s][1]
assert f(
'1234', {'1': [1,{'2': [1,{'3': [1,{'4': [1,{}]}]}]}]}) == 1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.