Supreme Sum String
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
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
add a comment |Â
up vote
5
down vote
favorite
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
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
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
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
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
code-golf string unicode text-processing
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
add a comment |Â
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
add a comment |Â
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
Wow, I'm always amazed by the answers made in dedicated golfing languages!
â GammaGames
13 mins ago
add a comment |Â
up vote
2
down vote
PowerShell, 74 bytes
$a=-split$args;($a[$a.count..0]|sort([int]($_)[-1]
Try it online!
-split
s 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 t
oCharArray
, re-casting that as an [int]
array, -join
ing 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.
add a comment |Â
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!
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
add a comment |Â
up vote
1
down vote
Perl 6, 34 bytes
*.words.max(*.encode('utf16').sum)
Try it online!
add a comment |Â
up vote
1
down vote
Python 3, 55 bytes
lambda s:max(s.split(' '),key=lambda w:sum(map(ord,w)))
Try it online!
add a comment |Â
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!
2
Doesn't seem to work foras sa
as it returnssa
, ie. not the first word.
â nimi
35 mins ago
Indeed. Missed that case. â¹ Thanks, @nimi.
â manatwork
2 mins ago
add a comment |Â
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.
add a comment |Â
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
Wow, I'm always amazed by the answers made in dedicated golfing languages!
â GammaGames
13 mins ago
add a comment |Â
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
Wow, I'm always amazed by the answers made in dedicated golfing languages!
â GammaGames
13 mins ago
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
up vote
2
down vote
PowerShell, 74 bytes
$a=-split$args;($a[$a.count..0]|sort([int]($_)[-1]
Try it online!
-split
s 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 t
oCharArray
, re-casting that as an [int]
array, -join
ing 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.
add a comment |Â
up vote
2
down vote
PowerShell, 74 bytes
$a=-split$args;($a[$a.count..0]|sort([int]($_)[-1]
Try it online!
-split
s 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 t
oCharArray
, re-casting that as an [int]
array, -join
ing 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.
add a comment |Â
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!
-split
s 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 t
oCharArray
, re-casting that as an [int]
array, -join
ing 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.
PowerShell, 74 bytes
$a=-split$args;($a[$a.count..0]|sort([int]($_)[-1]
Try it online!
-split
s 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 t
oCharArray
, re-casting that as an [int]
array, -join
ing 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.
answered 17 mins ago
AdmBorkBork
24.8k360215
24.8k360215
add a comment |Â
add a comment |Â
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!
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
add a comment |Â
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!
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
add a comment |Â
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!
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!
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
add a comment |Â
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
add a comment |Â
up vote
1
down vote
Perl 6, 34 bytes
*.words.max(*.encode('utf16').sum)
Try it online!
add a comment |Â
up vote
1
down vote
Perl 6, 34 bytes
*.words.max(*.encode('utf16').sum)
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Perl 6, 34 bytes
*.words.max(*.encode('utf16').sum)
Try it online!
Perl 6, 34 bytes
*.words.max(*.encode('utf16').sum)
Try it online!
answered 35 mins ago
Sean
2,89636
2,89636
add a comment |Â
add a comment |Â
up vote
1
down vote
Python 3, 55 bytes
lambda s:max(s.split(' '),key=lambda w:sum(map(ord,w)))
Try it online!
add a comment |Â
up vote
1
down vote
Python 3, 55 bytes
lambda s:max(s.split(' '),key=lambda w:sum(map(ord,w)))
Try it online!
add a comment |Â
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!
Python 3, 55 bytes
lambda s:max(s.split(' '),key=lambda w:sum(map(ord,w)))
Try it online!
answered 24 mins ago
dylnan
3,9182529
3,9182529
add a comment |Â
add a comment |Â
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!
2
Doesn't seem to work foras sa
as it returnssa
, ie. not the first word.
â nimi
35 mins ago
Indeed. Missed that case. â¹ Thanks, @nimi.
â manatwork
2 mins ago
add a comment |Â
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!
2
Doesn't seem to work foras sa
as it returnssa
, ie. not the first word.
â nimi
35 mins ago
Indeed. Missed that case. â¹ Thanks, @nimi.
â manatwork
2 mins ago
add a comment |Â
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!
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!
edited 2 mins ago
answered 50 mins ago
manatwork
16k43472
16k43472
2
Doesn't seem to work foras sa
as it returnssa
, ie. not the first word.
â nimi
35 mins ago
Indeed. Missed that case. â¹ Thanks, @nimi.
â manatwork
2 mins ago
add a comment |Â
2
Doesn't seem to work foras sa
as it returnssa
, 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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited 35 secs ago
answered 11 mins ago
dylnan
3,9182529
3,9182529
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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