Roll a 6-sided die until you have rolled a total of 25 6's.

2 Ansichten (letzte 30 Tage)
Colton Baker
Colton Baker am 11 Sep. 2020
Kommentiert: Walter Roberson am 12 Sep. 2020
Hello,
I am trying to wrtie a script to roll randi(6) and loop until it has reached 25 sixes and then count how many rolls it took. Help please.

Akzeptierte Antwort

KSSV
KSSV am 11 Sep. 2020
Bearbeitet: KSSV am 11 Sep. 2020
count = 0 ;
iwant = zeros([],1) ;
i = 0 ;
while count ~= 25
i = i+1 ;
N = randi(6) ;
iwant(i) = N ;
if N == 6
count = count+1 ;
end
end

Weitere Antworten (1)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam am 11 Sep. 2020
find(cumsum(randi(6,1,1000)==6)==25,1)
  3 Kommentare
Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam am 11 Sep. 2020
Bearbeitet: Asad (Mehrzad) Khoddam am 11 Sep. 2020
Yes, you are right. Simply if it happens, you can try again
The probability is 1.536e-48 (it happens once in 6.5e47 tries)
Walter Roberson
Walter Roberson am 12 Sep. 2020
You wouldn't quite just try again... you would have to subtract off the number of 6's that you got up to that point, and you would have to add the number of attempts you already made to the index.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by