# Farmer’s Dilemma

Question: A farmer bought a goat, a wolf and a cabbage from the market. On his way home, he has to cross a river. He has a small boat which only allows him to take one thing with him at a time. The farmer cannot leave the cabbage and the goat together (the goat would eat the cabbage) nor can he leave the goat and the wolf together (the wolf would eat the goat). How does he cross the river without losing any of the things he bought?

Answer: Seems easy enough, right? So let’s start with the goat. The farmer takes the goat with him and leaves it on the other side of the river. Then he comes back to the side of the river where he left the wolf and cabbage together. He then takes the cabbage with him. When he reaches the other side, he leaves the cabbage and brings the goat back with him. Then he leaves the goat and takes the wolf with him. He then drops the wolf off with the cabbage and finally comes back for the goat. So this way, the farmer avoids leaving the goat and the cabbage or the wolf and the goat together unattended.

There is an alternate solution. The farmer first takes the goat with him and leaves it on the other side. Then he comes back and gets the wolf. He leaves the wolf on the other side, and brings back the goat. Then he leaves the goat and brings the cabbage with him. He then leaves the cabbage with the wolf and comes back to get the goat.

Know any similar puzzles? Feel free to share them in our comments section!

If you're looking for some serious preparation for your interviews, I'd recommend this book written by a lead Google interviewer. It has 189 programming questions and solutions:

## 2 Responses

1. John says:

This puzzle is very interesting, the first step is obvious as the goat is in the middle of link, the next step is to swap the two groups: goat, wolf and cabbage, this step is a little tricky as you need think of the process of bringing back or exchange. Finally, put them together.

2. Mark says:

Not sure why he bought a wolf.

XHTML: These are some of the tags you can use: `<a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>`