R

@RealSaitama

Puzzle Fighter

Python
10 months ago
see_states = True class block: def __init__(self, x, y, col, h=1, w=1, _type="normal"): self.x, self.y = x, y self.col = col self.h, self.w = h, w self.type = _type def __repr__(self):

Path Finder Through Circular Obstacles

Python
10 months ago
from math import hypot, acos, cos, sin, pi, atan2, sqrt from collections import defaultdict import heapq as hq def is_between_angles(x, a, b): a %= 2 * pi b %= 2 * pi x %= 2 * pi delta = (b - a) % (2 * pi) if delta <= pi:

ClaudeAI CrossSums

Python
10 months 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 = len(grid[0])

AC3

Python
10 months 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__(self, arcs: list, domains: dict, constraints: dict):

Valid TicTacToe Board Count

Python
10 months 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]}" == c*3 or f"{b[0][2]}{b[1][1]}{b[2][0]}" == c*3 cnt = lambda c:''.join(''.join(r) for r in b).count(c) more = cnt('X') in range(0, 6) and cnt('O') in range(0, 5) diff = cnt('X') - cnt('O')

Tic Tac Toe

Python
10 months 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)) def available(self):

Subset Sum

Python
10 months 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
10 months 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
10 months 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 = [C[0] - A[0], C[1] - A[1], C[2] - A[2]]; return crossProduct(u, v);

Power Tail Series Approximation

Python
11 months 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
11 months 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), None) if idx is None:

Nightmare binary to decimal

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

Playing card odds

Python
11 months 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 if e in suits] if len(vs) == 0:

Bouncing simulator

Python
11 months 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
11 months 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
11 months 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
11 months 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(repr(repr(repr(repr(repr(repr(int()))))))), repr(repr(repr(repr(repr(repr(repr(repr(int())))))))),

Bitset LightsOut

Python
11 months 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 b[u][v] == "0" else "0" b[x][y] = "1" if b[x][y] == "0" else "0" return ''.join(b[0]) +''.join(b[1])+''.join(b[2])

Damerau

Python
11 months 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][j] = j

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, [] for i in range(1, 10): if counts[i] >= 3: