function derange1_weed_next_test ( )

%*****************************************************************************80
%
%% DERANGE1_WEED_NEXT_TEST tests DERANGE1_WEED_NEXT.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    08 June 2015
%
%  Author:
%
%    John Burkardt
%
  n = 5;
  a = [];
  more = 0;
  maxder = 0;
  numder = 0;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'DERANGE1_WEED_NEXT_TEST\n' );
  fprintf ( 1, '  DERANGE1_WEED_NEXT generates derangements\n' );
  fprintf ( 1, '  by generating ALL permutations, and "weeding out"\n' );
  fprintf ( 1, '  the ones that are not derangements.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Here, we seek all derangements of order N = %d\n', n );
  fprintf ( 1, '\n' );

  rank = 0;
 
  while ( true )

    [ a, more, maxder, numder ] = derange1_weed_next ( n, a, more, ...
      maxder, numder );

    rank = rank + 1;
    fprintf ( 1, '  %2d:', rank );
    for i = 1 : n
      fprintf ( 1, '  %2d', a(i) );
    end
    fprintf ( 1, '\n' );

    if ( ~more )
      break
    end
 
  end

  return
end
