function bulb ( n )

#*****************************************************************************80
#
## bulb() analyzes the light bulb problem.
#
#  Discussion:
#
#    This code calculates and plots the probability of a bulb,
#    wired in series/parallel with sheets of switches, glowing.
#
#  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.
#
#  Input:
#
#    integer N, the number of switches.
#
  print ( '' )
  print ( 'bulb():' )
  print ( '  Calculate and plot the probability of a bulb glowing,' )
  print ( '  wired in series/parallel with ', n, 'sheets of switches.' )

  for p = 1 : 200
    r = p / 200
    P1(p) = ( 1 - ( 1 - r ** n ) ** n ) ** n
    P2(p) = 1 - ( ( 1 - r ** n ) ** ( n * n ) )
  end
#
#  Graphics.
#
  clf ( )
  r = .005 : .005 : 1
  plot(r,P1,'-',r,P2,'.')
  grid ( 'on' )
  title('Solid Line for Series Sheets, Dots for Parallel Sheets')
  xlabel('probability, p, an individual switch is closed')
  ylabel('probability bulb glows, P(10,p)')
  filename = 'bulb.png'
  plt.savefig ( filename )
  print ( '  Graphics saved as "' + filename + '"' )
  plt.close ( )

  return
