Skip to main content
Commonmark migration
Source Link

Mathematica, 30 bytes

#Mathematica, 30 bytes TheThe answer below outputs a pure function which will take a list of integers as an input and sort them by their alphabetic name. Just what the doctor ordered ;)

SortBy[#~IntegerName~"Words"&] 

Here is the ungolfed version:

SortBy[IntegerName[#, "Words"]&] 

And here is an example usage:

SortBy[#~IntegerName~"Words"&][{0,1,2,3,4,5,6,7,8,9,10}] 

Which could also be written as

SortBy[#~IntegerName~"Words"&]@{0,1,2,3,4,5,6,7,8,9,10} 

They produce identical outputs - in mathematica, f[x] is equivilant to f@x.

Outputs: {8, 5, 4, 9, 1, 7, 6, 10, 3, 2} 

There is a much longer answer that another user posted in Mathematica. That answer tries to correct for some small differences between the way mathematica alphebatizes numbers to better conform to the way the OP stated numbers should be alphebatized, however the things they correct for don't affect sorting order, and my answer outputs identically to theirs:

MyF = SortBy[#~IntegerName~"Words"&]; TheirF = SortBy[#, #~IntegerName~"Words"~ StringReplace~{"," -> "", "-" -> ""} &] &; MyF[Range[-999999, 999999]] == TheirF[Range[-999999, 999999]] (*Outputs True*) 

#Mathematica, 30 bytes The answer below outputs a pure function which will take a list of integers as an input and sort them by their alphabetic name. Just what the doctor ordered ;)

SortBy[#~IntegerName~"Words"&] 

Here is the ungolfed version:

SortBy[IntegerName[#, "Words"]&] 

And here is an example usage:

SortBy[#~IntegerName~"Words"&][{0,1,2,3,4,5,6,7,8,9,10}] 

Which could also be written as

SortBy[#~IntegerName~"Words"&]@{0,1,2,3,4,5,6,7,8,9,10} 

They produce identical outputs - in mathematica, f[x] is equivilant to f@x.

Outputs: {8, 5, 4, 9, 1, 7, 6, 10, 3, 2} 

There is a much longer answer that another user posted in Mathematica. That answer tries to correct for some small differences between the way mathematica alphebatizes numbers to better conform to the way the OP stated numbers should be alphebatized, however the things they correct for don't affect sorting order, and my answer outputs identically to theirs:

MyF = SortBy[#~IntegerName~"Words"&]; TheirF = SortBy[#, #~IntegerName~"Words"~ StringReplace~{"," -> "", "-" -> ""} &] &; MyF[Range[-999999, 999999]] == TheirF[Range[-999999, 999999]] (*Outputs True*) 

Mathematica, 30 bytes

The answer below outputs a pure function which will take a list of integers as an input and sort them by their alphabetic name. Just what the doctor ordered ;)

SortBy[#~IntegerName~"Words"&] 

Here is the ungolfed version:

SortBy[IntegerName[#, "Words"]&] 

And here is an example usage:

SortBy[#~IntegerName~"Words"&][{0,1,2,3,4,5,6,7,8,9,10}] 

Which could also be written as

SortBy[#~IntegerName~"Words"&]@{0,1,2,3,4,5,6,7,8,9,10} 

They produce identical outputs - in mathematica, f[x] is equivilant to f@x.

Outputs: {8, 5, 4, 9, 1, 7, 6, 10, 3, 2} 

There is a much longer answer that another user posted in Mathematica. That answer tries to correct for some small differences between the way mathematica alphebatizes numbers to better conform to the way the OP stated numbers should be alphebatized, however the things they correct for don't affect sorting order, and my answer outputs identically to theirs:

MyF = SortBy[#~IntegerName~"Words"&]; TheirF = SortBy[#, #~IntegerName~"Words"~ StringReplace~{"," -> "", "-" -> ""} &] &; MyF[Range[-999999, 999999]] == TheirF[Range[-999999, 999999]] (*Outputs True*) 
Source Link
Alecto
  • 1.6k
  • 13
  • 24

#Mathematica, 30 bytes The answer below outputs a pure function which will take a list of integers as an input and sort them by their alphabetic name. Just what the doctor ordered ;)

SortBy[#~IntegerName~"Words"&] 

Here is the ungolfed version:

SortBy[IntegerName[#, "Words"]&] 

And here is an example usage:

SortBy[#~IntegerName~"Words"&][{0,1,2,3,4,5,6,7,8,9,10}] 

Which could also be written as

SortBy[#~IntegerName~"Words"&]@{0,1,2,3,4,5,6,7,8,9,10} 

They produce identical outputs - in mathematica, f[x] is equivilant to f@x.

Outputs: {8, 5, 4, 9, 1, 7, 6, 10, 3, 2} 

There is a much longer answer that another user posted in Mathematica. That answer tries to correct for some small differences between the way mathematica alphebatizes numbers to better conform to the way the OP stated numbers should be alphebatized, however the things they correct for don't affect sorting order, and my answer outputs identically to theirs:

MyF = SortBy[#~IntegerName~"Words"&]; TheirF = SortBy[#, #~IntegerName~"Words"~ StringReplace~{"," -> "", "-" -> ""} &] &; MyF[Range[-999999, 999999]] == TheirF[Range[-999999, 999999]] (*Outputs True*)