The answer in Ruby (so far)

a = [1,2,3,5,7,8,9,10,12,13,19,200,900,901,902,903,904,905,1000]
l = a[0]
f = a[0]
z = a.length
i = 0
s = ""
until i == z
  if (a[i]+1 == a[i+1])
    l = a[i+1]
  end
  if (a[i]+1 != a[i+1])
    if f == l
      s = s+"#{f}"
      if i+1 != z
        s = s+","
      end
  end
  if f != l
        s = s+"#{f}=>#{l}"
        if i+1 != z
          s = s+","
        end
    end
    f = a[i+1]
    l = f
  end
  i+=1
end

puts s
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: