Cody

Problem 604. Next lexicographic - permutation

Solution 92698

Submitted on 26 May 2012 by Richard Zapor
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
x = 'ABCD'; y_correct = 'ABDC'; assert(isequal(nextP(x),y_correct)) x = 'ABDC'; y_correct = 'ACBD'; assert(isequal(nextP(x),y_correct)) x = 'ACBD'; y_correct = 'ACDB'; assert(isequal(nextP(x),y_correct)) x = 'ACDB'; y_correct = 'ADBC'; assert(isequal(nextP(x),y_correct)) x = 'LOVE'; y_correct = 'LVEO'; assert(isequal(nextP(x),y_correct)) x = 'CAST'; y_correct = 'CATS'; assert(isequal(nextP(x),y_correct)) x = 'THEQUICKBROWNFOXJUMPEDOVERTHELAZYDOG'; y_correct = 'THEQUICKBROWNFOXJUMPEDOVERTHELAZYGOD'; assert(isequal(nextP(nextP(x)),y_correct)); s = 1; x = 'ABCDE'; y_correct = 120; y = x; while(1) y = nextP(y); if ( strcmp(x,y) ) break; end s = s+1; end assert(s == y_correct)

Suggested Problems

More from this Author10

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!