On Dec 4, 2005, at 3:47 PM, Ryan Leavengood wrote:

> On 12/4/05, James Edward Gray II <james / grayproductions.net> wrote:
>>
>> NOW you're talking!  You could just calculate them once and that's
>> the best of both worlds...  ;)
>
> Well I coded this up.

Just so others see the effect of this, here are some timings from  
runs.  The first is Ryan's original code, the second is the new  
version's first (cache-less) run, and the third is the code taking  
advantage of the cache:

Neo:~/Documents/Ruby/Ruby Quiz$ time ruby solutions/Ryan\ Leavengood/ 
weird_numbers.rb 50000
Weird numbers up to and including 50000:
...

real    0m6.258s
user    0m6.170s
sys     0m0.046s
Neo:~/Documents/Ruby/Ruby Quiz$ time ruby solutions/Ryan\ Leavengood/ 
weird_numbers.rb 50000
Weird numbers up to and including 50000:
...
This took 6.231214 seconds

real    0m6.253s
user    0m6.169s
sys     0m0.044s
Neo:~/Documents/Ruby/Ruby Quiz$ time ruby solutions/Ryan\ Leavengood/ 
weird_numbers.rb 50000
Weird numbers up to and including 50000:
...
This took 0.096576 seconds

real    0m0.116s
user    0m0.102s
sys     0m0.011s

James Edward Gray II