PronunciationSort™
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
We all know of different fancy sorting algorithms, but none of these give us numbers in a way that's easy to pronounce. To remedy this, I propose using PronunciationSort™, the most natural way to sort lists of numbers.
Pronunciation
The official rules for pronouncing numbers (in this challenge) is that the digits are pronounced one by one, and the resulting string is sorted in lexicographic order. As an example, this means that the number 845
is pronounced "eight four five"
, and should be sorted accordingly.
Negative numbers
Negative numbers are pronounced by prepending the word "minus"
. Thus, -23
is pronounced as "minus two three"
. Note that this causes negative numbers to end up in the middle of the output, right between numbers starting with 4
(four) and 9
(nine). It is permissible to interpret 0
as "minus zero"
if your language somehow could produce such a thing.
As a guide, the official order of words for PronunciationSort™ is:
- eight
- five
- four
- minus
- nine
- one
- seven
- six
- three
- two
- zero
Input
A list of integers in the range $[-999, 999]$, containing at most 100 elements.
Output
The same integers, in PronunciationSort™ order. Note that the numbers should only be converted to their pronunciations to get the sorting, the output should not contain any strings.
Examples
For the examples, the middle step (wrapped in parentheses) only serves as a guide, and is not a part of the output.
[1, 2, 3] -> (['one', 'two', 'three']) -> [1, 3, 2]
[-1, 0, 1, 2] -> (['minus one', 'zero', 'one', 'two']) -> [-1, 1, 2, 0]
[-100, 45, 96] -> (['minus one zero zero', 'four five', 'nine six']) -> [45, -100, 96]
[11, 12, 13, 134, 135] -> (['one one', 'one two', 'one three', 'one three four', 'one three five']) -> [11, 13, 135, 134, 12]
There's also a script for verifying your results.
code-golf string sorting natural-language
add a comment |Â
up vote
2
down vote
favorite
We all know of different fancy sorting algorithms, but none of these give us numbers in a way that's easy to pronounce. To remedy this, I propose using PronunciationSort™, the most natural way to sort lists of numbers.
Pronunciation
The official rules for pronouncing numbers (in this challenge) is that the digits are pronounced one by one, and the resulting string is sorted in lexicographic order. As an example, this means that the number 845
is pronounced "eight four five"
, and should be sorted accordingly.
Negative numbers
Negative numbers are pronounced by prepending the word "minus"
. Thus, -23
is pronounced as "minus two three"
. Note that this causes negative numbers to end up in the middle of the output, right between numbers starting with 4
(four) and 9
(nine). It is permissible to interpret 0
as "minus zero"
if your language somehow could produce such a thing.
As a guide, the official order of words for PronunciationSort™ is:
- eight
- five
- four
- minus
- nine
- one
- seven
- six
- three
- two
- zero
Input
A list of integers in the range $[-999, 999]$, containing at most 100 elements.
Output
The same integers, in PronunciationSort™ order. Note that the numbers should only be converted to their pronunciations to get the sorting, the output should not contain any strings.
Examples
For the examples, the middle step (wrapped in parentheses) only serves as a guide, and is not a part of the output.
[1, 2, 3] -> (['one', 'two', 'three']) -> [1, 3, 2]
[-1, 0, 1, 2] -> (['minus one', 'zero', 'one', 'two']) -> [-1, 1, 2, 0]
[-100, 45, 96] -> (['minus one zero zero', 'four five', 'nine six']) -> [45, -100, 96]
[11, 12, 13, 134, 135] -> (['one one', 'one two', 'one three', 'one three four', 'one three five']) -> [11, 13, 135, 134, 12]
There's also a script for verifying your results.
code-golf string sorting natural-language
Related
– Arnauld
20 mins ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
We all know of different fancy sorting algorithms, but none of these give us numbers in a way that's easy to pronounce. To remedy this, I propose using PronunciationSort™, the most natural way to sort lists of numbers.
Pronunciation
The official rules for pronouncing numbers (in this challenge) is that the digits are pronounced one by one, and the resulting string is sorted in lexicographic order. As an example, this means that the number 845
is pronounced "eight four five"
, and should be sorted accordingly.
Negative numbers
Negative numbers are pronounced by prepending the word "minus"
. Thus, -23
is pronounced as "minus two three"
. Note that this causes negative numbers to end up in the middle of the output, right between numbers starting with 4
(four) and 9
(nine). It is permissible to interpret 0
as "minus zero"
if your language somehow could produce such a thing.
As a guide, the official order of words for PronunciationSort™ is:
- eight
- five
- four
- minus
- nine
- one
- seven
- six
- three
- two
- zero
Input
A list of integers in the range $[-999, 999]$, containing at most 100 elements.
Output
The same integers, in PronunciationSort™ order. Note that the numbers should only be converted to their pronunciations to get the sorting, the output should not contain any strings.
Examples
For the examples, the middle step (wrapped in parentheses) only serves as a guide, and is not a part of the output.
[1, 2, 3] -> (['one', 'two', 'three']) -> [1, 3, 2]
[-1, 0, 1, 2] -> (['minus one', 'zero', 'one', 'two']) -> [-1, 1, 2, 0]
[-100, 45, 96] -> (['minus one zero zero', 'four five', 'nine six']) -> [45, -100, 96]
[11, 12, 13, 134, 135] -> (['one one', 'one two', 'one three', 'one three four', 'one three five']) -> [11, 13, 135, 134, 12]
There's also a script for verifying your results.
code-golf string sorting natural-language
We all know of different fancy sorting algorithms, but none of these give us numbers in a way that's easy to pronounce. To remedy this, I propose using PronunciationSort™, the most natural way to sort lists of numbers.
Pronunciation
The official rules for pronouncing numbers (in this challenge) is that the digits are pronounced one by one, and the resulting string is sorted in lexicographic order. As an example, this means that the number 845
is pronounced "eight four five"
, and should be sorted accordingly.
Negative numbers
Negative numbers are pronounced by prepending the word "minus"
. Thus, -23
is pronounced as "minus two three"
. Note that this causes negative numbers to end up in the middle of the output, right between numbers starting with 4
(four) and 9
(nine). It is permissible to interpret 0
as "minus zero"
if your language somehow could produce such a thing.
As a guide, the official order of words for PronunciationSort™ is:
- eight
- five
- four
- minus
- nine
- one
- seven
- six
- three
- two
- zero
Input
A list of integers in the range $[-999, 999]$, containing at most 100 elements.
Output
The same integers, in PronunciationSort™ order. Note that the numbers should only be converted to their pronunciations to get the sorting, the output should not contain any strings.
Examples
For the examples, the middle step (wrapped in parentheses) only serves as a guide, and is not a part of the output.
[1, 2, 3] -> (['one', 'two', 'three']) -> [1, 3, 2]
[-1, 0, 1, 2] -> (['minus one', 'zero', 'one', 'two']) -> [-1, 1, 2, 0]
[-100, 45, 96] -> (['minus one zero zero', 'four five', 'nine six']) -> [45, -100, 96]
[11, 12, 13, 134, 135] -> (['one one', 'one two', 'one three', 'one three four', 'one three five']) -> [11, 13, 135, 134, 12]
There's also a script for verifying your results.
code-golf string sorting natural-language
code-golf string sorting natural-language
asked 55 mins ago


