Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Roulette. Write a program, roulette.m. that simulates betting red (or black, or

ID: 3581175 • Letter: R

Question

Roulette. Write a program, roulette.m. that simulates betting red (or black, or even, or odd) each time for N spins of a roulette wheel. The wheel has 38 positions: 18 red. 18 black, 0 and 00 (green). Describe the game using a vector cash; cash(i spin) is the amount of cash you have after i spin-1 spins. The probability of winning on any spin is 18/38 = 47.37%. Start with cash(1)=100 dollars. Set a fixed amount to bet each time, bet Amount. If you have at least that much cash left, bet C dollars on the spin. Payout is 1:1, so if you win. you add bet Amount to your cash; if you lose, subtract it. You cant bet money you dont have. If you dont have betAmount dollars left, you must bet 0 until the game ends. (Or use a while loop to play only until youre broke.) Plot cash as a function of spin number. As in the previous problem, calculate all N spins first, then animate the results, plotting the current value of your cash and the history of your bankroll.

Explanation / Answer

%starting amount ie sm=100 dollars
startAmt = 100
%Initial betting amount
initiaBetAmt = 5
%Condition for winning
WIN = 335
%Condition for lossing
LOSE = 0
profit = 0
g = 0
%Total Number of bets
N = ((log(startAmt+5)-log(5))/log(2))
%Probability of a winning
winner = (1 - (1/2^N))^4
%bidding condition for a loss
a = initiaBetAmt * (2^N -1)
%probability of winning with green slots
greenWinner = (1 - (10/19)^N)^4
x = input('Do you want to allow the green slots (Press 1->Yes/0->No)? ');

if x == 0;

r = randi([1,36],[1000000 ,1]);
round(r)
else
r = randi([1,38],[1000000 ,1]);
round(r)
end
fprintf('Please wait for some time');

%Solution while startAmt < WIN && startAmt > LOSE

g = winner .* r;
round(g);
if g > 18;
startAmt = startAmt - initiaBetAmt
profit = (1/2^N) * startAmt
else
fprintf('Not Working ???? Please try later.Thank you')
end
end