Just Twice Is Nice












4












$begingroup$


Let's have string multiplication to take a string and a positive number and concatenate that string that many times. In Haskell:



0 * s = ""
n * s = s ++ ((n - 1) * s)


Your task is to write a program that outputs a number $n > 0$. When you double your program (with the described procedure) the new program should output $2n$. When your program is tripled or quadrupled it should once again output the original $n$.



This is code-golf so your answers will be scored in bytes with fewer bytes being better.





Related, Related.










share|improve this question









$endgroup$








  • 5




    $begingroup$
    All the solutions so far are trivial modifications of solutions to existing challenges so I wouldn't be surprised to see this dupe-hammered by someone.
    $endgroup$
    – Shaggy
    Dec 20 '18 at 22:14










  • $begingroup$
    @Shaggy I disagree. For some the best approach is from the 3rd times the charm from some its the doubling, for some still (klein, lost etc.) a port wouldn't even work.
    $endgroup$
    – Wît Wisarhd
    Dec 24 '18 at 22:03
















4












$begingroup$


Let's have string multiplication to take a string and a positive number and concatenate that string that many times. In Haskell:



0 * s = ""
n * s = s ++ ((n - 1) * s)


Your task is to write a program that outputs a number $n > 0$. When you double your program (with the described procedure) the new program should output $2n$. When your program is tripled or quadrupled it should once again output the original $n$.



This is code-golf so your answers will be scored in bytes with fewer bytes being better.





Related, Related.










share|improve this question









$endgroup$








  • 5




    $begingroup$
    All the solutions so far are trivial modifications of solutions to existing challenges so I wouldn't be surprised to see this dupe-hammered by someone.
    $endgroup$
    – Shaggy
    Dec 20 '18 at 22:14










  • $begingroup$
    @Shaggy I disagree. For some the best approach is from the 3rd times the charm from some its the doubling, for some still (klein, lost etc.) a port wouldn't even work.
    $endgroup$
    – Wît Wisarhd
    Dec 24 '18 at 22:03














4












4








4


0



$begingroup$


Let's have string multiplication to take a string and a positive number and concatenate that string that many times. In Haskell:



0 * s = ""
n * s = s ++ ((n - 1) * s)


Your task is to write a program that outputs a number $n > 0$. When you double your program (with the described procedure) the new program should output $2n$. When your program is tripled or quadrupled it should once again output the original $n$.



This is code-golf so your answers will be scored in bytes with fewer bytes being better.





Related, Related.










share|improve this question









$endgroup$




Let's have string multiplication to take a string and a positive number and concatenate that string that many times. In Haskell:



0 * s = ""
n * s = s ++ ((n - 1) * s)


Your task is to write a program that outputs a number $n > 0$. When you double your program (with the described procedure) the new program should output $2n$. When your program is tripled or quadrupled it should once again output the original $n$.



This is code-golf so your answers will be scored in bytes with fewer bytes being better.





Related, Related.







code-golf source-layout






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 20 '18 at 21:03









Wît WisarhdWît Wisarhd

34k10156366




34k10156366








  • 5




    $begingroup$
    All the solutions so far are trivial modifications of solutions to existing challenges so I wouldn't be surprised to see this dupe-hammered by someone.
    $endgroup$
    – Shaggy
    Dec 20 '18 at 22:14










  • $begingroup$
    @Shaggy I disagree. For some the best approach is from the 3rd times the charm from some its the doubling, for some still (klein, lost etc.) a port wouldn't even work.
    $endgroup$
    – Wît Wisarhd
    Dec 24 '18 at 22:03














  • 5




    $begingroup$
    All the solutions so far are trivial modifications of solutions to existing challenges so I wouldn't be surprised to see this dupe-hammered by someone.
    $endgroup$
    – Shaggy
    Dec 20 '18 at 22:14










  • $begingroup$
    @Shaggy I disagree. For some the best approach is from the 3rd times the charm from some its the doubling, for some still (klein, lost etc.) a port wouldn't even work.
    $endgroup$
    – Wît Wisarhd
    Dec 24 '18 at 22:03








5




5




$begingroup$
All the solutions so far are trivial modifications of solutions to existing challenges so I wouldn't be surprised to see this dupe-hammered by someone.
$endgroup$
– Shaggy
Dec 20 '18 at 22:14




