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

50
LINES

< > BotCompany Repo | #1036338 // UpDownSequence

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

Transpiled version (10309L) is out of date.

persistable sclass UpDownSequence extends RandomAccessAbstractList<UpDown> {
  new BitBuffer moves; // up is true
  
  *(S s) {
    for (c : characters(upper(s)))
      if (c == 'U') add(UpDown.up);
      else if (c == 'D') add(UpDown.down);
  }
  
  public UpDown get(int i) {
    ret UpDown.fromBool(moves.get(i));
  }
  
  public bool add(UpDown move) {
    moves.add(move.bit);
    true;
  }
  
  toString { ret join(countIterator moveChar(size())); }
  
  S moveChar(int i) { ret moves.get(i) ? "U" : "D"; }
  
  public int size() { ret moves.size(); }
  
  void addUp { add(UpDown.up); }
  void addDown { add(UpDown.down); }
  
  static UpDownSequence fromCellNumbers aka fromInts(L<Int> cellNumbers) {
    new UpDownSequence seq;
    if (nempty(cellNumbers)) {
      int cn = first(cellNumbers);
      for (int i = 1; i < l(cellNumbers); i++) {
        int cn2 = cellNumbers.get(i);
        int cn3 = clamp(cn2, cn-10, cn+10);
        while (cn3 > cn) {
          ping();
          ++cn;
          seq.addUp();
        }
        while (cn3 < cn) {
          ping();
          --cn;
          seq.addDown();
        }
        cn = cn2;
      }
    }
    ret seq;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036338
Snippet name: UpDownSequence
Eternal ID of this version: #1036338/15
Text MD5: 6b9f73aac149a4f4b2d3b55e6b24a25d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-11-21 17:35:53
Source code size: 1223 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 93 / 191
Version history: 14 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)