maxb
1,3741519
1,3741519
Related
– Arnauld
20 mins ago
add a comment |Â
Related
– Arnauld
20 mins ago
Related
– Arnauld
20 mins ago
Related
– Arnauld
20 mins ago
add a comment |Â
7 Answers
7
active
oldest
votes
up vote
1
down vote
Retina 0.8.2, 36 bytes
T`-d`3:598217604
O`
T`3:598217604`-d
Try it online! Link includes test suite. Explanation:
T`-d`3:598217604
Translate the minus sign and digits to their position in pronunciation order, using :
for 10th position.
O`
Sort in pronunciation order.
T`3:598217604`-d
Translate the order back to the original minus sign and digits.
add a comment |Â
up vote
1
down vote
K (ngn/k), 21 20 bytes
x@<"54-9176320"?$x
Try it online!
function with argument
x
$
format as strings
"
..."?
find indices of individual characters in the given string (or $-2^63$ for "not found" - note that the "8"
is missing)
<
compute sort-ascending permutation
x@
the argument at those indices
add a comment |Â
up vote
0
down vote
JavaScript (SpiderMonkey), 87 73 bytes
a=>a.sort((p,q,F=b=>[...""+b].map(x=>"54-9176320".search(x)))=>F(p)>F(q))
Try it online!
Thanks @Arnauld for telling that the sort in SpiderMonkey is stable, so the ||-(F(q)>F(p))
part can finally be dropped.
add a comment |Â
up vote
0
down vote
JavaScript (SpiderMonkey), 69 bytes
a=>a.sort((a,b)=>(g=n=>[...n+''].map(c=>':598217604'[c]||3))(a)>g(b))
Try it online!
Won't work for[-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10]
, which is why my solution is 14 bytes longer.
– Shieru Asakoto
25 mins ago
@ShieruAsakoto This works with SpiderMonkey, which is using a stable sort.
– Arnauld
24 mins ago
Oh then mine can be 73 bytes too.
– Shieru Asakoto
24 mins ago
It looks like you can remove the+''
, seeing as you're taking input as an array of strings.
– Shaggy
21 mins ago
@Shaggy I'm not taking strings anymore, as I'm not sure if that's allowed here.
– Arnauld
20 mins ago
 |Â
