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

58
LINES

< > BotCompany Repo | #1001890 - Is In Bot - can solve logic puzzles

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1630L/11K/37K).

// If the pope is in the house and the house is in the world, then is the pope in the world?


!752

p {
  makeBot("Is In Bot.");
}

static S answer(S s) {
  new MultiMap<S, S> isIn;
  
  new Matches m;
  if (
    flexmatch("if the * is in the *, and the * is in the *, then is the * in the *?", s, m) ||
    flexmatch("if the * is in the *, and the * is in the *, is the * in the *?", s, m)) {
    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);
    isIn.put(a, b);
    isIn.put(c, d);
    ret makeAnswer(isIn, e, f);
  }
  
  if (
    flexmatch("if the * is in the *, and the * is in the *, and the * is in the *, then is the * in the *?", s, m) ||
    flexmatch("if the * is in the *, and the * is in the *, and the * is in the *, is the * in the *?", s, m)) {
    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);
    isIn.put(a, b);
    isIn.put(c, d);
    isIn.put(e, f);
    ret makeAnswer(isIn, g, h);
  }
  ret null;
}

static S makeAnswer(MultiMap<S, S> isIn, S e, S f) {
  boolean result = hasTransitive(isIn, e, f);
  if (result)
    ret format("Yes, the * is in the *.", e, f);
  else
    ret format("No, the * is not in the *.", e, f);
}

static boolean flexmatch(S pat, S s, Matches m) {
  pat = simplify1(pat); s = simplify1(s);
  if (match(pat, s, m)) ret true;
  pat = simplify2(pat); s = simplify2(s);
  ret match(pat, s, m);
}
 
// simplifications that seem safe
static S simplify1(S s) {
  s = dropWords(s, "the", "an", "my", "your", "his", "her", "our", "their");
  ret replaceWords(s, "are", "is", "on", "in", "am", "is");
}

// simplifications that might fail (because a is a popular noun for this bot, like in "if a is in b and...2)
static S simplify2(S s) {
  ret dropWords(s, "a");
}

download  show line numbers  debug dex   

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

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: 619 / 2203
Referenced in: [show references]

Formerly at http://tinybrain.de/1001890 & http://1001890.tinybrain.de