From 708646baf490cd23585114df80fa39590ca7bea4 Mon Sep 17 00:00:00 2001 From: RobbeB32 Date: Wed, 25 Dec 2019 14:54:14 +0100 Subject: [PATCH 1/2] Update exercises.pl added alternative to exercise 3.2 --- chapter-03/exercises.pl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/chapter-03/exercises.pl b/chapter-03/exercises.pl index 1bec336..bfe4416 100644 --- a/chapter-03/exercises.pl +++ b/chapter-03/exercises.pl @@ -31,6 +31,11 @@ greater_than(succ(_),0). greater_than(succ(X),succ(Y)) :- greater_than(X,Y). + +%% alternative: +greater_than(succ(X), X). +greater_than(succ(Y), X) :- + greater_than(Y, X). %% Exercise 3.3 %% Binary trees are trees where all internal nodes have exactly two childres. The From 7c03f732e0b0d6c6443167818eb59366432e4703 Mon Sep 17 00:00:00 2001 From: RobbeB32 Date: Wed, 25 Dec 2019 15:13:05 +0100 Subject: [PATCH 2/2] Update exercises.pl alternative 3.5 for both directions --- chapter-03/exercises.pl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/chapter-03/exercises.pl b/chapter-03/exercises.pl index bfe4416..588be48 100644 --- a/chapter-03/exercises.pl +++ b/chapter-03/exercises.pl @@ -127,5 +127,12 @@ directTrain(Z,X), travelBetween(Z, Y). +%% alternative: +directTrain(X,Y) :- directTrain(Y,X). +travelBetween(X,Y) :- directTrain(X,Y). +travelBetween(X,Y) :- + directTrain(X,Z), + travelBetween(Z,Y). + %% You will end up in infinite loops since you can go both directions, so it is %% possible to keep calling the same function over and over.