body, html {font-family: 'Open Sans', sans-serif;} #nav a, #nav{font-family: 'Open Sans', sans-serif;} #title #tagline {font-family: 'Open Sans', sans-serif;} #main .gridItem h3 {font-family: 'Open Sans', sans-serif;}

22nd JC: Crossing the River


This brain teaser is quite well known in Germany: A farmer is reaching a river together with a wolf, a sheep and a cabbage. He, the wolf, the sheep and the cabbage must cross the river. There’s a boat available but the problem is, that there’re some conditions:

  • The boat is so small that only 2 can be onboard.
  • The farmer is the only one, who can steer the boat.
  • The farmer can’t leave the wolf and the sheep alone, because the wolf will eat the sheep.
  • The same with the sheep and the cabbage, because the sheep would eat the cabbage.

But there’s still a solution. The aim of the cache is to find it.

Dave Wagner built a great cache with a boat moving. Watch the video below:

it was clear for me, to build cache based on this brainteaser also. But not a mechanical one, but all displayed on a LCD screen.

Sounds quite easy, but it wasn’t. Let me explain what was the main challenge: It was the move of a figure depending on the current location and the direction of the boat. Let’s take the following example:

  • Boat_Direction can be 0 (boat will move left to right) or 1 ( right to left).
  • The location of a figure (let’s take the farmer as example) can be
    • 0 = on the left shore
    • 1 = inside the boat at the left shore
    • 2 = moving with the boat across the river
    • 3 = inside the boat at the right shore
    • 4 = on the right shore

Let’s assume Boat_direction is 0 (left to right) and Position_Farmer = 0. Pressing the Button of the farmer will move the farmer into the boat (position = 1). Pressing the button again, will move the farmer back to the left shore (position = 0). If the farmer is on board (position = 1) and pressing the start button will change the position to 2. The Farmer arives at the right shore and the position becomes 3. When pressing the button of the farmer again, the farmer will leave the boat and stay on the right shore (position = 4). 
So after crossing the river the position is changing from 2 to 3. But when the boat is moving from the right to the left the position must change from 2 to 1.

When Boat_direction is 0 (left to right) and the position is 1 (inside the boat at the left shore), pressing the button of the farmer means go back (!) to the left shore (position is decreasing from 1 to 0), but if the position is 3 (inside the boat on the right shore) it means going forward onto the right shore. But if Boat_direction is 1 (moving from right to left), it’s just the other way round…

It took a lot of thinking, try on error and test prints onto the serial monitor, up I got it working.

Here’s a short video of the prototype:

As ever: By clicking on the YouTube button, you can watch in 1080p quality…

The sketch will be soon available for download here...

©  Olaf Goette 2008 - 2018