# # magic_doubler.awk # # Obtain complete magic square of double size from # a complete magic square. # # V.1.0 # F.Poyo # Oct.3,1996 # # Run this by # # gawk -f magic_doubler.awk < input.txt > output.html # BEGIN{ # # You can set one of "both", "html", "text" into output. # # output="both"; # output="html"; output="text"; # k=0; N=2; first=0; } /^$/{next} (first==1) && (k < N) { for(i=1;i<=N;i++) { x[($i)-1]=i-1; y[($i)-1]=k; }; k++; if (k==N){ first=1; k=0; } next; } (first==0) && (k < N) { N=NF; for(i=1;i<=N;i++) { x[($i)-1]=i-1; y[($i)-1]=k; }; k++; if (k==N){ first=1; k=0;} next; } # END{ NN=N*N; for(i=0;i%s-%dd","%",int(log(NN*NN)/log(10))+1); print ""; print ""; print ""; printf("A %dx%d magic cube",NN,NN); print ""; print ""; print ""; printf("

A %dx%d magic cube


",NN,NN); printf("

Sum=%d

\n",sum); print "" for(x1=0;x1"); for(x0=0;x0"); } print "
"; print ""; } # # for text output. # function text_output() { format=sprintf("%s-%dd ","%",int(log(NN*NN)/log(10))+1); printf("----- N=%d SUM=%d -----\n",NN,NN*(NN*NN+1)/2); for(i=0;i