file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f10436.py
def f(L, b): smallest = b i = b + 1 while i != len(L): if L[i] < L[smallest]: smallest = i i = i + 1 return smallest assert f([3, -1, 7, 5], 3) == 3
benchmark_functions_edited/f7444.py
def f(filen): cname = '' for c in filen: if c.isdigit(): cname += c return int(cname) assert f('image_1.npy') == 1
benchmark_functions_edited/f2014.py
def f(value_db): return 10**(value_db*0.05) assert f(0) == 1
benchmark_functions_edited/f12349.py
def f(degree): return sum(range(1, degree + 2)) assert f(2) == 6
benchmark_functions_edited/f9491.py
def f(obj, *fields): try: for f in fields: obj = obj[f] return obj except: return None assert f([1, 2, 3], 0) == 1
benchmark_functions_edited/f12845.py
def f(a, b): if(b==0): return a else: return f(b, a % b) assert f(2, 3) == 1
benchmark_functions_edited/f10714.py
def f(a: int, d: float, n: int) -> int: assert n > 0, n return n * (2 * a + int((n - 1) * d)) // 2 assert f(1, 2, 1) == 1
benchmark_functions_edited/f9227.py
def f(n: int, m: int) -> int: return (n + m - 1) & ~(m - 1) assert f(0, 3) == 0
benchmark_functions_edited/f6747.py
def f(target, collection, key): occurences = sum([1 for item in collection if key(item) == key(target)]) return occurences assert f(4, [1, 2, 3, 4, 5], lambda x: x) == 1
benchmark_functions_edited/f1453.py
def f(x): if x < -1: return -x else: return x assert f(0) == 0
benchmark_functions_edited/f9124.py
def f(nums): if nums == []: return None tally = {} M = nums[0] for x in nums: tally[x] = tally.get(x, 0) + 1 if tally[x] > tally[M]: M = x return M assert f(range(2, 10000, 2)) == 2
benchmark_functions_edited/f3761.py
def f(fun, *args, **kwargs): if not hasattr(fun, "_has_run"): fun._has_run = True return fun(*args, **kwargs) assert f(lambda: 0) == 0
benchmark_functions_edited/f11645.py
def f(platelets_count: int) -> int: if platelets_count < 20_000: return 4 if platelets_count < 50_000: return 3 if platelets_count < 100_000: return 2 if platelets_count < 150_000: return 1 return 0 assert f(200_000) == 0
benchmark_functions_edited/f10081.py
def f(score, opponent_score): "*** YOUR CODE HERE ***" return 5 assert f(0, -1) == 5
benchmark_functions_edited/f4558.py
def f(x: float, minval: float, maxval: float) -> float: if x >= maxval: return maxval elif x <= minval: return minval return x assert f(4, 2, 4) == 4
benchmark_functions_edited/f10369.py
def f(thread): if not thread['children']: return 0 return max( max([f(reply) for reply in thread['children']]), len(thread['children']) ) assert f( {'children': [{'children': [],'reply_count': 1}]} ) == 1
benchmark_functions_edited/f6463.py
def f(F, E): x = 1 for y, z in zip(F, E): x *= y**z return x assert f([5, 5], [0]) == 1
benchmark_functions_edited/f2118.py
def f(year): return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) assert f(2027) == 0
benchmark_functions_edited/f5425.py
def f(d): # https://stackoverflow.com/a/23499101 if isinstance(d, dict): return 1 + (max(map(dict_depth, d.values())) if d else 0) return 0 assert f({1: {1: 1}, 2: {2: 2}, 3: {3: 3}}) == 2
benchmark_functions_edited/f12563.py
def f(click_time_one, click_time_two): delta_time = abs(click_time_two -click_time_one) norm_num = 60*60*24 delta_time = delta_time/ norm_num return 1/(1+delta_time) assert f(1, 1) == 1
benchmark_functions_edited/f11237.py
def f(n): result = n N = n p = 2 while p*p < N: if n % p == 0: while n % p == 0: n = n//p result -= result//p p += 1 if n > 1: result -= result//n return result assert f(2) == 1
benchmark_functions_edited/f5532.py
def f(a, b): jac = 1 - (a * b) / (2 * abs(a) + 2 * abs(b) - a * b) return jac assert f(1, 0) == 1
benchmark_functions_edited/f11121.py
def f(x,y,coeff): a,b,c,d,e,f,g,h,i,j = coeff return a + x*(x*(x*g + d) + b) + y*(y*(y*j + f) + c) + x*y*(e + x*h + y*i) assert f(1,2,[0,0,0,0,0,0,1,0,0,0]) == 1
benchmark_functions_edited/f4863.py
def f(number): return number / 1024 ** 2 assert f(1024 * 1024) == 1
benchmark_functions_edited/f8542.py
def f(lst: list) -> int: assert len(lst) == 2 return lst[1] - lst[0] assert f([2, 3]) == 1
benchmark_functions_edited/f3262.py
def f(line): i = 0 while i < len(line) and line[i] == ' ': i += 1 return i assert f(" \n") == 1
benchmark_functions_edited/f6102.py
def f(tcp_flags): if tcp_flags == 0x12: return 1 else: return 0 assert f(0x21) == 0
benchmark_functions_edited/f13012.py
def f(node): if node is None: return 0 length = 1 first_node = node while node.next: node = node.next if first_node is node: return length length += 1 return length assert f(None) == 0
benchmark_functions_edited/f3052.py
def f(summing_set, A): return sum(A[i - 1] for i in summing_set) assert f(set([1]), [1]) == 1
benchmark_functions_edited/f12958.py
def f(max_words, word_ngrams): max_words_with_ng = 1 for ng in range(word_ngrams): max_words_with_ng += max_words - ng return max_words_with_ng assert f(6, 1) == 7
benchmark_functions_edited/f3559.py
def f(x, a1, a2, a3, a4, a5): A = 1 + a1*x**2 + a2 * x**3 + a3 * x**4 B = 1 + a4*x**2 + a5 * x**4 return A/B**2 assert f(0, 0, 0, 0, 0, 0) == 1
benchmark_functions_edited/f4385.py
def f(byte_data): if isinstance(byte_data, (int)): return byte_data else: return int.from_bytes(byte_data, 'big') assert f(b'\x05') == 5
benchmark_functions_edited/f5499.py
def f(depths): return sum(x < y for x, y in zip(depths, depths[1:])) assert f([199, 200, 208, 210, 200, 207, 240, 269, 260, 263]) == 7
benchmark_functions_edited/f7637.py
def f(mdata): if mdata == None: return 1 if len(mdata) == 0: return 1 rlen = len(mdata[0]) for row in mdata: if len(row) != rlen: return 0 return 1 assert f([[1, 1], [1], [1, 1, 1]]) == 0
benchmark_functions_edited/f9845.py
def f(x: int, y: int = 5): #return np.max(x, y) return x assert f(3) == 3
benchmark_functions_edited/f5226.py
def f(epoch_i, base_lr, milestone, lr_mult): ind = [i for i, s in enumerate(milestone) if epoch_i >= s][-1] lr = base_lr * (lr_mult ** ind) return lr assert f(3, 2, [1, 3], 1) == 2
benchmark_functions_edited/f10560.py
def f(criterion, xs, y): #y.shape = bs * seqlen loss = 0. for x in xs: loss += criterion(x, y) loss /= len(xs) return loss assert f(lambda x, y: x, [1, 2, 3], 6) == 2
benchmark_functions_edited/f4575.py
def f(list_of_integers): if list_of_integers: list_of_integers.sort() return list_of_integers[-1] assert f([-1, 0, 1, 2, 3, 4]) == 4
benchmark_functions_edited/f4088.py
def f(K): return 9.0 / 5.0 * K assert f(0) == 0
benchmark_functions_edited/f9864.py
def f(km): #convert km to miles: return km*0.621371 assert f(0) == 0
benchmark_functions_edited/f11107.py
def f(guess, answer, turns): if guess > answer: print("Too High") return turns - 1 elif guess < answer: print("Too Low") return turns - 1 else: print(f" You got it! The answer was {answer} ") assert f(2, 1, 2) == 1
benchmark_functions_edited/f10374.py
def f(num): assert num >= 0 # this is much faster than you would think, AND it is easy to read ;) return len(bin(num)) - 2 assert f(8) == 4
benchmark_functions_edited/f14011.py
def f(r, ra, b0, bi): b = b0 + (bi - b0) / (1 + (ra / r)) return b assert f(1, 1, 2, 2) == 2
benchmark_functions_edited/f8795.py
def f(xvals,yvals): return (xvals[1]*yvals[0]-xvals[0]*yvals[1])/(xvals[1]-xvals[0]) assert f( (1, 0), (-1, 1) ) == 1
benchmark_functions_edited/f2733.py
def f(value, n): if value & (1 << n): return 1 else: return 0 assert f(0b00000001, 4) == 0
benchmark_functions_edited/f10918.py
def f(S, n): if n == 1: # reached the left most item return S[n-1] else: previous = f(S, n-1) current = S[n-1] if previous > current: return previous else: return current assert f(range(1000), 5) == 4
benchmark_functions_edited/f8291.py
def f(data: bytes) -> int: return ord(data[0:1]) + (ord(data[1:2]) * 0x100) + (ord(data[2:3]) * 0x10000) + (ord(data[3:4]) * 0x1000000) assert f(b'\x01\x00\x00\x00') == 1
benchmark_functions_edited/f10959.py
def f(values, value) -> int: return min(values, key=lambda x:abs(x-value)) assert f(list(range(10)), 3) == 3
benchmark_functions_edited/f1117.py
def f(i): res = 0 while i > 0: res += i&1 i>>=1 return res assert f(36) == 2
benchmark_functions_edited/f8452.py
def f(seq): seq = sorted(seq) return seq[len(seq)//2] assert f(range(0, 4)) == 2
benchmark_functions_edited/f4277.py
def f(number:int) -> int: n = 0 for letter in [l for l in str(number)]: n += int(letter)**2 return n assert f(1)==1
benchmark_functions_edited/f11319.py
def f(lca, lcb): la, lb = len(lca), len(lcb) return abs(la - lb) / float(max(la, lb) + 1e-5) assert f([], []) == 0
benchmark_functions_edited/f8718.py
def f(parsed_list): number_graded = len(parsed_list) return number_graded assert f([]) == 0
benchmark_functions_edited/f1157.py
def f(x, a, b, c, d, g): return d + ((a - d) / (1 + (x / c) ** b) ** g) assert f(1000, 1, 1, 1, 1, 1) == 1
benchmark_functions_edited/f6260.py
def f(func, exceptions): try: return func() except exceptions: return None assert f(lambda: 2**2, ZeroDivisionError) == 4
benchmark_functions_edited/f8066.py
def f(iterable): largest_key = 0 for key in iterable: if len( key ) > largest_key: largest_key = len( key ) return largest_key assert f( [ "a", "b", "ca", "de" ] ) == 2
benchmark_functions_edited/f13594.py
def f(x, y, bitsize=16): cap = 2 ** bitsize - 1 total = x + y if total > cap: total -= cap return total assert f(0, 2, 2) == 2
benchmark_functions_edited/f2705.py
def f(bit_count): return (bit_count + 7) // 8 assert f(3) == 1
benchmark_functions_edited/f13663.py
def f(first_dna, second_dna): hamming_distance = 0 for index in range(len(first_dna)): if first_dna[index] != second_dna[index]: hamming_distance += 1 return hamming_distance assert f( 'CATCGTAATGACGGCCT', 'CATCGTAATGACGGCCT') == 0
benchmark_functions_edited/f7297.py
def f(outlier_tuple): outlier_count = 0 for item in outlier_tuple: if item == -1: outlier_count += 1 return outlier_count assert f(tuple([1, 1, 1, 1])) == 0
benchmark_functions_edited/f13089.py
def f(A, B): a = min(A, B) b = max(A, B) c = 1 if a != 0: for i in range(b - a + 1, b + 1): c *= i return c assert f(2, 0) == 1
benchmark_functions_edited/f8076.py
def f(n): reversed_n = n % 10 while n > 0: n /= 10 if n > 0: reversed_n *= 10 reversed_n += n % 10 return reversed_n assert f(-123456789012345678901234567890) == 0
benchmark_functions_edited/f12339.py
def f(population: list) -> int: fitnesses = [individual.fitness for individual in population] unique = set(fitnesses) return len(unique) assert f([]) == 0
benchmark_functions_edited/f7113.py
def f(prev_temp, prev_next_temp, prev_to_prev_temp, lamb): return prev_temp + lamb * (prev_next_temp - 2*prev_temp + prev_to_prev_temp) assert f(0, 0, 0, 0) == 0
benchmark_functions_edited/f9088.py
def f(a, b): if a["file_first_event"] > b["file_first_event"]: return 1 if a["file_first_event"] == b["file_first_event"]: return 0 else: return -1 assert f({"file_first_event": 20}, {"file_first_event": 20}) == 0
benchmark_functions_edited/f7116.py
def f(i:int): return (i * 2) + 1 assert f(2) == 5
benchmark_functions_edited/f2507.py
def f(i,j,num_of_nodes): return (i*num_of_nodes+j) assert f(0, 0, 5) == 0
benchmark_functions_edited/f2144.py
def f(xs): return next(iter(xs)) assert f(range(100000)) == 0
benchmark_functions_edited/f7156.py
def f(string, sub): count = start = 0 while True: start = string.find(sub, start) + 1 if start > 0: count+=1 else: return count assert f( "this is a test string", "is") == 2
benchmark_functions_edited/f11431.py
def f(a, b, c, d): # <<< if a*b == c*d: return 0 if a*b > c*d: return 1 return -1 assert f(3, 1, 1, 2) == 1
benchmark_functions_edited/f13111.py
def f(obj, ids): if isinstance(ids, str): return f(obj, ids.split(".")) elif len(ids) == 0: return obj else: if isinstance(obj, dict): _obj = obj[ids[0]] elif isinstance(obj, (list, tuple)): _obj = obj[int(ids[0])] else: _obj = getattr(obj, ids[0]) return f(_obj, ids[1:]) assert f([{"foo": 5}, {"foo": 6}], "1.foo") == 6
benchmark_functions_edited/f8004.py
def f(n, k): if k > n - k: k = n - k # Use symmetry of Pascal's triangle accum = 1 for i in range(1, k + 1): accum *= (n - (k - i)) accum /= i return accum assert f(3, 1) == 3
benchmark_functions_edited/f914.py
def f(order): return int(order) - 1 assert f(5) == 4
benchmark_functions_edited/f9547.py
def f(hashed, alphabet): number = 0 len_alphabet = len(alphabet) for character in hashed: position = alphabet.index(character) number *= len_alphabet number += position return number assert f((), ()) == 0
benchmark_functions_edited/f10595.py
def f(a, b): import string o = 0 for character in string.ascii_lowercase: a_count = a.count(character) b_count = b.count(character) difference = abs(a_count - b_count) if difference > 0: o += difference return o assert f( "abc", "xbbc") == 3
benchmark_functions_edited/f9377.py
def f(seq): i = (len(seq) - 1) // 2 return sorted(seq)[i] assert f([0, 1, 1, 1, 2, 3, 4]) == 1
benchmark_functions_edited/f1417.py
def f(deck_size, position, *_): return deck_size - position - 1 assert f(4, 0) == 3
benchmark_functions_edited/f1718.py
def f(a, b): if not b: return a _a = a % b return f(b, _a) assert f(10, 4) == 2
benchmark_functions_edited/f8701.py
def f(number): if number <= 0: raise ValueError("Only positive integers are allowed") step = 0 while number != 1: number = 3 * number + 1 if number % 2 else number // 2 step += 1 return step assert f(2) == 1
benchmark_functions_edited/f6843.py
def f(text1, text2): return text2.lower().count(text1.lower()) assert f( 'a', 'This is a test string. A') == 2
benchmark_functions_edited/f3328.py
def f(difficulty): if difficulty == "easy": return 10 elif difficulty == "hard": return 5 assert f("hard") == 5
benchmark_functions_edited/f7562.py
def f(arrival_order: int, service_order: int, capacity: int, net_size: int) -> int: return arrival_order * (service_order * (capacity + 2))**net_size assert f(0, 1, 2, 3) == 0
benchmark_functions_edited/f1310.py
def f(ntp: int, rate: int) -> int: return int((ntp >> 16) * rate) >> 16 assert f(0x80000001, 0) == 0
benchmark_functions_edited/f9565.py
def f(val, limit): return max(min(limit, val), -limit) assert f(1.5, 1) == 1
benchmark_functions_edited/f11966.py
def f(a, b): # GCD(a, b) = GCD(b, a mod b). steps = 0 while b != 0: steps += 1 # Calculate the remainder. remainder = a % b # Calculate GCD(b, remainder). a = b b = remainder # GCD(a, 0) is a. #return a return steps assert f(10, 50) == 2
benchmark_functions_edited/f11748.py
def f(nums): total = 0 is6 = False for num in nums: print("adding:", num, is6) if num == 6 or is6: is6 = True else: total += num if num == 7: is6 = False return total assert f(list()) == 0
benchmark_functions_edited/f8097.py
def f(val: str) -> int: return int(val, 16 if val.startswith('0x') else 8 if val.startswith('0o') else 10) assert f( '0x1' ) == 1
benchmark_functions_edited/f8404.py
def f(poly, x, prime): accum = 0 for coeff in reversed(poly): accum *= x accum += coeff accum %= prime return accum assert f((1, 2, 3), 3, 3) == 1
benchmark_functions_edited/f10780.py
def f(n: int, k: int) -> int: if 0 <= k <= n: ntok = 1 ktok = 1 for t in range(1, min(k, n - k) + 1): ntok *= n ktok *= t n -= 1 return ntok // ktok else: return 0 assert f(6, 6) == 1
benchmark_functions_edited/f8458.py
def f(loads): return loads.index(min(loads)) assert f([2, 1]) == 1
benchmark_functions_edited/f10248.py
def f(qstr): q30_sum = 0 q30_seq = 0 # q30 = 0 for q in qstr: # qual = ord(q) - 33 qual = q - 33 q30_sum += qual # if qual >= 30: # q30 += 1 q30_seq = q30_sum/len(qstr) return q30_seq assert f(b"!" * 100) == 0
benchmark_functions_edited/f11217.py
def f(glTF, name): if name is None: return -1 if glTF.get('materials') is None: return -1 index = 0 for material in glTF['materials']: if material['name'] == name: return index index += 1 return -1 assert f({'materials': [{'name': 'foo'}, {'name': 'bar'}]}, "foo") == 0
benchmark_functions_edited/f7302.py
def f(ages, t, **extras): return ages * t - t**2 / 2 assert f(2, 0) == 0
benchmark_functions_edited/f7434.py
def f(obj): try: return obj.id except AttributeError: return int(obj) assert f(1) == 1
benchmark_functions_edited/f6181.py
def f(L, X, Y): P = 0.0 if (L <= 0) : return P for I in range(L): P += X[I] * Y[I] return P assert f(3, [1,2,3], [0,0,0]) == 0
benchmark_functions_edited/f11743.py
def f(n): if n <= 1: return 0 elif n == 2: return 1 else: return f(n - 1) + f(n - 2) + \ f(n - 3) assert f(5) == 4
benchmark_functions_edited/f840.py
def f(x): result = 0 while x: result ^= 1 x &= x - 1 return result assert f(0b100011110011) == 1
benchmark_functions_edited/f8586.py
def f(x, c = 0): return c + max(0.0, x) assert f(-0.1) == 0
benchmark_functions_edited/f10540.py
def f(text): count = 0 terminals = '.;?!' for char in text: if char in terminals: count = count + 1 return count assert f( 'My name is Mario. My name is Luigi. And my name is <NAME>.') == 3
benchmark_functions_edited/f117.py
def f(data): return sum(data) / len(data) assert f(list([1, 2, 3])) == 2