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


A slightly shorter but still unreadable version :-)

r =3D [ '1', '2', '3', '4', '6', '7', '9', 'S1', 'S2' ]
s =3D ('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