function top = lo_light_chase_top ( L )

%*****************************************************************************80
%
%% lo_slight_chase_top() returns a top button pattern for solution.
%
%  Discussion:
%
%    We assume that an initial Lights Out configuration has had the
%    light chasing algorithm applied to completion, so that the only
%    illuminated lights are in the bottom row.
%
%    This code examines the final row and determines whether the 
%    configuration is solvable.
%
%    If so, it returns a "top vector" and suggests the following 
%    strategy to complete the solution:
%    1) Push buttons in the top row corresponding to the top vector.
%    2) Restart the light chasing algorithm.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 November 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    logical L(5,5): the reduced configuration to check.
%
%  Output:
%
%    logical top[1,5]: the top buttons to push, in order to finish
%    the solution procedure.  If top = [0,0,0,0,0], the configuration
%    is already solved.  If top = [], the configuration is not solvable.
%
  if ( any ( L(1:4,1:5) ) )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'lo_solvable_light_chase(): Fatal error!\n' );
    fprintf ( 1, '  This matrix has not been reduced so that\n' );
    fprintf ( 1, '  the first four rows are entirely zero.\n' );
    error ( 'lo_solvable_light_chase(): Fatal error!\n' );
  end
%
%  Check for a solvable last row.
%
  if ( L(5,1:5) == [ 0, 0, 0, 0, 0 ] )
    top = [ 0, 0, 0, 0, 0 ];
  elseif ( L(5,1:5) == [ 0, 0, 1, 1, 1 ] )
    top = [ 0, 0, 0, 1, 0 ];
  elseif ( L(5,1:5) == [ 0, 1, 0, 1, 0 ] )
    top = [ 0, 1, 0, 0, 1 ];
  elseif ( L(5,1:5) == [ 0, 1, 1, 0, 1 ] )
    top = [ 1, 0, 0, 0, 0 ];
  elseif ( L(5,1:5) == [ 1, 0, 0, 0, 1 ] )
    top = [ 0, 0, 0, 1, 1 ];
  elseif ( L(5,1:5) == [ 1, 0, 1, 1, 0 ] )
    top = [ 0, 0, 0, 0, 1 ];
  elseif ( L(5,1:5) == [ 1, 1, 0, 1, 1 ] )
    top = [ 0, 0, 1, 0, 0 ];
  elseif ( L(5,1:5) == [ 1, 1, 1, 0, 0 ] )
    top = [ 0, 1, 0, 0, 0 ];
  else
    top = [];
  end

  return
end

