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 / puzzle.cc
Last active April 13, 2024 21:17
Fast libgmpxx implementation of 300 decimal digit factoring puzzle
/*
https://www.mersenneforum.org/showthread.php?t=29584
Factors 300 decimal digits semiprime n, knowing its prime factors consist of
digits 3 and 7 only, 10,000 times in less than 1s in total on 7950X CPU.
f=puzzle
g++ -O3 -Wall -Wextra -pedantic $f.cc -o $f -lgmp -lgmpxx
cpplint --filter=-legal/copyright,-runtime/references $f.cc
cppcheck --enable=all --suppress=missingIncludeSystem $f.cc --check-config
@Hermann-SW
Hermann-SW / proth_m.gp
Created March 23, 2024 11:11
Analyze Proth prine k*2^m+1 (odd k < 2^m, m≥1) distribution of "k"s for a given 1≤m≤20
P=extern("curl -s https://oeis.org/A080076/a080076.json.txt");
p2=eval(getenv("p2"));
r=eval(getenv("r"));
doit(r)={
for(m=r[1],r[2],
cnt=Vec(0,2^p2);
foreach(P,p,if(2^m<p&&p<2^(2*m),cnt[1+(p>>m)>>(m-p2)]++));
print(m," ",cnt," (0..",2^(p2)-1,") vecsum=",vecsum(cnt));
)
@Hermann-SW
Hermann-SW / proth.gp
Last active March 20, 2024 22:10
determine count of Proth primes until environment n
\\ detemine count of Proth primes until environment n
\\ environment l (loops) allows to tune work distribution
\\
\\ based on Karim's isProth2():
\\ https://pari.math.u-bordeaux.fr/archives/pari-users-2403/msg00064.html
\\ and Bill's parallel implementation:
\\ https://pari.math.u-bordeaux.fr/archives/pari-users-2403/msg00067.html
\\
isProth2(p) = !(p >> (valuation(p-1,2)<<1));
export(isProth2);
@Hermann-SW
Hermann-SW / dot2leda.cpp
Created March 18, 2024 19:55
Using C++ Boost lib "read_graphviz()" to convert a graph int LEDA graph format
//=======================================================================
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
/*
f=dot2leda
g++ -O3 -Wall -pedantic -Wextra $f.cpp -o $f -lboost_graph
cpplint --filter=-legal/copyright,-build/namespaces $f.cpp
cppcheck --enable=all --suppress=missingIncludeSystem $f.cpp --check-config
*/
@Hermann-SW
Hermann-SW / straight_line_graphviz.cpp
Last active March 15, 2024 19:49
Boost make_"connected / biconnected_planar / maximal_planar"+straight_line_drawing demos made create graphviz graph with fixed coordinates
//=======================================================================
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// f=straight_line_graphviz
// g++ -O3 -Wall -pedantic -Wextra $f.cpp -o $f
// cpplint --filter=-legal/copyright,-build/namespaces $f.cpp
// cppcheck --enable=all --suppress=missingIncludeSystem $f.cpp --check-config
//=======================================================================
@Hermann-SW
Hermann-SW / GraphvizFiddle.py
Last active March 15, 2024 01:40
Open graphviz .dot file in GraphvizFiddle in browser
#!/usr/bin/env python
""" view graphviz file """
# pylint: disable=C0103
import sys
import webbrowser
import urllib.parse
import time
if len(sys.argv)<3:
print("Format: "+sys.argv[0]+" browser dotfile")
else:
@Hermann-SW
Hermann-SW / Phi3.gp
Last active March 1, 2024 10:45
72 Phi(3,x) primes from t5k.org, and verification of fast determination of sqrt(-1) (mod p)
Phi(n,x)=polcyclo(n,x);
{
P=[
-516693^1048576, -465859^1048576, -123447^524288, -143332^393216,
-844833^262144, -712012^262144, -558640^196608, -237804^196608, 93606^177147,
55599^177147, -1082083^131072, -843575^131072, -362978^131072, -192098^131072,
-1202113^98304, -1110815^98304, -700219^98304, -660955^98304, -535386^98304,
-406515^98304, -107970^98304, -62721^98304, -1538654^65536, -1456746^65536,
-1427604^65536, -1395583^65536, -1181782^65536, -1147980^65536, -984522^65536,
@Hermann-SW
Hermann-SW / C36.10.fixed.jscad.good_enough.jscad
Last active January 24, 2024 16:33
Good enough GP3D generated C36.10.fixed version
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 / 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