Computer programs

A forum for topics that don't fit elsewhere. Introduce yourselves to other members of the forums, discuss how your name evolves when written out in the Game of Life, or just tell us how you found it. Forum rules still apply.
Post Reply
User avatar
PHPBB12345
Posts: 1150
Joined: August 5th, 2015, 11:55 pm
Contact:

Computer programs

Post by PHPBB12345 »

Unbias a random generator (Javascript):

Code: Select all

function biased(n){return Math.random()<(1/n)};
function unbiased(n){var a;while((a=biased(n))==biased(n));return a};
Kogge-Stone adder (Javascript):

Code: Select all

function KoggeStoneAdd (A, B)
{
	// Addition without "+" operator
	var G, P;
	G = A & B;
	P = A ^ B;
	G |= P & (G << 1);
	P  = P & (P << 1);
	G |= P & (G << 2);
	P  = P & (P << 2);
	G |= P & (G << 4);
	P  = P & (P << 4);
	G |= P & (G << 8);
	P  = P & (P << 8);
	G |= P & (G << 16);
	return (A ^ B) ^ (G << 1);
}
function KoggeStoneSub (A, B)
{
	// Subtraction without "-" operator
	var G, P, T;
	T = ~A;
	G = T & B;
	P = T ^ B;
	G |= P & (G << 1);
	P  = P & (P << 1);
	G |= P & (G << 2);
	P  = P & (P << 2);
	G |= P & (G << 4);
	P  = P & (P << 4);
	G |= P & (G << 8);
	P  = P & (P << 8);
	G |= P & (G << 16);
	return (A ^ B) ^ (G << 1);
}
function KoggeStoneAdd3 (A, B, C)
{
	// Addition without "+" operator
	var T = A & B;
	B ^= A;
	A = B & C;
	return KoggeStoneAdd((T | A) << 1, B ^ C);
}
function RevIntKoggeStoneAdd (A, B)
{
	// Reversed integer addition
	var G, P;
	G = A & B;
	P = A ^ B;
	G |= P & (G >>> 1);
	P  = P & (P >>> 1);
	G |= P & (G >>> 2);
	P  = P & (P >>> 2);
	G |= P & (G >>> 4);
	P  = P & (P >>> 4);
	G |= P & (G >>> 8);
	P  = P & (P >>> 8);
	G |= P & (G >>> 16);
	return (A ^ B) ^ (G >>> 1);
}
function RevIntKoggeStoneSub (A, B)
{
	// Reversed integer subtraction
	var G, P, T;
	T = ~A;
	G = T & B;
	P = T ^ B;
	G |= P & (G >>> 1);
	P  = P & (P >>> 1);
	G |= P & (G >>> 2);
	P  = P & (P >>> 2);
	G |= P & (G >>> 4);
	P  = P & (P >>> 4);
	G |= P & (G >>> 8);
	P  = P & (P >>> 8);
	G |= P & (G >>> 16);
	return (A ^ B) ^ (G >>> 1);
}
function RevIntKoggeStoneAdd3 (A, B, C)
{
	// Reversed integer addition
	var T = A & B;
	B ^= A;
	A = B & C;
	return RevIntKoggeStoneAdd((T | A) >>> 1, B ^ C);
}
function BigIntKoggeStoneAdd (A, B)
{
	// Addition without "+" operator
	// A and B must be same sign
	var G, P, i, n1 = BigInt(1);
	A = BigInt(A);
	B = BigInt(B);
	i = n1;
	G = A & B;
	P = A ^ B;
	while (P)
	{
		G |= P & (G << i);
		P  = P & (P << i);
		i <<= n1;
	}
	return (A ^ B) ^ (G << n1);
}
Permuted Congruential Generator (Javascript, Use BigInt):

Code: Select all

function pcg32_constructor (state, inc)
{
	// PCG-XSH-RR 64/32 (LCG)
	let mult = BigInt("6364136223846793005");
	let n1 = BigInt(1), n18 = BigInt(18), n27 = BigInt(27), n59 = BigInt(59), mask = BigInt("18446744073709551615");
	inc = (BigInt(inc) & mask) | n1;
	state = BigInt(state) & mask;
	return function ()
	{
		let oldstate = state;
		state = (oldstate * mult + inc) & mask;
		let xorshifted = Number(((oldstate >> n18) ^ oldstate) >> n27) | 0;
		let rot = Number(oldstate >> n59);
		return (xorshifted >>> rot) | (xorshifted << (-rot & 31));
	};
};
// Usage:
pcg32 = pcg32_constructor("5573589319906701683", "1442695040888963407");
pcg32 (); // 676697322
pcg32 (); // 420258633
pcg32 (); // -876335118
Jacobian elliptic functions:

Code: Select all

// http://www.netlib.org/cephes/
var ellipj = (function() {
    let sqrt = Math.sqrt;
    let fabs = Math.abs;
    let sin = Math.sin;
    let cos = Math.cos;
    let asin = Math.asin;
    let tanh = Math.tanh;
    let sinh = Math.sinh;
    let cosh = Math.cosh;
    let atan = Math.atan;
    let exp = Math.exp;

    let PIO2 = Math.PI / 2;
    let MACHEP = Number.EPSILON / 2;

    return function(u, m) {
        let sn, cn, dn, ph;
        let ai, b, phi, t, twon;
        let a = []
          , c = [];
        let i;

        /* Check for special cases */

        if (m < 0.0 || m > 1.0) {
            return ({
                sn: NaN,
                cn: NaN,
                dn: NaN,
                ph: NaN
            });
        }
        if (m < 1.0e-9) {
            t = sin(u);
            b = cos(u);
            ai = 0.25 * m * (u - t * b);
            return ({
                sn: t - ai * b,
                cn: b + ai * t,
                ph: u - ai,
                dn: 1.0 - 0.5 * m * t * t
            });
        }

        if (m >= 0.9999999999) {
            ai = 0.25 * (1.0 - m);
            b = cosh(u);
            t = tanh(u);
            phi = 1.0 / b;
            twon = b * sinh(u);
            sn = t + ai * (twon - u) / (b * b);
            ph = 2.0 * atan(exp(u)) - PIO2 + ai * (twon - u) / b;
            ai *= t * phi;
            cn = phi - ai * (twon - u);
            dn = phi + ai * (twon + u);
            return ({
                sn: sn,
                cn: cn,
                dn: dn,
                ph: ph
            });
        }

        /*	A. G. M. scale		*/
        a[0] = 1.0;
        b = sqrt(1.0 - m);
        c[0] = sqrt(m);
        twon = 1.0;
        i = 0;

        while (fabs(c[i] / a[i]) > MACHEP) {
            if (i > 7) {
                console.warn("Overflow in ellipj");
                break;
            }
            ai = a[i];
            ++i;
            c[i] = (ai - b) / 2.0;
            t = sqrt(ai * b);
            a[i] = (ai + b) / 2.0;
            b = t;
            twon *= 2.0;
        }

        /* backward recurrence */
        phi = twon * a[i] * u;
        do {
            t = c[i] * sin(phi) / a[i];
            b = phi;
            phi = (asin(t) + phi) / 2.0;
        } while (--i);
        t = sin(phi);
        sn = t;
        cn = cos(phi);
        /* Thanks to Hartmut Henkel for reporting a bug here:  */
        dn = sqrt(1.0 - m * t * t);
        ph = phi;
        return ({
            sn: sn,
            cn: cn,
            dn: dn,
            ph: ph
        });
    }
})();
Incomplete elliptic integral of the first kind:

Code: Select all

var ellik = (function(phi, m) {
    if (m > 1) {
        let k = Math.sqrt(m);
        return ellik(Math.asin(k * Math.sin(phi)), 1 / m) / k
    }
    let a, b, r, t, a1, b1, eps, i;
    phi /= 2;
    t = Math.cos(phi) / Math.sin(phi);
    a = t * t + (1 - 2 * m);
    b = Math.sign(a + 1 / a) * Math.sqrt(a * a + 4 * m * (1 - m));
    r = Math.sqrt(1 + 2 * m / (a + b));
    t = t / r;
    a1 = 1;
    b1 = Math.sqrt(1 - m);
    eps = Math.max(a1, b1) * Number.EPSILON;
    i = 0;
    do {
        a = a1;
        b = b1;
        a1 = (a + b) / 2;
        b1 = Math.sqrt(a * b);
        r = Math.sqrt(a1 * (r + 1) / (b * r + a));
        t *= r;
    } while (i++ < 100 && (Math.abs(a - b) > eps || Math.abs(r - 1) > Number.EPSILON));
    t = Math.atan(a / t);
    b = phi - t;
    r = Math.sign(b) * Math.PI;
    t += r * Math.round(b / r);
    return 2 * t / a;
});
CVP problem:

Code: Select all

