function 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?
%
% 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.
%
fprintf ( 1, '\n' );
fprintf ( 1, 'STEVE2:\n' );
fprintf ( 1, ' Steve gets on an elevator going up. There are N higher floors.\n' );
fprintf ( 1, ' Steve wishes to go up 9 floors.\n' );
fprintf ( 1, ' There are K additional riders in the elevator, each of whom has\n' );
fprintf ( 1, ' randomly chosen one of the higher floors as destination.\n' );
fprintf ( 1, ' On average, how many times will the elevator stop until Steve\n' );
fprintf ( 1, ' reaches his floor?\n' );
S = 0;
for loop = 1 : 1000000
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 / 1000000;
T = 1.0 + ( n - 3 ) * ( 1.0 - ( 1.0 - 1.0 / n ) ^ k );
fprintf ( 1, '\n' );
fprintf ( 1, ' Estimated number of stops = %g\n', S );
fprintf ( 1, ' Theoretical number is %g\n', T );
return
end