An ogl-edocf challenge

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











up vote
7
down vote

favorite












Input



A non-empty shuffled string consisting of ASCII characters in the range $[32..126]$.



Output



The output is obtained by applying successive rotations to the input string.



For each letter ([a-zA-Z]) in the input string, going from left to right:



  • if the letter is in upper case, rotate all characters before it by one position to the left

  • if the letter is in lower case, rotate all characters before it by one position to the right

Example



Input: "Cb-Ad"



  • The first letter is a "C". We should do a rotation to the left, but there's no character before this "C". So, there's nothing to rotate.

  • The next letter is a "b". We rotate "C" to the right. Because it's a single character, it is left unchanged.

  • The character "-" does not trigger any rotation, as it's not a letter.

  • The next letter is a "A". We rotate "Cb-" to the left, which gives "b-CAd"

  • The fourth and last letter is a "d". We rotate "b-CA" to the right, which gives "Ab-Cd"

Therefore, the expected output is "Ab-Cd".



Rules



  • You may take input as a string or as an array of characters -- which may or may not be the same thing, depending on your language.

  • You may also output an array of characters instead of a string.

  • This is ogl-edocf code-golf

Test cases



"cbad" -> "abcd"
"ACBD" -> "ABCD"
"Cb-Ad" -> "Ab-Cd"
"caeBDF" -> "aBcDeF"
"aEcbDF" -> "abcDEF"
"ogl-edocf" -> "code-golf"
"W o,ollelrHd!" -> "Hello, World!"
"ti HIs SSta ET!" -> "tHis IS a tEST!"









