Created
December 22, 2018 05:30
-
-
Save DonaldKellett/5d964ce2c992a382549d34c4e7064651 to your computer and use it in GitHub Desktop.
Learn Prolog Now! - Chapter 3 - Exercise 3.3 - Train routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Knowledge base of direct train routes (provided) | |
% Assumption: such direct train routes are unidirectional, i.e. directTrain(X, Y) does not imply directTrain(Y, X) | |
directTrain(saarbruecken,dudweiler). | |
directTrain(forbach,saarbruecken). | |
directTrain(freyming,forbach). | |
directTrain(stAvold,freyming). | |
directTrain(fahlquemont,stAvold). | |
directTrain(metz,fahlquemont). | |
directTrain(nancy,metz). | |
% travelFromTo/2 - can we travel from X to Y via a series of direct trains? | |
% We can travel from X to Y if there is a direct train from X to Y, or | |
% there is a direct train from X to some Z such that we can travel from Z to Y | |
travelFromTo(X, Y) :- directTrain(X, Y); directTrain(X, Z), travelFromTo(Z, Y). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment