Asked by Winnie
on 7 Apr 2019

Find the probability of rolling at least 1 even number using 3 dice. You cannot use any vectors or matrices, or any vectorized operations. Instead, do it using loops. Notice that in each trail, to see if there is at least one even number, there is no need to always inspect the value of each of the dice. No need to inspect the remaining dice as soon as an even number is encountered. Thus a while-loop should be used to handle that part of the problem

I have no idea how to use the while loop in this problem

clear;clc;

nDice = 3; % Number of dice

nTrials = 1e6; % Number of trials

for i = 1:nTrials

end

Answer by Walter Roberson
on 8 Apr 2019

For each trial Initialize dice remaining to 3. While number of dice remaining is positive Decrement dice remaining. roll a die. If it was even add 6 to power of remaining dice to statistics and set dice remaining 0.

After all trials divide statistics by 216 times number of trials.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## A. Sawas (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/454984-probability-of-at-least-1-even-number-using-while-loop#comment_691041

## Guillaume (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/454984-probability-of-at-least-1-even-number-using-while-loop#comment_691045

## John D'Errico (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/454984-probability-of-at-least-1-even-number-using-while-loop#comment_691047

## A. Sawas (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/454984-probability-of-at-least-1-even-number-using-while-loop#comment_691055

## Guillaume (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/454984-probability-of-at-least-1-even-number-using-while-loop#comment_691160

Sign in to comment.