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

31
LINES

< > BotCompany Repo | #1030505 // allWordsOfAlphabet_maxLength

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

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

1  
static ItIt<S> allWordsOfAlphabet_maxLength(int maxLength, S alphabet) {
2  
  ret new ItIt<S>() {
3  
    new L<Int> l;
4  
    
5  
    public bool hasNext() {
6  
      ret l(l) <= maxLength;
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)) l.add(0);
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  
}

Author comment

Began life as a copy of #1004581

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030505
Snippet name: allWordsOfAlphabet_maxLength
Eternal ID of this version: #1030505/1
Text MD5: cdbd7b3ffd16ec69e1a1f12c3ee0e055
Transpilation MD5: c44dba064d9223c63e7932e72c8432c9
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-01-02 17:31:17
Source code size: 691 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 126 / 182
Referenced in: [show references]