Supreme Sum String

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











up vote
5
down vote

favorite
1












Supreme Sum String



Given an input string, return the word with the highest sum of each of its unicode characters.



Rules



  • The input should be seperated by whitespace

  • The value of each word is based on the sum of each character in the word's UTF-16 code

  • The output should be the first word with the highest value (in case of duplicate sums)

Examples



Input: "a b c d e"
Output: "e"

Input: "hello world"
Output: "world"

Input: "this is a test"
Output: "test"

Input: "àà as a test"
Output: "àà"

Input: "💀 👻 🤡 🦇 🕷️ 🍬 🎃"
Output: "🕷️"


This is code golf, so the shortest answer wins! Good luck :)










share|improve this question





















  • Will there always be at least one space (at least 2 words)?
    – Emigna
    49 mins ago










  • If there's only one word just output the single word, since it's the max
    – GammaGames
    21 mins ago














up vote
5
down vote

favorite
1












Supreme Sum String



Given an input string, return the word with the highest sum of each of its unicode characters.



Rules



  • The input should be seperated by whitespace

  • The value of each word is based on the sum of each character in the word's UTF-16 code

  • The output should be the first word with the highest value (in case of duplicate sums)

Examples



Input: "a b c d e"
Output: "e"

Input: "hello world"
Output: "world"

Input: "this is a test"
Output: "test"

Input: "àà as a test"
Output: "àà"

Input: "💀 👻 🤡 🦇 🕷️ 🍬 🎃"
Output: "🕷️"


This is code golf, so the shortest answer wins! Good luck :)










share|improve this question





















  • Will there always be at least one space (at least 2 words)?
    – Emigna
    49 mins ago










  • If there's only one word just output the single word, since it's the max
    – GammaGames
    21 mins ago












up vote
5
down vote

favorite
1









up vote
5
down vote

favorite
1






1





Supreme Sum String



Given an input string, return the word with the highest sum of each of its unicode characters.



Rules



  • The input should be seperated by whitespace

  • The value of each word is based on the sum of each character in the word's UTF-16 code

  • The output should be the first word with the highest value (in case of duplicate sums)

Examples



Input: "a b c d e"
Output: "e"

Input: "hello world"
Output: "world"

Input: "this is a test"
Output: "test"

Input: "àà as a test"
Output: "àà"

Input: "💀 👻 🤡 🦇 🕷️ 🍬 🎃"
Output: "🕷️"


This is code golf, so the shortest answer wins! Good luck :)










share|improve this question













Supreme Sum String



Given an input string, return the word with the highest sum of each of its unicode characters.



Rules



  • The input should be seperated by whitespace

  • The value of each word is based on the sum of each character in the word's UTF-16 code

  • The output should be the first word with the highest value (in case of duplicate sums)

Examples



Input: "a b c d e"
Output: "e"

Input: "hello world"
Output: "world"

Input: "this is a test"
Output: "test"

Input: "àà as a test"
Output: "àà"

Input: "💀 👻 🤡 🦇 🕷️ 🍬 🎃"
Output: "🕷️"


This is code golf, so the shortest answer wins! Good luck :)







code-golf string unicode text-processing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









GammaGames

1355




1355











  • Will there always be at least one space (at least 2 words)?
    – Emigna
    49 mins ago










  • If there's only one word just output the single word, since it's the max
    – GammaGames
    21 mins ago
















  • Will there always be at least one space (at least 2 words)?
    – Emigna
    49 mins ago










  • If there's only one word just output the single word, since it's the max
    – GammaGames
    21 mins ago















Will there always be at least one space (at least 2 words)?
– Emigna
49 mins ago




Will there always be at least one space (at least 2 words)?
– Emigna
49 mins ago












If there's only one word just output the single word, since it's the max
– GammaGames
21 mins ago




If there's only one word just output the single word, since it's the max
– GammaGames
21 mins ago










7 Answers
7






active

oldest

votes

















up vote
2
down vote














05AB1E, 8 bytes



ð¡RΣÇO}θ


Try it online!



Explanation



ð¡ # split input on spaces
R # reverse the resulting list
Σ } # sort by
ÇO # sum of character codes
θ # take the last





share|improve this answer






















  • Wow, I'm always amazed by the answers made in dedicated golfing languages!
    – GammaGames
    13 mins ago

















up vote
2
down vote














PowerShell, 74 bytes





