4 thoughts on “Permutations and derangements

  1. I think you meant “the total number of derangements is 44″. You have 4, not 44.

  2. hi, I really like your algorithm. did you come up with this yourself or is it based on some permutation theorem?

  3. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>