Quantcast
Channel: Squirrel Hacker » Code Golf
Viewing all articles
Browse latest Browse all 2

The answer in Ruby (so far)

$
0
0
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

Flattr this!


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images