$begingroup$
All the solutions so far are trivial modifications of solutions to existing challenges so I wouldn't be surprised to see this dupe-hammered by someone.
$endgroup$
– Shaggy
Dec 20 '18 at 22:14












$begingroup$
@Shaggy I disagree. For some the best approach is from the 3rd times the charm from some its the doubling, for some still (klein, lost etc.) a port wouldn't even work.
$endgroup$
– Wît Wisarhd
Dec 24 '18 at 22:03




$begingroup$
@Shaggy I disagree. For some the best approach is from the 3rd times the charm from some its the doubling, for some still (klein, lost etc.) a port wouldn't even work.
$endgroup$
– Wît Wisarhd
Dec 24 '18 at 22:03










7 Answers
7






active

oldest

votes


















3












$begingroup$


Python 2, 9 bytes



Outputs via exit code. Full credit goes to Anders Kaseorg for this answer to I double the source, you double the output!.





';exit(2)


Try it online! | Doubled | Tripled | Quadrupled



Regularly, this raises a Syntax Error because the string is not closed properly and exists with exit code 1, then, when doubled, it becomes ';exit(2)';exit(2) which simply exits with code 2 because the string literal is now quoted properly and has no effect at all, and when repeated any other arbitrary number of times, it raises Syntax Errors.






share|improve this answer









