Skip to content

Instantly share code, notes, and snippets.

@zackster
Created November 2, 2017 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackster/5e43023c335737e08422241833ab6f9a to your computer and use it in GitHub Desktop.
Save zackster/5e43023c335737e08422241833ab6f9a to your computer and use it in GitHub Desktop.
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