
  if sp.size == 1
    []
  else
    id += 1
    sp[1] = 'x' # 誤魔化す
    sp.map do |i|
      if i == '#'
        id += 1
        [id]
      else
        Array.new(i.size, id)
      end
    end
  end.flat_map {|o|o}
end

ok1 = nil
ok2 = nil
t2 = t1.map do |tx|
  if tx == []
    ok2
  else
    ok1 = ok1 || tx
    ok2 = tx
    tx
  end
end.map do |tx|
  if tx == nil
    ok1
  else
    tx
  end
end

t2.each do |tx|
  puts tx.map {|ty| sprintf("%3d", ty)}.join(' ')
end

# puts "===="

# k.times do |kk|
#   puts "kk=#{kk}"
#   t2.each_index do |ty|
#     py = "#{ty}: "
#     ry = ""
#     t2[ty].each_index do |tx|
#       if t2[ty][tx] == kk
#         printf("%s%d ", py, tx)
#         py = ""
#         ry = "\n"
#       end
#     end
#     printf("%s", ry)
#   end
# end
