%%Matlab code for simulating a world series
function [ win1, win2 ] = worldseries_corrected( p, N )
% p is the probability that the best team (team1) wins
% N is the number of games in the world series--in reality N=7
win1=0; % this is a counter that counts the number of times team 1 (the best team) wins
win2=0; % this is a counter for the number of times team 2 (the worse team) wins
for i=1:N
    if rand(1,1) < p % check to see if a random number is < p
        win1=win1+1; % if it is, increase counter for team 1 by 1
    else
        win2=win2+1; % if not, increase counter for the team 2 by 1
    end
    if (max(win1,win2)>(N/2))
        break;
    end
end

end

