Heap’s algorithm permutation generator
Historical prologue The Wikipedia article on Heap’s algorithm has been corrected, defaced and corrected again several times since this answer was written. The version referred to by the question and original answer was incorrect; you can see it in Wikipedia’s change history. The current version may or may not be correct; at the time of … Read more