I am trying to figure out the best way to write some JSL to enumerate all the permutations of a vector or list.
One algorithm I've found, that looks promising, is Heap's Algorithm https://en.wikipedia.org/wiki/Heap%27s_algorithm , but I just can't seem to figure out how to code this up. Can someone help me out here?
I realize that the larger the size of a vector or list, the size of the output would grow factorially (number of permutations of k items is k! ), so I'm also interested in a way to generate each item in the list of permutations and do an operation on that permutation and then discard it when it is no longer needed to generate the next permutation(s).