function demere1(numreps) % demere1(n) finds the number of rolls until we get a 6 and records the % the number of rolls. It repeats n times and displays the proportion of % times the number was at most 4. % % It also shows a plot of how many times a given number of rolls was % required to get a 6. reps=numreps; rec=NaN(1,reps); % where we'll keep the record for k=1:reps n=0; gotit=false; while not(gotit) n=n+1; % one more roll roll=ceil(6*rand); if roll==6 gotit=true; end end rec(k)=n; end plot(sort(rec)) hold on plot([1 reps],[4 4],'--m') hold off disp(['The proportion of trials with a 6 in the first 4 rolls is ', num2str(length(find(rec<=4))/reps)])