1 | static <A> L<O[]> allPermutations_arrays(L<A> l) { |
2 | int n = factorial(l(l)); |
3 | L<O[]> out = new L(n); |
4 | allPermutations_arrays_impl(cloneList(l), l(l), out); |
5 | ret out; |
6 | } |
7 | |
8 | static <A> void allPermutations_arrays_impl(L<A> l, int n, L<O[]> out) { |
9 | if (n <= 1) { |
10 | ping(); |
11 | out.add(toObjectArray(l)); |
12 | } else for(int i = 0; i < n; i++) { |
13 | allPermutations_arrays_impl(l, n-1, out); |
14 | swapElements(l, n % 2 == 0 ? i : 0, n-1); |
15 | } |
16 | } |
Began life as a copy of #1010320
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: | #1010344 |
Snippet name: | allPermutations_arrays - return all permutations of a list |
Eternal ID of this version: | #1010344/5 |
Text MD5: | 444c7af8dc2df0fe1719603048a7c80b |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-09-12 02:39:40 |
Source code size: | 455 bytes / 16 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 415 / 462 |
Version history: | 4 change(s) |
Referenced in: | [show references] |