solve permutation