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

30
LINES

< > BotCompany Repo | #1017451 // allCombinations

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2504L/16K).

static <A> IterableIterator<L<A>> allCombinations(final LL<A> base) {
  if (anyListEmpty(base)) ret emptyItIt();
  ret iteratorFromFunction(new F0<L<A>>() {
    final int n = l(base);
    L<Int> l = rep((Int) 0, n);
    
    public L<A> get() {
      if (l == null) null;
      L<A> out = makeList();
      int i = 0;
      while (i < n) {
        int n = l.get(i);
        if (n+1 < l(base.get(i))) {
          l.set(i, n+1);
          break;
        }
        l.set(i++, 0);
      }
      if (i >= n) l = null;
      ret out;
    }
    
    L<A> makeList() {
      L<A> list = emptyList(n);
      for i to n:
        list.add(base.get(i).get(l.get(i)));
      ret list;
    }
  });
}

Author comment

Began life as a copy of #1009424

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1017451
Snippet name: allCombinations
Eternal ID of this version: #1017451/7
Text MD5: 32cf2f6dbf8c2faf3d993391b33bdc76
Transpilation MD5: baffd031477021a8323a98af1d5a8e86
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-21 13:20:58
Source code size: 714 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 458 / 570
Version history: 6 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)