Given an a-by-b sized grid, and a chess knight, determine:
- A starting point and path the knight can take to visit every square in the grid
- or "NOT POSSIBLE", if not possible.
Input: Two integers,
Output: Numbers output in an a-by-b grid:
1 4 7 10 8 11 2 5 3 6 9 12
1 is where the knight starts,
a*b is where the knight ends, and the numbers signify the path the knight must take, in ascending order. The knight cannot land on the same square twice.
The rows of the grid must be separated with a newline, and the items in each row must be separated with a space.
| is a newline.
3 4 -> 1 4 7 10 | 8 11 2 5 | 3 6 9 12
2 3 -> NOT POSSIBLE
If there is a solution there will be more than one: any valid solution is acceptable.
Shortest code wins. Please do not use any programming languages that are known to produce short programs: e.x. GolfScript, APL, J, K, etc.