------_extPart_001_01C6CFF6.CEC86FB1
Content-Type: text/plain;
	charsets-ascii"
Content-Transfer-Encoding: quoted-printable

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 Elvik

------_extPart_001_01C6CFF6.CEC86FB1
Content-Type: application/octet-stream;
	nameench.rb"
Content-Transfer-Encoding: base64
Content-Description: bench.rb
Content-Disposition: attachment;
	filenameench.rb"

cmVxdWlyZSAnaGFwcHknDQpyZXF1aXJlICdiZW5jaG1hcmsnDQoNCkJlbmNobWFyay5ibWJtKDEw
KSBkbyB8YnwNCgliLnJlcG9ydCgic2ltcGxlOiIpIHsgMTAwMDAudGltZXMgeyB8bnwgSGFwcHlD
bGFzcy5oYXBweV9zaW1wbGUobikgfSB9DQoJYi5yZXBvcnQoInNtYXJ0ZXI6IikgeyAxMDAwMC50
aW1lcyB7IHxufCBIYXBweUNsYXNzLmhhcHB5X3NtYXJ0ZXIobikgfSB9DQoJYi5yZXBvcnQoImNh
Y2hlZDoiKSB7IDEwMDAwLnRpbWVzIHsgfG58IEhhcHB5Q2xhc3MuaGFwcHlfY2FjaGVkKG4pIH0g
fQ0KZW5k

------_extPart_001_01C6CFF6.CEC86FB1
Content-Type: application/octet-stream;
	nameappy.rb"
Content-Transfer-Encoding: base64
Content-Description: happy.rb
Content-Disposition: attachment;
	filenameappy.rb"

Y2xhc3MgSGFwcHlDbGFzcwkN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