diff --git a/chapter-03/exercises.pl b/chapter-03/exercises.pl index 1bec336..588be48 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 @@ -122,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.