21
1
Given a positive integer nesting level n
and string s
of printable ascii characters( to
~
, output a program which, when run in the same language, outputs a program which outputs a program . . . which outputs the string s
.
A total of n
programs should be generated, all of which should be run in the same language as your answer.
Note: you may output programs or functions -- anything you are allowed by default as a submission.
You may input s
with escaped characters, how a program or function in your language would usually input a string.
Example
For example, given n=1
and s="recursion"
, a Python 2 program might output:
print "recursion"
Running this would output:
recursion
Given n=2
and s="PPCG", a Python 2 program might output:
print "print \"PPCG\" "
Running this outputs:
print "PPCG"
Running this outputs:
PPCG
Related (+title inspiration): One more LUL and I'm out
Also Related (in sandbox - now deleted, but can still be viewed with enough reputation): Source Code Recursion
Test Cases
Make sure that your code works for the following test cases (one per line):
n s
2 PPCG
4 Robert'); DROP TABLE Students;--
17 Deep
2 Spaces In Here
3 "Don't forget quotes!"
5 'Backt`cks might be a h`tch'
6 5%s
8 [Brackets]<Are>(Great){Usually}
3 !"#$%&'()*+,-./ 0123456789:;<=>?@ABCDEFGHIJKLMN
6 OPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
7 THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
3 the quick brown fox jumps over the lazy dog
1
Was reading the challenge and was like "hey, that looks very familiar..", and then noticed your "Also Related (in sandbox): Source Code Inspiration" to my Sandbox question. :) I'll leave my question there for now, but will delete it after a couple of weeks. Yours is basically the same, except with the addition of an integer parameter.
– Kevin Cruijssen – 2017-09-28T07:11:22.8971As suggested here, is it allowed to return anonymous functions instead of programs? – Arnauld – 2017-09-28T09:07:18.760
1Does "positive integer" include
0
? – Felix Palmen – 2017-09-28T09:16:57.6731Did you choose program for a reason? The default is function or program? Is it allowed to have a function printing a function? – Kevin Cruijssen – 2017-09-28T11:48:45.860
Can we use escape characters in the input or must submissions handle inputs that are hard (possibly impossible in some languages) to parse? – Stewie Griffin – 2017-09-28T14:08:16.590
@Arnauld yes, an anonymous function may be output. – fireflame241 – 2017-09-28T14:28:42.740
@FelixPalmen No. Positive integer does not include 0, so you will never be asked to output
s
directly – fireflame241 – 2017-09-28T14:29:30.467@StewieGriffin yes, escape characters may be used, such as inputting
'don\'t'
in Python. – fireflame241 – 2017-09-28T14:31:48.307Then those test cases doesn't make much sense. They seem to suggest the input format is very strict. Why else have all the "Don't forget quotes", "Back ticks might be a hitch", Little bobby tables and so on? – Stewie Griffin – 2017-09-28T14:33:32.337
1@StewieGriffin because escaping in sub-expressions or nested programs might be problematic (and someone asked for quote test cases in sandbox). – fireflame241 – 2017-09-28T14:41:26.393
1Is there any consensus on meta about that? The fact that a program or function is able to process a string including some special characters and the valid way(s) to pass it such a string properly are two completely independent issues, IMHO. String unescaping usually takes place at the tokenizer level exclusively and the final program is not even aware of that. Now, if a program really needs to receive, say, two raw backslashes instead of one, that would be indeed a problem. – Arnauld – 2017-09-28T15:12:35.170
"You may input
s
with escaped characters, however you would usually input a string." What does this mean? – Jakob – 2017-10-05T15:59:55.5231@Jakob I think your confusion comes from "however" able to be used as a conjunction. Specified in question. – fireflame241 – 2017-10-05T22:41:58.130