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