file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f5018.py
def f(point_a, point_b): return (point_a[0] - point_b[0])**2 + (point_a[1] - point_b[1])**2 assert f( (0, 0), (0, 0) ) == 0
benchmark_functions_edited/f8178.py
def f(temp): return ((temp - 491.67) * 5) / 9 assert f(491.67) == 0
benchmark_functions_edited/f11870.py
def f(poly, id): if id==0: return len(poly)-2 else: return id-1 assert f( [(0,0),(0,1),(1,1),(1,0),(0,0)], 3 ) == 2
benchmark_functions_edited/f482.py
def f(n): return n * (n + 1) // 2 assert f(2) == 3
benchmark_functions_edited/f561.py
def f(v, dfs_data): return dfs_data['lowpoint_1_lookup'][v] assert f(3, {'lowpoint_1_lookup': {0:0, 1:1, 2:2, 3:3}}) == 3
benchmark_functions_edited/f8415.py
def f(number): weights = (7, 5, 3, 2, 1, 7, 5, 3, 2) number = (9 - len(number)) * '0' + number check = 10 * sum(w * int(n) for w, n in zip(weights, number)) return check % 11 % 10 assert f( "2300000000000") == 4
benchmark_functions_edited/f3603.py
def f(lines, i): for j in range(i-1, -1, -1): if lines[j][1] == '': return j assert f( [ ('a', ''), ('b', ''), ('', ''), ('', 'c'), ('d', ''), ('', ''), ], 5 ) == 4
benchmark_functions_edited/f10669.py
def f(valor, lista, index): if len(lista) == 0 or index == len(lista): return -1 if lista[index] == valor: return index return f(valor, lista, index + 1) assert f(3, [3, 2, 3], 0) == 0
benchmark_functions_edited/f11950.py
def f(player_score, opponent_score): # BEGIN PROBLEM 4 if (player_score % 10) == (opponent_score % 10): return player_score % 10 else: return 0 # END PROBLEM 4 assert f(1, 10) == 0
benchmark_functions_edited/f2707.py
def f(lst, K): return lst[min(range(len(lst)), key = lambda i: abs(lst[i]-K))] assert f(range(100), 2) == 2
benchmark_functions_edited/f10295.py
def f(interval_1, interval_2): a, b = interval_1 c, d = interval_2 intersection = max(0, min(b, d) - max(a, c)) if intersection > 0: union = max(b, d) - min(a, c) else: union = (b - a) + (d - c) return intersection / union assert f( (-10, 10), (-10, 10), ) == 1
benchmark_functions_edited/f12993.py
def f(n, k, d={}): if k == 0: return 1 if n == 0: return 0 try: return d[n, k] except KeyError: res = f(n-1, k) + f(n-1, k-1) d[n, k] = res return res assert f(5, 4) == 5
benchmark_functions_edited/f576.py
def f(n): k = 1 while (k << 1) < n: k <<= 1 return k assert f(2) == 1
benchmark_functions_edited/f7887.py
def f(a, b, c): return round(((a + b + c) / 3), 2) assert f(-10, 0, 10) == 0
benchmark_functions_edited/f12423.py
def f(text, pos, char1, char2): depth = 1 for i in range(pos, len(text)): if text[i] == char1: depth += 1 elif text[i] == char2: depth -= 1 if depth == 0: return i return -1 assert f(r"hi(hi(hi))bye)", 4, r"(", r")") == 9
benchmark_functions_edited/f11284.py
def f(seq): for x in seq: if seq.count(x) % 2 != 0: return x assert f( [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5]) == 5
benchmark_functions_edited/f8685.py
def f(value): try: return int(value) except: # Not a bug or error, just for added clarity print("Not a valid entry. Try again.") return 0 assert f("a12") == 0
benchmark_functions_edited/f9698.py
def f(func, *args, exception=Exception, ret=False, **kwargs): try: return func(*args, **kwargs) except exception as e: return (None, e)[ret] assert f(len, ['x', 'y', 'z']) == 3
benchmark_functions_edited/f8239.py
def f(n): if n <= 1: return n return f(n-1) + f(n-2) assert f(2) == 1
benchmark_functions_edited/f1808.py
def f(x): try: return int(x) except: return x assert f(1) == 1
benchmark_functions_edited/f3345.py
def f(condition, expr1, expr2): if condition: return expr1 else: return expr2 assert f("1", 1, 2) == 1
benchmark_functions_edited/f10848.py
def f(time, tempo): return time * (60.0 / tempo) assert f(0, 300) == 0
benchmark_functions_edited/f5984.py
def f(adjMatrix): for j in range(len(adjMatrix)): adjMatrix[j].append(0) return len(adjMatrix[0])-1 assert f( [[1]] ) == 1
benchmark_functions_edited/f3457.py
def f(list): if list == (): return 0 else: _, tail = list return 1 + f(tail) assert f(()) == 0
benchmark_functions_edited/f1054.py
def f(n): c = 0 while n: c += n%2 n /= 2 return c assert f(0b00000000) == 0
benchmark_functions_edited/f2851.py
def f(n): if n < -1: return -1 elif n > 1: return 1 else: return n assert f(10000) == 1
benchmark_functions_edited/f2409.py
def f(level): return int((level * 255) / 100) assert f(0) == 0
benchmark_functions_edited/f8075.py
def f(number: int) -> int: number = abs(number) while number >= 10: number //= 10 return number assert f(-0) == 0
benchmark_functions_edited/f414.py
def f(cat): if cat == '6': return 1 return 0 assert f('0') == 0
benchmark_functions_edited/f7423.py
def f(center, min, max): true_center = ((max - min) // 2) + min if true_center != center: return true_center elif true_center == min: return max else: return min assert f(1, 2, 6) == 4
benchmark_functions_edited/f13650.py
def f(val, length): if length <= 8: return val if length <= 16: return (val & 0xFF00) >> 8 | (val & 0xFF) << 8 if length <= 32: return ((val & 0xFF000000) >> 24 | (val & 0x00FF0000) >> 8 | (val & 0x0000FF00) << 8 | (val & 0x000000FF) << 24) raise Exception('Cannot swap endianness for length ' + length) assert f(1, 8) == 1
benchmark_functions_edited/f4677.py
def f(a, *array): result = a for ele in array: result += ele return result assert f(1) == 1
benchmark_functions_edited/f1802.py
def f(items_list: list): return items_list[0] if items_list else None assert f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1
benchmark_functions_edited/f8048.py
def f(sequence): size = len(sequence) if size != 1: msg = f"Expected single element sequence, but had {size} entries ({sequence})" raise ValueError(msg) return next(iter(sequence)) assert f([2]) == 2
benchmark_functions_edited/f8241.py
def f(attr, key): assert isinstance(attr, dict) if key not in attr: raise AttributeError("Required attribute {} not found.".format(key)) return attr[key] assert f( {"a": 1, "b": 2, "c": 3}, "a") == 1
benchmark_functions_edited/f8228.py
def f(text, full_term, case_sensitive): if not case_sensitive: text = text.lower() full_term = full_term.lower() return 1 if text == full_term else 0 assert f("aB", "ab", True) == 0
benchmark_functions_edited/f3070.py
def f(a, b): xA, yA = a xB, yB = b return (xA - xB)**2 + (yA - yB)**2 assert f( (1, 0), (0, 0), ) == 1
benchmark_functions_edited/f3115.py
def f(j, max): if j > max: j %= max return j assert f(3, 5) == 3
benchmark_functions_edited/f11897.py
def f(numbers): slow = numbers[0] fast = numbers[numbers[0]] while slow != fast: slow = numbers[slow] fast = numbers[numbers[fast]] fast = 0 while slow != fast: slow = numbers[slow] fast = numbers[fast] return slow assert f( [3, 1, 3, 4, 2] ) == 3
benchmark_functions_edited/f1587.py
def f(a, b): while b != 0: a, b = b, a % b return a assert f(-1, 10) == 1
benchmark_functions_edited/f9896.py
def f(a, b): covariance_result = 0 for i in range(len(a)): covariance_result += (a[i] * b[i]) / (len(a) - 1) return covariance_result assert f( [0, 0, 0, 0, 0], [1, 2, 3, 4, 5]) == 0
benchmark_functions_edited/f13840.py
def f(score: float) -> int: if 0 <= score <= 35: return 1 elif 35 < score <= 75: return 2 elif 75 < score <= 100: return 3 return 0 assert f(35.0000000001) == 2
benchmark_functions_edited/f4473.py
def f(value): return int(value, 0) assert f("1") == 1
benchmark_functions_edited/f3041.py
def f(x, c): df_x = 0 for i in range(1, len(c)): df_x += pow(x, i - 1) * c[i] * i return df_x assert f(0, [0, 0, 1]) == 0
benchmark_functions_edited/f6898.py
def f(key_a: str, key_b: str) -> int: if key_a == '*': return 1 elif key_b == '*': return -1 return key_a.__lt__(key_b) assert f(1, 1) == 0
benchmark_functions_edited/f9314.py
def f(d_Dict: dict) -> int: return len(list(set(d_Dict.values()))) assert f({}) == 0
benchmark_functions_edited/f3670.py
def f(num, n): # Make a mask of all 0s with the nth bit set to 1. mask = 1 << n return num | mask assert f(0, 1) == 2
benchmark_functions_edited/f2680.py
def f(n): ndx = 0 while 1 < n: n = (n >> 1) ndx += 1 return ndx assert f(0b1) == 0
benchmark_functions_edited/f12759.py
def f(in_list: list) -> int: if len(in_list) == 0: raise Exception("empy list") _min = in_list[0] for element in in_list[1:]: if element < _min: _min = element return _min assert f( [ 1, 2, 3, 4 ] ) == 1
benchmark_functions_edited/f14335.py
def f(name, trained_schema): for i in range(len(trained_schema)): if trained_schema[i]['name'] == name: return i return None assert f( 'x', [{'name': 'x', 'type': 'number', 'constraints': [{'name': 'greaterThanOrEqualTo', 'value': 0}, {'name': 'lessThanOrEqualTo', 'value': 100}, {'name': 'isEven'}]}] ) == 0
benchmark_functions_edited/f12923.py
def f(x, coefs): if not coefs: return 0 else: # Actually faster than cos_sum because pypy hates slices. x2 = x + x bk = 0 bk1 = 0 for coef in reversed(coefs): bk1, bk = coef + x2 * bk1 - bk, bk1 return bk1 - x * bk assert f(1, (2, 3)) == 5
benchmark_functions_edited/f12607.py
def f(a, b) -> int: a_parts = a.split(".") b_parts = b.split(".") return 0 assert f( "1.1.1", "1.1.1" ) == 0
benchmark_functions_edited/f12783.py
def f(knot=-1, knot_vector=(), tol=0.001): # Find and return the multiplicity of the input knot in the given knot vector mult = 0 # initial multiplicity # Loop through the knot vector for kv in knot_vector: # Float equality should be checked w.r.t a tolerance value if abs(knot - kv) <= tol: mult += 1 return mult assert f(-1, [0, 0, 0, 1, 2, 3, 3, 3, 4, 5, 6]) == 0
benchmark_functions_edited/f13711.py
def f(string, substring): if len(substring) > len(string): return -1 j = 1 i = 1 while i < len(string): if string[i] == substring[j]: if j == (len(substring) - 1): return i - j j += 1 i += 1 return -1 assert f( 'hello', 'he' ) == 0
benchmark_functions_edited/f842.py
def f(uint): return uint[0] + (uint[1] << 128) assert f((1, 0)) == 1
benchmark_functions_edited/f11086.py
def f(lp): return {'l_2': 2, 'l2': 2, 'l_inf': 1, 'linf': 1, 'l_1': float('inf'), 'l1': float('inf'), 2: 2, float('inf'): 1, 1: float('inf')}[lp] assert f('l_2') == 2
benchmark_functions_edited/f874.py
def f(x): return 1 if x > 0 else 0 assert f(-1000000) == 0
benchmark_functions_edited/f13772.py
def f(s, outfile, enum): list = [l + "\n" for l in s.split("\n") if l] ouf = open(outfile, "a") for element in list: if element.startswith("chain"): element = " ".join(element.split()[:-1]) + "\t{}\n".format(enum) enum += 1 ouf.write(element) else: ouf.write(element) ouf.close() return enum assert f( "chain A 1 2 3 4\nchain B 5 6\nchain C 7 8\n", "test.out", 0 ) == 3
benchmark_functions_edited/f8204.py
def f(num_list): total_sum = 0 for num in num_list: total_sum ^= num return total_sum assert f( [1, 2, 3, 4] ) == 4
benchmark_functions_edited/f3267.py
def f(p,q,r): return (q[1]-p[1])*(r[0]-p[0]) - (q[0]-p[0])*(r[1]-p[1]) assert f( (20,20), (10,10), (10,10) ) == 0
benchmark_functions_edited/f9613.py
def f(datapath_id): if isinstance(datapath_id, int): return datapath_id if isinstance(datapath_id, str) and datapath_id: return int(datapath_id.replace(':', ''), 16) raise ValueError('Invalid datapath_id: %r' % datapath_id) assert f(0) == 0
benchmark_functions_edited/f4443.py
def f(values): return len("".join([value for value in values.values()])) assert f(eval('dict(a="a", b="b", c="c", d="d", e="e")')) == 5
benchmark_functions_edited/f10892.py
def f(a, b): return max(0, min(a[1], b[1]) - max(a[0], b[0])) assert f( [0,2], [0,1] ) == 1
benchmark_functions_edited/f5356.py
def f(dict_or_list): return list(dict_or_list.keys()) if isinstance(dict_or_list, dict) else dict_or_list assert f(5) == 5
benchmark_functions_edited/f5503.py
def f(list): fn = list.pop(0) return fn(*list) assert f( [ lambda x: 2*x, 3 ] ) == 6
benchmark_functions_edited/f680.py
def f(s): return len(s) - len(s.lstrip()) assert f(u" a") == 1
benchmark_functions_edited/f8091.py
def component (tn, multiindex): return tn[multiindex] if hasattr(tn,'shape') else tn assert f(3, (1,1,1)) == 3
benchmark_functions_edited/f2794.py
def f(a: int, b: int) -> int: while b: a, b = b, a % b return a assert f(4, 5) == 1
benchmark_functions_edited/f2172.py
def f(p=1/3, n=1): return (1-p)**(n-1)*p assert f(0, 5) == 0
benchmark_functions_edited/f2503.py
def f(nth,first_term,term_number): return (nth-first_term)/(term_number-1) assert f(1, 1, 2) == 0
benchmark_functions_edited/f6218.py
def f(n, target): ct = 0 if n is None: return 0 if n.value == target: ct = 1 return ct + f(n.next, target) assert f(None, 1) == 0
benchmark_functions_edited/f7421.py
def f(a, b): c = a + b return (c & 0xFFFF) + (c >> 16) assert f(1, 0) == 1
benchmark_functions_edited/f3664.py
def f(a, b): assert len(a) == len(b) return sum(c1 != c2 for c1, c2 in zip(a, b)) assert f(b'C', b'A') == 1
benchmark_functions_edited/f12887.py
def f(reg): result = -(reg >> 31 & 0x1) * (1 << 31) for i in range(31): result += (reg >> i & 0x1) * (1 << i) return result assert f(0b0000000000000000000000000000001) == 1
benchmark_functions_edited/f6125.py
def f(a, b, c, d): return max(0, min(b, d) - max(a, c)) assert f(0, 5, -5, -1) == 0
benchmark_functions_edited/f8996.py
def f(A, p, r): x = A[r] i = p - 1 for j in range(p, r): # de p a r-1 if A[j] <= x: i += 1 A[i], A[j] = A[j], A[i] # troca valores A[i+1], A[r] = A[r], A[i+1] # troca valores return i + 1 assert f(list(range(10)), 0, 2) == 2
benchmark_functions_edited/f5707.py
def f(is_rev): if is_rev == 240.0: return 1 else: return 0 assert f(240) == 1
benchmark_functions_edited/f231.py
def f(a, b): return (a > b) - (a < b) assert f(2.0, 1.0+0.1) == 1
benchmark_functions_edited/f11825.py
def f( start: float, end: float, start_time: int, end_time: int, trade_time: int ) -> float: time = max(0, trade_time - start_time) rate = (end - start) / (end_time - start_time) return min(end, start + (rate * time)) assert f(0, 1, 100, 120, 12000000) == 1
benchmark_functions_edited/f2495.py
def f(self, *args, **kwargs): return self(*args, **kwargs) assert f(lambda x: x + 1, 3) == 4
benchmark_functions_edited/f11455.py
def f(sig_info, error): if 'mailing_list' not in sig_info.keys(): print('ERROR! mailing_list is a required field') error += 1 else: print('Check mailing_list: PASS') return error assert f( {"mailing_list": "invalid_email"}, 1) == 1
benchmark_functions_edited/f8090.py
def f(power: int, minimum: int, maximum: int) -> int: return len([base**power for base in range(1, maximum+1) if base**power >= minimum and base**power <= maximum]) assert f(2, 3, 7) == 1
benchmark_functions_edited/f5114.py
def f(n, k, base): return n // base**k % base assert f(1234, 0, 2) == 0
benchmark_functions_edited/f13022.py
def f(FMzul, P, d2, DKm, mu_Gmin, mu_Kmin, MU = 0, MKZu = 0): # The tightening torque may be calculated : MA = (FMzul * (0.16 * P + 0.58 * d2 * mu_Gmin + mu_Kmin * (DKm / 2.0))) # (R13/1) # if MU != 0: MAS = MA + MU + MKZu # (R13/1) return MAS # return MA # assert f(0, 0, 0, 0, 0, 0) == 0
benchmark_functions_edited/f11727.py
def f(bag_name, bag_to_outer_bag, visited): if bag_name in visited: return 0 count = 0 for bag in bag_to_outer_bag[bag_name]: if bag in visited: continue count += 1 + f(bag, bag_to_outer_bag, visited) visited.add(bag) return count assert f( 'shiny gold', {'light red': ['bright white','muted yellow'], 'dark orange': ['bright white','muted yellow'], 'bright white': ['shiny gold'], 'muted yellow': ['shiny gold'], 'shiny gold': ['dark olive', 'vibrant plum'], 'dark olive': ['faded blue', 'dotted black'], 'vibrant plum': ['faded blue', 'dotted black'], 'faded blue': [], 'dotted black': []}, set() ) == 4
benchmark_functions_edited/f2867.py
def f(a, b): return abs(a[0] - b[0]) + abs(a[1] - b[1]) assert f( (3, 4), (3, 4) ) == 0
benchmark_functions_edited/f11841.py
def f(op_slice_sizes): return max([len(slices) for slices in op_slice_sizes]) assert f( [[10, 10, 10], [10, 10, 10], [10, 10, 10], [10, 10, 10]]) == 3
benchmark_functions_edited/f6245.py
def f(node_list): from operator import add from functools import reduce return reduce(add, node_list) assert f([0, 1, 2]) == 3
benchmark_functions_edited/f8771.py
def f(variable, attribute): if '.' in attribute: top, remaining = attribute.split('.', 1) return f(getattr(variable, top), remaining) else: return getattr(variable, attribute) assert f(2j,'real') == 0
benchmark_functions_edited/f11286.py
def f(points): if not points: return 0 points.sort(key=lambda x: x[1]) end = points[0][1] count = 1 for i in range(1, len(points)): if points[i][0] <= end: continue else: end = points[i][1] count += 1 return count assert f( [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9]] ) == 4
benchmark_functions_edited/f1121.py
def f(x, y=2): r = 1 while y > 0: r = x * r y = y - 1 return r assert f(100, 0) == 1
benchmark_functions_edited/f9783.py
def f(passwords): valid = 0 for (min_occur, max_occur, key_letter, password) in passwords: if min_occur <= password.count(key_letter) <= max_occur: valid += 1 return valid assert f( [(1, 3, "a", "abcde"), (1, 3, "b", "cdefg"), (2, 9, "c", "ccccccccc")] ) == 2
benchmark_functions_edited/f1537.py
def f(S, Q): S2 = S * S return ((1.0 / Q) + S2) * (1 + (1.0 / S2)) assert f(1, 2) == 3
benchmark_functions_edited/f2407.py
def f(rounded, divider): return int(rounded + divider - 1) // divider * divider assert f(2, 6) == 6
benchmark_functions_edited/f8451.py
def f(L): result = L[0] for x in L: if x > result: result = x return result assert f([2, 1, 4, 5]) == 5
benchmark_functions_edited/f3539.py
def f(iterator): count = 0 total = 0 for num in iterator: count += 1 total += num return float(total)/count assert f(iter([1, 2, 3, 4, 5])) == 3
benchmark_functions_edited/f12170.py
def f(m, threshold, zeta): # m: float; m_j in the thesis # t: float; truncation threshold # zeta: float; penalty factor, the same as the `lambda` in the thesis. if (zeta < abs(m)): z = (-m - zeta) / (2 * threshold) if (m < 0) else (-m + zeta) / (2 * threshold) else: z = 0 return z assert f(-0.5, 1.0, 0.5) == 0
benchmark_functions_edited/f12109.py
def f(gpus): if gpus is None: return None assert isinstance(gpus, list), "gpus should be a list" assert len(gpus) > 0, "gpus should be a non empty list" # set root gpu root_gpu = gpus[0] return root_gpu assert f([0, 2, 0]) == 0
benchmark_functions_edited/f11747.py
def f(n): # Base Case if n == 0: return 0 else: # Mod (%) by 10 gives you the rightmost digit (227 % 10 == 7), # while doing integer division by 10 removes the rightmost # digit (227 // 10 is 22) return (n % 10) + f(n // 10) assert f(22) == 4
benchmark_functions_edited/f12181.py
def f(base, height): return 0.5 * base * height assert f(3, 4) == 6