• + 72 comments

    Here is a good explanation of a next lexicographical permutation algorithm:

    http://www.nayuki.io/page/next-lexicographical-permutation-algorithm