$endgroup$





















    3












    $begingroup$


    R, 27 25 bytes





    1+!1-length(readLines())



    Try it online!



    Inspired by rturnbull's answer to Third time the charm, but the simplicity of the check makes it shorter.



    Doubled | Tripled | Quadrupled



    Why this works:



    readLines() will actually reads the source file itself rather than stdin. Hence, adding lines just increments the length() of the vector returned by readLines(). Therefore, we compute !(1-length()) to obtain 1 whenever length()==1 and 0 when length()!=1, adding one to have the desired effect.






    share|improve this answer











    $endgroup$





















      2












      $begingroup$


      Runic Enchantments, 29 bytes



      ^w '
      /1@ 3
      / ~!4
      2'51w
      /yyy


      Try it online!



      Slight alteration from the Third Times A Charm entry, using Jo King's compressed version and swapping the two reflection locations.



      Twice



      Thrice



      And frice for good measure.






      share|improve this answer











      $endgroup$













      • $begingroup$
        What did you name the language after? God of War?
        $endgroup$
        – Riker
        Dec 25 '18 at 0:39










      • $begingroup$
        @Riker I named it because I want to (eventually) have a RPG-esque game where enchantments on gear can be created by players using a runic script (that, to the best of my ability) mapped to the 95 keyboard printable characters. I've added some extension symbols utilizing unicode combining characters (as well as a handful of other unicode characters that more readily represent the given action, such as π and several arrows). Once I have that game I'll end up making "runic 2.0" that has those game-specific commands (and probably remaps a lot of mathy stuff).
        $endgroup$
        – Draco18s
        Dec 25 '18 at 2:10










      • $begingroup$
        Draco: huh, interesting, I'd love to see the final result.
        $endgroup$
        – Riker
        Dec 25 '18 at 4:26



















      2












      $begingroup$


      Klein 000, 6 bytes



      1+@



      Try it online!



      Explanation



      The idea here is pretty simple, the first 2 copies require the ip to move off the edge of the program but the third does not, that way adding anything extra after the third doesn't change anything.



      The first program reflects off of both edges the







      At the begining is just a fancy noop. So we just run 1+@.



      For the two copies this gets interrupted



      1+@
      \1+@



      We hit both 1s and a + to get 2.



      On the three we interrupt the path even further



      1+@
      \1+@
      \1+@



      At this point it might not be the clearest, but the ip bounces around in the mirrors a bit before it hits runs the 3rd line.



      This is what it runs




      \
      1+@


      Since this doesn't go off an edge further additions don't make any change to the program.






      share|improve this answer











      $endgroup$





















        1












        $begingroup$


        Charcoal, 10 bytes



        PI⊕⁼²L⊞Oυω


        Try it online! Based on my answer to I double the source, you double the output! but compares the length to 2. Try it doubled. Try it tripled. Try it quadrupled. In verbose syntax this is Multiprint(Cast(Incremented(Equals(2, Length(PushOperator(u, w)))))));.






        share|improve this answer









        $endgroup$





















          1












          $begingroup$


          MATL, 9 bytes



          vxHQXH4=Q


          Uses n = 1.



          Try it online! Original, doubled, tripled, quadrupled.



          Explanation



          This uses clipboard H to store state information. Function H pastes the clipboard contents onto the stack. Function XH copies the top of the stack into the clipboard. The clipboard initially contains the number 2.



          Each time the snippet vxHQXH4=Q is run it does the following.
          The stack contents, if any, are deleted (vx). The clipboard contents are pushed (H) and incremented (Q), and the result is copied back into the clipboard (XH). This gives 4 the second time, and only that time.



          The number in the stack is tested for equality with 4 (4=) and incremented (Q). This gives 2 for 4 (second time), and 1 otherwise (any other time).






          share|improve this answer











          $endgroup$





















            1












            $begingroup$


            05AB1E, 7 6 bytes, n=3



            ₆.g2Qè


            Try it online; try it doubled; try it tripled; try it quadrupled.



            Explanation:





            ₆         # Push 36
            .g # Push the amount of items on the stack
            2Q # Check if that amount is equal to 2 (results in 1 if truthy; 0 if falsey)
            è # Index that into the 36 (and output the top of the stack implicitly)





            share|improve this answer











            $endgroup$













              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',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              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%2f177881%2fjust-twice-is-nice%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              7 Answers
              7






              active

              oldest

              votes








              7 Answers
              7






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3












              $begingroup$


              Python 2, 9 bytes



              Outputs via exit code. Full credit goes to Anders Kaseorg for this answer to I double the source, you double the output!.





              ';exit(2)


              Try it online! | Doubled | Tripled | Quadrupled



              Regularly, this raises a Syntax Error because the string is not closed properly and exists with exit code 1, then, when doubled, it becomes ';exit(2)';exit(2) which simply exits with code 2 because the string literal is now quoted properly and has no effect at all, and when repeated any other arbitrary number of times, it raises Syntax Errors.






              share|improve this answer









              $endgroup$


















                3












                $begingroup$


                Python 2, 9 bytes



                Outputs via exit code. Full credit goes to Anders Kaseorg for this answer to I double the source, you double the output!.





                ';exit(2)


                Try it online! | Doubled | Tripled | Quadrupled



                Regularly, this raises a Syntax Error because the string is not closed properly and exists with exit code 1, then, when doubled, it becomes ';exit(2)';exit(2) which simply exits with code 2 because the string literal is now quoted properly and has no effect at all, and when repeated any other arbitrary number of times, it raises Syntax Errors.






                share|improve this answer









                $endgroup$
















                  3












                  3








                  3





                  $begingroup$


                  Python 2, 9 bytes



                  Outputs via exit code. Full credit goes to Anders Kaseorg for this answer to I double the source, you double the output!.





                  ';exit(2)


                  Try it online! | Doubled | Tripled | Quadrupled



                  Regularly, this raises a Syntax Error because the string is not closed properly and exists with exit code 1, then, when doubled, it becomes ';exit(2)';exit(2) which simply exits with code 2 because the string literal is now quoted properly and has no effect at all, and when repeated any other arbitrary number of times, it raises Syntax Errors.






                  share|improve this answer









                  $endgroup$




                  Python 2, 9 bytes



                  Outputs via exit code. Full credit goes to Anders Kaseorg for this answer to I double the source, you double the output!.





                  ';exit(2)


                  Try it online! | Doubled | Tripled | Quadrupled



                  Regularly, this raises a Syntax Error because the string is not closed properly and exists with exit code 1, then, when doubled, it becomes ';exit(2)';exit(2) which simply exits with code 2 because the string literal is now quoted properly and has no effect at all, and when repeated any other arbitrary number of times, it raises Syntax Errors.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 20 '18 at 21:29









                  Mr. XcoderMr. Xcoder

                  31.7k759198




                  31.7k759198























                      3












                      $begingroup$


                      R, 27 25 bytes





                      1+!1-length(readLines())



                      Try it online!



                      Inspired by rturnbull's answer to Third time the charm, but the simplicity of the check makes it shorter.



                      Doubled | Tripled | Quadrupled



                      Why this works:



                      readLines() will actually reads the source file itself rather than stdin. Hence, adding lines just increments the length() of the vector returned by readLines(). Therefore, we compute !(1-length()) to obtain 1 whenever length()==1 and 0 when length()!=1, adding one to have the desired effect.






                      share|improve this answer











                      $endgroup$


















                        3












                        $begingroup$


                        R, 27 25 bytes





                        1+!1-length(readLines())



                        Try it online!



                        Inspired by rturnbull's answer to Third time the charm, but the simplicity of the check makes it shorter.



                        Doubled | Tripled | Quadrupled



                        Why this works:



                        readLines() will actually reads the source file itself rather than stdin. Hence, adding lines just increments the length() of the vector returned by readLines(). Therefore, we compute !(1-length()) to obtain 1 whenever length()==1 and 0 when length()!=1, adding one to have the desired effect.






                        share|improve this answer











                        $endgroup$
















                          3












                          3








                          3





                          $begingroup$


                          R, 27 25 bytes





                          1+!1-length(readLines())



                          Try it online!



                          Inspired by rturnbull's answer to Third time the charm, but the simplicity of the check makes it shorter.



                          Doubled | Tripled | Quadrupled



                          Why this works:



                          readLines() will actually reads the source file itself rather than stdin. Hence, adding lines just increments the length() of the vector returned by readLines(). Therefore, we compute !(1-length()) to obtain 1 whenever length()==1 and 0 when length()!=1, adding one to have the desired effect.






                          share|improve this answer











                          $endgroup$




                          R, 27 25 bytes





                          1+!1-length(readLines())



                          Try it online!



                          Inspired by rturnbull's answer to Third time the charm, but the simplicity of the check makes it shorter.



                          Doubled | Tripled | Quadrupled



                          Why this works:



                          readLines() will actually reads the source file itself rather than stdin. Hence, adding lines just increments the length() of the vector returned by readLines(). Therefore, we compute !(1-length()) to obtain 1 whenever length()==1 and 0 when length()!=1, adding one to have the desired effect.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Dec 20 '18 at 21:41

























                          answered Dec 20 '18 at 21:28









                          GiuseppeGiuseppe

                          16.5k31052




                          16.5k31052























                              2












                              $begingroup$


                              Runic Enchantments, 29 bytes



                              ^w '
                              /1@ 3
                              / ~!4
                              2'51w
                              /yyy


                              Try it online!



                              Slight alteration from the Third Times A Charm entry, using Jo King's compressed version and swapping the two reflection locations.



                              Twice



                              Thrice



                              And frice for good measure.






                              share|improve this answer











                              $endgroup$













                              • $begingroup$
                                What did you name the language after? God of War?
                                $endgroup$
                                – Riker
                                Dec 25 '18 at 0:39










                              • $begingroup$
                                @Riker I named it because I want to (eventually) have a RPG-esque game where enchantments on gear can be created by players using a runic script (that, to the best of my ability) mapped to the 95 keyboard printable characters. I've added some extension symbols utilizing unicode combining characters (as well as a handful of other unicode characters that more readily represent the given action, such as π and several arrows). Once I have that game I'll end up making "runic 2.0" that has those game-specific commands (and probably remaps a lot of mathy stuff).
                                $endgroup$
                                – Draco18s
                                Dec 25 '18 at 2:10










                              • $begingroup$
                                Draco: huh, interesting, I'd love to see the final result.
                                $endgroup$
                                – Riker
                                Dec 25 '18 at 4:26
















                              2












                              $begingroup$


                              Runic Enchantments, 29 bytes



                              ^w '
                              /1@ 3
                              / ~!4
                              2'51w
                              /yyy


                              Try it online!



                              Slight alteration from the Third Times A Charm entry, using Jo King's compressed version and swapping the two reflection locations.



                              Twice



                              Thrice



                              And frice for good measure.






                              share|improve this answer











                              $endgroup$













                              • $begingroup$
                                What did you name the language after? God of War?
                                $endgroup$
                                – Riker
                                Dec 25 '18 at 0:39










                              • $begingroup$
                                @Riker I named it because I want to (eventually) have a RPG-esque game where enchantments on gear can be created by players using a runic script (that, to the best of my ability) mapped to the 95 keyboard printable characters. I've added some extension symbols utilizing unicode combining characters (as well as a handful of other unicode characters that more readily represent the given action, such as π and several arrows). Once I have that game I'll end up making "runic 2.0" that has those game-specific commands (and probably remaps a lot of mathy stuff).
                                $endgroup$
                                – Draco18s
                                Dec 25 '18 at 2:10










                              • $begingroup$
                                Draco: huh, interesting, I'd love to see the final result.
                                $endgroup$
                                – Riker
                                Dec 25 '18 at 4:26














                              2












                              2








                              2





                              $begingroup$


                              Runic Enchantments, 29 bytes



                              ^w '
                              /1@ 3
                              / ~!4
                              2'51w
                              /yyy


                              Try it online!



                              Slight alteration from the Third Times A Charm entry, using Jo King's compressed version and swapping the two reflection locations.



                              Twice



                              Thrice



                              And frice for good measure.






                              share|improve this answer











                              $endgroup$




                              Runic Enchantments, 29 bytes



                              ^w '
                              /1@ 3
                              / ~!4
                              2'51w
                              /yyy


                              Try it online!



                              Slight alteration from the Third Times A Charm entry, using Jo King's compressed version and swapping the two reflection locations.



                              Twice



                              Thrice



                              And frice for good measure.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Dec 21 '18 at 0:31

























                              answered Dec 20 '18 at 21:32









                              Draco18sDraco18s

                              1,261619




                              1,261619












                              • $begingroup$
                                What did you name the language after? God of War?
                                $endgroup$
                                – Riker
                                Dec 25 '18 at 0:39










                              • $begingroup$
                                @Riker I named it because I want to (eventually) have a RPG-esque game where enchantments on gear can be created by players using a runic script (that, to the best of my ability) mapped to the 95 keyboard printable characters. I've added some extension symbols utilizing unicode combining characters (as well as a handful of other unicode characters that more readily represent the given action, such as π and several arrows). Once I have that game I'll end up making "runic 2.0" that has those game-specific commands (and probably remaps a lot of mathy stuff).
                                $endgroup$
                                – Draco18s
                                Dec 25 '18 at 2:10










                              • $begingroup$
                                Draco: huh, interesting, I'd love to see the final result.
                                $endgroup$
                                – Riker
                                Dec 25 '18 at 4:26


















                              • $begingroup$
                                What did you name the language after? God of War?
                                $endgroup$
                                – Riker
                                Dec 25 '18 at 0:39










                              • $begingroup$
                                @Riker I named it because I want to (eventually) have a RPG-esque game where enchantments on gear can be created by players using a runic script (that, to the best of my ability) mapped to the 95 keyboard printable characters. I've added some extension symbols utilizing unicode combining characters (as well as a handful of other unicode characters that more readily represent the given action, such as π and several arrows). Once I have that game I'll end up making "runic 2.0" that has those game-specific commands (and probably remaps a lot of mathy stuff).
                                $endgroup$
                                – Draco18s
                                Dec 25 '18 at 2:10










                              • $begingroup$
                                Draco: huh, interesting, I'd love to see the final result.
                                $endgroup$
                                – Riker
                                Dec 25 '18 at 4:26
















                              $begingroup$
                              What did you name the language after? God of War?
                              $endgroup$
                              – Riker
                              Dec 25 '18 at 0:39




                              $begingroup$
                              What did you name the language after? God of War?
                              $endgroup$
                              – Riker
                              Dec 25 '18 at 0:39












                              $begingroup$
                              @Riker I named it because I want to (eventually) have a RPG-esque game where enchantments on gear can be created by players using a runic script (that, to the best of my ability) mapped to the 95 keyboard printable characters. I've added some extension symbols utilizing unicode combining characters (as well as a handful of other unicode characters that more readily represent the given action, such as π and several arrows). Once I have that game I'll end up making "runic 2.0" that has those game-specific commands (and probably remaps a lot of mathy stuff).
                              $endgroup$
                              – Draco18s
                              Dec 25 '18 at 2:10




                              $begingroup$
                              @Riker I named it because I want to (eventually) have a RPG-esque game where enchantments on gear can be created by players using a runic script (that, to the best of my ability) mapped to the 95 keyboard printable characters. I've added some extension symbols utilizing unicode combining characters (as well as a handful of other unicode characters that more readily represent the given action, such as π and several arrows). Once I have that game I'll end up making "runic 2.0" that has those game-specific commands (and probably remaps a lot of mathy stuff).
                              $endgroup$
                              – Draco18s
                              Dec 25 '18 at 2:10












                              $begingroup$
                              Draco: huh, interesting, I'd love to see the final result.
                              $endgroup$
                              – Riker
                              Dec 25 '18 at 4:26




                              $begingroup$
                              Draco: huh, interesting, I'd love to see the final result.
                              $endgroup$
                              – Riker
                              Dec 25 '18 at 4:26











                              2












                              $begingroup$


                              Klein 000, 6 bytes



                              1+@



                              Try it online!



                              Explanation



                              The idea here is pretty simple, the first 2 copies require the ip to move off the edge of the program but the third does not, that way adding anything extra after the third doesn't change anything.



                              The first program reflects off of both edges the







                              At the begining is just a fancy noop. So we just run 1+@.



                              For the two copies this gets interrupted



                              1+@
                              \1+@



                              We hit both 1s and a + to get 2.



                              On the three we interrupt the path even further



                              1+@
                              \1+@
                              \1+@



                              At this point it might not be the clearest, but the ip bounces around in the mirrors a bit before it hits runs the 3rd line.



                              This is what it runs




                              \
                              1+@


                              Since this doesn't go off an edge further additions don't make any change to the program.






                              share|improve this answer











                              $endgroup$


















                                2












                                $begingroup$


                                Klein 000, 6 bytes



                                1+@



                                Try it online!



                                Explanation



                                The idea here is pretty simple, the first 2 copies require the ip to move off the edge of the program but the third does not, that way adding anything extra after the third doesn't change anything.



                                The first program reflects off of both edges the







                                At the begining is just a fancy noop. So we just run 1+@.



                                For the two copies this gets interrupted



                                1+@
                                \1+@



                                We hit both 1s and a + to get 2.



                                On the three we interrupt the path even further



                                1+@
                                \1+@
                                \1+@



                                At this point it might not be the clearest, but the ip bounces around in the mirrors a bit before it hits runs the 3rd line.



                                This is what it runs




                                \
                                1+@


                                Since this doesn't go off an edge further additions don't make any change to the program.






                                share|improve this answer











                                $endgroup$
















                                  2












                                  2








                                  2





                                  $begingroup$


                                  Klein 000, 6 bytes



                                  1+@



                                  Try it online!



                                  Explanation



                                  The idea here is pretty simple, the first 2 copies require the ip to move off the edge of the program but the third does not, that way adding anything extra after the third doesn't change anything.



                                  The first program reflects off of both edges the







                                  At the begining is just a fancy noop. So we just run 1+@.



                                  For the two copies this gets interrupted



                                  1+@
                                  \1+@



                                  We hit both 1s and a + to get 2.



                                  On the three we interrupt the path even further



                                  1+@
                                  \1+@
                                  \1+@



                                  At this point it might not be the clearest, but the ip bounces around in the mirrors a bit before it hits runs the 3rd line.



                                  This is what it runs




                                  \
                                  1+@


                                  Since this doesn't go off an edge further additions don't make any change to the program.






                                  share|improve this answer











                                  $endgroup$




                                  Klein 000, 6 bytes



                                  1+@



                                  Try it online!



                                  Explanation



                                  The idea here is pretty simple, the first 2 copies require the ip to move off the edge of the program but the third does not, that way adding anything extra after the third doesn't change anything.



                                  The first program reflects off of both edges the







                                  At the begining is just a fancy noop. So we just run 1+@.



                                  For the two copies this gets interrupted



                                  1+@
                                  \1+@



                                  We hit both 1s and a + to get 2.



                                  On the three we interrupt the path even further



                                  1+@
                                  \1+@
                                  \1+@



                                  At this point it might not be the clearest, but the ip bounces around in the mirrors a bit before it hits runs the 3rd line.



                                  This is what it runs




                                  \
                                  1+@


                                  Since this doesn't go off an edge further additions don't make any change to the program.







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Dec 25 '18 at 3:04

























                                  answered Dec 25 '18 at 2:58









                                  Wît WisarhdWît Wisarhd

                                  34k10156366




                                  34k10156366























                                      1












                                      $begingroup$


                                      Charcoal, 10 bytes



                                      PI⊕⁼²L⊞Oυω


                                      Try it online! Based on my answer to I double the source, you double the output! but compares the length to 2. Try it doubled. Try it tripled. Try it quadrupled. In verbose syntax this is Multiprint(Cast(Incremented(Equals(2, Length(PushOperator(u, w)))))));.






                                      share|improve this answer









                                      $endgroup$


















                                        1












                                        $begingroup$


                                        Charcoal, 10 bytes



                                        PI⊕⁼²L⊞Oυω


                                        Try it online! Based on my answer to I double the source, you double the output! but compares the length to 2. Try it doubled. Try it tripled. Try it quadrupled. In verbose syntax this is Multiprint(Cast(Incremented(Equals(2, Length(PushOperator(u, w)))))));.






                                        share|improve this answer









                                        $endgroup$
















                                          1












                                          1








                                          1





                                          $begingroup$


                                          Charcoal, 10 bytes



                                          PI⊕⁼²L⊞Oυω


                                          Try it online! Based on my answer to I double the source, you double the output! but compares the length to 2. Try it doubled. Try it tripled. Try it quadrupled. In verbose syntax this is Multiprint(Cast(Incremented(Equals(2, Length(PushOperator(u, w)))))));.






                                          share|improve this answer









                                          $endgroup$




                                          Charcoal, 10 bytes



                                          PI⊕⁼²L⊞Oυω


                                          Try it online! Based on my answer to I double the source, you double the output! but compares the length to 2. Try it doubled. Try it tripled. Try it quadrupled. In verbose syntax this is Multiprint(Cast(Incremented(Equals(2, Length(PushOperator(u, w)))))));.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Dec 20 '18 at 21:19









                                          NeilNeil

                                          79.8k744177




                                          79.8k744177























                                              1












                                              $begingroup$


                                              MATL, 9 bytes



                                              vxHQXH4=Q


                                              Uses n = 1.



                                              Try it online! Original, doubled, tripled, quadrupled.



                                              Explanation



                                              This uses clipboard H to store state information. Function H pastes the clipboard contents onto the stack. Function XH copies the top of the stack into the clipboard. The clipboard initially contains the number 2.



                                              Each time the snippet vxHQXH4=Q is run it does the following.
                                              The stack contents, if any, are deleted (vx). The clipboard contents are pushed (H) and incremented (Q), and the result is copied back into the clipboard (XH). This gives 4 the second time, and only that time.



                                              The number in the stack is tested for equality with 4 (4=) and incremented (Q). This gives 2 for 4 (second time), and 1 otherwise (any other time).






                                              share|improve this answer











                                              $endgroup$


















                                                1












                                                $begingroup$


                                                MATL, 9 bytes



                                                vxHQXH4=Q


                                                Uses n = 1.



                                                Try it online! Original, doubled, tripled, quadrupled.



                                                Explanation



                                                This uses clipboard H to store state information. Function H pastes the clipboard contents onto the stack. Function XH copies the top of the stack into the clipboard. The clipboard initially contains the number 2.



                                                Each time the snippet vxHQXH4=Q is run it does the following.
                                                The stack contents, if any, are deleted (vx). The clipboard contents are pushed (H) and incremented (Q), and the result is copied back into the clipboard (XH). This gives 4 the second time, and only that time.



                                                The number in the stack is tested for equality with 4 (4=) and incremented (Q). This gives 2 for 4 (second time), and 1 otherwise (any other time).






                                                share|improve this answer











                                                $endgroup$
















                                                  1












                                                  1








                                                  1





                                                  $begingroup$


                                                  MATL, 9 bytes



                                                  vxHQXH4=Q


                                                  Uses n = 1.



                                                  Try it online! Original, doubled, tripled, quadrupled.



                                                  Explanation



                                                  This uses clipboard H to store state information. Function H pastes the clipboard contents onto the stack. Function XH copies the top of the stack into the clipboard. The clipboard initially contains the number 2.



                                                  Each time the snippet vxHQXH4=Q is run it does the following.
                                                  The stack contents, if any, are deleted (vx). The clipboard contents are pushed (H) and incremented (Q), and the result is copied back into the clipboard (XH). This gives 4 the second time, and only that time.



                                                  The number in the stack is tested for equality with 4 (4=) and incremented (Q). This gives 2 for 4 (second time), and 1 otherwise (any other time).






                                                  share|improve this answer











                                                  $endgroup$




                                                  MATL, 9 bytes



                                                  vxHQXH4=Q


                                                  Uses n = 1.



                                                  Try it online! Original, doubled, tripled, quadrupled.



                                                  Explanation



                                                  This uses clipboard H to store state information. Function H pastes the clipboard contents onto the stack. Function XH copies the top of the stack into the clipboard. The clipboard initially contains the number 2.



                                                  Each time the snippet vxHQXH4=Q is run it does the following.
                                                  The stack contents, if any, are deleted (vx). The clipboard contents are pushed (H) and incremented (Q), and the result is copied back into the clipboard (XH). This gives 4 the second time, and only that time.



                                                  The number in the stack is tested for equality with 4 (4=) and incremented (Q). This gives 2 for 4 (second time), and 1 otherwise (any other time).







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Dec 20 '18 at 23:47

























                                                  answered Dec 20 '18 at 22:57









                                                  Luis MendoLuis Mendo

                                                  74.1k886291




                                                  74.1k886291























                                                      1












                                                      $begingroup$


                                                      05AB1E, 7 6 bytes, n=3



                                                      ₆.g2Qè


                                                      Try it online; try it doubled; try it tripled; try it quadrupled.



                                                      Explanation:





                                                      ₆         # Push 36
                                                      .g # Push the amount of items on the stack
                                                      2Q # Check if that amount is equal to 2 (results in 1 if truthy; 0 if falsey)
                                                      è # Index that into the 36 (and output the top of the stack implicitly)





                                                      share|improve this answer











                                                      $endgroup$


















                                                        1












                                                        $begingroup$


                                                        05AB1E, 7 6 bytes, n=3



                                                        ₆.g2Qè


                                                        Try it online; try it doubled; try it tripled; try it quadrupled.



                                                        Explanation:





                                                        ₆         # Push 36
                                                        .g # Push the amount of items on the stack
                                                        2Q # Check if that amount is equal to 2 (results in 1 if truthy; 0 if falsey)
                                                        è # Index that into the 36 (and output the top of the stack implicitly)





                                                        share|improve this answer











                                                        $endgroup$
















                                                          1












                                                          1








                                                          1





                                                          $begingroup$


                                                          05AB1E, 7 6 bytes, n=3



                                                          ₆.g2Qè


                                                          Try it online; try it doubled; try it tripled; try it quadrupled.



                                                          Explanation:





                                                          ₆         # Push 36
                                                          .g # Push the amount of items on the stack
                                                          2Q # Check if that amount is equal to 2 (results in 1 if truthy; 0 if falsey)
                                                          è # Index that into the 36 (and output the top of the stack implicitly)





                                                          share|improve this answer











                                                          $endgroup$




                                                          05AB1E, 7 6 bytes, n=3



                                                          ₆.g2Qè


                                                          Try it online; try it doubled; try it tripled; try it quadrupled.



                                                          Explanation:





                                                          ₆         # Push 36
                                                          .g # Push the amount of items on the stack
                                                          2Q # Check if that amount is equal to 2 (results in 1 if truthy; 0 if falsey)
                                                          è # Index that into the 36 (and output the top of the stack implicitly)






                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Dec 22 '18 at 18:09

























                                                          answered Dec 22 '18 at 17:50









                                                          Kevin CruijssenKevin Cruijssen

                                                          36.3k555192




                                                          36.3k555192






























                                                              draft saved

                                                              draft discarded




















































                                                              If this is an answer to a challenge…




                                                              • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                              • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                Explanations of your answer make it more interesting to read and are very much encouraged.


                                                              • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                              More generally…




                                                              • …Please make sure to answer the question and provide sufficient detail.


                                                              • …Avoid asking for help, clarification or responding to other answers (use comments instead).





                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f177881%2fjust-twice-is-nice%23new-answer', 'question_page');
                                                              }
                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                                                              Alcedinidae

                                                              Can an atomic nucleus contain both particles and antiparticles? [duplicate]