Background
Famously, the acronym GNU
stands for GNU's Not Unix
. 1
It's recursive because, after expanding it once, it still contains the acronym GNU
, and so must be exanded again:
(GNU's Not Unix)'s Not Unix
And so on, ad infinitum. Visualizing this, we get a kind of Droste effect:
┌────────────────────────────────────────────┬───────────┐
│┌──────────────────────────────┬───────────┐│'s Not Unix│
││┌────────────────┬───────────┐│'s Not Unix││ │
│││┌──────────────┐│'s Not Unix││ ││ │
││││GNU's Not Unix││ ││ ││ │
│││└──────────────┘│ ││ ││ │
││└────────────────┴───────────┘│ ││ │
│└──────────────────────────────┴───────────┘│ │
└────────────────────────────────────────────┴───────────┘
Recursive acronyms need not recurse on the first word, or only once. For example:
YOPY
:Your Own Personal YOPY
PIPER
:PIPER Is PIPER Expanded Recursively
Visualized:
Challenge
Input
You will be given two inputs:
- A string whose space-delimited words form a recursive acronym. That is, if you form a string from the first letter of each word, that string is guaranteed to be either:
- One of the words of the input string (it may occur more than once).
- A prefix of one or more of those words (e.g.
GNU
is a prefix ofGNU's
) - The casing will match exactly
- A non-negative integer -- the number of times to recursively expand. Given
0
, you'll return the input unaltered (or "framed" once, in its entirety). Given1
, you'll expand once. Etc.
Output
The output is the input string with all instances of the acronym visually expanded, recursively, the specified number of times.
You must use some visual effect to "frame" the nesting -- at minimum, distinct start and end delimiters like parentheses. Ascii boxing of some sort, as in the examples above, is also fine. As would be outputting an actual image that showed the nesting.
I'm flexible as long as the nesting is in fact visualized.
For clarity, parenthesized output would like this:
(((GNU's Not Unix)'s Not Unix)'s Not Unix)'s Not Unix
You are guaranteed that parentheses will never be part of acronym. Other than alphanumeric characters, the acronym will only contain apostrophes, commas, quotes, question marks and exclamation points, and those will only occur as valid punctuation (e.g., a question mark will not appear at the beginning of a word).
This is code golf, fewest bytes wins, no loopholes.
Test Cases
This assumes you're using a parentheses visualization.
Format for test cases:
- Input string (the acronym)
- Input integer (recursion)
- Expected Output
GNU's Not Unix
0
GNU's Not Unix
GNU's Not Unix
2
((GNU's Not Unix)'s Not Unix)'s Not Unix
YOPY Own Personal YOPY
1
(YOPY Own Personal YOPY) Own Personal (YOPY Own Personal YOPY)
YOPY Own Personal YOPY
2
((YOPY Own Personal YOPY) Own Personal (YOPY Own Personal YOPY)) Own Personal ((YOPY Own Personal YOPY) Own Personal (YOPY Own Personal YOPY))
YourYOPY Own Personal YOPY
2
YourYOPY Own Personal (YourYOPY Own Personal (YourYOPY Own Personal YOPY))
YourYOPY Own Personal YOPY
as if theYOPY
inYourYOPY
is not the acronym - the caps seem to imply it should be :/ \$\endgroup\$ – Jonathan Allan Feb 19 '20 at 18:29