How to solve the permutations problem