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

183
LINES

< > BotCompany Repo | #1007798 // Gunnar numbers [WORKS]

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

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (11250L/79K).

1  
!7
2  
3  
sS theFacts = [[
4  
5  
  Gunnar number n is n plus 777 if n > 1.
6  
  There is no Gunnar number with a negative index.
7  
  There is no Gunnar number 0.
8  
  Gunnar number 1 is 50.
9  
10  
  // Some technical stuff
11  
  gmtzfidalveipfyx feyhbrhdeovmbvaw amcmxkgwhivbouqs
12  
  pqnfhkzxoqkaoyqk sppxbuuqeetjmzuo
13  
]];
14  
15  
sS theRiddle = [[
16  
  What is Gunnar number 0?
17  
  What is Gunnar number 1?
18  
  What is Gunnar number 2?
19  
  What is Gunnar number 3?
20  
  What is Gunnar number 4?
21  
]];
22  
23  
static S concepts = [[
24  
  ["feyhbrhdeovmbvaw", "There is no X."],
25  
  ["mtsrzasaoxrmicch", "X is Y if Z."],
26  
  ["fgvvrzypbkqomktd", "X is Y."],
27  
  ["sppxbuuqeetjmzuo", "X plus Y"],
28  
  ["devwldetfsfylnod", "X with a negative index"],
29  
  ["rgsamtbrhpcqowko", "Gunnar number X"],
30  
  ["jxcubqjtqykhfvyo", "X - Y", "as in minus"],
31  
  ["wdbphzfoxwlrhdyl", "X > Y"],
32  
  ["urfkhwfasdaqqqse", "What is X?"],
33  
  ["pqnfhkzxoqkaoyqk", "Operation X should be expanded."],
34  
  ["amcmxkgwhivbouqs", "Something that doesn't exist"],
35  
  ["yissyloatogavyuu", "Gunnar number"],
36  
  ["gmtzfidalveipfyx", "Marker X implies label Y."]
37  
]];
38  
39  
!include #1007689 // Web v2
40  
41  
static int saveInterval = 60000;
42  
static new Web web;
43  
static L<Lisp> facts;
44  
static long lastSave, sizeSaved;
45  
46  
p-tt {
47  
  setConsoleTitle(programTitle());
48  
  load("web"); lastSave = sysNow();
49  
  setFrameHeight(consoleFrame(), 400);
50  
  centerConsole();
51  
  //magellan();
52  
  //graphite();
53  
  //mistAqua();
54  
  //moderateTheme();
55  
  sahara();
56  
  swing {
57  
    setConsoleInput("What is Gunnar number 500?");
58  
    consoleAddAskButton();
59  
    focusConsole();
60  
    final JLabel lblBrainSize = jRightAlignedLabel();
61  
    addToConsole(lblBrainSize);
62  
    awtEvery(lblBrainSize, 1000, r {
63  
      lblBrainSize.setText("Brain Size: " + toM(fileSize(programFile("web.structure")), 1) + "MB");
64  
    });
65  
  }
66  
67  
  aiEnhancements();
68  
  aiConcepts_noAutoClear();
69  
  useConceptsDump(concepts);
70  
  set englishToConceptLanguage_useBrackets;
71  
  facts = clParse(linesToCL(theFacts));
72  
  print(theFacts);
73  
  useFacts(theFacts);
74  
  //printNumberedLines(facts);
75  
  print();
76  
  
77  
  for (S rid : toLinesFullTrim(theRiddle)) {
78  
    print("? " + rid);
79  
    print("  " + answer(rid));
80  
  }
81  
    
82  
  makeBot();
83  
  notDone();
84  
}
85  
86  
static S answer(S rid) {
87  
  if (eq(rid, "web")) { print(web); ret "OK"; }
88  
  Lisp riddle = clParse(englishToConceptLanguage(rid));
89  
  //print("# " + riddle);
90  
  
91  
  if (!riddle.is("urfkhwfasdaqqqse", "mrhggsmuykeceghd")) ret "huh?"; // What is X? // What is the decimal representation of X?
92  
  Lisp mainConcept = riddle.get(0);
93  
94  
  // Make web
95  
  web.node(mainConcept);
96  
  web.relations(facts);
97  
  
98  
  int webSize = web.count();
99  
  int cursor = 0;
100  
  while licensed {
101  
    //print("Web size: " + webSize);
102  
    if (webSize != sizeSaved && sysNow() >= lastSave+saveInterval) {
103  
      printWithoutNL("S");
104  
      save("web");
105  
      sizeSaved = webSize;
106  
      lastSave = sysNow();
107  
    } else
108  
      printWithoutNL(".");
109  
    if ((++cursor % 60) == 0) print();
110  
    
111  
    CriticalAction action = beginCriticalAction("Web Update");
112  
    try {
113  
      web_expandMarkers(web);
114  
      web_expandOperations(web);
115  
  
116  
      for (Lisp rule : trueStatementsByHead("mtsrzasaoxrmicch")) {
117  
        Lisp x = rule.get(0);
118  
        for (WebNode node : cloneList(web.nodes)) {
119  
          for (Lisp lbl : cloneList(node.labels)) {
120  
            //print("Matching " + x + " and " + lbl);
121  
            Map<S, Lisp> matches = lispMatch(x, lbl, ll("n"));
122  
            if (matches != null) {
123  
              //print("Rule match: " + struct(matches));
124  
              Lisp bla = lispReplaceVars(rule.get(2), matches);
125  
              if (checkACondition(bla)) {
126  
                bla = lispReplaceVars(rule.get(1), matches);
127  
                bla = lispCalculateDeep(bla);
128  
                bla = web_insertNumbers(web, bla);
129  
                //print("bla: " + bla);
130  
                bla = lispCalculateDeep(bla);
131  
                if (lispIsInt(bla))
132  
                  node.addLabel(bla); // Found!
133  
                else {
134  
                  //print("Condition OK! Evaluating: " + bla);
135  
                  web.node(bla);
136  
                }
137  
              }
138  
            }
139  
          }
140  
        }
141  
        //print("Node: " + node + ", condition: " + condition);
142  
      }
143  
    } finally {
144  
      action.done();
145  
    }
146  
    
147  
    int n = web.count();
148  
    if (n == webSize) break;
149  
    webSize = n;
150  
  }
151  
  print();
152  
  
153  
  // print question again
154  
  if (cursor / 60 >= 10)
155  
    print("? " + rid);
156  
    
157  
  // Answer question
158  
  L<Lisp> l = listWithout(web.findNode(mainConcept).labels, mainConcept);
159  
  //print("Labels: " + l);
160  
  S s = chooseALabelToReturn(l);
161  
  s = or2(conceptLanguageToEnglish(unquote(s)), "I don't know");
162  
  ret s;
163  
}
164  
165  
sS chooseALabelToReturn(L<Lisp> ll) {
166  
  L<S> l = map(f clUnparse, ll);
167  
  //print("  Labels: " + l);
168  
  S s = findInteger(l);
169  
  if (s == null) s = firstGlobalID(l);
170  
  //if (s == null) s = random(l);
171  
  if (s == null) ret s = first(l);
172  
  ret s;
173  
}
174  
175  
sbool checkACondition(Lisp l) false on exception {
176  
  ret lispCalculateDeep(l).is("true");
177  
}
178  
179  
svoid cleanMeUp {
180  
  while (criticalActionsInFlight()) sleep(5);
181  
  if (sizeSaved != web.count())
182  
    save("web");
183  
}

Author comment

Began life as a copy of #1007674

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: #1007798
Snippet name: Gunnar numbers [WORKS]
Eternal ID of this version: #1007798/4
Text MD5: e91ec476414ec40e0d4329af45a5dfee
Transpilation MD5: e168e953052abdecde4a6be618f71965
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-08 20:56:23
Source code size: 5203 bytes / 183 lines
Pitched / IR pitched: No / No
Views / Downloads: 479 / 940
Version history: 3 change(s)
Referenced in: [show references]