/awk-wolfgoatcabbage

gawk brain teaser

Primary LanguageAwk

awk-wolfgoatcabbage

from https://illuminations.nctm.org/BrainTeasers.aspx?id=4992

Wolf Goat Cabbage

The Wolf, Goat, and Cabbage

This problem can be found in eighth-century writings.

A man has to take a wolf, a goat, and some cabbage across a river. His rowboat has enough room for the man plus either the wolf or the goat or the cabbage. If he takes the cabbage with him, the wolf will eat the goat. If he takes the wolf, the goat will eat the cabbage. Only when the man is present are the goat and the cabbage safe from their enemies. All the same, the man carries wolf, goat, and cabbage across the river. How?

Not sure where I got this idea from, but it has a nifty use of gawk 4.1's SYMTAB[] in here:

https://www.gnu.org/software/gawk/manual/html_node/Auto_002dset.html#index-SYMTAB-array