file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f7642.py
def f(num): # print(num) if num == 0: return 32 # assuming 32bit inputs p = 0 while (num >> p) & 1 == 0: p += 1 return p assert f(27) == 0
benchmark_functions_edited/f4912.py
def f(filename): from os.path import getmtime try: return getf(filename) except: return 0 assert f('nonexistent-file.xyz') == 0
benchmark_functions_edited/f12638.py
def f(address): if hasattr(address, 'version'): return address.version if '.' in address: return 4 elif ':' in address: return 6 else: raise ValueError("Invalid IP: {}".format(address)) assert f('127.0.0.1') == 4
benchmark_functions_edited/f14281.py
def f(numValues): if numValues == 0: return 0 if numValues == 1: return 1 return (numValues - 1).bit_length() assert f(34) == 6
benchmark_functions_edited/f5296.py
def f(x) -> int: return len(x) if type(x) is list else 1 assert f(True) == 1
benchmark_functions_edited/f11528.py
def f(b): value, n = 0, len(b) weights = [ [2048, 1024, 512, 256], [1024, 512, 256, 128], [256, 8, 2, 1], [4, 2, 1, 1] ] for i in range(n): for j in range(n): value += (b[i][j] * weights[i][j]) return value assert f( [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == 0
benchmark_functions_edited/f10002.py
def f(i, text): # Type casting can have spaces before the variable. # Example: (NSString *) variable if text[i - 1] == ')': return i - 1 return i assert f(0, '(NSString*) variable') == 0
benchmark_functions_edited/f13473.py
def f(string_to_encode:str,string_length:int) -> int: x=0 string_to_encode=string_to_encode[::-1] i=0 while i<string_length: tmp=ord(string_to_encode[i:i+1]) x+=(tmp*pow(256,i)) i+=1 return x assert f(b'\x00\x00\x00\x00',4) == 0
benchmark_functions_edited/f11810.py
def f(location, board_width): corners = (0, board_width - 1) if location[0] in corners and location[1] in corners: return 3 if location[0] in corners or location[1] in corners: return 2 return 1 assert f( (0, 0), 4 ) == 3
benchmark_functions_edited/f12475.py
def f(mbsize): size = mbsize.lower() import re units = re.compile("[gmkb].*") newsize = float(re.sub(units, '', size)) if size.find("g") > -1: newsize *= 1024 elif size.find("m") > -1: newsize *= 1 elif size.find("k") > -1: newsize /= 1024 else: newsize *= 1 return newsize assert f("1mib") == 1
benchmark_functions_edited/f3683.py
def f(a, b): return max(0, min(a[1], b[1]) - max(a[0], b[0])) assert f( [0,2], [1,2]) == 1
benchmark_functions_edited/f7064.py
def f(n: int) -> int: if not n >= 0: raise ValueError return n*(5*n - 3)//2 assert f(1) == 1
benchmark_functions_edited/f8596.py
def f(s, size): h = 0 for c in s: h += ord(c) h += (h << 10) h ^= (h >> 6) h += (h << 3); h ^= (h >> 11); h += (h << 15); return h % size; assert f( 'ab', 11) == 0
benchmark_functions_edited/f6728.py
def f(cluster): charCount = 0 for fromTo in cluster: charCount += fromTo["to"] - fromTo["from"] + 1; return charCount assert f([]) == 0
benchmark_functions_edited/f12036.py
def f(set_1, set_2): intersection = len(set_1.intersection(set_2)) smaller_set = min(len(set_1), len(set_2)) return intersection / smaller_set assert f(set([1, 2, 3]), set([1, 2, 3])) == 1
benchmark_functions_edited/f7066.py
def f(register, register_check, jump_by): if register.get(register_check, register_check) != 0: return jump_by if isinstance(jump_by, int) else register[jump_by] assert f({0: 2}, 0, 2) == 2
benchmark_functions_edited/f6224.py
def f(low, high, step, endpoint=True): num_steps = (high - low) // step if endpoint: num_steps += 1 return int(num_steps) assert f(1, 10, 4) == 3
benchmark_functions_edited/f12227.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(0, 0, 3) == 3
benchmark_functions_edited/f8603.py
def f(a: int, b: int) -> int: if a < 1 or b < 1: raise ValueError(f'Input arguments (a={a}, b={b}) must be positive integers') while a != 0: a, b = b % a, a return b assert f(1000, 5) == 5
benchmark_functions_edited/f9508.py
def f(budget, denomination): return int(budget // denomination) assert f(20, 10) == 2
benchmark_functions_edited/f12843.py
def f(luminance1, luminance2): (l1, l2) = sorted((luminance1, luminance2), reverse=True) return (l1 + 0.05) / (l2 + 0.05) assert f(0.5, 0.5) == 1
benchmark_functions_edited/f13160.py
def f(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, x4: float, y4: float): n = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4) d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4) if d == 0: return None else: return n / d assert f(0, 0, 1, 1, 0, 2, 2, 0) == 1
benchmark_functions_edited/f1853.py
def f(x, mi, ma): x = max(x, mi) x = min(x, ma) return x assert f(4, 1, max(1, 3)) == 3
benchmark_functions_edited/f978.py
def f(a, b): return -(-a // b) assert f(5, 5) == 1
benchmark_functions_edited/f12535.py
def f(x): if x is None: return None elif x in ("", " "): return None else: try: return int(float(x)) except: return None assert f(1.0) == 1
benchmark_functions_edited/f5848.py
def f(raw_val): result = raw_val * 2 / ((2**15) - 1) return result assert f(0) == 0
benchmark_functions_edited/f5569.py
def f(s1: str, s2: str): if len(s1) != len(s2): return float('inf') return sum(el1 != el2 for el1, el2 in zip(s1, s2)) assert f( 'CATCGTAATGACGGCAT', 'CATCGTAATGACGGCAT' ) == 0
benchmark_functions_edited/f12823.py
def f(target, in_list): next_highest = None for item in in_list: if item > target: next_highest = item break if next_highest is None: next_highest = in_list[-1] return next_highest assert f(144, [5]) == 5
benchmark_functions_edited/f9121.py
def f(tl, t, tr, l, r, dl, d, dr): vertEnergy = tl + 2 * t + tr - dl - 2 * d - dr horizEnergy = tl + 2 * l + dl - tr - 2 * r - dr return (vertEnergy ** 2 + horizEnergy ** 2) ** 0.5 assert f(0, 0, 0, 0, 0, 0, 0, 0) == 0
benchmark_functions_edited/f9820.py
def f(set_one: list, set_two: list) -> int: return len(set(set_one) & set(set_two)) assert f( ["John", "Patricia"], ["Elizabeth", "Maria"] ) == 0
benchmark_functions_edited/f2929.py
def f(string): try: number = int(float(string)) except: number = 0 return number assert f("") == 0
benchmark_functions_edited/f1449.py
def f(mod): if mod == "lambda": return "awslambda" return mod assert f(1) == 1
benchmark_functions_edited/f12496.py
def f(c): return c**2 * 6 assert f(0) == 0
benchmark_functions_edited/f2206.py
def f(word): try: return int(word) except ValueError: return 0 assert f(" ") == 0
benchmark_functions_edited/f7410.py
def f(type_): if type_ in ["void"]: return 0 if type_ in ["int", "float"]: return 4 if type_ in ["long", "double"]: return 8 return type_._arg_size_() assert f("long") == 8
benchmark_functions_edited/f7744.py
def f(a, b): lena, lenb = len(a), len(b) j = next((i for i in range(lenb) if i >= lena or a[i] != b[i]), lenb) return b[j:].count("#") assert f( ["1.", "2.", "3."], ["1.", "2.", "3.", "4."]) == 0
benchmark_functions_edited/f14505.py
def f(bb, bbother): chflag = 0 if not ((bbother[2] < bb[0]) or (bbother[0] > bb[2])): if not ((bbother[3] < bb[1]) or (bbother[1] > bb[3])): chflag = 1 return chflag assert f([0.0, 0.0, 1.0, 1.0], [0.0, 0.0, 1.0, 1.0]) == 1
benchmark_functions_edited/f4686.py
def f(item): ret = 1 try: float(item) ret = 0 except ValueError: pass return ret assert f(bytes('asdf', 'utf-8')) == 1
benchmark_functions_edited/f5446.py
def f(x, p=0.50): # Eg x, 0.10 returns 10th percentile value. pindex = int(p * len(x)) return sorted(x)[pindex] assert f([1, 2, 3], 0.00) == 1
benchmark_functions_edited/f10636.py
def f(a, b): if b == 0: return a return f(b, a % b) assert f(1, 1) == 1
benchmark_functions_edited/f3342.py
def f(f: str) -> int: f = f[0] if not f.isnumeric(): return 1 return int(f) assert f(f"y") == 1
benchmark_functions_edited/f9736.py
def f(sheet): # Internal representation? if (hasattr(sheet, "num_cols")): return sheet.num_cols() # xlrd sheet? if (hasattr(sheet, "ncols")): return sheet.ncols # Unhandled sheet object. return 0 assert f(()) == 0
benchmark_functions_edited/f12494.py
def f(x, y, min_rel_proximity=0.05): min_abs_proximity = (y[-1] - y[0]) * min_rel_proximity final_y = y[-1] for i in range(len(x)): if abs(y[i] - final_y) < min_abs_proximity: return x[i] assert f(range(10), range(10), 0.1) == 9
benchmark_functions_edited/f12431.py
def f(p, p1, p2): x = p1['x'] y = p1['y'] dx = p2['x'] - x dy = p2['y'] - y if dx != 0 or dy != 0: t = ((p['x'] - x) * dx + (p['y'] - y) * dy) / (dx * dx + dy * dy) if t > 1: x = p2['x'] y = p2['y'] elif t > 0: x += dx * t y += dy * t dx = p['x'] - x dy = p['y'] - y return dx * dx + dy * dy assert f( {'x': 0, 'y': 1}, {'x': 0, 'y': 0}, {'x': 1, 'y': 0} ) == 1
benchmark_functions_edited/f6488.py
def f(income): return int(income/10000) assert f(1000) == 0
benchmark_functions_edited/f3684.py
def f(array, val): length = len(array) for i in range(length): if array[i] == val: return i return None assert f(list(range(10)), 5) == 5
benchmark_functions_edited/f14016.py
def f(ip_str): # FIX ME try: #ip = ip_str.split(':') hh, mm, ss = ip_str.split(':') hh = int(hh) * 60 * 60 mm = int(mm) * 60 ss = int(ss) except ValueError: hh = 0 try: mm, ss = ip_str.split(':') mm = int(mm) * 60 ss = int(ss) except ValueError: raise sec = hh + mm + ss return sec * 1000 assert f('0:0:0') == 0
benchmark_functions_edited/f2643.py
def f(v, seq): for s in seq: if s > v: return s return v assert f(0, [1, 3, 5, 8, 10]) == 1
benchmark_functions_edited/f8972.py
def lharmonicmean (inlist): sum = 0 for item in inlist: sum = sum + 1.0/item return len(inlist) / sum assert f( [1,1,1,1,1] ) == 1
benchmark_functions_edited/f9780.py
def f(vector_1, vector_2): if len(vector_1) != len(vector_2): return 0 return sum(i[0] * i[1] for i in zip(vector_1, vector_2)) assert f( [1, 2, 3], [1, 0, 1] ) == 4
benchmark_functions_edited/f1787.py
def f(dict, item): try: return dict.get(item) except KeyError: return '' assert f({'a': 1}, 'a') == 1
benchmark_functions_edited/f7589.py
def f(position): if (position != None): return position.get("width", 0) * position.get("height", 0) else: return 0 assert f({"width": 1, "height": 1}) == 1
benchmark_functions_edited/f11678.py
def f(board_state, player): board = board_state knight_amt = 0 for row in board: for column in row: if player == 1 and column == "k": knight_amt += 1 elif player == 0 and column == "K": knight_amt += 1 return knight_amt assert f( ["..", ".."], 0) == 0
benchmark_functions_edited/f10423.py
def f(values, pct): assert 0 < pct < 1, "percentage should be lower than 1" values = sorted(values) return values[-int(len(values)*pct)] assert f( [1, 2, 3, 4], 0.5 ) == 3
benchmark_functions_edited/f11164.py
def f(base, exponent, modulus): result = 1 while exponent > 0: if exponent & 1 == 1: result = (result * base) % modulus exponent = exponent >> 1 base = (base * base) % modulus return result assert f(5, 0, 7) == 1
benchmark_functions_edited/f5846.py
def f(limit): sequence = [0, 1] [sequence.append(sequence[i] + sequence[i-1]) for i in range(1, limit)] return sequence[-1] assert f(6) == 8
benchmark_functions_edited/f14167.py
def f(digits, b): count = 0 for pos, d in enumerate(digits): count += d*(b**pos) return count assert f((1,), 2) == 1
benchmark_functions_edited/f7885.py
def f(file_name): line_idx = -1 with open(file_name) as file: for line_idx, _ in enumerate(file): pass return line_idx + 1 assert f(' ') == 1
benchmark_functions_edited/f7581.py
def f(in_v, limiter): out_v = int((in_v/limiter) * 255) return out_v assert f(0, 255) == 0
benchmark_functions_edited/f4908.py
def f(maybe_string, base): if isinstance(maybe_string, int): return maybe_string else: return int(maybe_string, base) assert f("1", 10) == 1
benchmark_functions_edited/f13603.py
def f(d, max_level=None): keys = 0 for key, value in d.items(): if isinstance(value, dict): if max_level is None: keys += f(value) elif max_level > 1: keys += f(value, max_level - 1) else: keys += 1 else: keys += 1 return keys assert f({"a": {"b": 1, "c": {"d": 2}}, "e": 3}, 1) == 2
benchmark_functions_edited/f1431.py
def f(issues, field_key): return sum([int(i[field_key]) for i in issues]) assert f([], 'points') == 0
benchmark_functions_edited/f6424.py
def f(digits): n = 0 multiplier = 1 for d in reversed(digits): n += multiplier * d multiplier *= 10 return n assert f([]) == 0
benchmark_functions_edited/f216.py
def f(x, s, e) -> int: return (x >> e) & ((1 << (s - e + 1))-1) assert f(2, 0, 1) == 0
benchmark_functions_edited/f8758.py
def f(values): for u in values: if len(values[u]) < 1: return -1 elif len(values[u]) > 1: return 0 return 1 assert f(dict([(1, {1}), (2, {2}), (3, {3}), (4, {4}), (5, {5}), (6, {6}), (7, {7}), (8, {8}), (9, {9})])) == 1
benchmark_functions_edited/f8005.py
def f(array: list) -> list: min_so_far = array[0] for i in array: if i < min_so_far: min_so_far = i return min_so_far assert f(list([10, 20, 5, 12])) == 5
benchmark_functions_edited/f6433.py
def f(f, x, h): return 1/(3*h) * (8*(f(x+h/4) - f(x-h/4)) - (f(x+h/2) - f(x-h/2))) assert f(lambda x: x**2, 1, 1) == 2
benchmark_functions_edited/f11587.py
def f(caption_time): ms = caption_time.split('.')[1] h, m, s = caption_time.split('.')[0].split(':') return (int(h) * 3600 + int(m) * 60 + int(s)) * 1000 + int(ms) assert f( "00:00:00.0000" ) == 0
benchmark_functions_edited/f9956.py
def f(value1, value2): abs_diff = abs(value1 - value2) if abs_diff > 180: smallest_diff = 360 - abs_diff else: smallest_diff = abs_diff return smallest_diff assert f(10, 10) == 0
benchmark_functions_edited/f10746.py
def f(x): if '__len__' in dir(x): return len(x) return 0 assert f(False) == 0
benchmark_functions_edited/f13907.py
def f(value_list): max_value = value_list[0] max_pos = 0 for index in range(1, len(value_list)): if value_list[index] > max_value: max_value = value_list[index] max_pos = index return max_pos assert f( [4, 3, 3, 2] ) == 0
benchmark_functions_edited/f2452.py
def f(num): return sum([num[i]*2**i for i in range(len(num))]) assert f([1,0,1]) == 5
benchmark_functions_edited/f14245.py
def f(line: str) -> int: last_c = None padding = 0 for i, c in enumerate(line): if i == 0 and c != ' ': padding = 2 break if last_c == ' ' and c != ' ': padding = i + 2 break last_c = c padding = i return padding assert f('{0}foo: bar'.format(10 *'')) == 2
benchmark_functions_edited/f4787.py
def f(val, mini, maxi): return max(mini, min(maxi, val)) assert f(1, 0, 2) == 1
benchmark_functions_edited/f3577.py
def f(service_lane, i, j): return min(service_lane[i:j]) assert f(range(1, 10), 2, 7) == 3
benchmark_functions_edited/f7466.py
def f(x, y, z, stage_tilt): return z + stage_tilt[0] + stage_tilt[1]*x + stage_tilt[2]*y assert f(1, 2, 3, [0, 0, 0]) == 3
benchmark_functions_edited/f14143.py
def f(f, arity, data): while len(data) > 1: data_chunk = data[:arity] data = data[arity:] data.append(f(*data_chunk)) return data[0] assert f(lambda x, y: x + y, 2, [1, 2, 3]) == 6
benchmark_functions_edited/f5742.py
def f(a, b): return sum([a[i] == b[i] for i in range(len(a))]) assert f('apple','melonie') == 0
benchmark_functions_edited/f10968.py
def f(id_edge, edges_dict): nodes_list = list(edges_dict.keys()) edges_id = list(edges_dict.values()) id_edge = edges_id.index(id_edge) return nodes_list[id_edge] assert f(3, {1: 2, 2: 3, 3: 4, 4: 1, 5: 6, 6: 5}) == 2
benchmark_functions_edited/f8121.py
def f(name, val): if val: return val raise LookupError(f'{name} not ready') assert f(None, 1) == 1
benchmark_functions_edited/f6016.py
def f(a: str, b: str) -> int: distance = 0 for i in range(len(a)): if a[i] != b[i]: distance += 1 return distance assert f("aaa bbb", "aaa abf") == 2
benchmark_functions_edited/f3141.py
def f(v): try: return int(v or 0) except ValueError: return 0 assert f("") == 0
benchmark_functions_edited/f10367.py
def f(address, mesh): # X runs first in XYZ # (*In spglib, Z first is possible with MACRO setting.) m = mesh return ( address[0] % m[0] + (address[1] % m[1]) * m[0] + (address[2] % m[2]) * m[0] * m[1] ) assert f( (0, 0, 0), (1, 1, 1) ) == 0
benchmark_functions_edited/f10018.py
def f(data, p): q = len(data) * p for index, _ in enumerate(data): if (index + 1) >= q: return(data[index]) assert f(range(10), 0) == 0
benchmark_functions_edited/f14051.py
def f(step, session) -> list: _ = session['index'] + step if _ > len(session['graphs_list']) - 1 or _ < 0: try: return session['graphs_list'][session['index']] except KeyError: return [] try: session['index'] = _ return session['graphs_list'][_] except KeyError: return [] assert f(1, {'index': 0, 'graphs_list': [1, 2, 3, 4]}) == 2
benchmark_functions_edited/f12208.py
def f(gen): return list(gen)[0] assert f(range(4)) == 0
benchmark_functions_edited/f6367.py
def f(hr, fc): return hr * fc / 1000000 assert f(3, 0) == 0
benchmark_functions_edited/f6961.py
def f(a, b, size, gram=True): if gram: trace_ = a**2 + (size-1) * (a**2 + b**2) else: trace_ = size * a return trace_ assert f(1, 1, 5) == 9
benchmark_functions_edited/f11867.py
def f(T, t): if 0 < t < (T/2): return 1 elif t == 0: return 0 elif -(T/2) < t < 0: return -1 else: print("That is not within the given range of [-T/2, T/2]") return None assert f(10, 0) == 0
benchmark_functions_edited/f1740.py
def f(fn, args, kwargs): return fn(*args, **kwargs) assert f(lambda x, y: x + y, (2, 3), {}) == 5
benchmark_functions_edited/f9217.py
def f(x): assert x > 0 bits = 1 representable = 2 ** bits while representable < x: bits += 1 representable *= 2 return bits assert f(21) == 5
benchmark_functions_edited/f6676.py
def f(list_input): value = 1 for val in list_input: value *= val return value assert f([]) == 1
benchmark_functions_edited/f1101.py
def f(gt): x = gt.split(b'/') return int(x[0])+int(x[1]) assert f(b'0/1') == 1
benchmark_functions_edited/f11234.py
def f(n): return f(n-1) + f(n-2) if n > 2 else 1 assert f(0) == 1
benchmark_functions_edited/f9456.py
def f(entries: list) -> int: nice_strings = 0 for string in entries: if any([string.count(string[i:i+2]) >= 2 for i in range(len(string)-2)]) and any([string[i] == string[i+2] for i in range(len(string)-2)]): nice_strings += 1 return nice_strings assert f([ "qjhvhtzxzqqjkmpb", "xxyxx", "uurcxstgmygtbstg", "ieodomkazucvgmuy", ]) == 2
benchmark_functions_edited/f11175.py
def f(a, b): if a > b: a, b = b, a return sum(i for i in range(a, (b + 1))) assert f(-1, 1) == 0
benchmark_functions_edited/f7119.py
def f(hbot,zeta,hc,dCs,N): return (zeta + hbot)*(hc/N+dCs*hbot)/(hc + hbot) assert f(1,0,0,0,1) == 0
benchmark_functions_edited/f7709.py
def f(A): xor = 0 for item in A: xor ^= item return xor assert f( [1, 2, 2]) == 1
benchmark_functions_edited/f3449.py
def f(seq1, seq2): return sum(0 if a == b else 1 for (a, b) in zip(seq1, seq2)) assert f(list('123'), list('321')) == 2
benchmark_functions_edited/f13404.py
def f(technology_id: int, type_id: int) -> int: if technology_id > 0: return technology_id return 1 if type_id in {1, 3, 4, 6} else 2 assert f(0, 8) == 2