file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f5996.py
def f(item, problem, heuristic): # heuristic None means null so return Zero if heuristic is None: return 0 return heuristic(item[0], problem) assert f( ('a', 'b'), ('a', 'b'), lambda x, y: 1) == 1
benchmark_functions_edited/f13946.py
def f(digits: str, base: int) -> int: try: return int(digits, base) except ValueError: baseDesc = {2: "binary", 10: "decimal", 16: "hexadecimal"} raise ValueError(f"bad {baseDesc[base]} number: {digits}") from None assert f("0b111", 2) == 7
benchmark_functions_edited/f14370.py
def f(start, end): if start % 2 == 0: start += 1 sum_of_numbers = 0 for number in range(start, end+1, 2): sum_of_numbers += number return sum_of_numbers assert f(1, -1) == 0
benchmark_functions_edited/f1861.py
def f(theta, Aw, alpha): return Aw * theta**alpha assert f(5, 1, 1) == 5
benchmark_functions_edited/f10548.py
def f(datum, type): if type == "a" or type == "A": return str(datum) if type == "i" or type == "I": return int(datum) if type == "e" or type == "E": return float(datum) assert f(1.0, "i") == 1
benchmark_functions_edited/f6366.py
def f(num): if num < 0: return 0 if num > 1: return 1 return num assert f(2) == 1
benchmark_functions_edited/f4510.py
def f(parameter, z): return parameter / (1. + z) assert f(1., 0.) == 1
benchmark_functions_edited/f6985.py
def f(n: int) -> int: return sum(int(digit) for digit in str(n)) assert f(12) == 3
benchmark_functions_edited/f8814.py
def f(node): if node is not None: return 1 + f(node.next_node) # count nodes basically return 0 assert f(None) == 0
benchmark_functions_edited/f6927.py
def f(data): num = 0 for i, val in enumerate(data[:4]): num += ord(val) << ((3 - i) * 8) return num assert f(b"") == 0
benchmark_functions_edited/f4183.py
def f(x, item): for idx, val in enumerate(x): if val == item: return idx return -1 assert f([5, 2, 3, 5], 5) == 0
benchmark_functions_edited/f2379.py
def f(x, y, levels=256): return x*levels + y assert f(0, 2) == 2
benchmark_functions_edited/f9139.py
def f(function, list, initial): for item in list[::-1]: initial = function(item, initial) return initial assert f(lambda x, y: x + y, [], 1) == 1
benchmark_functions_edited/f7749.py
def f(n, m): return n * m - 1 if n * m > 0 else 0 assert f(**{'n': 4,'m': 1}) == 3
benchmark_functions_edited/f6473.py
def f(number:int) -> int: PHI = (1 + 5 ** 0.5) / 2 return int((PHI**number - (-PHI)**(-number))/(5**0.5)) assert f(3) == 2
benchmark_functions_edited/f12099.py
def f(sim_hash_one, sim_hash_two): f = 128 x = (sim_hash_one ^ sim_hash_two) & ((1 << f) - 1) ans = 0 while x: ans += 1 x &= x - 1 return ans assert f(10, 10) == 0
benchmark_functions_edited/f11788.py
def f(mat): n = sum(mat[0]) assert all( sum(line) == n for line in mat[1:]), "Line count != %d (n value)." % n return n assert f([[1]]) == 1
benchmark_functions_edited/f11346.py
def f(coorSM, maxS, maxM): return int((maxS) / 2.0 + coorSM - (maxM) / 2.0) assert f(1, 5, 3) == 2
benchmark_functions_edited/f11124.py
def f(N_particles, N_grid, dx): return (N_particles / N_grid) * dx assert f(1, 1, 1) == 1
benchmark_functions_edited/f4008.py
def f(m: int, n: int) -> int: return 2 * m * (m + n) assert f(1, 1) == 4
benchmark_functions_edited/f6903.py
def f(xs): mid = len(xs) // 2 if len(xs) % 2 == 0: return (xs[mid] + xs[mid - 1]) / 2 else: return xs[mid] assert f(sorted([1, 2, 3, 4, 5])) == 3
benchmark_functions_edited/f5659.py
def f(qs, arg=None): qs = qs.filter(tenure__name=arg) if qs else None return round(qs[0].area, 2) if qs else 0 assert f([]) == 0
benchmark_functions_edited/f440.py
def f(m_act, n, Wint): return m_act * n - Wint assert f(1, 1, 1) == 0
benchmark_functions_edited/f6208.py
def f(array, index_tuple): to_return = array for index in index_tuple: to_return = to_return[index] return to_return assert f( [[1, 2], [3, 4]], (1, 0) ) == 3
benchmark_functions_edited/f11489.py
def f(aggregate, x, y): if y is None: return x else: return aggregate(x, y) assert f(max, 1, None) == 1
benchmark_functions_edited/f11954.py
def f(n: int) -> int: if n < 0: print("n must be a positive number. {} is an invalid response.".format(n)) exit(code=1) if n in (0, 1): return 1 return f(n - 1) * n assert f(2) == 2
benchmark_functions_edited/f13254.py
def f(args): f = args[0] args = args[1:] return f(*args) assert f( ( lambda x, y: x + y, 1, 2, ) ) == 3
benchmark_functions_edited/f6073.py
def f(sd): global standard_deviation if sd is not None: standard_deviation = sd return standard_deviation assert f(0.0) == 0
benchmark_functions_edited/f9104.py
def f(lat): if lat < 0.0: return 0 else: return 1 assert f(100.0) == 1
benchmark_functions_edited/f11163.py
def f(n): n = abs(n) if n < 10: # n should be a number with single digit return n else: digit = (n % 10) # the remainder of n divided by 10 #f(n // 10) # recursion deduct the digits return max(digit, f(n // 10)) assert f(-281) == 8
benchmark_functions_edited/f1356.py
def f(iIndex): return 2 * iIndex + 1 assert f(4) == 9
benchmark_functions_edited/f205.py
def f(n): return (n > 0) - (n < 0) assert f(23) == 1
benchmark_functions_edited/f8621.py
def f(v, a, n): v1, v2 = v, (v**2 - 2) % n for bit in bin(a)[3:]: v1, v2 = ((v1**2 - 2) % n, (v1*v2 - v) % n) if bit == "0" else ((v1*v2 - v) % n, (v2**2 - 2) % n) return v1 assert f(2, 16, 3) == 2
benchmark_functions_edited/f13398.py
def f(freq): if freq < 652.0: Ndec = 1 elif freq < 1303.0: Ndec = 2 elif freq < 2607.0: Ndec = 3 else: Ndec = 4 return Ndec assert f(0) == 1
benchmark_functions_edited/f1045.py
def f(s: str): return len([c for c in s if c == "!"]) assert f( "This is a test string!" ) == 1
benchmark_functions_edited/f12559.py
def f(val, inverse=True): if inverse: return val - 273.15 else: return val + 273.15 assert f(273.15) == 0
benchmark_functions_edited/f5158.py
def f(l): l= str(l) if l.count('/')<5: return 0 elif l.count('/')>=5 and l.count('/')<=7: return 2 else: return 1 assert f('100000/200000/300000') == 0
benchmark_functions_edited/f4898.py
def f(tree_list): max_len = 0 for row in tree_list: if len(row) > max_len: max_len = len(row) return max_len assert f(["ab", "bc"]) == 2
benchmark_functions_edited/f11218.py
def f(vector): if len(vector) == 0: return 0 vector = [ord(c) for c in vector] sign = 1 if vector[0] & 0x80: vector[0] = (vector[0] & 0x7f) sign = -1 value = 0 for c in vector: value *= 256 value += c return sign * value assert f(b"") == 0
benchmark_functions_edited/f12995.py
def f(color_list): color_set = set(color_list) count = 0 while True: if count not in color_set: return count count += 1 assert f([1, 2, 3]) == 0
benchmark_functions_edited/f8625.py
def f(x): #All the valid values appear to be <= 6 if float(x) <= 9: return x #replace those with 1 bed since that is 90% of all properties else: return 1 assert f(5) == 5
benchmark_functions_edited/f5850.py
def default_thread_index (value, threads): value_index = threads.index(value) return value_index assert f(3, [1, 2, 3, 4]) == 2
benchmark_functions_edited/f2540.py
def f(a, b, p): return (a * pow(b, p-2, p)) % p assert f(10, 4, 4) == 0
benchmark_functions_edited/f118.py
def f(str): return len(str.encode('gb2312')) assert f(u"a") == 1
benchmark_functions_edited/f11446.py
def f(t48): t68 = t48 - 4.4e-6 * t48 * (100 - t48) return t68 assert f(0) == 0
benchmark_functions_edited/f13479.py
def f(x0, alpha, T, t): if t <= T: return x0 - (1 - alpha) * x0 * t / T else: return alpha * x0 assert f(0, 1, 1, 1) == 0
benchmark_functions_edited/f12897.py
def f(link): is_web = 0 keywords = ["http", "www.", "://", "git@git"] for keyword in keywords: if keyword in link: is_web = 1 return is_web assert f( "http://www.google.com") == 1
benchmark_functions_edited/f5513.py
def f(n): if n>0 and n<2: return 1 if n>=2: return n*f(n-1) assert f(3)==6
benchmark_functions_edited/f8545.py
def f(pred, true_operand, true_fun, false_operand, false_fun): # pragma: no cover if pred: return true_fun(true_operand) else: return false_fun(false_operand) assert f(False, 1, lambda x: x + 1, 1, lambda x: x - 1) == 0
benchmark_functions_edited/f3663.py
def f(bytes, signed: bool): return int.from_bytes(bytes, 'little', signed=signed) assert f(bytes.fromhex('01'), False) == 1
benchmark_functions_edited/f6944.py
def f(concepts_1: set, concepts_2: set): intersection = len(concepts_1.intersection(concepts_2)) return (2*intersection)/(len(concepts_2)+len(concepts_1)) assert f({1}, {2}) == 0
benchmark_functions_edited/f11565.py
def f(azimuth, zero_center=False): if (azimuth > 360 or azimuth < 0): azimuth %= 360 if zero_center: if azimuth > 180: azimuth -= 360 return azimuth assert f(-360) == 0
benchmark_functions_edited/f11143.py
def f(integer_string, strict=False, cutoff=None): if integer_string: ret = int(integer_string) else: return integer_string if ret < 0 or (ret == 0 and strict): raise ValueError() if cutoff: return min(ret, cutoff) return ret assert f(5.5) == 5
benchmark_functions_edited/f11677.py
def calcAverage (theList): sum = 0 numValues = 0 for value in theList: sum += value numValues += 1 return sum / numValues assert f( [1, 2, 3, 4, 5] ) == 3
benchmark_functions_edited/f10512.py
def f(n): result = n for i in range(2, int(n ** 0.5) + 1): if n % i == 0: while n % i == 0: n //= i result -= result // i if n > 1: result -= result // n return result assert f(1) == 1
benchmark_functions_edited/f9667.py
def f(text, target): last=-1 here=text.find(target) if here>-1: last=here there=0 while there>-1: there=text[last+1:].find(target) if there>-1: last+=there+1 return last assert f( "1234567890", "4" ) == 3
benchmark_functions_edited/f4368.py
def f(a, b): b = abs(b) while b != 0: a, b = (b, a % b) return a assert f(21, 14) == 7
benchmark_functions_edited/f394.py
def f( argv ): # Return success. return 0 assert f( [] ) == 0
benchmark_functions_edited/f1468.py
def f(x, p): p_index = int(p * len(x)) return sorted(x)[p_index] assert f(range(10), 0) == 0
benchmark_functions_edited/f12886.py
def f(nval, kval): assert(nval >= kval) choose = dict() for n in range(nval + 1): choose[n, 0] = 1 choose[n, n] = 1 for k in range(1, n): choose[n, k] = choose[n - 1, k - 1] + choose[n - 1, k] return choose[nval, kval] assert f(6, 6) == 1
benchmark_functions_edited/f9889.py
def f(values, target): closest = values[0] for value in values: if abs(target - value) < abs(target - closest): closest = value return closest assert f( (1, 5, 2, 6, 7), 4) == 5
benchmark_functions_edited/f13156.py
def f(mode, memory, ptr, relative_base): # position mode if mode == 0: return memory[ptr] # immediate mode elif mode == 1: # immediate mode is not supported raise Exception elif mode == 2: return memory[ptr] + relative_base else: raise Exception assert f(0, [1, 2, 3], 2, 3) == 3
benchmark_functions_edited/f8562.py
def f(i, k, s): return round(((i - 1) * s - i + k) / 2 + 0.1) assert f(28, 5, 1) == 2
benchmark_functions_edited/f2644.py
def f(row): if row['prev_winner_runnerup'] == row['winner_name']: val = 1 else: val = 0 return val assert f( {'prev_winner_runnerup': 'B', 'winner_name': 'A'}) == 0
benchmark_functions_edited/f11975.py
def f(val, bits): if (val & (1 << (bits - 1))) != 0: # if sign bit is set e.g., 8bit: 128-255 val = val - (1 << bits) # compute negative value return val & ((2 ** bits) - 1) # return positive value as is assert f(0x0000, 16) == 0
benchmark_functions_edited/f11983.py
def f(index): valid_indexes = (1, 2, 3, 4) if index not in valid_indexes: raise ValueError(f"GPIO pin index must be in {valid_indexes}" + f" but instead got {index}") index -= 1 return index assert f(3) == 2
benchmark_functions_edited/f7984.py
def f(x): if x == 666666666:#if x is a non data value return 255 x_string = str(x) sum = 0 for i in range(1,6): if str(i) in x_string: sum += 2**i return sum assert f(1) == 2
benchmark_functions_edited/f2719.py
def f(metric): total = 0 for i in metric: total += i return total assert f([]) == 0
benchmark_functions_edited/f7949.py
def f(quarter): if quarter not in range(1, 5): raise ValueError("invalid quarter") return {1: 1, 2: 4, 3: 7, 4: 10}[quarter] # return 3 * quarter - 2 assert f(2) == 4
benchmark_functions_edited/f513.py
def f(direction): return (direction + 3) % 4 assert f(3) == 2
benchmark_functions_edited/f9233.py
def f(string, index): if index < 0 or index >= len(string): return 0 if string[index] == ' ': return 0 if string[index].isalnum(): return 2 return 1 assert f(' ', 0) == 0
benchmark_functions_edited/f2927.py
def f(n): if n <= 1: return n else: return(f(n-1) + f(n-2)) assert f(2) == 1
benchmark_functions_edited/f701.py
def f(r2, C12, C6): return C12/r2**6 - C6/r2**3 assert f(3, 0, 0) == 0
benchmark_functions_edited/f13053.py
def f(suffix_bits, suffix): assert suffix % 2 == 1, "Target suffix must be odd" s = 1 for i in range(suffix_bits): if (((s ** 3) >> i) & 1) != ((suffix >> i) & 1): s |= (1 << i) return s assert f(24, 1) == 1
benchmark_functions_edited/f635.py
def f(x): return min(x, key=abs) assert f( (1,2,1,1) ) == 1
benchmark_functions_edited/f6087.py
def f(n): if n < 1: return 0 a, b = 0, 1 while n > 2: a = a + b b = a + b n -= 2 return a if (n == 1) else b assert f(0) == 0
benchmark_functions_edited/f2012.py
def f(val, entries): return list(entries.keys())[list(entries.values()).index(val)] assert f(1, {1: 1, 2: 2, 3: 3}) == 1
benchmark_functions_edited/f3529.py
def f(num, nearest): return int((num + (nearest / 2)) // nearest * nearest) assert f(0, 15) == 0
benchmark_functions_edited/f9609.py
def f(n): s0 = 1 s1 = n while s0 != s1: s0, s1 = s1, round((s1 * s1 + n) / (2 * s1)) return s0 assert f(16) == 4
benchmark_functions_edited/f1606.py
def f(seq): return seq[(len(seq) - 1) // 2] assert f(range(9)) == 4
benchmark_functions_edited/f12437.py
def f(values): key = 0 max_value, multi = 100000000, 1 for value in values[::-1]: key += multi + value max_value *= multi return key assert f(tuple()) == 0
benchmark_functions_edited/f7206.py
def f(a, b): if a == b: return 0 else: return int((a - b) / abs(a - b)) assert f(5.0, 2.5) == 1
benchmark_functions_edited/f1044.py
def f(angle): return int(angle/300.0*1023) assert f(0.0) == 0
benchmark_functions_edited/f14394.py
def f(area_data: list, down: int, right: int) -> int: width = len(area_data[0]) count = 0 for i, line in enumerate(area_data[::down]): count += line[(right * i) % width] == '#' return count assert f( [ "..##.......", "#...#...#..", ".#....#..#.", "..#.#...#.#", ".#...##..#.", "..#.##.....", ".#.#.#....#", ".#........#", "#.##...#...", "#...##....#", ".#..#...#.#", ], 1, 3 ) == 7
benchmark_functions_edited/f11699.py
def f(a, b): if type(a) is not int and type(a) is not float: raise TypeError("a must be an integer") if type(b) is not int and type(b) is not float: raise TypeError("b must be an integer") if type(a) is float: a = int(a) if type(b) is float: b = int(b) return a + b assert f(0, 0.0) == 0
benchmark_functions_edited/f14112.py
def f(x): # assuming on 64 bit machine shift = int(64 / 2) while shift: x = x ^ (x >> shift) shift = int(shift / 2) # parity is at the last bit return x & 1 assert f(100000) == 0
benchmark_functions_edited/f3807.py
def f(minimum, value, maximum): return max(minimum, min(maximum, value)) assert f(-100, 0, 100) == 0
benchmark_functions_edited/f13115.py
def f(item): if item is None or item.get('order') is None: return -1 try: return int(item['order']) except (ValueError, TypeError): return -1 assert f({'order': '2'}) == 2
benchmark_functions_edited/f4874.py
def f(buf): chars = buf.split(",") result = 0 for c in chars: result += int(c) return result assert f(r"1,2,3") == 6
benchmark_functions_edited/f1761.py
def f(c): return next(iter(c), None) assert f(iter([1, 2, 3])) == 1
benchmark_functions_edited/f8089.py
def f(oldPartCount, newPartCount): partDecrease = max(oldPart-newPart for oldPart,newPart in zip(oldPartCount, newPartCount)) return max(0, partDecrease) assert f( [1,2,3], [1,2,2] ) == 1
benchmark_functions_edited/f8277.py
def f(val, bits): if (val & (1 << (bits - 1))) != 0: # if sign bit is set val = val - (1 << bits) # compute negative value return val # return positive value as is assert f(6, 2) == 2
benchmark_functions_edited/f14248.py
def f(arr): i = 0 count = 0 # since we know exact place in arr for each element # we could just check each one and swap it to right position if thats # required while i < len(arr): if arr[i] != i + 1: arr[arr[i] - 1], arr[i] = arr[i], arr[arr[i] - 1] count += 1 else: i += 1 return count assert f( [1, 2, 3] ) == 0
benchmark_functions_edited/f11567.py
def f(n, memo = None): if memo == None: memo = {} if n == 0 or n == 1: return 1 try: return memo[n] except KeyError: result = f(n-1, memo) + f(n-2, memo) memo[n] = result return result assert f(4) == 5
benchmark_functions_edited/f12973.py
def f(data): count = 0 try: for value in data.items(): if isinstance(value, list): count += len(value) except: print('Invalid NE sequences format') return count assert f([]) == 0
benchmark_functions_edited/f13534.py
def f(n, k): if n < 0: return 0 elif n == 0: return 1 else: return sum([f(n - i, k) for i in range(1, k + 1)]) assert f(4, 4) == 8
benchmark_functions_edited/f11854.py
def f(n): if n == 0: return 0 elif n == 1: return 1 elif n < 0: return -1 return f(n - 1) + f(n - 2) assert f(2) == 1
benchmark_functions_edited/f10151.py
def f(vals, key, default_val=None): val = vals for part in key.split('.'): if isinstance(val, dict): val = val.f(part, None) if val is None: return default_val else: return default_val return val assert f({'1': 2}, '1') == 2
benchmark_functions_edited/f8822.py
def f(t): assert len(t) > 0, "Le tableau est vide" m = 0 for i in range(len(t)): if t[i] > t[m]: m = i return m assert f( [-1]) == 0
benchmark_functions_edited/f3225.py
def f(space: int, d: int) -> int: return (space - 1 + d) % 10 + 1 assert f(4, 1) == 5