31
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!
@AdmBorkBork That's just to avoid confusion if I put
#
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 – HyperNeutrino – 2019-11-11T18:39:37.367@AdmBorkBork Fair enough. I'll do that instead. Thanks. – HyperNeutrino – 2019-11-11T18:42:18.830
@LuisMendo Whoops - yes. Thanks for catching that. – HyperNeutrino – 2019-11-11T20:42:22.320
@ChasBrown At stage 0, it's 2x2, and each time, it scales by x2, so wouldn't stage 1 be 4x4 (like shown) and stage 2 be 8x8 (like shown)? – HyperNeutrino – 2019-11-11T20:44:17.643
Ah I see:
and all _ will be in a rectangular sub-grid such that...
I thought we were replacing each_
with a copy, not some sub-range. – Chas Brown – 2019-11-11T20:55:11.200These can be integers too So can we input and output matrices of numbers (not of characters)? – Luis Mendo – 2019-11-11T22:08:17.843
The _ are shown in this output - you are to replace them with # or ., by choice.
andOutput requires a grid. This grid can be given in any reasonable, convenient format, and you can replace the characters with any three consistent, distinct values.
. Those two clauses contradict each other. In the first one, you say all_
must be replaced with either#
or.
in the output leaving only two distinct characters, but in the second you say that there should be three distinct characters – Embodiment of Ignorance – 2019-11-11T23:59:40.440@EmbodimentofIgnorance Oh. Forgot about that, thanks. – HyperNeutrino – 2019-11-12T01:26:22.097
@LuisMendo Yes. – HyperNeutrino – 2019-11-12T01:51:18.257
Are you sure it's a good idea to request multiple passes in one run? That seems to be difficult to achieve without simply wrapping everything in a loop (effectively directly increasing the gap between concise and verbose languages). – my pronoun is monicareinstate – 2019-11-12T12:08:16.837
@someone Hm. That's fair enough; I'll definitely keep that in mind going into future challenges but for this one it's too late to change it now, but thanks for the reminder anyway. – HyperNeutrino – 2019-11-12T12:32:37.030