Find next lexicographic - permutation (permutations as it would occur in a dictionary order).
E.g: nextP('ABCD') = ABDC
If you can generate the next permutation, then you can also generate a 'cycle' of all permutations using a construct like,
cycle = +1;
curr = start;
while ( true )
curr = nextP(curr);
if ( curr == start )
break;
end
cycle = cycle+1;
end
For fun, you could generate all the n! permutations of a, unique n-letter string.
Solution Stats
Problem Comments
2 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers51
Suggested Problems
-
1777 Solvers
-
Return a list sorted by number of consecutive occurrences
427 Solvers
-
1609 Solvers
-
Who has power to do everything in this world?
483 Solvers
-
Remove element(s) from cell array
1976 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
I think test case 6 is wrong. The lexicographic follower of 'xyzDOG' is 'xyzGDO', not 'xyzGOD'.
@Stefan, if you see carefully, test case 6 asks for the *next to next* lexicographic permutation of 'DOG', which is 'GOD'.