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

70
LINES

< > BotCompany Repo | #1008140 // Magnus Carlsens Frühstück [translation of #1007814]

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

Download Jar. Uses 4489K of libraries. Click here for Pure Java version (13579L/98K).

!7

sS theRiddle = [[
  Was hatte Magnus Carlsen zum Frühstück?
]];

sS theFacts = [[
  Magnus Carlsen wohnt in Norwegen.
  In Norwegen isst man Fisch.
  Jan Gustafsson wohnt in Deutschland.
  In Deutschland isst man Bratwurst.
  
  (Q: Was hatte X zum Frühstück?) und (X wohnt in Y.) und (In Y isst man Z.) => (A: Wahrscheinlich Z!)
]];

sS concepts = [[
  ["vouwrrhtmajsgaby", "Q: X"],
  ["nywfcwkkcknzhmdy", "A: X"],
  ["bzvabitchqhqkldm", "In X isst man Y."],
  ["pizxszvxocdluica", "Was hatte X zum Y?"],
  ["fhsukilpoasgkvcs", "X wohnt in Y."],
  ["oceicdfeiyftxuwi", "Wahrscheinlich X!"],
  ["eijdjqhyzheusetj", "(X) und (Y) und (Z) => (AA)"],
]];

svoid createWeb(Web web, Lisp riddle) {}

svoid calc(Web web, Lisp riddle) {
  //print("Vars: " + vars);
  for (LispStatement ls : lispStatementsByHead("eijdjqhyzheusetj")) {
    Lisp rule = ls.term;
    L<Lisp> conditions = dropLast(rule.args);
    Lisp out = last(rule.args);
    
    new Map<S, Lisp> matches;
    if (matchConditions(conditions, matches, riddle)) {
      //print("Yo! " + struct(matches));
      web.node(lispReplaceVars(out, matches));
    }
  }
}

static bool matchConditions(L<Lisp> conditions, Map<S, Lisp> m, Lisp riddle) {
  if (empty(conditions)) true;
  Lisp cond = first(conditions);
  for (Lisp fact : concatLists(ll(riddle), facts)) {
    Map<S, Lisp> m2 = cloneMap(m);
    if (lispMatchIC_sub(cond, fact, vars, m2)) {
      if (matchConditions(dropFirst(conditions), m2, riddle)) {
        m.putAll(m2);
        true;
      }
    }
  }
  false;
}

sS getAnswer(Web web) {
  Lisp l = web_nodeByHead(web, "nywfcwkkcknzhmdy");
  if (l != null)
    ret crazyEnglishFixing(conceptLanguageToEnglish_rec(l.get(0)));
  null;
}

p {
  setConsoleInput(firstLineFullTrim(theRiddle));
  pConsoleThoughtMachine();
}

!include #1007815 // Console Thought Machine

Author comment

Began life as a copy of #1007814

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: #1008140
Snippet name: Magnus Carlsens Frühstück [translation of #1007814]
Eternal ID of this version: #1008140/3
Text MD5: 60b03b0811c31ce530f35d29f27954b2
Transpilation MD5: 3cded2d7f7f5c291e0ba5fffbd26d3e2
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-26 12:39:20
Source code size: 1909 bytes / 70 lines
Pitched / IR pitched: No / No
Views / Downloads: 481 / 1143
Version history: 2 change(s)
Referenced in: [show references]