Permutations and derangements

Two snippets to compute permuatations and derangements in Python.

This entry was posted in Math, Python, Snippet. Bookmark the permalink.

4 Responses to Permutations and derangements

  1. Anonymous says:

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

  2. Anonymous says:

    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 *