n = gets.chomp.to_i result = Array.new() n.times do result.push((1..n).to_a.map(&:to_i)) end tl, rb = n-1, n spn = 1 loop do (rb-1).times do | i | result[i+spn][n-spn] = result[i+spn-1][n-spn] + 1 end (rb-1).times do | i | result[n-spn][n-spn-i-1] = result[n-spn][n-spn-i] + 1 end (tl-1).times do | i | result[n-spn-i-1][spn-1] = result[n-spn-i][spn-1] + 1 end (tl-1).times do | i | result[spn][i+spn] = result[spn][i+spn-1] + 1 end tl-=2 rb-=2 if tl <= 0 break end spn+=1 end for re in result for r in re r = r.to_s if r.length == 1 print "00#{r} " elsif r.length == 2 print "0#{r} " else print "#{r} " end end print "\n" end