$a=-split$args;($a[$a.count..0]|sort([int]($_)[-1]


Try it online!



-splits the input $args on whitespace, stores the resulting array into $a. Then provides the reverse of $a (i.e., $a.count back down to 0). Pipes that into sort with a particular sorting mechanism ....



Here we're taking the current word $_, changing it toCharArray, re-casting that as an [int] array, -joining the resultant numbers with a + sign between, and piping that to iex (short for Invoke-Expression and similar to eval or the like). That turns the string into a number based on its UTF-16 representation.



For once, PowerShell having all strings be UTF-16 in the background is a life-saver!



We then encapsulate those results in (...) to transform them into an array and take the last [-1] one, i.e., the largest result that's the closest to the start of the sentence. That is left on the pipeline and output is implicit.






share|improve this answer



























    up vote
    1
    down vote













    JavaScript (ES6), 81 bytes





    s=>s.split` `.map(m=s=>m=[...s].map(c=>t+=c.charCodeAt(),t=0)&&t<=m?m:(r=s,t))&&r


    Try it online!






    share|improve this answer




















    • That's way better than the code I came up with when I was writing the challenge, mine was ~200 chars long!
      – GammaGames
      16 mins ago

















    up vote
    1
    down vote














    Perl 6, 34 bytes



    *.words.max(*.encode('utf16').sum)


    Try it online!






    share|improve this answer



























      up vote
      1
      down vote














      Python 3, 55 bytes





      lambda s:max(s.split(' '),key=lambda w:sum(map(ord,w)))


      Try it online!






      share|improve this answer



























        up vote
        0
        down vote













        jq, 61 43 57 characters



        (57 39 53 characters code + 4 characters command line options)



        ./" "|map([(.|explode|add),.])|reverse|max_by(0)|.[1]


        Sample run:



        bash-4.4$ jq -Rr './" "|map([(.|explode|add),.])|reverse|max_by(0)|.[1]' <<< 'àà as a test'
        àà


        Try it online!






        share|improve this answer


















        • 2




          Doesn't seem to work for as sa as it returns sa, ie. not the first word.
          – nimi
          35 mins ago










        • Indeed. Missed that case. ☹ Thanks, @nimi.
          – manatwork
          2 mins ago


















        up vote
        0
        down vote














        Jelly, 7 bytes



        ḲOS$ÐṀḢ


        Try it online!



        ḲOS$ÐṀḢ
        Ḳ Split input on spaces
        ÐṀ Give words that have maximum of:
        $ Monad:
        O ord(each character)
        S sum
        Ḣ First word that gives the max ord-sum.





        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%2f173422%2fsupreme-sum-string%23new-answer', 'question_page');

          );

          Post as a guest






























          7 Answers
          7






          active

          oldest

          votes








          7 Answers
          7






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote














          05AB1E, 8 bytes



          ð¡RΣÇO}θ


          Try it online!



          Explanation



          ð¡ # split input on spaces
          R # reverse the resulting list
          Σ } # sort by
          ÇO # sum of character codes
          θ # take the last





          share|improve this answer






















          • Wow, I'm always amazed by the answers made in dedicated golfing languages!
            – GammaGames
            13 mins ago














          up vote
          2
          down vote














          05AB1E, 8 bytes



          ð¡RΣÇO}θ


          Try it online!



          Explanation



          ð¡ # split input on spaces
          R # reverse the resulting list
          Σ } # sort by
          ÇO # sum of character codes
          θ # take the last





          share|improve this answer






















          • Wow, I'm always amazed by the answers made in dedicated golfing languages!
            – GammaGames
            13 mins ago












          up vote
          2
          down vote










          up vote
          2
          down vote










          05AB1E, 8 bytes



          ð¡RΣÇO}θ


          Try it online!



          Explanation



          ð¡ # split input on spaces
          R # reverse the resulting list
          Σ } # sort by
          ÇO # sum of character codes
          θ # take the last





          share|improve this answer















          05AB1E, 8 bytes



          ð¡RΣÇO}θ


          Try it online!



          Explanation



          ð¡ # split input on spaces
          R # reverse the resulting list
          Σ } # sort by
          ÇO # sum of character codes
          θ # take the last






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 41 mins ago

























          answered 49 mins ago









          Emigna

          43.6k431131




          43.6k431131











          • Wow, I'm always amazed by the answers made in dedicated golfing languages!
            – GammaGames
            13 mins ago
















          • Wow, I'm always amazed by the answers made in dedicated golfing languages!
            – GammaGames
            13 mins ago















          Wow, I'm always amazed by the answers made in dedicated golfing languages!
          – GammaGames
          13 mins ago




          Wow, I'm always amazed by the answers made in dedicated golfing languages!
          – GammaGames
          13 mins ago










          up vote
          2
          down vote














          PowerShell, 74 bytes





          $a=-split$args;($a[$a.count..0]|sort([int]($_)[-1]


          Try it online!



          -splits the input $args on whitespace, stores the resulting array into $a. Then provides the reverse of $a (i.e., $a.count back down to 0). Pipes that into sort with a particular sorting mechanism ....



          Here we're taking the current word $_, changing it toCharArray, re-casting that as an [int] array, -joining the resultant numbers with a + sign between, and piping that to iex (short for Invoke-Expression and similar to eval or the like). That turns the string into a number based on its UTF-16 representation.



          For once, PowerShell having all strings be UTF-16 in the background is a life-saver!



          We then encapsulate those results in (...) to transform them into an array and take the last [-1] one, i.e., the largest result that's the closest to the start of the sentence. That is left on the pipeline and output is implicit.






          share|improve this answer
























            up vote
            2
            down vote














            PowerShell, 74 bytes





            $a=-split$args;($a[$a.count..0]|sort([int]($_)[-1]


            Try it online!



            -splits the input $args on whitespace, stores the resulting array into $a. Then provides the reverse of $a (i.e., $a.count back down to 0). Pipes that into sort with a particular sorting mechanism ....



            Here we're taking the current word $_, changing it toCharArray, re-casting that as an [int] array, -joining the resultant numbers with a + sign between, and piping that to iex (short for Invoke-Expression and similar to eval or the like). That turns the string into a number based on its UTF-16 representation.



            For once, PowerShell having all strings be UTF-16 in the background is a life-saver!



            We then encapsulate those results in (...) to transform them into an array and take the last [-1] one, i.e., the largest result that's the closest to the start of the sentence. That is left on the pipeline and output is implicit.






            share|improve this answer






















              up vote
              2
              down vote










              up vote
              2
              down vote










              PowerShell, 74 bytes





              $a=-split$args;($a[$a.count..0]|sort([int]($_)[-1]


              Try it online!



              -splits the input $args on whitespace, stores the resulting array into $a. Then provides the reverse of $a (i.e., $a.count back down to 0). Pipes that into sort with a particular sorting mechanism ....



              Here we're taking the current word $_, changing it toCharArray, re-casting that as an [int] array, -joining the resultant numbers with a + sign between, and piping that to iex (short for Invoke-Expression and similar to eval or the like). That turns the string into a number based on its UTF-16 representation.



              For once, PowerShell having all strings be UTF-16 in the background is a life-saver!



              We then encapsulate those results in (...) to transform them into an array and take the last [-1] one, i.e., the largest result that's the closest to the start of the sentence. That is left on the pipeline and output is implicit.






              share|improve this answer













              PowerShell, 74 bytes





              $a=-split$args;($a[$a.count..0]|sort([int]($_)[-1]


              Try it online!



              -splits the input $args on whitespace, stores the resulting array into $a. Then provides the reverse of $a (i.e., $a.count back down to 0). Pipes that into sort with a particular sorting mechanism ....



              Here we're taking the current word $_, changing it toCharArray, re-casting that as an [int] array, -joining the resultant numbers with a + sign between, and piping that to iex (short for Invoke-Expression and similar to eval or the like). That turns the string into a number based on its UTF-16 representation.



              For once, PowerShell having all strings be UTF-16 in the background is a life-saver!



              We then encapsulate those results in (...) to transform them into an array and take the last [-1] one, i.e., the largest result that's the closest to the start of the sentence. That is left on the pipeline and output is implicit.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered 17 mins ago









              AdmBorkBork

              24.8k360215




              24.8k360215




















                  up vote
                  1
                  down vote













                  JavaScript (ES6), 81 bytes





                  s=>s.split` `.map(m=s=>m=[...s].map(c=>t+=c.charCodeAt(),t=0)&&t<=m?m:(r=s,t))&&r


                  Try it online!






                  share|improve this answer




















                  • That's way better than the code I came up with when I was writing the challenge, mine was ~200 chars long!
                    – GammaGames
                    16 mins ago














                  up vote
                  1
                  down vote













                  JavaScript (ES6), 81 bytes





                  s=>s.split` `.map(m=s=>m=[...s].map(c=>t+=c.charCodeAt(),t=0)&&t<=m?m:(r=s,t))&&r


                  Try it online!






                  share|improve this answer




















                  • That's way better than the code I came up with when I was writing the challenge, mine was ~200 chars long!
                    – GammaGames
                    16 mins ago












                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  JavaScript (ES6), 81 bytes





                  s=>s.split` `.map(m=s=>m=[...s].map(c=>t+=c.charCodeAt(),t=0)&&t<=m?m:(r=s,t))&&r


                  Try it online!






                  share|improve this answer












                  JavaScript (ES6), 81 bytes





                  s=>s.split` `.map(m=s=>m=[...s].map(c=>t+=c.charCodeAt(),t=0)&&t<=m?m:(r=s,t))&&r


                  Try it online!







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 59 mins ago









                  Arnauld

                  65.8k583278




                  65.8k583278











                  • That's way better than the code I came up with when I was writing the challenge, mine was ~200 chars long!
                    – GammaGames
                    16 mins ago
















                  • That's way better than the code I came up with when I was writing the challenge, mine was ~200 chars long!
                    – GammaGames
                    16 mins ago















                  That's way better than the code I came up with when I was writing the challenge, mine was ~200 chars long!
                  – GammaGames
                  16 mins ago




                  That's way better than the code I came up with when I was writing the challenge, mine was ~200 chars long!
                  – GammaGames
                  16 mins ago










                  up vote
                  1
                  down vote














                  Perl 6, 34 bytes



                  *.words.max(*.encode('utf16').sum)


                  Try it online!






                  share|improve this answer
























                    up vote
                    1
                    down vote














                    Perl 6, 34 bytes



                    *.words.max(*.encode('utf16').sum)


                    Try it online!






                    share|improve this answer






















                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote










                      Perl 6, 34 bytes



                      *.words.max(*.encode('utf16').sum)


                      Try it online!






                      share|improve this answer













                      Perl 6, 34 bytes



                      *.words.max(*.encode('utf16').sum)


                      Try it online!







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 35 mins ago









                      Sean

                      2,89636




                      2,89636




















                          up vote
                          1
                          down vote














                          Python 3, 55 bytes





                          lambda s:max(s.split(' '),key=lambda w:sum(map(ord,w)))


                          Try it online!






                          share|improve this answer
























                            up vote
                            1
                            down vote














                            Python 3, 55 bytes





                            lambda s:max(s.split(' '),key=lambda w:sum(map(ord,w)))


                            Try it online!






                            share|improve this answer






















                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote










                              Python 3, 55 bytes





                              lambda s:max(s.split(' '),key=lambda w:sum(map(ord,w)))


                              Try it online!






                              share|improve this answer













                              Python 3, 55 bytes





                              lambda s:max(s.split(' '),key=lambda w:sum(map(ord,w)))


                              Try it online!







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 24 mins ago









                              dylnan

                              3,9182529




                              3,9182529




















                                  up vote
                                  0
                                  down vote













                                  jq, 61 43 57 characters



                                  (57 39 53 characters code + 4 characters command line options)



                                  ./" "|map([(.|explode|add),.])|reverse|max_by(0)|.[1]


                                  Sample run:



                                  bash-4.4$ jq -Rr './" "|map([(.|explode|add),.])|reverse|max_by(0)|.[1]' <<< 'àà as a test'
                                  àà


                                  Try it online!






                                  share|improve this answer


















                                  • 2




                                    Doesn't seem to work for as sa as it returns sa, ie. not the first word.
                                    – nimi
                                    35 mins ago










                                  • Indeed. Missed that case. ☹ Thanks, @nimi.
                                    – manatwork
                                    2 mins ago















                                  up vote
                                  0
                                  down vote













                                  jq, 61 43 57 characters



                                  (57 39 53 characters code + 4 characters command line options)



                                  ./" "|map([(.|explode|add),.])|reverse|max_by(0)|.[1]


                                  Sample run:



                                  bash-4.4$ jq -Rr './" "|map([(.|explode|add),.])|reverse|max_by(0)|.[1]' <<< 'àà as a test'
                                  àà


                                  Try it online!






                                  share|improve this answer


















                                  • 2




                                    Doesn't seem to work for as sa as it returns sa, ie. not the first word.
                                    – nimi
                                    35 mins ago










                                  • Indeed. Missed that case. ☹ Thanks, @nimi.
                                    – manatwork
                                    2 mins ago













                                  up vote
                                  0
                                  down vote










                                  up vote
                                  0
                                  down vote









                                  jq, 61 43 57 characters



                                  (57 39 53 characters code + 4 characters command line options)



                                  ./" "|map([(.|explode|add),.])|reverse|max_by(0)|.[1]


                                  Sample run:



                                  bash-4.4$ jq -Rr './" "|map([(.|explode|add),.])|reverse|max_by(0)|.[1]' <<< 'àà as a test'
                                  àà


                                  Try it online!






                                  share|improve this answer














                                  jq, 61 43 57 characters



                                  (57 39 53 characters code + 4 characters command line options)



                                  ./" "|map([(.|explode|add),.])|reverse|max_by(0)|.[1]


                                  Sample run:



                                  bash-4.4$ jq -Rr './" "|map([(.|explode|add),.])|reverse|max_by(0)|.[1]' <<< 'àà as a test'
                                  àà


                                  Try it online!







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited 2 mins ago

























                                  answered 50 mins ago









                                  manatwork

                                  16k43472




                                  16k43472







                                  • 2




                                    Doesn't seem to work for as sa as it returns sa, ie. not the first word.
                                    – nimi
                                    35 mins ago










                                  • Indeed. Missed that case. ☹ Thanks, @nimi.
                                    – manatwork
                                    2 mins ago













                                  • 2




                                    Doesn't seem to work for as sa as it returns sa, ie. not the first word.
                                    – nimi
                                    35 mins ago










                                  • Indeed. Missed that case. ☹ Thanks, @nimi.
                                    – manatwork
                                    2 mins ago








                                  2




                                  2




                                  Doesn't seem to work for as sa as it returns sa, ie. not the first word.
                                  – nimi
                                  35 mins ago




                                  Doesn't seem to work for as sa as it returns sa, ie. not the first word.
                                  – nimi
                                  35 mins ago












                                  Indeed. Missed that case. ☹ Thanks, @nimi.
                                  – manatwork
                                  2 mins ago





                                  Indeed. Missed that case. ☹ Thanks, @nimi.
                                  – manatwork
                                  2 mins ago











                                  up vote
                                  0
                                  down vote














                                  Jelly, 7 bytes



                                  ḲOS$ÐṀḢ


                                  Try it online!



                                  ḲOS$ÐṀḢ
                                  Ḳ Split input on spaces
                                  ÐṀ Give words that have maximum of:
                                  $ Monad:
                                  O ord(each character)
                                  S sum
                                  Ḣ First word that gives the max ord-sum.





                                  share|improve this answer


























                                    up vote
                                    0
                                    down vote














                                    Jelly, 7 bytes



                                    ḲOS$ÐṀḢ


                                    Try it online!



                                    ḲOS$ÐṀḢ
                                    Ḳ Split input on spaces
                                    ÐṀ Give words that have maximum of:
                                    $ Monad:
                                    O ord(each character)
                                    S sum
                                    Ḣ First word that gives the max ord-sum.





                                    share|improve this answer
























                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote










                                      Jelly, 7 bytes



                                      ḲOS$ÐṀḢ


                                      Try it online!



                                      ḲOS$ÐṀḢ
                                      Ḳ Split input on spaces
                                      ÐṀ Give words that have maximum of:
                                      $ Monad:
                                      O ord(each character)
                                      S sum
                                      Ḣ First word that gives the max ord-sum.





                                      share|improve this answer















                                      Jelly, 7 bytes



                                      ḲOS$ÐṀḢ


                                      Try it online!



                                      ḲOS$ÐṀḢ
                                      Ḳ Split input on spaces
                                      ÐṀ Give words that have maximum of:
                                      $ Monad:
                                      O ord(each character)
                                      S sum
                                      Ḣ First word that gives the max ord-sum.






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited 35 secs ago

























                                      answered 11 mins ago









                                      dylnan

                                      3,9182529




                                      3,9182529



























                                           

                                          draft saved


                                          draft discarded















































                                           


                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173422%2fsupreme-sum-string%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