Created
September 7, 2011 21:09
-
-
Save mark-d-holmberg/1201737 to your computer and use it in GitHub Desktop.
The Man, The Wolf, The Goat, and The Cabbage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% See the Gist Here | |
% https://gist.github.com/1201748 | |
change(e,w). | |
change(w,e). | |
move([X,X,Goat,Cabbage],wolf,[Y,Y,Goat,Cabbage]) :- | |
change(X,Y). | |
move([X,Wolf,X,Cabbage],goat,[Y,Wolf,Y,Cabbage]) :- | |
change(X,Y). | |
move([X,Wolf,Goat,X],cabbage,[Y,Wolf,Goat,Y]) :- | |
change(X,Y). | |
move([X,Wolf,Goat,C],nothing,[Y,Wolf,Goat,C]) :- | |
change(X,Y). | |
oneEq(X,X,_). | |
oneEq(X,_,X). | |
safe([Man,Wolf,Goat,Cabbage]) :- | |
oneEq(Man,Goat,Wolf), | |
oneEq(Man,Goat,Cabbage). | |
solution([e,e,e,e],[]). | |
solution(Config,[Move|Rest]) :- | |
move(Config,Move,NextConfig), | |
safe(NextConfig), | |
solution(NextConfig,Rest). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment