Created
November 2, 2017 19:38
-
-
Save zackster/5e43023c335737e08422241833ab6f9a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
trials = 1000000 | |
events = 0 | |
trials.times do | |
coords = 8.times.map { [rand, rand] } | |
squares = coords.map { |x,y| [(x/0.25).ceil, (y/0.25).ceil] } | |
unless squares.inject(Hash.new(0)) { |total, e| total[e] += 1 ;total}.select{|k,v| v>=3}.count.zero? | |
events += 1 | |
end | |
end | |
puts events.to_f / trials.to_f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment