15
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: "α"
Input: " 隣隣隣"
Output: "隣隣隣"
Input: " ️ "
Output: "️"
This is code golf, so the shortest answer wins! Good luck :)
Will there always be at least one space (at least 2 words)? – Emigna – 2018-10-05T16:13:57.003
If there's only one word just output the single word, since it's the max – GammaGames – 2018-10-05T16:41:55.740
2This would have been more interesting with ASCII instead of Unicode, because more languages could have participated. Requiring Unicode support doesn't seem to add anything to the challenge – Luis Mendo – 2018-10-05T17:05:54.550
1I mostly used Unicode because it has emojis lol – GammaGames – 2018-10-05T17:45:55.260
2Since many of the current answers seem to use the sum of UTF-8 or UTF-32 code units, you should add some additional test cases. For example "α ää" yields different results with UTF-8 (383 < 718) and UTF-16 (945 > 456). – nwellnhof – 2018-10-05T18:04:09.180
" 隣隣隣" could be used to weed out answers that simply add codepoints (UTF-32). Also, do you really mean to sum UTF-16 code units (16-bit numbers) or something else? – nwellnhof – 2018-10-05T18:10:21.853
I mean the number given by Javascript's
charCodeAt
function, which is a UTF-16 code according to the documentation. That's what I used when I was testing how feasible the challenge was. I'll add the other test cases though! – GammaGames – 2018-10-05T18:23:34.333When you say separated by whitespace... is input separated by newline allowed? – JayCe – 2018-10-05T18:37:07.817
1Yeah, newlines area allowed. Tabs too! – GammaGames – 2018-10-05T22:37:14.003
Can we take input as an array/list of words? – Shaggy – 2018-10-06T00:31:34.237
It cannot be an array, it has to be a string of words with any whitespace characters in between – GammaGames – 2018-10-06T03:01:12.343