Iterative all_permutations