From: "H.Yamamoto" Date: 2004-07-11T17:21:29+09:00 Subject: Re: A little algorithmic help requested... Hello. >[1,2,3,4,6,7,8,11,12,15,16,17] ==> [1..4,6..8,11,12,15..17] > >How would *you* do this? How about this? It seems working. a = [1,2,3,4,6,7,8,11,12,15,16,17] b = [] i = 0 (0..a.size).each do |j| if (j == a.size) || (j - i != a[j] - a[i]) case j - i when 0 when 1 b << a[i] when 2 b << a[i] << a[i+1] else b << (a[i]..a[j-1]) end i = j end end p b # [1..4, 6..8, 11, 12, 15..17]