Generate permutations of a slice in a memory-efficient and deterministic manner, using Heap's algorithm.