Skip to content

Instantly share code, notes, and snippets.

@glauco
Created January 26, 2013 16:04
Show Gist options
  • Save glauco/4643041 to your computer and use it in GitHub Desktop.
Save glauco/4643041 to your computer and use it in GitHub Desktop.
require 'set'
class Lottery
@max = 0
def generate_lottery_cards(amount, numbers_per_game)
games = []
randoms = Random.new
loop do
current_game = Set.new
loop do
current_game << rand(@max)
break if current_game.size == numbers_per_game
end
games << current_game unless games.include? current_game
break if games.size == amount
end
games
end
end
class MegaSena < Lottery
def initialize
@max = 60
end
end
class LotoFacil < Lottery
def initialize
@max = 25
end
end
puts "Mega Sena Games"
mega = MegaSena.new
mega_sena_games = mega.generate_lottery_cards(2, 6)
mega_sena_games.each do |game|
puts game.to_a.sort
puts "---"
end
puts "Loto Facil Games"
loto = LotoFacil.new
loto_facil_games = loto.generate_lottery_cards(2, 6)
loto_facil_games.each do |game|
puts game.to_a.sort
puts "---"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment