Jelly, 40 32 bytes
1SÆD>Ðḟ½ƊṀṭƲ³¡Äż$Ḷ:Ḃ^þ`ʋ/€Ṛṛ""/Y
A full program taking the zero-indexed \$S-1\$ as input and writing to stdout ASCII art using 0 = #, 1 = +.
Without the trailing Y
, this returns a list of lists of integers, but this is out of spec for this challenge.
Explanation
This program works in three stages.
- Generate a list of values of \$k\$ and the cumulative sum of \$k\$
- Generate a checkerboard for each of these with the tile size of \$k\$ and the board size of the cumulative sum
- Work backwards through the list of checkerboards, each time replacing the top-left section of the board with the new, smaller board.
Stage 1
1 | Start with 1
Ʋ³¡ | Loop through the following the number of times indicated by the first argument to the program; this generates a list of values of k
S | - Sum
Ɗ | - Following three links as a monad
ÆD | - List of divisors
>Ðḟ½ | - Exclude those greater than the square root
Ṁ | - Maximum
ṭ | - Concatenate this to the end of the current list of values of k
Äż$ | Zip the cumulative sum of the values of k with the values
Stage 2
ʋ/€ | For each pair of k and cumulative sum, call the following as a dyad with the cumulative sum of k as the left argument and k as the right (e.g. 15, 3)
Ḷ | - Lowered range [0, 1 ... , 13, 14]
: | - Integer division by k [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]
Ḃ | - Mod 2 [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]
^þ` | - Outer product using xor function and same argument to both side
Stage 3
Ṛ | Reverse list
/ | Reduce using the following:
ṛ"" | - Replace the top left portion of the current matrix with the next one
Y | Finally join by newlines