Skip to content

Instantly share code, notes, and snippets.

@robinhouston
robinhouston / bijective-truncatable-primes.py
Created June 19, 2019 07:49
Sage code to find left-truncatable primes in bijective numeration
DIGITS = "123456789X"
ENCODE = dict(( (i+1, d) for (i, d) in enumerate(DIGITS) ))
DECODE = dict(( (d, i+1) for (i, d) in enumerate(DIGITS) ))
def encode(n):
a = []
while n > 0:
n, r = divmod(n, 10)
if r == 0: n, r = n - 1, 10
a.append(ENCODE[r])
create table tweet (
id serial,
in_reply_to integer references tweet(id)
);
insert into tweet (id, in_reply_to)
values (1, NULL),
(2, NULL),
(3, 2),
(4, 3),
sage: var("x, y")
....: f = exp(x) / (1 - (1+x)*y)
....:
....: for (c, i) in f.taylor(x, 0, 13).coefficients():
....: fac = factorial(i)
....: for (d, j) in c.taylor(y, 0, 13).coefficients():
....: print(i, j, d * fac)
....:
(x, y)
(0, 0, 1)
sage: var("x1, x2, y")
....: f = exp(x1 + x2) / (1 - (1+x1)*(1+x2)*y)
....:
....: for (c, i) in f.taylor(x1, 0, 5).coefficients():
....: fac1 = factorial(i)
....: for (d, j) in c.taylor(x2, 0, 5).coefficients():
....: fac = fac1 * factorial(j)
....: for (e, k) in d.taylor(y, 0, 5).coefficients():
....: print(i, j, k, e * fac)
....:
^(0|7|[18]5*4|(2|9|[18]5*6)(3|[29]5*6)*(1|8|[29]5*4)|(3|[18]5*[07]|(2|9|[18]5*6)(3|[29]5*6)*(4|[29]5*[07]))(1|8|65*[07]|(0|7|65*6)(3|[29]5*6)*(4|[29]5*[07]))*(5|65*4|(0|7|65*6)(3|[29]5*6)*(1|8|[29]5*4))|(4|[18]5*[18]|(2|9|[18]5*6)(3|[29]5*6)*(5|[29]5*[18])|(3|[18]5*[07]|(2|9|[18]5*6)(3|[29]5*6)*(4|[29]5*[07]))(1|8|65*[07]|(0|7|65*6)(3|[29]5*6)*(4|[29]5*[07]))*(2|9|65*[18]|(0|7|65*6)(3|[29]5*6)*(5|[29]5*[18])))(6|35*[18]|(4|35*6)(3|[29]5*6)*(5|[29]5*[18])|(5|35*[07]|(4|35*6)(3|[29]5*6)*(4|[29]5*[07]))(1|8|65*[07]|(0|7|65*6)(3|[29]5*6)*(4|[29]5*[07]))*(2|9|65*[18]|(0|7|65*6)(3|[29]5*6)*(5|[29]5*[18])))*(2|9|35*4|(4|35*6)(3|[29]5*6)*(1|8|[29]5*4)|(5|35*[07]|(4|35*6)(3|[29]5*6)*(4|[29]5*[07]))(1|8|65*[07]|(0|7|65*6)(3|[29]5*6)*(4|[29]5*[07]))*(5|65*4|(0|7|65*6)(3|[29]5*6)*(1|8|[29]5*4)))|(5|[18]5*[29]|(2|9|[18]5*6)(3|[29]5*6)*(6|[29]5*[29])|(3|[18]5*[07]|(2|9|[18]5*6)(3|[29]5*6)*(4|[29]5*[07]))(1|8|65*[07]|(0|7|65*6)(3|[29]5*6)*(4|[29]5*[07]))*(3|65*[29]|(0|7|65*6)(3|[29]5*6)*(6|[29]5*[29]))|(4|[18]5*[18]|(2|9|[1
import re
for n in range(1, 101):
r = re.match(r'''
(?=(?P<Fizz>
^(
[0369]|
[147][0369]*[258]|
([258]|[147][0369]*[147])([0369]|[258][0369]*[147])*([147]|[258][0369]*[258])
)*$
var dfa = DFA.create();
var i, j;
for (i = 0; i <= 5; i++) for (j = 0; j <= 1; j++) {
dfa.addState(i + "." + j);
}
for (i = 0; i <= 5; i++) for (j = 0; j <= 1; j++) {
dfa.addTransition(i + "." + j, Math.min(5, i+1) + "." + Math.min(j+1, 1), C('c'));
dfa.addTransition(i + "." + j, Math.min(5, i+1) + "." + j, A(C('f'), C('a'), C('e'), C('t'), C('i'), C('o')));
}
; "memories" by HellMood/DESiRE
; the tiny megademo, 256 byte msdos intro
; shown in April 2020 @ REVISION
;
; (= WILL BE COMMENTED IN DETAIL LATER =)
;
; create : nasm.exe memories.asm -fbin -o memories.com
; CHOOSE YOUR TARGET PLATFORM (compo version is dosbox)
; be sure to use the dosbox.conf from this archive!
; only ONE of the defines should be active!
^(1|8|[29]3*[29]|(3|[29]3*4)(1|8|[07]3*4)*(6|[07]3*[29])|(4|[29]3*5|(3|[29]3*4)(1|8|[07]3*4)*(2|9|[07]3*5))(6|43*5|(5|43*4)(1|8|[07]3*4)*(2|9|[07]3*5))*(3|43*[29]|(5|43*4)(1|8|[07]3*4)*(6|[07]3*[29]))|(5|[29]3*6|(3|[29]3*4)(1|8|[07]3*4)*(3|[07]3*6)|(4|[29]3*5|(3|[29]3*4)(1|8|[07]3*4)*(2|9|[07]3*5))(6|43*5|(5|43*4)(1|8|[07]3*4)*(2|9|[07]3*5))*(0|7|43*6|(5|43*4)(1|8|[07]3*4)*(3|[07]3*6)))(4|[18]3*6|(2|9|[18]3*4)(1|8|[07]3*4)*(3|[07]3*6)|(3|[18]3*5|(2|9|[18]3*4)(1|8|[07]3*4)*(2|9|[07]3*5))(6|43*5|(5|43*4)(1|8|[07]3*4)*(2|9|[07]3*5))*(0|7|43*6|(5|43*4)(1|8|[07]3*4)*(3|[07]3*6)))*(0|7|[18]3*[29]|(2|9|[18]3*4)(1|8|[07]3*4)*(6|[07]3*[29])|(3|[18]3*5|(2|9|[18]3*4)(1|8|[07]3*4)*(2|9|[07]3*5))(6|43*5|(5|43*4)(1|8|[07]3*4)*(2|9|[07]3*5))*(3|43*[29]|(5|43*4)(1|8|[07]3*4)*(6|[07]3*[29])))|(6|[29]3*[07]|(3|[29]3*4)(1|8|[07]3*4)*(4|[07]3*[07])|(4|[29]3*5|(3|[29]3*4)(1|8|[07]3*4)*(2|9|[07]3*5))(6|43*5|(5|43*4)(1|8|[07]3*4)*(2|9|[07]3*5))*(1|8|43*[07]|(5|43*4)(1|8|[07]3*4)*(4|[07]3*[07]))|(5|[29]3*6|(3|[29]3*4)(1|8|[07]3*4)*(
@robinhouston
robinhouston / output.txt
Created August 22, 2020 20:16
Search for English words that have a hex representation as a prime number
445
ABACA5
A64CA5
A84C45
4BACA5
ABAC1
484C1
46AC5
ABAF7
48AF7