How to find the number of possible dice/side combinations that equal the number you wish to roll.

1 visualización (últimos 30 días)
function [ prob ] = probdiceroll( nd, no )
% nd = the number of dice with which you are rolling. % no = the number you are wishing to roll. % The output is the probability that you will roll that number.
if no < 1
disp('ERROR')
elseif nd < 1
disp('ERROR')
else
end
ds = 6^(no) ;
% ds = number of sides on the dice
pc = [ ((nd - no) + (no - 1)) ; (no - 1) ] ;
% pc = the number of possible dice/side combinations that equal the number you wish to roll % ^^^ This is where I went wrong ^^^
prob = (pc)/(ds)*100 ;
end
^^^ This is the function I have so far ^^^
How would you find the number of possible combinations that add up to the number you are wishing to roll?
i.e. with 2 dice there are 4 ways to roll a 5 --> (1-4)(4-1)(2-3)(3-2)
or with 3 dice there are 6 ways to roll a 5 --> (1-1-3)(1-3-1)(3-1-1)(2-2-1)(2-1-2)(1-2-2)
or with 4 dice there are 4 ways to roll a 5 --> (1-1-1-2)(1-1-2-1)(1-2-1-1)(2-1-1-1)
or with 5 dice there is one way to roll a 5 --> (1-1-1-1-1)
I think you get the point. :) Thanks for any help you can offer!

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by