I have learned graph theory, and am using it to solve the classic Fox, goose and bag of beans puzzle. If we consider that there are three locations for each of the fox (X), goose (G), farmer (F) and beans (B) (near side of river, in the boat, far side of the river), and there are four characters, there are hence 4^3 = 81 combinations. Two of these combinations would be
(Near) (Boat) (Far)
F,G,B,X - -
(Near) (Boat) (Far)
B,X F,G -
...for the starting state and the state when the farmer and the goose have entered the boat respectively.
I want to generate all of these states programatically (in C++, but that is beyond the point), but simply cannot get my head around how to do it. (I know that some of these 81 possible states will be invalid (e.g. that with all characters in the boat at once) but I can search for those and remove them afterwards.)
I am well aware of binary and how I get 81 combinations, and am aware using C++ I could generate all combinations of the characters F,G,X,B, but still cannot figure how to add the three "locations" into this.
Can someone please advise?