R

@RealSaitama

Splitting digits

Python
2 hours ago
# https://oeis.org/A193238 def is_prime(n): for d in range(2, int(n**0.5) + 1): if n % d == 0: return 0 return 1 if n > 1 else 0 def f(n): if n < 10:

Tandem duplication string

Python
1 week ago
from itertools import groupby s = "01" l = [] q = [(s, [])] m = 5 f = lambda s: [len(list(g)) for k, g in groupby(s)] while q: x, ops = q.pop() l.append((x, f(x), ops))

GCD path

Python
3 weeks ago
def make_sq(x, y): sq = set([(x, y)]) u, v = x, y while v > 0: u, v = v, u % v if u > 0 and v > 0: sq.add((u, v)) o1 = set([(abs(x - y), y) for x, y in sq if x != y]) o2 = set([(x, abs(x - y)) for x, y

Minimax Dijkstra

Python
1 month ago
grid = [[22, 85, 42, 19, 75, 56, 3, 8, 16, 96, 78, 37, 14, 70, 80, 6, 84, 23, 79, 63, 10, 97, 93, 18, 44, 59, 18, 5, 70, 82, 34, 13, 75, 44, 70, 80, 62, 86, 68, 26], [75, 73, 40, 56, 27, 4, 19, 15, 94, 82, 21, 25, 66, 40, 90, 52, 10, 33, 79, 33, 72,

Naive Shuffle Algorithm

Python
1 month ago
from collections import defaultdict n = 3 h = defaultdict(int) xs = list(range(1, n + 1)) q = [(xs, 0)] while q: e, c = q.pop() if c == n: h[tuple(e)] += 1

IOI (level 5)

Python
1 month ago
d, m = map(int, input().split(' ')) h = {} for _ in range(d): s = input() h[(s[0], s[-1], len(s), ''.join(sorted(s[1: -1])))] = s for k, v in h.items(): print(k, v) print("#" * 20) while 1: try:

Infinite Chessboard

Python
1 month ago
from math import ceil # n = 20 # arr =[ ['' for _ in range(n)] for _ in range(n)] # for x in range(n): # for y in range(n): # if x + y == 1: # arr[x][y] = ' 3' # elif x == y == 2: # arr[x][y] = ' 4'

Jumbled Clock

Python
1 month ago
angle = {12:0,1:30,2:60,3:90,4:120,5:150,6:180,7:210,8:240,9:270,10:300,11:330, 0: 0} n = [1,2,3,4,5,6,7,8,9,10,11,12] def hr(arr, h, m, s): f = lambda x: arr.index(x if x > 0 else 12) hh = h + 1 if h < 12 else 1 a = angle[f(hh)] -

Game Solver

NodeJS
1 month ago
showEachStepOfGame=false //or true language="English" //or "Chinese" function calc(arr, x){ let nx; if(arr[1] === ""){ nx = arr[2] !== '/' ? eval(`${x}${arr[2]}${arr[3]}`) : (x >= Number(arr[3]) ? Math.round(eval(`${x}${arr[2]}${arr[3]}`))

Bitwise OR and AND

Python
1 month ago
from random import randint # for _ in range(10): # a, b = randint(0, 100), randint(0, 100) # x = a & b # y = ~((~a) | (~b)) # print(x, y) def union(a, b): x = 0

Frog Claude

Python
1 month ago
import sys, time from math import isqrt # ---- FINAL VERSION to ship ---- def T(k): return k*(k+1)//2 def phase2_feasible(k, l, n): """O(1)-ish replacement: is (S2-n)/2 a subset sum of {k+1,...,l}?""" S2 = T(l) - T(k) if (S2 - n) % 2 !

Milk

Python
1 month ago
def solve(n, m): if n % 2 == 1 and m == n: print("rec1 :", [[n - k, k] for k in range(1, n // 2 + 1)] + [[n]]) return [[n - k, k] for k in range(1, n // 2)] + [[n]] elif n % 2 == 0 and m == n + 1: print("rec2 :", [[n

Frog

Python
1 month ago
from math import isqrt def T(k): return k*(k+1)//2 def phase2_feasible(k, l, n): S2 = T(l) - T(k) if (S2 - n) % 2 != 0: return False T2p = (S2 - n) // 2 if T2p < 0: return False if T2p == 0: return True

Frog Jump

Python
1 month ago
from math import isqrt # [1, 2, -3] => f(1) = 3 # [1, -2, 3, 4, -5, 6, -7] => f(2) = 7 # [1, 2, -3] => f(3) = 3 # [-1, 2, 3, -4] => f(4) = 4 # [1, 2, 3, 4, -5, -6, -7, 8] => f(5) = 8 def solve(n): triangular = lambda x: x *(x + 1) // 2

Automorphic numbers

Python
1 month ago
# 0, 1, 5, 6, 25, 76, 376, 625, 9376, 90625, 109376, # 890625, 2890625, 7109376, 12890625, 87109376 n = 100 alpha = pow(2, 10**n, 10**(n+1)) a = str(alpha) b = "" for i, s in enumerate(a): b += str(9 - int(s)) if i != len(a) - 1 else '5'

Square roots over G(q)

Python
2 months ago
def DLPpow2(u, g, n): if n == 1: return 0 if u == 1 else 1 a = n // 2 b = n - a c = DLPpow2(u**(2**b), g**(2**b), a) d = DLPpow2(u*g**(2**a-c),g**(2**a), b) return c + (d - 1) % 2**b def sqrt(x, q):

Décomposition

Python
2 months ago
N = 10**5 is_prime = lambda n: n > 1 and all(n % i != 0 for i in range(2, int(n**0.5) + 1)) primes = [i for i in range(2, N) if is_prime(i)] def decompose(n):

Perfect squares GCDS

Python
2 months ago
from math import gcd, isqrt from collections import defaultdict, Counter def liouville(m): n = m f = [] for d in [2, 3, 5]: while n % d == 0: f.append(d) n //= d

V.A paramètres

Python
2 months ago
from fractions import Fraction n = int(input()) xs, fs = [], [] for _ in range(n): a, b = input().split(' ') x, f = int(a), Fraction(b) xs.append(x) fs.append(f)

Bezout

Python
2 months ago
def bezout_ext(a, b): qs, rs = [], [a, b] while b > 0: q, r = divmod(a, b) print(f"{a} = {b} * {q} + {r}") qs.append(q) rs.append(r) a, b = b, a % b n = len(qs) - 3 m = len(rs) - 3