Skip to content

Instantly share code, notes, and snippets.

@connorjclark
Created May 23, 2015 05:09
Show Gist options
  • Save connorjclark/3ab613a959d9c565a976 to your computer and use it in GitHub Desktop.
Save connorjclark/3ab613a959d9c565a976 to your computer and use it in GitHub Desktop.
def play
cards = (-10..10).to_a - [0]
sum = 0
begin
sum += cards.delete_at(rand(cards.length))
end while sum != 0
20 - cards.length
end
num_trials = 100000
average = num_trials.times.map {
play
}.inject(0.0) { |acc, e|
acc + e
} / num_trials
puts average
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment