The farmer problem: JSON, MetaPost and Mathematica

This HTML file contains a JavaScript program that generates the framework specification for the Farmer's problem of moving goat, cabbage and wolf across a river (use your browser's View Source to see the JavaScript). The problem is from Press On.

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.

JSON for the farmer's problem

// 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: "",