Cycle my input please

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












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










share|improve this question























  • Are functions that output programs or functions allowed?
    – nwellnhof
    2 hours ago






  • 3




    related duplicate?
    – Emigna
    2 hours ago










  • @nwellnhof According to the default rules, yes.
    – FireCubez
    2 hours ago










  • @LuisfelipeDejesusMunoz Sorry, I mistyped, I meant the same language, not code
    – FireCubez
    2 hours ago















up vote
1
down vote

favorite












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










share|improve this question























  • Are functions that output programs or functions allowed?
    – nwellnhof
    2 hours ago






  • 3




    related duplicate?
    – Emigna
    2 hours ago










  • @nwellnhof According to the default rules, yes.
    – FireCubez
    2 hours ago










  • @LuisfelipeDejesusMunoz Sorry, I mistyped, I meant the same language, not code
    – FireCubez
    2 hours ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











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










share|improve this question















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







code-golf string






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago

























asked 3 hours ago









FireCubez

1267




1267











  • Are functions that output programs or functions allowed?
    – nwellnhof
    2 hours ago






  • 3




    related duplicate?
    – Emigna
    2 hours ago










  • @nwellnhof According to the default rules, yes.
    – FireCubez
    2 hours ago










  • @LuisfelipeDejesusMunoz Sorry, I mistyped, I meant the same language, not code
    – FireCubez
    2 hours ago

















  • Are functions that output programs or functions allowed?
    – nwellnhof
    2 hours ago






  • 3




    related duplicate?
    – Emigna
    2 hours ago










  • @nwellnhof According to the default rules, yes.
    – FireCubez
    2 hours ago










  • @LuisfelipeDejesusMunoz Sorry, I mistyped, I meant the same language, not code
    – FireCubez
    2 hours ago
















Are functions that output programs or functions allowed?
– nwellnhof
2 hours ago




Are functions that output programs or functions allowed?
– nwellnhof
2 hours ago




3




3




related duplicate?
– Emigna
2 hours ago




related duplicate?
– Emigna
2 hours ago












@nwellnhof According to the default rules, yes.
– FireCubez
2 hours ago




@nwellnhof According to the default rules, yes.
– FireCubez
2 hours ago












@LuisfelipeDejesusMunoz Sorry, I mistyped, I meant the same language, not code
– FireCubez
2 hours ago





@LuisfelipeDejesusMunoz Sorry, I mistyped, I meant the same language, not code
– FireCubez
2 hours ago











9 Answers
9






active

oldest

votes

















up vote
3
down vote














R, 43 bytes





f=function(s,n)"if"(n,function()f(s,n-1),s)


Try it online!



Returns a zero-argument function that recursively calls f with n set to n-1. n successive function applications returns s.






