http://www.perlmonks.org?node_id=1123492


in reply to Re: perl array matrix
in thread perl array matrix

How to convert the following concept into the code:

1. Create a mapping from numbers to start positions: Hash of Number to Array of Position.

2. Create a neighbor mapping for all positions: Hash of Position to (Hash of Number to Array of Position) -- or just Hash of Number to Position if you can only have one neighbor with that number.

3. For each search string: initialize position possibilities to the array returned by the start mapping.

Iterate through remaining numbers, getting next position set from the neighbor mapping for the possibilities.

If you have no position possibilities left, it's not a match.