The original intent was not producing only permutation sets, but all possible contained groups and order of elements on the given list (e.g. [1,2,3] would also produce [2,3], [3,2], [3], etc). To achieve that just remove the constraint on the queue size before yielding the value.
I think you meant “the total number of derangements is 44″. You have 4, not 44.
Right! Thanks!
hi, I really like your algorithm. did you come up with this yourself or is it based on some permutation theorem?
It’s my own child.
The original intent was not producing only permutation sets, but all possible contained groups and order of elements on the given list (e.g. [1,2,3] would also produce [2,3], [3,2], [3], etc). To achieve that just remove the constraint on the queue size before yielding the value.