Untitled

mail@pastecode.io avatar
unknown
prolog
a year ago
783 B
5
Indexable
Never
%connections work both ways
is_connected(A,B) :- con_test(A,B).
is_connected(A,B) :- con_test(B,A).

 

%recursion rule no printing
%con_test(A,B) :- con(A,B).
%con_test(A,B) :- con(A,X), con_test(X,B)

 

%recursion rule with printing
con_test(A,B) :- con(A,B), write(A), write(" connected to "), writeln(B).
con_test(A,B) :- con(A,X), con_test(X,B), write(A), write(" connected to "), writeln(X).

 

%---------------
% knowledgebase
%---------------

 

% ZERO -> 26+5+18+15 -> 64
con(0,64).
con(1,34).
con(2,58).
con(3,56).
con(4,60).
con(5,42).
con(6,52).
con(7,65).
con(8,49).
con(9,42).

 

% ZERO -> 26+5+18+15 -> 64 -> 10 -> 1
con(0,1).
con(1,7).
con(2,4).
con(3,2).
con(4,6).
con(5,6).
con(6,7).
con(7,2).
con(8,4).
con(9,6).