🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.prolog
Article #727

How should I do this?

#727
From: Mario O. Bourgoin
Date: Mon, 04 Aug 1986 18:02
35 lines
1796 bytes
Hello,
	I  am trying   to write  a solution  program    for the Farmer
problem. Simply stated:

	A farmer wants to move himself, a silver fox, a fat  goose and
	some jucy grain across a river. Unfortunately, his  boat is so
	tiny he  can only  take one of his things  across on any trip.
	Worse   yet, an unattended  fox will   eat  a  goose, and   an
	unattended goose  will eat the grain,  so the  farmer must not
	leave the fox alone with the goose or the goose alone with the
	grain.  What is he to do?

So far,  I  have stated  the  problem in the   way outlined below. Can
someone   help we  to  get this  working? It figures   out   the first
alternative of moving the goose across but then starts looping on what
to do for the next move.

same(yes,1,1).
same(yes,2,2).
same(no,1,2).
same(no,2,1).

legal(state(F,X,G,A)) :-
	(same(no,X,G);same(yes,F,X)),
	(same(no,G,A);same(yes,F,G)).

linked(state(F1,X1,G1,A1),state(F2,X2,G2,A2)) :-
	same(no,F1,F2),
	(same(yes,X1,X2);(same(yes,F1,X1),same(yes,G1,G2),same(yes,A1,A2))),
	(same(yes,G1,A2);(same(yes,F1,G1),same(yes,X1,X2),same(yes,A1,A2))),
	(same(yes,A1,A2);(same(yes,F1,A1),same(yes,G1,G2),same(yes,X1,X2))).

path(State1,State2) :-
	legal(State1),legal(State2),
	(linked(State1,State2);(path(State1,State3),path(State3,State2))).
Technical Details
Message-ID: <276@mit-amt.MIT.EDU>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!husc6!harvard!panda!genrad!mit-eddie!mit-amt!mob

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!husc6!harvard!panda!genrad!mit-eddie!mit-amt!mob
From: mob@mit-amt.MIT.EDU (Mario O. Bourgoin)
Newsgroups: net.lang.prolog
Subject: How should I do this?
Message-ID: <276@mit-amt.MIT.EDU>
Date: Mon, 4-Aug-86 14:02:14 EDT
Article-I.D.: mit-amt.276
Posted: Mon Aug  4 14:02:14 1986
Date-Received: Tue, 5-Aug-86 02:00:56 EDT
Organization: MIT Media Lab, Cambridge, MA
Lines: 35