From 50dbc5f0c0870238876ba03fce69ebf0ee2e9119 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Thu, 18 Jan 2018 10:29:30 -0800 Subject: [PATCH] Finish ch03 exercises. --- lpn/ch03/travel.pl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lpn/ch03/travel.pl b/lpn/ch03/travel.pl index dda6630..f920845 100644 --- a/lpn/ch03/travel.pl +++ b/lpn/ch03/travel.pl @@ -57,3 +57,26 @@ travel(X, Y) :- travel(X, Z), %% go(metz,paris, %% go(paris,losAngeles))) %% to the query travel(valmont,losAngeles,X). + +%% First, we need set up the terminal scenario: +%% travel(X, Y, go(travelDirect(X, Y))) :- travelDirect(X, Y). + +%% Next, we recurse. +%% travel(X, Y, go(travelDirect(X, Z), W)) :- +%% travelDirect(X, Z), +%% travel(Z, Y, W). + +%% The next exercise says we should modify this to include the +%% mechanism of transport. This is more tedious, but doable. +travel(X, Y, go(byCar(X, Y))) :- byCar(X, Y). +travel(X, Y, go(byCar(X, Z), W)) :- + byCar(X, Z), + travel(Z, Y, W). +travel(X, Y, go(byPlane(X, Y))) :- byPlane(X, Y). +travel(X, Y, go(byPlane(X, Z), W)) :- + byPlane(X, Z), + travel(Z, Y, W). +travel(X, Y, go(byTrain(X, Y))) :- byTrain(X, Y). +travel(X, Y, go(byTrain(X, Z), W)) :- + byTrain(X, Z), + travel(Z, Y, W).