Libraryless. Click here for Pure Java version (5631L/31K).
srecord noeq LexicographicIterator(S alphabet) extends ItIt<S> { new IntBuffer l; *(S *alphabet, int minLength) { repeat minLength { l.add(0); } } public bool hasNext() { ret true; // haha! } public S next() { S s = makeString(); int i = 0; while (i < l(l)) { int n = l.get(i); if (n+1 < l(alphabet)) { l.set(i, n+1); break; } l.set(i++, 0); } if (i >= l(l)) l.add(0); ret s; } S makeString() { int n = l(l); char[] chars = new[n]; for i to n: chars[i] = alphabet.charAt(l.get(i)); ret str(chars); } }
Began life as a copy of #1004581
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1034542 |
| Snippet name: | LexicographicIterator |
| Eternal ID of this version: | #1034542/2 |
| Text MD5: | dc4b9e3bc65ff8de05f7bf5ac532fdcf |
| Transpilation MD5: | cf6896d60e8da81a8ca145cb7a9606e4 |
| Author: | stefan |
| Category: | javax / a.i. |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-02-11 21:53:20 |
| Source code size: | 658 bytes / 34 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 564 / 696 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |