Mauricio Fern?ndez <batsman.geo / yahoo.com> writes:

>> a.each_index{|i|a[i..j=i+2]==[x=a[i],x+1,x+2]and(0while a[j]+1==a[j+=1];a[i..j-=1]=a[i]..a[j])}
>
> Golfing a bit on #ruby-lang, exoticorn & I got
>
> s=[];a.map{|x|(l=s[-1])&&x-l[-1]<2?l<<x:s<<[x]};s.map{|f|f[2]?f[0]..f[-1]:f}.flatten
>
> Note that whereas your solution is in-place, this one creates a new
> array. It is easier to specify the minimum range size, too.

Nice!  The "(l=s[-1])&&x-l[-1]<2" bit is quite clever.  Using it (and
a few other tweaks) I can get mine down to:

i=0;a.map{a[j=i+2]&&a[j]-a[i]<3&&(j+=1while a[j+1]==1+x=a[j];a[i..j]=a[i]..x);i+=1}

But yeah, in-place isn't how I'd normally do it.