Warped chessboard

20

1

This challenge is about building a chessboard in which the square size, instead of being constant across the board, follows a certain non-decreasing sequence, as described below.

The board is defined iteratively. A board of size \$n \times n\$ is enlarged to size \$(n+k)\times(n+k)\$ by extending it down and to the right by a "layer" of squares of size \$k\$, where \$k\$ is the greatest divisor of \$n\$ not exceeding \$\sqrt{n}\$. The squares in the diagonal are always of the same colour.

Specifically, consider the board with colours represented as # and +.

  1. Initialize the chessboard to

    #
    
  2. The board so far has size \$1\times 1\$. The only divisor of \$1\$ is \$1\$, and it does not exceed \$\sqrt{1}\$. So we take \$k=1\$, and extend the board by adding a layer of squares of size \$1\$, with # in the diagonal:

    #+
    +#
    
  3. The board built so far has size \$2 \times 2\$. The divisors of \$2\$ are \$1,2\$, and the maximum divisor not exceeding \$\sqrt{2}\$ is \$1\$. So again \$k=1\$, and the board is extended to

    #+#
    +#+
    #+#
    
  4. Size is \$3 \times 3\$. \$k=1\$. Extend to

    #+#+
    +#+#
    #+#+
    +#+#
    
  5. Size is \$4 \times 4\$. Now \$k=2\$, because \$2\$ is the maximum divisor of \$4\$ not exceeding \$\sqrt 4\$. Extend with a layer of thickness \$2\$, formed by squares of size \$2\times 2\$, with colour # in the diagonal:

    #+#+##
    +#+###
    #+#+++
    +#+#++
    ##++##
    ##++##
    
  6. Size is \$6 \times 6\$. Now \$k=2\$. Extend to size \$8 \times 8\$. Now \$k=2\$. Extend to size \$10 \times 10\$. Now \$k=2\$. Extend to size \$12 \times 12\$. Now \$k=3\$. Extend to size \$15\$:

    #+#+##++##++###
    +#+###++##++###
    #+#+++##++#####
    +#+#++##++##+++
    ##++##++##+++++
    ##++##++##+++++
    ++##++##++#####
    ++##++##++#####
    ##++##++##++###
    ##++##++##+++++
    ++##++##++##+++
    ++##++##++##+++
    ###+++###+++###
    ###+++###+++###
    ###+++###+++###
    

Note how the most recently added squares, of size \$3 \times 3\$, have sides that partially coincide with those of the previously added squares of size \$ 2 \times 2 \$.

The sequence formed by the values of \$k\$ is non-decreasing:

1 1 1 2 2 2 2 3 3 3 3 4 4 4 6 6 6 6 6 6 ...

and does not seem to be in OEIS. However, its cumulative version, which is the sequence of sizes of the board, is A139542 (thanks to @Arnauld for noticing).

The challenge

Input: a positive integer \$S\$ representing the number of layers in the board. If you prefer, you may also get \$S-1\$ instead of \$S\$ as input (\$0\$-indexed); see below.

Output: an ASCII-art representation of a board with \$S\$ layers.

  • Output may be through STDOUT or an argument returned by a function. In this case it may be a string with newlines, a 2D character array or an array of strings.

  • You can consistently choose any two characters for representing the board.

  • You can consistently choose the direction of growth. That is, instead of the above representations (which grow downward and rightward), you can produce any of its reflected or rotated versions.

  • Trailing or leading space is allowed (if output is through STDOUT), as long as space is not one of the two characters used for the board.

  • You can optionally use "\$0\$-indexed" input; that is, take as input \$S-1\$, which specifies a board with \$S\$ layers.

Shortest code in bytes wins.

Test cases

1:

#

3:

#+#
+#+
#+#

5:

#+#+##
+#+###
#+#+++
+#+#++
##++##
##++##

6:

#+#+##++
+#+###++
#+#+++##
+#+#++##
##++##++
##++##++
++##++##
++##++##

10:

