Walk Across a Keyboard











up vote
6
down vote

favorite
1












Given a word (or any sequence of letters) as input, you must interpolate between each letter such that each adjacent pair of letters in the result is also adjacent on a QWERTY keyboard, as if you typed the input by walking on a giant keyboard. For example, 'yes' might become 'ytres', 'cat' might become 'cxzawert'.



Rules:





  • This is the keyboard format you should use:



    qwertyuiop

    asdfghjkl

      zxcvbnm



    Any pair of keys which is touching in this layout is considered adjacent. For instance, 's' and 'e' are ajacent, but 's' and 'r' are not.



  • The input "word" will consist of any sequence of letters. It will have only letters, so you don't have do deal with special characters.

  • The input can be in any convenient form: stdin, a string, a list, etc. Letter case does not matter; you can take whatever is more convenient.

  • The output can be in any convenient form: stdout, a string, a list, etc. Letter case does not matter, and it does not need to be consistent.

  • Any path across the keyboard is valid, except that you cannot cross the previous letter again before getting to the next letter. For example, 'hi' could become 'hji' or 'hjnbgyui', but not 'hbhui'.

  • A letter is not ajacent with itself, so 'poll' cannot become 'poll'. Instead it would need to become something like 'polkl'.

  • No output letters are allowed before or after the word. For example, 'was' cannot become 'trewas' or 'wasdfg'.


This is code golf, the shortest answer in bytes wins.










share|improve this question






















  • So we're outputting any valid 'walk' per input? This seems like it'd be better as given two inputs, determine if it's a valid walk.
    – Veskah
    5 hours ago










  • It seems like dewqwerty is a valid path for dy. Could you confirm that?
    – Arnauld
    5 hours ago










  • @Arnauld yes, it is.
    – Vaelus
    5 hours ago












  • @Veskah That's right; output any valid walk for an input. This is to allow for optimizations which might not be possible if, for instance, it had to be a shortest walk.
    – Vaelus
    5 hours ago















up vote
6
down vote

favorite
1












Given a word (or any sequence of letters) as input, you must interpolate between each letter such that each adjacent pair of letters in the result is also adjacent on a QWERTY keyboard, as if you typed the input by walking on a giant keyboard. For example, 'yes' might become 'ytres', 'cat' might become 'cxzawert'.



Rules:





  • This is the keyboard format you should use:



    qwertyuiop

    asdfghjkl

      zxcvbnm



    Any pair of keys which is touching in this layout is considered adjacent. For instance, 's' and 'e' are ajacent, but 's' and 'r' are not.



  • The input "word" will consist of any sequence of letters. It will have only letters, so you don't have do deal with special characters.

  • The input can be in any convenient form: stdin, a string, a list, etc. Letter case does not matter; you can take whatever is more convenient.

  • The output can be in any convenient form: stdout, a string, a list, etc. Letter case does not matter, and it does not need to be consistent.

  • Any path across the keyboard is valid, except that you cannot cross the previous letter again before getting to the next letter. For example, 'hi' could become 'hji' or 'hjnbgyui', but not 'hbhui'.

  • A letter is not ajacent with itself, so 'poll' cannot become 'poll'. Instead it would need to become something like 'polkl'.

  • No output letters are allowed before or after the word. For example, 'was' cannot become 'trewas' or 'wasdfg'.


This is code golf, the shortest answer in bytes wins.










share|improve this question






















  • So we're outputting any valid 'walk' per input? This seems like it'd be better as given two inputs, determine if it's a valid walk.
    – Veskah
    5 hours ago










  • It seems like dewqwerty is a valid path for dy. Could you confirm that?
    – Arnauld
    5 hours ago










  • @Arnauld yes, it is.
    – Vaelus
    5 hours ago












  • @Veskah That's right; output any valid walk for an input. This is to allow for optimizations which might not be possible if, for instance, it had to be a shortest walk.
    – Vaelus
    5 hours ago