var nearest = (function() {
	"use strict";
	function norm(w) {
		return w[0] * w[0] + w[1] * w[1];
	}
	function proj(w1, w2) {
		return (w1[0] * w2[0] + w1[1] * w2[1]) / norm(w2);
	}
	function nint(x) {
		return Math.sign(x) * Math.ceil(Math.abs(x) - 0.5);
	}
	function reduce(w1, w2) {
		var i, t;
		w1 = [+w1[0], +w1[1]];
		w2 = [+w2[0], +w2[1]];
		if (norm(w1) > norm(w2)) t = w1, w1 = w2, w2 = t;
		for (i = 0; i < 1000; i++) {
			t = nint(proj(w2, w1));
			if (!t) break;
			w2[0] -= t * w1[0];
			w2[1] -= t * w1[1];
			t = w1, w1 = w2, w2 = t;
		}
		if (norm(w1) > norm(w2)) t = w1, w1 = w2, w2 = t;
		return [w1, w2];
	}
	function nearesti(p, w) {
		var n = nint(proj(p, w));
		p[0] -= n * w[0];
		p[1] -= n * w[1];
		return [n, norm(p)];
	}
	return function (p, w1, w2) {
		var w = reduce(w1, w2);
		var a = proj(w[1], w[0]);
		var b = proj(p, [w[1][0] - a * w[0][0], w[1][1] - a * w[0][1]]);
		var c = nint(b);
		var d = c + Math.sign(b - c);
		var e = nearesti([p[0] - c * w[1][0], p[1] - c * w[1][1]], w[0]);
		if (c !== d) {
			a = nearesti([p[0] - d * w[1][0], p[1] - d * w[1][1]], w[0]);
			if (e[1] > a[1]) c = d, e = a;
		}
		d = e[0];
		return [d * w[0][0] + c * w[0][1], d * w[1][0] + c * w[1][1]];
	}
})();
2Sum:

Code: Select all

function twosum(a, b) {
	let s = a + b;
	let v = s - a;
	let e = (a - (s - v)) + (b - v);
	return [s, e]
}
function split(a) {
	let t = 134217729 * a;
	let hi = t - (t - a);
	let lo = a - hi;
	return [hi, lo];
}
function twoprod(a, b) {
	let p = a * b;
	let [ahi, alo] = split(a);
	let [bhi, blo] = split(b);
	let e = ((ahi * bhi - p) + ahi * blo + alo * bhi) + alo * blo;
	return [p, e];
}
function fma(a, b, c) {
	[a, b] = twoprod(a, b);
	[b, c] = twosum(b, c);
	return a + b;
}
Gini index:

Code: Select all

function GiniIndex (list) {
	let i, n, sum, eps, max;
	list = Array.from(list).sort((x, y) => y - x);
	max = list[0];
	for (i = sum = eps = 0, n = list.length; i < n; i++) {
		let y = (max - list[i]) - eps;
		let t = sum + y;
		eps = (t - sum) - y;
		sum = t;
	}
	return sum / ((n - 1) * max);
}
Variants of Verlet integration:

Code: Select all

function integrator1 (a, b, h, f, steps) {
    a = +a; b = +b;
    for (let i = 0; i < steps; i++) {
        let c = f(a, b);
        a += h*(b+c*h/2);
        b += c*h;
        let d = f(a, b);
        b += (d-c)*h/2;
    }
    return [a, b];
}

function integrator2 (a, b, h, f, steps) {
    a = +a; b = +b;
    for (let i = 0; i < steps; i++) {
        let c = f(a, b);
        a += h*(b+c*h/2);
        b += c*h;
        let d = f(a, b);
        b += (d-c)*h/2;
        let e = f(a, b) - d;
        if (e !== 0) b += e/(1-e/(d-c))*h/2;
    }
    return [a, b];
}
Last edited by PHPBB12345 on March 30th, 2025, 10:12 pm, edited 23 times in total.
ColorfulGabrielsp138
Posts: 288
Joined: March 29th, 2021, 5:45 am

Re: Computer programs

Post by ColorfulGabrielsp138 »

Pixel characters (please send the output to CyberChef)

Code: Select all

#include <cstdio>
!0;
int i;

int main(){

for(i=0;i<=255;++i){
if(i%16==0){printf("0a \n");};
printf("28%02x ",i);
}

return 0;
}

Code: Select all

!
⠀⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋⠌⠍⠎⠏
⠐⠑⠒⠓⠔⠕⠖⠗⠘⠙⠚⠛⠜⠝⠞⠟
⠠⠡⠢⠣⠤⠥⠦⠧⠨⠩⠪⠫⠬⠭⠮⠯
⠰⠱⠲⠳⠴⠵⠶⠷⠸⠹⠺⠻⠼⠽⠾⠿
⡀⡁⡂⡃⡄⡅⡆⡇⡈⡉⡊⡋⡌⡍⡎⡏
⡐⡑⡒⡓⡔⡕⡖⡗⡘⡙⡚⡛⡜⡝⡞⡟
⡠⡡⡢⡣⡤⡥⡦⡧⡨⡩⡪⡫⡬⡭⡮⡯
⡰⡱⡲⡳⡴⡵⡶⡷⡸⡹⡺⡻⡼⡽⡾⡿
⢀⢁⢂⢃⢄⢅⢆⢇⢈⢉⢊⢋⢌⢍⢎⢏
⢐⢑⢒⢓⢔⢕⢖⢗⢘⢙⢚⢛⢜⢝⢞⢟
⢠⢡⢢⢣⢤⢥⢦⢧⢨⢩⢪⢫⢬⢭⢮⢯
⢰⢱⢲⢳⢴⢵⢶⢷⢸⢹⢺⢻⢼⢽⢾⢿
⣀⣁⣂⣃⣄⣅⣆⣇⣈⣉⣊⣋⣌⣍⣎⣏
⣐⣑⣒⣓⣔⣕⣖⣗⣘⣙⣚⣛⣜⣝⣞⣟
⣠⣡⣢⣣⣤⣥⣦⣧⣨⣩⣪⣫⣬⣭⣮⣯
⣰⣱⣲⣳⣴⣵⣶⣷⣸⣹⣺⣻⣼⣽⣾⣿.
Last edited by ColorfulGabrielsp138 on August 12th, 2021, 8:38 am, edited 1 time in total.

Code: Select all

x = 21, y = 21, rule = LifeColorful
11.E$10.3E$10.E.2E$13.E4$2.2B$.2B$2B$.2B15.2D$19.2D$18.2D$17.2D4$7.C$
7.2C.C$8.3C$9.C!
I have reduced the glider cost of quadratic growth to eight and probably to seven. Looking for conduits...
User avatar
PHPBB12345
Posts: 1150
Joined: August 5th, 2015, 11:55 pm
Contact:

Re: Computer programs

Post by PHPBB12345 »

SSE2 hypot/hypotf (i386 fasm assembly):

Code: Select all

format PE Console 4.0
entry start

include 'win32a.inc'

section '.text' code readable executable

start:
        push dword 3.0
        push dword 4.0
        call hypotf_sse2
        push $40100000
        push 0
        push $40080000
        push 0
        call hypot_sse2
        ud2
        align 4

 hypotf_sse2:
        push ebp
        mov ebp, esp
        sub esp, 4
        mov eax, [ebp+8]
        mov ecx, [ebp+12]
        and eax, 0x7FFFFFFF
        and ecx, 0x7FFFFFFF
        movd xmm0, eax
        or eax, ecx
        jz .return
        movd xmm1, ecx
        movss xmm2, xmm0
        maxss xmm0, xmm1
        minss xmm1, xmm2
        ; assume xmm0 >= xmm1
        mov eax, 1.0
        movd xmm2, eax
        divss xmm1, xmm0
        mulss xmm1, xmm1
        addss xmm1, xmm2
        sqrtss xmm1, xmm1
        mulss xmm0, xmm1
  .return:
        movss [ebp-12], xmm0
        fld dword [ebp-12]
        mov esp, ebp
        pop ebp
        ret
        align 4

 hypot_sse2:
        push ebp
        mov ebp, esp
        sub esp, 8
        and esp, -16
        movupd xmm0, [ebp+8]
        pcmpeqb xmm1, xmm1
        psrlq xmm1, 1
        pand xmm0, xmm1
        ptest xmm0, xmm0
        jz .return
        pshufd xmm1, xmm0, 0xEE
        movsd xmm2, xmm0
        maxsd xmm0, xmm1
        minsd xmm1, xmm2
        ; assume xmm0 >= xmm1
        movsd xmm2, [.const.1]
        divsd xmm1, xmm0
        mulsd xmm1, xmm1
        addsd xmm1, xmm2
        sqrtsd xmm1, xmm1
        mulsd xmm0, xmm1
  .return:
        movsd [esp], xmm0
        fld qword [esp]
        mov esp, ebp
        pop ebp
        ret
        align 16
  .const.1 dq 1.0

 hypotl:
        ; 80-bit floating point via x87 stack?
        ; For higher precision floating point, use GMP's mpf_xxx functions
Boot code cause VirtualBox shutdown (x86 fasm assembly):

Code: Select all

org 0x7c00

        cli
        mov ax,cs
        mov ds,ax
        mov es,ax
        mov ss,ax
        mov sp,0x7c00
        sti
        call push_str
        db "Shutdown"
 push_str:
        pop si
        mov cx,8
        mov dx,1039
        cld
        rep outsb
 halt:
        hlt
        jmp halt

        times 510 - ($ - $$) db 0
        dw 0aa55h
SEH trampoline (x86-64 assembly):

Code: Select all

        lea rax, [scopetable]
        mov [r9+56], rax
        jmp [__C_specific_handler]
Last edited by PHPBB12345 on August 22nd, 2021, 2:53 am, edited 1 time in total.
ColorfulGabrielsp138
Posts: 288
Joined: March 29th, 2021, 5:45 am

Re: Computer programs

Post by ColorfulGabrielsp138 »

Code: Select all

#include <cstdio>
!0;
int list[]=
{ 0,  00,02,03,00,05, 00,07,00,00,
  0,  11,00,13,00,00, 00,17,00,19,
  0,  00,00,23,00,00, 00,00,00,29,
  0,  31,00,00,00,00, 00,37,00,00,
  0,  41,00,43,00,0 , 00,47,00,00,
  0,  00,00,53,00,00, 00,00,00,59,
  0,  61,00,00,00,00, 00,67,00,00,
  0,  71, 0,73,00,00, 00,00,00,79,
  0,  00,00,83,00,00, 00,00,00,89,
  0,  00,00,00,00,00, 00,97,00,00,
  0};

