def odd_magic_square(n)
  raise ArgumentError  if n.even? || n <= 0
  n.times.map{|i| n.times.map{|j| n*((i+j+1+n/2)%n) + ((i+2*j-5)%n) + 1} }
end

[3, 5, 9].each do |n|
  puts 
  fmt =  * n
  odd_magic_square(n).each{|row| puts fmt % row}
end