On Tue, Sep 21, 2010 at 12:51 PM, Harry Kakueki <list.push / gmail.com> wrote:
>
> arr = [ '1', '2', '3', '4', '6', '7', '9', 'S1', 'S2' ]
> s = ('1'..'20').to_a + ('S1'..'S5').to_a
>
> t = []
> s.each do |x|
>  >  > 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"]
>
>


A slightly shorter but still unreadable version :-)

r = [ '1', '2', '3', '4', '6', '7', '9', 'S1', 'S2' ]
s = ('1'..'20').to_a + ('S1'..'S5').to_a

p [].tap{|m| s.each {|x| m << (r.include?(x) ? x : "*")}}.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