#+#+##++##++###+++
+#+###++##++###+++
#+#+++##++#####+++
+#+#++##++##+++###
##++##++##+++++###
##++##++##+++++###
++##++##++#####+++
++##++##++#####+++
##++##++##++###+++
##++##++##+++++###
++##++##++##+++###
++##++##++##+++###
###+++###+++###+++
###+++###+++###+++
###+++###+++###+++
+++###+++###+++###
+++###+++###+++###
+++###+++###+++###

15:

#+#+##++##++###+++###+++####++++####
+#+###++##++###+++###+++####++++####
#+#+++##++#####+++###+++####++++####
+#+#++##++##+++###+++#######++++####
##++##++##+++++###+++###++++####++++
##++##++##+++++###+++###++++####++++
++##++##++#####+++###+++++++####++++
++##++##++#####+++###+++++++####++++
##++##++##++###+++###+++####++++####
##++##++##+++++###+++#######++++####
++##++##++##+++###+++#######++++####
++##++##++##+++###+++#######++++####
###+++###+++###+++###+++++++####++++
###+++###+++###+++###+++++++####++++
###+++###+++###+++###+++++++####++++
+++###+++###+++###+++###++++####++++
+++###+++###+++###+++#######++++####
+++###+++###+++###+++#######++++####
###+++###+++###+++###+++####++++####
###+++###+++###+++###+++####++++####
###+++###+++###+++###+++++++####++++
+++###+++###+++###+++###++++####++++
+++###+++###+++###+++###++++####++++
+++###+++###+++###+++###++++####++++
####++++####++++####++++####++++####
####++++####++++####++++####++++####
####++++####++++####++++####++++####
####++++####++++####++++####++++####
++++####++++####++++####++++####++++
++++####++++####++++####++++####++++
++++####++++####++++####++++####++++
++++####++++####++++####++++####++++
####++++####++++####++++####++++####
####++++####++++####++++####++++####
####++++####++++####++++####++++####
####++++####++++####++++####++++####

25:

#+#+##++##++###+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+#+###++##++###+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
#+#+++##++#####+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+#+#++##++##+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
##++##++##+++++###+++###++++####++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
##++##++##+++++###+++###++++####++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++##++##++#####+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
++##++##++#####+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
##++##++##++###+++###+++####++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
##++##++##+++++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
++##++##++##+++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
++##++##++##+++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
+++###+++###+++###+++###++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
+++###+++###+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+++###+++###+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
###+++###+++###+++###+++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
###+++###+++###+++###+++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
###+++###+++###+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++####++++####++++####++++####++++++++++######++++++######++++++##############++++++++########++++++++########++++++++
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########

Luis Mendo

Posted 2019-05-17T18:31:40.367

Reputation: 87 464

Is an integer matrix permitted as output (e.g. 0s and 1s), or does it have to be strings/characters? – Nick Kennedy – 2019-05-18T04:07:38.573

@Nick It has to be chars, sorry – Luis Mendo – 2019-05-18T08:47:54.720

2Very well-written question! – Greg Martin – 2019-05-18T17:25:00.733

@GregMartin Hey, thanks! – Luis Mendo – 2019-05-18T17:44:20.327

Answers

3

Jelly, 40 31 bytes

