function idiots2 ( )

%*****************************************************************************80
%
%% idiots2() simulates a duel in which the N-th turn involves N shots.
%
%  Discussion:
%
%    Evaluate the theoretical probability that idiot A
%    wins the duel with idiot B, using the revised duelling rules
%    described in the problem assignment. 
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'idiots2():\n' );
  fprintf ( 1, '  Simulate a Russian-roulette duel between A and B.\n' );
  fprintf ( 1, '  A fires at B one time.\n' );
  fprintf ( 1, '  If A misses, B fires at A two times.\n' );
  fprintf ( 1, '  If B misses, A fires at B three times, and so on.\n' );
  fprintf ( 1, '  Each shot is preceded by spinning the revolver cylinder,\n' );
  fprintf ( 1, '  so there is a 1/6 chance that the revolver will fire.\n' );
  fprintf ( 1, '  Calculate the probability that A survives.\n' );

  S = 0;
  T = 1;
  r = 5 / 6;
  e = 3;
  incr = 7;                    
  startp = 0;
  stopp = 2;

  for k = 1 : 30

    for i = startp : stopp
      S = S + r ^ i;
    end

    M = r ^ e;
    T = T + M * S;
    startp = stopp + 1;
    stopp = startp + 1;
    e = e + incr;
    incr = incr + 4;

  end

  fprintf ( 1, '  Probability that A survives = %14.6g\n', T / 6 );

  return
end

