Play Zip, Zap, Zop












10












$begingroup$


There's a little improv warm up game where you arrange yourselves in a circle and send zips, zaps, and zops around by pointing to a person and saying the next word in the sequence, then they do the same until all of you are warmed up or whatever.



Your task is to create a program that gives the next word in sequence given an input word. (Zip --> Zap --> Zop --> Zip) Since there's a lot of different ways to say these three words and flairs that can be added to them, your program should imitate case and letter duplication and carry suffixes.



To elaborate, your input will be one or more Zs, then one or more Is, As, or Os (all the same letter), then one or more Ps, (all letters up to this point may be in mixed case) followed by some arbitrary suffix (which may be empty). You should leave the runs of Zs and Ps, as well as the suffix exactly as received, but then change the Is to As, As to Os, or Os to Is, preserving case at each step.



Example Test Cases



zip         ==> zap
zAp ==> zOp
ZOP ==> ZIP
ZiiP ==> ZaaP
ZZaapp ==> ZZoopp
zzzzOoOPppP ==> zzzzIiIPppP
Zipperoni ==> Zapperoni
ZAPsky ==> ZOPsky
ZoPtOn ==> ZiPtOn
zipzip ==> zapzip
zapzopzip ==> zopzopzip
zoopzaap ==> ziipzaap


Rules and Notes




  • You may use any convenient character encoding for input and output, provided that it supports all ASCII letters and that it was created prior to this challenge.

  • You may assume the input word is some variant of Zip, Zap, or Zop. All other inputs result in undefined behavior.


    • Valid inputs will full-match the regex Z+(I+|A+|O+)P+.* (in mixed case)




Happy Golfing!










share|improve this question











