def hoge(h) loop { s = "" 18.times do s += (rand(26) + ?a.ord).chr end if !h.has_key?(s) h[s] = 1 return s end } end h = {} n = gets.to_i n.times do |i| foo = hoge(h) if i + 1 == n puts "a" + hoge(h) + "n" else puts "a" + hoge(h) + "a" end end