Prolog Fox, Goose & Grain riddle, not showing output

1.1k Views Asked by At

I'm trying to solve the fox, goose, and grain riddle (where the farmer can only transport himself and one of the three across the river), and am following the code given here: http://hilltop.bradley.edu/~chris/prolog.html (about 4/5 of the way into the document)

Basically the code tells Prolog which moves are valid and Prolog then calculates the answer from that.

%[Farmer_position, Fox_position, Goose_position, Grain_position]
graph([w,w,w,w],[e,w,e,w]).
graph([e,w,e,w],[w,w,e,w]).
graph([w,w,e,w],[e,w,e,w]).
graph([w,w,e,w],[e,e,e,w]).
graph([w,w,e,w],[e,w,e,e]).
graph([e,e,e,w],[w,w,e,w]).
graph([e,e,e,w],[w,e,w,w]).
graph([e,w,e,e],[w,w,w,e]).
graph([e,w,e,e],[w,w,e,w]).
graph([w,w,w,e],[e,e,w,e]).
graph([w,w,w,e],[e,w,e,e]).
graph([e,e,w,e],[w,e,w,e]).
graph([e,e,w,e],[w,w,w,e]).
graph([e,e,w,e],[w,e,w,w]).
dfs([w,w,w,w],[[e,e,e,e]],answer).
?- dfs([w,w,w,w],[[e,e,e,e]],answer).

However, I can't get Prolog to display the answer. Am I doing something wrong? I'm using SWI-Prolog and as an IDE I'm using SWI-Prolog-Editor.

EDIT: Just to be clear, it compiles, it's just not showing the "value" of the "answer" variable.

0

There are 0 best solutions below