Solving the Missionaries and Cannibals puzzle

There is a traditional puzzle where 3 missionaries and 3 cannibals have to cross a river using a small canoe. Rules are:

* You cannot have more cannibals than missionaries in either bank because cannibals will eat missionaries.
* The canoe can be run by either one or two persons. Both cannibals and missionaries know how to run it.

This puzzle is really easy to solve either by hand or programming. However, hacking a script to solve it is always more challenging than solving it by hand. Juanjo proposes a solution using Ruby in Misioneros y can

This entry was posted in Gentoo. Bookmark the permalink.

2 Responses to Solving the Missionaries and Cannibals puzzle

  1. Kim says:

    Seen any solutions in other languages?
    ie. bash, perl, C, C++

  2. Fernando J. Pereda says:

    In the post I linked there is a solution in Ruby, and two links to solutions in Prolog and Lisp:

    Missionaries and Cannibals in Prolog
    Missionaries and Cannibals in Lisp

    It shouldn’t be too hard to do it in C (thus in C++ and Objective-C). Perl, Java, Python and other imperative languages should also be ‘easy’. Bash will be a bit tricker though.

    Cheers,
    Ferdy