User:PrimeHunter/Table of prime factors (program)

The below program was made to generate tables for Table of prime factors. See Talk:Table of prime factors.

/* PARI/GP program by PrimeHunter */ /* Generates tables for http://en.wikipedia.org/wiki/Table_of_prime_factors */

largelinked = Set([440,449,451,464,465,475,485,486,487,496,501,509,512,\ 519,525,529,554,555,556,561,580,585,586,593,603,610,611,613,616,619,\ 629,641,666,702,707,715,717,720,727,747,765,777,786,790,874,880,881,\ 883,911,985,987,992,999]) islinked(n) = (n<=436) || (n<=1000 && n%100==0) || setsearch(largelinked,n) /* islinked(n) is true if "n (number)" (n<=1000) has a Wikipedia article or redirect */

maketable(rows,columns,start,o) = { local(r,c,n,f,i); write(o,"{| class=\"wikitable\""); write(o,"|+ ",start," &minus; ",start+rows*columns-1); for(r=1,rows,   write(o,"|-");    for(c=1,columns, n = start + r-1 + rows*(c-1); if (c>1,write1(o,"|")); write1(o,"|"); if (islinked(n), write1(o,"",n,""), write1(o,n) ); write1(o,"||"); if (n==1,write1(o,"unit")); f=factor(n); if (isprime(n),write1(o,"'''")); for(i=1,#f[,1],       if (i>1,write1(o,"·"));        write1(o,f[i,1]);        if (f[i,2]>1,write1(o,"",f[i,2],""));      ); if (isprime(n),write1(o,"'''")); );   write(o,"");  ); write(o,"|}"); }

makemultitable(rows,columns,start,o) = { local(c); write(o,"{| border=\"0\" cellpadding=\"0\" cellspacing=\"0\""); /*write(o,"|+ Prime factorization of ",start," to ",start+rows*columns-1,"");*/ for(c=1,columns,write(o,"|");maketable(rows,1,start+(c-1)*rows,o)); write(o,"|}"); }

makemultitables(tables,rows,columns,start,o) = { local(t); for(t=1,tables,   write(o,"== ",start+(t-1)*rows*columns, " to ",start+t*rows*columns-1," ==");    makemultitable(rows,columns,start+(t-1)*rows*columns,o);    write(o,"");  ); }

makemultitables(10,20,5,1,"factortables.txt"); /* Makes 10 tables, each with 5 20-row tables side by side. First table starts with 1. Result in wiki-table format written to factortables.txt */