$endgroup$

















    10












    $begingroup$


    There's a little improv warm up game where you arrange yourselves in a circle and send zips, zaps, and zops around by pointing to a person and saying the next word in the sequence, then they do the same until all of you are warmed up or whatever.



    Your task is to create a program that gives the next word in sequence given an input word. (Zip --> Zap --> Zop --> Zip) Since there's a lot of different ways to say these three words and flairs that can be added to them, your program should imitate case and letter duplication and carry suffixes.



    To elaborate, your input will be one or more Zs, then one or more Is, As, or Os (all the same letter), then one or more Ps, (all letters up to this point may be in mixed case) followed by some arbitrary suffix (which may be empty). You should leave the runs of Zs and Ps, as well as the suffix exactly as received, but then change the Is to As, As to Os, or Os to Is, preserving case at each step.



    Example Test Cases



    zip         ==> zap
    zAp ==> zOp
    ZOP ==> ZIP
    ZiiP ==> ZaaP
    ZZaapp ==> ZZoopp
    zzzzOoOPppP ==> zzzzIiIPppP
    Zipperoni ==> Zapperoni
    ZAPsky ==> ZOPsky
    ZoPtOn ==> ZiPtOn
    zipzip ==> zapzip
    zapzopzip ==> zopzopzip
    zoopzaap ==> ziipzaap


    Rules and Notes




    • You may use any convenient character encoding for input and output, provided that it supports all ASCII letters and that it was created prior to this challenge.

    • You may assume the input word is some variant of Zip, Zap, or Zop. All other inputs result in undefined behavior.


      • Valid inputs will full-match the regex Z+(I+|A+|O+)P+.* (in mixed case)




    Happy Golfing!










    share|improve this question











    $endgroup$















      10












      10








      10





      $begingroup$


      There's a little improv warm up game where you arrange yourselves in a circle and send zips, zaps, and zops around by pointing to a person and saying the next word in the sequence, then they do the same until all of you are warmed up or whatever.



      Your task is to create a program that gives the next word in sequence given an input word. (Zip --> Zap --> Zop --> Zip) Since there's a lot of different ways to say these three words and flairs that can be added to them, your program should imitate case and letter duplication and carry suffixes.



      To elaborate, your input will be one or more Zs, then one or more Is, As, or Os (all the same letter), then one or more Ps, (all letters up to this point may be in mixed case) followed by some arbitrary suffix (which may be empty). You should leave the runs of Zs and Ps, as well as the suffix exactly as received, but then change the Is to As, As to Os, or Os to Is, preserving case at each step.



      Example Test Cases



      zip         ==> zap
      zAp ==> zOp
      ZOP ==> ZIP
      ZiiP ==> ZaaP
      ZZaapp ==> ZZoopp
      zzzzOoOPppP ==> zzzzIiIPppP
      Zipperoni ==> Zapperoni
      ZAPsky ==> ZOPsky
      ZoPtOn ==> ZiPtOn
      zipzip ==> zapzip
      zapzopzip ==> zopzopzip
      zoopzaap ==> ziipzaap


      Rules and Notes




      • You may use any convenient character encoding for input and output, provided that it supports all ASCII letters and that it was created prior to this challenge.

      • You may assume the input word is some variant of Zip, Zap, or Zop. All other inputs result in undefined behavior.


        • Valid inputs will full-match the regex Z+(I+|A+|O+)P+.* (in mixed case)




      Happy Golfing!










      share|improve this question











      $endgroup$




      There's a little improv warm up game where you arrange yourselves in a circle and send zips, zaps, and zops around by pointing to a person and saying the next word in the sequence, then they do the same until all of you are warmed up or whatever.



      Your task is to create a program that gives the next word in sequence given an input word. (Zip --> Zap --> Zop --> Zip) Since there's a lot of different ways to say these three words and flairs that can be added to them, your program should imitate case and letter duplication and carry suffixes.



      To elaborate, your input will be one or more Zs, then one or more Is, As, or Os (all the same letter), then one or more Ps, (all letters up to this point may be in mixed case) followed by some arbitrary suffix (which may be empty). You should leave the runs of Zs and Ps, as well as the suffix exactly as received, but then change the Is to As, As to Os, or Os to Is, preserving case at each step.



      Example Test Cases



      zip         ==> zap
      zAp ==> zOp
      ZOP ==> ZIP
      ZiiP ==> ZaaP
      ZZaapp ==> ZZoopp
      zzzzOoOPppP ==> zzzzIiIPppP
      Zipperoni ==> Zapperoni
      ZAPsky ==> ZOPsky
      ZoPtOn ==> ZiPtOn
      zipzip ==> zapzip
      zapzopzip ==> zopzopzip
      zoopzaap ==> ziipzaap


      Rules and Notes




      • You may use any convenient character encoding for input and output, provided that it supports all ASCII letters and that it was created prior to this challenge.

      • You may assume the input word is some variant of Zip, Zap, or Zop. All other inputs result in undefined behavior.


        • Valid inputs will full-match the regex Z+(I+|A+|O+)P+.* (in mixed case)




      Happy Golfing!







      code-golf string






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago







      Beefster

















      asked 3 hours ago









      BeefsterBeefster

      1,787732




      1,787732






















          6 Answers
          6






          active

          oldest

          votes


















          2












          $begingroup$


          Retina 0.8.2, 21 bytes



          iT`Io`AOIiaoi`^.+?p


          Try it online! Transliterates letters up to and including the first p, although the z and p aren't in the transliteration section so aren't affected. The first O is quoted because it normally expands to 13567 and the second o is quoted because it too is magic; in the first part of the transliteration it expands to the other string. The resulting transliteration is therefore from IAOIiaoi to AOIiaoi then removing the duplicate source letters results in IAOiao to AOIaoi.






          share|improve this answer









          $endgroup$





















            1












            $begingroup$


            Stax, 19 bytes



            Ç╛√êΣ%,╖FP╚`=Lh←⌡·ƒ


            Run and debug it






            share|improve this answer









            $endgroup$





















              1












              $begingroup$


              Perl 6, 41 bytes





              {S:i{z+<(.+?)>p}=$/.&{TR/iaoIAO/aoiAOI/}}


              Try it online!



              Simple case-insensitive substitution to shift the vowel section.






              share|improve this answer









              $endgroup$





















                1












                $begingroup$


                Japt, 22 20 bytes



                -2 bytes thanks to Oliver



                r"%v+"_d`i¬iao¯`pu}"


                Try it online!






                share|improve this answer











                $endgroup$





















                  1












                  $begingroup$


                  JavaScript (Node.js),  69  63 bytes





                  s=>Buffer(s).map(c=>s|c%4<1?s=c:c&1?c-[6,-14,,,8][c%16%5]:c)+''


                  Try it online!



                  How?



                  We process the input string $s$ character by character.



                  We reuse $s$ as a flag: as soon as a numeric value is stored in it, we know that we must not update anything else.



                  We use the following properties to identify the characters at the beginning of the string:




                  • The ASCII codes of p (112) and P (80) are multiples of $4$.

                  • The ASCII codes of z (122) and Z (90) are even, but not multiples of $4$.

                  • The ASCII codes of the vowels a (97), A (65), i (105), I (73), o (111) and O (79) are odd.


                  To turn a vowel with ASCII code $c$ into its counterpart, we use the following hash function:



                  $$n=(cbmod 16)bmod 5$$



                  and use $n$ to pick a value that must be subtracted from or added to $c$ from a lookup table.



                  Commented



                  s =>                  // s = input string
                  Buffer(s) // convert it to a Buffer of ASCII codes
                  .map(c => // for each ASCII code c in s:
                  s | // if s is numeric
                  c % 4 < 1 ? // or c is either 'p' or 'P':
                  s = c // turn s into a numeric value and yield c
                  : // else:
                  c & 1 ? // if c is a vowel:
                  c - // update c to either c - 6 ('o' -> 'i'), c + 14 ('a' -> 'o')
                  [6, -14,,, 8] // or c - 8 ('i' -> 'a')
                  [c % 16 % 5] // small hash function to convert from ASCII code to index
                  : // else (c is either 'z' or 'Z'):
                  c // let it unchanged
                  ) + '' // end of map(); coerce the Buffer back to a string





                  share|improve this answer











                  $endgroup$





















                    1












                    $begingroup$


                    C (gcc),  81 76  74 bytes



                    Similar to my JS answer, with another hash function. Outputs by modifying the input string.





                    x,c;f(char*s){for(x=1;c=*s;)*s++=c%4<x?x=c:c&1?c+"zx16"[c*3%11%3]&127:c;}


                    Try it online!



                    Commented



                    x,                          // x is used to test if we've reached a 'p' or a 'P'
                    c; // c is the current character
                    f(char * s) { // f = function taking the input string s
                    for(x = 1; c = *s;) // start with x = 1; for each character c in s:
                    *s++ = // update the current character and advance the pointer:
                    c % 4 < x ? // if c is 'p' or 'P' or x was raised beyond 3:
                    x = c // store c in x and let the character unchanged
                    : // else:
                    c & 1 ? // if c is a vowel:
                    c + // update it to the next vowel in the sequence
                    "zx16" // by adding either 122, 120 or 14
                    [c * 3 % 11 % 3] // according to the result of the hash function:
                    // 'a'/'A' -> 2, 'i'/'I' -> 1, 'o'/'O' -> 0
                    & 127 // and forcing it back into [0..127]
                    : // else (c is either 'z' or 'Z'):
                    c; // let it unchanged
                    } // implicit end of for(); end of function





                    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%2f180463%2fplay-zip-zap-zop%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown

























                      6 Answers
                      6






                      active

                      oldest

                      votes








                      6 Answers
                      6






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes









                      2












                      $begingroup$


                      Retina 0.8.2, 21 bytes



                      iT`Io`AOIiaoi`^.+?p


                      Try it online! Transliterates letters up to and including the first p, although the z and p aren't in the transliteration section so aren't affected. The first O is quoted because it normally expands to 13567 and the second o is quoted because it too is magic; in the first part of the transliteration it expands to the other string. The resulting transliteration is therefore from IAOIiaoi to AOIiaoi then removing the duplicate source letters results in IAOiao to AOIaoi.






                      share|improve this answer









                      $endgroup$


















                        2












                        $begingroup$


                        Retina 0.8.2, 21 bytes



                        iT`Io`AOIiaoi`^.+?p


                        Try it online! Transliterates letters up to and including the first p, although the z and p aren't in the transliteration section so aren't affected. The first O is quoted because it normally expands to 13567 and the second o is quoted because it too is magic; in the first part of the transliteration it expands to the other string. The resulting transliteration is therefore from IAOIiaoi to AOIiaoi then removing the duplicate source letters results in IAOiao to AOIaoi.






                        share|improve this answer









                        $endgroup$
















                          2












                          2








                          2





                          $begingroup$


                          Retina 0.8.2, 21 bytes



                          iT`Io`AOIiaoi`^.+?p


                          Try it online! Transliterates letters up to and including the first p, although the z and p aren't in the transliteration section so aren't affected. The first O is quoted because it normally expands to 13567 and the second o is quoted because it too is magic; in the first part of the transliteration it expands to the other string. The resulting transliteration is therefore from IAOIiaoi to AOIiaoi then removing the duplicate source letters results in IAOiao to AOIaoi.






                          share|improve this answer









                          $endgroup$




                          Retina 0.8.2, 21 bytes



                          iT`Io`AOIiaoi`^.+?p


                          Try it online! Transliterates letters up to and including the first p, although the z and p aren't in the transliteration section so aren't affected. The first O is quoted because it normally expands to 13567 and the second o is quoted because it too is magic; in the first part of the transliteration it expands to the other string. The resulting transliteration is therefore from IAOIiaoi to AOIiaoi then removing the duplicate source letters results in IAOiao to AOIaoi.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 33 mins ago









                          NeilNeil

                          81.1k744178




                          81.1k744178























                              1












                              $begingroup$


                              Stax, 19 bytes



                              Ç╛√êΣ%,╖FP╚`=Lh←⌡·ƒ


                              Run and debug it






                              share|improve this answer









                              $endgroup$


















                                1












                                $begingroup$


                                Stax, 19 bytes



                                Ç╛√êΣ%,╖FP╚`=Lh←⌡·ƒ


                                Run and debug it






                                share|improve this answer









                                $endgroup$
















                                  1












                                  1








                                  1





                                  $begingroup$


                                  Stax, 19 bytes



                                  Ç╛√êΣ%,╖FP╚`=Lh←⌡·ƒ


                                  Run and debug it






                                  share|improve this answer









                                  $endgroup$




                                  Stax, 19 bytes



                                  Ç╛√êΣ%,╖FP╚`=Lh←⌡·ƒ


                                  Run and debug it







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered 3 hours ago









                                  recursiverecursive

                                  5,3191322




                                  5,3191322























                                      1












                                      $begingroup$


                                      Perl 6, 41 bytes





                                      {S:i{z+<(.+?)>p}=$/.&{TR/iaoIAO/aoiAOI/}}


                                      Try it online!



                                      Simple case-insensitive substitution to shift the vowel section.






                                      share|improve this answer









                                      $endgroup$


















                                        1












                                        $begingroup$


                                        Perl 6, 41 bytes





                                        {S:i{z+<(.+?)>p}=$/.&{TR/iaoIAO/aoiAOI/}}


                                        Try it online!



                                        Simple case-insensitive substitution to shift the vowel section.






                                        share|improve this answer









                                        $endgroup$
















                                          1












                                          1








                                          1





                                          $begingroup$


                                          Perl 6, 41 bytes





                                          {S:i{z+<(.+?)>p}=$/.&{TR/iaoIAO/aoiAOI/}}


                                          Try it online!



                                          Simple case-insensitive substitution to shift the vowel section.






                                          share|improve this answer









                                          $endgroup$




                                          Perl 6, 41 bytes





                                          {S:i{z+<(.+?)>p}=$/.&{TR/iaoIAO/aoiAOI/}}


                                          Try it online!



                                          Simple case-insensitive substitution to shift the vowel section.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered 2 hours ago









                                          Jo KingJo King

                                          23.7k257123




                                          23.7k257123























                                              1












                                              $begingroup$


                                              Japt, 22 20 bytes



                                              -2 bytes thanks to Oliver



                                              r"%v+"_d`i¬iao¯`pu}"


                                              Try it online!






                                              share|improve this answer











                                              $endgroup$


















                                                1












                                                $begingroup$


                                                Japt, 22 20 bytes



                                                -2 bytes thanks to Oliver



                                                r"%v+"_d`i¬iao¯`pu}"


                                                Try it online!






                                                share|improve this answer











                                                $endgroup$
















                                                  1












                                                  1








                                                  1





                                                  $begingroup$


                                                  Japt, 22 20 bytes



                                                  -2 bytes thanks to Oliver



                                                  r"%v+"_d`i¬iao¯`pu}"


                                                  Try it online!






                                                  share|improve this answer











                                                  $endgroup$




                                                  Japt, 22 20 bytes



                                                  -2 bytes thanks to Oliver



                                                  r"%v+"_d`i¬iao¯`pu}"


                                                  Try it online!







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited 1 hour ago

























                                                  answered 2 hours ago









                                                  ASCII-onlyASCII-only

                                                  3,4501236




                                                  3,4501236























                                                      1












                                                      $begingroup$


                                                      JavaScript (Node.js),  69  63 bytes





                                                      s=>Buffer(s).map(c=>s|c%4<1?s=c:c&1?c-[6,-14,,,8][c%16%5]:c)+''


                                                      Try it online!



                                                      How?



                                                      We process the input string $s$ character by character.



                                                      We reuse $s$ as a flag: as soon as a numeric value is stored in it, we know that we must not update anything else.



                                                      We use the following properties to identify the characters at the beginning of the string:




                                                      • The ASCII codes of p (112) and P (80) are multiples of $4$.

                                                      • The ASCII codes of z (122) and Z (90) are even, but not multiples of $4$.

                                                      • The ASCII codes of the vowels a (97), A (65), i (105), I (73), o (111) and O (79) are odd.


                                                      To turn a vowel with ASCII code $c$ into its counterpart, we use the following hash function:



                                                      $$n=(cbmod 16)bmod 5$$



                                                      and use $n$ to pick a value that must be subtracted from or added to $c$ from a lookup table.



                                                      Commented



                                                      s =>                  // s = input string
                                                      Buffer(s) // convert it to a Buffer of ASCII codes
                                                      .map(c => // for each ASCII code c in s:
                                                      s | // if s is numeric
                                                      c % 4 < 1 ? // or c is either 'p' or 'P':
                                                      s = c // turn s into a numeric value and yield c
                                                      : // else:
                                                      c & 1 ? // if c is a vowel:
                                                      c - // update c to either c - 6 ('o' -> 'i'), c + 14 ('a' -> 'o')
                                                      [6, -14,,, 8] // or c - 8 ('i' -> 'a')
                                                      [c % 16 % 5] // small hash function to convert from ASCII code to index
                                                      : // else (c is either 'z' or 'Z'):
                                                      c // let it unchanged
                                                      ) + '' // end of map(); coerce the Buffer back to a string





                                                      share|improve this answer











                                                      $endgroup$


















                                                        1












                                                        $begingroup$


                                                        JavaScript (Node.js),  69  63 bytes





                                                        s=>Buffer(s).map(c=>s|c%4<1?s=c:c&1?c-[6,-14,,,8][c%16%5]:c)+''


                                                        Try it online!



                                                        How?



                                                        We process the input string $s$ character by character.



                                                        We reuse $s$ as a flag: as soon as a numeric value is stored in it, we know that we must not update anything else.



                                                        We use the following properties to identify the characters at the beginning of the string:




                                                        • The ASCII codes of p (112) and P (80) are multiples of $4$.

                                                        • The ASCII codes of z (122) and Z (90) are even, but not multiples of $4$.

                                                        • The ASCII codes of the vowels a (97), A (65), i (105), I (73), o (111) and O (79) are odd.


                                                        To turn a vowel with ASCII code $c$ into its counterpart, we use the following hash function:



                                                        $$n=(cbmod 16)bmod 5$$



                                                        and use $n$ to pick a value that must be subtracted from or added to $c$ from a lookup table.



                                                        Commented



                                                        s =>                  // s = input string
                                                        Buffer(s) // convert it to a Buffer of ASCII codes
                                                        .map(c => // for each ASCII code c in s:
                                                        s | // if s is numeric
                                                        c % 4 < 1 ? // or c is either 'p' or 'P':
                                                        s = c // turn s into a numeric value and yield c
                                                        : // else:
                                                        c & 1 ? // if c is a vowel:
                                                        c - // update c to either c - 6 ('o' -> 'i'), c + 14 ('a' -> 'o')
                                                        [6, -14,,, 8] // or c - 8 ('i' -> 'a')
                                                        [c % 16 % 5] // small hash function to convert from ASCII code to index
                                                        : // else (c is either 'z' or 'Z'):
                                                        c // let it unchanged
                                                        ) + '' // end of map(); coerce the Buffer back to a string





                                                        share|improve this answer











                                                        $endgroup$
















                                                          1












                                                          1








                                                          1





                                                          $begingroup$


                                                          JavaScript (Node.js),  69  63 bytes





                                                          s=>Buffer(s).map(c=>s|c%4<1?s=c:c&1?c-[6,-14,,,8][c%16%5]:c)+''


                                                          Try it online!



                                                          How?



                                                          We process the input string $s$ character by character.



                                                          We reuse $s$ as a flag: as soon as a numeric value is stored in it, we know that we must not update anything else.



                                                          We use the following properties to identify the characters at the beginning of the string:




                                                          • The ASCII codes of p (112) and P (80) are multiples of $4$.

                                                          • The ASCII codes of z (122) and Z (90) are even, but not multiples of $4$.

                                                          • The ASCII codes of the vowels a (97), A (65), i (105), I (73), o (111) and O (79) are odd.


                                                          To turn a vowel with ASCII code $c$ into its counterpart, we use the following hash function:



                                                          $$n=(cbmod 16)bmod 5$$



                                                          and use $n$ to pick a value that must be subtracted from or added to $c$ from a lookup table.



                                                          Commented



                                                          s =>                  // s = input string
                                                          Buffer(s) // convert it to a Buffer of ASCII codes
                                                          .map(c => // for each ASCII code c in s:
                                                          s | // if s is numeric
                                                          c % 4 < 1 ? // or c is either 'p' or 'P':
                                                          s = c // turn s into a numeric value and yield c
                                                          : // else:
                                                          c & 1 ? // if c is a vowel:
                                                          c - // update c to either c - 6 ('o' -> 'i'), c + 14 ('a' -> 'o')
                                                          [6, -14,,, 8] // or c - 8 ('i' -> 'a')
                                                          [c % 16 % 5] // small hash function to convert from ASCII code to index
                                                          : // else (c is either 'z' or 'Z'):
                                                          c // let it unchanged
                                                          ) + '' // end of map(); coerce the Buffer back to a string





                                                          share|improve this answer











                                                          $endgroup$




                                                          JavaScript (Node.js),  69  63 bytes





                                                          s=>Buffer(s).map(c=>s|c%4<1?s=c:c&1?c-[6,-14,,,8][c%16%5]:c)+''


                                                          Try it online!



                                                          How?



                                                          We process the input string $s$ character by character.



                                                          We reuse $s$ as a flag: as soon as a numeric value is stored in it, we know that we must not update anything else.



                                                          We use the following properties to identify the characters at the beginning of the string:




                                                          • The ASCII codes of p (112) and P (80) are multiples of $4$.

                                                          • The ASCII codes of z (122) and Z (90) are even, but not multiples of $4$.

                                                          • The ASCII codes of the vowels a (97), A (65), i (105), I (73), o (111) and O (79) are odd.


                                                          To turn a vowel with ASCII code $c$ into its counterpart, we use the following hash function:



                                                          $$n=(cbmod 16)bmod 5$$



                                                          and use $n$ to pick a value that must be subtracted from or added to $c$ from a lookup table.



                                                          Commented



                                                          s =>                  // s = input string
                                                          Buffer(s) // convert it to a Buffer of ASCII codes
                                                          .map(c => // for each ASCII code c in s:
                                                          s | // if s is numeric
                                                          c % 4 < 1 ? // or c is either 'p' or 'P':
                                                          s = c // turn s into a numeric value and yield c
                                                          : // else:
                                                          c & 1 ? // if c is a vowel:
                                                          c - // update c to either c - 6 ('o' -> 'i'), c + 14 ('a' -> 'o')
                                                          [6, -14,,, 8] // or c - 8 ('i' -> 'a')
                                                          [c % 16 % 5] // small hash function to convert from ASCII code to index
                                                          : // else (c is either 'z' or 'Z'):
                                                          c // let it unchanged
                                                          ) + '' // end of map(); coerce the Buffer back to a string






                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited 1 hour ago

























                                                          answered 2 hours ago









                                                          ArnauldArnauld

                                                          76.9k693322




                                                          76.9k693322























                                                              1












                                                              $begingroup$


                                                              C (gcc),  81 76  74 bytes



                                                              Similar to my JS answer, with another hash function. Outputs by modifying the input string.





                                                              x,c;f(char*s){for(x=1;c=*s;)*s++=c%4<x?x=c:c&1?c+"zx16"[c*3%11%3]&127:c;}


                                                              Try it online!



                                                              Commented



                                                              x,                          // x is used to test if we've reached a 'p' or a 'P'
                                                              c; // c is the current character
                                                              f(char * s) { // f = function taking the input string s
                                                              for(x = 1; c = *s;) // start with x = 1; for each character c in s:
                                                              *s++ = // update the current character and advance the pointer:
                                                              c % 4 < x ? // if c is 'p' or 'P' or x was raised beyond 3:
                                                              x = c // store c in x and let the character unchanged
                                                              : // else:
                                                              c & 1 ? // if c is a vowel:
                                                              c + // update it to the next vowel in the sequence
                                                              "zx16" // by adding either 122, 120 or 14
                                                              [c * 3 % 11 % 3] // according to the result of the hash function:
                                                              // 'a'/'A' -> 2, 'i'/'I' -> 1, 'o'/'O' -> 0
                                                              & 127 // and forcing it back into [0..127]
                                                              : // else (c is either 'z' or 'Z'):
                                                              c; // let it unchanged
                                                              } // implicit end of for(); end of function





                                                              share|improve this answer











                                                              $endgroup$


















                                                                1












                                                                $begingroup$


                                                                C (gcc),  81 76  74 bytes



                                                                Similar to my JS answer, with another hash function. Outputs by modifying the input string.





                                                                x,c;f(char*s){for(x=1;c=*s;)*s++=c%4<x?x=c:c&1?c+"zx16"[c*3%11%3]&127:c;}


                                                                Try it online!



                                                                Commented



                                                                x,                          // x is used to test if we've reached a 'p' or a 'P'
                                                                c; // c is the current character
                                                                f(char * s) { // f = function taking the input string s
                                                                for(x = 1; c = *s;) // start with x = 1; for each character c in s:
                                                                *s++ = // update the current character and advance the pointer:
                                                                c % 4 < x ? // if c is 'p' or 'P' or x was raised beyond 3:
                                                                x = c // store c in x and let the character unchanged
                                                                : // else:
                                                                c & 1 ? // if c is a vowel:
                                                                c + // update it to the next vowel in the sequence
                                                                "zx16" // by adding either 122, 120 or 14
                                                                [c * 3 % 11 % 3] // according to the result of the hash function:
                                                                // 'a'/'A' -> 2, 'i'/'I' -> 1, 'o'/'O' -> 0
                                                                & 127 // and forcing it back into [0..127]
                                                                : // else (c is either 'z' or 'Z'):
                                                                c; // let it unchanged
                                                                } // implicit end of for(); end of function





                                                                share|improve this answer











                                                                $endgroup$
















                                                                  1












                                                                  1








                                                                  1





                                                                  $begingroup$


                                                                  C (gcc),  81 76  74 bytes



                                                                  Similar to my JS answer, with another hash function. Outputs by modifying the input string.





                                                                  x,c;f(char*s){for(x=1;c=*s;)*s++=c%4<x?x=c:c&1?c+"zx16"[c*3%11%3]&127:c;}


                                                                  Try it online!



                                                                  Commented



                                                                  x,                          // x is used to test if we've reached a 'p' or a 'P'
                                                                  c; // c is the current character
                                                                  f(char * s) { // f = function taking the input string s
                                                                  for(x = 1; c = *s;) // start with x = 1; for each character c in s:
                                                                  *s++ = // update the current character and advance the pointer:
                                                                  c % 4 < x ? // if c is 'p' or 'P' or x was raised beyond 3:
                                                                  x = c // store c in x and let the character unchanged
                                                                  : // else:
                                                                  c & 1 ? // if c is a vowel:
                                                                  c + // update it to the next vowel in the sequence
                                                                  "zx16" // by adding either 122, 120 or 14
                                                                  [c * 3 % 11 % 3] // according to the result of the hash function:
                                                                  // 'a'/'A' -> 2, 'i'/'I' -> 1, 'o'/'O' -> 0
                                                                  & 127 // and forcing it back into [0..127]
                                                                  : // else (c is either 'z' or 'Z'):
                                                                  c; // let it unchanged
                                                                  } // implicit end of for(); end of function





                                                                  share|improve this answer











                                                                  $endgroup$




                                                                  C (gcc),  81 76  74 bytes



                                                                  Similar to my JS answer, with another hash function. Outputs by modifying the input string.





                                                                  x,c;f(char*s){for(x=1;c=*s;)*s++=c%4<x?x=c:c&1?c+"zx16"[c*3%11%3]&127:c;}


                                                                  Try it online!



                                                                  Commented



                                                                  x,                          // x is used to test if we've reached a 'p' or a 'P'
                                                                  c; // c is the current character
                                                                  f(char * s) { // f = function taking the input string s
                                                                  for(x = 1; c = *s;) // start with x = 1; for each character c in s:
                                                                  *s++ = // update the current character and advance the pointer:
                                                                  c % 4 < x ? // if c is 'p' or 'P' or x was raised beyond 3:
                                                                  x = c // store c in x and let the character unchanged
                                                                  : // else:
                                                                  c & 1 ? // if c is a vowel:
                                                                  c + // update it to the next vowel in the sequence
                                                                  "zx16" // by adding either 122, 120 or 14
                                                                  [c * 3 % 11 % 3] // according to the result of the hash function:
                                                                  // 'a'/'A' -> 2, 'i'/'I' -> 1, 'o'/'O' -> 0
                                                                  & 127 // and forcing it back into [0..127]
                                                                  : // else (c is either 'z' or 'Z'):
                                                                  c; // let it unchanged
                                                                  } // implicit end of for(); end of function






                                                                  share|improve this answer














                                                                  share|improve this answer



                                                                  share|improve this answer








                                                                  edited 17 mins ago

























                                                                  answered 1 hour ago









                                                                  ArnauldArnauld

                                                                  76.9k693322




                                                                  76.9k693322






























                                                                      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%2f180463%2fplay-zip-zap-zop%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

                                                                      數位音樂下載

                                                                      When can things happen in Etherscan, such as the picture below?

                                                                      格利澤436b