Solved Permutation problem with an iterative method