S
Semih Ozkoseoglu
One problem that I can see is that you're allowing your random betting
Hi everyone,
After I changed the code as Paul's note above the code started to
create identical results for both bet_rand and bet_red.
Thanks to everyone who helped. Its much appreciated.
The new code reads as this:
colors = {}
[2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33,
35].each do |i|
colors = :black
end
[1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36].each
do |i|
colors = :red
end
colors[0] = :zero
bet_rand = 0
bet_red = 0
puts 'How many rolls to simulate'
number_of_rolls = gets.chomp.to_i
number_of_rolls.times do
number_01 = rand(37)
color_01 = colors[number_01]
number_02 = rand(37)
if number_02 == [:red, :black]
color_02 = colors[number_02]
else
color_02 = :red
end
if color_01 == :red
bet_red += 1
else
bet_red -= 1
end
if color_02 == color_01
bet_rand += 1
else
bet_rand -= 1
end
end
puts bet_rand
puts bet_red
strategy to pick 0, rather than red or black, which I don't think is
your intention.
Change
number_02 = rand(37)
color_02 = colors[number_02]
to
color_02 = [:red, :black][rand(2)]
Hi everyone,
After I changed the code as Paul's note above the code started to
create identical results for both bet_rand and bet_red.
Thanks to everyone who helped. Its much appreciated.
The new code reads as this:
colors = {}
[2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33,
35].each do |i|
colors = :black
end
[1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36].each
do |i|
colors = :red
end
colors[0] = :zero
bet_rand = 0
bet_red = 0
puts 'How many rolls to simulate'
number_of_rolls = gets.chomp.to_i
number_of_rolls.times do
number_01 = rand(37)
color_01 = colors[number_01]
number_02 = rand(37)
if number_02 == [:red, :black]
color_02 = colors[number_02]
else
color_02 = :red
end
if color_01 == :red
bet_red += 1
else
bet_red -= 1
end
if color_02 == color_01
bet_rand += 1
else
bet_rand -= 1
end
end
puts bet_rand
puts bet_red