Y 6. Roulette. Write a program, roulette. m, that simulates betting red (or blac
ID: 3571810 • Letter: Y
Question
Y 6. 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 Cispin) is the amount of cash you have after i spin-1 spins. e Start with cash (1) 100 dollars. Set a fixed amount to bet each time, betAmount. 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 betAmount to your cash: if you lose, subtract it. You can't bet money you don't have. If you don't have betAmount dollars left, you must bet 0 until the game ends. (Or use a while loop to play only until you're broke.) Plot cash as a function of in number. As in the previous problem, calculate all N spins first, then animate the results, plotting the current value 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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.