R

@RealSaitama

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,

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 knigh

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 >

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 =

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)))

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_

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_facto

Happy Number

Python
1 year ago
# B4B solution from itertools import permutations from bisect import bisect PERMS = [int(''.join(p)) for p in permutations('0123456789') if p[0] != '0'] def next_happy_number(number): return PERMS[bisect(PERMS,number)] def _next_happy_num

DLX

Python
1 year ago
#!/usr/bin/env python # # Copyright 2008 Sebastian Raaphorst. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http