Last active
December 30, 2015 12:09
-
-
Save dliberalesso/7827289 to your computer and use it in GitHub Desktop.
Gera um array contendo números para apostar na Mega-Sena.
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
#!/usr/local/bin/ruby -w | |
class Mega | |
attr_reader :apostas | |
def initialize(n = 6, l = 1) | |
@l = l | |
@n = n | |
@apostas = Array.new | |
apostar | |
jogos | |
end | |
private | |
def random(aposta) | |
r = rand(1..60) | |
aposta.include?(r) ? (random) : (aposta << r) | |
end | |
def sortear | |
aposta = Array.new | |
@n.times { random(aposta) } | |
aposta.sort! | |
aposta.map { |a| "%02d" % a } | |
end | |
def apostar | |
@l.times { @apostas << sortear } | |
end | |
public | |
def jogos | |
@l.times { |i| puts @apostas[i - 1].join(', ') } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment