/cows_in_the_maze_puzzle

Solve the "Cows in the Maze" puzzle from "Mathematical Recreations", Scientific American 1996-12

Primary LanguageC++The UnlicenseUnlicense

"Cows in the Maze" puzzle solver

What is this

Solve the "Cows in the Maze" puzzle from the section "Mathematical Recreations" of Scientific American, December 1996.

The puzzle originally appeared in Robert Abbott's book Supermazes (Prima Publishing, Rocklin, California, 1996) (review). There is a Wikipedia reference for this puzzle. The author of this "Mathematical Recreations" installment, University of Warwick Mathematics Professor Ian Stewart, has written a book with the eponymous title "Cows in the Maze".

This is an early coding effort, written in December 1996. In C++. Today I would do it in Prolog. I had modernize it a bit so that it compiles with GNU C++ Compiler.

Here is the relevant page from Scientific American.

The task is:

  • You have two pencils.
  • One pencil starts in box 1, one in box 7.
  • Following the (nondeterministic) instructions so that at least one of the pencils ends up in the box labeled GOAL.

Extract from Scientific American

The solution

(.., 1, 7, )
(m., 2, 7, )
(m.,15, 7, )
(m.,40, 7, )
(m.,60, 7, )
(.m,60, 5, )
(m.,25, 5,*)
(m., 7, 5,*)
(m.,26, 5,*)
(m.,61, 5,*)
(.m,61, 2,*)
(.m,61,15,*)
(.m,61,40,*)
(.m,61,65,*)
(.m,61,75, )
(mm, 1, 1, )
(m., 9, 1, )
(m.,35, 1, )
(.m,35, 9, )
(.m,35,35, )
(m.,40,35, )
(m.,60,35, )
(m.,25,35,*)
(m., 7,35,*)
(m.,26,35,*)
(m.,61,35,*)
(m., 1,35,*)
(m., 9,35,*)
Goal state encountered at (m., 2,35,*)