[SOLUTION] Happy Numbers (#93)

Hi,

Here's my solution to this weeks problem. I haven't done the "extra
credit" work to make it work with different bases, but I have done a bit
of work to maybe make the method a bit faster (by caching some results).
Here's the benchmark for my different solutions calculating all happy
values from 0-10000:

Rehearsal ---------------------------------------------
simple: 4.032000 0.000000 4.032000 ( 4.032000)
smarter: 1.984000 0.000000 1.984000 ( 2.000000)
cached: 1.125000 0.000000 1.125000 ( 1.125000)
------------------------------------ total: 7.141000sec

                user system total real
simple: 4.016000 0.000000 4.016000 ( 4.015000)
smarter: 1.969000 0.000000 1.969000 ( 1.969000)
cached: 1.187000 0.000000 1.187000 ( 1.187000)

I might look into making this support different bases as well if I get
the time.

Fun quiz. :slight_smile:

Cheers,
Helge Elvik

bench.rb (291 Bytes)

happy.rb (2.54 KB)