Magic squares of singly even order: Difference between revisions

Added 11l
(→‎{{header|J}}: use wiki markup for link)
(Added 11l)
Line 16:
* [http://www.1728.org/magicsq3.htm Singly Even Magic Squares (1728.org)]<br><br>
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>-V LOG_10 = 2.302585092994
 
F build_oms(=s)
I s % 2 == 0
s++
V q = [[0] * s] * s
V p = 1
V i = s I/ 2
V j = 0
 
L p <= (s * s)
q[i][j] = p
V ti = i + 1
I ti >= s
ti = 0
V tj = j - 1
I tj < 0
tj = s - 1
I q[ti][tj] != 0
ti = i
tj = j + 1
i = ti
j = tj
p++
 
R (q, s)
 
F build_sems(=s)
I s % 2 == 1
s++
L s % 4 == 0
s += 2
V q = [[0] * s] * s
V z = s I/ 2
V b = z * z
V c = 2 * b
V d = 3 * b
V o = build_oms(z)
 
L(j) 0 .< z
L(i) 0 .< z
V a = o[0][i][j]
q[i][j] = a
q[i + z][j + z] = a + b
q[i + z][j] = a + c
q[i][j + z] = a + d
 
V lc = z I/ 2
V rc = lc
L(j) 0 .< z
L(i) 0 .< s
I i < lc
| i > s - rc
| (i == lc & j == lc)
I !(i == 0 & j == lc)
swap(&q[i][j], &q[i][j + z])
R (q, s)
 
F display(q)
V s = q[1]
print(" - #. x #.\n".format(s, s))
V k = 1 + Int(floor(log(s * s) / :LOG_10))
L(j) 0 .< s
L(i) 0 .< s
print(String(q[0][i][j]).zfill(k), end' ‘ ’)
print()
print(‘Magic sum: #.’.format(s * ((s * s) + 1) I/ 2))
 
print(‘Singly Even Magic Square’, end' ‘’)
display(build_sems(6))</lang>
 
{{out}}
<pre>
Singly Even Magic Square - 6 x 6
 
35 01 06 26 19 24
03 32 07 21 23 25
31 09 02 22 27 20
08 28 33 17 10 15
30 05 34 12 14 16
04 36 29 13 18 11
Magic sum: 111
</pre>
 
=={{header|Befunge}}==
1,480

edits