Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
[QUIZ] Happy Numbers (#93)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Phrogz, post: 4525256"] 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) [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
[QUIZ] Happy Numbers (#93)
Top