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

74
LINES

< > BotCompany Repo | #1007814 // Magnus Carlsen's Breakfast [WORKS]

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

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

1  
!7
2  
3  
sS theRiddle = [[
4  
  What did Magnus Carlsen eat for breakfast?
5  
]];
6  
7  
sS theFacts = [[
8  
  Magnus Carlsen lives in Norway.
9  
  In Norway, they eat fish.
10  
  Jan Gustafsson lives in Germany.
11  
  John Doe lives in Germany.
12  
  In Germany, they eat Bratwurst.
13  
  
14  
  (Q: What did X eat for breakfast?) and (X lives in Y.) and (In Y, they eat Z.) => (A: Probably Z!)
15  
]];
16  
17  
sS concepts = [[
18  
  ["vouwrrhtmajsgaby", "Q: X"],
19  
  ["nywfcwkkcknzhmdy", "A: X"],
20  
  ["zlydvmmyckgcyrak", "Magnus Carlsen"],
21  
  ["verqumbshvchuquw", "Norway"],
22  
  ["wvqzrhdaqnygqgll", "Fish"],
23  
  ["bzvabitchqhqkldm", "In X, they eat Y."],
24  
  ["pizxszvxocdluica", "What did X eat for Y?"],
25  
  ["fhsukilpoasgkvcs", "X lives in Y."],
26  
  ["oceicdfeiyftxuwi", "Probably X!"],
27  
  ["eijdjqhyzheusetj", "(X) and (Y) and (Z) => (AA)"],
28  
]];
29  
30  
svoid createWeb(Web web, Lisp riddle) {}
31  
32  
svoid calc(Web web, Lisp riddle) {
33  
  //print("Vars: " + vars);
34  
  for (LispStatement ls : lispStatementsByHead("eijdjqhyzheusetj")) {
35  
    Lisp rule = ls.term;
36  
    L<Lisp> conditions = dropLast(rule.args);
37  
    Lisp out = last(rule.args);
38  
    
39  
    new Map<S, Lisp> matches;
40  
    if (matchConditions(conditions, matches, riddle)) {
41  
      //print("Yo! " + struct(matches));
42  
      web.node(lispReplaceVars(out, matches));
43  
    }
44  
  }
45  
}
46  
47  
static bool matchConditions(L<Lisp> conditions, Map<S, Lisp> m, Lisp riddle) {
48  
  if (empty(conditions)) true;
49  
  Lisp cond = first(conditions);
50  
  for (Lisp fact : concatLists(ll(riddle), facts)) {
51  
    Map<S, Lisp> m2 = cloneMap(m);
52  
    if (lispMatchIC_sub(cond, fact, vars, m2)) {
53  
      if (matchConditions(dropFirst(conditions), m2, riddle)) {
54  
        m.putAll(m2);
55  
        true;
56  
      }
57  
    }
58  
  }
59  
  false;
60  
}
61  
62  
sS getAnswer(Web web) {
63  
  Lisp l = web_nodeByHead(web, "nywfcwkkcknzhmdy");
64  
  if (l != null)
65  
    ret crazyEnglishFixing(conceptLanguageToEnglish_rec(l.get(0)));
66  
  null;
67  
}
68  
69  
p {
70  
  setConsoleInput(firstLineFullTrim(theRiddle));
71  
  pConsoleThoughtMachine();
72  
}
73  
74  
!include #1007815 // Console Thought Machine

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: #1007814
Snippet name: Magnus Carlsen's Breakfast [WORKS]
Eternal ID of this version: #1007814/34
Text MD5: bd8a2564a60b9055288a97c43ad5ddea
Transpilation MD5: 44805287a53718dee9b2e20ce2cda445
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-13 17:40:00
Source code size: 2034 bytes / 74 lines
Pitched / IR pitched: No / No
Views / Downloads: 819 / 4314
Version history: 33 change(s)
Referenced in: [show references]