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

62
LINES

< > BotCompany Repo | #1003283 // class C (character + input/output flag) with functions

JavaX fragment (include)

1  
sclass C {
2  
  char c;
3  
  bool output;
4  
 
5  
  *() {}
6  
  *(char *c, bool *output) {}
7  
  
8  
  public bool equals(O o) {
9  
    ret o instanceof C && c == ((C) o).c && output == ((C) o).output;
10  
  }
11  
  
12  
  public int hashCode() {
13  
    ret (int) c + (output ? 0x1000 : 0);
14  
  }
15  
}
16  
17  
static L<C> poemToC(S poemID) {
18  
  new L<C> l;
19  
  for (E e : parsePoem(poemID))
20  
    if (e.q != null)
21  
      addC(l, e.q + "\n", false);
22  
    else if (e.a != null)
23  
      addC(l, e.a + "\n", true);
24  
  ret l;
25  
}
26  
27  
static void addC(L<C> script, S s, bool output) {
28  
  for (char c : asChars(s))
29  
    script.add(new C(c, output));
30  
}
31  
32  
static L<E> poemFromC(L<C> script) {
33  
  new L<E> l;
34  
  int i = 0;
35  
  while (i < l(script)) {
36  
    new E e;
37  
    int j = poemFromC_scan(script, i, false);
38  
    if (j > i)
39  
      e.q = poemFromC_join(script, i, j);
40  
    else {
41  
      j = poemFromC_scan(script, i, true);
42  
      assertTrue(j > i);
43  
      e.a = poemFromC_join(script, i, j);
44  
    }
45  
    l.add(e);
46  
    i = j;
47  
  }
48  
  ret l;
49  
}
50  
51  
static int poemFromC_scan(L<C> script, int i, bool output) {
52  
  while (i < l(script) && script.get(i).output == output)
53  
    ++i;
54  
  ret i;
55  
}
56  
57  
static S poemFromC_join(L<C> script, int i, int j) {
58  
  new StringBuilder buf;
59  
  for (; i < j; i++)
60  
    buf.append(script.get(i).c);
61  
  ret str(buf);
62  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1003283
Snippet name: class C (character + input/output flag) with functions
Eternal ID of this version: #1003283/1
Text MD5: 7ed6da074296a2baa5d1c6f197614f4c
Author: stefan
Category: javax / talking robots
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-06-15 00:19:55
Source code size: 1304 bytes / 62 lines
Pitched / IR pitched: No / No
Views / Downloads: 454 / 667
Referenced in: [show references]