  n = 5;

  a = [ 0.0,  3.0,  4.0,  2.0,  7.0;
        3.0,  0.0,  4.0,  6.0,  3.0;
        4.0,  4.0,  0.0,  5.0,  8.0;
        2.0,  6.0,  5.0,  0.0,  6.0;
        7.0,  3.0,  8.0,  6.0,  0.0 ];

  label = [ 'A', 'B', 'C', 'D', 'E' ];

  p = zeros ( 5, 1 );
  dstar = Inf;
  pstar = [];

  while ( true )

    p = next_perm ( p );
    if ( isempty ( p ) )
      break
    end

    d = 0.0;
    i = n;
    for j = 1 : n
      d = d + a(p(i),p(j));
      i = j;
    end

    if ( d < dstar )
      dstar = d;
      pstar = p;
      fprintf ( 1, '  Tour distance reduced to %g\n', d );
    end

  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  DSTAR = %f\n', dstar );
  fprintf ( 1, '  PSTAR = %c %c %c %c %c\n', label(pstar(1:n)) );
