Skip to content

Instantly share code, notes, and snippets.

@lantoli
Created May 22, 2011 15:11
Show Gist options
  • Save lantoli/985561 to your computer and use it in GitHub Desktop.
Save lantoli/985561 to your computer and use it in GitHub Desktop.
Bingo number generation
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