Libraryless. Click here for Pure Java version (2504L/16K).
1 | static <A> IterableIterator<L<A>> allCombinations(final LL<A> base) { |
2 | if (anyListEmpty(base)) ret emptyItIt(); |
3 | ret iteratorFromFunction(new F0<L<A>>() { |
4 | final int n = l(base); |
5 | L<Int> l = rep((Int) 0, n); |
6 | |
7 | public L<A> get() { |
8 | if (l == null) null; |
9 | L<A> out = makeList(); |
10 | int i = 0; |
11 | while (i < n) { |
12 | int n = l.get(i); |
13 | if (n+1 < l(base.get(i))) { |
14 | l.set(i, n+1); |
15 | break; |
16 | } |
17 | l.set(i++, 0); |
18 | } |
19 | if (i >= n) l = null; |
20 | ret out; |
21 | } |
22 | |
23 | L<A> makeList() { |
24 | L<A> list = emptyList(n); |
25 | for i to n: |
26 | list.add(base.get(i).get(l.get(i))); |
27 | ret list; |
28 | } |
29 | }); |
30 | } |
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: | 459 / 571 |
Version history: | 6 change(s) |
Referenced in: | [show references] |