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.
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 subpprogram, selection or iteration.
Use this boilerplate code as a starting point:
In the main program:
3 marks
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:
In the main program write selection statements to change the variables:
4 marks
Note, if you are not confident with subprograms you can do this in the main program instead.
4 marks
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
-----------------------
Note, if you are not confident with subprograms you can do this in the main program instead.
5 marks
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.
2 marks
Note, if you are not confident with subprograms you can do this in the main program instead.
5 marks
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.
Use these resources as a reference to help you meet the success criteria.
Run the unit tests below to check that your program has met the success criteria.
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: fox
-----------------------
This side of the river:
Chicken
Grain
The other side of the river:
Farmer
Fox
-----------------------
The chicken ate the grain.
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.
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
-----------------------
Which item will you take in your rowboat to the other side?
fox, chicken, grain or farmer?
Choose: farmer
-----------------------
This side of the river:
Farmer
Fox
Grain
The other side of the river:
Chicken
-----------------------
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
The other side of the river:
Farmer
Chicken
Grain
-----------------------
Which item will you take in your rowboat to the other side?
fox, chicken, grain or farmer?
Choose: chicken
-----------------------
This side of the river:
Farmer
Fox
Chicken
The other side of the river:
Grain
-----------------------
Which item will you take in your rowboat to the other side?
fox, chicken, grain or farmer?
Choose: fox
-----------------------
This side of the river:
Chicken
The other side of the river:
Farmer
Fox
Grain
-----------------------
Which item will you take in your rowboat to the other side?
fox, chicken, grain or farmer?
Choose: farmer
-----------------------
This side of the river:
Farmer
Chicken
The other side of the river:
Fox
Grain
-----------------------
Which item will you take in your rowboat to the other side?
fox, chicken, grain or farmer?
Choose: chicken
-----------------------
This side of the river:
The other side of the river:
Farmer
Fox
Chicken
Grain
-----------------------
You solved the puzzle.