This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from mpmath import * | |
from math import comb, factorial | |
def A(r, s): | |
if r == 0 or s in (0, 2): | |
return 1 | |
if s == 1: | |
return 0 | |
bits_needed = int((loggamma(s*r+1) - s*loggamma(r+1)) / log(2)) + 40 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
# paste into SageMathCell | |
# https://puzzling.stackexchange.com/q/125902/75318 | |
straights = [list(range(i, i+5)) for i in range(1, 6)] | |
# For simplicity we assign (35, 36, 37, 38, 39) as the royal flush; | |
# since any 0-4 straight would then prevent four of a kind we omit that from the straights list | |
def hand_strength(hand): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from subprocess import run | |
# Requires the compiled sharpSAT solver (https://github.com/marcthurley/sharpSAT) to be in the same folder as this script | |
def a(N): | |
if N < 2: | |
return 1 | |
fam = {i: [] for i in range(2, N+1)} | |
for i in range(2, N+1): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
# https://puzzling.stackexchange.com/q/118794/75318 | |
root = DiGraph({v: [] for v in range(6)}, immutable=True) | |
G = DiGraph({root: []}) | |
unproc = G.vertices(sort=False) | |
while unproc: | |
H = unproc.pop() | |
HG = H.automorphism_group() | |
# Find orbit representatives of incomparable pairs | |
incomps = [(i,j) for (i,j) in combinations(range(6), 2) if H.distance(i,j) == H.distance(j,i) == infinity] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from sage.combinat.matrices.dancing_links import dlx_solver | |
from itertools import combinations | |
import numpy as np | |
t7 = np.array([[3,2], [3,1], [4,1], [4,3], [4,4], [2,2], [1,1]]) | |
t7r = np.stack([t7[:,0]-t7[:,1],t7[:,0]], axis=1) | |
t14 = np.concatenate([t7, t7r]) | |
tt = np.concatenate([t14, t14-[5,1], t14+[1,-4], t14+[6,-3]]) # triangles | |
ttl = tt.tolist() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from sage.combinat.matrices.dancing_links import dlx_solver | |
compass = "RULD" | |
rings = ("0R 1L 5D 11D 16D 23D 24R 25R 26R 27R", # blue | |
"2R 3R 4R 5R 6D 13D 18D 24D 28L 29R", # red | |
"9R 10R 11R 12R 13R 14R 20D 26D 29D 21U", # orange | |
"15R 16R 17R 18R 19R 20R 8U 0D 3D 9D", # yellow | |
"21R 22R 23R 17U 12U 6R 7R 8R 27D 2D", # green | |
"4D 10D 15D 22D 28D 25U 19U 14U 7U 1U") # violet | |
rings = [[(int(c[:-1]), c[-1]) for c in s.split()] for s in rings] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from math import isqrt, factorial, log | |
from itertools import combinations, permutations, chain | |
# https://puzzling.stackexchange.com/q/118708/75318 | |
lim = factorial(12) | |
sqrt = (lambda x: x > 1 and isqrt(x)**2 == x, | |
isqrt, | |
lambda s: f"{s} r") | |
fact = (lambda x: 3 <= x <= 12, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from mpmath import * | |
mp.dps = 50 | |
# https://math.stackexchange.com/a/4539522/357390 | |
def l(n): | |
return 2*n*quad(lambda v: sqrt(power(v,n-2)+power(1-v,n-2)), [0,1]) | |
def L(n): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <cstdint> | |
#include <cstdio> | |
#include <algorithm> | |
#include <numeric> | |
#include <random> | |
typedef uint32_t rk_t; // rank type | |
typedef uint8_t el_t; // element type | |
struct cover_data { | |
rk_t** neighbours; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import random | |
from collections import Counter | |
rng = random.SystemRandom() | |
import numpy as np | |
wheel = [0]*7 + [1,2,3,4,5,6,7,8,9]*2 | |
def guess(): | |
probs = np.full(10, 1/10) | |
trials = 0 |
NewerOlder