Created
December 22, 2018 06:50
-
-
Save DonaldKellett/92aae6eef065301aa4163bd82ca4e94c to your computer and use it in GitHub Desktop.
Learn Prolog Now! - Chapter 3 - Practical Session - Programming Exercise 2 - Travelling
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 travel information (provided) | |
| % Assumption: these routes are unidirectional | |
| byCar(auckland,hamilton). | |
| byCar(hamilton,raglan). | |
| byCar(valmont,saarbruecken). | |
| byCar(valmont,metz). | |
| byTrain(metz,frankfurt). | |
| byTrain(saarbruecken,frankfurt). | |
| byTrain(metz,paris). | |
| byTrain(saarbruecken,paris). | |
| byPlane(frankfurt,bangkok). | |
| byPlane(frankfurt,singapore). | |
| byPlane(paris,losAngeles). | |
| byPlane(bangkok,auckland). | |
| byPlane(singapore,auckland). | |
| byPlane(losAngeles,auckland). | |
| % travel/2 - Can we travel from X to Y using various modes of transportation? | |
| % Basis: if we can travel from X to Y directly by car, train or plane then we can travel from X to Y | |
| travel(X, Y) :- byCar(X, Y); byTrain(X, Y); byPlane(X, Y). | |
| % Inductive Step 1: If we can travel directly by car from X to some Z such that we can also travel from Z to Y then we can travel from X to Y | |
| travel(X, Y) :- byCar(X, Z), travel(Z, Y). | |
| % Inductive Steps 2/3: Similar rules hold for trains and planes | |
| travel(X, Y) :- byTrain(X, Z), travel(Z, Y). | |
| travel(X, Y) :- byPlane(X, Z), travel(Z, Y). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment