You are on page 1of 17

The Missionary & Cannibal River Crossing Problem tutorial solution

This problem is part of a class of problems that we are not taught to solve at school, and for most of us not even at university. The solutions are often given briefly, but crucially the method by which the solution is to be found never seems to be mentioned. No doubt there is a small group of gifted individuals who can just figure these things out on their own. For the rest of us, it would be nice to have a systematic method of solving these problems. Problem Three missionaries and three cannibals are on one side of a river. They all need to get to the other side of the river and the only method of doing so is by means of a two person rowing boat. Unfortunately, if there are ever more cannibals than missionaries in the same place, the missionaries will get eaten. How can they all get safely across the river?

Discussion This is not a tric !uestion. There are no annoying things to guess, it is simply an e"ercise in pure logic. #nd a solution is possible. To clarify, the rowing boat can only travel with either one or two people on board. Nobody can swim in the crocodile and piranha infested waters. There are no trees or ropes or anything else, just the boat. #s an e"ample of the rules, if the rowing boat is at a river ban with one cannibal on board, whilst one missionary and one cannibal are on the river ban , that counts as having two cannibals in the same location as one missionary. The missionary would get eaten and therefore this situation, or any li e it, is not allowed as part of the solution. Thin about how you could go about solving this problem. $f you can solve it then that%s great& compare your method to mine. $f, after some thin ing, you can%t even figure out how to get started, then $ will give you a hint on the ne"t page. 'ut don%t loo too soon(

)eslie *reen +,ng -$,,

. of ./

v..01 Feb 20.3

Spoiler Alert stop reading now if you want to solve the problem on your own.

)eslie *reen +,ng -$,,

2 of ./

v..01 Feb 20.3

Hint 4ou cannot hope to solve this sort of problem without paper and a pen5pencil. The problem is not complicated in the sense that you need higher mathematics to solve it. However, it is complicated by the number of se!uences that can occur. 6nce you can decide on a way to write down the problem you will have made a good start on the solution.

)eslie *reen +,ng -$,,

7 of ./

v..01 Feb 20.3

Spoiler Alert stop reading now if you want to solve the problem on your own.

)eslie *reen +,ng -$,,

3 of ./

v..01 Feb 20.3

Second Hint This problem re!uires a step by step solution. 8tart from the given state, which is three missionaries and three cannibals on the left ban of the river. 9efine who is going to travel in the rowing boat and then you will have the ne"t state when the boat reaches the other side of the river. There are five possible combinations of occupants of the rowing boat -issionary : -issionary -issionary : +annibal +annibal : +annibal -issionary only +annibal only 8ome of these will not be available for all trips because they won%t be on the river ban . For e"ample, after the first trip across the river there can only be two people on the far river ban . The solution of the problem consists of systematically eliminating those cases which brea the rules.

To those who have studied a bit of mathematics, the problem may now seem tremendously complicated. $f there are five possibilities for each trip, and it loo s li e we need ; trips, that seems li e <; 2,000,000 possibilities to consider. Ta e heart( The problem is nowhere near as complicated as that. Have a go =

)eslie *reen +,ng -$,,

< of ./

v..01 Feb 20.3

Spoiler Alert stop reading now if you want to solve the problem on your own.

)eslie *reen +,ng -$,,

> of ./

v..01 Feb 20.3

Tutorial Solution The first thing we need to do is to define a notation for the state of the problem at any point in time. $ am going to use M to represent a missionary, C to represent a cannibal, and either a > or a < to indicate which ban the boat is on at the time, at the same time separating the people on the left and right ban s of the river. The system state is then uni!uely defined by these / symbols. #ll states will consist of seven symbols. The starting state is CCCMMM< the river where the left ban is the starting side of

