function [ d, i, j ] = closest_pair_brute ( z )

%*****************************************************************************80
%
%% closest_pair_brute() finds closest pair of points in 2d using brute force.
%
%  License:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    02 April 2024
%
%  Author:
%
%    Original MATLAB code by Cleve Moler.
%    This version by John Burkardt.
%
%  Reference:
%
%    Cleve Moler,
%    https://blogs.mathworks.com/cleve/2024/03/28/closest-pair-of-points-problem/
%    Closest pair of points problem,
%    28 March 2024.
%
%  Input:
%
%    complex z(n): the X and Y coordinates of the points.
%
%  Output:
%
%    real d: the distance of the closest pair.
%
%    integer i, j: the indices of the closest pair.
%
  n = length ( z );
  d = Inf; 
  i = 0;
  j = 0;

  for i2 = 1 : n
    for j2 = i2 + 1 : n
      d2 = abs ( z(i2) - z(j2) );
      if ( d2 < d )
        d = d2;
        i = i2;
        j = j2;
      end    
    end
  end
end
