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
sS theRiddle = [[
What is Fibonacci number 0?
What is Fibonacci number 1?
What is Fibonacci number 2?
What is Fibonacci number 3?
]];
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
]];
static L priorityConcepts = ll(
"mtsrzasaoxrmicch" // "X is Y if Z."
);
!include #1007689 // Web v2
static L facts;
p-tt {
setFrameHeight(consoleFrame(), 400);
centerConsole();
substance();
aiEnhancements();
aiConcepts_noAutoClear();
//useConceptsDump(concepts);
set englishToConceptLanguage_useBrackets;
facts = clParse(printNumberedLines(linesToCL(theFacts)));
useFacts(theFacts);
printNumberedLines(facts);
print();
for (S rid : toLinesFullTrim(theRiddle)) {
print("? " + rid);
Lisp riddle = clParse(englishToConceptLanguage(rid));
//print("# " + riddle);
if (!riddle.is("urfkhwfasdaqqqse", "mrhggsmuykeceghd")) continue; // What is X? // What is the decimal representation of X?
Lisp mainConcept = riddle.get(0);
// Make web
new Web web;
web.node(mainConcept);
web.relations(facts);
web_expandMarkers(web);
for (Lisp rule : trueStatementsByHead("mtsrzasaoxrmicch")) {
Lisp x = rule.get(0);
for (WebNode node : web.nodes) {
for (Lisp lbl : node.labels) {
//print("Matching " + x + " and " + lbl);
Map matches = lispMatch(x, lbl, ll("n"));
if (matches != null) {
print("Rule match: " + struct(matches));
if (checkACondition(lispReplaceVars(rule.get(2), matches))) {
print("Condition OK! Evaluating: " + calculateDeep(lispReplaceVars(rule.get(1), matches)));
}
}
}
}
//print("Node: " + node + ", condition: " + condition);
}
// Answer question
L l = listWithout(web.findNode(mainConcept).labels, mainConcept);
//print("Labels: " + l);
S s = chooseALabelToReturn(l);
print(" " + or2(conceptLanguageToEnglish(unquote(s)), "I don't know"));
//print(web);
}
aiUsing_print();
}
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;
}
static L aiConceptsPrioritized() {
new L l;
for (S id : priorityConcepts) {
AIConcept c = getAIConcept(id);
if (c == null) print("Warning: Not found " + id);
addIfNotNull(l, c);
}
Set index = new HashSet(priorityConcepts);
for (AIConcept c : aiConceptsByAge())
if (!index.contains(c.globalID))
l.add(c);
ret l;
}
sbool checkACondition(Lisp l) {
print("Checking: " + l);
if (l.is("wdbphzfoxwlrhdyl")) // X > Y
ret calculate(l.get(0)).compareTo(calculate(l.get(1))) > 0;
print("Ignoring unknown condition " + l);
false;
}
static BigInteger calculate(Lisp l) {
l = calculateDeep(l);
if (lispIsInt(l)) ret bigint(l.head);
fail("Not an int: " + l);
}
sbool lispIsInt(Lisp x) {
ret x != null && x.isLeaf() && isInteger(x.head);
}
static BigInteger lispToInt(Lisp x) {
ret lispIsInt(x) ? bigint(x.head) : null;
}
static Lisp lispInt(BigInteger x) {
ret lisp(str(x));
}
// evaluate anywhere in the tree (e.g. Fib number 2-1 => Fib number 1)
static Lisp calculateDeep(Lisp x) {
ret lispMap_after(x, func(Lisp l) {
if (l.is("jxcubqjtqykhfvyo") && lispIsInt(l.get(0)) && lispIsInt(l.get(1)))
ret lispInt(minus(lispToInt(l.get(0)), lispToInt(l.get(1))));
ret l;
});
}