From: Phrogz Date: 2006-09-02T04:35:40+09:00 Subject: Re: Happy Numbers (#93) Although others are sure to have better results, I thought I'd post mine (no spoilers). I did it a simple way first, and then another more sophisticated way second. Nice speed improvement. The below tests 1000 numbers for happiness in 33 different bases. range = 1..1000 require 'Benchmark' Benchmark.bm(20){ |r| r.report( "Technique 1" ){ 3.upto(36){ |base| range.select{ |i| # find out if 'i' is a happy number in the supplied base } } } r.report( "Technique 2" ){ 3.upto(36){ |base| range.select{ |i| # find out if 'i' is a happy number in the supplied base } } } } user system total real Technique 1 19.282000 0.031000 19.313000 ( 19.359000) Technique 2 2.140000 0.000000 2.140000 ( 2.156000)