in reply to How implement AMB in perl?

I know that this is not why you posted but I couldn't resist pointing out that the Games::LogicPuzzle module was built to solve these types of puzzles.

You might want to look and see how it works in th general case.

--
Clayton