Transpiled version (10309L) is out of date.
1 | persistable sclass UpDownSequence extends RandomAccessAbstractList<UpDown> { |
2 | new BitBuffer moves; // up is true |
3 | |
4 | *(S s) { |
5 | for (c : characters(upper(s))) |
6 | if (c == 'U') add(UpDown.up); |
7 | else if (c == 'D') add(UpDown.down); |
8 | } |
9 | |
10 | public UpDown get(int i) { |
11 | ret UpDown.fromBool(moves.get(i)); |
12 | } |
13 | |
14 | public bool add(UpDown move) { |
15 | moves.add(move.bit); |
16 | true; |
17 | } |
18 | |
19 | toString { ret join(countIterator moveChar(size())); } |
20 | |
21 | S moveChar(int i) { ret moves.get(i) ? "U" : "D"; } |
22 | |
23 | public int size() { ret moves.size(); } |
24 | |
25 | void addUp { add(UpDown.up); } |
26 | void addDown { add(UpDown.down); } |
27 | |
28 | static UpDownSequence fromCellNumbers aka fromInts(L<Int> cellNumbers) { |
29 | new UpDownSequence seq; |
30 | if (nempty(cellNumbers)) { |
31 | int cn = first(cellNumbers); |
32 | for (int i = 1; i < l(cellNumbers); i++) { |
33 | int cn2 = cellNumbers.get(i); |
34 | int cn3 = clamp(cn2, cn-10, cn+10); |
35 | while (cn3 > cn) { |
36 | ping(); |
37 | ++cn; |
38 | seq.addUp(); |
39 | } |
40 | while (cn3 < cn) { |
41 | ping(); |
42 | --cn; |
43 | seq.addDown(); |
44 | } |
45 | cn = cn2; |
46 | } |
47 | } |
48 | ret seq; |
49 | } |
50 | } |
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: | 146 / 275 |
Version history: | 14 change(s) |
Referenced in: | [show references] |