Skip to content

Instantly share code, notes, and snippets.

View Parcly-Taxel's full-sized avatar

Jeremy Tan Jie Rui Parcly-Taxel

View GitHub Profile
@Parcly-Taxel
Parcly-Taxel / phyllo.py
Created August 23, 2019 08:18
Phyllotaxis convex hulls
#!/usr/bin/env python3.7
import numpy as np
N = 1024
rng = np.arange(N) + 1
theta = rng * np.pi * (3 - np.sqrt(5))
r = 5 * np.sqrt(rng)
pts = r * (np.cos(theta) + 1j * np.sin(theta))
with open("phyllo.svg", 'w') as f:
@Parcly-Taxel
Parcly-Taxel / paths.py
Created November 25, 2019 13:48
Kinross and Shinjuku sample code
# From Kinross
# Bézier curves, elliptical arcs, lines, ellipses and paths
import numpy as np
from functools import lru_cache
from cmath import rect, polar
from .matrices import mt
from .algebra import ccquad, fproot
from .regexes import pcomm_re, number_re, sf, ssf
from .bernpol import berneval, bernmul, bernraise, bernder
from .bernpol import bernroots, bernvdm, x_conic
@Parcly-Taxel
Parcly-Taxel / oneplus.py
Last active February 3, 2022 21:34
1+ and 0-1+2 interpreters
#!/usr/bin/env python3
# 1+ interpreter with : not printing newline
# as discussed at https://codegolf.stackexchange.com/q/209529/110698
# Parcly Taxel, 2022
# https://gist.github.com/Parcly-Taxel/0bc9ed77c2f6fe0e4ec976d3121e340a
import sys
from collections import deque
s, sd = deque(), {}
@Parcly-Taxel
Parcly-Taxel / peano.v
Created April 15, 2020 07:45
A mechanisation of Peano arithmetic theorems in Coq
Inductive nat : Set :=
| O : nat
| S : nat -> nat.
Theorem zero_no_succ: forall n, S n <> O.
Proof. intros. unfold not. intro H0. inversion H0. Qed.
Theorem succ_eq_succ: forall m n, S m = S n -> m = n.
Proof. intros. inversion H. reflexivity. Qed.
@Parcly-Taxel
Parcly-Taxel / turing.cpp
Last active September 24, 2021 02:18
Turing machine for PSE #110567
#include <deque>
#include <cstdio>
#include <numeric>
using namespace std;
const int L = -1;
const int R = 1;
int rules[6][2][3] = {{{1,L,1},{1,L,0}},
@Parcly-Taxel
Parcly-Taxel / addnotes.py
Last active September 5, 2021 10:56
Periodic Ponies composite assembly code
#!/usr/bin/env python3
import requests, time
import numpy as np
# e621 script that added "index notes" to the periodic table
PT = np.array([[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2],
[ 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 8, 9, 10],
[11, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 15, 16, 17, 18],
[19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36],
@Parcly-Taxel
Parcly-Taxel / pse52527a.py
Last active September 24, 2021 05:33
SAT-based solver for PSE #67058 and related problems
#!/usr/bin/env python3
# https://puzzling.stackexchange.com/questions/52527/seven-matches-digits (part a)
import re
from subprocess import run
import numpy as np
lit_re = re.compile(r"-?\d+")
verts = np.arange(18, dtype=int).reshape(2,3,3)
edges = tuple({i,j} for i in range(18) for j in range(i+1,18) if sum(abs(np.argwhere(verts == i)-np.argwhere(verts == j)).flat) == 1 and (i,j) != (4,13))
print(edges)
@Parcly-Taxel
Parcly-Taxel / pse111850.py
Created September 27, 2021 15:43
Pandigital supremacy (PSE #111850)
#!/usr/bin/env python3
from math import comb, factorial as fac
def oS(n, k): # "ordered Stirling numbers" S(n,k) * k!
return sum((-1)**i * comb(k,i) * (k-i)**n for i in range(k+1))
def num_pandig(n):
return 9*oS(n,10)//10
def num_pandig_with_prefix(prefix, f):
@Parcly-Taxel
Parcly-Taxel / analyse.py
Created September 30, 2021 09:39
Uniquising a Disconnect Four puzzle (PSE #111929)
#!/usr/bin/env python3
with open("sols", 'r') as f:
sols = [s.strip() for s in f.readlines()]
def checksols(remsols, start, remlevels):
if len(remsols) == 1:
raise ValueError(remsols[0])
if remlevels == 0:
return
@Parcly-Taxel
Parcly-Taxel / unsatproof
Created October 11, 2021 18:37
Arithmetic 3-colour Ramsey number for x + y = 3z is 54 (MSE #3577641)
4 0
d 4 0
-72 -108 0
-70 -102 -108 0
-68 -96 -108 0
-66 -90 -108 0
-64 -84 -108 0
-62 -78 -108 0
-60 -74 -106 0
-58 -74 -100 0