Warped chessboardSet the chessboardBuild a working chessboardGenerate Pascal's PyramidChess Light SolverASCII Art ChessboardBuild a chessboardChessboard mazeHexaGolf: WordagonsEscape a chessboardReconstruct an arithmetic sequence
Word for a small burst of laughter that can't be held back
Is having a hidden directory under /etc safe?
Accidentally cashed a check twice
Is the decompression of compressed and encrypted data without decryption also theoretically impossible?
Strange math syntax in old basic listing
Hygienic footwear for prehensile feet?
Initialize an array of doubles at compile time
Is it possible for people to live in the eye of a permanent hypercane?
Pros and cons of writing a book review?
Please help me identify this plane
How do I remove hundreds of automatically added network printers?
What if you don't bring your credit card or debit for incidentals?
When leasing/renting out an owned property, is there a standard ratio between monthly rent and the mortgage?
What is a simple, physical situation where complex numbers emerge naturally?
Access to all elements on the page
Can a class take a different class's spell in their ritual book?
What does it mean by "d-ism of Leibniz" and "dotage of Newton" in simple English?
Why does a helium balloon rise?
What does War Machine's "Canopy! Canopy!" line mean in "Avengers: Endgame"?
Why is Colorado so different politically from nearby states?
Get value of the passed argument to script importing variables from another script
How to make thick Asian sauces?
Show sparse matrices like chessboards
Credit card offering 0.5 miles for every cent rounded up. Too good to be true?
Warped chessboard
Set the chessboardBuild a working chessboardGenerate Pascal's PyramidChess Light SolverASCII Art ChessboardBuild a chessboardChessboard mazeHexaGolf: WordagonsEscape a chessboardReconstruct an arithmetic sequence
$begingroup$
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 $sqrtn$. The squares in the diagonal are always of the same colour.
Specifically, consider the board with colours represented as #
and +
.
Initialize the chessboard to
#
The board so far has size $1times 1$. The only divisor of $1$ is $1$, and it does not exceed $sqrt1$. So we take $k=1$, and extend the board by adding a layer of squares of size $1$, with
#
in the diagonal:#+
+#The board built so far has size $2 times 2$. The divisors of $2$ are $1,2$, and the maximum divisor not exceeding $sqrt2$ is $1$. So again $k=1$, and the board is extended to
#+#
+#+
#+#Size is $3 times 3$. $k=1$. Extend to
#+#+
+#+#
#+#+
+#+#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 $2times 2$, with colour
#
in the diagonal:#+#+##
+#+###
#+#+++
+#+#++
##++##
##++##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
:
#+#+##++##++###+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+#+###++##++###+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
#+#+++##++#####+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+#+#++##++##+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
##++##++##+++++###+++###++++####++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
##++##++##+++++###+++###++++####++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++##++##++#####+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
++##++##++#####+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
##++##++##++###+++###+++####++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
##++##++##+++++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
++##++##++##+++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
++##++##++##+++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
+++###+++###+++###+++###++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
+++###+++###+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+++###+++###+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
###+++###+++###+++###+++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
###+++###+++###+++###+++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
###+++###+++###+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++####++++####++++####++++####++++++++++######++++++######++++++##############++++++++########++++++++########++++++++
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
code-golf ascii-art integer
$endgroup$
add a comment |
$begingroup$
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 $sqrtn$. The squares in the diagonal are always of the same colour.
Specifically, consider the board with colours represented as #
and +
.
Initialize the chessboard to
#
The board so far has size $1times 1$. The only divisor of $1$ is $1$, and it does not exceed $sqrt1$. So we take $k=1$, and extend the board by adding a layer of squares of size $1$, with
#
in the diagonal:#+
+#The board built so far has size $2 times 2$. The divisors of $2$ are $1,2$, and the maximum divisor not exceeding $sqrt2$ is $1$. So again $k=1$, and the board is extended to
#+#
+#+
#+#Size is $3 times 3$. $k=1$. Extend to
#+#+
+#+#
#+#+
+#+#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 $2times 2$, with colour
#
in the diagonal:#+#+##
+#+###
#+#+++
+#+#++
##++##
##++##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
:
#+#+##++##++###+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+#+###++##++###+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
#+#+++##++#####+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+#+#++##++##+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
##++##++##+++++###+++###++++####++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
##++##++##+++++###+++###++++####++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++##++##++#####+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
++##++##++#####+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
##++##++##++###+++###+++####++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
##++##++##+++++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
++##++##++##+++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
++##++##++##+++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
+++###+++###+++###+++###++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
+++###+++###+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+++###+++###+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
###+++###+++###+++###+++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
###+++###+++###+++###+++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
###+++###+++###+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++####++++####++++####++++####++++++++++######++++++######++++++##############++++++++########++++++++########++++++++
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
code-golf ascii-art integer
$endgroup$
$begingroup$
Is an integer matrix permitted as output (e.g. 0s and 1s), or does it have to be strings/characters?
$endgroup$
– Nick Kennedy
May 18 at 4:07
$begingroup$
@Nick It has to be chars, sorry
$endgroup$
– Luis Mendo
May 18 at 8:47
2
$begingroup$
Very well-written question!
$endgroup$
– Greg Martin
May 18 at 17:25
$begingroup$
@GregMartin Hey, thanks!
$endgroup$
– Luis Mendo
May 18 at 17:44
add a comment |
$begingroup$
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 $sqrtn$. The squares in the diagonal are always of the same colour.
Specifically, consider the board with colours represented as #
and +
.
Initialize the chessboard to
#
The board so far has size $1times 1$. The only divisor of $1$ is $1$, and it does not exceed $sqrt1$. So we take $k=1$, and extend the board by adding a layer of squares of size $1$, with
#
in the diagonal:#+
+#The board built so far has size $2 times 2$. The divisors of $2$ are $1,2$, and the maximum divisor not exceeding $sqrt2$ is $1$. So again $k=1$, and the board is extended to
#+#
+#+
#+#Size is $3 times 3$. $k=1$. Extend to
#+#+
+#+#
#+#+
+#+#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 $2times 2$, with colour
#
in the diagonal:#+#+##
+#+###
#+#+++
+#+#++
##++##
##++##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
:
#+#+##++##++###+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+#+###++##++###+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
#+#+++##++#####+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+#+#++##++##+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
##++##++##+++++###+++###++++####++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
##++##++##+++++###+++###++++####++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++##++##++#####+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
++##++##++#####+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
##++##++##++###+++###+++####++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
##++##++##+++++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
++##++##++##+++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
++##++##++##+++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
+++###+++###+++###+++###++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
+++###+++###+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+++###+++###+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
###+++###+++###+++###+++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
###+++###+++###+++###+++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
###+++###+++###+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++####++++####++++####++++####++++++++++######++++++######++++++##############++++++++########++++++++########++++++++
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
code-golf ascii-art integer
$endgroup$
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 $sqrtn$. The squares in the diagonal are always of the same colour.
Specifically, consider the board with colours represented as #
and +
.
Initialize the chessboard to
#
The board so far has size $1times 1$. The only divisor of $1$ is $1$, and it does not exceed $sqrt1$. So we take $k=1$, and extend the board by adding a layer of squares of size $1$, with
#
in the diagonal:#+
+#The board built so far has size $2 times 2$. The divisors of $2$ are $1,2$, and the maximum divisor not exceeding $sqrt2$ is $1$. So again $k=1$, and the board is extended to
#+#
+#+
#+#Size is $3 times 3$. $k=1$. Extend to
#+#+
+#+#
#+#+
+#+#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 $2times 2$, with colour
#
in the diagonal:#+#+##
+#+###
#+#+++
+#+#++
##++##
##++##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
:
#+#+##++##++###+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+#+###++##++###+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
#+#+++##++#####+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+#+#++##++##+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
##++##++##+++++###+++###++++####++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
##++##++##+++++###+++###++++####++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++##++##++#####+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
++##++##++#####+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
##++##++##++###+++###+++####++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
##++##++##+++++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
++##++##++##+++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
++##++##++##+++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
+++###+++###+++###+++###++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
+++###+++###+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+++###+++###+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
###+++###+++###+++###+++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
###+++###+++###+++###+++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
###+++###+++###+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++####++++####++++####++++####++++++++++######++++++######++++++##############++++++++########++++++++########++++++++
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
code-golf ascii-art integer
code-golf ascii-art integer
edited May 17 at 22:38
Luis Mendo
asked May 17 at 18:31
Luis MendoLuis Mendo
76k889298
76k889298
$begingroup$
Is an integer matrix permitted as output (e.g. 0s and 1s), or does it have to be strings/characters?
$endgroup$
– Nick Kennedy
May 18 at 4:07
$begingroup$
@Nick It has to be chars, sorry
$endgroup$
– Luis Mendo
May 18 at 8:47
2
$begingroup$
Very well-written question!
$endgroup$
– Greg Martin
May 18 at 17:25
$begingroup$
@GregMartin Hey, thanks!
$endgroup$
– Luis Mendo
May 18 at 17:44
add a comment |
$begingroup$
Is an integer matrix permitted as output (e.g. 0s and 1s), or does it have to be strings/characters?
$endgroup$
– Nick Kennedy
May 18 at 4:07
$begingroup$
@Nick It has to be chars, sorry
$endgroup$
– Luis Mendo
May 18 at 8:47
2
$begingroup$
Very well-written question!
$endgroup$
– Greg Martin
May 18 at 17:25
$begingroup$
@GregMartin Hey, thanks!
$endgroup$
– Luis Mendo
May 18 at 17:44
$begingroup$
Is an integer matrix permitted as output (e.g. 0s and 1s), or does it have to be strings/characters?
$endgroup$
– Nick Kennedy
May 18 at 4:07
$begingroup$
Is an integer matrix permitted as output (e.g. 0s and 1s), or does it have to be strings/characters?
$endgroup$
– Nick Kennedy
May 18 at 4:07
$begingroup$
@Nick It has to be chars, sorry
$endgroup$
– Luis Mendo
May 18 at 8:47
$begingroup$
@Nick It has to be chars, sorry
$endgroup$
– Luis Mendo
May 18 at 8:47
2
2
$begingroup$
Very well-written question!
$endgroup$
– Greg Martin
May 18 at 17:25
$begingroup$
Very well-written question!
$endgroup$
– Greg Martin
May 18 at 17:25
$begingroup$
@GregMartin Hey, thanks!
$endgroup$
– Luis Mendo
May 18 at 17:44
$begingroup$
@GregMartin Hey, thanks!
$endgroup$
– Luis Mendo
May 18 at 17:44
add a comment |
8 Answers
8
active
oldest
votes
$begingroup$
Canvas, 34 32 bytes
0#0⁸[#+¶+#xx*yx+m⤢αm;nlw√{y;%‽²X
Try it here!
$endgroup$
$begingroup$
Input can now be 0-indexed; in case that helps
$endgroup$
– Luis Mendo
May 17 at 20:58
add a comment |
$begingroup$
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
$endgroup$
1
$begingroup$
@LuisMendo saved 2 bytes :D
$endgroup$
– Rod
May 21 at 12:41
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
- 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 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
$endgroup$
$begingroup$
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?
$endgroup$
– Fabian Röling
May 18 at 22:36
$begingroup$
@FabianRöling The OP states any two characters were acceptable. There’s a good introductory tutorial for Jelly at the 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.
$endgroup$
– Nick Kennedy
May 19 at 0:35
add a comment |
$begingroup$
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!
$endgroup$
add a comment |
$begingroup$
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 $kleqsqrtn+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.
$endgroup$
add a comment |
$begingroup$
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'
$endgroup$
add a comment |
$begingroup$
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+),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!
$endgroup$
$begingroup$
Fixed. Now the corners should share the same colour.
$endgroup$
– bb94
May 21 at 5:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f185744%2fwarped-chessboard%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Canvas, 34 32 bytes
0#0⁸[#+¶+#xx*yx+m⤢αm;nlw√{y;%‽²X
Try it here!
$endgroup$
$begingroup$
Input can now be 0-indexed; in case that helps
$endgroup$
– Luis Mendo
May 17 at 20:58
add a comment |
$begingroup$
Canvas, 34 32 bytes
0#0⁸[#+¶+#xx*yx+m⤢αm;nlw√{y;%‽²X
Try it here!
$endgroup$
$begingroup$
Input can now be 0-indexed; in case that helps
$endgroup$
– Luis Mendo
May 17 at 20:58
add a comment |
$begingroup$
Canvas, 34 32 bytes
0#0⁸[#+¶+#xx*yx+m⤢αm;nlw√{y;%‽²X
Try it here!
$endgroup$
Canvas, 34 32 bytes
0#0⁸[#+¶+#xx*yx+m⤢αm;nlw√{y;%‽²X
Try it here!
edited May 17 at 20:18
answered May 17 at 19:19
dzaimadzaima
16.3k22061
16.3k22061
$begingroup$
Input can now be 0-indexed; in case that helps
$endgroup$
– Luis Mendo
May 17 at 20:58
add a comment |
$begingroup$
Input can now be 0-indexed; in case that helps
$endgroup$
– Luis Mendo
May 17 at 20:58
$begingroup$
Input can now be 0-indexed; in case that helps
$endgroup$
– Luis Mendo
May 17 at 20:58
$begingroup$
Input can now be 0-indexed; in case that helps
$endgroup$
– Luis Mendo
May 17 at 20:58
add a comment |
$begingroup$
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
$endgroup$
1
$begingroup$
@LuisMendo saved 2 bytes :D
$endgroup$
– Rod
May 21 at 12:41
add a comment |
$begingroup$
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
$endgroup$
1
$begingroup$
@LuisMendo saved 2 bytes :D
$endgroup$
– Rod
May 21 at 12:41
add a comment |
$begingroup$
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
$endgroup$
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
edited May 21 at 12:46
answered May 17 at 19:45
RodRod
16.6k41983
16.6k41983
1
$begingroup$
@LuisMendo saved 2 bytes :D
$endgroup$
– Rod
May 21 at 12:41
add a comment |
1
$begingroup$
@LuisMendo saved 2 bytes :D
$endgroup$
– Rod
May 21 at 12:41
1
1
$begingroup$
@LuisMendo saved 2 bytes :D
$endgroup$
– Rod
May 21 at 12:41
$begingroup$
@LuisMendo saved 2 bytes :D
$endgroup$
– Rod
May 21 at 12:41
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
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.
edited May 18 at 0:12
answered May 17 at 22:13
Chas BrownChas Brown
5,5491623
5,5491623
add a comment |
add a comment |
$begingroup$
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.
- 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 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
$endgroup$
$begingroup$
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?
$endgroup$
– Fabian Röling
May 18 at 22:36
$begingroup$
@FabianRöling The OP states any two characters were acceptable. There’s a good introductory tutorial for Jelly at the 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.
$endgroup$
– Nick Kennedy
May 19 at 0:35
add a comment |
$begingroup$
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.
- 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 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
$endgroup$
$begingroup$
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?
$endgroup$
– Fabian Röling
May 18 at 22:36
$begingroup$
@FabianRöling The OP states any two characters were acceptable. There’s a good introductory tutorial for Jelly at the 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.
$endgroup$
– Nick Kennedy
May 19 at 0:35
add a comment |
$begingroup$
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.
- 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 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
$endgroup$
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.
- 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 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
edited May 18 at 17:38
answered May 18 at 4:23
Nick KennedyNick Kennedy
2,65469
2,65469
$begingroup$
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?
$endgroup$
– Fabian Röling
May 18 at 22:36
$begingroup$
@FabianRöling The OP states any two characters were acceptable. There’s a good introductory tutorial for Jelly at the 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.
$endgroup$
– Nick Kennedy
May 19 at 0:35
add a comment |
$begingroup$
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?
$endgroup$
– Fabian Röling
May 18 at 22:36
$begingroup$
@FabianRöling The OP states any two characters were acceptable. There’s a good introductory tutorial for Jelly at the 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.
$endgroup$
– Nick Kennedy
May 19 at 0:35
$begingroup$
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?$endgroup$
– Fabian Röling
May 18 at 22:36
$begingroup$
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?$endgroup$
– Fabian Röling
May 18 at 22:36
$begingroup$
@FabianRöling The OP states any two characters were acceptable. There’s a good introductory tutorial for Jelly at the 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.
$endgroup$
– Nick Kennedy
May 19 at 0:35
$begingroup$
@FabianRöling The OP states any two characters were acceptable. There’s a good introductory tutorial for Jelly at the 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.
$endgroup$
– Nick Kennedy
May 19 at 0:35
add a comment |
$begingroup$
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!
$endgroup$
add a comment |
$begingroup$
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!
$endgroup$
add a comment |
$begingroup$
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!
$endgroup$
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!
edited May 17 at 22:33
answered May 17 at 20:50
ArnauldArnauld
85.2k7100349
85.2k7100349
add a comment |
add a comment |
$begingroup$
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 $kleqsqrtn+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.
$endgroup$
add a comment |
$begingroup$
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 $kleqsqrtn+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.
$endgroup$
add a comment |
$begingroup$
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 $kleqsqrtn+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.
$endgroup$
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 $kleqsqrtn+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.
edited May 18 at 15:31
answered May 18 at 15:25
NeilNeil
84.6k845183
84.6k845183
add a comment |
add a comment |
$begingroup$
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'
$endgroup$
add a comment |
$begingroup$
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'
$endgroup$
add a comment |
$begingroup$
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'
$endgroup$
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'
edited May 18 at 21:58
answered May 18 at 15:47
niminimi
33.2k32491
33.2k32491
add a comment |
add a comment |
$begingroup$
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+),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!
$endgroup$
$begingroup$
Fixed. Now the corners should share the same colour.
$endgroup$
– bb94
May 21 at 5:03
add a comment |
$begingroup$
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+),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!
$endgroup$
$begingroup$
Fixed. Now the corners should share the same colour.
$endgroup$
– bb94
May 21 at 5:03
add a comment |
$begingroup$
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+),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!
$endgroup$
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+),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!
edited May 21 at 4:59
answered May 19 at 18:00
bb94bb94
1,431715
1,431715
$begingroup$
Fixed. Now the corners should share the same colour.
$endgroup$
– bb94
May 21 at 5:03
add a comment |
$begingroup$
Fixed. Now the corners should share the same colour.
$endgroup$
– bb94
May 21 at 5:03
$begingroup$
Fixed. Now the corners should share the same colour.
$endgroup$
– bb94
May 21 at 5:03
$begingroup$
Fixed. Now the corners should share the same colour.
$endgroup$
– bb94
May 21 at 5:03
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f185744%2fwarped-chessboard%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Is an integer matrix permitted as output (e.g. 0s and 1s), or does it have to be strings/characters?
$endgroup$
– Nick Kennedy
May 18 at 4:07
$begingroup$
@Nick It has to be chars, sorry
$endgroup$
– Luis Mendo
May 18 at 8:47
2
$begingroup$
Very well-written question!
$endgroup$
– Greg Martin
May 18 at 17:25
$begingroup$
@GregMartin Hey, thanks!
$endgroup$
– Luis Mendo
May 18 at 17:44