1 | sclass SuperPrecise {
|
2 | sclass C {
|
3 | char c; |
4 | bool output; |
5 | |
6 | *() {}
|
7 | *(char *c, bool *output) {}
|
8 | } |
9 | |
10 | S poemID; |
11 | new L<C> script; |
12 | int i = 0; |
13 | bool fail; |
14 | new StringBuilder out; |
15 | |
16 | *(S *poemID) {
|
17 | for (E e : parsePoem(poemID)) {
|
18 | if (e.q != null) |
19 | addInput(e.q + "\n"); |
20 | else if (e.a != null) |
21 | addOutput(e.a + "\n"); |
22 | } |
23 | |
24 | loop(); |
25 | } |
26 | |
27 | // probably remove this |
28 | void loop() {
|
29 | printOut(); |
30 | S line; |
31 | while ((line = readLine()) != null) {
|
32 | for (char c : chars(line + "\n")) |
33 | onIncomingCharacter(c); |
34 | printOut(); |
35 | } |
36 | } |
37 | |
38 | void addOutput(S text) {
|
39 | for (char c : asChars(text)) |
40 | script.add(new C(c, true)); |
41 | } |
42 | |
43 | void addInput(S text) {
|
44 | for (char c : asChars(text)) |
45 | script.add(new C(c, false)); |
46 | } |
47 | |
48 | void onIncomingCharacter(char c) {
|
49 | if (fail || get(script, i) == null) |
50 | charPut('?');
|
51 | else {
|
52 | C x = get(script, i); |
53 | assertFalse(x.output); |
54 | if (c == x.c) {
|
55 | ++i; |
56 | printOut(); |
57 | } else {
|
58 | fail = true; |
59 | charPut('?');
|
60 | } |
61 | } |
62 | } |
63 | |
64 | void printOut() {
|
65 | while (!fail && get(script, i) != null && get(script, i).output) |
66 | charPut(get(script, i++).c); |
67 | //charPut_flush(); |
68 | } |
69 | |
70 | void charPut(char c) {
|
71 | out.append(c); |
72 | } |
73 | } |
Began life as a copy of #1003257
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: | #1003274 |
| Snippet name: | "Super Precise" Engine As Class |
| Eternal ID of this version: | #1003274/1 |
| Text MD5: | d4725039e614212ce70c97014f206e0f |
| 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-13 01:01:18 |
| Source code size: | 1387 bytes / 73 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 810 / 1081 |
| Referenced in: | [show references] |