MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayFind 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.

20 correct solutions
20 incorrect solutions

Last solution submitted on Jul 22, 2014

1 Comment