Skip to content

Instantly share code, notes, and snippets.

View Hermann-SW's full-sized avatar

Hermann Stamm-Wilbrandt Hermann-SW

View GitHub Profile
@Hermann-SW
Hermann-SW / C36_10.correct.jscad
Last active January 20, 2024 17:52
For curl test whether gists set CORS header
const jscad = require('@jscad/modeling')
const { colorize } = jscad.colors
const { cuboid, cube, sphere, cylinder, circle, polygon } = jscad.primitives
const { rotate, translate } = jscad.transforms
const { degToRad } = jscad.utils
const { add, normalize, length, scale, dot } = jscad.maths.vec3
const { extrudeRotate, extrudeLinear } = require('@jscad/modeling').extrusions
const { intersect, subtract, union } = require('@jscad/modeling').booleans
const { hull, hullChain } = require('@jscad/modeling').hulls
const { vectorText } = require('@jscad/modeling').text
@Hermann-SW
Hermann-SW / gp_oeis_search
Created December 31, 2023 17:57
Search integer sequence specified by short PARI/GP script on oeis.org
@Hermann-SW
Hermann-SW / Kunerth.gp
Last active November 26, 2023 11:35
Kunerth's algorithm from 1878, for determining modular sqrt
assert(b,s)=if(!(b), error(Str(s)));
m=eval(getenv("m"));
b=m.mod;
c=lift(m);
if(ispseudoprime(c),s=sqrt(Mod(-b,c)),issquare(Mod(b,-c),&s));
V=r=lift(s);;
print("V=",r);
@Hermann-SW
Hermann-SW / tqf.gp
Last active February 29, 2024 02:18
Generate ternary quadratic form that represents n and has determinant 1, for determining sum of 3(4) squares for n
assert(b,s)=if(!(b), error(Str(s)));
dbg(a,b,c="")=if(getenv("dbg"),print(a,b,c));
get_tqf(n,vstart)={
assert(n%4!=0);
assert(n%8!=7);
my(Q,v,b,p,a12);
if(n%4==2,
for(vv=vstart,oo,
@Hermann-SW
Hermann-SW / foursquare.cc
Created October 4, 2023 00:13
libgmpxx+libpari code to determine sum of four squares for semiprime p*q with qfsolve()
// p,q -> a,b,c,d with a^2+b^2+c^2+d^2==p*q
//
// f=foursquare
//
// g++ $f.cc -lgmp -lgmpxx -O3 -o $f -lpari -DPARI -Wall -Wextra -pedantic
//
// $ ./$f 999999999999999999999999999989 999999999999999999999999999983
// R = qfsolve(M)
// 2.85703s
// 223605138439657340220247124809 147944036070869714718268156597 314020169936458430849348767399 910771451642793118995923538064
@Hermann-SW
Hermann-SW / nsum.py
Last active September 23, 2023 14:36
Find permutations of numbers 1..N with each successive pair summing to a square
# pylint: disable=C0103, R1728
# invalid-name, consider-using-generator
""" blacked and pylinted; https://mersenneforum.org/showthread.php?t=22915 """
import sys
from sys import argv, stderr
from math import isqrt
N = 15 if len(argv) < 2 else int(argv[1])
a = [[] for i in range(N + 1)]
stop = len(argv) >= 3
@Hermann-SW
Hermann-SW / rsa_test.gp
Last active September 5, 2023 19:33
PARI/GP test script wrt kronecker(), chinese(), and prime factors of rsa numbers
\r RSA_numbers_factored.gp
test(v)=
{
if(#v<4,
break());
my([l,n,p,q]=v,pnr,qnr,sqrtm1);
if ((p%4!=1)||(q%4!=1),
break());
forprime(t=2,oo,
@Hermann-SW
Hermann-SW / range_client
Created August 25, 2023 14:27
client demonstrating working with range_server.py, Cullen prime demo
#!/bin/bash
if [[ "$3" != '' ]]
then
for((i=1; i<=$3; ++i))
do
$0 "$1" "$2" &
done
exit
fi
@Hermann-SW
Hermann-SW / range_server.py
Last active August 25, 2023 14:38
HTTP server: serves numbers in range for multi-host multi-core work distribution
# pylint: disable=C0103 (invalid-name)
"""
python range_server.py port start stop
"""
from socketserver import TCPServer
from http.server import SimpleHTTPRequestHandler
from threading import Thread
from timeit import default_timer
from time import strftime, gmtime
from sys import argv, stdout
@Hermann-SW
Hermann-SW / cado-nfs.loop
Created July 28, 2023 11:55
Simple bash script restarting cado-nfs.py until factorization completes successful (only needed for ARM bug)
#!/bin/bash
p=""
date
echo "======================="
./cado-nfs.py $1
while [ $? -ne 0 ]
do
date
echo "======================="