Jump to content

Magic squares of doubly even order: Difference between revisions

m (→‎{{header|FreeBASIC}}: removed redundant code)
Line 325:
 
Magic constant: 260</pre>
 
=={{header|PARI/GP}}==
 
A magic one-liner:
<lang parigp>magicsqare(n)={matrix(n,n,i,j,k=i+j*n-n;if(bitand(38505,2^((j-1)%4*4+(i-1)%4)),k,n*n+1-k))}</lang>
 
Output:<pre>magicsquare(8)
 
[ 1 56 48 25 33 24 16 57]
 
[63 10 18 39 31 42 50 7]
 
[62 11 19 38 30 43 51 6]
 
[ 4 53 45 28 36 21 13 60]
 
[ 5 52 44 29 37 20 12 61]
 
[59 14 22 35 27 46 54 3]
 
[58 15 23 34 26 47 55 2]
 
[ 8 49 41 32 40 17 9 64]</pre>
 
BTW: The number 38505 = 9669h seems to come from hell to do the magic...
 
=={{header|Perl 6}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.