Last active
December 16, 2015 12:09
-
-
Save springaki/5432350 to your computer and use it in GitHub Desktop.
This file contains 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
class Lottery | |
def initialize(winners) | |
@winners = winners | |
@ary = [] | |
end | |
def add(name, weight) | |
@ary += Array.new(weight, name) | |
end | |
def winners | |
winners = [] | |
@winners.times { | |
winners << @ary.at(rand(@ary.size)) | |
} | |
winners | |
end | |
end |
This file contains 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
require './lottery.rb' | |
lottery = Lottery.new(3) | |
lottery.add("John", 1) | |
lottery.add("Tom", 2) | |
lottery.add("Bill", 5) | |
lottery.add("Woz", 2) | |
lottery.add("Ken", 10) | |
lottery.winners |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment