Given a string, calculate the number of columns it corresponds to

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











up vote
1
down vote

favorite












In Excel, the columns range from A-Z, AA,AB,AZ,BA,..,BZ and so on. They actually each stand for numbers, but rather are encoded as alphabet strings.



In this challenge, you will be given a string of alphabets, and you must calculate the column it corresponds to.



Some tests:




'A' returns 1 (meaning that it is the first column)



'B' returns 2



'Z' returns 26



'AA' returns 27



'AB' returns 28



'AZ' returns 52



'ZZ' returns 702



'AAA' returns 703




You can assume that capital letters will be given only.



Shortest bytes win.



Good luck!










share|improve this question





















  • So... base 26 with the alphabet?
    – Jo King
    1 hour ago










  • It isn't quite base 26 because there's no zero.
    – J.Doe
    1 hour ago










  • @J.Doe Ah, I guess you're right. I didn't notice since my solution automatically treated Z as 10 anyway
    – Jo King
    32 mins ago










  • Reverse challenge.
    – user202729
    27 mins ago






  • 1




    @JoKing Bijective base.
    – user202729
    25 mins ago














up vote
1
down vote

favorite












In Excel, the columns range from A-Z, AA,AB,AZ,BA,..,BZ and so on. They actually each stand for numbers, but rather are encoded as alphabet strings.



In this challenge, you will be given a string of alphabets, and you must calculate the column it corresponds to.



Some tests:




'A' returns 1 (meaning that it is the first column)



'B' returns 2



'Z' returns 26



'AA' returns 27



'AB' returns 28



'AZ' returns 52



'ZZ' returns 702



'AAA' returns 703




You can assume that capital letters will be given only.



Shortest bytes win.



Good luck!










share|improve this question





















  • So... base 26 with the alphabet?
    – Jo King
    1 hour ago










  • It isn't quite base 26 because there's no zero.
    – J.Doe
    1 hour ago










  • @J.Doe Ah, I guess you're right. I didn't notice since my solution automatically treated Z as 10 anyway
    – Jo King
    32 mins ago










  • Reverse challenge.
    – user202729
    27 mins ago






  • 1




    @JoKing Bijective base.
    – user202729
    25 mins ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











In Excel, the columns range from A-Z, AA,AB,AZ,BA,..,BZ and so on. They actually each stand for numbers, but rather are encoded as alphabet strings.



In this challenge, you will be given a string of alphabets, and you must calculate the column it corresponds to.



Some tests:




'A' returns 1 (meaning that it is the first column)



'B' returns 2



'Z' returns 26



'AA' returns 27



'AB' returns 28



'AZ' returns 52



'ZZ' returns 702



'AAA' returns 703




You can assume that capital letters will be given only.



Shortest bytes win.



Good luck!










share|improve this question













In Excel, the columns range from A-Z, AA,AB,AZ,BA,..,BZ and so on. They actually each stand for numbers, but rather are encoded as alphabet strings.



In this challenge, you will be given a string of alphabets, and you must calculate the column it corresponds to.



Some tests:




'A' returns 1 (meaning that it is the first column)



'B' returns 2



'Z' returns 26



'AA' returns 27



'AB' returns 28



'AZ' returns 52



'ZZ' returns 702



'AAA' returns 703




You can assume that capital letters will be given only.



Shortest bytes win.



Good luck!







code-golf math






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









K Split X

376110




376110











  • So... base 26 with the alphabet?
    – Jo King
    1 hour ago










  • It isn't quite base 26 because there's no zero.
    – J.Doe
    1 hour ago










  • @J.Doe Ah, I guess you're right. I didn't notice since my solution automatically treated Z as 10 anyway
    – Jo King
    32 mins ago










  • Reverse challenge.
    – user202729
    27 mins ago






  • 1




    @JoKing Bijective base.
    – user202729
    25 mins ago
















  • So... base 26 with the alphabet?
    – Jo King
    1 hour ago










  • It isn't quite base 26 because there's no zero.
    – J.Doe
    1 hour ago










  • @J.Doe Ah, I guess you're right. I didn't notice since my solution automatically treated Z as 10 anyway
    – Jo King
    32 mins ago










  • Reverse challenge.
    – user202729
    27 mins ago






  • 1




    @JoKing Bijective base.
    – user202729
    25 mins ago















So... base 26 with the alphabet?
– Jo King
1 hour ago




So... base 26 with the alphabet?
– Jo King
1 hour ago












It isn't quite base 26 because there's no zero.
– J.Doe
1 hour ago




It isn't quite base 26 because there's no zero.
– J.Doe
1 hour ago












@J.Doe Ah, I guess you're right. I didn't notice since my solution automatically treated Z as 10 anyway
– Jo King
32 mins ago




@J.Doe Ah, I guess you're right. I didn't notice since my solution automatically treated Z as 10 anyway
– Jo King
32 mins ago












Reverse challenge.
– user202729
27 mins ago




Reverse challenge.
– user202729
27 mins ago




1




1




@JoKing Bijective base.
– user202729
25 mins ago




@JoKing Bijective base.
– user202729
25 mins ago










3 Answers
3






active

oldest

votes

















up vote
2
down vote














R, 48 bytes





function(s)(utf8ToInt(s)-64)%*%26^(nchar(s):1-1)


Try it online!






share|improve this answer





























    up vote
    2
    down vote














    Perl 6, 17 bytes





    :26[.ords X-64]


    Try it online!



    Anonymous code block that subtracts 64 from each byte value and converts from base 26 with Z overflowing to the next column.






    share|improve this answer





























      up vote
      1
      down vote














      Python 2, 52 45 bytes





      t=0
      for c in input():t=26*t+ord(c)%64
      print t


      Try it online!






      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: 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%2f174336%2fgiven-a-string-calculate-the-number-of-columns-it-corresponds-to%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        2
        down vote














        R, 48 bytes





        function(s)(utf8ToInt(s)-64)%*%26^(nchar(s):1-1)


        Try it online!






        share|improve this answer


























          up vote
          2
          down vote














          R, 48 bytes





          function(s)(utf8ToInt(s)-64)%*%26^(nchar(s):1-1)


          Try it online!






          share|improve this answer
























            up vote
            2
            down vote










            up vote
            2
            down vote










            R, 48 bytes





            function(s)(utf8ToInt(s)-64)%*%26^(nchar(s):1-1)


            Try it online!






            share|improve this answer















            R, 48 bytes





            function(s)(utf8ToInt(s)-64)%*%26^(nchar(s):1-1)


            Try it online!







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 1 hour ago

























            answered 1 hour ago









            J.Doe

            1,691112




            1,691112




















                up vote
                2
                down vote














                Perl 6, 17 bytes





                :26[.ords X-64]


                Try it online!



                Anonymous code block that subtracts 64 from each byte value and converts from base 26 with Z overflowing to the next column.






                share|improve this answer


























                  up vote
                  2
                  down vote














                  Perl 6, 17 bytes





                  :26[.ords X-64]


                  Try it online!



                  Anonymous code block that subtracts 64 from each byte value and converts from base 26 with Z overflowing to the next column.






                  share|improve this answer
























                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote










                    Perl 6, 17 bytes





                    :26[.ords X-64]


                    Try it online!



                    Anonymous code block that subtracts 64 from each byte value and converts from base 26 with Z overflowing to the next column.






                    share|improve this answer















                    Perl 6, 17 bytes





                    :26[.ords X-64]


                    Try it online!



                    Anonymous code block that subtracts 64 from each byte value and converts from base 26 with Z overflowing to the next column.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 36 mins ago

























                    answered 1 hour ago









                    Jo King

                    17.4k24197




                    17.4k24197




















                        up vote
                        1
                        down vote














                        Python 2, 52 45 bytes





                        t=0
                        for c in input():t=26*t+ord(c)%64
                        print t


                        Try it online!






                        share|improve this answer


























                          up vote
                          1
                          down vote














                          Python 2, 52 45 bytes





                          t=0
                          for c in input():t=26*t+ord(c)%64
                          print t


                          Try it online!






                          share|improve this answer
























                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote










                            Python 2, 52 45 bytes





                            t=0
                            for c in input():t=26*t+ord(c)%64
                            print t


                            Try it online!






                            share|improve this answer















                            Python 2, 52 45 bytes





                            t=0
                            for c in input():t=26*t+ord(c)%64
                            print t


                            Try it online!







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 19 mins ago

























                            answered 29 mins ago









                            Chas Brown

                            4,4561419




                            4,4561419



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174336%2fgiven-a-string-calculate-the-number-of-columns-it-corresponds-to%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