function p = ds ( )

%*****************************************************************************80
%
%% ds analyzes the first Newton dice problem.
%
%  Discussion:
%
%    If we toss a fair die repeatedly, how many tosses will we expect to make
%    until we encounter two consecutive 6's?
%
%  Modified:
%
%    07 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 expected number of tosses until two 6's appear
%    consecutively?
%
  trial_num = 100000;
  person = zeros ( trial_num, 1 );

  check = 1.0 / 6.0;

  for loop = 1 : trial_num

    toss = 1;
    flip2 = 0;
    keeptossing = 1;

    while ( keeptossing == 1 )

      result = rand ( );
      if ( result < check )
        flip1 = 1;
      else
        flip1 = 0;
      end

      if ( flip1 + flip2 == 2 )
        keeptossing = 0;
        person(loop) = toss;
      else
        toss = toss + 1;
        flip2 = flip1;
      end

    end

  end

  p = sum ( person ) / trial_num;

  return
end
