Created
July 6, 2015 16:33
-
-
Save jspc/c21bac6fc772930deaa8 to your computer and use it in GitHub Desktop.
99.95 + 99.95 percent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):072:0* counter = 0 | |
=> 0 | |
irb(main):073:0> iterations = 0 | |
=> 0 | |
irb(main):074:0> 1000000000000.times { iterations += 1 ; counter += 1 if Random.rand(2000) == Random.rand(2000) } | |
^CIRB::Abort: abort then interrupt! | |
from (irb):74:in `call' | |
from (irb):74:in `block in irb_binding' | |
from (irb):74:in `times' | |
from (irb):74 | |
from /usr/bin/irb:11:in `<main>' | |
# The above took about 20 minutes. The 11 trillion iterations it managed should be fine | |
irb(main):075:0> iterations | |
=> 11490861039 | |
irb(main):076:0> counter | |
=> 5745685 | |
irb(main):077:0> 100 - (counter.to_f / iterations.to_f) | |
=> 99.99949997785366 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment