Hi,

not much new in this solution, but it's short:

-------------------------------------------------------------
data = [3, 4, 5, 6, 7, 8, 9, 15, 31, 32, 33, 34, 35, 36, 
	37, 38, 39, 40, 41, 6789, 6790, 6791, 9998, 9999, 99999]

p1, p2, ranges = 0, data.size - 1, []

until p1 == data.size
    if data[p2] - data[p1] == p2 - p1
        if ranges.last && ranges.last.end+1 == data[p1]
            ranges[ranges.size-1] = (ranges.last.begin..data[p2])
        else
            ranges << (data[p1]..data[p2]) 
        end
        p1, p2 = p2+1, data.size-1
    else 
        p2 = (p1 + p2) / 2
    end
end

puts ranges 
-------------------------------------------------------------

output:

3..9
15..15
31..41
6789..6791
9998..9999
99999..99999

Simon