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).

1  
!7
2  
3  
sS theRiddle = [[
4  
  Was hatte Magnus Carlsen zum Frühstück?
5  
]];
6  
7  
sS theFacts = [[
8  
  Magnus Carlsen wohnt in Norwegen.
9  
  In Norwegen isst man Fisch.
10  
  Jan Gustafsson wohnt in Deutschland.
11  
  In Deutschland isst man Bratwurst.
12  
  
13  
  (Q: Was hatte X zum Frühstück?) und (X wohnt in Y.) und (In Y isst man Z.) => (A: Wahrscheinlich Z!)
14  
]];
15  
16  
sS concepts = [[
17  
  ["vouwrrhtmajsgaby", "Q: X"],
18  
  ["nywfcwkkcknzhmdy", "A: X"],
19  
  ["bzvabitchqhqkldm", "In X isst man Y."],
20  
  ["pizxszvxocdluica", "Was hatte X zum Y?"],
21  
  ["fhsukilpoasgkvcs", "X wohnt in Y."],
22  
  ["oceicdfeiyftxuwi", "Wahrscheinlich X!"],
23  
  ["eijdjqhyzheusetj", "(X) und (Y) und (Z) => (AA)"],
24  
]];
25  
26  
svoid createWeb(Web web, Lisp riddle) {}
27  
28  
svoid calc(Web web, Lisp riddle) {
29  
  //print("Vars: " + vars);
30  
  for (LispStatement ls : lispStatementsByHead("eijdjqhyzheusetj")) {
31  
    Lisp rule = ls.term;
32  
    L<Lisp> conditions = dropLast(rule.args);
33  
    Lisp out = last(rule.args);
34  
    
35  
    new Map<S, Lisp> matches;
36  
    if (matchConditions(conditions, matches, riddle)) {
37  
      //print("Yo! " + struct(matches));
38  
      web.node(lispReplaceVars(out, matches));
39  
    }
40  
  }
41  
}
42  
43  
static bool matchConditions(L<Lisp> conditions, Map<S, Lisp> m, Lisp riddle) {
44  
  if (empty(conditions)) true;
45  
  Lisp cond = first(conditions);
46  
  for (Lisp fact : concatLists(ll(riddle), facts)) {
47  
    Map<S, Lisp> m2 = cloneMap(m);
48  
    if (lispMatchIC_sub(cond, fact, vars, m2)) {
49  
      if (matchConditions(dropFirst(conditions), m2, riddle)) {
50  
        m.putAll(m2);
51  
        true;
52  
      }
53  
    }
54  
  }
55  
  false;
56  
}
57  
58  
sS getAnswer(Web web) {
59  
  Lisp l = web_nodeByHead(web, "nywfcwkkcknzhmdy");
60  
  if (l != null)
61  
    ret crazyEnglishFixing(conceptLanguageToEnglish_rec(l.get(0)));
62  
  null;
63  
}
64  
65  
p {
66  
  setConsoleInput(firstLineFullTrim(theRiddle));
67  
  pConsoleThoughtMachine();
68  
}
69  
70  
!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: 491 / 1159
Version history: 2 change(s)
Referenced in: [show references]