R

@RealSaitama

Geometric problem (ladder)

Python
11 months ago
l = 7 c = 2.4 r = (c**2+l**2)**0.5 x = c + r y=c*x print(x, y) d = l**2 -2*c**2-2*c*r print(d, r) x1 = (c+r +d**0.5) /2 x2 = (c+r -d**0.5) /2

Maximizer

Python
11 months ago
import numpy as np import scipy.optimize as opt from scipy.optimize import differential_evolution, basinhopping import itertools from typing import List, Tuple, Dict, Any import time class FunctionOptimizer: """ Optimizer for the function:

Mysterious Cipher

Python
11 months ago
ts = [ ('this will probably not be fun', 'tiks zjop twrggfrf uwz kl pcx'), ('hopefully you will find satisfaction at least', 'hprehxmoc ctx cmrs mqtl zjdqcqjnfsaa nh ztnhj'), ('really this is very tedious', 'rfclnb wlkw lx zkyd

Bi-tangents

Python
11 months ago
from math import hypot, acos, cos, sin, pi, atan2 class Segment: def __init__(self, p1, p2): self.p1 = p1 self.p2 = p2 def length(self): return hypot(self.p1.x - self.p2.x, self.p1.y - self.p2.y)

Euclidean MST (minimum spanning tree)

Python
11 months ago
from math import dist import heapq as hq from scipy.spatial import Delaunay # Requires scipy def bridge(pts): n = len(pts) if n <= 1: return 0 # Compute Delaunay triangulation

Prim Algorithm (Fibonacci Heap)

Python
11 months ago
import math from typing import List, Tuple, Optional, Dict class FibonacciHeapNode: """Node in a Fibonacci heap.""" def __init__(self, key: float, value: int): self.key = key self.value = value self.parent: Opti

Kruskal c++

C++
11 months ago
#include <iostream> #include <vector> #include <algorithm> std::vector<int> parent, rank; void make_set(int v) { parent[v] = v; rank[v] = 0; }

Kruskal (disjoint sets)

Python
11 months ago
class Edge: def __init__(self, u, v, weight): self.u = u self.v = v self.weight = weight def __str__(self): return f"({self.u},{self.v},{self.weight})" def __lt__(self, other):

Minimum Spanning Tree (Kruskal)

Python
11 months ago
class Edge: def __init__(self, u, v, weight): self.u = u self.v = v self.weight = weight def __str__(self): return f"({self.u},{self.v},{self.weight})" def __lt__(self, other):

Trampoline Code Optimization

NodeJS
11 months ago
// Transform function definitions to support tail call optimization via trampolines function transformToTCO(functionDefs) { const functions = new Map(); // Parse function definitions functionDefs.forEach(([name, params, body]) => {

Max sum contiguous Submatrix (Kadane)

NodeJS
11 months ago
tests = [ [ [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ], 45 ], [ [

Switch Bulbs (Hamitonian Path)

Python
11 months ago
# Claude AI Hamiltonian path finder class HamiltonianPathSolver: def __init__(self, graph): self.graph = [list(graph[k]) for k in sorted(graph.keys())] # adjacency list representation self.n = len(graph) self.forced_star

Jordan

Python
11 months ago
from fractions import Fraction arr = [[1, 1, 1, 1, 0, 0, 1, 0, 0, 0] , [1, 1, 1, 0, 1, 0, 0, 1, 0, 1] , [1, 1, 1, 0, 0, 1, 0, 0, 1, 0] , [1, 0, 0, 1, 1, 1, 1, 0, 0, 1] , [0, 1, 0, 1, 1, 1, 0, 1, 0, 1] , [0, 0, 1, 1, 1, 1, 0, 0, 1, 1] , [1, 0, 0, 1,

Advanced binary toggling puzzle

Python
11 months ago
tests = [ [[ [1, 0, 1], [0, 0, 0], [1, 0, 1] ],[(1, 1)]], [[ [0, 1, 0], [1, 0, 0], [0, 0, 1]

Segment Tree

Python
11 months ago
op = lambda x, y: x + y tree = {} def build(node, L, R): if L == R: tree[node] = xs[L] else: mid = (L + R) // 2 build(2 * node, L, mid) build(2 * node + 1, mid + 1, R)

Largest Palindromic product

Python
11 months ago
arr = [] a, b = 1234, 4321 # for x in range(1, a + 1): # for y in range(1, b + 1): # arr.append((x * y, x, y)) # arr.sort(key=lambda x: -x[0]) def makePalindrome(number): num_str = str(number) digits = len(num_str)

Number concatenation

Python
11 months ago
tests = [ (4748, 47), (123, 122), (5347, 3475), (121, 12), (213, 12), (321, 132), (7234723, 7234), (122, 21), (12, 1),

Associative operation

Python
11 months ago
xs = [2, 1, 5, 3, 4] op = lambda x, y: x + y tree = {} def build(node, L, R): if L == R: tree[node] = xs[L] else: mid = (L + R) // 2 build(2 * node, L, mid)

CodeWars SAFE (TipToe)

Python
11 months ago
from math import hypot, acos, cos, sin, pi, atan2 from collections import defaultdict import heapq as hq import time EPS = 1e-7 # returns True if the point corresponding to the angle x lies between the points for angles a and b def is_between_angles

Quad Tree

Python
11 months ago
from math import hypot, acos, cos, sin, pi, atan2 class _Point: def __init__(self, x, y): self.x = x self.y = y def __str__(self): return f"({self.x}, {self.y})"