// output of ./demo/comb/perm-gray-ffact2-demo.cc: // Description: //% Generate all permutations in minimal-change order //% via Gray code for falling factorial numbers, loopless algorithm. arg 1: 4 == n [Permutations of n elements.] default=4 0: [ . 1 2 3 ] (3, 2) [ . . . ] 3 -1 [ . 1 2 3 ] 1: [ 1 . 2 3 ] (0, 1) [ 1 . . ] 0 +1 [ 1 . 2 3 ] 2: [ 1 2 . 3 ] (1, 2) [ 2 . . ] 0 +1 [ 2 . 1 3 ] 3: [ 1 2 3 . ] (2, 3) [ 3 . . ] 0 +1 [ 3 . 1 2 ] 4: [ 2 1 3 . ] (0, 1) [ 3 1 . ] 1 +1 [ 3 1 . 2 ] 5: [ 2 1 . 3 ] (3, 2) [ 2 1 . ] 0 -1 [ 2 1 . 3 ] 6: [ 2 . 1 3 ] (2, 1) [ 1 1 . ] 0 -1 [ 1 2 . 3 ] 7: [ . 2 1 3 ] (1, 0) [ . 1 . ] 0 -1 [ . 2 1 3 ] 8: [ . 2 3 1 ] (2, 3) [ . 2 . ] 1 +1 [ . 3 1 2 ] 9: [ 2 . 3 1 ] (0, 1) [ 1 2 . ] 0 +1 [ 1 3 . 2 ] 10: [ 2 3 . 1 ] (1, 2) [ 2 2 . ] 0 +1 [ 2 3 . 1 ] 11: [ 2 3 1 . ] (2, 3) [ 3 2 . ] 0 +1 [ 3 2 . 1 ] 12: [ 3 2 1 . ] (0, 1) [ 3 2 1 ] 2 +1 [ 3 2 1 . ] 13: [ 3 2 . 1 ] (3, 2) [ 2 2 1 ] 0 -1 [ 2 3 1 . ] 14: [ 3 . 2 1 ] (2, 1) [ 1 2 1 ] 0 -1 [ 1 3 2 . ] 15: [ . 3 2 1 ] (1, 0) [ . 2 1 ] 0 -1 [ . 3 2 1 ] 16: [ . 3 1 2 ] (3, 2) [ . 1 1 ] 1 -1 [ . 2 3 1 ] 17: [ 3 . 1 2 ] (0, 1) [ 1 1 1 ] 0 +1 [ 1 2 3 . ] 18: [ 3 1 . 2 ] (1, 2) [ 2 1 1 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