file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f6429.py
def f(n): x = n y = (x + 1) // 2 while y < x: x = y y = (x + n // x) // 2 return x assert f(64) == 8
benchmark_functions_edited/f9114.py
def f(state, path): if path.strip("/") == '': return state for p in path.strip("/").split("/"): if p not in state: return {} state = state[p] return state assert f( {"a": {"b": {"c": 0}}}, "a/b/c" ) == 0
benchmark_functions_edited/f1890.py
def f(a, b, ret=0): if b == 0: return ret return a/b assert f(0, 0, 2) == 2
benchmark_functions_edited/f4127.py
def f(value, default): if value is None: return default return value assert f(1, None) == 1
benchmark_functions_edited/f10872.py
def f(ls): left = 0 right = len(ls) - 1 while left < right: mid = (left + right) // 2 if ls[mid] > ls[right]: left = mid + 1 else: right = mid return left assert f( [0, 1, 2, 2, 3]) == 0
benchmark_functions_edited/f3242.py
def f(s1, s2): assert len(s1) == len(s2) return sum(c1 != c2 for c1, c2 in zip(s1, s2)) assert f(b"ATGGC", b"ATGGC") == 0
benchmark_functions_edited/f14001.py
def f(f): try: f2 = int(f) except ValueError as e: f2 = None if f2 is None or f2 != f: raise ValueError("%r is not an int" % f) return int(f) assert f(1.0) == 1
benchmark_functions_edited/f7401.py
def f(mut, grid, full_levels=False): if full_levels: mu = grid["C1F"] * mut + grid["C2F"] else: mu = grid["C1H"] * mut + grid["C2H"] return mu assert f(1, {"C1H": 2, "C2H": 3}) == 5
benchmark_functions_edited/f5959.py
def f(pack_idx, x_max): # similarly, if np.count_nonzero(bed_space) == x_max if pack_idx >= x_max: return 1 else: return 0 assert f(5, 3) == 1
benchmark_functions_edited/f2515.py
def f(n): count = 0 while n: n &= n - 1 count += 1 return count assert f(15) == 4
benchmark_functions_edited/f94.py
def f(a, b): return -(-a//b) assert f(1.0, 1) == 1
benchmark_functions_edited/f2638.py
def f(rows): return len([row for row in rows if row["interest"] is not None]) assert f( [ {"name": "John", "interest": 1}, {"name": "Samantha", "interest": 3}, {"name": "Jane", "interest": 5}, {"name": "Sarah", "interest": 7}, ] ) == 4
benchmark_functions_edited/f2818.py
def f(a, b): return sum([a[i]*b[i] for i in range(len(a))]) assert f([1], [1, 2]) == 1
benchmark_functions_edited/f9552.py
def f(client, server): if not (client and server): return 0 return max(client, server) assert f(None, 0) == 0
benchmark_functions_edited/f1686.py
def f(n): return (((n & -n) << 1) & n) != 0 assert f(12) == 1
benchmark_functions_edited/f11837.py
def f(num, a, b): return min(max(num, a), b) assert f(3, 1, 2) == 2
benchmark_functions_edited/f12798.py
def f(L): if len(L) == 0: return float('NaN') summ = 0 for i in L: summ += len(i) mean = summ / float(len(L)) tot = 0.0 for i in L: tot += (len(i) - mean) ** 2 std = (tot / len(L)) ** 0.5 return std assert f(list('abcd')) == 0
benchmark_functions_edited/f11736.py
def f(arr): four_plus = 0 res = [] for char in arr: if char == 0: res.append(char) if char != 0: if len(res) >= 4: four_plus += 1 for x in res: res.pop() if len(res) < 4 and len(res) > 0: return 0 return four_plus assert f( [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0
benchmark_functions_edited/f3891.py
def f(values): return sum(values) / len(values) assert f([-1, 0, 1]) == 0
benchmark_functions_edited/f11494.py
def f(n=100): # not space efficient n_fact = 1 for i in range(1, n + 1): n_fact *= i # insights: we can divide all the zeroes out as we go # while n_fact % 10 == 0: # n_fact /= 10 return sum([int(x) for x in str(n_fact)]) assert f(1) == 1
benchmark_functions_edited/f4256.py
def f(support_color): if 240.0 <= support_color <= 255.0: return 1 if 0.0 <= support_color <= 10.0: return 0 assert f(0.0) == 0
benchmark_functions_edited/f4860.py
def f(n): assert isinstance(n, int), "Digital sum is defined for integers only." return sum([int(digit) for digit in str(n)]) assert f(101) == 2
benchmark_functions_edited/f11573.py
def f(byte, offset, bit_value): if bit_value: return byte | (1 << offset) return byte & ~(1 << offset) assert f(0, 2, 1) == 4
benchmark_functions_edited/f2659.py
def f(func, id): if func (id) == True: return 1 else: return 0 assert f(lambda i: i == 3, 1) == 0
benchmark_functions_edited/f10003.py
def f(request, countType): count = request['items'][0]['statistics'][countType] print(f"{countType}: {count}") return count assert f( { 'items': [{ 'statistics': { 'viewCount': 1, 'subscriberCount': 2, 'hiddenSubscriberCount': 3, 'videoCount': 4 } }] }, 'videoCount' ) == 4
benchmark_functions_edited/f13297.py
def f(n): if n == 1: return 1 elif n == 2: return 2 elif n == 3: return 1 + 2 * 2 + 1 else: ways = f(n - 1) * n + f(n - 2) * (n - 1) assert f(2) == 2
benchmark_functions_edited/f9569.py
def f(x): return x * (x > 0) assert f(0.0) == 0
benchmark_functions_edited/f12819.py
def f(str1, str2): return sum(str1[i] != str2[i] for i in range(len(str1))) assert f('SOSSPSSQSSOR', 'SOSSOSSOSSOS') == 3
benchmark_functions_edited/f11487.py
def f(n): "*** YOUR CODE HERE ***" index = n - 1 while index > 0: if n % index == 0: return index index -= 1 assert f(15) == 5
benchmark_functions_edited/f4044.py
def f(result, error): if result is None: raise ValueError(error) return result assert f(1, "error message") == 1
benchmark_functions_edited/f4519.py
def f(tot, deltaT): return int( (tot - deltaT)*60. ) assert f(0, 0) == 0
benchmark_functions_edited/f3617.py
def f(argv=()): print(argv) return 0 assert f((x for x in [])) == 0
benchmark_functions_edited/f13713.py
def f(this, other): if len(this) != len(other): return -1 if len(this) < len(other) else 1 for i in range(len(this)): this_item, other_item = this[i], other[i] if this_item != other_item: return -1 if this_item < other_item else 1 else: return 0 assert f(list("abc"), list("abc")) == 0
benchmark_functions_edited/f1841.py
def f(m, f, w): s = 0 for i in range(len(f)): s += f[i] * w[i] return float(m)/float(s) assert f(0, [1,1], [1,0]) == 0
benchmark_functions_edited/f9894.py
def f(depigm, incpigm, cga, anyga): if depigm == 1 or incpigm == 1 or (anyga == 1 and cga == 0): return 1 elif depigm == 0 and incpigm == 0 and anyga == 0: return 0 else: return 88 assert f(1, 1, 1, 0) == 1
benchmark_functions_edited/f6395.py
def f(n): if n <= 1: return n else: return f(n - 1) + f(n - 2) assert f(0) == 0
benchmark_functions_edited/f4643.py
def f(year): if year % 100 == 0: return year // 100 return (year // 100) + 1 assert f(11) == 1
benchmark_functions_edited/f12865.py
def f(_str, _substr, i): count = 0 while i > 0: index = _str.find(_substr) if index == -1: return -1 else: _str = _str[index+1:] i -= 1 count = count + index + 1 return count - 1 assert f( "a", "", 1) == 0
benchmark_functions_edited/f901.py
def f(x): return x * 0. + 1. assert f(4) == 1
benchmark_functions_edited/f11890.py
def f(a,b): res, fail = divmod(a,b) if fail: raise ValueError("%r does not divide %r" % (b,a)) else: return res assert f(10,5) == 2
benchmark_functions_edited/f14498.py
def f(value,index,*args,**kwargs): if callable(value): return value(*args,**kwargs) if index is not None and (isinstance(value,tuple) or isinstance(value,list) or isinstance(value,dict)): return value[index] return value assert f((1,2,3),2) == 3
benchmark_functions_edited/f5596.py
def f(grid, c): acc = 0 for row in grid: for elem in row: acc += c == elem return acc assert f([], 1) == 0
benchmark_functions_edited/f8273.py
def f(attrib, key): val = attrib.get(key, 0) if isinstance(val, str): if val.isspace() or val == '': return 0 return val assert f({'key': 0}, 'key') == 0
benchmark_functions_edited/f3622.py
def f(d): return (0 if not isinstance(d, dict) else len(d) + sum(f(v) for v in d.values())) assert f(b'a') == 0
benchmark_functions_edited/f4247.py
def f(stringy): return(sum([float(i) for i in stringy.split(":")[1].split(",")])) assert f("1:1") == 1
benchmark_functions_edited/f12517.py
def f(text): try: return int(text, 0) except ValueError as ex: raise RuntimeError(f"Could not parse hex number '{text}': {ex}") assert f(b'5') == 5
benchmark_functions_edited/f1107.py
def f(x): return (x > 0) + 0.5 * (x == 0) assert f(10) == 1
benchmark_functions_edited/f4834.py
def f(memories): if "itim" in memories and "length" in memories["itim"]: return memories["itim"]["length"] return 0 assert f({}) == 0
benchmark_functions_edited/f5759.py
def f(grid): return grid[0][0] + grid[0][1] + grid[1][0] + grid[1][1] assert f( [[0, 0], [0, 0]]) == 0
benchmark_functions_edited/f4013.py
def f(x, y): if x == y == 0: return 0 else: return abs(x - y) / ((x + y) / 2) assert f(3, -1) == 4
benchmark_functions_edited/f742.py
def f(n): a, b = 0, 1 for _ in range(n): a, b = b, a+b return a assert f(0) == 0
benchmark_functions_edited/f8520.py
def f(temp): return round((int(temp) - 32) * .5556, 3) assert f(32) == 0
benchmark_functions_edited/f12915.py
def f(v, index, x): mask = 1 << index # Compute mask, an integer with just bit 'index' set. v &= ~mask # Clear the bit indicated by the mask (if x is False) if x: v |= mask # If x was True, set the bit indicated by the mask. return v # Return the result, we're done. assert f(1, 1, True) == 3
benchmark_functions_edited/f2088.py
def f(a, b): return abs(a[0] - b[0]) + abs(a[1] - b[1]) + abs(a[2] - b[2]) assert f( (0, 1, 1), (0, 1, 1) ) == 0
benchmark_functions_edited/f13270.py
def f(obj, attr, _type, default=None): try: val = _type(getattr(obj, attr, default)) except (TypeError, ValueError): return default return val assert f(object(), "no_such_attr", int, 0) == 0
benchmark_functions_edited/f4645.py
def f(pitch): return ((pitch % 12) + 3) % 12 assert f(24) == 3
benchmark_functions_edited/f6786.py
def f(file_data_type): switcher = { 'VolumeDataType_Float': 4 } return switcher.get(file_data_type, 2) assert f( "VolumeDataType_Float" ) == 4
benchmark_functions_edited/f14557.py
def f(m, n, j, *f_i): dof = m * (n - 1 - j) + sum(f_i) return dof assert f(3, 5, 2, 1, 1, 1) == 9
benchmark_functions_edited/f5523.py
def f(headers): return sum(len(key) + len(value) + 4 for key, value in headers.items()) + 2 assert f(dict()) == 2
benchmark_functions_edited/f13310.py
def f(matrix): count = 0 i = 0 j = len(matrix) while j >= 0 and i < len(matrix): if matrix[i][j] < 0: count += j + 1 i += 1 else: j -= 1 return count assert f([]) == 0
benchmark_functions_edited/f12035.py
def f(n_terms): if not isinstance(n_terms, int): raise ValueError wallis_product = 2 for i in range(1, n_terms + 1): wallis_product = wallis_product * 4 * i**2 / ( 4 * i**2 - 1) return wallis_product assert f(0) == 2
benchmark_functions_edited/f8002.py
def f(rows, column_id): headers = rows[0] if column_id in headers: return headers.index(column_id) else: return None # add an exeption if not found? assert f( [ ['id', 'name', 'age'], [1, 'Jane', 24], [2, 'John', 25], [3, 'Jill', 26] ], 'age' ) == 2
benchmark_functions_edited/f7405.py
def f(bitmap): bmp = bitmap count = 0 n = 1 while bmp > 0: if bmp & 1: count += 1 bmp = bmp >> 1 n = n + 1 return count assert f(15) == 4
benchmark_functions_edited/f11222.py
def f(origin, next_ids, graph): prod = 1 for next_id in next_ids: if next_id in graph[origin]: prod *= graph[origin][next_id] else: prod *= 1-graph[next_id][origin] return prod assert f(3, [], {}) == 1
benchmark_functions_edited/f7762.py
def f(array, length): if length == 1: return array[0] if length == 2: return array[1] return max( array[-1] + f(array[:-1], length - 1), array[-2] + f(array[:-2], length - 2) ) assert f([2], 1) == 2
benchmark_functions_edited/f869.py
def f(base, height): area = 0.5 * base * height return area assert f(3, 4) == 6
benchmark_functions_edited/f10264.py
def f(path, value): if not path: return value if isinstance(path, str): path = path.split(".") curr = result = {} for k in path[:-1]: curr[k] = {} curr = curr[k] curr[path[-1]] = value return result assert f("", 1) == 1
benchmark_functions_edited/f9981.py
def f(nt): treeLength = 0 if nt is None: return treeLength treeLength = nt.distance return treeLength + f(nt.right) + f(nt.left) assert f(None) == 0
benchmark_functions_edited/f4463.py
def f(threads: int, single_threaded: bool) -> int: if single_threaded: return 1 return threads assert f(7, True) == 1
benchmark_functions_edited/f7640.py
def f(string: str) -> int: return len(string.splitlines()) assert f( "This is a string" ) == 1
benchmark_functions_edited/f3494.py
def f(t,fs,u,p): alpha = u['alpha'](t) f_st = p['F_st'](alpha) return 1/p['tau'] * (f_st - fs) assert f(0,0,{'alpha': lambda t: 0.5}, {'F_st': lambda alpha: 1, 'tau': 1}) == 1
benchmark_functions_edited/f5351.py
def f(arr: list) -> int: if len(arr) is None: return 0 res = 1 for item in arr: res *= item return res assert f([1]) == 1
benchmark_functions_edited/f4203.py
def f(f): gradient = 1 - f ** 2 return gradient assert f(-1) == 0
benchmark_functions_edited/f10098.py
def f(n: int) -> int: negative = False if n < 0: negative = True n = -n result = 0 while n > 0: result = result * 10 + n % 10 n //= 10 if negative: return -result return result assert f(0) == 0
benchmark_functions_edited/f2356.py
def f(nb_cards, n, position): return (position + n) % nb_cards assert f(5, 2, 2) == 4
benchmark_functions_edited/f12074.py
def f(added_content, deleted_content): return abs(len(added_content) - len(deleted_content)) assert f(list("123456789"), list("")) == 9
benchmark_functions_edited/f4040.py
def f(values): vmin = min(values) vmax = max(values) return (vmin + vmax) / 2 assert f(range(7)) == 3
benchmark_functions_edited/f10280.py
def f(cigar_tuple): if cigar_tuple[0] == 0 and cigar_tuple[1] >= 5: return 1 else: return 0 assert f((0, 5)) == 1
benchmark_functions_edited/f2230.py
def f(level=1): global verbosity verbosity = level return verbosity assert f(0) == 0
benchmark_functions_edited/f445.py
def f(bin_len): return int(bin_len,36) assert f('1') == 1
benchmark_functions_edited/f7814.py
def f(kd1, kd2): if kd1 == kd2: return 0 if kd1 < kd2: return -1 return 1 assert f('ac', 'ab') == 1
benchmark_functions_edited/f150.py
def f(x,y): z=x**2+y**2 return z assert f(2,2) == 8
benchmark_functions_edited/f3764.py
def f(vec1, vec2)->float: product = 0. for idx, val in enumerate(vec1): product += val * vec2[idx] return product assert f( (1, 0), (0, 0) ) == 0
benchmark_functions_edited/f13633.py
def f(increment, level): if level == 1: return 3 return increment*level+1 assert f(3, 1) == 3
benchmark_functions_edited/f7106.py
def f(periodType, timeToElapse): if periodType == "weeks": return timeToElapse*7 if periodType == "months": return timeToElapse*30 return timeToElapse assert f(1, 2) == 2
benchmark_functions_edited/f1203.py
def f(l1, l2): return sum([i1 * i2 for (i1, i2) in zip(l1, l2)]) assert f( [1, 2, 3], [] ) == 0
benchmark_functions_edited/f14126.py
def f(n: int, k: int) -> int: if k > n: return 0 k = min(k, n - k) # take advantage of symmetry c = 1 for i in range(k): c = (c * (n - i)) // (i + 1) return c assert f(0, 0) == 1
benchmark_functions_edited/f10368.py
def f(x1,y1,x2,y2): return int(abs(x2-x1) + abs(y2-y1)+.5) assert f(1,1,1,1) == 0
benchmark_functions_edited/f8143.py
def f(time_in_seconds, winlength, winstep): time_in_frames = (time_in_seconds - winlength/2)/winstep time_in_frames = int(round(time_in_frames)) if time_in_frames < 0: time_in_frames = 0 return time_in_frames assert f(5, 2, 2) == 2
benchmark_functions_edited/f11034.py
def f(x, low=None, high=None): if high is not None and x > high: return high elif low is not None and x < low: return low else: return x assert f(4, 1, 3) == 3
benchmark_functions_edited/f6028.py
def f(row, col): row_offset = (row * (row + 1)) / 2 index = row_offset + col return index assert f(3, 3) == 9
benchmark_functions_edited/f5020.py
def f(prod): return (prod > 0.5) assert f(0.4) == 0
benchmark_functions_edited/f13604.py
def f(*it): m = set() for i in it: try: m.add(len(i)) except TypeError: pass if len(m) > 0: return max(m) else: return 1 assert f({1, 2, 3}) == 3
benchmark_functions_edited/f2047.py
def f(if_func, func, arg): if if_func(arg): return func(arg) return arg assert f(lambda x: x > 0, lambda x: x, 1) == 1
benchmark_functions_edited/f1784.py
def f(element, seq): return seq.f(element) assert f(3, [1, 2, 1, 3, 4]) == 1
benchmark_functions_edited/f12527.py
def f(karma): if karma is None: return 1 if karma >= 1000: return 2 return 1 assert f(30) == 1
benchmark_functions_edited/f6195.py
def f(lst): for element in lst: if element: return element assert f( [[], [], 1, [2, 3, 4], [], []]) == 1
benchmark_functions_edited/f9273.py
def f(beta, x): # Expression of the line that we want to fit to the data y = beta[0] + beta[1] * x return y assert f([1, 2], 2) == 5
benchmark_functions_edited/f13277.py
def f(m: int, n: int) -> int: if m == 1 and n == 1: # base case return 1 if m == 0 or n == 0: # either dims empty no way to travel return 0 return f(m - 1, n) + f(m, n - 1) assert f(3, 2) == 3
benchmark_functions_edited/f14235.py
def f(timeseries, end_timestamp, full_duration): try: t = (timeseries[-1][1] + timeseries[-2][1] + timeseries[-3][1]) / 3 return t except IndexError: return timeseries[-1][1] assert f( [ (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), ], 6, 6, ) == 5