R

@RealSaitama

iban

Python
1 year ago
''' • IBAN: GB82 WEST 1234 5698 7654 32 • Rearrange: W E S T12345698765432 G B82 • Convert to integer: 3214282912345698765432161182 • Compute remainder: 3214282912345698765432161182 mod 97 = 1 ''' import re COUNTRIES = {'AT': 20, 'BE': 16, 'BG': 22, 'CY': 28, 'CZ': 24, 'FO': 18, 'GL': 18, 'DK': 18, 'EE': 20, 'FI': 18, 'FR': 27, 'DE': 22, 'GI': 23, 'GR': 27, 'HU': 28, 'IS': 26, 'IE': 22, 'IT': 27, 'LV': 21, 'LI': 21, 'LT': 20, 'LU': 20, 'MT': 31, 'MC': 27, 'NL': 18, 'NO': 15, 'PL': 28,

Screen locking pattern

Python
1 year ago
# xs = list(divmod(i, 4) for i in range(16)) # dct = dict(zip("ABCDEFGIJLMNOP", xs)) # from collections import defaultdict # # print(dct) # def are_aligned(p1, p2, p3): # det = (p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0]) # k = (p2[0] - p1[0]) / (p3[0] - p1[0]) if p3[0] != p1[0] else (p2[1] - p1[1]) / (p3[1] - p1[1]) # same = 0 < k < 1 # return det == 0 and same

Area

Python
1 year ago
# https://www.youtube.com/watch?v=0KjG8Pg6LGk def det(u, v): return u[0] * v[1] - u[1] * v[0] def area(xs): n = len(xs) return abs(sum(det(xs[i], xs[(i + 1) % n]) for i in range(n))) / 2 pts = [(1, 3), (2, 1), (4, 2), (3, -1), (-2, -2), (-3, 2), (-1, 1)]

JSFuck

NodeJS
1 year ago
const MIN = 32, MAX = 126; const SIMPLE = { 'false': '![]', 'true': '!![]', 'undefined': '[][[]]', 'NaN': '+[![]]', 'Infinity': '+(+!+[]+(!+[]+[])[!+[]+!+[]+!+[]]+[+!+[]]+[+[]]+[+[]]+[+[]])' // +"1e1000" };

Chess960

Python
1 year ago
from itertools import combinations lst = [] cnt = 0 for bishop1 in range(0, 8, 2): for bishop2 in range(1, 8, 2): s = set(range(8)) - set([bishop1, bishop2]) for queen in s: t = s - set([queen]) for knight1, knight2 in combinations(t, r=2):

Romeo & Juliet

Python
1 year ago
from random import random def sim(t, n): s = 0 for _ in range(n): r, j = random(), random() if abs(r - j) <= t: s += 1 return s / n step = 100

KUboble

Python
1 year ago
import re b = ". X . . ;a X b . ;. C cB A" def show(b): return '\n'.join(b.split(";")) def move(piece, b, dx, dy): board = [r[:] for r in b] n, m = len(board), len(board[0])

JSfuck

NodeJS
1 year ago
// [+[]]+[] // [+!+[]]+[] // [!+[]+!+[]]+[] // [!+[]+!+[]+!+[]]+[] // [!+[]+!+[]+!+[]+!+[]]+[] // [!+[]+!+[]+!+[]+!+[]+!+[]]+[] // [!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[] // [!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[] // [!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[] // [!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[]

Radical Continued Fraction

Python
1 year ago
from math import isqrt def frac(n): a0 = isqrt(n) seq = [] r, s = 0, 1 seen = set() while not (r, s) in seen: seen.add((r, s)) a = (r + a0) // s

Chiffrement (Ex 126 Maths expertes)

Python
1 year ago
def cipher(a, b, s): ans = "" for c in s: m = ord(c) - ord('A') p = (a * m + b) % 26 l = chr(65 + p) ans += l return ans def decode(s):

Tchebyshev

Python
1 year ago
T = [[1], [1, 0]] for n in range(2, 10): A = [2 * x for x in T[-1]] + [0] B = [0, 0] + T[-2] C = [x - y for x, y in zip(A, B)] T.append(C) for i, p in enumerate(T): print(f"i = {i} => {T[i]}") # pol = ' '.join(f"{'+' if a > 0 else '-'} {abs(a)}X^{i-k}" for k, a in enumerate(T[i]) if a != 0)

codewars

Python
1 year ago
from math import isqrt def solve(num, k): ans = [] for a in range(num - 1, 1, -1): for nm in range(1, a): b2 = a * a - nm * nm b = isqrt(b2) if b * b == b2: n, m = isqrt(a + b), isqrt(a - b)

Rallye 2025

Python
1 year ago
ns = set() for c in range(1, (int(2025**(1/3)))+1): for b in range(c+1, (int((2025/2)**(1/3)))+1): for a in range(b+1, (int(2025**(1/3)))+1): N = a**3+2*b**3+c**3 if N < 2025: ns.add((N,(a,b,c))) # for x in sorted(ns,key=lambda x:x[1]): # print(x)

Cut the number

Python
1 year ago
from functools import cache def decompose(n): if n == 0: return [[]] elif n == 1: return [[1]] ans = [] for k in range(1, n + 1): for d in decompose(n - k):

Shunting Yard RPN Evaluator

Python
1 year ago
# https://inspirnathan.com/posts/155-handling-unary-operations-with-shunting-yard-algorithm import re import math import operator funcs = { "sin": math.sin, "cos": math.cos, "tan": math.tan,

Factorial Digit Sum

Python
1 year ago
from functools import cache fac = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880] pfds = lambda xs: sum((i + 1) * fac[x] for i, x in enumerate(xs[::-1])) @cache def gen(s, k): if s < k: return []

Amicable Numbers

Python
1 year ago
from collections import defaultdict def strict_divisor_sum(n): return 1 + sum(((d if d * d == n else d + n // d) for d in range(2, int(n**0.5) + 1) if n % d == 0)) N = 150000 dct = defaultdict(set) for n in range(1, N): s = strict_divisor_sum(n) dct[s].add(n)

Subtract sum of digits (https://oeis.org/A309417)

Python
1 year ago
# from collections import defaultdict # M = 10**3 # dp = [0 for _ in range(M + 1)] # for i in range(1, M): # dp[i] = 1 + dp[i - sum(int(c) for c in str(i))] # def jump_to_zero(xs): # return list(map(lambda x: dp[x], xs))

Uniq Sets

Python
1 year ago
tests = [ [ [ frozenset([5, 8, (1, 2), "rvbc"]), frozenset(["fnyh", "esa", 1]), frozenset([("cev", "cdv", 0), 18]), ], False, ], [

Network Simplex

Python
1 year ago
from itertools import chain, islice, repeat from math import ceil, sqrt class Graph: node_dict_factory = dict node_attr_dict_factory = dict adjlist_outer_dict_factory = dict adjlist_inner_dict_factory = dict edge_attr_dict_factory = dict graph_attr_dict_factory = dict