share|improve this answer



























    up vote
    1
    down vote














    PHP, 69 bytes





    function($s,$n)while($n--)$s='echo'.var_export($s,1).';';return $s;


    Try it online!



    From the documentation about var_export:




    var_export — Outputs or returns a parsable string representation of a variable




    This function calls var_export prepends echo and appends ; $n times.






    share|improve this answer






















    • Could you provide an explanation?
      – FireCubez
      2 hours ago










    • 1) There´s no need for a space between return and $s. 2) recursive function, 67 bytes function f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s; 3) full program, 63 bytes: for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s; (run with -r)
      – Titus
      1 hour ago











    • I'd have to include -r in the byte count, don't I?
      – oktupol
      1 hour ago


















    up vote
    1
    down vote














    V, 3 bytes



    ÀII


    Try it online!



    Takes string as input, prepends as many I as stated in the first argument.






    share|improve this answer



























      up vote
      0
      down vote














      JavaScript (Node.js), 43 bytes



      Outputs a program that outputs a program that outp.... until b=1





      f=(a,b)=>b?--b?`(f=$f)('$a',$b)`:a:''


      Try it online!






      share|improve this answer






















      • This does not match the test cases, the output for f("hello", 2) should be console.log("console.log("hello")") or console.log("console.log('hello')")
        – FireCubez
        2 hours ago










      • Yes it is... it just outputs console.log("hello")
        – FireCubez
        2 hours ago










      • Does not work for n=0
        – FireCubez
        2 hours ago










      • Nevermind, it's just 1-indexed
        – FireCubez
        2 hours ago

















      up vote
      0
      down vote














      Haskell, 42 bytes





      s#n|n<1=s|0<1="main=putStr"++show(s#(n-1))


      Try it online!






      share|improve this answer




















      • I think ...0<1=show$s#(n-1) is enough, because we treat values in Haskell as functions.
        – nimi
        1 hour ago

















      up vote
      0
      down vote














      Perl 6, 25 bytes





      'Q«'x$^n~$^s~'»'x$n


      Try it online!



      Function returning function code. Uses Q« » to quote unescaped ASCII strings.






      share|improve this answer





























        up vote
        0
        down vote













        PHP, 12+1 bytes, not competing



        plain text is a valid PHP program, but, if N is not 0, this fails for text containing <? with short tags enabled and for text containing <?php or <?= in any case:



        <?=$argv[1];


        call with php -R '<code>' '<string>' <n>;
        call the output with php -R '<code>'






        share|improve this answer



























          up vote
          0
          down vote













          Google Sheets, 96 bytes



          =Join("",If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),),A1,Rept("""",2^B1-1))


          Inputs are in cells A1 (s) and B1 (n).



          Sample Results



          (Columns D, E, and F show the result if you copy the output from the column to its left and input it as a formula.)




          The formula concatenates 3 pieces into a single string. The first piece is the most complicated.



          If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),)


          If If statement drops the prefix if n=0 so you end up with No cycles instead of ="No cycles. The ArrayFormula creates an array of equal signs followed by some number quotes. That number is 2^(x-1) where x counts up from 1 to n thanks to the Row(Offset(~)) combination.



          The next piece (A1) adds in s and the final piece (Rept("""",2^B1-1)) adds in 2^n-1 quotes at the end.






          share|improve this answer



























            up vote
            0
            down vote














            Jelly, 2 bytes



            Ṿ¡


            Try it online!






            share|improve this answer




















            • Explanation? How does this wor
              – FireCubez
              1 hour ago










            • @FireCubez It simply executes the value → string representation function n times.
              – Erik the Outgolfer
              53 mins ago










            • And does executing the string representation of a value print the value?
              – FireCubez
              52 mins ago










            • @FireCubez The eval function (V) simply evaluates the code within a string. It doesn't implicitly print anything.
              – Erik the Outgolfer
              50 mins ago











            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "200"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173915%2fcycle-my-input-please%23new-answer', 'question_page');

            );

            Post as a guest






























            9 Answers
            9






            active

            oldest

            votes








            9 Answers
            9






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote














            R, 43 bytes





            f=function(s,n)"if"(n,function()f(s,n-1),s)


            Try it online!



            Returns a zero-argument function that recursively calls f with n set to n-1. n successive function applications returns s.






            share|improve this answer
























              up vote
              3
              down vote














              R, 43 bytes





              f=function(s,n)"if"(n,function()f(s,n-1),s)


              Try it online!



              Returns a zero-argument function that recursively calls f with n set to n-1. n successive function applications returns s.






              share|improve this answer






















                up vote
                3
                down vote










                up vote
                3
                down vote










                R, 43 bytes





                f=function(s,n)"if"(n,function()f(s,n-1),s)


                Try it online!



                Returns a zero-argument function that recursively calls f with n set to n-1. n successive function applications returns s.






                share|improve this answer













                R, 43 bytes





                f=function(s,n)"if"(n,function()f(s,n-1),s)


                Try it online!



                Returns a zero-argument function that recursively calls f with n set to n-1. n successive function applications returns s.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 hours ago









                Giuseppe

                15.4k31051




                15.4k31051




















                    up vote
                    1
                    down vote














                    PHP, 69 bytes





                    function($s,$n)while($n--)$s='echo'.var_export($s,1).';';return $s;


                    Try it online!



                    From the documentation about var_export:




                    var_export — Outputs or returns a parsable string representation of a variable




                    This function calls var_export prepends echo and appends ; $n times.






                    share|improve this answer






















                    • Could you provide an explanation?
                      – FireCubez
                      2 hours ago










                    • 1) There´s no need for a space between return and $s. 2) recursive function, 67 bytes function f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s; 3) full program, 63 bytes: for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s; (run with -r)
                      – Titus
                      1 hour ago











                    • I'd have to include -r in the byte count, don't I?
                      – oktupol
                      1 hour ago















                    up vote
                    1
                    down vote














                    PHP, 69 bytes





                    function($s,$n)while($n--)$s='echo'.var_export($s,1).';';return $s;


                    Try it online!



                    From the documentation about var_export:




                    var_export — Outputs or returns a parsable string representation of a variable




                    This function calls var_export prepends echo and appends ; $n times.






                    share|improve this answer






















                    • Could you provide an explanation?
                      – FireCubez
                      2 hours ago










                    • 1) There´s no need for a space between return and $s. 2) recursive function, 67 bytes function f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s; 3) full program, 63 bytes: for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s; (run with -r)
                      – Titus
                      1 hour ago











                    • I'd have to include -r in the byte count, don't I?
                      – oktupol
                      1 hour ago













                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote










                    PHP, 69 bytes





                    function($s,$n)while($n--)$s='echo'.var_export($s,1).';';return $s;


                    Try it online!



                    From the documentation about var_export:




                    var_export — Outputs or returns a parsable string representation of a variable




                    This function calls var_export prepends echo and appends ; $n times.






                    share|improve this answer















                    PHP, 69 bytes





                    function($s,$n)while($n--)$s='echo'.var_export($s,1).';';return $s;


                    Try it online!



                    From the documentation about var_export:




                    var_export — Outputs or returns a parsable string representation of a variable




                    This function calls var_export prepends echo and appends ; $n times.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 2 hours ago

























                    answered 2 hours ago









                    oktupol

                    4618




                    4618











                    • Could you provide an explanation?
                      – FireCubez
                      2 hours ago










                    • 1) There´s no need for a space between return and $s. 2) recursive function, 67 bytes function f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s; 3) full program, 63 bytes: for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s; (run with -r)
                      – Titus
                      1 hour ago











                    • I'd have to include -r in the byte count, don't I?
                      – oktupol
                      1 hour ago

















                    • Could you provide an explanation?
                      – FireCubez
                      2 hours ago










                    • 1) There´s no need for a space between return and $s. 2) recursive function, 67 bytes function f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s; 3) full program, 63 bytes: for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s; (run with -r)
                      – Titus
                      1 hour ago











                    • I'd have to include -r in the byte count, don't I?
                      – oktupol
                      1 hour ago
















                    Could you provide an explanation?
                    – FireCubez
                    2 hours ago




                    Could you provide an explanation?
                    – FireCubez
                    2 hours ago












                    1) There´s no need for a space between return and $s. 2) recursive function, 67 bytes function f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s; 3) full program, 63 bytes: for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s; (run with -r)
                    – Titus
                    1 hour ago





                    1) There´s no need for a space between return and $s. 2) recursive function, 67 bytes function f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s; 3) full program, 63 bytes: for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s; (run with -r)
                    – Titus
                    1 hour ago













                    I'd have to include -r in the byte count, don't I?
                    – oktupol
                    1 hour ago





                    I'd have to include -r in the byte count, don't I?
                    – oktupol
                    1 hour ago











                    up vote
                    1
                    down vote














                    V, 3 bytes



                    ÀII


                    Try it online!



                    Takes string as input, prepends as many I as stated in the first argument.






                    share|improve this answer
























                      up vote
                      1
                      down vote














                      V, 3 bytes



                      ÀII


                      Try it online!



                      Takes string as input, prepends as many I as stated in the first argument.






                      share|improve this answer






















                        up vote
                        1
                        down vote










                        up vote
                        1
                        down vote










                        V, 3 bytes



                        ÀII


                        Try it online!



                        Takes string as input, prepends as many I as stated in the first argument.






                        share|improve this answer













                        V, 3 bytes



                        ÀII


                        Try it online!



                        Takes string as input, prepends as many I as stated in the first argument.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered 2 hours ago









                        oktupol

                        4618




                        4618




















                            up vote
                            0
                            down vote














                            JavaScript (Node.js), 43 bytes



                            Outputs a program that outputs a program that outp.... until b=1





                            f=(a,b)=>b?--b?`(f=$f)('$a',$b)`:a:''


                            Try it online!






                            share|improve this answer






















                            • This does not match the test cases, the output for f("hello", 2) should be console.log("console.log("hello")") or console.log("console.log('hello')")
                              – FireCubez
                              2 hours ago










                            • Yes it is... it just outputs console.log("hello")
                              – FireCubez
                              2 hours ago










                            • Does not work for n=0
                              – FireCubez
                              2 hours ago










                            • Nevermind, it's just 1-indexed
                              – FireCubez
                              2 hours ago














                            up vote
                            0
                            down vote














                            JavaScript (Node.js), 43 bytes



                            Outputs a program that outputs a program that outp.... until b=1





                            f=(a,b)=>b?--b?`(f=$f)('$a',$b)`:a:''


                            Try it online!






                            share|improve this answer






















                            • This does not match the test cases, the output for f("hello", 2) should be console.log("console.log("hello")") or console.log("console.log('hello')")
                              – FireCubez
                              2 hours ago










                            • Yes it is... it just outputs console.log("hello")
                              – FireCubez
                              2 hours ago










                            • Does not work for n=0
                              – FireCubez
                              2 hours ago










                            • Nevermind, it's just 1-indexed
                              – FireCubez
                              2 hours ago












                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote










                            JavaScript (Node.js), 43 bytes



                            Outputs a program that outputs a program that outp.... until b=1





                            f=(a,b)=>b?--b?`(f=$f)('$a',$b)`:a:''


                            Try it online!






                            share|improve this answer















                            JavaScript (Node.js), 43 bytes



                            Outputs a program that outputs a program that outp.... until b=1





                            f=(a,b)=>b?--b?`(f=$f)('$a',$b)`:a:''


                            Try it online!







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 2 hours ago

























                            answered 2 hours ago









                            Luis felipe De jesus Munoz

                            3,24611049




                            3,24611049











                            • This does not match the test cases, the output for f("hello", 2) should be console.log("console.log("hello")") or console.log("console.log('hello')")
                              – FireCubez
                              2 hours ago










                            • Yes it is... it just outputs console.log("hello")
                              – FireCubez
                              2 hours ago










                            • Does not work for n=0
                              – FireCubez
                              2 hours ago










                            • Nevermind, it's just 1-indexed
                              – FireCubez
                              2 hours ago
















                            • This does not match the test cases, the output for f("hello", 2) should be console.log("console.log("hello")") or console.log("console.log('hello')")
                              – FireCubez
                              2 hours ago










                            • Yes it is... it just outputs console.log("hello")
                              – FireCubez
                              2 hours ago










                            • Does not work for n=0
                              – FireCubez
                              2 hours ago










                            • Nevermind, it's just 1-indexed
                              – FireCubez
                              2 hours ago















                            This does not match the test cases, the output for f("hello", 2) should be console.log("console.log("hello")") or console.log("console.log('hello')")
                            – FireCubez
                            2 hours ago




                            This does not match the test cases, the output for f("hello", 2) should be console.log("console.log("hello")") or console.log("console.log('hello')")
                            – FireCubez
                            2 hours ago












                            Yes it is... it just outputs console.log("hello")
                            – FireCubez
                            2 hours ago




                            Yes it is... it just outputs console.log("hello")
                            – FireCubez
                            2 hours ago












                            Does not work for n=0
                            – FireCubez
                            2 hours ago




                            Does not work for n=0
                            – FireCubez
                            2 hours ago












                            Nevermind, it's just 1-indexed
                            – FireCubez
                            2 hours ago




                            Nevermind, it's just 1-indexed
                            – FireCubez
                            2 hours ago










                            up vote
                            0
                            down vote














                            Haskell, 42 bytes





                            s#n|n<1=s|0<1="main=putStr"++show(s#(n-1))


                            Try it online!






                            share|improve this answer




















                            • I think ...0<1=show$s#(n-1) is enough, because we treat values in Haskell as functions.
                              – nimi
                              1 hour ago














                            up vote
                            0
                            down vote














                            Haskell, 42 bytes





                            s#n|n<1=s|0<1="main=putStr"++show(s#(n-1))


                            Try it online!






                            share|improve this answer




















                            • I think ...0<1=show$s#(n-1) is enough, because we treat values in Haskell as functions.
                              – nimi
                              1 hour ago












                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote










                            Haskell, 42 bytes





                            s#n|n<1=s|0<1="main=putStr"++show(s#(n-1))


                            Try it online!






                            share|improve this answer













                            Haskell, 42 bytes





                            s#n|n<1=s|0<1="main=putStr"++show(s#(n-1))


                            Try it online!







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 2 hours ago









                            Max Yekhlakov

                            3016




                            3016











                            • I think ...0<1=show$s#(n-1) is enough, because we treat values in Haskell as functions.
                              – nimi
                              1 hour ago
















                            • I think ...0<1=show$s#(n-1) is enough, because we treat values in Haskell as functions.
                              – nimi
                              1 hour ago















                            I think ...0<1=show$s#(n-1) is enough, because we treat values in Haskell as functions.
                            – nimi
                            1 hour ago




                            I think ...0<1=show$s#(n-1) is enough, because we treat values in Haskell as functions.
                            – nimi
                            1 hour ago










                            up vote
                            0
                            down vote














                            Perl 6, 25 bytes





                            'Q«'x$^n~$^s~'»'x$n


                            Try it online!



                            Function returning function code. Uses Q« » to quote unescaped ASCII strings.






                            share|improve this answer


























                              up vote
                              0
                              down vote














                              Perl 6, 25 bytes





                              'Q«'x$^n~$^s~'»'x$n


                              Try it online!



                              Function returning function code. Uses Q« » to quote unescaped ASCII strings.






                              share|improve this answer
























                                up vote
                                0
                                down vote










                                up vote
                                0
                                down vote










                                Perl 6, 25 bytes





                                'Q«'x$^n~$^s~'»'x$n


                                Try it online!



                                Function returning function code. Uses Q« » to quote unescaped ASCII strings.






                                share|improve this answer















                                Perl 6, 25 bytes





                                'Q«'x$^n~$^s~'»'x$n


                                Try it online!



                                Function returning function code. Uses Q« » to quote unescaped ASCII strings.







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited 2 hours ago

























                                answered 2 hours ago









                                nwellnhof

                                4,307817




                                4,307817




















                                    up vote
                                    0
                                    down vote













                                    PHP, 12+1 bytes, not competing



                                    plain text is a valid PHP program, but, if N is not 0, this fails for text containing <? with short tags enabled and for text containing <?php or <?= in any case:



                                    <?=$argv[1];


                                    call with php -R '<code>' '<string>' <n>;
                                    call the output with php -R '<code>'






                                    share|improve this answer
























                                      up vote
                                      0
                                      down vote













                                      PHP, 12+1 bytes, not competing



                                      plain text is a valid PHP program, but, if N is not 0, this fails for text containing <? with short tags enabled and for text containing <?php or <?= in any case:



                                      <?=$argv[1];


                                      call with php -R '<code>' '<string>' <n>;
                                      call the output with php -R '<code>'






                                      share|improve this answer






















                                        up vote
                                        0
                                        down vote










                                        up vote
                                        0
                                        down vote









                                        PHP, 12+1 bytes, not competing



                                        plain text is a valid PHP program, but, if N is not 0, this fails for text containing <? with short tags enabled and for text containing <?php or <?= in any case:



                                        <?=$argv[1];


                                        call with php -R '<code>' '<string>' <n>;
                                        call the output with php -R '<code>'






                                        share|improve this answer












                                        PHP, 12+1 bytes, not competing



                                        plain text is a valid PHP program, but, if N is not 0, this fails for text containing <? with short tags enabled and for text containing <?php or <?= in any case:



                                        <?=$argv[1];


                                        call with php -R '<code>' '<string>' <n>;
                                        call the output with php -R '<code>'







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered 1 hour ago









                                        Titus

                                        12.6k11236




                                        12.6k11236




















                                            up vote
                                            0
                                            down vote













                                            Google Sheets, 96 bytes



                                            =Join("",If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),),A1,Rept("""",2^B1-1))


                                            Inputs are in cells A1 (s) and B1 (n).



                                            Sample Results



                                            (Columns D, E, and F show the result if you copy the output from the column to its left and input it as a formula.)




                                            The formula concatenates 3 pieces into a single string. The first piece is the most complicated.



                                            If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),)


                                            If If statement drops the prefix if n=0 so you end up with No cycles instead of ="No cycles. The ArrayFormula creates an array of equal signs followed by some number quotes. That number is 2^(x-1) where x counts up from 1 to n thanks to the Row(Offset(~)) combination.



                                            The next piece (A1) adds in s and the final piece (Rept("""",2^B1-1)) adds in 2^n-1 quotes at the end.






                                            share|improve this answer
























                                              up vote
                                              0
                                              down vote













                                              Google Sheets, 96 bytes



                                              =Join("",If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),),A1,Rept("""",2^B1-1))


                                              Inputs are in cells A1 (s) and B1 (n).



                                              Sample Results



                                              (Columns D, E, and F show the result if you copy the output from the column to its left and input it as a formula.)




                                              The formula concatenates 3 pieces into a single string. The first piece is the most complicated.



                                              If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),)


                                              If If statement drops the prefix if n=0 so you end up with No cycles instead of ="No cycles. The ArrayFormula creates an array of equal signs followed by some number quotes. That number is 2^(x-1) where x counts up from 1 to n thanks to the Row(Offset(~)) combination.



                                              The next piece (A1) adds in s and the final piece (Rept("""",2^B1-1)) adds in 2^n-1 quotes at the end.






                                              share|improve this answer






















                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote









                                                Google Sheets, 96 bytes



                                                =Join("",If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),),A1,Rept("""",2^B1-1))


                                                Inputs are in cells A1 (s) and B1 (n).



                                                Sample Results



                                                (Columns D, E, and F show the result if you copy the output from the column to its left and input it as a formula.)




                                                The formula concatenates 3 pieces into a single string. The first piece is the most complicated.



                                                If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),)


                                                If If statement drops the prefix if n=0 so you end up with No cycles instead of ="No cycles. The ArrayFormula creates an array of equal signs followed by some number quotes. That number is 2^(x-1) where x counts up from 1 to n thanks to the Row(Offset(~)) combination.



                                                The next piece (A1) adds in s and the final piece (Rept("""",2^B1-1)) adds in 2^n-1 quotes at the end.






                                                share|improve this answer












                                                Google Sheets, 96 bytes



                                                =Join("",If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),),A1,Rept("""",2^B1-1))


                                                Inputs are in cells A1 (s) and B1 (n).



                                                Sample Results



                                                (Columns D, E, and F show the result if you copy the output from the column to its left and input it as a formula.)




                                                The formula concatenates 3 pieces into a single string. The first piece is the most complicated.



                                                If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),)


                                                If If statement drops the prefix if n=0 so you end up with No cycles instead of ="No cycles. The ArrayFormula creates an array of equal signs followed by some number quotes. That number is 2^(x-1) where x counts up from 1 to n thanks to the Row(Offset(~)) combination.



                                                The next piece (A1) adds in s and the final piece (Rept("""",2^B1-1)) adds in 2^n-1 quotes at the end.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered 1 hour ago









                                                Engineer Toast

                                                4,9641136




                                                4,9641136




















                                                    up vote
                                                    0
                                                    down vote














                                                    Jelly, 2 bytes



                                                    Ṿ¡


                                                    Try it online!






                                                    share|improve this answer




















                                                    • Explanation? How does this wor
                                                      – FireCubez
                                                      1 hour ago










                                                    • @FireCubez It simply executes the value → string representation function n times.
                                                      – Erik the Outgolfer
                                                      53 mins ago










                                                    • And does executing the string representation of a value print the value?
                                                      – FireCubez
                                                      52 mins ago










                                                    • @FireCubez The eval function (V) simply evaluates the code within a string. It doesn't implicitly print anything.
                                                      – Erik the Outgolfer
                                                      50 mins ago















                                                    up vote
                                                    0
                                                    down vote














                                                    Jelly, 2 bytes



                                                    Ṿ¡


                                                    Try it online!






                                                    share|improve this answer




















                                                    • Explanation? How does this wor
                                                      – FireCubez
                                                      1 hour ago










                                                    • @FireCubez It simply executes the value → string representation function n times.
                                                      – Erik the Outgolfer
                                                      53 mins ago










                                                    • And does executing the string representation of a value print the value?
                                                      – FireCubez
                                                      52 mins ago










                                                    • @FireCubez The eval function (V) simply evaluates the code within a string. It doesn't implicitly print anything.
                                                      – Erik the Outgolfer
                                                      50 mins ago













                                                    up vote
                                                    0
                                                    down vote










                                                    up vote
                                                    0
                                                    down vote










                                                    Jelly, 2 bytes



                                                    Ṿ¡


                                                    Try it online!






                                                    share|improve this answer













                                                    Jelly, 2 bytes



                                                    Ṿ¡


                                                    Try it online!







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered 1 hour ago









                                                    Erik the Outgolfer

                                                    29.8k42899




                                                    29.8k42899











                                                    • Explanation? How does this wor
                                                      – FireCubez
                                                      1 hour ago










                                                    • @FireCubez It simply executes the value → string representation function n times.
                                                      – Erik the Outgolfer
                                                      53 mins ago










                                                    • And does executing the string representation of a value print the value?
                                                      – FireCubez
                                                      52 mins ago










                                                    • @FireCubez The eval function (V) simply evaluates the code within a string. It doesn't implicitly print anything.
                                                      – Erik the Outgolfer
                                                      50 mins ago

















                                                    • Explanation? How does this wor
                                                      – FireCubez
                                                      1 hour ago










                                                    • @FireCubez It simply executes the value → string representation function n times.
                                                      – Erik the Outgolfer
                                                      53 mins ago










                                                    • And does executing the string representation of a value print the value?
                                                      – FireCubez
                                                      52 mins ago










                                                    • @FireCubez The eval function (V) simply evaluates the code within a string. It doesn't implicitly print anything.
                                                      – Erik the Outgolfer
                                                      50 mins ago
















                                                    Explanation? How does this wor
                                                    – FireCubez
                                                    1 hour ago




                                                    Explanation? How does this wor
                                                    – FireCubez
                                                    1 hour ago












                                                    @FireCubez It simply executes the value → string representation function n times.
                                                    – Erik the Outgolfer
                                                    53 mins ago




                                                    @FireCubez It simply executes the value → string representation function n times.
                                                    – Erik the Outgolfer
                                                    53 mins ago












                                                    And does executing the string representation of a value print the value?
                                                    – FireCubez
                                                    52 mins ago




                                                    And does executing the string representation of a value print the value?
                                                    – FireCubez
                                                    52 mins ago












                                                    @FireCubez The eval function (V) simply evaluates the code within a string. It doesn't implicitly print anything.
                                                    – Erik the Outgolfer
                                                    50 mins ago





                                                    @FireCubez The eval function (V) simply evaluates the code within a string. It doesn't implicitly print anything.
                                                    – Erik the Outgolfer
                                                    50 mins ago


















                                                     

                                                    draft saved


                                                    draft discarded















































                                                     


                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function ()
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173915%2fcycle-my-input-please%23new-answer', 'question_page');

                                                    );

                                                    Post as a guest













































































                                                    Comments

                                                    Popular posts from this blog

                                                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                                                    What does second last employer means? [closed]

                                                    One-line joke