1
I did the following program:
class PowerBall
def jogo
brancas = Array.new
50.times{brancas << false}
brancasSorteadas = Array.new
5.times{brancasSorteadas << 0}
for x in brancasSorteadas
j = rand(48) + 1
if brancas[j-1] == false
brancas[j-1] = true
brancasSorteadas[x] = j
else
x -= 1
end
end
for x in brancasSorteadas
puts "A bola branca eh: #{brancasSorteadas[x]}"
end
puts "A bola vermelha eh: #{rand(42)}"
end
end
a = PowerBall.new
a.jogo
His goal is to pull five white balls out of a 49-ball bucket without repetition and pull a red ball out of a 42-ball bucket and repeat some taken from the white bucket.
Only the result is giving the following:
A bola branca eh:
A bola branca eh:38
A bola branca eh:38
A bola branca eh:38
A bola branca eh:38
A bola vermelha eh:numero aleatorio
Varying the number that repeats each time the program is called. Does anyone know where the mistake is?
x
is always0
. It is not the index of the array in the loop, it is each value (and its array only contains zeros). I think it also has logic errors, but start from there.– bfavaretto