1SÆD>Ðḟ½ƊṀṭƲ³¡Äż$Ḷ:Ḃ^þ`ʋ/€ḷ""/Y

Try it online!

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.

  1. Generate a list of values of \$k\$ and the cumulative sum of \$k\$
  2. Generate a checkerboard for each of these with the tile size of \$k\$ and the board size of the cumulative sum
  3. Work through the list of checkerboards, each time replacing the top-left section of the next board with the existing 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

   /  | Reduce using the following:
ḷ""   | - Replace the top left portion of the next matrix with the current one
    Y | Finally join by newlines

Nick Kennedy

Posted 2019-05-17T18:31:40.367

Reputation: 11 829

I think the asker actually wants the # and + characters. But wow, still impressive, I understood about half of it. And how do you even program in such a language? Is there a table of characters and their meaning where you just copy from? – Fabian Röling – 2019-05-18T22:36:26.143

@FabianRöling The OP states any two characters were acceptable. There’s a good introductory tutorial for Jelly at the https://github.com/DennisMitchell/jelly. If you know Python, the source is also fairly readable. Even with the tutorial and lists of atoms and Quicks, I found it took a little time and in some cases reference to the source to get my head round it.

– Nick Kennedy – 2019-05-19T00:35:16.120

6

Canvas, 34 32 bytes

0#0⁸[#+¶+#xx*yx+m⤢αm;nlw√{y;%‽²X

Try it here!

dzaima

Posted 2019-05-17T18:31:40.367

Reputation: 19 048

Input can now be 0-indexed; in case that helps – Luis Mendo – 2019-05-17T20:58:55.190

4

Python 2, 217 215 212 bytes

def f(x):
 b=['1'];n=1
 for i in range(x):P=max(j*(n%j<(j<=n**.5))for j in range(1,1+n));n+=P;b=[l+P*`j/P%2^i%2`for j,l in enumerate(b)];s=len(b[0]);b+=[((v*P+`1^int(v)`*P)*s)[:s]for v in b[0][len(b):]]
 return b

Try it online!

0-indexed, uses 0 and 1 as characters

Rod

Posted 2019-05-17T18:31:40.367

Reputation: 17 588

1@LuisMendo saved 2 bytes :D – Rod – 2019-05-21T12:41:02.433

3

Python 2, 184 178 176 169 bytes

def h(j,a=['1'],R=range):
 for i in R(j):L=len(a);k=max(x for x in R(1,L+1)if(x*x<=L)>L%x);a=[a[m]+k*`(i+m/k)%2`for m in R(L)]+[((`i%2`*k+`~i%2`*k)*L)[:L+k]]*k
 return a

Try it online!

Uses 1, 0 for #, -; uses 0-indexing.

Chas Brown

Posted 2019-05-17T18:31:40.367

Reputation: 8 959

2

JavaScript (ES7), 164 bytes

Input is 0-indexed. Outputs a matrix with \$0\$ for # and \$1\$ for +.

n=>(b=[1],g=(a,w,d=w**.5|0)=>b[n]?a:w%d?g(a,w,d-1):g(a.concat(Array(d).fill(b.push(d)&&i++)),w+d))([0],i=1).map((_,y,a)=>a.map((_,x)=>(x/b[v=a[x>y?x:y]]^y/b[v])&1))

Try it online!

Arnauld

Posted 2019-05-17T18:31:40.367

Reputation: 111 334

2

Charcoal, 37 bytes

FN«≔⊕⌈Φ₂⊕Lυ¬﹪Lυ⊕κηFη«PL⭆⊞Oυω§#+÷⁻κμη↙

Try it online! Link is to verbose version of code. 1-indexed. Output grows down and left (down and right costs an extra byte, but can grow up for the same byte count). Explanation:

FN«

Loop \$S\$ times.

≔⊕⌈Φ₂⊕Lυ¬﹪Lυ⊕κη

Calculate \$k\leq\sqrt{n+1}\$. This only makes a difference when \$n=0\$ in which case this formula allows \$k=1\$.

Fη«

Loop \$k\$ times, once for each new row and column.

PL⭆⊞Oυω§#+÷⁻κμη

Output the row and column, being sure to alternate between the # and + characters in such a way that # is always the first character but that there is a boundary at the end of the string (because we're drawing from the diagonal outwards). ⊞Oυω makes each row one character longer each time, which also keeps track of \$n\$ as the length.

Move down and left ready for the next row.

Neil

Posted 2019-05-17T18:31:40.367

Reputation: 95 035

2

05AB1E, 43 42 bytes

$G©ÐX‚ˆÑʒ®>t‹}àDU+}¯εÝ`θ÷ɨDδ^}RζεðKζðδK€θ

Inspired by @NickKennedy's Jelly answer, and the trailing portion ζεðKζðδK€θ is a port from @Emigna's 05AB1E answer here.

Returns a matrix of 0 instead of # and 1 instead of +.

Try it online or try it online by outputting the first \$[2,n]\$ results (J, in the footer and the --no-lazy flag are to pretty-print the resulting matrix).

