Você está na página 1de 9

9.

River-Crossing Puzzles

Robert Snapp
snapp@cs.uvm.edu

Department of Computer Science


University of Vermont

Robert R. Snapp © 2012 9. River-Crossing Puzzles CS 32, Fall 2012 1/9


Alcuin’s Farmer-Wolf-Goat-Cabbage Puzzle

Propositio de lupo et capra et fasciculo cauli:


Homo quidam debebat ultra flavium transferre lupum, capram, et fasciculum cauli.
Et non potuit aliam navem invenire, nisi quae duos tantum ex ipsis ferre valebat.
Praeceptum itaque ei fuerat ut omnia haec ultra illaesa omnino transferret. Dicat,
qui potest, quomodo eis illaesis transire potuit.

So reads the Latin text written by the eighth-century Catholic monk and educator,
Acluin of York, which stands as problem 18 (of 53) in his Propositiones ad acuendos
juvenes, or Propositions to Sharpen the Young. In the year 781, Alcuin was invited by
Charlemagne to teach at the palace school in Aachen. Some historians credit
Alcuin’s pedagogy for the foundation for the earliest European universities.
The above puzzle represents one of Alcuin’s most famous problems. Hadley and
Singmaster’s translation follows:

Proposition of a wolf, a goat and a bunch of cabbages:


A man had to take a wolf, a goat and a bunch of cabbages across a river. The only
boat he could find could only take two of them at a time. But he had been ordered
to transfer all of these to the other side in good condition. How could this be done?

Robert R. Snapp © 2012 9. River-Crossing Puzzles CS 32, Fall 2012 2/9


Farmer-Wolf-Goat-Cabbage Puzzle
The following diagram epresents the initial state, with the Farmer, Wolf, Goat, and
Cabbages, each represented by its first initial (F, W, G, C) on the left bank of the river.
Note that the Farmer must pilot the boat in each direction, and can carry at most one
the other item. However, if the farmer abandons the Goat with the Cabbage, or the
Wolf with the Goat, something will get eaten. Can you find a sequence of moves that
will safely bring the Farmer, Wolf, Goat, and Cabbage to the opposite bank of the
river?

F
W
G
C

Robert R. Snapp © 2012 9. River-Crossing Puzzles CS 32, Fall 2012 3/9


State representation

We will define a state of the puzzle by the locations of the Farmer (F), the Wolf (W),
the Goat (G), and the Cabbages (C). After each crossing of the boat, each entity
must be either on the left bank, or on the right bang. By applying the multiplication
principle, we find that the number of states equals

nF  nW  nG  nC D 2  2  2  2 D 16:

Each state can be represented in nested-list notation, using two sub-lists: the first
sub-list describes the entities on the left bank, while the second denotes those
entities on the right bank. Thus the initial state is denoted by

((F W G C) ()):

and the goal state, by


(() (F W G C)):
Note that the order within each sub-list is not important.

Robert R. Snapp © 2012 9. River-Crossing Puzzles CS 32, Fall 2012 4/9


Building the State Transition Graph
Which moves are possible from the initial state ..F W G C / .//? Either the Farmer
crosses the river alone by himself, or with one of his three possessions. Thus there
are four possible moves, which we represent by the resulting state:
1 ((W G C) (F)).
2 ((G C) (F W)).
3 ((W C) (F G)).
4 ((W G) (F C)).
In the above, safe states appear in blue, and lethal states in red. For example, State
2 is lethal because the Goat can eat the Cabbages.
We can now begin to construct the state transition graph, which when completed will
contain one node for each of the sixteen possible states of the puzzle. Its edges will
connect each pair of states that are accessible to each another by a single move.

((FWGC) ())

((GC) (FW)) ((WGC) (F)) ((WC) (FG)) ((WG) (FC))

Robert R. Snapp © 2012 9. River-Crossing Puzzles CS 32, Fall 2012 5/9


The State Transition Graph
By continuing the expansion process, and carefully accounting for each state and
transition, we obtain the following state transition graph.
((FWGC) ())

((WGC) (F)) ((WC) (FG))


((GC) (FW)) ((FWC) (G)) ((WG) (FC))

((C) (FWG)) ((W) (FCG))

((FC) (WG)) ((FW) (CG))

(() (FWCG))
((FGC) (W)) ((FWG) (C))
((FG) (WC)) ((F) (WCG))

((G) (FWC))

Note that the puzzle has two solutions of minimal length; each requires seven moves.

Robert R. Snapp © 2012 9. River-Crossing Puzzles CS 32, Fall 2012 6/9


Applying Trémaux’s Algorithm
As was the case for our graph of the Hampton Court maze, the paths that represent
the two solutions to Alcuin’s puzzle are conspicuous. In any event, it is possible to
discover at least one of them by applying Trémaux’s algorithm to the graph, treating
lethal states as dead ends, and safe states of degree 3 or higher as junctions. For
example, a left-bearing mouse following Trémaux’s rules would label the edges of the
state transition graph as follows: ((FWGC) ())

N2 N1

((WGC) (F)) ((WC) (FG))

X3
((FWC) (G))
((GC) (FW)) N4 ((WG) (FC))
N17
N16 X5
X15((C) (FWG)) ((W) (FCG)) N6
N18

((FC) (WG)) ((FW) (CG))

N13 N8
N14 X7
(() (FWCG))
((FGC) (W)) X12 N9 ((FWG) (C))
((FG) (WC))
((F) (WCG))

N11N19
X10
((G) (FWC))

Robert R. Snapp © 2012 9. River-Crossing Puzzles CS 32, Fall 2012 7/9


The Missionaries and the Cannibals
Three missionaries (M) and three cannibals (C) must cross a river using a boat that
can at most hold two passengers. If ever the number of cannibals exceeds the
number of missionaries on either bank, then those missionaries will be consumed.

MC
MC
MC

Here it is advantageous to represent each state by a list of three numbers, which we


lablel .m c b/. Here m, c , and b denote the number of missionaries, cannibals, and
boats on the original bank, respectively. Note that (assuming that nobody gets eaten)
the number of missionaries, cannibals, and boats on the destination bank are
likewise 3 m, 3 c and 1 b .
Thus the initial state is .3 3 1/ and the goal state, .0 0 0/. How many states are
there? How many of these are “safe?” Construct a state transition graph and solve
the puzzle.
Robert R. Snapp © 2012 9. River-Crossing Puzzles CS 32, Fall 2012 8/9
References

1 Saul Amarel, “On representations of problems of reasoning about action,” in


Donald Michie, ed., Machine Intelligence, 3, Edinburgh University Press, 1971,
pp. 131–171.
2 John Hadley and David Singmaster, “Problems to Sharpen the Young,” from The
Use of the History of Mathematics in the Teaching of Mathematics, The
Mathematics Gazette, 76 (475), 1992, pp. 102–126.
3 W. S. Howell, The Rhetoric of Alcuin and Charlemagne, Russell & Russell, New
York, 1965.
4 A. F. West, Alcuin and the Rise of the Christian Schools, Scribner’s Sons, New
York, 1909.

Robert R. Snapp © 2012 9. River-Crossing Puzzles CS 32, Fall 2012 9/9

Você também pode gostar