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 / miniball_int.cpp
Created July 9, 2024 20:04
Determination of convex set diameter with Miniball.hpp
#include <cstdlib>
#include <iostream>
#include <math.h>
#include "Miniball.hpp"
// from https://people.inf.ethz.ch/gaertner/subdir/software/miniball.html
/*
$ g++ miniball_int.cpp -O3 -o miniball_int
$
*/
int main (int argc, char* argv[])
@Hermann-SW
Hermann-SW / SquaresRepresentations.gp
Last active July 8, 2024 07:00
Representatins of n as sum of k squares (non-negative monotonic increasing, all, count)
assert(b)=if(!(b),error());
SquaresRepresentations(n,k,a=0)={
my(R=List(),m=sqrtint(n\k));
if(k==1,return(if(m>=a&&n==m^2,[m],[])));
for(b=a,m,foreach(SquaresRepresentations(n-b^2,k-1,b),s,listput(R,concat([b],s))));
Vec(R);
}
signs(a)={
@Hermann-SW
Hermann-SW / 131072.gp
Last active June 4, 2024 18:12
1108 Generalized Fermat prime bases with exponent 131072 from t5k.org
{[
2022202116,
1777034894,
1000032472,
399866798,
314187728,
271643232,
232050760,
231583998,
231295516,
@Hermann-SW
Hermann-SW / Fermat.gp
Last active June 29, 2024 19:50
Prime factors of Fermat numbers F0..F30
F__={[\\ needs parisizemax >= 600M; from http://www.prothsearch.com/fermat.html
[3], \\ F0
[5],
[17],
[257],
[65537],
[641, 6700417],
[274177, 67280421310721],
[59649589127497217, 5704689200685129054721],
[1238926361552897, "P62"],
@Hermann-SW
Hermann-SW / palindrome.gp
Created May 1, 2024 21:38
20 palindrome primes from t5k.org
{[
"10^2000007-10^1127194-10^872812-1",
"10^2000005-10^1051046-10^948958-1",
"10^1888529-10^944264-1",
"10^1234567-20342924302*10^617278-1",
"10^1234567-1927633367291*10^617277-1",
"10^1234567-3626840486263*10^617277-1",
"10^1234567-4708229228074*10^617277-1",
"10^490000+3*(10^7383-1)/9*10^241309+1",
"10^474500+999*10^237249+1",
@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 July 21, 2024 22:16
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
*/