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

조회 수: 1 (최근 30일)
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!

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by