From: Harry Kakueki Date: 2010-09-21T12:53:00+09:00 Subject: Re: An elegant way... On Tue, Sep 21, 2010 at 2:10 AM, F. Senault wrote: > Hello everybody. > >  My > goal is to find sequences in the numbers and join them with dashes : > > > This is not a complete solution but *maybe* it is something worth looking at. It depends on your specs. I'll leave it to you to work out the details. arr = [ '1', '2', '3', '4', '6', '7', '9', 'S1', 'S2' ] s = ('1'..'20').to_a + ('S1'..'S5').to_a t = [] s.each do |x| t << x if arr.include?(x) t << "*" if arr.include?(x) == false end p t.join(" ").split("*").map{|y| y.strip.split(" ")}.select{|z| z.size > 0}.map{|w| "#{w[0]}-#{w[-1]}"} #> ["1-4", "6-7", "9-9", "S1-S2"] Harry