Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

15
LINES

< > BotCompany Repo | #1010320 // allPermutations - return all permutations of a list

JavaX fragment (include)

static <A> LL<A> allPermutations(L<A> l) {
  new LL<A> out;
  allPermutations_impl(cloneList(l), l(l), out);
  ret out;
}

static <A> void allPermutations_impl(L<A> l, int n, LL<A> out) {
  if (n <= 1) {
    ping();
    out.add(cloneList(l));
  } else for(int i = 0; i < n; i++) {
    allPermutations_impl(l, n-1, out);
    swapElements(l, n % 2 == 0 ? i : 0, n-1);
  }
}

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: 516 / 562
Version history: 1 change(s)
Referenced in: [show references]