A classic logic puzzle.

A farmer has a fox, a chicken and a bag of grain. Left alone without the farmer, the fox would eat the chicken and the chicken would eat the grain. The farmer must transport all three to the other side of a river but can only take one item in his rowboat at a time. How does he get all three to the other side? In this puzzle, the position of the fox, chicken, grain and farmer can be represented with a number. Zero means they are on this side of the river, or one which means they are on the other side of the river. E.g. `farmer = 0` Means assign the farmer to be on this side of the river. `grain = 1` Means assign the grain to be on the other side of the river.

Fox, chicken, grain

Assessment

These objectives get progressively harder. Attempt as much of the program as you can in the order presented below. Remember to use a comment to describe a subprogram, selection or iteration.

Success Criteria

Initialising the variables

In the main program:

3 marks

The output should now look like this:

A fox, chicken and a bag of grain wait by the side of a river.
Which item will you take in your rowboat to the other side?
fox, chicken, grain or farmer?
Choose:

Row across the river

In the main program write selection statements to change the variables:

4 marks

Show the state of the game

Note, if you are not confident with subprograms you can do this in the main program instead.

4 marks

The output should now look like this:

A fox, chicken and a bag of grain wait by the side of a river.
Which item will you take in your rowboat to the other side?
fox, chicken, grain or farmer?
Choose: chicken
-----------------------
This side of the river:
Fox
Grain

The other side of the river:
Farmer
Chicken
-----------------------

Losing the puzzle

Note, if you are not confident with subprograms you can do this in the main program instead.

5 marks

The output should now look like this:

A fox, chicken and a bag of grain wait by the side of a river.
Which item will you take in your rowboat to the other side?
fox, chicken, grain or farmer?
Choose: grain
-----------------------
This side of the river:
Fox
Chicken

The other side of the river:
Farmer
Grain
-----------------------
The fox ate the chicken.

Apply the logic to the other side of the river:

2 marks

Puzzle is solved

Note, if you are not confident with subprograms you can do this in the main program instead.

5 marks

Good programming practices

2 marks

Maximum mark: 25

If you score less than 20 you need more practice at levels 1-3 before you continue to the next level.