Libraryless. Click here for Pure Java version (1630L/11K/37K).
1 | // If the pope is in the house and the house is in the world, then is the pope in the world? |
2 | |
3 | !752 |
4 | |
5 | p { |
6 | makeBot("Is In Bot."); |
7 | } |
8 | |
9 | static S answer(S s) { |
10 | new MultiMap<S, S> isIn; |
11 | |
12 | new Matches m; |
13 | if ( |
14 | flexmatch("if the * is in the *, and the * is in the *, then is the * in the *?", s, m) || |
15 | flexmatch("if the * is in the *, and the * is in the *, is the * in the *?", s, m)) { |
16 | S a = m.unq(0), b = m.unq(1), c = m.unq(2), d = m.unq(3), e = m.unq(4), f = m.unq(5); |
17 | isIn.put(a, b); |
18 | isIn.put(c, d); |
19 | ret makeAnswer(isIn, e, f); |
20 | } |
21 | |
22 | if ( |
23 | flexmatch("if the * is in the *, and the * is in the *, and the * is in the *, then is the * in the *?", s, m) || |
24 | flexmatch("if the * is in the *, and the * is in the *, and the * is in the *, is the * in the *?", s, m)) { |
25 | S a = m.unq(0), b = m.unq(1), c = m.unq(2), d = m.unq(3), e = m.unq(4), f = m.unq(5), g = m.unq(6), h = m.unq(7); |
26 | isIn.put(a, b); |
27 | isIn.put(c, d); |
28 | isIn.put(e, f); |
29 | ret makeAnswer(isIn, g, h); |
30 | } |
31 | ret null; |
32 | } |
33 | |
34 | static S makeAnswer(MultiMap<S, S> isIn, S e, S f) { |
35 | boolean result = hasTransitive(isIn, e, f); |
36 | if (result) |
37 | ret format("Yes, the * is in the *.", e, f); |
38 | else |
39 | ret format("No, the * is not in the *.", e, f); |
40 | } |
41 | |
42 | static boolean flexmatch(S pat, S s, Matches m) { |
43 | pat = simplify1(pat); s = simplify1(s); |
44 | if (match(pat, s, m)) ret true; |
45 | pat = simplify2(pat); s = simplify2(s); |
46 | ret match(pat, s, m); |
47 | } |
48 | |
49 | // simplifications that seem safe |
50 | static S simplify1(S s) { |
51 | s = dropWords(s, "the", "an", "my", "your", "his", "her", "our", "their"); |
52 | ret replaceWords(s, "are", "is", "on", "in", "am", "is"); |
53 | } |
54 | |
55 | // simplifications that might fail (because a is a popular noun for this bot, like in "if a is in b and...2) |
56 | static S simplify2(S s) { |
57 | ret dropWords(s, "a"); |
58 | } |
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001890 |
Snippet name: | Is In Bot - can solve logic puzzles |
Eternal ID of this version: | #1001890/1 |
Text MD5: | 3e83d55f1a8f94807b936ea4029db5c6 |
Transpilation MD5: | 2456b5fae926362b83d76c5b493d2e2f |
Author: | stefan |
Category: | |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-12-09 21:45:37 |
Source code size: | 1868 bytes / 58 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 889 / 2614 |
Referenced in: | [show references] |