Magic squares of doubly even order: Difference between revisions
Content added Content deleted
m (simplified t/mod) |
|||
Line 1,507: | Line 1,507: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{trans|C++}} |
{{trans|C++}} |
||
<lang Phix>constant t = {{1, |
<lang Phix>constant t = {{1,1,0,0}, |
||
{ |
{1,1,0,0}, |
||
{0, |
{0,0,1,1}, |
||
{ |
{0,0,1,1}} |
||
function magic_square(integer n) |
function magic_square(integer n) |
||
Line 1,518: | Line 1,518: | ||
for r=1 to n do |
for r=1 to n do |
||
for c=1 to n do |
for c=1 to n do |
||
square[r,c] = iff(t[mod(r |
square[r,c] = iff(t[mod(r,4)+1,mod(c,4)+1]?i+1:n*n-i) |
||
i += 1 |
i += 1 |
||
end for |
end for |
||
Line 1,524: | Line 1,524: | ||
return square |
return square |
||
end function |
end function |
||
procedure check(sequence sq) |
procedure check(sequence sq) |
||
integer n = length(sq) |
integer n = length(sq) |