Use this example and compare it with other devices in the Press On JavaScript framework. This web page also provides a Mathematica definition of the farmer problem.
The diagrams for the farmer's problem in Press On were in fact generated using MetaPost; see later in this page for the MetaPost diagram used for the book.
// Code in support of Press On, MIT Press, 2007 (c) harold@thimbleby.net // farmer's problem JSON specification - which you can cut-and-paste into the framework { notes: "Farmer problem with wolf, goats and cabbage. States are named using the letters fwgc for farmer, wolf, goat and cabbage, one either side of ~ representing the river; thus fw ~ g is a state where farmer and wolf are one side, the goat the other, and the cabbage has long since been eaten.<p>The definition of the problem was generated by a <a href=farmer.html>JavaScript program</a>.",
modelType: "Farmer problem",
startState: 0,
state: 0,
action: ["row", "rowed", "rowing"],
errors: "never",
graphics: "",