function prob = double_dart ( )

%*****************************************************************************80
%
%% double_dart() analyzes the double dart problem.
%
%  Discussion:
%
%    If two darts land inside the unit circle, what is the probability
%    that they will be at least 1 unit apart?
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  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
%
%  Output:
%
%    real prob, the probability that two darts, landing inside
%    the unit circle, will be at least 1 unit apart.
%
  hits = 0;
  total = 0;
  trial_num = 100000;

  while ( hits < trial_num )

    x1 = -1.0 + 2.0 * rand ( );
    y1 = -1.0 + 2.0 * rand ( );
    d1 = x1^2 + y1^2;

    x2 = -1.0 + 2.0 * rand ( );
    y2 = -1.0 + 2.0 * rand ( );
    d2 = x2^2 + y2^2;

    if ( d1 < 1.0 && d2 < 1.0 )
      hits = hits + 1;
      s = ( x1 - x2 )^2 + ( y1 - y2 )^2;
      if ( 1.0 < s )
        total = total + 1;
      end
    end

  end

  prob = total / hits;

  return
end
