name | correct guesses | games together | ratio |
---|
name | correct guesses | games together | ratio |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import itertools import functools import operator def vectorize(f): def g(*args): match args: case [*x], [*y]: return [*map(f, x, y)] case [*x], y: return [f(a, y) for a in x] case x, [*y]: return [f(x, b) for b in y] case x, y: return f(x, y) return g def evaluate(ast, input): if ast == "a": return input if callable(ast): return ast acc = evaluate(ast[-1], input) i = len(ast) - 2 while i >= 0: assert callable(f := ast[i]) if i > 0 and not callable(lhs := evaluate(ast[i - 1], input)): acc = f(lhs, acc) i -= 2 else: acc = f(acc) i -= 1 return acc builtins = { "+": vectorize(operator.add), "-": vectorize(operator.sub), "⌊": vectorize(min), "⌈": vectorize(max), "⌽": lambda x: list(reversed(x)), } def run(code, input): stack = [[]] for c in code: if c == "(": stack.append([]) elif c == ")": top = stack.pop() stack[-1].append(top) elif c == "/": f = stack[-1].pop() stack[-1].append(lambda x, f=f: functools.reduce(f, x)) elif c == "\\": f = stack[-1].pop() stack[-1].append(lambda x, f=f: list(itertools.accumulate(x, f))) else: stack[-1].append(builtins.get(c, c)) return evaluate(stack.pop(), input) entry = functools.partial(run, r"+/((⌈\a)⌊⌽⌈\⌽a)-a") print(entry([0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1])) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | """ given two strings, there exists at least one string that is a substring of both strings such that there is no longer string with the same property. your challenge is to return one of these strings. """ exec( __doc__ .replace("given two strings, ", "def entry(x: str, y: str):") .replace("there exists at least one", "substrings_of_x = {x[i:j] for i in range(len(x) + 1) for j in range(i, len(x) + 1)}; substrings_of_y = {y[i:j] for i in range(len(y) + 1) for j in range(i, len(y) + 1)}; substrings_of_both_strings = substrings_of_x & substrings_of_y; these_strings = (") .replace("that is a", "for string in") .replace("substring of both strings", "substrings_of_both_strings") .replace("such that", "if") .replace("there is no", "not any(") .replace("longer string", "len(x) > len(string)") .replace("with the same property.", "for x in substrings_of_both_strings))") .replace("your challenge is to ", ";") .replace("one of these strings.", "next(these_strings)") ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from sympy import * def entry(m, a, b): n = len(m) p = m = Matrix(n, n, lambda i, j: int(m[i][j]) * Symbol(f'e{n*i+j}', commutative=False)) while pprint(p) or not p[a, b]: p *= m path = Mul.make_args(Add.make_args(p[a, b])[0]) return [a] + [int(v.name[1:]) % n for v in path] if __name__ == "__main__": print(entry([ [False, True, True,False], [False,False, True, True], [ True, True,False, True], [False,False, True,False], ], 3, 1)) |
post a comment