[QUIZ] Count and Say (#138)

Dude, that's elegant. Thanks for sharing. I particularly like keeping
it as a String, avoiding the performance issues of Bignum for the
truly large.

Your solution scales much, much better than mine after a few
iterations:

                    user system total real
Simon up to 30 0.203000 0.000000 0.203000 ( 0.219000)
Gavin up to 30 0.500000 0.000000 0.500000 ( 0.531000)

Simon up to 32 0.390000 0.000000 0.390000 ( 0.407000)
Gavin up to 32 0.672000 0.000000 0.672000 ( 0.672000)

Simon up to 34 0.485000 0.000000 0.485000 ( 0.484000)
Gavin up to 34 1.578000 0.000000 1.578000 ( 1.579000)

Simon up to 36 0.750000 0.016000 0.766000 ( 0.765000)
Gavin up to 36 4.000000 0.000000 4.000000 ( 4.032000)

Simon up to 38 1.328000 0.000000 1.328000 ( 1.328000)
Gavin up to 38 10.312000 0.094000 10.406000 ( 10.471000)

Simon up to 40 2.500000 0.015000 2.515000 ( 2.531000)
Gavin up to 40 28.016000 0.031000 28.047000 ( 28.270000)

Simon up to 42 4.375000 0.079000 4.454000 ( 4.485000)
Gavin up to 42 80.219000 0.046000 80.265000 ( 81.029000)

···

On Sep 10, 6:23 am, Simon Kröger <SimonKroe...@gmx.de> wrote:

class String
  def look_and_say
    gsub(/(.)\1*/){|s| "#{s.size}#{s[0,1]}"}
  end
end