Jump to content

Magic squares of doubly even order: Difference between revisions

Added 11l
(Added 11l)
Line 38:
* [http://www.1728.org/magicsq2.htm Doubly Even Magic Squares (1728.org)]
<br><br>
 
=={{header|11l}}==
{{trans|Java}}
 
<lang 11l>F magicSquareDoublyEven(n)
V bits = 1001'0110'0110'1001b
V size = n * n
V mult = n I/ 4
 
V result = [[0] * n] * n
V i = 0
L(r) 0 .< n
L(c) 0 .< n
V bitPos = c I/ mult + (r I/ mult) * 4
result[r][c] = I (bits [&] (1 << bitPos)) != 0 {i + 1} E size - i
i++
R result
 
V n = 8
L(row) magicSquareDoublyEven(n)
L(x) row
print(‘#2 ’.format(x), end' ‘’)
print()
print("\nMagic constant: "((n * n + 1) * n I/ 2))</lang>
 
{{out}}
<pre>
1 2 62 61 60 59 7 8
9 10 54 53 52 51 15 16
48 47 19 20 21 22 42 41
40 39 27 28 29 30 34 33
32 31 35 36 37 38 26 25
24 23 43 44 45 46 18 17
49 50 14 13 12 11 55 56
57 58 6 5 4 3 63 64
 
Magic constant: 260
</pre>
 
=={{header|360 Assembly}}==
1,481

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.