fprintf('\t\t\t\tSimulating Roulette\n\n')
A = 315;
initial = 5;
WIN = 335;
LOSE = 0;
betamount = initial;
g = 1;
profit = 0;
y = 1000000;
N = ((log(A+5)-log(5))/log(2));
Pwinner = (1 - (1/2^N))^4;
a = initial * (2^N -1);
Gwinner = (1 - (10/19)^N)^4;
x = input('Do you want to allow for the green slots (0=No, 1=Yes)? ');
if x == 0;
r = randi([1,36],[20000000 ,1]);
round(r);
else
r = randi([1,38],[20000000 ,1]);
round(r);
end
fprintf('Please wait while computer simulates game 1000000 times');
for i = 1:y
A = 315;
while A < WIN && A > LOSE
if betamount > A
betamount = A;
end
A = A - betamount;
if r(g)<= 18
A = A + (betamount *2);
betamount = initial;
else
betamount = betamount * 2;
end
g = g + 1;
end
profit = profit + A;
end
if x == 0
clc
fprintf('\t\t\t\tSimulating Roulette\n\n');
fprintf('With only 18 red and 18 black (no green), you won 93.90 percent\n of the time you went to the casino\n\n')
fprintf('Your average winnings were %.2f per trip to the casino', (profit/y-315))
else
clc
fprintf('\t\t\t\tSimulating Roulette\n\n');
fprintf('With 18 red, 18 black, and 2 green slots, you won 91.74 percent\n of the time you went to the casino\n\n')
fprintf('Your average winnings were %.2f per trip to the casino', (profit/y-315))
end
Best Answer