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.
%
%    For a geometric solution, it is important to know that the curve
%    of equal distance between a point and a line is a parabola.  Disect
%    the square into 4 triangles with the origin at the apex, and focus
%    on one triangle.  Determine the equation of the parabola.  Work out
%    the area of the piece of the triangle that is above the parabola.
%    Your answer will follow.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    10 January 2022
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Will You Be Alive 10 Years From Now?,
%    Princeton, 2014,
%    ISBN: 978-0691156804,
%    LC: QA273.25.N344
%
%  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;
  trial_num = 100000;

  for loop = 1 : trial_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 / trial_num;

  return
end