share|improve this question

























    up vote
    7
    down vote

    favorite












    Input



    A non-empty shuffled string consisting of ASCII characters in the range $[32..126]$.



    Output



    The output is obtained by applying successive rotations to the input string.



    For each letter ([a-zA-Z]) in the input string, going from left to right:



    • if the letter is in upper case, rotate all characters before it by one position to the left

    • if the letter is in lower case, rotate all characters before it by one position to the right

    Example



    Input: "Cb-Ad"



    • The first letter is a "C". We should do a rotation to the left, but there's no character before this "C". So, there's nothing to rotate.

    • The next letter is a "b". We rotate "C" to the right. Because it's a single character, it is left unchanged.

    • The character "-" does not trigger any rotation, as it's not a letter.

    • The next letter is a "A". We rotate "Cb-" to the left, which gives "b-CAd"

    • The fourth and last letter is a "d". We rotate "b-CA" to the right, which gives "Ab-Cd"

    Therefore, the expected output is "Ab-Cd".



    Rules



    • You may take input as a string or as an array of characters -- which may or may not be the same thing, depending on your language.

    • You may also output an array of characters instead of a string.

    • This is ogl-edocf code-golf

    Test cases



    "cbad" -> "abcd"
    "ACBD" -> "ABCD"
    "Cb-Ad" -> "Ab-Cd"
    "caeBDF" -> "aBcDeF"
    "aEcbDF" -> "abcDEF"
    "ogl-edocf" -> "code-golf"
    "W o,ollelrHd!" -> "Hello, World!"
    "ti HIs SSta ET!" -> "tHis IS a tEST!"









    share|improve this question























      up vote
      7
      down vote

      favorite









      up vote
      7
      down vote

      favorite











      Input



      A non-empty shuffled string consisting of ASCII characters in the range $[32..126]$.



      Output



      The output is obtained by applying successive rotations to the input string.



      For each letter ([a-zA-Z]) in the input string, going from left to right:



      • if the letter is in upper case, rotate all characters before it by one position to the left

      • if the letter is in lower case, rotate all characters before it by one position to the right

      Example



      Input: "Cb-Ad"



      • The first letter is a "C". We should do a rotation to the left, but there's no character before this "C". So, there's nothing to rotate.

      • The next letter is a "b". We rotate "C" to the right. Because it's a single character, it is left unchanged.

      • The character "-" does not trigger any rotation, as it's not a letter.

      • The next letter is a "A". We rotate "Cb-" to the left, which gives "b-CAd"

      • The fourth and last letter is a "d". We rotate "b-CA" to the right, which gives "Ab-Cd"

      Therefore, the expected output is "Ab-Cd".



      Rules



      • You may take input as a string or as an array of characters -- which may or may not be the same thing, depending on your language.

      • You may also output an array of characters instead of a string.

      • This is ogl-edocf code-golf

      Test cases



      "cbad" -> "abcd"
      "ACBD" -> "ABCD"
      "Cb-Ad" -> "Ab-Cd"
      "caeBDF" -> "aBcDeF"
      "aEcbDF" -> "abcDEF"
      "ogl-edocf" -> "code-golf"
      "W o,ollelrHd!" -> "Hello, World!"
      "ti HIs SSta ET!" -> "tHis IS a tEST!"









      share|improve this question













      Input



      A non-empty shuffled string consisting of ASCII characters in the range $[32..126]$.



      Output



      The output is obtained by applying successive rotations to the input string.



      For each letter ([a-zA-Z]) in the input string, going from left to right:



      • if the letter is in upper case, rotate all characters before it by one position to the left

      • if the letter is in lower case, rotate all characters before it by one position to the right

      Example



      Input: "Cb-Ad"



      • The first letter is a "C". We should do a rotation to the left, but there's no character before this "C". So, there's nothing to rotate.

      • The next letter is a "b". We rotate "C" to the right. Because it's a single character, it is left unchanged.

      • The character "-" does not trigger any rotation, as it's not a letter.

      • The next letter is a "A". We rotate "Cb-" to the left, which gives "b-CAd"

      • The fourth and last letter is a "d". We rotate "b-CA" to the right, which gives "Ab-Cd"

      Therefore, the expected output is "Ab-Cd".



      Rules



      • You may take input as a string or as an array of characters -- which may or may not be the same thing, depending on your language.

      • You may also output an array of characters instead of a string.

      • This is ogl-edocf code-golf

      Test cases



      "cbad" -> "abcd"
      "ACBD" -> "ABCD"
      "Cb-Ad" -> "Ab-Cd"
      "caeBDF" -> "aBcDeF"
      "aEcbDF" -> "abcDEF"
      "ogl-edocf" -> "code-golf"
      "W o,ollelrHd!" -> "Hello, World!"
      "ti HIs SSta ET!" -> "tHis IS a tEST!"






      code-golf string






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Arnauld

      64.5k580271




      64.5k580271




















          6 Answers
          6






          active

          oldest

          votes

















          up vote
          1
          down vote














          Python 2, 100 98 95 bytes





          f=lambda s,p='':s and f(s[1:],[p[x:]+p[:x]+s[0]for x in[s[0].isupper()-s[0].islower()]][0])or p


          Try it online!






          share|improve this answer





























            up vote
            1
            down vote














            ><>, 45 bytes



            ii:2+7$.::&"`")$""(*?&:&:"@")$"["(*?&!
            ror


            Try it online!






            shareLNrBG1N)k


            Try it here



            Explanation



            VQ=k+.>k-F}LNrBG1N)k
            VQ ) For each N in the input...
            =k .>k ... rotate k (initially '')...
            -F}LNrBG1 ... by (N in lowercase alphabet) - (N in uppercase alphabet)...
            + N ... then append N to k.
            k Output the result.





            share|improve this answer





























              up vote
              0
              down vote














              Jelly, 19 bytes



              W€ḷṙ01ŒlƑ?-ŒuƑ?};ʋ/


              Try it online!






              share|improve this answer



























                up vote
                0
                down vote














                05AB1E, 18 bytes



                õIvy.liÁëy.uiÀ}}y«


                Try it online.



                Explanation:



                TODO: Will add an explanation and test suite if I'm unable to golf it further.





                share



























                  up vote
                  0
                  down vote














                  JavaScript (Node.js), 116 bytes





                  s=>Buffer(s).map((x,i)=>s=(t=s[S="slice"](i),i<2)?s:x>64&x<91?s[S](1,i)+s[0]+t:x>96&x<123?s[i-1]+s[S](0,i-1)+t:s)&&s


                  Try it online!





                  share




















                    Your Answer




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

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

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

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

                    else
                    createEditor();

                    );

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



                    );













                     

                    draft saved


                    draft discarded


















                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172455%2fan-ogl-edocf-challenge%23new-answer', 'question_page');

                    );

                    Post as a guest






























                    6 Answers
                    6






                    active

                    oldest

                    votes








                    6 Answers
                    6






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes








                    up vote
                    1
                    down vote














                    Python 2, 100 98 95 bytes





                    f=lambda s,p='':s and f(s[1:],[p[x:]+p[:x]+s[0]for x in[s[0].isupper()-s[0].islower()]][0])or p


                    Try it online!






                    share|improve this answer


























                      up vote
                      1
                      down vote














                      Python 2, 100 98 95 bytes





                      f=lambda s,p='':s and f(s[1:],[p[x:]+p[:x]+s[0]for x in[s[0].isupper()-s[0].islower()]][0])or p


                      Try it online!






                      share|improve this answer
























                        up vote
                        1
                        down vote










                        up vote
                        1
                        down vote










                        Python 2, 100 98 95 bytes





                        f=lambda s,p='':s and f(s[1:],[p[x:]+p[:x]+s[0]for x in[s[0].isupper()-s[0].islower()]][0])or p


                        Try it online!






                        share|improve this answer















                        Python 2, 100 98 95 bytes





                        f=lambda s,p='':s and f(s[1:],[p[x:]+p[:x]+s[0]for x in[s[0].isupper()-s[0].islower()]][0])or p


                        Try it online!







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited 49 mins ago

























                        answered 55 mins ago









                        TFeld

                        11.6k2833




                        11.6k2833




















                            up vote
                            1
                            down vote














                            ><>, 45 bytes



                            ii:2+7$.::&"`")$""(*?&:&:"@")$"["(*? 










                            up vote
                            1
                            down vote














                            ><>, 45 bytes



                            ii:2+7$.::&"`")$""(*?&:&:"@")$"["(*?improve this answer



















                              shareLNrBG1N)k


                              Try it here



                              Explanation



                              VQ=k+.>k-F}LNrBG1N)k
                              VQ ) For each N in the input...
                              =k .>k ... rotate k (initially '')...
                              -F}LNrBG1 ... by (N in lowercase alphabet) - (N in uppercase alphabet)...
                              + N ... then append N to k.
                              k Output the result.





                              share|improve this answer
























                                up vote
                                1
                                down vote










                                up vote
                                1
                                down vote









                                Pyth, 21 20 bytes



                                VQ=k+.>k-F}LNrBG1N)k


                                Try it here



                                Explanation



                                VQ=k+.>k-F}LNrBG1N)k
                                VQ ) For each N in the input...
                                =k .>k ... rotate k (initially '')...
                                -F}LNrBG1 ... by (N in lowercase alphabet) - (N in uppercase alphabet)...
                                + N ... then append N to k.
                                k Output the result.





                                share|improve this answer














                                Pyth, 21 20 bytes



                                VQ=k+.>k-F}LNrBG1N)k


                                Try it here



                                Explanation



                                VQ=k+.>k-F}LNrBG1N)k
                                VQ ) For each N in the input...
                                =k .>k ... rotate k (initially '')...
                                -F}LNrBG1 ... by (N in lowercase alphabet) - (N in uppercase alphabet)...
                                + N ... then append N to k.
                                k Output the result.






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited 8 mins ago

























                                answered 13 mins ago









                                Mnemonic

                                4,1671427




                                4,1671427




















                                    up vote
                                    0
                                    down vote














                                    Jelly, 19 bytes



                                    W€ḷṙ01ŒlƑ?-ŒuƑ?};ʋ/


                                    Try it online!






                                    share|improve this answer
























                                      up vote
                                      0
                                      down vote














                                      Jelly, 19 bytes



                                      W€ḷṙ01ŒlƑ?-ŒuƑ?};ʋ/


                                      Try it online!






                                      share|improve this answer






















                                        up vote
                                        0
                                        down vote










                                        up vote
                                        0
                                        down vote










                                        Jelly, 19 bytes



                                        W€ḷṙ01ŒlƑ?-ŒuƑ?};ʋ/


                                        Try it online!






                                        share|improve this answer













                                        Jelly, 19 bytes



                                        W€ḷṙ01ŒlƑ?-ŒuƑ?};ʋ/


                                        Try it online!







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered 23 mins ago









                                        Erik the Outgolfer

                                        29.5k42798




                                        29.5k42798




















                                            up vote
                                            0
                                            down vote














                                            05AB1E, 18 bytes



                                            õIvy.liÁëy.uiÀ}}y«


                                            Try it online.



                                            Explanation:



                                            TODO: Will add an explanation and test suite if I'm unable to golf it further.





                                            share
























                                              up vote
                                              0
                                              down vote














                                              05AB1E, 18 bytes



                                              õIvy.liÁëy.uiÀ}}y«


                                              Try it online.



                                              Explanation:



                                              TODO: Will add an explanation and test suite if I'm unable to golf it further.





                                              share






















                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote










                                                05AB1E, 18 bytes



                                                õIvy.liÁëy.uiÀ}}y«


                                                Try it online.



                                                Explanation:



                                                TODO: Will add an explanation and test suite if I'm unable to golf it further.





                                                share













                                                05AB1E, 18 bytes



                                                õIvy.liÁëy.uiÀ}}y«


                                                Try it online.



                                                Explanation:



                                                TODO: Will add an explanation and test suite if I'm unable to golf it further.






                                                share











                                                share


                                                share










                                                answered 7 mins ago









                                                Kevin Cruijssen

                                                30.2k553167




                                                30.2k553167




















                                                    up vote
                                                    0
                                                    down vote














                                                    JavaScript (Node.js), 116 bytes





                                                    s=>Buffer(s).map((x,i)=>s=(t=s[S="slice"](i),i<2)?s:x>64&x<91?s[S](1,i)+s[0]+t:x>96&x<123?s[i-1]+s[S](0,i-1)+t:s)&&s


                                                    Try it online!





                                                    share
























                                                      up vote
                                                      0
                                                      down vote














                                                      JavaScript (Node.js), 116 bytes





                                                      s=>Buffer(s).map((x,i)=>s=(t=s[S="slice"](i),i<2)?s:x>64&x<91?s[S](1,i)+s[0]+t:x>96&x<123?s[i-1]+s[S](0,i-1)+t:s)&&s


                                                      Try it online!





                                                      share






















                                                        up vote
                                                        0
                                                        down vote










                                                        up vote
                                                        0
                                                        down vote










                                                        JavaScript (Node.js), 116 bytes





                                                        s=>Buffer(s).map((x,i)=>s=(t=s[S="slice"](i),i<2)?s:x>64&x<91?s[S](1,i)+s[0]+t:x>96&x<123?s[i-1]+s[S](0,i-1)+t:s)&&s


                                                        Try it online!





                                                        share













                                                        JavaScript (Node.js), 116 bytes





                                                        s=>Buffer(s).map((x,i)=>s=(t=s[S="slice"](i),i<2)?s:x>64&x<91?s[S](1,i)+s[0]+t:x>96&x<123?s[i-1]+s[S](0,i-1)+t:s)&&s


                                                        Try it online!






                                                        share











                                                        share


                                                        share










                                                        answered 7 mins ago









                                                        Shieru Asakoto

                                                        1,505310




                                                        1,505310



























                                                             

                                                            draft saved


                                                            draft discarded















































                                                             


                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function ()
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172455%2fan-ogl-edocf-challenge%23new-answer', 'question_page');

                                                            );

                                                            Post as a guest













































































                                                            Comments

                                                            Popular posts from this blog

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

                                                            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                                                            Confectionery