Skip to content

Instantly share code, notes, and snippets.

@bentona
Created October 24, 2016 21:36
Show Gist options
  • Save bentona/de4437379257aad55c65e302f17de821 to your computer and use it in GitHub Desktop.
Save bentona/de4437379257aad55c65e302f17de821 to your computer and use it in GitHub Desktop.
Simulation to determine (roughly) odds of getting all sour patch kids colors in a pack.
class Pack
attr_accessor :pieces
COLORS = [:blue, :green, :yellow, :red]
def initialize
@pieces = (1..6).map{|_| COLORS.sample }
end
def has_all?
COLORS.all?{|c| @pieces.include?(c) }
end
end
(1..10000).map{|_| Pack.new.has_all? }.select{|x| x}.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment