function [ S, T ] = steve2 ( k, n )

%*****************************************************************************80
%
%% steve2(): Steve's elevator problem.
%
%  Discussion:
%
%    Steve gets on an elevator going up.  There are N higher floors.
%    Steve wishes to go up 9 floors.
%    There are K additional riders in the elevator, each of whom has
%    randomly chosen one of the N higher floors as destination.
%
%    On average, how many times will the elevator stop until Steve
%    reaches his floor?
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  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
%
%  Input:
%
%    integer K, the number of elevator riders in addition to Steve.
%
%    integer N, the nuber of floors.
%
%  Output:
%
%    real S: the estimated number of stops.
%
%    real T: the theoretical number of stops.
%
  trial_num = 100000;
  S = 0;

  for loop = 1 : trial_num

    x = zeros ( 1, n );
    x(9) = 1;
    for j = 1 : k
      rider = floor ( n * rand ( ) ) + 1;
      x(rider) = 1;
    end

    stops = 1;
    for j = 1 : 8
      stops = stops + x(j);
    end

    S = S + stops;

  end

  S = S / trial_num;

  T = 1.0 + ( n - 3 ) * ( 1.0 - ( 1.0 - 1.0 / n ) ^ k );

  return
end
