% % Written by: % -- % John L. Weatherwax 2007-07-01 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- %format rat; numOfTotalBalls = 10; numOfRedBalls = 3; numOfBlackBalls = numOfTotalBalls-numOfRedBalls; cprod=1; adraw=1; while( numOfBlackBalls > 0 ) % this is player A's chance to get red at this stage draw ... pADrawRed = (numOfRedBalls/numOfTotalBalls); % this is player A's chance to get red at this depth in the tree ... p_i(adraw) = cprod*pADrawRed; % to "keep going" A did not draw a RED ball cprod = (1-pADrawRed)*cprod; % update the ball count (A must not have drawn red): numOfBlackBalls=numOfBlackBalls-1; numOfTotalBalls=numOfTotalBalls-1; % calcuate the probability that B draws red: pBDrawRed = numOfRedBalls/numOfTotalBalls; % to "keep going" B did not draw a RED ball cprod = (1-pBDrawRed)*cprod; % update the ball count (B must not have drawn red): numOfBlackBalls=numOfBlackBalls-1; numOfTotalBalls=numOfTotalBalls-1; adraw = adraw+1; end p_i sum( p_i )