Add function to calculate a permutation