R

@RealSaitama

Minesweeper

NodeJS
1 year ago
class Constraint { constructor(cells, total) { this.cells = cells; this.total = total;

Make pairs of prime

Python
1 year ago
M = 2 * 10**5 + 1 sieve = [True] * M sieve[0] = sieve[1] = False for i in range(2, int(M**0.5) + 1): for j in range(2 * i, M, i): sieve[j] = False def make_pairs(n): ans = [] def find(m):

Golden section search (max)

Python
1 year ago
def fct(x): return x * (1.5 - x) c = (-1 + 5**0.5) / 2 a, b = 0, 1 x1, x2 = c * a + (1 - c) * b, (1 - c) * a + c * b fx1, fx2 = fct(x1), fct(x2) for i in range(28): if fx1 > fx2: # "<" insread of ">" if minimum search b = x2;

Smallest window containing a pattern

Python
1 year ago
from collections import Counter w, h = map(int, input().split()) s = ''.join(input() for _ in range(h)) n = int(input()) ps = [input() for _ in range(n)] cnt = Counter(s) print(s)

Shortest Unique Prefix

Python
1 year ago
n = int(input()) words = [input() for _ in range(n)] fst = [w[0] for w in words] hsh = {f: set([word for word in words if word.startswith(f)]) for f in fst } while any(len(v) > 1 for v in hsh.values()): _hsh = {} for k, v in hsh.items(): if len(v) > 1:

Baker Biscuit

Python
1 year ago
from math import pi s, d = map(float, input().split()) a = pi * (d / 2)**2 t = int(s / d)**2 r = 0 while s >= d: u = int(s / d)**2 r += u s = (s**2 - u * a)**0.5 print("s :", s, "r :", r)

Railway Station Clock

Python
1 year ago
from fractions import Fraction import datetime x, d = input().split() h, m, s = map(int, x.split(':')) if d == 'PM': h += 12 h %= 12 # t = int(8 * 3600 + (3600 * (h - 8) + 60 * m + s) / 239 * 240) # h1 = t // 3600

Find Spaces Between Words

Python
1 year ago
from collections import deque w = input() ws = input().split() q = deque([([], w)]) ans = set() while len(q) > 0: path, r = q.popleft() if r == '':

Root directory

Python
1 year ago
from collections import defaultdict import os # Build the directory tree root_dir = 'Desktop' files = [ 'meetings/2021-01-12/notes.txt', 'meetings/2020_calendar.ods',

Strobogrammatic number

Python
1 year ago
def flip(st): return st[::-1].translate({ord('6'):ord('9'), ord('9'):ord('6')}) def is_strobo(st): return flip(st) == st and all(c in "0125689" for c in st) tests = (("69", "88"), ("99", "101"), ("999", "1001"), ("161", "181"), ("9987", "10001"), ("654321", "655559"), ("1260921", "1261921"), ("88888888", "88896888"), ("123456789", "125000521"), ("314159265359", "500000000005"), ("6920158510269", "6920160910269"), ("12688109960188921", "12688110001188921"))

Tree and seeds

Python
1 year ago
m = int(input()) n = int(input()) grid = [list(input()) for _ in range(n)] def _next(g): _g = [['.' for _ in range(m)] for _ in range(n)] for i in range(n): for j in range(m):

Paving with dominoes

Python
1 year ago
h, w = int(input()), int(input()) grid = [[False]*w for _ in range(h)] def backtrack(x, y): count = 0 while y < h and grid[y][x]: # Recherche de la prochaine case vide x += 1 if x >= w: x = 0 y += 1

Anagram position in dictionary

Python
1 year ago
# https://www.codingame.com/ide/puzzle/lexiscramble-quest word = input() from functools import reduce from math import factorial def position(s): n = 0

Cellular Binary Automaton

Python
1 year ago
# https://reference.wolfram.com/language/ref/CellularAutomaton.html n, it, rule = [int(input()) for _ in range(3)] def get_steps(n, it, rule): seen = {} b = [*map(int, f"{rule:08b}")] dct = {tuple(map(int, f"{i:03b}")) : b[7 - i] for i in reversed(range(8))} line = [1 if i == n // 2 else 0 for i in range(n)] k = 0

Range Number Division

Python
1 year ago
def cnt_digit(st): k = len(st) n = int(st) i = 0 ans = 0 while n > (m := 9 * 10**i): n -= m i += 1 ans += i * m ans += (i + 1) * n

Prime Ant

Python
1 year ago
import math def is_prime(a): for i in range(2, int(math.sqrt(a)) + 1): if a % i == 0: return i return True

Change cash

Python
1 year ago
xs = sorted(list(map(int, input().split())), reverse=True) n = int(input()) print(xs) def solve(n): q = [(n, [])] seen = set() ans = [] while len(q) > 0: e, p = q.pop(0)

Words inside sphere

Python
1 year ago
from math import comb from itertools import product def gen(s, k): if k < 1: return if k == 1: yield [s] for i in range(s + 1): for g in gen(s - i, k - 1):

Stern Brocot

Python
1 year ago
from fractions import Fraction def continued_frac_to_rational(cs): e = cs[-1] for x in reversed(cs[:-1]): e = x + Fraction(1) / e return e def rational_to_continued_frac(frac): ans = []

Ascii orbiting planet

Python
1 year ago
# https://www.codingame.com/ide/puzzle/chebyshev-orbiting r, x, y, vx, vy, t = [*map(int, input().split())] c = 0 visited = set() path = [] while c < t: if (x, y, vx, vy) in visited: xx, yy = path[t % len(path)] print(xx, yy, 0) exit()