Magic square by MG

$t=$s=<>;$v=0;$h=int($s/2);for($t*=$t,$c=1;$t>0;$t--,$c++){$a[$h][$v]=$c;if($a[($h+1)%$s][($v+2)%$s]){$v=($v+1)%$s}else{$h=($h+1)%$s,$v=($v+2)%$s}}for($v=0;$v<$s;$v++,$o=''){map{$o.=sprintf'%3d ',$a[$_][$v]}0..($s-1);chop$o;print"$o\n";}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page