unfairFlip - annWinsTrial = true; elseif (n == 2...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
% Eric Young % CS 100 M % Script unfairFlip.m % clc c % Intiliaze variables: annWins, bobWins, and # of trials all start at 0 % annWins = 0; bobWins = 0; b trials = 0; t % Outer loop stops when one of them has 5 wins or there have been more than % 30 trials % w annWinsTrial = false; bobWinsTrial = false; % First repetition through loop is Ann; second, Bob for n = 1:2 coinflip1 = rand; % Random number represents coin flip coinflip2 = rand; % Random number represents 2nd flip % If Ann goes and gets two tails, annWinsTrial gets value 1 % Else, if Bob goes and gets HT or TH, bobWinsTrial gets value 1 %
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: annWinsTrial = true; elseif (n == 2 && ((coinflip1 < 2/3 && coinflip2 > 2/3) ||. .. (coinflip1 > 2/3 && coinflip2 < 2/3))) bobWinsTrial = true; end end % If Ann wins and bob doesn't. .Ann gets a win / If Bob wins and Ann % doesn't. ..Bob gets a win % if annWinsTrial && ~bobWinsTrial annWins = annWins + 1; elseif ~annWinsTrial && bobWinsTrial bobWins = bobWins + 1; end % Increase # trials by one trials = trials + 1; end e disp(sprintf('Trials: \t%9d',trials)); disp(sprintf('Times Ann wins: \t%d',annWins)); disp(sprintf('Times Bob wins: \t%d',bobWins));...
View Full Document

Ask a homework question - tutors are online