R

@RealSaitama

ClaudeAI CrossSums

Python
1 year ago
from collections import deque from itertools import product class CrossSumsCSP: def __init__(self, grid, rows, cols): self.grid = grid self.rows = rows self.cols = cols self.n_rows = len(grid) self.n_cols

AC3

Python
1 year ago
import queue class CSPSolver: worklist = queue.Queue() # a queue of arcs (this can be a queue or set in ac-3) # arcs: list of tuples # domains: dict of { tuples: list } # constraints: dict of { tuples: list } def __init__(sel

Valid TicTacToe Board Count

Python
1 year ago
from itertools import product def is_valid_position(_b): b = [list(_b[:3]), list(_b[3: 6]), list(_b[6:])] winner = lambda c:any(''.join(r) == c*3 for r in b) or any(''.join(r) == c*3 for r in zip(*b)) or f"{b[0][0]}{b[1][1]}{b[2][2]}" ==

Tic Tac Toe

Python
1 year ago
class TicTacToe: def __init__(self): self.grid = [" " for _ in range(9)] self.human = "O" self.ai = "X" def __str__(self): return'\n'.join(' | ' .join(self.grid[3 * i: 3 * (i + 1)]) for i in range(3))

Subset Sum

Python
1 year ago
from itertools import product n = 8 d = 4 s = 0 for ps in product(*([range(2)] * n)): x = 0 for i, p in enumerate(ps): if p == 1: x += (i + 1)

GOL

NodeJS
1 year ago
function decodeCanon(apgcode) { var i; var chars = "0123456789abcdefghijklmnopqrstuvwxyz" for (i = 0; i < apgcode.length; i++) { if (apgcode[i] == "_") { i += 1; break; }

Hide from the Sun

NodeJS
1 year ago
const degToRad = Math.PI / 180; function crossProduct(u, v) { return [u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]]; } function normal(A, B, C){ let u = [B[0] - A[0], B[1] - A[1], B[2] - A[2]]; let v

Power Tail Series Approximation

Python
1 year ago
import numpy as np from math import exp, log xs = [-1.428086671, -0.357021668, -0.158676297, -0.089255417, -0.057123467, -0.039669074, -0.029144626,

Triads

Python
1 year ago
from itertools import combinations, permutations import numpy as np def gauss(a): arr = [r[:] for r in a] n, m = len(arr), len(arr[0]) h, k = 0, 0 while h < n and k < m: idx = next((i for i in range(h, n) if arr[i][k] != 0),

Nightmare binary to decimal

NodeJS
1 year ago
$=([__,..._$],_=+[])=>__?$(_$,_+_+ +__):_ console.log($("1101001101"))

Playing card odds

Python
1 year ago
from itertools import product values = "23456789TJKQKA" suits = "DCHS" cards = set([f"{x}{y}" for x, y in product(values, suits)]) def solve(a, b): start = set(cards) for x in a: vs, ss = [e for e in x if e in values], [e for e in x

Bouncing simulator

Python
1 year ago
def show(g): return '\n'.join(''.join(x) for x in g) +'\n\n' def solve(m, n, k): g = [["#"] * (m + 2) ] + [list(f"#{' ' * m}#") for _ in range(n)] + [["#"] * (m + 2)] if m == 1: x, y = 0, 1 dx = 1 r = 0

Organic Compounds

Python
1 year ago
s='''CH2(2)CH0(1)CH1(2)CH0(1)CH3 (1) (1) CH0 CH1(1)CH2(1)CH3 (3) (1) CH1 CH3'''.split('\n') def solve(_s): _m = max(len(x) for x in _s) s = [x.ljust(_m, ' ') for x in _s] print(s)

Wynne

Python
1 year ago
import numpy as np from math import log n = 15 def wynnepsilon(sn, r): """Perform Wynn Epsilon Convergence Algorithm""" r = int(r) n = 2 * r + 1 e = np.zeros(shape=(n + 1, n + 1)) for i in range(1, n + 1):

Generating numbers from letter

Python
1 year ago
[1, 3, 5, 9, 17, 33, 65, 129, 257, 513] xs = [ repr(int()), repr(repr(int())), repr(repr(repr(int()))), repr(repr(repr(repr(int())))), repr(repr(repr(repr(repr(int()))))), repr(repr(repr(repr(repr(repr(int())))))), repr(r

Bitset LightsOut

Python
1 year ago
def _next(idx, xs): x, y = divmod(idx, 3) b = [list(xs[:3]), list(xs[3: 6]), list(xs[6:])] for dx, dy in ((0, 1), (0, -1), (1, 0), (-1, 0)): u, v = x + dx, y + dy if 0 <= u < 3 and 0 <= v < 3: b[u][v] = "1" if

Damerau

Python
1 year ago
def damerau_levenshtein_distance(s, t, alphabet_size=256): m = len(s) n = len(t) # Initialize DP table dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(m + 1): dp[i][0] = i for j in range(n + 1): dp[0

Mahjong PureHand

Python
1 year ago
from collections import Counter from itertools import combinations_with_replacement def is_valid_hand(counts): """Recursive function to check if counts can be split into 4 melds.""" if sum(counts.values()) == 0: return True, []

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,

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