Explanation:

$                # Push 1 and the input
 G               # Loop the input - 1 amount of times:
  ©              #  Store the top of the stack in variable `r` (without popping)
   Ð             #  And triplicate the top as well
    X‚           #  Pair it with variable `X` (which is 1 by default)
      ˆ          #  And pop and store this pair in the global array
    Ñ            #  Get the divisors of the integer we triplicated
     ʒ    }à     #  Get the highest divisor which is truthy for:
         ‹       #   Where the divisor integer is smaller than
      ®>t        #   the square root of `r+1`
            DU   #  Store a copy of this largest filtered divisor as new variable `X`
              +  #  And add it to the triplicated integer
 }¯              # After the loop: push the global array
   ε             # Map each pair to:
    Ý θ          #  Convert the first value in the pair to a list in the range [0,n]
     `           #  and push both this list and the second value to the stack
       ÷         # Integer-divide each value in the list by the second value
        É        # Check for each value if it's even (1 if even; 0 if odd)
         ¨       # Remove the last item
          Dδ     # Loop double vectorized over this list:
            ^    #  And XOR the values with each other
   }R            # After the map: reverse the list of digit-matrices
     ζ           # Zip/transpose; swapping rows and columns, with a space as filler
      ε          # map each matrix to:
       ðK        #  Remove all spaces from the current matrix
         ζ       #  Zip/transpose with a space as filler again
          ðδK    #  Deep remove all spaces
             €θ  #  Then only leave the last values of each row
                 # (after which the resulting matrix of 0s and 1s is output implicitly)

Kevin Cruijssen

Posted 2019-05-17T18:31:40.367

Reputation: 67 575

1

Haskell, 149 146 bytes

(iterate g["#"]!!)
g b|let e=(<$[1..d]);l=length b;d=last[i|i<-[1..l],i*i<=l,mod l i<1];m="+#"++m=(e$take(l+d)$e=<<'#':m)++zipWith(++)(e=<<e<$>m)b

This is 0 indexed, returns a list of strings and grows upwards and leftwards.

Try it online!

(iterate g["#"]!!)                    -- start with ["#"], repeatedly add a layer
                                      -- (via function 'g'), collect all results in
                                      -- a list and index it with the input number

g b | let                             -- add a single layer to chessboard 'b'

 l=length b                           -- let 'l' be the size of 'b'
 d=last[i|i<-[1..l],i*i<=l,mod l i<1] -- let 'd' be the size of the new layer
 e=(<$[1..d])                         -- let 'e' be a functions that makes 'd'
                                      --   copies of it's argument
 m="#+"++m                            -- let 'm' be an infinite string of "+#+#+..."

 =                                    -- return
              zipWith(++)             --   concatenate pairwise
                         (e=<<e<$>m)  --   a list of squares made by expanding each
                                      --   char in 'm' to size 'd'-by-'d'
                                    b --   and 'b' (zipWith truncates the infinite
                                      --   list of squares to the length of 'b')
                                      --
           ++                         --   and prepend
                                      --
(e$take(l+d)$e=<<'#':m)               --   the top layer, i.e. a list of 'd' strings
                                      --   each with the pattern 'd' times '#'
                                      --   followed by 'd' times '+', etc., each
                                      --   shortened to the correct size of 'l'+'g'

nimi

Posted 2019-05-17T18:31:40.367

Reputation: 34 639

1

Perl 6, 156 144 155 154 bytes

+11 to fix a bug reported by nimi.

{$!=-1;join "
",(1,{my \k=max grep $_%%*,1.. .sqrt;++$!;flat .kv.map(->\i,\l {l~($!+i/k)%2+|0 x k}),substr(($!%2 x k~1-$!%2 x k)x$_,0,$_+k)xx k}...*)[$_]}

Roughly based on Chas Brown's Python solution. Takes S zero-indexedly. Outputs 0 and 1.

Try it online!

bb94

Posted 2019-05-17T18:31:40.367

Reputation: 1 831

Fixed. Now the corners should share the same colour. – bb94 – 2019-05-21T05:03:30.023