Last active
May 29, 2017 08:45
-
-
Save kyanagi/2b3845363873cb0e1bca15d17ab34d3b 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
def run | |
results = [] | |
1.upto(100000) do |i| | |
results.push(rand(2)) | |
results.shift if results.size == 4 | |
if results.size == 3 && results.uniq.size == 1 | |
return i | |
end | |
end | |
end | |
trials = Array.new(10000) { run } | |
require 'enumerable/statistics' | |
p trials.max | |
p trials.mean_stdev | |
p trials.sort[trials.size / 2] | |
p trials.select { |n| n > 20 }.size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment