# Happy Numbers (#93)

**URL:** <https://www.ruby-forum.com/t/happy-numbers-93/67470>\
**Category:** Ruby\
**Created:** [September 4, 2006, 2:44pm UTC](https://www.ruby-forum.com/t/happy-numbers-93/67470 "2006-09-04T14:44:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kivle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kivle](https://www.ruby-forum.com/u/kivle)\
**Post date:** [September 4, 2006, 2:44pm UTC](https://www.ruby-forum.com/t/happy-numbers-93/67470/1 "2006-09-04T14:44:15Z")

</div>

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. 🙂

Cheers,  
Helge E.
