1 | static <A> LL<A> allPermutations(L<A> l) { |
2 | new LL<A> out; |
3 | allPermutations_impl(cloneList(l), l(l), out); |
4 | ret out; |
5 | } |
6 | |
7 | static <A> void allPermutations_impl(L<A> l, int n, LL<A> out) { |
8 | if (n <= 1) { |
9 | ping(); |
10 | out.add(cloneList(l)); |
11 | } else for(int i = 0; i < n; i++) { |
12 | allPermutations_impl(l, n-1, out); |
13 | swapElements(l, n % 2 == 0 ? i : 0, n-1); |
14 | } |
15 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1010320 |
Snippet name: | allPermutations - return all permutations of a list |
Eternal ID of this version: | #1010320/2 |
Text MD5: | cbd1e9f43a2e184121c53ebd46923031 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-09-11 20:59:25 |
Source code size: | 385 bytes / 15 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 517 / 563 |
Version history: | 1 change(s) |
Referenced in: | [show references] |