Fixed caluclations. Calculates distance for 1st permutation.