function found = strategy4 ( locker_num, locker_value, player_num, try_max )

%*****************************************************************************80
%
%% strategy4() uses strategy #4 on the locker problem.
%
%  Discussion:
%
%    Strategy 1 used a completely random list of lockers.
%    Strategy 2 uses a list that is random, except that there are no duplicates.
%    Strategy 3 starts at the player's own locker, then to the locker 
%      "pointed to" by the wallet inside, and so on.
%    Strategy 4 starts at a random locker, then to the locker 
%      "pointed to" by the wallet inside, and so on.
%
%    Surprisingly, strategy 4 is very bad.  It is WORSE than strategy 2.
%    That might seem impossible until you realize that the player may easily
%    end up in a "short loop" that does not include his wallet, and hence 
%    in 50 searches may actually only view far fewer distinct wallets.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    18 December 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer locker_num: the number of lockers.
%
%    integer locker_value(locker_num): the number stored in each locker.
%
%    integer player_num: the number of players.
%
%    integer try_max: the maximum number of tries allowed.
%
%  Output:
%
%    integer found: the number of wallets that were found.
%
  if ( locker_num < try_max )
    try_max = locker_num;
  end

  found = 0;

  for player = 1 : player_num

    locker = randi ( [ 1, locker_num ], 1 );

    for trial = 1 : try_max
      if ( locker_value(locker) == player )
        found = found + 1;
        break
      end
      locker = locker_value(locker);
    end

  end

  return
end

