Efficient iterator for permutations and combinations