Warning: session_start(): open(/var/lib/php/sessions/sess_sfdg90es4383odfi4hck5omrcs, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
sbool printWebs;
sS theRiddle = [[
What is Fibonacci number 0?
What is Fibonacci number 1?
What is Fibonacci number 2?
What is Fibonacci number 3?
What is Fibonacci number 4?
]];
sS theFacts = [[
Fibonacci number n is Fibonacci number n-1 plus Fibonacci number n-2 if n > 2.
There is no Fibonacci number with a negative index.
There is no Fibonacci number 0.
Fibonacci number 1 is 1.
Fibonacci number 2 is 1.
gmtzfidalveipfyx feyhbrhdeovmbvaw amcmxkgwhivbouqs
pqnfhkzxoqkaoyqk sppxbuuqeetjmzuo
]];
static S concepts = [[
["feyhbrhdeovmbvaw", "There is no X."],
["mtsrzasaoxrmicch", "X is Y if Z."],
["fgvvrzypbkqomktd", "X is Y."],
["sppxbuuqeetjmzuo", "X plus Y"],
["devwldetfsfylnod", "X with a negative index"],
["rgsamtbrhpcqowko", "Fibonacci number X"],
["jxcubqjtqykhfvyo", "X - Y", "as in minus"],
["wdbphzfoxwlrhdyl", "X > Y"],
["urfkhwfasdaqqqse", "What is X?"],
["pqnfhkzxoqkaoyqk", "Operation X should be expanded."],
["amcmxkgwhivbouqs", "Something that doesn't exist"],
["yissyloatogavyuu", "Fibonacci number"],
["gmtzfidalveipfyx", "Marker X implies label Y."]
]];
!include #1007689 // Web v2
static Web web;
static L facts;
p-tt {
setFrameHeight(consoleFrame(), 400);
centerConsole();
substance();
aiEnhancements();
aiConcepts_noAutoClear();
useConceptsDump(concepts);
set englishToConceptLanguage_useBrackets;
facts = clParse(linesToCL(theFacts));
print(theFacts);
useFacts(theFacts);
//printNumberedLines(facts);
print();
for (S rid : toLinesFullTrim(theRiddle)) {
print("? " + rid);
print(" " + answer(rid));
}
//aiUsing_print(priorityConcepts);
makeBot();
setConsoleInput("What is Fibonacci number 500?");
}
static S answer(S rid) {
if (eq(rid, "web")) { print(web); ret "OK"; }
Lisp riddle = clParse(englishToConceptLanguage(rid));
//print("# " + riddle);
if (!riddle.is("urfkhwfasdaqqqse", "mrhggsmuykeceghd")) ret "huh?"; // What is X? // What is the decimal representation of X?
Lisp mainConcept = riddle.get(0);
// Make web
web = new Web;
web.node(mainConcept);
web.relations(facts);
int webSize = web.count();
int cursor = 0;
while licensed {
//print("Web size: " + webSize);
printWithoutNL(".");
if ((++cursor % 60) == 0) print();
web_expandMarkers(web);
web_expandOperations(web);
for (Lisp rule : trueStatementsByHead("mtsrzasaoxrmicch")) {
Lisp x = rule.get(0);
for (WebNode node : cloneList(web.nodes)) {
for (Lisp lbl : cloneList(node.labels)) {
//print("Matching " + x + " and " + lbl);
Map matches = lispMatch(x, lbl, ll("n"));
if (matches != null) {
//print("Rule match: " + struct(matches));
Lisp bla = lispReplaceVars(rule.get(2), matches);
if (checkACondition(bla)) {
bla = lispReplaceVars(rule.get(1), matches);
bla = lispCalculateDeep(bla);
bla = web_insertNumbers(web, bla);
//print("bla: " + bla);
bla = lispCalculateDeep(bla);
if (lispIsInt(bla))
node.addLabel(bla); // Found!
else {
//print("Condition OK! Evaluating: " + bla);
web.node(bla);
}
}
}
}
}
//print("Node: " + node + ", condition: " + condition);
}
int n = web.count();
if (n == webSize) break;
webSize = n;
}
print();
// print question again
if (cursor / 60 >= 10)
print("? " + rid);
// Answer question
L l = listWithout(web.findNode(mainConcept).labels, mainConcept);
//print("Labels: " + l);
S s = chooseALabelToReturn(l);
s = or2(conceptLanguageToEnglish(unquote(s)), "I don't know");
if (printWebs) print(web);
ret s;
}
sS chooseALabelToReturn(L ll) {
L l = map(f clUnparse, ll);
//print(" Labels: " + l);
S s = findInteger(l);
if (s == null) s = firstGlobalID(l);
//if (s == null) s = random(l);
if (s == null) ret s = first(l);
ret s;
}
sbool checkACondition(Lisp l) false on exception {
ret lispCalculateDeep(l).is("true");
}
static BigInteger calculate(Lisp l) {
l = assertIsInt(lispCalculateDeep(l);
if (lispIsInt(l)) ret bigint(l.head);
fail("Not an int: " + l);
}