Finished the permutation sequence function.