% Lecture #0: Monte Carlo % Roll six dice % Count how many times you get 3 of a kind % xxx a b c % xxx aa b Pair3 = 0; for games = 1:1e4 Dice = ceil( 6*rand(1,6) ); Dice = sort(Dice); % check for pairs N = zeros(1,6); for i=1:6 N(i) = sum(Dice == i); end [N,b] = sort(N, 'descend'); if ( (N(1) == 3) & (N(2) < 3)) Pair3 = Pair3 + 1; end end % probability: disp('3 of a kind odds') Pair3 / 1e4