n=input('enter the number of dice rolls per trial') nt=input('enter the number of trials') A=rand(n,nt)>0.5;%matrix of zeros and ones %each column represents a trial with n coin tosses st=zeros(n,1);% st(ii) how many times a strk of length ii occurs for jj=1:nt %go through each trial wstrklen=0;%local winning streak -changes as go through the n coin tosses for ii= 1:n %through column jj (which is trial jj) if A(ii,jj)==1 wstrklen=wstrklen+1;%keep track of the number of consecutive 1's else % if zero then the winning streak is over if (wstrklen~=0) st(wstrklen)=st(wstrklen)+1;%update the number of times wstrklen has occurred wstrklen=0;%when at zero update this for next set of consecutive ones end end end % if the trial doesn't end in a zero need to still update the number of times wstrklen has occurred. if (wstrklen~=0) st(wstrklen)=st(wstrklen)+1 ; end end av=st/nt