show 1 more comment
up vote
0
down vote
Japt, 19 bytes
-2 bytes if we can take input as an array of strings.
ñ_s £"54-9176320"bX
Try it
add a comment |Â
up vote
0
down vote
Pyth, 17 bytes
oxL"854-9176320"`
Try it online here, or verify all the test cases at once here.
oxL"854-9176320"`NQ Implicit: Q=eval(input())
Trailing N, Q inferred
o Q Order the elements of Q, as N, using...
`N Convert N to string
xL Get the index of each character of that string...
"854-9176320" ... in the lookup ordering
add a comment |Â
up vote
0
down vote
05AB1E (legacy), 15 bytes
Σε•Koéa₃•'-3ÇÂsk
Try it online!
add a comment |Â
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Retina 0.8.2, 36 bytes
T`-d`3:598217604
O`
T`3:598217604`-d
Try it online! Link includes test suite. Explanation:
T`-d`3:598217604
Translate the minus sign and digits to their position in pronunciation order, using :
for 10th position.
O`
Sort in pronunciation order.
T`3:598217604`-d
Translate the order back to the original minus sign and digits.
add a comment |Â
up vote
1
down vote
Retina 0.8.2, 36 bytes
T`-d`3:598217604
O`
T`3:598217604`-d
Try it online! Link includes test suite. Explanation:
T`-d`3:598217604
Translate the minus sign and digits to their position in pronunciation order, using :
for 10th position.
O`
Sort in pronunciation order.
T`3:598217604`-d
Translate the order back to the original minus sign and digits.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Retina 0.8.2, 36 bytes
T`-d`3:598217604
O`
T`3:598217604`-d
Try it online! Link includes test suite. Explanation:
T`-d`3:598217604
Translate the minus sign and digits to their position in pronunciation order, using :
for 10th position.
O`
Sort in pronunciation order.
T`3:598217604`-d
Translate the order back to the original minus sign and digits.
Retina 0.8.2, 36 bytes
T`-d`3:598217604
O`
T`3:598217604`-d
Try it online! Link includes test suite. Explanation:
T`-d`3:598217604
Translate the minus sign and digits to their position in pronunciation order, using :
for 10th position.
O`
Sort in pronunciation order.
T`3:598217604`-d
Translate the order back to the original minus sign and digits.
answered 40 mins ago
Neil
75.7k744171
75.7k744171
add a comment |Â
add a comment |Â
up vote
1
down vote
K (ngn/k), 21 20 bytes
x@<"54-9176320"?$x
Try it online!
function with argument
x
$
format as strings
"
..."?
find indices of individual characters in the given string (or $-2^63$ for "not found" - note that the "8"
is missing)
<
compute sort-ascending permutation
x@
the argument at those indices
add a comment |Â
up vote
1
down vote
K (ngn/k), 21 20 bytes
x@<"54-9176320"?$x
Try it online!
function with argument
x
$
format as strings
"
..."?
find indices of individual characters in the given string (or $-2^63$ for "not found" - note that the "8"
is missing)
<
compute sort-ascending permutation
x@
the argument at those indices
add a comment |Â
up vote
1
down vote
up vote
1
down vote
K (ngn/k), 21 20 bytes
x@<"54-9176320"?$x
Try it online!
function with argument
x
$
format as strings
"
..."?
find indices of individual characters in the given string (or $-2^63$ for "not found" - note that the "8"
is missing)
<
compute sort-ascending permutation
x@
the argument at those indices
K (ngn/k), 21 20 bytes
x@<"54-9176320"?$x
Try it online!
function with argument
x
$
format as strings
"
..."?
find indices of individual characters in the given string (or $-2^63$ for "not found" - note that the "8"
is missing)
<
compute sort-ascending permutation
x@
the argument at those indices
edited 16 mins ago
answered 43 mins ago
ngn
6,23812357
6,23812357
add a comment |Â
add a comment |Â
up vote
0
down vote
JavaScript (SpiderMonkey), 87 73 bytes
a=>a.sort((p,q,F=b=>[...""+b].map(x=>"54-9176320".search(x)))=>F(p)>F(q))
Try it online!
Thanks @Arnauld for telling that the sort in SpiderMonkey is stable, so the ||-(F(q)>F(p))
part can finally be dropped.
add a comment |Â
up vote
0
down vote
JavaScript (SpiderMonkey), 87 73 bytes
a=>a.sort((p,q,F=b=>[...""+b].map(x=>"54-9176320".search(x)))=>F(p)>F(q))
Try it online!
Thanks @Arnauld for telling that the sort in SpiderMonkey is stable, so the ||-(F(q)>F(p))
part can finally be dropped.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
JavaScript (SpiderMonkey), 87 73 bytes
a=>a.sort((p,q,F=b=>[...""+b].map(x=>"54-9176320".search(x)))=>F(p)>F(q))
Try it online!
Thanks @Arnauld for telling that the sort in SpiderMonkey is stable, so the ||-(F(q)>F(p))
part can finally be dropped.
JavaScript (SpiderMonkey), 87 73 bytes
a=>a.sort((p,q,F=b=>[...""+b].map(x=>"54-9176320".search(x)))=>F(p)>F(q))
Try it online!
Thanks @Arnauld for telling that the sort in SpiderMonkey is stable, so the ||-(F(q)>F(p))
part can finally be dropped.
edited 23 mins ago
answered 29 mins ago
Shieru Asakoto
1,640311
1,640311
add a comment |Â
add a comment |Â
up vote
0
down vote
JavaScript (SpiderMonkey), 69 bytes
a=>a.sort((a,b)=>(g=n=>[...n+''].map(c=>':598217604'[c]||3))(a)>g(b))
Try it online!
Won't work for[-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10]
, which is why my solution is 14 bytes longer.
– Shieru Asakoto
25 mins ago
@ShieruAsakoto This works with SpiderMonkey, which is using a stable sort.
– Arnauld
24 mins ago
Oh then mine can be 73 bytes too.
– Shieru Asakoto
24 mins ago
It looks like you can remove the+''
, seeing as you're taking input as an array of strings.
– Shaggy
21 mins ago
@Shaggy I'm not taking strings anymore, as I'm not sure if that's allowed here.
– Arnauld
20 mins ago
 |Â
show 1 more comment
up vote
0
down vote
JavaScript (SpiderMonkey), 69 bytes
a=>a.sort((a,b)=>(g=n=>[...n+''].map(c=>':598217604'[c]||3))(a)>g(b))
Try it online!
Won't work for[-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10]
, which is why my solution is 14 bytes longer.
– Shieru Asakoto
25 mins ago
@ShieruAsakoto This works with SpiderMonkey, which is using a stable sort.
– Arnauld
24 mins ago
Oh then mine can be 73 bytes too.
– Shieru Asakoto
24 mins ago
It looks like you can remove the+''
, seeing as you're taking input as an array of strings.
– Shaggy
21 mins ago
@Shaggy I'm not taking strings anymore, as I'm not sure if that's allowed here.
– Arnauld
20 mins ago
 |Â
show 1 more comment
up vote
0
down vote
up vote
0
down vote
JavaScript (SpiderMonkey), 69 bytes
a=>a.sort((a,b)=>(g=n=>[...n+''].map(c=>':598217604'[c]||3))(a)>g(b))
Try it online!
JavaScript (SpiderMonkey), 69 bytes
a=>a.sort((a,b)=>(g=n=>[...n+''].map(c=>':598217604'[c]||3))(a)>g(b))
Try it online!
edited 22 mins ago
answered 29 mins ago


Arnauld
65.1k581275
65.1k581275
Won't work for[-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10]
, which is why my solution is 14 bytes longer.
– Shieru Asakoto
25 mins ago
@ShieruAsakoto This works with SpiderMonkey, which is using a stable sort.
– Arnauld
24 mins ago
Oh then mine can be 73 bytes too.
– Shieru Asakoto
24 mins ago
It looks like you can remove the+''
, seeing as you're taking input as an array of strings.
– Shaggy
21 mins ago
@Shaggy I'm not taking strings anymore, as I'm not sure if that's allowed here.
– Arnauld
20 mins ago
 |Â
show 1 more comment
Won't work for[-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10]
, which is why my solution is 14 bytes longer.
– Shieru Asakoto
25 mins ago
@ShieruAsakoto This works with SpiderMonkey, which is using a stable sort.
– Arnauld
24 mins ago
Oh then mine can be 73 bytes too.
– Shieru Asakoto
24 mins ago
It looks like you can remove the+''
, seeing as you're taking input as an array of strings.
– Shaggy
21 mins ago
@Shaggy I'm not taking strings anymore, as I'm not sure if that's allowed here.
– Arnauld
20 mins ago
Won't work for
[-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10]
, which is why my solution is 14 bytes longer.– Shieru Asakoto
25 mins ago
Won't work for
[-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10]
, which is why my solution is 14 bytes longer.– Shieru Asakoto
25 mins ago
@ShieruAsakoto This works with SpiderMonkey, which is using a stable sort.
– Arnauld
24 mins ago
@ShieruAsakoto This works with SpiderMonkey, which is using a stable sort.
– Arnauld
24 mins ago
Oh then mine can be 73 bytes too.
– Shieru Asakoto
24 mins ago
Oh then mine can be 73 bytes too.
– Shieru Asakoto
24 mins ago
It looks like you can remove the
+''
, seeing as you're taking input as an array of strings.– Shaggy
21 mins ago
It looks like you can remove the
+''
, seeing as you're taking input as an array of strings.– Shaggy
21 mins ago
@Shaggy I'm not taking strings anymore, as I'm not sure if that's allowed here.
– Arnauld
20 mins ago
@Shaggy I'm not taking strings anymore, as I'm not sure if that's allowed here.
– Arnauld
20 mins ago
 |Â
show 1 more comment
up vote
0
down vote
Japt, 19 bytes
-2 bytes if we can take input as an array of strings.
ñ_s £"54-9176320"bX
Try it
add a comment |Â
up vote
0
down vote
Japt, 19 bytes
-2 bytes if we can take input as an array of strings.
ñ_s £"54-9176320"bX
Try it
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Japt, 19 bytes
-2 bytes if we can take input as an array of strings.
ñ_s £"54-9176320"bX
Try it
Japt, 19 bytes
-2 bytes if we can take input as an array of strings.
ñ_s £"54-9176320"bX
Try it
answered 18 mins ago


Shaggy
16.8k21661
16.8k21661
add a comment |Â
add a comment |Â
up vote
0
down vote
Pyth, 17 bytes
oxL"854-9176320"`
Try it online here, or verify all the test cases at once here.
oxL"854-9176320"`NQ Implicit: Q=eval(input())
Trailing N, Q inferred
o Q Order the elements of Q, as N, using...
`N Convert N to string
xL Get the index of each character of that string...
"854-9176320" ... in the lookup ordering
add a comment |Â
up vote
0
down vote
Pyth, 17 bytes
oxL"854-9176320"`
Try it online here, or verify all the test cases at once here.
oxL"854-9176320"`NQ Implicit: Q=eval(input())
Trailing N, Q inferred
o Q Order the elements of Q, as N, using...
`N Convert N to string
xL Get the index of each character of that string...
"854-9176320" ... in the lookup ordering
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Pyth, 17 bytes
oxL"854-9176320"`
Try it online here, or verify all the test cases at once here.
oxL"854-9176320"`NQ Implicit: Q=eval(input())
Trailing N, Q inferred
o Q Order the elements of Q, as N, using...
`N Convert N to string
xL Get the index of each character of that string...
"854-9176320" ... in the lookup ordering
Pyth, 17 bytes
oxL"854-9176320"`
Try it online here, or verify all the test cases at once here.
oxL"854-9176320"`NQ Implicit: Q=eval(input())
Trailing N, Q inferred
o Q Order the elements of Q, as N, using...
`N Convert N to string
xL Get the index of each character of that string...
"854-9176320" ... in the lookup ordering
answered 11 mins ago


Sok
2,891722
2,891722
add a comment |Â
add a comment |Â
up vote
0
down vote
05AB1E (legacy), 15 bytes
Σε•Koéa₃•'-3ÇÂsk
Try it online!
add a comment |Â
up vote
0
down vote
05AB1E (legacy), 15 bytes
Σε•Koéa₃•'-3ÇÂsk
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
05AB1E (legacy), 15 bytes
Σε•Koéa₃•'-3ÇÂsk
Try it online!
05AB1E (legacy), 15 bytes
Σε•Koéa₃•'-3ÇÂsk
Try it online!
answered 56 secs ago


Emigna
43.3k431131
43.3k431131
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%2f172891%2fpronunciationsort%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
Related
– Arnauld
20 mins ago