Skip to content

Instantly share code, notes, and snippets.

@kyanagi
Last active May 29, 2017 08:45
Show Gist options
  • Save kyanagi/2b3845363873cb0e1bca15d17ab34d3b to your computer and use it in GitHub Desktop.
Save kyanagi/2b3845363873cb0e1bca15d17ab34d3b to your computer and use it in GitHub Desktop.
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