1 | static IterableIterator<S> allWordsOfAlphabet_fixedLength(fS alphabet, final int length) {
|
2 | ret new IterableIterator<S>() {
|
3 | L<Int> l = rep((Int) 0, length); |
4 | |
5 | public bool hasNext() {
|
6 | ret true; // should change |
7 | } |
8 | |
9 | public S next() {
|
10 | S s = makeString(); |
11 | int i = 0; |
12 | while (i < l(l)) {
|
13 | int n = l.get(i); |
14 | if (n+1 < l(alphabet)) {
|
15 | l.set(i, n+1); |
16 | break; |
17 | } |
18 | l.set(i++, 0); |
19 | } |
20 | if (i >= l(l)) null; |
21 | ret s; |
22 | } |
23 | |
24 | S makeString() {
|
25 | StringBuilder buf = new StringBuilder(l(l)); |
26 | for (int i = 0; i < l(l); i++) |
27 | buf.append(alphabet.charAt(l.get(i))); |
28 | ret str(buf); |
29 | } |
30 | }; |
31 | } |
Began life as a copy of #1004581
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: | #1009424 |
| Snippet name: | allWordsOfAlphabet_fixedLength |
| Eternal ID of this version: | #1009424/3 |
| Text MD5: | 0dbdbbae6cbcd10409e8f400f32c2188 |
| Author: | stefan |
| Category: | javax / a.i. |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-09-06 19:59:32 |
| Source code size: | 740 bytes / 31 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 703 / 750 |
| Version history: | 2 change(s) |
| Referenced in: | [show references] |