Algorithm

The method involves the square formats in terms of symmetric sub-rectangles. The steps are:

  1. List the "first level" or unnested rectangle formats.
  2. Traverse the list adding formats for the next level nested rectangles.
  3. Repeat 2 until formats for all levels of nesting are added.
  4. For each format, recursively fill the rectangles with sequential numbers.

Details

The implementation is in Reversible.cpp

Rectangles are defined by the number of columns and rows. The formats are listed in an array separated by (0 0). (For convenience two arrays are used. One array is copied to the other when adding new formats.)

Examples

The format arrays for orders 4 to 16 are, (columns rows):


      order 4       order 8          order 12            order 16
    ----------- ---------------  ----------------  ---------------------
     (0 0)       (0 0)            (0 0)             (0 0)
 1:  (4 4)(0 0)  (8 8)(0 0)       (12 12)(0 0)      (16 16)(0 0)
 2:  (2 2)(0 0)  (4 2)(0 0)       (6 2)(0 0)        (8 2)(0 0)
 3:  (2 4)(0 0)  (4 4)(0 0)       (6 3)(0 0)        (8 4)(0 0)
 4:  (0 0)       (4 8)(0 0)       (6 4)(0 0)        (8 8)(0 0)
 5:              (2 2)(0 0)       (6 6)(0 0)        (8 16)(0 0)
 6:              (2 2)(4 4)(0 0)  (6 12)(0 0)       (4 2)(0 0)
 7:              (2 2)(4 8)(0 0)  (4 2)(0 0)        (4 2)(8 4)(0 0)
 8:              (2 4)(0 0)       (4 3)(0 0)        (4 2)(8 8)(0 0)
 9:              (2 4)(4 8)(0 0)  (4 4)(0 0)        (4 2)(8 16)(0 0)
10:              (2 8)(0 0)       (4 6)(0 0)        (4 4)(0 0)
11:              (0 0)            (4 12)(0 0)       (4 4)(8 8)(0 0)
12:                               (3 2)(0 0)        (4 4)(8 16)(0 0)
13:                               (3 2)(6 4)(0 0)   (4 8)(0 0)
14:                               (3 2)(6 6)(0 0)   (4 8)(8 16)(0 0)
15:                               (3 2)(6 12)(0 0)  (4 16)(0 0)
16:                               (3 3)(0 0)        (2 2)(0 0)
17:                               (3 3)(6 6)(0 0)   (2 2)(8 4)(0 0)
18:                               (3 3)(6 12)(0 0)  (2 2)(8 8)(0 0)
19:                               (3 4)(0 0)        (2 2)(8 16)(0 0)
20:                               (3 4)(6 12)(0 0)  (2 2)(4 4)(0 0)
21:                               (3 6)(0 0)        (2 2)(4 4)(8 8)(0 0)
22:                               (3 6)(6 12)(0 0)  (2 2)(4 4)(8 16)(0 0)
23:                               (3 12)(0 0)       (2 2)(4 8)(0 0)
24:                               (2 2)(0 0)        (2 2)(4 8)(8 16)(0 0)
25:                               (2 2)(6 4)(0 0)   (2 2)(4 16)(0 0)
26:                               (2 2)(6 6)(0 0)   (2 4)(0 0)
27:                               (2 2)(6 12)(0 0)  (2 4)(8 8)(0 0)
28:                               (2 2)(4 4)(0 0)   (2 4)(8 16)(0 0)
29:                               (2 2)(4 6)(0 0)   (2 4)(4 8)(0 0)
30:                               (2 2)(4 12)(0 0)  (2 4)(4 8)(8 16)(0 0)
31:                               (2 3)(0 0)        (2 4)(4 16)(0 0)
32:                               (2 3)(6 6)(0 0)   (2 8)(0 0)
33:                               (2 3)(6 12)(0 0)  (2 8)(8 16)(0 0)
34:                               (2 3)(4 6)(0 0)   (2 8)(4 16)(0 0)
35:                               (2 3)(4 12)(0 0)  (2 16)
36:                               (2 4)(0 0)        (0 0)
37:                               (2 4)(6 12)(0 0)
38:                               (2 4)(4 12)(0 0)
39:                               (2 6)(0 0)
40:                               (2 6)(6 12)(0 0)
41:                               (2 6)(4 12)(0 0)
42:                               (2 12)
                                  (0 0) 

The order 16 format (2 4)(4 8)(8 16)(0 0) means fill the square with 8x16 rectangles, each filled with 4x8 rectangles, each filled with 2x4 rectangles. Rectangles are filled left to right, top to bottom.