def to_ranges d
return unless d && d.size > 0
return [d.first..d.last] if (d.last - d.first).abs==d.size-1
r1, r2 = to_ranges(d[0...(d.size/2)]),
to_ranges(d[(d.size/2)..-1])
return r1+r2 if (r1.last.last - r2.first.first).abs != 1
r1[0..-2]+[r1.last.first..r2.first.last]+r2[1..-1]
end
but than, I'm not sure how the slicing is implemented, so no
assumption about the complexity.
damm, another post
Simon