int a=0;

int main(){

for(a=32;a<100;++a){
if(list[a]==0){
printf("===%i===\n",a);
printf("<div style=\"border:2px solid #ff00ff;\">\n\n");
printf("</div>\n\n\n");
} else {
printf("===%i===\n",a);
printf("<div style=\"border:2px solid blue;\">\n\n");
printf("</div>\n\n\n");
}
}
 
return 0;
}

Code: Select all

x = 21, y = 21, rule = LifeColorful
11.E$10.3E$10.E.2E$13.E4$2.2B$.2B$2B$.2B15.2D$19.2D$18.2D$17.2D4$7.C$
7.2C.C$8.3C$9.C!
I have reduced the glider cost of quadratic growth to eight and probably to seven. Looking for conduits...
ColorfulGabrielsp138
Posts: 288
Joined: March 29th, 2021, 5:45 am

Re: Computer programs

Post by ColorfulGabrielsp138 »

Code: Select all

x = 35, y = 5, rule = Wireworld5
FBCIJABCDE.BCDEABC.E.BCDEABCDEABCDE$10.A6.CD.A$11.BC3.BC3.BC$12.CD.A6.
CD$AGCDJABCDEABC.E.BCDEABC.EABCDEABCDE!
A WireWorld5 Crossover based on this C++ code:

Code: Select all

#include <cstdio>
!0;
int a,b;
int main(){
scanf("%d%d",&a,&b);
a^=b;b^=a;a^=b;
printf("%d %d",a,b);
return 0;}

Code: Select all

x = 21, y = 21, rule = LifeColorful
11.E$10.3E$10.E.2E$13.E4$2.2B$.2B$2B$.2B15.2D$19.2D$18.2D$17.2D4$7.C$
7.2C.C$8.3C$9.C!
I have reduced the glider cost of quadratic growth to eight and probably to seven. Looking for conduits...
User avatar
PHPBB12345
Posts: 1150
Joined: August 5th, 2015, 11:55 pm
Contact:

Re: Computer programs

Post by PHPBB12345 »

Code: Select all

