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 GNU LGPL license.
#
#  Modified:
#
#    08 February 2023
#
#  Author:
#
#    Original MATLAB version by Paul Nahin.
#    This version by John Burkardt.
#
#  Reference:
#
#    Paul Nahin,
#    Dueling Idiots and Other Probability Puzzlers,
#    Princeton, 2012,
#    ISBN: 978-0691155005.
#
  print ( '' )
  print ( 'idiots2():' )
  print ( '  Simulate a Russian-roulette duel between A and B.' )
  print ( '  A fires at B one time.' )
  print ( '  If A misses, B fires at A two times.' )
  print ( '  If B misses, A fires at B three times, and so on.' )
  print ( '  Each shot is preceded by spinning the revolver cylinder,' )
  print ( '  so there is a 1/6 chance that the revolver will fire.' )
  print ( '  Calculate the probability that A survives.' )

  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

  print ( '  Probability that A survives = ', T / 6 )

  return
end

