Skip to content

Instantly share code, notes, and snippets.

View adventofcode-2021-day-22.py
import re
from rtree import index
p = index.Property()
p.dimension = 3
ix = index.Index(properties=p)
def volume(cuboids):
return sum((
View adventofcode-2021-day-21-part-2.sage
P.<x,y> = ZZ[]
R = P.quo((x^10 - 1, y^22 - y^21))
die = x + x^2 + x^3
f = P.hom([x*y, y])
def reduce(f):
return R.cover()(f).lift()
def next_move(p):
View adventofcode-2021-day-18.hs
import Control.Monad.State
( MonadState(put, get), runState, State )
import System.IO (isEOF)
import Text.Parsec ( char, digit, (<|>), parse )
data Snailfish = Leaf Int | Branch Snailfish Snailfish
deriving (Eq)
instance Show Snailfish where
show (Leaf n) = show n
@robinhouston
robinhouston / README.md
Last active Jul 20, 2021
Parabolic flow
View README.md

A flow that preserves a parabola

@robinhouston
robinhouston / gist:7f9a5bb719222a18b11205c2a2a8bf3c
Created Apr 14, 2021
Regex to test for divisibility by 11, in base 9
View gist:7f9a5bb719222a18b11205c2a2a8bf3c
^(0|13*2|(2|13*4)(6|53*4)*(4|53*2)|(3|13*5|(2|13*4)(6|53*4)*(7|53*5))(73*5|(8|73*4)(6|53*4)*(7|53*5))*(6|73*2|(8|73*4)(6|53*4)*(4|53*2))|(4|13*6|(2|13*4)(6|53*4)*(8|53*6)|(3|13*5|(2|13*4)(6|53*4)*(7|53*5))(73*5|(8|73*4)(6|53*4)*(7|53*5))*(73*6|(8|73*4)(6|53*4)*(8|53*6)))(1|0(73*5|(8|73*4)(6|53*4)*(7|53*5))*(73*6|(8|73*4)(6|53*4)*(8|53*6)))*(8|0(73*5|(8|73*4)(6|53*4)*(7|53*5))*(6|73*2|(8|73*4)(6|53*4)*(4|53*2)))|(5|13*7|(2|13*4)(6|53*4)*53*7|(3|13*5|(2|13*4)(6|53*4)*(7|53*5))(73*5|(8|73*4)(6|53*4)*(7|53*5))*(0|73*7|(8|73*4)(6|53*4)*53*7)|(4|13*6|(2|13*4)(6|53*4)*(8|53*6)|(3|13*5|(2|13*4)(6|53*4)*(7|53*5))(73*5|(8|73*4)(6|53*4)*(7|53*5))*(73*6|(8|73*4)(6|53*4)*(8|53*6)))(1|0(73*5|(8|73*4)(6|53*4)*(7|53*5))*(73*6|(8|73*4)(6|53*4)*(8|53*6)))*(2|0(73*5|(8|73*4)(6|53*4)*(7|53*5))*(0|73*7|(8|73*4)(6|53*4)*53*7)))(4|03*7|(1|03*4)(6|53*4)*53*7|(2|03*5|(1|03*4)(6|53*4)*(7|53*5))(73*5|(8|73*4)(6|53*4)*(7|53*5))*(0|73*7|(8|73*4)(6|53*4)*53*7)|(3|03*6|(1|03*4)(6|53*4)*(8|53*6)|(2|03*5|(1|03*4)(6|53*4)*(7|53*5))(73*5|(8|73
View Regex to test for divisibility by 9, in base 11
^(0|9|[1a]8*7|(2|[1a]8*[09])(7|68*[09])*(5|68*7)|(3|[1a]8*[1a]|(2|[1a]8*[09])(7|68*[09])*(8|68*[1a]))(6|48*[1a]|(5|48*[09])(7|68*[09])*(8|68*[1a]))*(3|48*7|(5|48*[09])(7|68*[09])*(5|68*7))|(4|[1a]8*2|(2|[1a]8*[09])(7|68*[09])*(0|9|68*2)|(3|[1a]8*[1a]|(2|[1a]8*[09])(7|68*[09])*(8|68*[1a]))(6|48*[1a]|(5|48*[09])(7|68*[09])*(8|68*[1a]))*(7|48*2|(5|48*[09])(7|68*[09])*(0|9|68*2)))(5|28*2|(3|28*[09])(7|68*[09])*(0|9|68*2)|(4|28*[1a]|(3|28*[09])(7|68*[09])*(8|68*[1a]))(6|48*[1a]|(5|48*[09])(7|68*[09])*(8|68*[1a]))*(7|48*2|(5|48*[09])(7|68*[09])*(0|9|68*2)))*(1|a|28*7|(3|28*[09])(7|68*[09])*(5|68*7)|(4|28*[1a]|(3|28*[09])(7|68*[09])*(8|68*[1a]))(6|48*[1a]|(5|48*[09])(7|68*[09])*(8|68*[1a]))*(3|48*7|(5|48*[09])(7|68*[09])*(5|68*7)))|(5|[1a]8*3|(2|[1a]8*[09])(7|68*[09])*(1|a|68*3)|(3|[1a]8*[1a]|(2|[1a]8*[09])(7|68*[09])*(8|68*[1a]))(6|48*[1a]|(5|48*[09])(7|68*[09])*(8|68*[1a]))*(8|48*3|(5|48*[09])(7|68*[09])*(1|a|68*3))|(4|[1a]8*2|(2|[1a]8*[09])(7|68*[09])*(0|9|68*2)|(3|[1a]8*[1a]|(2|[1a]8*[09])(7|68*[09])*(8|68*[1a])
@robinhouston
robinhouston / output.txt
Last active Oct 1, 2020
Plouffe’s prime-generating constant
View output.txt
True 21430172143725346418968500981200036211228096234110672148875007767407021022498722449863967576313917162551893458351062936503742905713846280871969155149397149607869135549648461970842149210124742283755908364306092949967163882534797535118331087892154125829142392955373084335320859663305248773674411336138779
True 3966212458442419910671365779256433097896266098256444502994761104680485792040114698622334941551824185891729333090617747067852863746301856735596028175773861022082860675594962411634044322686894523823171200352765854123386843446869283314184698519162260023471518534376441033216641163191116687452396104764753405716908275693926617999038170654156222260226520346000668993323085068131797019884440806222984681657959124218247652049531642454130249113786478964606565384901503505452972077736233
True 45925227810970180969313328047107279360892708083547808019105709473030650455694812554266379452660250796737838585559498510937884758434522213257037254246666127415651995658124912000275511659296017948571570796025394497912646185458555
@robinhouston
robinhouston / gist:6c74a607a7ee8d4553feead2828107d9
Created Sep 17, 2020
3×3 troll-square matrices with two-digit entries
View gist:6c74a607a7ee8d4553feead2828107d9
sage: %paste
def cgfh(cg_plus_fh):
for cg in range(1, cg_plus_fh):
fh = cg_plus_fh - cg
for c in divisors(cg):
for f in divisors(fh):
yield (c, cg//c, f, fh//f)
for r in range(1, 99, 2):
cg_plus_fh = (101^2 - r^2)/4
View gist:83f0fa99046aeaaf5d27ddbb3218142e
sage: digits = 3
....:
....: for a in range(10^(digits-1), 10^digits - 10^(digits - 1) + 2):
....: x = (10^digits + 1)*a - a^2
....: for b in divisors(x):
....: if 10^(digits - 1) <= b < 10^digits and 10^(digits - 1) <= x//b < 10^digits:
....: print(a, b, "|", x//b, 10^digits + 1 - a)
....:
100 100 | 901 901
100 106 | 850 901
View gist:7c60f4593ea5a990564490559e40cf1e
sage: for a in range(10, 92):
....: x = 101*a - a^2
....: for b in divisors(x):
....: if 10 <= b < 100 and 10 <= x//b < 100:
....: print(a, b, "|", x//b, 101 - a)
....:
10 10 | 91 91
10 13 | 70 91
10 14 | 65 91
10 26 | 35 91