Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
% start program with a query like either: % is_connected(64,A). % setof(A, is_connected(1,A), Output). % connections work both ways (currently disabled) is_connected(A,B) :- con_test(A,B,1). %is_connected(A,B) :- con_test(B,A,1). % recursion rules % Depth prevents infinite loops con_test(A, B, Depth) :- dif(A,B), Depth < 5, con(A,B), write(A), write(" is connected to "), writeln(B). con_test(A, B, Depth) :- dif(A,B), Depth < 5, con_test(A,X,Depth+1), con_test(X,B,Depth+1). % write("--Therefore, "), write(B), write(" connects to "), write(A), write(" through "), writeln(X). %--------------- % knowledgebase %--------------- % Rule: Split up a two-digit number and sum its digits % e.g. 26 -> 2 + 6 -> 8 con(A,B) :- A < 100, A > 9, X is A mod 10, Y is A div 10, B is X + Y, write("By summing digits, "). %, write(X), write(" and "), write(Y), write(", "). % Rule: Split up a two-digit number and multiply its digits % e.g. 26 -> 2 * 6 -> 12 % numbers with zeroes are ignored con(A,B) :- A < 100, X is A mod 10, Y is A div 10, dif(X,0), dif(Y,0), B is X * Y, write("By multiplying digits, "). % , write(X), write(" and "), write(Y), write(", "). % add text when using a fact con(A,B) :- con_gem(A,B), write("By using gematria, "). % Precomputed gematria facts % e.g. ZERO -> 26+5+18+15 -> 64 con_gem(0,64). con_gem(1,34). con_gem(2,58). con_gem(3,56). con_gem(4,60). con_gem(5,42). con_gem(6,52). con_gem(7,65). con_gem(8,49). con_gem(9,42).