CSE505/A/reach.P

23 lines
587 B
Plaintext
Raw Normal View History

2024-02-19 23:38:00 -05:00
source(3).
edge(0,1).
edge(1,2).
edge(1,5).
edge(2,5).
edge(3,5).
edge(3,5).
%input :- [reachin1000]. % one way of reading input facts
%:- include(reachin1000). % 2nd way of reading input facts
reach(X) :- source(X).
reach(Y) :- reach(X), edge(X,Y).
:- table reach/1.
printReach :- reach(X), write(X), write(' '), fail.
printReach.
%timeReach :- cputime(X), input, printReach, cputime(Y), T is Y-X, write(T).
%timeReach :- input, cputime(X), printReach, cputime(Y), T is Y-X, write(T).
timeReach :- cputime(X), printReach, cputime(Y), T is Y-X, write(T).