Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- class Card
- attr_reader :name
- def initialize(name)
- @name = name
- end
- def to_s()
- "<Card #{@name}>"
- end
- end
- class Deck
- def initialize()
- @cards = Array.new
- end
- def add(card)
- @cards << card
- end
- def draw_random_five()
- return @cards.shuffle()[0..4]
- end
- end
- myDeck = Deck.new()
- 3.times { myDeck.add(Card.new("Forge")) }
- 3.times { myDeck.add(Card.new("Duchy")) }
- 3.times { myDeck.add(Card.new("Gold")) }
- 6.times { myDeck.add(Card.new("Other")) }
- matches = 0
- iterations = 1000000
- iterations.times do
- hand = myDeck.draw_random_five()
- num_forge = hand.count { |c| c.name == "Forge" }
- num_duchy = hand.count { |c| c.name == "Duchy" }
- num_gold = hand.count { |c| c.name == "Gold" }
- matches += 1 if num_forge>0 and num_duchy>0 and num_gold>0
- end
- puts "#{100*matches.to_f/iterations.to_f}%"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement