CSE505/Assignment1/A/cycle.P

17 lines
373 B
Plaintext
Raw Normal View History

2024-02-22 23:50:15 -05:00
:- include(randompath1000). % 2nd way of reading input facts
2024-02-19 23:38:00 -05:00
2024-02-22 23:50:15 -05:00
:- table path/2.
2024-02-19 23:38:00 -05:00
path(X,Y) :- edge(X,Y).
2024-02-22 23:50:15 -05:00
% Way 1
%path(X,Y) :- edge(X,Z), path(Z,Y).
% Way 2
path(X,Y) :- path(X,Z), edge(Z,Y).
% Way 3
%path(X,Y) :- path(X,Z), path(Z,Y).
2024-02-19 23:38:00 -05:00
cycle(X) :- path(X,X), !.
2024-02-22 23:50:15 -05:00
printPath :- path(X, Y), fail.
printPath.
timePath :- cputime(X), printPath, cputime(Y), T is Y-X, write(T).