Libraryless. Click here for Pure Java version (1987L/12K/42K).
1 | !752 |
2 | |
3 | !include #1002461 // Source |
4 | |
5 | static class TuringQuestion { |
6 | S id; |
7 | S question; |
8 | S answer; |
9 | Source source; |
10 | int level; // difficulty level, 1 or higher (0 means 1) |
11 | } |
12 | |
13 | // validate or invalidate a question |
14 | static class Val { |
15 | S id; // turing question id |
16 | boolean value; |
17 | Source source; |
18 | |
19 | *() {} |
20 | *(S *id, boolean *value, Source *source) {} |
21 | } |
22 | |
23 | static new L<TuringQuestion> questions; |
24 | static long nextID = 1; |
25 | static new L<Val> vals; |
26 | |
27 | p { |
28 | load("questions"); |
29 | load("nextID"); |
30 | load("vals"); |
31 | } |
32 | |
33 | synchronized answer { |
34 | if (match("list turing questions", s) || match("list tq", s)) { |
35 | S url = "bots.tinybrain.de/1002408?id=" + parseSnippetID("#1002463"); |
36 | ret n(l(questions), "question") + ", results here: " + url + "\n" + simpleList(); |
37 | } |
38 | |
39 | if (match("full list turing questions", s) || match("full list tq", s)) |
40 | ret n(l(questions), "question") + "\n" + structureLines(questions); |
41 | if (match("count turing questions", s) || match("count tq", s)) |
42 | ret str(l(questions)); |
43 | |
44 | if "show tq * full" { |
45 | S id = "tq" + m.unq(0); |
46 | ret structure(findQuestion(id)); |
47 | } |
48 | |
49 | if (match("*", s, m)) { |
50 | S x = m.unq(0); |
51 | if (x.startsWith("tq")) |
52 | ret structure(findQuestion(x)); |
53 | } |
54 | |
55 | // add last dialog as turing question |
56 | if "add tq" { |
57 | O dialog = last(getDialog()); |
58 | if (dialog == null) ret "No dialog to add"; |
59 | |
60 | new TuringQuestion tq; |
61 | tq.question = getString(dialog, "question"); |
62 | tq.answer = removeAtName(getString(dialog, "answer")); |
63 | tq.source = new Source(s); |
64 | ret addTQ(tq); |
65 | } |
66 | |
67 | // add last question as turing question with custom answer |
68 | if "add tq *" { |
69 | O dialog = last(getDialog()); |
70 | if (dialog == null) ret "No dialog to add"; |
71 | |
72 | new TuringQuestion tq; |
73 | tq.question = getString(dialog, "question"); |
74 | tq.answer = m.unq(0); |
75 | tq.source = new Source(s); |
76 | ret addTQ(tq); |
77 | } |
78 | |
79 | if (match("add tq * *", s, m) || match("add turing question * *", s, m)) { |
80 | new TuringQuestion tq; |
81 | tq.question = m.unq(0); |
82 | tq.answer = m.unq(1); |
83 | tq.source = new Source(s); |
84 | ret addTQ(tq); |
85 | } |
86 | |
87 | if (match("add tq level * * *", s, m) || match("add turing question level * * *", s, m)) { |
88 | new TuringQuestion tq; |
89 | tq.level = m.psi(0); |
90 | tq.question = m.unq(1); |
91 | tq.answer = m.unq(2); |
92 | tq.source = new Source(s); |
93 | ret addTQ(tq); |
94 | } |
95 | |
96 | if (match("run tq", s) || match("run turing questions", s)) |
97 | ret askSelf(format("run turing test *", "#1002463")); |
98 | |
99 | if "run tq *" { |
100 | S id = "tq" + m.unq(0); |
101 | TuringQuestion tq = findQuestion(id); |
102 | if (tq == null) ret "TQ not found"; |
103 | ret checkTQ(tq) ? id + " solved" : id +" not solved"; |
104 | } |
105 | |
106 | if "show tq *" { |
107 | S id = "tq" + m.unq(0); |
108 | TuringQuestion tq = findQuestion(id); |
109 | if (tq == null) ret "TQ not found"; |
110 | ret tq.question + " => " + tq.answer; |
111 | } |
112 | |
113 | if "invalidate tq *" { |
114 | S id = "tq" + m.unq(0); |
115 | TuringQuestion tq = findQuestion(id); |
116 | if (tq == null) ret "TQ not found"; |
117 | vals.add(new Val(id, false, new Source(s))); |
118 | save("vals"); |
119 | ret "OK, your input is recorded."; |
120 | } |
121 | } |
122 | |
123 | static synchronized TuringQuestion findQuestion(S id) { |
124 | ret findByField(questions, "id", id); |
125 | } |
126 | |
127 | static synchronized L<TuringQuestion> getLiveList() { |
128 | ret cloneList(questions); |
129 | } |
130 | |
131 | static synchronized S simpleList() { |
132 | Map valsByID = indexByField(vals, "id"); |
133 | new L<S> l; |
134 | for (TuringQuestion tq : questions) { |
135 | boolean inv = valsByID.containsKey(tq.id); |
136 | l.add(tq.question + " => " + tq.answer + (inv ? " (invalidated)" : "")); |
137 | } |
138 | ret fromLines(l); |
139 | } |
140 | |
141 | static S html() { |
142 | ret h3("Turing Questions") |
143 | + sourceCodeToHTML(simpleList()); |
144 | } |
145 | |
146 | static S addTQ(TuringQuestion tq) { |
147 | tq.id = "tq" + nextID++; |
148 | save("nextID"); |
149 | questions.add(tq); |
150 | save("questions"); |
151 | boolean solved = checkTQ(tq); |
152 | ret "OK, added as question " + tq.id + ". " |
153 | + (solved ? "Also, solved." : "Not solved yet."); |
154 | } |
155 | |
156 | static boolean checkTQ(TuringQuestion tq) { |
157 | ret turingMatch(tq.answer, askSelf(tq.question)); |
158 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002462 |
Snippet name: | Dynamic Turing Questions Bot |
Eternal ID of this version: | #1002462/1 |
Text MD5: | e3e6e6c451a46919522e96e1e986b711 |
Transpilation MD5: | a8f465feecabe48e5821c498605143fb |
Author: | stefan |
Category: | eleu |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-02-03 00:05:14 |
Source code size: | 4175 bytes / 158 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 657 / 1588 |
Referenced in: | [show references] |