% MCAS Problem 37 example;
die=[-15 -10 -5 5 10 15];
% m.file based on LMex020202.m
% Larsen & Marx (2001) Example 2.2.2, page 24 Figure 2.2.1
% tile die down 6 times
a=repmat(die,6,1)  % repmat is a built-in function
b=repmat(die',1,6)
c=a+b
[d,e]=size(c)
% Probability of rolling a zero with 2 dice:
i=find(c==0)
length(i)
P=length(i)/(d*e)
format rat; P
format
% Monte Carlo simulation
% note that it has length 6;
success=0;trials=10000;
for i=1:trials
  [temp1,i]=sort(rand(1,6)); % shuffles 1 to 6 in vector i
  [temp1,j]=sort(rand(1,6)); % shuffles 1 to 6 in vector j
  if die(i(1))+die(j(1))==0
      success=success+1;
  end
end
success/trials
