Input
A string s
of printable ASCII characters, newlines, and spaces (0x20 ( )
to 0x7E (~)
), and a non-negative integer n
.
Challenge
To write a program that outputs either another program, or s
depending on n
. If n = 1
, Then your code should output code which outputs s
. If n = 2
, Your code should output code which outputs code which outputs s
and so on.
All outputted code should be in the same language as the language of the original submission.
Test Cases
Format: s, n -> output
Assuming your submission is written in JavaScript:
No cycles, 0 -> No cycles
Hello, 1 -> console.log("Hello");
Cycle!, 3 -> console.log("console.log(\"console.log(\\\"Cycle!\\\")\")");
:), 3 -> console.log("console.log('console.log(`:)`)')");
Scoring
This is code-golf, so aim for shortest code in bytes.
Additional Rules
- I/O format is flexible
- Default rules and standard loopholes apply.
- The output of your submission must be valid.
- You can use any language, even if it was created after this challenge, as long as it wasn't created for the purpose of this challenge
- This isn't a polyglot challenge. A JavaScript submission shouldn't output Ruby code.
- Input is guaranteed to be valid as defined in the
Input
section
Validation
Here's a quick tip to test your answers:
For n=0
, output=s
For n=1
, eval(output)=s
For n=2
, eval(eval(output))=s
Where n
and s
are inputs