function p = golf ( )

%*****************************************************************************80
%
%% golf estimates probability golf ball nearer to center than side of square.
%
%  Discussion:
%
%    Estimate the probability that a golf ball, hit into the unit square,
%    is closer to the center of the unit square than to any side.
%
%  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:
%
%    Output, real p, the probability a golf ball randomly landing in the
%    unit square is nearer the center than to any side.
%    Exact value is (4*sqrt(2)-5)/3 = 0.2189514...
%
  total = 0;
  test_num = 10000000;

  for loop = 1 : test_num

    x = rand ( );
    y = rand ( );
    V = [ x, 1.0-x, y, 1.0-y ];
    dedge = min ( V );
    dcenter = sqrt ( ( x - 0.5 )^2 + ( y - 0.5 )^2 );
    if ( dcenter < dedge )
      total = total + 1;
    end

  end

  p = total / test_num;

  return
end
