Magic squares of odd order: Difference between revisions

add PicoLisp
(+Stata)
(add PicoLisp)
Line 3,170:
{26,20,14, 1,44,38,32},
{42,29,23,17,11, 5,48}}
</pre>
 
=={{header|PicoLisp}}==
<lang PicoLisp>(load "@lib/simul.l")
(de magic (A)
(let
(Grid (grid A A T T)
Sum (/ (* A (inc (** A 2))) 2))
(println 'N A 'Sum Sum)
# cut one important edge
(with (last (last Grid)) (con (: 0 1)))
(with (get Grid (inc (/ A 2)) A)
(for N (* A A)
(=: V N)
(setq This
(if
(with (setq @@ (north (east This)))
(not (: V)) )
@@
(south This) ) ) ) )
# display
(mapc
'((L)
(for This L
(prin (align 4 (: V))) )
(prinl) )
Grid )
# clean
(mapc '((L) (mapc zap L)) Grid) ) )
(magic 5)
(prinl)
(magic 7)</lang>
{{out}}
<pre>
N 5 Sum 65
11 10 4 23 17
18 12 6 5 24
25 19 13 7 1
2 21 20 14 8
9 3 22 16 15
 
N 7 Sum 175
22 21 13 5 46 38 30
31 23 15 14 6 47 39
40 32 24 16 8 7 48
49 41 33 25 17 9 1
2 43 42 34 26 18 10
11 3 44 36 35 27 19
20 12 4 45 37 29 28
</pre>
 
298

edits