?hen there are three or less symbols that is a movement statement @who is in the boat and which way are they goingA, also now as a transition. $ will represent a cannibal and a missionary in the boat going left to right by the movement statement CM> $f that was the first step in the solution the resulting state when the boat reached the opposite river ban would be CCMM>CM $n the second hint $ said there were five possible contents of the rowing boat. )et%s simplify that a little. ?e are trying to get people from the left ban to the right ban . $t therefore seems a bit strange to be only sending one person in the left to right direction. $ will therefore guess that we will always have two people going left to right. $f $ can%t find a solution to the problem under that limitation then $ will have to change my mind. For the moment then we have the possibilities CC> CM> MM> for left to right travel, and <CC <CM <MM <C <M for right to left travel. #ll this will soon become clear in the pictures that follow.
)eslie *reen +,ng -$,, / of ./ v..01 Feb 20.3

$ have just one more simplifying statement. $ will never allow a step which completely undoes the previous step. 8o the movement CM> will never be followed by <CM because it would just ta e us bac to where we came from. 6 , here we go. This is the first step in the solution.

Notice that of the three possible movements on the first step, the one on the right has been eliminated because it has three cannibals ne"t to one missionary.

Have a go at the ne"t step yourself =

)eslie *reen +,ng -$,,

B of ./

v..01 Feb 20.3

Spoiler Alert stop reading now if you want to solve the problem on your own.

)eslie *reen +,ng -$,,

; of ./

v..01 Feb 20.3

Here is the second step.

Notice how few possibilities there really are. #lso notice that the two valid states at the end of this step are identical. There are two ways to get to the same state. Note that in the diagram all the movements @transitionsA at the same horiContal level have the arrows @D or EA going in the same direction. The same goes for the states at the same horiContal level. Notice how $ am going through the possible movements systematically, just li e a computer would. 4ou should be able to do the ne"t step on your own. Have a go =

)eslie *reen +,ng -$,,

.0 of ./

v..01 Feb 20.3

Here is the third step.

Notice how few valid states we are getting. 8o in actual fact this is really a very easy problem because there are so few paths to follow. Now you should do the ne"t two steps yourself =

)eslie *reen +,ng -$,,

.. of ./

v..01 Feb 20.3

Spoiler Alert stop reading now if you want to solve the problem on your own.

)eslie *reen +,ng -$,,

.2 of ./

v..01 Feb 20.3

$t should be getting easier for you now. This is just a repetition of simple steps.

)eslie *reen +,ng -$,,

.7 of ./

v..01 Feb 20.3

Try to do the ne"t two steps on your own =

)eslie *reen +,ng -$,,

.3 of ./

v..01 Feb 20.3

Spoiler Alert stop reading now if you want to solve the problem on your own.

)eslie *reen +,ng -$,,

.< of ./

v..01 Feb 20.3

From here the result is obvious. ?e have all three missionaries safely across. $t would be tiresome to draw out the final steps.
)eslie *reen +,ng -$,, .> of ./ v..01 Feb 20.3

)et%s summarise the valid path. CCCMMM< CMMM>CC CCMMM<C MMM>CCC CMMM<CC CM>CCMM come bac CCMM<CM CC>CMMM CCC<MMM C>CCMMM CC<CMMM >CCCMMM CC> <C CC> <C MM> <CM MM> <C CC> <C CC> Two cannibals go across = and one comes bac Two cannibals go across = and one comes bac Two missionaries go across = and both a cannibal and a missionary Two missionaries go across = and a cannibal comes bac Two cannibals go across = and a cannibal comes bac Two cannibals go across.

)et%s review the method of solution. .. +reate a notation for the states. 2. +reate a notation for the transitions between states. 7. 8ystematically try all possible transitions from a state, eliminating those transitions which brea any of the rules of the problem. This type of problem involves a Ftree search algorithmG, the various states branching out to multiple new states. $ drew the diagrams using the program Evolus Pencil. $ used D instead of because the nice arrows wouldn%t paste into the pencil program correctly $f you have followed the method for this problem then this ne"t problem should be easy. $n any case $ am not giving any hints or the solution. Problem # man has three valuable assets1 a lion, a goat and a bale of hay. ?hen he is there the animals are well behaved. $f he leaves then the lion will eat the goat, or the goat will eat the hay. The lion will not eat the hay. He has to cross a river in a rowing boat and can only ta e one of his three assets at a time. How does he get all three assets safely across the river.

)eslie *reen +,ng -$,,

./ of ./

v..01 Feb 20.3

You might also like