Created
May 22, 2011 15:11
-
-
Save lantoli/985561 to your computer and use it in GitHub Desktop.
Bingo number generation
This file contains hidden or 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 Bingo | |
MAX_NUM = 50 | |
NUMBERS_IN_CARDBOARD = 10 | |
CARDBOARD_IN_GAME = 15 | |
def with_repetitions? cardboard | |
cardboard.inject do |prev, current| | |
return true if prev == current | |
current | |
end | |
false | |
end | |
def cardboard | |
c = NUMBERS_IN_CARDBOARD.times.map { rand(MAX_NUM)+1 }.sort | |
return c unless with_repetitions? c | |
cardboard | |
end | |
def puts_cardboard cardboard | |
cardboard.each { |n| print "#{n}, " } | |
print "\n" | |
end | |
def game | |
CARDBOARD_IN_GAME.times.map { cardboard } | |
end | |
def puts_game game | |
game.each { |cardboard| puts_cardboard cardboard } | |
end | |
end | |
bingo = Bingo.new | |
bingo.puts_game bingo.game |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment