Given a description of the base state of a recursive ASCII pattern, output an expanded state somewhere along the recursion steps.
More specifically: Let the following be an example:
##..
##..
..__
..__
Where #
is filled, .
is empty, and _
is recursive.
This describes a pattern wherein the top left quarter is filled, the top right and bottom left are empty, and the bottom right repeats the current pattern.
More rigorously, the pattern is a grid containing some number of #
, .
, and _
. The grid will always be rectangular, and there will be at least one _
and all _
will be in a rectangular sub-grid such that the overall grid's (width, height)
is an integer multiple of the sub-grid's (width, height)
.
Your task is, given such a pattern and a number of steps, build up an expanded form of this pattern. That is, each step, expand the grid by n
times (where n
is the ratio between the recursive sub-grid and the overall grid), and fill the _
sub-grid with the pattern. At the end, fill the base-state _
all with #
or .
- you choose which, but it must all be the same, and it must be consistently one or the other no matter the input.
To be VERY rigorous, f(g, n)
where f
is this challenge, g
is the pattern grid, and n
is the number of steps, then f(g, 0) == g
(with the _
replaced by #
OR .
), and f(g, n)
is the grid scaled up by r ** n
times (where r
is the ratio of the pattern to the recursive sub-grid), with _
replaced by f(g, n - 1)
.
Let's do an example:
#.
._
3
At 0 steps, the grid is this:
#.
._
At 1 step, the grid is this:
##..
##..
..#.
..._
At 2 steps, the grid is this:
####....
####....
####....
####....
....##..
....##..
......#.
......._
At 3 steps, the grid is this:
########........
########........
########........
########........
########........
########........
########........
########........
........####....
........####....
........####....
........####....
............##..
............##..
..............#.
..............._
Then, your output can either replace the _
with .
or #
, but again, all _
must become the same in the final output, and you must always fill it with .
or #
no matter the input.
Examples
The _
are shown in this output - you are to replace them with #
or .
, by choice. They are simply shown as _
just to reduce confusion as to where the _
were and where pre-filled #
and .
are meant to be.
#.#.
.__#
#__.
.#.#
2
becomes
####....####....
####....####....
####....####....
####....####....
....##..##..####
....##..##..####
......#.#.######
.......__#######
#######__.......
######.#.#......
####..##..##....
####..##..##....
....####....####
....####....####
....####....####
....####....####
(Just gonna put this out there - this is NOT what I thought it would look like AT ALL)
A non-square non-double example:
##.
##.
##.
##.
.#_
.#_
2
becomes
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........#########...#####.
.........#########...#####.
.........#########...#####.
.........#########...#####.
.........#########...###.#_
.........#########...###.#_
Last example.
#__#
.##.
3
becomes
###############__###############
##############.##.##############
############..####..############
############..####..############
########....########....########
########....########....########
########....########....########
########....########....########
........################........
........################........
........################........
........################........
........################........
........################........
........################........
........################........
Rules and Specifications
Input requires a grid and an integer. This grid can be taken in any reasonable, convenient format, and you can replace the characters with any three consistent, distinct values. These can be integers too, for example.
Output requires a grid. This grid can be given in any reasonable, convenient format, and you can replace the characters with any two consistent, distinct values. These do not have to be the same as the ones corresponding to the inputs (why???).
Standard loopholes apply.
This is a code-golf challenge, so the shortest program in bytes for each language wins. No answer will be accepted.
Happy golfing!
#
and then an answer has.
and it looks different. It's going to be potentially confusing any way I put it :/ Unless you have a better suggestion :P I am not certain \$\endgroup\$and all _ will be in a rectangular sub-grid such that...
I thought we were replacing each_
with a copy, not some sub-range. \$\endgroup\$