Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- next_permutation = (x) ->
- l = x.length - 1;
- while (l >= 1 and x[l] < x[l - 1])
- l--;
- #console.log(l);
- if (l != 0)
- m = x.length - 1;
- while(m > l - 1 and x[m] < x[l - 1])
- m--;
- [x[m], x[l - 1]] = [x[l - 1], x[m]];
- #console.log(m);
- r = x.length - 1;
- while(l < r)
- [x[l], x[r]] = [x[r], x[l]];
- l++;
- r--;
- return x;
Advertisement