A snake is defined as a path around a two dimensional grid which touches each square exactly once by repeatedly moving one up/down/left/right, starting at the square (0, 0). Below is an example of one snake of a 3x4 grid:
0 1 2 3
7 6 5 4
8 9 10 11
For any positive integer N, there are N snakes which occupy a 2xN grid. For example, the snakes of a 2x6 grid are:
Or, as 2x6 number grids:
0 1 2 3 4 5 0 3 4 11 10 9
11 10 9 8 7 6 1 2 5 6 7 8
0 11 10 9 8 7 0 3 4 7 8 9
1 2 3 4 5 6 1 2 5 6 11 10
0 3 4 5 6 7 0 3 4 7 8 11
1 2 11 10 9 8 1 2 5 6 9 10
Given N, output all N snakes of the 2xN grid. The output can have any shape (i.e. it can be flattened however you want). The snakes may start at 1 rather than 0. The snakes may be of the transposed (Nx2) grid. The N snakes may be in any order.
As an alternative output format, you may represent each snake as an ordered list of coordinate pairs.
In the following test cases, the snakes are separated by semicolons, the two rows of a snake are separated by a comma, and each number is separated by a space.
1 -> 0,1
2 -> 0 1,3 2;0 3,1 2
3 -> 0 1 2,5 4 3;0 5 4,1 2 3;0 3 4,1 2 5
4 -> 0 1 2 3,7 6 5 4;0 7 6 5,1 2 3 4;0 3 4 5,1 2 7 6;0 3 4 7,1 2 5 6
5 -> 0 1 2 3 4,9 8 7 6 5;0 9 8 7 6,1 2 3 4 5;0 3 4 5 6,1 2 9 8 7;0 3 4 9 8,1 2 5 6 7;0 3 4 7 8,1 2 5 6 9
6 -> 0 1 2 3 4 5,11 10 9 8 7 6;0 11 10 9 8 7,1 2 3 4 5 6;0 3 4 5 6 7,1 2 11 10 9 8;0 3 4 11 10 9,1 2 5 6 7 8;0 3 4 7 8 9,1 2 5 6 11 10;0 3 4 7 8 11,1 2 5 6 9 10
7 -> 0 1 2 3 4 5 6,13 12 11 10 9 8 7;0 13 12 11 10 9 8,1 2 3 4 5 6 7;0 3 4 5 6 7 8,1 2 13 12 11 10 9;0 3 4 13 12 11 10,1 2 5 6 7 8 9;0 3 4 7 8 9 10,1 2 5 6 13 12 11;0 3 4 7 8 13 12,1 2 5 6 9 10 11;0 3 4 7 8 11 12,1 2 5 6 9 10 13
