function step = combination_lock ( m, n, c )

%*****************************************************************************80
%
%% COMBINATION_LOCK seeks the combination of a lock.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    12 January 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M, the number of dials.
%
%    integer N, the number of symbols on each dial.
%    We assume the symbols are the integers 0 to N-1.
%
%    integer C(M), the combination.
%
%  Output:
%
%    integer STEP, the step on which the combination was found.
%

%
%  Starting with the guess [ 0, 0, ... 0],
%  generate every possible combination, in order, and try it.
%
  more = false;
  a = zeros ( m, 1 );
  step = 0;

  while ( true )
  
    [ a, more ] = combination_next ( m, n, a, more );

    step = step + 1;

    if ( i4vec_eq ( a, c ) )
      i4vec_print ( m, a, '  The combination was found!' );
      return;
    end

    if ( ~ more )
      step = -1;
      return;
    end

  end

end

