Next permutation solved