((side**2).downto(1)).each do |n|
$tab[a][b] = n
if $tab[a+v][b+h] != nil
if h==0
if v==1
h,v = -1,0
else
h,v = 1,0
end
elsif v==0
if h==1
h,v = 0,1
else
h,v = 0,-1
end
end
end
a,b = a+v, b+h
break if $tab[a][b] != nil
end
sum = 0
1.upto(side) do |a|
sum += $tab[a][a]
sum += $tab[a][side+1-a]
end
sum -= $tab[(side+1)/2][(side+1)/2]
puts “suma: #{sum}”[/code]
[code=ruby]num = 1001**2
sum = 0
n = 1000
$tmp = num
while n >= 2
4.times do
sum += $tmp-n
$tmp -= n
end
n -= 2
end