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.
@bmtran, thanks for the improvement :D.
2531 Solvers
Get the area codes from a list of phone numbers
417 Solvers
73 Solvers
157 Solvers
Put two time series onto the same time basis
137 Solvers
Solution 1681640
I have the impression, that the testcase is broken.
My solution runs fine on my computer and fails in Cody.
It even does not give an output (which I usualy get in all other problems). The simple testfunction
function next = nextP(curr)
disp(curr);
next=curr;
end
Does not give an output too. What is the issue? How can I get the thing working?
Thanks for any reply ;-)