3 dices sum that gets 3 or 18 ?

5 views (last 30 days)
rana alamri
rana alamri on 18 Sep 2015
Commented: Walter Roberson on 20 Jan 2021
Given a dice with six numbers ({1, 2, 3, 4, 5, 6}), each number comes with the same probability when you roll it. Suppose you have such THREE dices and you simultaneously roll all of them to get the sum of those three output numbers. When the sum is 3 or 18, you win. Otherwise, you lose. You are so addicted to this game and will not stop until win it once (get 3 or 18 in one play). Let the random variable Y denote the number of plays when you stop playing. You have to repeat the game several times (1000) and plot the histogram of how many times did you tossed the three dice before you reached 3 or 18.
i seriously have no clue how to write the code does it include a loop for it to stop ?
(The following was moved from the Answers section to here)
well that's what i got so far i'm not sure how to do the if statement ?
NumberOfDices = 2;
NumberOfFaces = 6;
NumberOfRoll = 50;
AllRoll = randi(NumFace, NumRoll, NumDice);
SumRoll = sum(AllRoll, 2);
Bins = (NumberOfRoll:NumberOfFaces * NumberOfDices)';
if ( SumRoll == 3 || SumRoll == 18)
end
hist(SumRoll, Bins);
title(sprintf('Histogram generated from %d rolls of %d %d-sided dice', NumRoll, NumDice, NumFace));
xlabel(sprintf('Sum of %d dice', NumDice));
ylabel('Count');
  6 Comments
Walter Roberson
Walter Roberson on 20 Jan 2021
NumberOfDices = 2;
NumberOfFaces = 6;
NumberOfRoll = 50;
NumFace = NumberOfFaces;
NumRoll = NumberOfRoll;
NumDice = NumberOfDices;
AllRoll = randi(NumFace, NumRoll, NumDice);
SumRoll = sum(AllRoll, 2);
Bins = (NumberOfRoll:NumberOfFaces * NumberOfDices)';
if ( SumRoll == 3 || SumRoll == 18)
end
hist(SumRoll, Bins);
title(sprintf('Histogram generated from %d rolls of %d %d-sided dice', NumRoll, NumDice, NumFace));
xlabel(sprintf('Sum of %d dice', NumDice));
ylabel('Count');
But the code has problems.
Walter Roberson
Walter Roberson on 20 Jan 2021
Reminder: user posted the code because it does not work. Do not expect it to work. The version I posted is only intended to get someone past the obvious change of variable names, so that they can get their attention off that part and start thinking about the logic problems with the code.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 17 Oct 2015

I'm attaching a much more interesting dice game. It's between Oppenheimer and Einstein. It uses intransitive dice. Here's a snippet from the attached fascinating puzzle:

% God does not throw dice, Albert Einstein famously declared, but suppose he was wrong. 
% Suppose God decided to demonstrate otherwise by showing up one day at the Institute for Advanced Study. 
% God announces that dice games are in fact wildly popular in heaven, 
% and that the purpose of this visit it to teach a new game to Einstein and J. Robert Oppenheimer. God explains the rules:
% There are three blank dice. First, Oppenheimer will take each of the six-sided dice 
% and write the numbers from 1 to 18, in any order he likes, on the 18 faces of the three dice. 
% Einstein will then examine the dice and select one of them as his own. 
% Oppenheimer will then examine the remaining two dice and select one of them. 
% (The third die will be discarded.) Oppenheimer and Einstein will then play repeated rounds
% of “Dice War” in which they roll the dice simultaneously, with a point being awarded each round 
% to the player who rolls the higher number. The player with the most points wins.
% Assume that Oppenheimer and Einstein employ the smartest possible strategies, 
% and that the outcome will be determined by the laws of probability (meaning that God doesn’t skew the dice 
% or the influence the rolls). Which player, if either, is favored to win?

Of course you could adapt it to do similar Monte Carlo experiments like yours.


Walter Roberson
Walter Roberson on 18 Sep 2015
As this is based upon probability, you cannot determine any upper limit for when an event will first occur. You must therefore use a loop and generate until you find a match, counting as you go. Then store the count. Repeat that 1000 times.

Categories

Find more on Word games in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!