Problem 11.18
Nasser Abbasi
Used matlab rand to generate a uniform deviate random numbers between [0,1), then used the inversion method to map the number of a die value.
Ran the program two times. One for a loaded die, and one for a non loaded die. Each time I played 100,000 games. Before starting each run, I reset the matlab random number generator. This is the result
Loaded Die? |
Number of games |
Total number of throws |
Average number of throws per game |
Probability of winning |
Probability of 10 throws without hitting mark |
NO |
100,000 |
339,928 |
3.40657 |
0.46472 |
0.03566 |
YES |
100,000 |
323,375 |
3.23375 |
0.44257 |
0.02905 |
First of all, the probability of winning in both cases is less than 50% (which makes sense, sine otherwise the casinos in Las Vegas will not have this game to play for they will lose money).
When the die is loaded, the probability of winning is less. (this makes sense since the numbers 1 and 6 and loaded, then the chance of hitting total of 7 at each throw after the first throw is more likely, hence the chance of losing is higher). But the chance of hitting a 7 on the first throw is higher also, but on balance the loaded die made the chance of winning a little less.
Also with a loaded die, there is less probability of making 10 throws without hitting the mark (this is becuase a load die made the probability of hitting a 7 more, so less chance of getting to 10 throws before losing).
» nma_problem_11_18
Enter number of games to play (suggest 100,000):100000
Use a loaded die? (for part d)? [0=NO, 1=YES]0
number of games=100000
Total number of throws made=340657
Average number of throws per game = 3.406570
probability of winning = 0.464720
Probability of 10 throws without hitting mark = 0.035660
» nma_problem_11_18
Enter number of games to play (suggest 100,000):100000
Use a loaded die? (for part d)? [0=NO, 1=YES]1
number of games=100000
Total number of throws made=323375
Average number of throws per game = 3.233750
probability of winning = 0.442570
Probability of 10 throws without hitting mark = 0.029050
»
code:
function nma_problem_11_18()
%
% solve
problem 11.18 in book
% Nasser
Abbasi
%
rand('state',0);
fprintf('\n');
numberOfGames = input('Enter
number of games to play (suggest 100,000):');
loadedDie = input('Use
a loaded die? (for part d)? [0=NO, 1=YES]');
totalNumberOfWins = 0;
totalNumberOfThrows = 0;
totalNumberOfTenThrows =
0;
averageNumberOfThrowsPerGame
= 0;
for(gameNumber=1:numberOfGames)
currentGameNumberOfThrows = 0;
v1 = throwOneDice(loadedDie);
v2 =
throwOneDice(loadedDie);
currentGameNumberOfThrows = currentGameNumberOfThrows + 1;
mark = v1+v2;
%fprintf('Throw number %d
is=%d\n',i,mark);
if(mark == 7 | mark == 11)
totalNumberOfWins = totalNumberOfWins + 1;
% fprintf('you won!\n');
else
keepPlaying = 1;
while(keepPlaying)
v1 = throwOneDice(loadedDie);
v2 = throwOneDice(loadedDie);
currentGameNumberOfThrows = currentGameNumberOfThrows
+ 1;
currentScore = v1+v2;
%fprintf('Throw
number %d is=%d\n',i,currentScore);
if( currentScore ==
mark )
%fprintf('You
won!\n');
totalNumberOfWins = totalNumberOfWins + 1;
keepPlaying = 0;
else
if( currentScore
==7 | currentScore==11)
%fprintf('You
lose!\n');
keepPlaying = 0; % lost
end
end
end % while(keepPLaying)
end
totalNumberOfThrows = totalNumberOfThrows +
currentGameNumberOfThrows;
if( currentGameNumberOfThrows
>= 10 )
totalNumberOfTenThrows = totalNumberOfTenThrows + 1;
end
end
averageNumberOfThrowsPerGame
= totalNumberOfThrows / numberOfGames;
probabilityOfWinning = totalNumberOfWins / numberOfGames;
fprintf('number of games=%d\n',numberOfGames);
fprintf('Total number of throws made=%d\n',totalNumberOfThrows);
fprintf('Average number of throws per game = %f\n',...
averageNumberOfThrowsPerGame);
fprintf('probability of winning = %f\n',...
probabilityOfWinning);
fprintf('Probability of 10 throws without hitting mark = %f\n',...
totalNumberOfTenThrows / numberOfGames);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% throws
one die. loadedDie is a flag. if 1 then
% biased
die, 1 or 6 twice as likely as anyother number.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function v=throwOneDice(loadedDie)
%Not
sure how to do the loaded die part, the best I
%can
come up with is this:
%
%for a
fair die, each number have a change of 1/6 of comming
%out. So
to make the 6 or 1 come out twice as much, assume we
%have a
die with 8 faces instead of six (one additial imaginary
%face
which is an duplicate of a 6 face or a duplicate of a 1 face.
%let the
image for 6 be the number 7 and let the image of 1 be
%the
number 8. So now throw this imaginary die, and if the
%number
that comes out is an 8 or 1, we return 1. If the number
%that
comes out is a 6 or 7, we return 6.
%if the
number that comes out is not a 7 nor an 8, we just return it as is.
%This
makes 1 and 6 appear to come out twice as likely as the others.
if(loadedDie)
v= ceil(8*rand(1)); % notice 8
faces.
if(v==8)
v=1;
else
if(v==7)
v=6;
end
end
else
v= ceil(6*rand(1)); % notice 6 faces
end