{
\\ Header
my(thetaall_,jacobi_,ellpointtoz_,ellR_,elllemn_,ellsigma_);
\\ Jacobi theta functions
theta1=((q,z)->theta(q,z));
theta2=((q,z)->my(s,t);s=real(z);if(s>0,z=-z);t=theta(q,Pi/2+z);if(!imag(q)&&real(q)>0&&(!s||!real(z)),real(t),t));
theta3=((q,z)->theta4(-q,z));
theta4=((q,z)->my(s,t);s=imag(z);if(s>0,z=-z);t=-I*exp(I*z)*q^(1/4)*theta(q,z-I*log(q)/2);if(!imag(q)&&(!s||!real(z)),real(t),t));
thetaall_=if(arity(theta)>2,
	((z,tau)->call(theta,[z,tau,0])),
	((z,tau)->my(q=exp(I*Pi*tau));z*=Pi;[theta3(q,z),theta4(q,z),theta2(q,z),-theta1(q,z)])
);
\\ Elliptic nome
ellnome=((k)->my(m=k^2);if(k,exp(-Pi*agm(1,sqrt(1-m))/agm(1,k)),m/16));
invellnome=((q)->my(s=4*q^(1/2),t);if(s,t=log(q)/(Pi*I);s*=(eta(t/2)*eta(2*t)^2/eta(t)^3)^4);s);
nometomodularangle=((q)->my(r,e,p,t);if(r=!imag(q),q=real(q));e=exponent(1.*q);p=bitprecision(q);if(p==oo,p=getlocalbitprec());if(!q||-e>p,return(4*sqrt(q)));t=ceil(p-e/2+10);if(r&&q<=1&&2*t*log(2)*(1-q)<Pi^2,localbitprec(p);return(Pi/2));localbitprec(t);t=-I*log(bitprecision(q,t))/(4*Pi);t=2*I*(logeta(t+1/4)-logeta(t-1/4))+Pi/12;bitprecision(if(r,abs(t)*sqrt(sign(q)),t),p));
\\ j-invariant
invellj=((j)->if(!j,return((-1)^(2/3)));my(a=tan(asin(12^(3/2)/sqrt(j))/3));a*=2/(a+sqrt(3));I*agm(1,sqrt(1-a))/agm(1,sqrt(a)));
\\ Logarithm of Dedekind eta function
logeta=((t)->
	if(imag(t)<=0,error("domain error in modular function: Im(argument) <= 0"));
	my(w=[t,1],a,b,c,d,M);t=ellperiods(w);M=round(Mat([real(t),imag(t)]~)^(-1)*Mat([real(w),imag(w)]~));c=M[1,2];t=1.*t[1]/t[2];if(c,M*=sign(c);a=M[1,1];b=M[2,1];c=M[1,2];d=M[2,2];I*Pi*((a+d)/(12*c)+sumdedekind(-d,c))+log(-I*(c*t+d))/2,I*Pi*M[2,1]/12)+Pi*I*t/12+if(9*imag(t)<bitprecision(t),log(eta(t)),0)
);
\\ Neville theta functions
thetaS=((k,z)->my(m=k^2,a,q);if(m==0,sin(z),m==1,sinh(z),a=agm(1,sqrt(1-m));q=exp(-Pi*a/agm(1,k));theta1(q,z*a)*sqrt(a)*q^(-1/4)*(q/m)^(1/4)*(1-m)^(-1/4)));
thetaC=((k,z)->my(m=k^2,a,q);if(m==0,cos(z),m==1,1.,a=agm(1,sqrt(1-m));q=exp(-Pi*a/agm(1,k));theta2(q,z*a)*sqrt(a)*q^(-1/4)*(q/m)^(1/4)));
thetaD=((k,z)->my(m=k^2,a,q);if(m==0,1.,m==1,1.,a=agm(1,sqrt(1-m));q=exp(-Pi*a/agm(1,k));theta3(q,z*a)*sqrt(a)));
thetaN=((k,z)->my(m=k^2,a,q);if(m==0,1.,m==1,cosh(z),a=agm(1,sqrt(1-m));q=exp(-Pi*a/agm(1,k));theta4(q,z*a)*sqrt(a)*(1-m)^(-1/4)));
\\ Jacobi elliptic functions
\\ If PARI/GP version >= 2.18.1, use elljacobi(z,k)
jacobi_=((k,z)->if(real(k)<0,k=-k);my(m=k^2,m1=1-m,w1=2*ellK(k),w2=-I*Pi/agm(1,k),w,v1,v2,v,a,b);if(real(m)>real(m1),if(norm(m)>1,b=-sign(imag(w1));w1-=b*w2),norm(m1)>1,a=sign(real(w2));w2-=a*w1);w=[w1,w2];[v1,v2]=v=round(Mat([real(w),imag(w)]~)^(-1)*[real(z),imag(z)]~);[w,z-w*v,v1-a*v2,v2-b*v1,a,b]);
jacobiSN=((k,z)->my(w,p,t,m=k^2,v1,v2);if(m==0,return(sin(z)),m==1,return(tanh(z)));[w,z,v1,v2]=jacobi_(k,z);t=(-1)^v1;z*=1.;my(lp=getlocalbitprec(),m1=1+m,e=exponent(z));if(!z||max(0,exponent(m1))+2*e<-lp,return(t*z));e-=exponent(w[2]);if(e<0,[w,z]=bitprecision([w,z],lp-e));p=iferr(ellwp(w,z/2,1),E,return(t*z),errname(E)=="e_DOMAIN");t*p[2]/(m-(p[1]+m1/3)^2));
jacobiCN=((k,z)->my(w,p,t,m=k^2,v1,v2);if(m==0,return(cos(z)),m==1,return(1/cosh(z)));[w,z,v1,v2]=jacobi_(k,z);t=(-1)^(v1+v2);p=iferr(ellwp(w,z/2),E,return(t*1.),errname(E)=="e_DOMAIN");t*(1+2*(p+(1-2*m)/3)/(m-(p+(1+m)/3)^2)));
jacobiTN=((k,z)->my(w,p,t,m=k^2,v1,v2);if(m==0,return(tan(z)),m==1,return(sinh(z)));[w,z,v1,v2]=jacobi_(k,z);t=(-1)^v2;z*=1.;my(lp=getlocalbitprec(),m1=2-m,e=exponent(z));if(!z||max(0,exponent(m1))+2*e<-lp,return(t*z));e-=exponent(w[2]);if(e<0,[w,z]=bitprecision([w,z],lp-e));p=iferr(ellwp(w,z/2,1),E,return(t*z),errname(E)=="e_DOMAIN");t*p[2]/(1-m-(p[1]-m1/3)^2));
jacobiDN=((k,z)->my(w,p,t,m=k^2,v1,v2);if(m==0,return(1.),m==1,return(1/cosh(z)));[w,z,v1,v2]=jacobi_(k,z);t=(-1)^v2;p=iferr(ellwp(w,z/2),E,return(t*1.),errname(E)=="e_DOMAIN");t*(1+2*m*((m-2)/3+p)/(m-(p+(1+m)/3)^2)));
jacobiZN=((k,z)->my(w,e,t,m=k^2,v1,v2,a,b,c,r);if(m==0,return(0.),m==1,return(tanh(z)));r=imag(z)||imag(m)||real(m)>1;[w,z,v1,v2,a,b]=jacobi_(k,z);e=elleta(w);v2*=2;if(z,c=z/w[1];t=if(imag(c)<0,-1,1);z+=t*w[2]/2;v2-=t;if(a,z+=if(real(c)<0,1,-1)*w[1]/2);t=ellzeta([w,e],z),t=z*(1+m)/3);t+=(v2*I*Pi-z*(e[1]+b*e[2]))/(w[1]+b*w[2]);if(r,t,real(t)));
jacobiEpsilon=((k,z)->my(w,e,t,m=k^2,v1,v2,a,b,c,d,s=z*(2-m)/3,r);if(m==0,return(z),m==1,return(tanh(z)));r=imag(z)||imag(m);[w,z,v1,v2,a,b]=jacobi_(k,z);e=elleta(w);v1+=a*v2;v2+=b*v1;v1*=2;v2*=2;if(z,c=z/w[1];t=if(imag(c)<0,-1,1);d=t*w[2]/2;v2-=t;if(a,t=if(real(c)<0,1,-1);d+=t*w[1]/2;v1-=t);z=ellzeta([w,e],z+d));s+=z+[v1,v2]*e~/2;if(r,s,real(s)));
jacobiAM=((k,z)->my(w,p,m=k^2,v1,v2,a,b,n,q);if(m==0,return(z),m==1,return(2*atan(tanh(z/2))));[w,z,v1,v2,a,b]=jacobi_(k,z);z*=1.;my(lp=getlocalbitprec(),e=exponent(z));q=z;until(1,if(!z||exponent(m)+2*e<-lp,break);e-=exponent(w[2]);if(e<0,[w,z]=bitprecision([w,z],lp-e));p=iferr(ellwp(w,z/2,1),E,break,errname(E)=="e_DOMAIN");q=2*atan(2*((2*m-1)/3-p[1])/p[2]);n=2*(real(z/w[1]-q/Pi)\/2));if(v2%2,my(w1=w[1],w2=w[2]+a*w1);n=2*(imag(z/w2)\imag(w1/w2))+1-n;q=-q);(v1+n)*Pi+q);
\\ Elliptic exponential and logarithm
ellpointtoz_=((E,P,w=ellperiods(E))->my(z=ellpointtoz(E,P));z-w*round(Mat([real(w),imag(w)]~)^(-1)*[real(z),imag(z)]~));
ellexpnum=((E,z)->my(P=ellztopoint(E,z));if(#P<2,0.,-P[1]/P[2]));
elllognum=((E,z)->if(!z,return(z));my(R=polroots(Pol([z^2,-1+E.a1*z+E.a2*z^2,E.a3*z+E.a4*z^2,E.a6*z^2])),r,x);foreach(R,t,my(a=abs(t));if(a>r,r=a;x=t));ellpointtoz_(E,[x,-x/z]));
\\ Incomplete elliptic integrals
incellF=((k,phi)->my(m=k^2,a=2*m-1,b=m*(m-1),E=ellinit([0,a,0,b,0]));phi*=1.;if(#E,my(n,x,c,d,w1,w2);n=real(phi)\/Pi;w1=2*ellK(k);phi-=n*Pi;x=k*phi;if(!x||bitprecision(x)<-2*exponent(x),return(phi+n*w1));x=cotan(phi/2);c=x^2-a;d=sqrt(c^2-4*b);if(real(c*conj(d))<0,d=-d);c=(c+d)/2;a=2*ellpointtoz(E,[c,-c*x]);if(real(k)<0,k=-k);w2=I*Pi/agm(1,k);b=imag(a/w1)\/imag(w2/w1);a-=b*w2;if(b%2,a=w1-a);n+=2*(real(phi/Pi-a/w1)\/2);a+n*w1,real(a)<0,phi,2*atanh(tan(phi/2))));
incellE=((k,phi)->jacobiEpsilon(k,incellF(k,phi)));
incellD=((k,phi)->my(m=k^2,u,p,e);if(!m,return(phi/2-sin(2*phi)/4));u=incellF(k,phi);if(!u,return(u^3/3));p=bitprecision(u);e=exponent(m);if(e<0,p-=e);localbitprec(p);[k,u]=bitprecision([k,u],p);(u-jacobiEpsilon(k,u))/m);
jacobiZeta=((k,phi)->jacobiZN(k,incellF(k,phi)));
invellwp=((w,z)->w=ellperiods(w);my(g2=elleisnum(w,4)/12,g3=-elleisnum(w,6)/216,E=ellinit(-[g2,g3]/4),x,y,l);z=Vec(z);x=z[1];l=#z<2;y=if(l,-sqrt(4*x^3-g2*x-g3),z[2]);z=ellpointtoz_(E,[x,-y/2],w);if(l&&real(z)>=0,z,-z));
invjacobiSN=((k,v)->incellF(k,asin(v)));
invjacobiCN=((k,v)->incellF(k,acos(v)));
invjacobiTN=((k,v)->incellF(k,atan(v)));
invjacobiDN=((k,v)->my(m=k^2,m1=1-m,kp=sqrt(m1),w=ellK(kp),s=norm(v)<abs(kp),u=I*(incellF(kp,asin(if(s,v/kp,1/v)))-w));if(real(u/w)<0,u=-u);if(s,u=ellK(k)-u);if(!imag(k)&&!imag(v)&&(v=real(v))<=1&&v>=real(kp),real(u),u));
\\ Carlson elliptic integrals
ellR_=((x,y,z)->my(u,P,E);[x,y,z]=vecextract([x,y,z],vecsort([y-z,z-x,x-y],norm,1));a=y-z;b=x-z;P=z+(a+b)/3;E=ellinit([0,a+b,0,a*b,0]);if(#E,my(w=ellperiods(E));u=ellpointtoz_(E,[z,-sqrt(x)*sqrt(y)*sqrt(z)],w);if(real(u)<0,my(a=real(w[1]),b=real(w[2]));u+=if(abs(a)<abs(b),sign(b)*w[2],sign(a)*w[1]));E=w,E=[x,(y+z)/2];u=ellRC(x,(y+z)/2));[u,P,E]);
ellRC=((x,y)->my(sx=sqrt(x),sy=sqrt(y),t=sqrt(x-y));if(!t,return(1/sy));t=bitprecision(t,bitprecision([sx,sy]));t=log1p(t*(t/(sx+sy)+1)/sy)/t;if(imag(sx)||imag(sy),t,real(t)));
ellRD=((x,y,z)->my([u,P,E]=ellR_(x,y,z),a=z-x,b=z-y);(u*(a+b)+3*(sqrt(x)*sqrt(y)/sqrt(z)-ellzeta(E,u)))/(a*b));
ellRE=((x,y)->my(sx=sqrt(x),sy=sqrt(y),t=sx*sy);2*((sx+sy)*ellE((sx-sy)/(sx+sy))/Pi-if(t,t/(2*agm(sx,sy)),0)));
ellRF=((x,y,z)->ellR_(x,y,z)[1]);
ellRG=((x,y,z)->my([u,P,E]=ellR_(x,y,z));(u*P+ellzeta(E,u))/2);
ellRH=((x,y,z,p)->my(r=3*ellRF(x,y,z));if(p,r-=p*ellRJ(x,y,z,p));r/2);
ellRJ=((x,y,z,p)->my(L=[x,y,z,p],r=normlp(L));[x,y,z,p]=L/r;(3/2)*r^(-3/2)*intnum(t=[0,-(!x+!y+!z)/2],[oo,-5/2],1/(sqrt(t+x)*sqrt(t+y)*sqrt(t+z)*(t+p))));
ellRK=((x,y)->1/agm(sqrt(x),sqrt(y)));
ellRL=((x,y,p)->8/(3*Pi)*ellRH(0,x,y,p));
ellRM=((x,y,p)->4/(3*Pi)*ellRJ(0,x,y,p));
\\ Complete elliptic integrals
ellD=((k)->my(m=k^2,lp=getlocalbitprec(),e=exponent(m));if(e<-lp,return(Pi/4));if(e<0,lp-=e);localbitprec(lp);k=bitprecision(k,lp);(ellK(k)-ellE(k))/m);
\\ Lemniscatic elliptic functions
elllemn_=((z,n)->my(lp=getlocalbitprec(),b,L);localbitprec(b=lp+64);z=bitprecision(1.*z,b);bitprecision(if(z&&-4*exponent(z)<=lp,z/=ellK(I);z-=I*(b=round(imag(z)));b%=4;L=thetaall_(z/2,I);if(b%2,n=n+2);if(n==1,b=2-b);I^b*L[5-n]/L[n],if(n==1,z,z*=z;1.-z/(1.+z/2))),lp));
sinlemn=((z)->elllemn_(z,1));
coslemn=((z)->elllemn_(z,2));
asinlemn=((z)->z*hypergeom([1/4,1/2],5/4,z^4));
acoslemn=((z)->ellK(I)-asinlemn(z));
\\ Associated Weierstrass sigma functions
ellsigma_=((w,z,i)->my([t,e]=ellperiods(w,1),a=Mat([real(t),imag(t)]~),b=round(a^(-1)*Mat([real(w),imag(w)]~))*Col(i)%2,c);if(real(t[1]/t[2])>0,b[2]*=-1);[a,e]=[t*b,e*b]/2;c=real(z*conj(a));if(iferr(c>0,E,c=t;c[2-b[1]]=a;return(exp(-ellwp(t,a)*z^2/2)*ellsigma(c,z)/ellsigma(t,z)),errname(E)=="e_TYPE2"),z=-z);ellsigma(w,z+a)/ellsigma(w,a)*exp(-z*e));
ellsigma1=((w,z='x)->ellsigma_(w,z,[1,0]));
ellsigma2=((w,z='x)->ellsigma_(w,z,[0,1]));
ellsigma3=((w,z='x)->ellsigma_(w,z,[1,1]));
\\ Dixon elliptic functions
DixonLambda=((a)->if(a==-1,return([2*Pi/sqrt(27)]));my(s=sqrt(3),g=gamma(1/3)^3,m=g*hypergeom([1/3,1/3],2/3,-a^3)/Pi,n=Pi^2*a*hypergeom([2/3,2/3],4/3,-a^3)/(3*g));[s*m/6+4*n,-(s-3*I)*m/12-2*(1+s*I)*n,-(s+3*I)*m/12-2*(1-s*I)*n]);
DixonKappa=((a)->if(a==-1,return([2*Pi/sqrt(27)-1]));my(s,g,m,n);if(!imag(a)&&abs(a)>1,g=2*Pi/a^2;s=g*hypergeom([2/3,4/3],1,1+1/a^3)/sqrt(27);if(a>0,m=real(s);n=I*abs(imag(s));[a-2*m,a+m-n,a+m+n],n=g*I*hypergeom([2/3,4/3],2,-1/a^3)/9;[a+s,a+s+n,a-2*s-n]),s=sqrt(3);g=gamma(1/3)^3;m=Pi^2*hypergeom([-1/3,2/3],1/3,-a^3)/(3*g);n=a^2*g*hypergeom([1/3,4/3],5/3,-a^3)/Pi;[a+4*m+s*n/12,a-2*(1+s*I)*m-(s-3*I)*n/24,a-2*(1-s*I)*m-(s+3*I)*n/24]));
DixonSM=((a,z)->if(a==-1,z*=sqrt(3)/2;return(sin(z)/sin(Pi/3+z)));my(x,y,b=a^3);iferr([x,y]=ellwp(ellinit([a*(8-b)/48,(b*(20+b)-8)/864]),z,1),E,return(.),errname(E)=="e_DOMAIN");-(a^2/2+2*x)/(y+a*x-(a^3+4)/12));
DixonCM=((a,z)->if(a==-1,z*=sqrt(3)/2;return(sin(Pi/3-z)/sin(Pi/3+z)));my(x,y,b=a^3);iferr([x,y]=ellwp(ellinit([a*(8-b)/48,(b*(20+b)-8)/864]),z,1),E,return(1.),errname(E)=="e_DOMAIN");b=(a^3+4)/12;(y-a*x+b)/(y+a*x-b));
DixonF=((a,z)->if(a==-1,my(t=z*sqrt(3)/2);return(z-sin(t)/sin(Pi/3+t)));my(E=ellinit([-a*(24+a^3*27)/16,(8+a^3*(36+a^3*27))/32]),l=DixonLambda(a)[1],k=DixonKappa(a)[1]);3/4*a*(2+a*(z+l))+ellzeta(E,z+l)-k);
DixonThetaS=((a,z)->if(a==-1,my(t=sqrt(3)/2);return(exp(z*(z-1)/2)/t*sin(z*t)));my(E=ellinit([-a*(24+a^3*27)/16,(8+a^3*(36+a^3*27))/32]));exp((4*a*z+3*a^2*z^2)/8)*ellsigma(E,z));
DixonThetaC=((a,z)->if(a==-1,my(t=sqrt(3)/2);return(exp(z*(z-1)/2)/t*sin(Pi/3-z*t)));my(E=ellinit([-a*(24+a^3*27)/16,(8+a^3*(36+a^3*27))/32]),l=DixonLambda(a)[1],k=DixonKappa(a)[1]);exp((4*a*z+3*a^2*(l-z)^2-4*(k-a)*(l-2*z))/8)*ellsigma(E,l-z));
DixonThetaM=((a,z)->if(a==-1,my(t=sqrt(3)/2);return(exp(z*(z-1)/2)/t*sin(Pi/3+z*t)));my(E=ellinit([-a*(24+a^3*27)/16,(8+a^3*(36+a^3*27))/32]),l=DixonLambda(a)[1],k=DixonKappa(a)[1]);exp((4*a*z+3*a^2*(l+z)^2-4*(k-a)*(l+2*z))/8)*ellsigma(E,l+z));
invDixonSM=((a,z)->my(b=(1+a^3)/3,E=ellinit([-a,-a^2,b,a*b,-b^2/3]));elllognum(E,z));
\\ q-Pochhammer
qpoch=((a,q)->my(p=getlocalbitprec(),r=1,t=1);[a,q]=bitprecision([-a,q],p+10);localbitprec(p+10);bitprecision((1+a)*(1+suminf(i=1,r*=q;t*=a*r/(1-r);t)),p));
qfactorial=((n,q)->my(r=1,t=1);while(n-->0,t=1+q*t;r*=t);r);
qbinomial=((n,m,q)->m=min(m,n-m);if(m<0,return(0));prod(i=0,m-1,(1-q^(n-i))/(1-q^(i+1))));
qgamma=((z,q)->my(t);if(norm(q)>1,t=1/q;return(self()(z,t)*t^(-(z-1)*(z-2)/2)));t=1-q;if(!t,return(gamma(z)));t^(1-z)*qpoch(q,q)/qpoch(q^z,q));
qpsi=((z,q)->my(t);if(norm(q)>1,t=1/q;return((3/2-z)*log(t)+self()(z,t)));t=1-q;if(!t,return(psi(z)));z=q^(z-1);-log(t)+log(q)*suminf(n=1,z^n*q^(n^2)*(1-z*q^(2*n))/((1-q^n)*(1-z*q^n))));
\\ Genus 2 arithmetic geometric mean
genus2agm=((args[..])->my(p=getlocalbitprec());localbitprec(p+64);bitprecision(if(
	#args==4,my([a,b,c,d]=bitprecision(args,p+64));while(exponent(abs(b-a)+abs(c-a)+abs(d-a))-exponent(a)>=-p,my(sa=sqrt(a),sb=sqrt(b),sc=sqrt(c),sd=sqrt(d));[a,b,c,d]=[(a+b+c+d)/4,(sa*sb+sc*sd)/2,(sa*sc+sb*sd)/2,(sa*sd+sb*sc)/2]);a,
	#args==6,my([a,b,c,d,e,f]=bitprecision(args,p+64));while(exponent(abs(a-b)+abs(c-d)+abs(e-f))-exponent([a,b,c,d,e,f])>=-p,my(ab=a*b,cd=c*d,ef=e*f,ac=a-c,ad=a-d,ae=a-e,af=a-f,bc=b-c,bd=b-d,be=b-e,bf=b-f,ce=c-e,cf=c-f,de=d-e,df=d-f,n1=ab-cd,n2=ab-ef,n3=cd-ef,d1=ac+bd,d2=ae+bf,d3=ce+df,s1=sqrt(ac)*sqrt(ad)*sqrt(bc)*sqrt(bd),s2=sqrt(ae)*sqrt(af)*sqrt(be)*sqrt(bf),s3=sqrt(ce)*sqrt(cf)*sqrt(de)*sqrt(df),r1=[n1+s1,n1-s1]/d1,r2=[n2+s2,n2-s2]/d2,r3=[n3+s3,n3-s3]/d3,E=oo);for(i=1,2,for(j=1,2,for(k=1,2,my(t=abs(r2[i]-r1[j])+abs(r1[3-j]-r3[k])+abs(r3[3-j]-r2[3-k]));if(E>t,E=t;a=r2[i];b=r1[j];c=r1[3-j];d=r3[i];e=r3[3-i];f=r2[3-i];break)))));[a,c,e],
	error("genus2agm: must be 4 or 6 arguments")
),p));
\\ Inverse of incomplete elliptic integrals
invincellE=((k,y)->my(t=y*Pi/(2*ellE(k)));solve(x=t-1/3,t+1/3,incellE(k,x)-y));
}

Code: Select all

{
jacobiAM_Landen=((k,z)->my(L=List(),a=1,b=sqrt(1-k^2),c=k,e=bitprecision([k,z]));
	if(e==oo,e=getlocalbitprec();k*=1.);
	until(exponent(c)<-e/2,[a,b]=[(a+b)/2,sqrt(a*b)];c=(c/2)^2/a;listput(~L,c/a));
	z*=a<<#L;while(#L,c=L[#L];listpop(~L);z=(z+asin(c*sin(z)))/2);return(z)
);
}

Code: Select all

\\ Scaled complementary error function
erfcx(x) = {
  if(real(x) < 0, return(erfc(x) * exp(x^2)));
  my(h, h2, eh2, denom, res, lambda, u, v, D, npoints, k, t, Uk, Vk, prec);
  prec = getlocalbitprec();
  localbitprec(64);
  D = prec * log(2);
  npoints = ceil(D / Pi) + 1;
  t = exp(-2 * sqr(Pi) / D);
  v = 30;
  u = floor(t << v);
  localbitprec(prec + 64);
  x = bitprecision(x * 1., prec + 64);
  eh2 = sqrt(shiftmul(u, -v));
  h2 = -log(eh2);
  h = sqrt(h2);
  lambda = x / h;
  denom = sqr(lambda);
  Vk = eh2;
  denom = 1 + denom;
  Uk = Vk;
  Vk = shiftmul(u * Vk, -v);
  res = Uk / denom;
  for (k = 1, npoints - 1, 
    denom += 2 * k + 1;
    Uk *= Vk;
    Vk = shiftmul(u * Vk, -v);
    res = res + Uk / denom;
  );
  res *= 2 * lambda;
  res += 1 / lambda;
  res /= Pi;
  if (real(x) < sqrt(D),
    t = (2 * Pi / h) * x;
    res = res - (2 * exp(sqr(x))) / expm1(t)
  );
  return(bitprecision(res, prec));
}

Code: Select all

\\ Phase of Bessel function
besselphase=((n,x)->if(!x,return(-Pi/2));my(t,J=besselj(n,x),Y=bessely(n,x));t=2*real(intnum(t=0,x,1/(t*(besselj(n,t)^2+bessely(n,t)^2))))/Pi^2;if(norm(J)>norm(Y),Pi*floor(t)+atan(Y/J),Pi*(round(t)-1/2)-atan(J/Y)));
Last edited by PHPBB12345 on December 7th, 2025, 9:26 am, edited 98 times in total.
User avatar
PHPBB12345
Posts: 1150
Joined: August 5th, 2015, 11:55 pm
Contact:

Re: Computer programs

Post by PHPBB12345 »

Code: Select all

var parseRule = function (rule_str) {
var table = [], tablecnt = [];
var add4f = function (n, v) {
  var r = n & 0x88 | (n * 0x101 >> 4) & 0x77;
  r = r & 0xAA | (r << 2) & 0x44 | (r >> 2) & 0x11;
  var n2 = n * 0x101, r2 = r * 0x101;
  table[n] = v, table[r] = v;
  table[(n2>>2)&255] = v, table[(r2>>2)&255] = v;
  table[(n2>>4)&255] = v, table[(r2>>4)&255] = v;
  table[(n2>>6)&255] = v, table[(r2>>6)&255] = v;
}
for (var i = 0, j; i < 256; ++i) {
  j = (i & 0x55) + ((i>>1) & 0x55);
  j = (j & 0x33) + ((j>>2) & 0x33);
  tablecnt[i] = (j + (j>>4)) & 15;
}
var nbrhd = [
  {c: 0x00},
  {c: 0x01, e: 0x02},
  {c: 0x05, e: 0x0a, k: 0x09, a: 0x03, i: 0x22, n: 0x11},
  {c: 0x15, e: 0x2a, k: 0x29, a: 0x0e, i: 0x07, n: 0x0d, y: 0x49, q: 0x13, j: 0x0b, r: 0x23},
  {c: 0x55, e: 0xaa, k: 0x4b, a: 0x0f, i: 0x36, n: 0x17, y: 0x35, q: 0x39, j: 0x2b, r: 0x2e, t: 0x27, w: 0x1b, z: 0x33},
  {c: 0xea, e: 0xd5, k: 0xd6, a: 0xf1, i: 0xf8, n: 0xf2, y: 0xb6, q: 0xec, j: 0xf4, r: 0xdc},
  {c: 0xfa, e: 0xf5, k: 0xf6, a: 0xfc, i: 0xdd, n: 0xee},
  {c: 0xfe, e: 0xfd},
  {c: 0xff}
]
var nbrcnt = [1,2,6,10,13,10,6,2,1];
var nbrstr = "cekainyqjrtwz".split("");
var parsePartRule = function (pstr) {
  var pstr = pstr.split(""), index = -1, n = [[0],[0,0],[0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0],[0,0],[0]], nstr = "", m, invert, nh, exist = [false,false,false,false,false,false,false,false,false];
  for (var i = 0; i < 256; ++i) {
    table[i] = 0;
  }
  for (var i = pstr.length - 1; i >= 0; i--) {
    nstr += pstr[i];
    if (pstr[i] >= '0' && pstr[i] <= '8') {
      nh = +pstr[i];
      if (exist[nh]) { throw(Error("Repeated number found")); }
      exist[nh] = true
      invert = false
      m = nstr.length - 1;
      if (m === 0 || nh === 0 || nh === 8) { invert = true; } else {
        if (nstr[m - 1] === "-") {
          invert = true;
          m--;
        }
        for (var i2 = 0; i2 < m; ++i2) {
          var indstr = nbrstr.indexOf(nstr[i2]);
          n[nh][indstr] = 1
        }
      }
      if (invert) {
        for (var i3 = nbrcnt[nh]-1; i3 >= 0; i3--) { n[nh][i3] ^= 1; }
      }
      for (i3 = nbrcnt[nh]-1; i3 >= 0; i3--) { (m = n[nh][i3]) && add4f(nbrhd[nh][nbrstr[i3]], 1) }
      nstr = "";
    }
  }
  return table;
}
return (function (rstr) {
  rstr = rstr.replace(/\//g, "_");
  var params = rstr.split("_");
  if (params.length === 1) {params[1] = "";}
  if (params[0].charAt(0).toUpperCase() === "B" || params[1].charAt(0).toUpperCase() === "S") {
    syntax = [params[0], params[1]];
  } else {
    syntax = [params[1], params[0]];
  }
  var m2, arr, syntax;
  parsePartRule(syntax[0]); arr = table.slice();
  parsePartRule(syntax[1]); return [arr, table];
})(rule_str);
}
function random_rule() {
  var nbrcnt = [1,2,6,10,13,10,6,2,1];
  var nbrstr = "cekainyqjrtwz".split("");
  var b, i, j, k, s = "", t;
  for (b = 1; b >= 0; b--)
  {
    s += b ? "B" : "/S";
    for (i = b; i < 9; i++) {
      t = "";
      k = nbrcnt[i] - 1;
      for (j = 0; j <= k; j++) {
        if (Math.random() < 0.5)
          t += nbrstr[j];
      }
      if (t.length)
      {
        s += i;
        if (t.length <= k)
          s += t;
      }
    }
  }
  return s;
}
User avatar
PHPBB12345
Posts: 1150
Joined: August 5th, 2015, 11:55 pm
Contact:

Re: Computer programs

Post by PHPBB12345 »

Code: Select all

#include <algorithm>
#include <stdint.h>
#include <iostream>
#include <type_traits>

#if !(defined(__GNUC__) && defined(__x86_64__))
static uint64_t AddDiv64 (uint64_t a, uint64_t b, uint64_t m, uint64_t &s)
{
	s = a + b;
	uint64_t q = s < a || s >= m;
	s -= m & -q;
	return q;
}
#endif

void MulDiv32 (uint32_t a, uint32_t b, uint32_t m, uint32_t &q, uint32_t &r)
{
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
	__asm__("mull %3":"=a"(a),"=d"(b):"%a"(a),"rm"(b):"flags");
	__asm__("divl %4":"=a"(q),"=d"(r):"a"(a),"d"(b),"rm"(m):"flags");
#else
	uint64_t t = (uint64_t)a * (uint64_t)b;
	q = t / m;
	r = t - q * m;
#endif
}

void MulDiv64 (uint64_t a, uint64_t b, uint64_t m, uint64_t &q, uint64_t &r)
{
#if defined(__GNUC__) && defined(__x86_64__)
	__asm__("mulq %3":"=a"(a),"=d"(b):"%a"(a),"rm"(b):"flags");
	__asm__("divq %4":"=a"(q),"=d"(r):"a"(a),"d"(b),"rm"(m):"flags");
#else
	if (a < b) ::std::swap(a, b);
	uint64_t c = a / m, d, e;
	d = a - c * m;
	e = r = 0;
	q = b * c;
	while (b)
	{
		if (b & 1)
			q += e + AddDiv64(d, r, m, r);
		b >>= 1;
		if (!b)
			break;
		e += e + AddDiv64(d, d, m, d);
	}
#endif
}

template <typename T>
typename std::enable_if<std::is_unsigned<T>::value && (sizeof(T) <= 4)>::type
MulDiv (T a, T b, T m, T &q, T &r)
{
	uint32_t _q;
	uint32_t _r;
	MulDiv32((uint32_t)a, (uint32_t)b, (uint32_t)m, _q, _r);
	q = _q;
	r = _r;
}

template <typename T>
typename std::enable_if<std::is_unsigned<T>::value && (sizeof(T) == 8)>::type
MulDiv (T a, T b, T m, T &q, T &r)
{
	uint64_t _q;
	uint64_t _r;
	MulDiv64((uint32_t)a, (uint32_t)b, (uint32_t)m, _q, _r);
	q = _q;
	r = _r;
}

template <typename T>
typename std::enable_if<std::is_signed<T>::value && std::is_integral<T>::value>::type
MulDiv (T a, T b, T m, T &q, T &r)
{
	using U = std::make_unsigned<T>::type;
	U _a = ::std::abs(a);
	U _b = ::std::abs(b);
	U _m = ::std::abs(m);
	U _q;
	U _r;
	MulDiv(_a, _b, _m, _q, _r);
	q = _q;
	r = _r;
	if ((a ^ b) < 0)
	{
		q = -q;
		r = -r;
	}
}

int main ()
{
	uint64_t a, b, m, q, r;
	::std::cin >> a >> b >> m;
	MulDiv(a, b, m, q, r);
	::std::cout << q << " " << r;
	return 0;
}
User avatar
PHPBB12345
Posts: 1150
Joined: August 5th, 2015, 11:55 pm
Contact:

Hypergeometric series

Post by PHPBB12345 »

Code: Select all

sqrt_impl(x)=hypergeom([-1/2],[],1-x)
pow_impl(x,y)=hypergeom([-y],[],1-x)
exp_impl(x)=hypergeom([],[],x)
log_impl(x)=(x-1)*hypergeom([1,1],[2],1-x)
sin_impl(x)=x*hypergeom([],[3/2],-x^2/4)
cos_impl(x)=hypergeom([],[1/2],-x^2/4)
tan_impl(x)=sin(x)/cos(x)
sinh_impl(x)=x*hypergeom([],[3/2],x^2/4)
cosh_impl(x)=hypergeom([],[1/2],x^2/4)
tanh_impl(x)=sinh(x)/cosh(x)
asin_impl(x)=x*hypergeom([1/2,1/2],[3/2],x^2)
acos_impl(x)=Pi/2-asin(x)
atan_impl(x)=x*hypergeom([1,1/2],[3/2],-x^2)
asinh_impl(x)=x*hypergeom([1/2,1/2],[3/2],-x^2)
acosh_impl(x)=log(2*x)-hypergeom([3/2,1,1],[2,2],1/x^2)/(4*x^2)
atanh_impl(x)=x*hypergeom([1,1/2],[3/2],x^2)
Citation needed
Posts: 698
Joined: April 1st, 2021, 1:03 am

Re: Computer programs

Post by Citation needed »

Code: Select all

from selenium import webdriver

# Create a Chrome driver
driver = webdriver.Chrome()

# Navigate to a webpage
driver.get('https://example.com')

# Get the HTML source of the entire page
html_source = driver.page_source

# Print the HTML source
print(html_source)

# Close the browser
driver.quit()

Code: Select all

from selenium import webdriver

# Create a Chrome driver
driver = webdriver.Chrome()

# Navigate to a webpage
driver.get('https://example.com')

# Perform actions on the webpage (e.g., clicking a button)
# ...

# Get the HTML source after performing actions
html_source = driver.page_source

# Print the HTML source
print(html_source)

# Close the browser
driver.quit()

Code: Select all

from selenium import webdriver

# Create a Chrome driver
driver = webdriver.Chrome()

# Navigate to a webpage
driver.get('https://example.com')

# Get the HTML source of the entire page
html_source = driver.page_source

# Save the HTML source to a file
with open('output.html', 'w', encoding='utf-8') as file:
    file.write(html_source)

# Close the browser
driver.quit()

Code: Select all

# imported the requests library 
import requests 
image_url = "https://www.python.org/static/community_logos/python-logo-master-v3-TM.png"
  
# URL of the image to be downloaded is defined as image_url 
r = requests.get(image_url) # create HTTP response object 
  
# send a HTTP request to the server and save 
# the HTTP response in a response object called r 
with open("python_logo.png",'wb') as f: 
  
    # Saving received content as a png file in 
    # binary format 
  
    # write the contents of the response (r.content) 
    # to a new file in binary mode. 
    f.write(r.content) 

Code: Select all

import requests
from bs4 import BeautifulSoup
 
 
url = 'https://www.geeksforgeeks.org/'
reqs = requests.get(url)
soup = BeautifulSoup(reqs.text, 'html.parser')
 
urls = []
for link in soup.find_all('a'):
    print(link.get('href'))

Code: Select all

import requests
from bs4 import BeautifulSoup
 
urls = 'https://www.geeksforgeeks.org/'
grab = requests.get(urls)
soup = BeautifulSoup(grab.text, 'html.parser')
 
# opening a file in write mode
f = open("test1.txt", "w")
# traverse paragraphs from soup
for link in soup.find_all("a"):
   data = link.get('href')
   f.write(data)
   f.write("\n")
 
f.close()
User avatar
haaaaaands
Posts: 705
Joined: September 7th, 2023, 7:22 am
Location: on the deck of a lwss inside a b3s23 bottle
Contact:

Re: Computer programs

Post by haaaaaands »

BASIC FTW

Code: Select all

10 score=0
20 print "welcome to my quiz"
30 print "which planet in our solar system has rings?"
40 print "a) jupiter"
50 print "b) venus"
60 print "c) saturn"
70 print "d) mercury"
80 input "your choice: ", answer$
90 if answer$="c"
100 print "correct"
110 score=score+1
120 else
130 print "wrong. correct answer: c"
140 end
150 print "how many strings does a violin have"
160 print "a) 4"
170 print "b) 6"
180 print "c) 10"
190 print "d) 12"
200 input "your choice: ", answer$
210 if answer$="a"
220 print "correct"
230 score=score+1
240 else
250 print "wrong. correct answer: a"
260 end
270 print "what color is a giraffe's tongue"
280 print "a) white"
290 print "b) purple"
300 print "c) red"
310 print "d) yellow"
320 input "your choice: ", answer$
330 if answer$="b"
340 print "correct"
350 score=score+1
360 else
370 print "wrong. correct answer: b"
380 end
390 print "quiz over"
400 print "your score is: ";score
edit: here have a bat

Code: Select all

@echo off
echo format c:
pause>NUL
-- haaaaaands with 6 a's



my hands are typing words!

not quite as active anymore :/
Citation needed
Posts: 698
Joined: April 1st, 2021, 1:03 am

Re: C++

Post by Citation needed »

Code: Select all

#include <cstdio>
#define x int b
#define Life 79;
#define o1b int
#define ob1o main
#define oo (
#define bo )
#define bb {
#define b1ob putchar(
#define b1oo );
#define ob ;
#define $o ;
#define o2b y
#define b2bo3bobo ;
#define AAb putchar
#define o1bo +
#define b2bo3bo 76
#define A3bo +
#define o2ob3ob3o rule
#define bbb return 0;}
x = 72, y = 69, rule = Life
o1b ob1o oo bo bb b1ob b b1oo ob $o b1ob o2b bo b2bo3bobo $o AAb oo o1bo b2bo3bo bo $o b1ob A3bo b2bo3bo bo $o b1ob o2ob3ob3o b1oo ob bbb
User avatar
confocaloid
Posts: 6697
Joined: February 8th, 2022, 3:15 pm
Location: learn to protect yourself against stray gliders and sparks and self-destruct mechanisms

Re: Computer programs

Post by confocaloid »

The rules of Conway's Game of Life, written as a single rule that involves only four arithmetic operations:

"If the cell's current state is c and the number of alive neighbours is n, then the cell's state will be f(c,n) in the next generation."

Code: Select all

f(c,n) = (n-8) (n-7) (n-6) (n-5) (n-4) (n-1) n (cn-2n-3c+4) / 1440

Code: Select all

>>> [ [ (n-8)*(n-7)*(n-6)*(n-5)*(n-4)*(n-1)*n*(c*n-2*n-3*c+4) // 1440 for n in range(9) ] for c in range(2) ]
[[0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0]]
127:1 B3/S234c User:Confocal/R (isotropic CA, incomplete)
Unlikely events happen.
My silence does not imply agreement, nor indifference. If I disagreed with something in the past, then please do not construe my silence as something that could change that.
User avatar
tommyaweosme
Posts: 1581
Joined: January 15th, 2024, 9:37 am

Re: Computer programs

Post by tommyaweosme »

this brainf*ck program prints something

Code: Select all

+++++++++++[>+++++++++++<-]>.----------.++++++.-.+.>++++[>+++++<-]>-[<<->>-]<<.+++.>+++++++++++[>++<-]>+[<++>-]<.<--.++++++++++++.--.>+.<++++++++++.>>+++++[<<<++++>>>-]<<<+[>-<-]>-.<++++++++++[>++<-]>-.<+++++++++[>--<-]>+.+++++.>>++++++[>++++++++++<-]>+++.<<<<+++++++[>++<-]>.>>>--.[-]<<[-]<<+++++++++[>--<-]>.>+++++++++[>+++++++++<-]>.<+++++[<++++>-]<-.>>>+++++[>++++++++++<-]>++.<<<<.>>>>+++++.<<++++++.<++++[<---->-]<.>>+.<<----.>>-------.
here's the gosper glider gun

Code: Select all

#R life
24bo$22bobo$12b2o6b2o12b2o$11bo3bo4b2o12b2o$2o8bo5bo3b2o$2o8bo3bob2o4b
obo$10bo5bo7bo$11bo3bo$12b2o!
User avatar
haaaaaands
Posts: 705
Joined: September 7th, 2023, 7:22 am
Location: on the deck of a lwss inside a b3s23 bottle
Contact:

Re: Computer programs

Post by haaaaaands »

tommyaweosme wrote: June 24th, 2024, 10:21 am this brainf*ck program prints something

Code: Select all

+++++++++++[>+++++++++++<-]>.----------.++++++.-.+.>++++[>+++++<-]>-[<<->>-]<<.+++.>+++++++++++[>++<-]>+[<++>-]<.<--.++++++++++++.--.>+.<++++++++++.>>+++++[<<<++++>>>-]<<<+[>-<-]>-.<++++++++++[>++<-]>-.<+++++++++[>--<-]>+.+++++.>>++++++[>++++++++++<-]>+++.<<<<+++++++[>++<-]>.>>>--.[-]<<[-]<<+++++++++[>--<-]>.>+++++++++[>+++++++++<-]>.<+++++[<++++>-]<-.>>>+++++[>++++++++++<-]>++.<<<<.>>>>+++++.<<++++++.<++++[<---->-]<.>>+.<<----.>>-------.
output: youtube.com/watch?v=dQw4w9WgXcQ
-- haaaaaands with 6 a's



my hands are typing words!

not quite as active anymore :/
User avatar
tommyaweosme
Posts: 1581
Joined: January 15th, 2024, 9:37 am

Re: Computer programs

Post by tommyaweosme »

great you ruined it for everyone else

my 952nd post! 4x238=952
here's the gosper glider gun

Code: Select all

#R life
24bo$22bobo$12b2o6b2o12b2o$11bo3bo4b2o12b2o$2o8bo5bo3b2o$2o8bo3bob2o4b
obo$10bo5bo7bo$11bo3bo$12b2o!
olivia enessemir
Posts: 21
Joined: August 7th, 2023, 5:29 pm

Re: Computer programs

Post by olivia enessemir »

Was discussing this with a friend earlier this morning; I think some people here might be interested in this horrifying lisp interpreter written in malbolge (well, malbolge unshackled, but pretty much the same, just a TC version)-- a horrendously difficult esolang to work with.

(...Admittedly this has been around for, what, four years now? probably most of the people who would be interested are already aware of the existence of this. Still, I'm posting this because it's interesting I guess!)

The author wrote a book about her work on this program here.
omelette
Citation needed
Posts: 698
Joined: April 1st, 2021, 1:03 am

Re: C++

Post by Citation needed »

Citation needed wrote: June 23rd, 2024, 11:00 pm

Code: Select all

#include <cstdio>
#define x int b
#define Life 79;
#define o1b int
#define ob1o main
#define oo (
#define bo )
#define bb {
#define b1ob putchar(
#define b1oo );
#define ob ;
#define $o ;
#define o2b y
#define b2bo3bobo ;
#define AAb putchar
#define o1bo +
#define b2bo3bo 76
#define A3bo +
#define o2ob3ob3o rule
#define bbb return 0;}
x = 72, y = 69, rule = Life
o1b ob1o oo bo bb b1ob b b1oo ob $o b1ob o2b bo b2bo3bobo $o AAb oo o1bo b2bo3bo bo $o b1ob A3bo b2bo3bo bo $o b1ob o2ob3ob3o b1oo ob bbb
This post on a forum may be introducing a similar concept.
User avatar
haaaaaands
Posts: 705
Joined: September 7th, 2023, 7:22 am
Location: on the deck of a lwss inside a b3s23 bottle
Contact:

Re: Computer programs

Post by haaaaaands »

tommyaweosme wrote: June 24th, 2024, 11:18 am great you ruined it for everyone else
oops...
-- haaaaaands with 6 a's



my hands are typing words!

not quite as active anymore :/
Citation needed
Posts: 698
Joined: April 1st, 2021, 1:03 am

Re: Computer programs

Post by Citation needed »

Code: Select all

#include <cstdio>
int c;
int main(){
while((c=getchar())+1){
putchar(c==32?46:c);
}return 0;}
Citation needed
Posts: 698
Joined: April 1st, 2021, 1:03 am

Re: Computer programs

Post by Citation needed »

If you need to have your Python program take in Unicode characters one by one without triggering "Input Limit Exceeded", you can do something like this.

Code: Select all

import sys

while(1):
 c=sys.stdin.read(1)
 print(ord(c),end=' ')
Citation needed
Posts: 698
Joined: April 1st, 2021, 1:03 am

Re: Computer programs

Post by Citation needed »

Code: Select all

#include <cstdio>
const int b1i45[256]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
       0,(0),0,0,0,0,0,0,0,0,0,0,0,0,0,0,
       0,44,39,42,22,23,38,26,41,0,0,0,0,0,0,0,
       0,35,27,0,11,34,25,0,14,0,0,0,37,0,15,0,
       0,0,0,0,40,0,43,0,0,36,0,0,0,0,0,0,
       0,31,1,28,17,33,29,19,21,45,5,20,16,3,9,32,
       2,6,13,12,18,30,24,4,7,8,10,0,0,0,0,0,0};
const int a1[47]={0,1,1,1,1,1,1,1,1,1,
              2,2,2,2,2,2,2,2,
              3,3,3,3,3,3,3,
              4,4,4,4,4,4,
              5,5,5,5,5,
              6,6,6,6,
              7,7,7,
              8,8,
              9};
const int a2[47]={0,1,2,3,4,5,6,7,8,9,
              1,2,3,4,5,6,7,8,
              1,2,3,4,5,6,7,
              1,2,3,4,5,6,
              1,2,3,4,5,
              1,2,3,4,
              1,2,3,
              1,2,
              1};

char c;
int b;
int p1;
int p2;
unsigned char uc;
int main(){
printf("x = 10, y = 0, rule = B3S23\n");
while((c=getchar())+1){
uc=c;
b=b1i45[uc];
p1=a1[b];
p2=a2[b];
if(p2>1)printf("%db",p2-1);
if(p1>0)printf("%do",p1+1);
putchar('$');
}
putchar('!');
return 0; // XDI8AHO
}
Citation needed
Posts: 698
Joined: April 1st, 2021, 1:03 am

Re: Computer programs

Post by Citation needed »

Citation needed wrote: November 8th, 2024, 5:31 am
The following program handles the Shidinn chat alphabet.

Code: Select all

""" XDI8AHO """
username=list(input())
part1="http://catagolue.appspot.com/object/xp0_"
part2="z"
part3="/b3s23"
dict1={
'A':"v888v0",
'a':"u999u0",
'a`':"v999u0",
'B':"v999m0",
'b':"f999h0",
'C':"h9f9h0",
'c':"u11120",
'C`':"g8l370",
'D':"h999f0",
'd':"v111u0",
'E':"v99990",
'e':"u999e0",
'F':"1199v0",
'f':"v99110",
'G':"v222u0",
'g':"u119q0",
'g`':"253h20",
'H':"v88880",
'h':"v888v0",
'I':"v8v8n0",
'i':"11v110",
'J':"wv960",
'j':"gxv0",
'K':"3cgc30",
'k':"v8k210",
'k`':"8ata80",
'L':"1p52s0",
'l':"vy1",
'L`':"0v11v0",
'M':"119l30",
'm':"v1v1v0",
'm`':"ut1tu0",
'N':"s48gv0",
'n':"v11110",
'N`':"61v0g0",
'n`':"nhhhn0",
'O':"gc3cg0",
'o':"u111u0",
'O`':"7p1p70",
'P':"v222s0",
'p':"v99960",
'P`':"vaaas0",
'p`':"8kd370",
'Q':"u222v0",
'q':"u1h1u0",
'Q`':"m9v9m0",
'q`':"69p960",
'R':"v8o0o0",
'r':"v999m0",
'R`':"v9p990",
'r`':"m999v0",
'S':"u9v9u0",
's':"6999i0",
's`':"3l9110",
'T':"u999u0",
't':"11v110",
'U':"u11ug0",
'u':"vxv0",
'V':"s212s0",
'v':"vxv0",
'v`':"11u110",
'W':"s2v2s0",
'w':"v0v0v0",
'W`':"j4j4j0",
'w`':"sv0vs0",
'X':"wvx",
'x':"n888n0",
'x`':"29v800",
'Y':"ha4ah0",
'y':"78g870",
'Y`':"1p7p10",
'y`':"9asa90",
'Z':"88vx",
'z':"1h9530",
'0':"22v220",
'1':"21vx",
'2':"h999v0",
'3':"9999v0",
'4':"ca9v80",
'5':"vg84s0",
'5`':"g0v160",
'6':"u999i0",
'6`':"0ktb70",
'7':"1111v0",
'8':"m999v0",
'8`':"u1v1u0",
'9':"6999u0",
'!`':"11v110",
'$`':"4avai0",
'-':"888880",
'_':"y2",
' ':"y2",
'`':''
}
dict2={
'A':"122210",
'a':"3x30",
'a`':"322210",
'B':"322210",
'b':"222210",
'C':"122210",
'c':"122210",
'C`':"121x",
'D':"122220",
'd':"322210",
'E':"322220",
'e':"122220",
'F':"y030",
'f':"3y1",
'G':"111130",
'g':"122230",
'g`':"123210",
'H':"3y1",
'h':"3x30",
'I':"303030",
'i':"223220",
'J':"121x",
'j':"122210",
'K':"223220",
'k':"300120",
'k`':"223220",
'L':"3x30",
'l':"322220",
'L`':"210210",
'M':"222230",
'm':"303030",
'm`':"0303w",
'N':"3y1",
'n':"3y1",
'N`':"w3210",
'n`':"3x30",
'O':"322230",
'o':"122210",
'O`':"w3x",
'P':"3111w",
'p':"3y1",
'P`':"3111w",
'p`':"131x",
'Q':"311110",
'q':"122120",
'Q`':"303030",
'q`':"013100",
'R':"3w3w",
'r':"3x30",
'R`':"300120",
'r`':"3x30",
'S':"123210",
's':"122210",
's`':"322220",
'T':"122210",
't':"w3x",
'U':"3w3w",
'u':"122210",
'V':"3x30",
'v':"0121w",
'v`':"w3x",
'W':"303030",
'w':"121210",
'W`':"121210",
'w`':"122210",
'X':"223220",
'x':"3x30",
'x`':"w3210",
'Y':"122210",
'y':"w3x",
'Y`':"3x30",
'y`':"113110",
'Z':"w3220",
'z':"322220",
'0':"113110",
'1':"w3x",
'2':"122230",
'3':"222230",
'4':"x3w",
'5':"y030",
'5`':"123x",
'6':"122210",
'6`':"121x",
'7':"y030",
'8':"122230",
'8`':"123210",
'9':"122210",
'!`':"22b220",
'$`':"113100",
'-':"y2",
'_':"222220",
' ':"y2",
'`':''
}

for n in range(abs(len(username)-1)):
 if username[n+1]=="`":
  username[n]+="`"

for i in username:
 part1+=dict1[i]
 part2+=dict2[i]
print(part1,part2,part3,sep='')
EDIT: Someone actually used this program to find a soup (B3/S23) lasting 7164 ticks with a final population of 1752. The soup started with 110 cells. There is a temporary MWSS, a temporary queen bee, a temporary "land of lakes" and a temporary pulsar. A paperclip and four toads survived.
Post Reply