up vote
6
down vote

favorite
1









up vote
6
down vote

favorite
1






1





Given a word (or any sequence of letters) as input, you must interpolate between each letter such that each adjacent pair of letters in the result is also adjacent on a QWERTY keyboard, as if you typed the input by walking on a giant keyboard. For example, 'yes' might become 'ytres', 'cat' might become 'cxzawert'.



Rules:





  • This is the keyboard format you should use:



    qwertyuiop

    asdfghjkl

      zxcvbnm



    Any pair of keys which is touching in this layout is considered adjacent. For instance, 's' and 'e' are ajacent, but 's' and 'r' are not.



  • The input "word" will consist of any sequence of letters. It will have only letters, so you don't have do deal with special characters.

  • The input can be in any convenient form: stdin, a string, a list, etc. Letter case does not matter; you can take whatever is more convenient.

  • The output can be in any convenient form: stdout, a string, a list, etc. Letter case does not matter, and it does not need to be consistent.

  • Any path across the keyboard is valid, except that you cannot cross the previous letter again before getting to the next letter. For example, 'hi' could become 'hji' or 'hjnbgyui', but not 'hbhui'.

  • A letter is not ajacent with itself, so 'poll' cannot become 'poll'. Instead it would need to become something like 'polkl'.

  • No output letters are allowed before or after the word. For example, 'was' cannot become 'trewas' or 'wasdfg'.


This is code golf, the shortest answer in bytes wins.










share|improve this question













Given a word (or any sequence of letters) as input, you must interpolate between each letter such that each adjacent pair of letters in the result is also adjacent on a QWERTY keyboard, as if you typed the input by walking on a giant keyboard. For example, 'yes' might become 'ytres', 'cat' might become 'cxzawert'.



Rules:





  • This is the keyboard format you should use:



    qwertyuiop

    asdfghjkl

      zxcvbnm



    Any pair of keys which is touching in this layout is considered adjacent. For instance, 's' and 'e' are ajacent, but 's' and 'r' are not.



  • The input "word" will consist of any sequence of letters. It will have only letters, so you don't have do deal with special characters.

  • The input can be in any convenient form: stdin, a string, a list, etc. Letter case does not matter; you can take whatever is more convenient.

  • The output can be in any convenient form: stdout, a string, a list, etc. Letter case does not matter, and it does not need to be consistent.

  • Any path across the keyboard is valid, except that you cannot cross the previous letter again before getting to the next letter. For example, 'hi' could become 'hji' or 'hjnbgyui', but not 'hbhui'.

  • A letter is not ajacent with itself, so 'poll' cannot become 'poll'. Instead it would need to become something like 'polkl'.

  • No output letters are allowed before or after the word. For example, 'was' cannot become 'trewas' or 'wasdfg'.


This is code golf, the shortest answer in bytes wins.







code-golf keyboard






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 5 hours ago









Vaelus

220110




220110












  • So we're outputting any valid 'walk' per input? This seems like it'd be better as given two inputs, determine if it's a valid walk.
    – Veskah
    5 hours ago










  • It seems like dewqwerty is a valid path for dy. Could you confirm that?
    – Arnauld
    5 hours ago










  • @Arnauld yes, it is.
    – Vaelus
    5 hours ago












  • @Veskah That's right; output any valid walk for an input. This is to allow for optimizations which might not be possible if, for instance, it had to be a shortest walk.
    – Vaelus
    5 hours ago


















  • So we're outputting any valid 'walk' per input? This seems like it'd be better as given two inputs, determine if it's a valid walk.
    – Veskah
    5 hours ago










  • It seems like dewqwerty is a valid path for dy. Could you confirm that?
    – Arnauld
    5 hours ago










  • @Arnauld yes, it is.
    – Vaelus
    5 hours ago












  • @Veskah That's right; output any valid walk for an input. This is to allow for optimizations which might not be possible if, for instance, it had to be a shortest walk.
    – Vaelus
    5 hours ago
















