function prob = pp ( p )

%*****************************************************************************80
%
%% pp computes the likelihood of winning at ping pong.
%
%  Discussion:
%
%    A score of 11 wins in ping-pong...except that the winner must be
%    ahead by at least 2 points.  We ignore that exception here.
%    
%    We assume player 1 has a probability p of winning any single point.
%
%    We construct a table T such that T(i,j) is the probability that
%    player 1 will win, given that player 1 needs i more points to win,
%    and player 2 needs j more points to win.  Then T(11,11) is the
%    probability that player 1 wins.
%
%  Modified:
%
%    08 May 2019
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Will You Be Alive 10 Years From Now?,
%    Princeton, 2014,
%    ISBN: 978-0691156804,
%    LC: QA273.25.N344
%
%  Parameters:
%
%    Input, real p, the probability that player 1 wins a single ....
%
%    Output, real prob, the probability that player 1 wins the game.
%
  t = zeros ( 11, 11 );
  for j = 1 : 11
    t(1,j) = 1.0 - ( 1.0 - p )^j;
    t(j,1) = p^j;
  end

  for i = 2 : 11
    for j = 2 : 11
      t(i,j) = p * t(i-1,j) + ( 1.0 - p ) * t(i,j-1);
    end
  end

  prob = t(11,11);

  return
end
