$n=<>; $x=$y=0; $u=1; for(1..$n*$n){ $$y[$x]=sprintf"%03d",$_; if($x+$u==$n||$y+$v==$n||$x+$u<0||$y+$v<0||${$y+$v}[$x+$u]){ ($u,$v)=(-$v,$u); } $x+=$u;$y+=$v; } for(0..$n-1){ print"@$_\n"; }