function car ( xi, yi )

%*****************************************************************************80
%
%% UMBRELLA simulates the umbrella problem.
%
%  Discussion:
%
%    A person has XI umbrellas at home, and YI at the office.
%    With probability P, it will be raining at any given time.
%    If it is raining, the person takes an umbrella from one place to the other.
%    How many walks will the person take before running out of umbrellas?
%
%  Modified:
%
%    24 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Digital Dice: Computational Solutions to Practical Probability Problems,
%    Princeton, 2008,
%    ISBN: 978-0-691-15821-1.
%
%  Input parameters:
%
%    Input, integer XI, YI, the number of umbrellas at home, and at the office.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'UMBRELLA:\n' );
  fprintf ( 1, '  A person has XI umbrellas at home, and YI at the office.\n' );
  fprintf ( 1, '  With probability P, it will be raining at any given time.\n' );
  fprintf ( 1, '  If it is raining, the person takes an umbrella from one place to the other.\n' );
  fprintf ( 1, '  How many walks will the person take before running out of umbrellas?\n' );
  fprintf ( 1, '  Use graphics to display results.\n' );

  duration = zeros ( 1, 99 );

  for P = 1 : 99
    p = P / 100;
    walk_sum = 0;
    for loop = 1 : 10000
      x = xi;
      y = yi;
      walks = 0;
      location = -1;
      wet = 0;

      while ( wet == 0 )

        if ( rand ( ) > p )

          walks = walks + 1;
          location = - location;

        else

          if ( location == -1 )

            if ( x == 0 )
              walk_sum = walk_sum + walks;
              wet = 1;
            else
              x = x - 1;
              walks = walks + 1;
              y = y + 1;
              location = -location;
            end

          else

            if ( y == 0 )
              walk_sum = walk_sum + walks;
              wet = 1;
            else
              y = y - 1;
              walks = walks + 1;
              x = x + 1;
              location = - location;
            end

          end
        end
      end
    end

    duration(P) = walk_sum / 10000;

  end
%
%  Graphics.
%
  clf
  p = 1 : 99;
  p = p / 100;
  plot ( p, duration, 'linewidth', 3 );
  grid ( 'on' );
  title ( 'UMBRELLA' )
  xlabel ( 'Probability of rain' );
  ylabel ( 'Average number of walks before getting wet' );
  filename = 'umbrella.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  pause ( 5 );

  return
end