So we're outputting any valid 'walk' per input? This seems like it'd be better as given two inputs, determine if it's a valid walk.
– Veskah
5 hours ago




So we're outputting any valid 'walk' per input? This seems like it'd be better as given two inputs, determine if it's a valid walk.
– Veskah
5 hours ago












It seems like dewqwerty is a valid path for dy. Could you confirm that?
– Arnauld
5 hours ago




It seems like dewqwerty is a valid path for dy. Could you confirm that?
– Arnauld
5 hours ago












@Arnauld yes, it is.
– Vaelus
5 hours ago






@Arnauld yes, it is.
– Vaelus
5 hours ago














@Veskah That's right; output any valid walk for an input. This is to allow for optimizations which might not be possible if, for instance, it had to be a shortest walk.
– Vaelus
5 hours ago




@Veskah That's right; output any valid walk for an input. This is to allow for optimizations which might not be possible if, for instance, it had to be a shortest walk.
– Vaelus
5 hours ago










3 Answers
3






active

oldest

votes

















up vote
2
down vote














Python 2, 83 bytes





lambda s:re.findall('.*?'.join(s),'qwertyuioplkmnjhbvgfcxdsza'*len(s))[0]
import re


Try it online!



Walks the entire keyboard until the word is written.






share|improve this answer




























    up vote
    0
    down vote













    JavaScript (ES6), 70 bytes



    Same strategy as TFeld.





    s=>'qazsxdcfvgbhnjmklpoiuytrew'.repeat(s.length).match(s.join`.*?`)[0]


    Try it online!






    share|improve this answer




























      up vote
      0
      down vote














      Japt -g, 24 bytes



      ;D·ÎÔ+D·Årí)pUl)fU¬q".*?


      Try it online!



      Takes input in all caps. Very similar to the other answers otherwise.



      Explanation:



      ;                           :Set D to the keyboard layout
      D·Î :Get the first row of keys
      Ô :Reversed
      + :Concat
      D·Å :The other two rows
      rí) :Interleaved
      p :Repeat that string
      Ul) : A number of times equal to the length of the input
      f :Get the substrings that match
      U : The input
      ¬ : split into characters
      q".*? : and joined back with ".*?"
      :Implicitly output just once of the matches





      share|improve this answer





















        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: 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%2f177096%2fwalk-across-a-keyboard%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        2
        down vote














        Python 2, 83 bytes





        lambda s:re.findall('.*?'.join(s),'qwertyuioplkmnjhbvgfcxdsza'*len(s))[0]
        import re


        Try it online!



        Walks the entire keyboard until the word is written.






        share|improve this answer

























          up vote
          2
          down vote














          Python 2, 83 bytes





          lambda s:re.findall('.*?'.join(s),'qwertyuioplkmnjhbvgfcxdsza'*len(s))[0]
          import re


          Try it online!



          Walks the entire keyboard until the word is written.






          share|improve this answer























            up vote
            2
            down vote










            up vote
            2
            down vote










            Python 2, 83 bytes





            lambda s:re.findall('.*?'.join(s),'qwertyuioplkmnjhbvgfcxdsza'*len(s))[0]
            import re


            Try it online!



            Walks the entire keyboard until the word is written.






            share|improve this answer













            Python 2, 83 bytes





            lambda s:re.findall('.*?'.join(s),'qwertyuioplkmnjhbvgfcxdsza'*len(s))[0]
            import re


            Try it online!



            Walks the entire keyboard until the word is written.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 5 hours ago









            TFeld

            13.8k21239




            13.8k21239






















                up vote
                0
                down vote













                JavaScript (ES6), 70 bytes



                Same strategy as TFeld.





                s=>'qazsxdcfvgbhnjmklpoiuytrew'.repeat(s.length).match(s.join`.*?`)[0]


                Try it online!






                share|improve this answer

























                  up vote
                  0
                  down vote













                  JavaScript (ES6), 70 bytes



                  Same strategy as TFeld.





                  s=>'qazsxdcfvgbhnjmklpoiuytrew'.repeat(s.length).match(s.join`.*?`)[0]


                  Try it online!






                  share|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    JavaScript (ES6), 70 bytes



                    Same strategy as TFeld.





                    s=>'qazsxdcfvgbhnjmklpoiuytrew'.repeat(s.length).match(s.join`.*?`)[0]


                    Try it online!






                    share|improve this answer












                    JavaScript (ES6), 70 bytes



                    Same strategy as TFeld.





                    s=>'qazsxdcfvgbhnjmklpoiuytrew'.repeat(s.length).match(s.join`.*?`)[0]


                    Try it online!







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 3 hours ago









                    Arnauld

                    70.6k688298




                    70.6k688298






















                        up vote
                        0
                        down vote














                        Japt -g, 24 bytes



                        ;D·ÎÔ+D·Årí)pUl)fU¬q".*?


                        Try it online!



                        Takes input in all caps. Very similar to the other answers otherwise.



                        Explanation:



                        ;                           :Set D to the keyboard layout
                        D·Î :Get the first row of keys
                        Ô :Reversed
                        + :Concat
                        D·Å :The other two rows
                        rí) :Interleaved
                        p :Repeat that string
                        Ul) : A number of times equal to the length of the input
                        f :Get the substrings that match
                        U : The input
                        ¬ : split into characters
                        q".*? : and joined back with ".*?"
                        :Implicitly output just once of the matches





                        share|improve this answer

























                          up vote
                          0
                          down vote














                          Japt -g, 24 bytes



                          ;D·ÎÔ+D·Årí)pUl)fU¬q".*?


                          Try it online!



                          Takes input in all caps. Very similar to the other answers otherwise.



                          Explanation:



                          ;                           :Set D to the keyboard layout
                          D·Î :Get the first row of keys
                          Ô :Reversed
                          + :Concat
                          D·Å :The other two rows
                          rí) :Interleaved
                          p :Repeat that string
                          Ul) : A number of times equal to the length of the input
                          f :Get the substrings that match
                          U : The input
                          ¬ : split into characters
                          q".*? : and joined back with ".*?"
                          :Implicitly output just once of the matches





                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote










                            Japt -g, 24 bytes



                            ;D·ÎÔ+D·Årí)pUl)fU¬q".*?


                            Try it online!



                            Takes input in all caps. Very similar to the other answers otherwise.



                            Explanation:



                            ;                           :Set D to the keyboard layout
                            D·Î :Get the first row of keys
                            Ô :Reversed
                            + :Concat
                            D·Å :The other two rows
                            rí) :Interleaved
                            p :Repeat that string
                            Ul) : A number of times equal to the length of the input
                            f :Get the substrings that match
                            U : The input
                            ¬ : split into characters
                            q".*? : and joined back with ".*?"
                            :Implicitly output just once of the matches





                            share|improve this answer













                            Japt -g, 24 bytes



                            ;D·ÎÔ+D·Årí)pUl)fU¬q".*?


                            Try it online!



                            Takes input in all caps. Very similar to the other answers otherwise.



                            Explanation:



                            ;                           :Set D to the keyboard layout
                            D·Î :Get the first row of keys
                            Ô :Reversed
                            + :Concat
                            D·Å :The other two rows
                            rí) :Interleaved
                            p :Repeat that string
                            Ul) : A number of times equal to the length of the input
                            f :Get the substrings that match
                            U : The input
                            ¬ : split into characters
                            q".*? : and joined back with ".*?"
                            :Implicitly output just once of the matches






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 1 hour ago









                            Kamil Drakari

                            2,686416




                            2,686416






























                                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).






                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f177096%2fwalk-across-a-keyboard%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

                                How did Captain America manage to do this?

                                迪纳利

                                南乌拉尔铁路局