19
2
Alphabetize Integers
For a given set of numbers, put them in alphabetical order when they are spelled out (i.e. 1: one, 2: two, 90: ninety, 19: nineteen). Your code should work for the range [-999999, 999999]
. Output must have a delimiter between numbers. A space will work, as will a space and a comma as shown in the examples below. Input can be an array of integers, a string of delimited numbers, or however you see fit. All integers are assumed to be unique.
Numbers are not hyphenated for the purposes of this challenge and spaces are alphabetized before any other characters. Negative numbers are assumed to be expressed by using the word minus
. For example, four
would precede four thousand
and the number -40
would be sorted using the string minus forty
. Assume all numbers will be solely comprised of number words and no conjunctions (e.g. use two thousand forty two
instead of two thousand and forty two
).
Test Cases
Single Digit Integers:
Input:
1, 2, 3, 4, 5
Output:
5, 4, 1, 3, 2
Multiple Digit Integers:
Input:
-1002, 5, 435012, 4, 23, 81, 82
Output:
81, 82, 5, 4, 435012, -1002, 23
Spaces between words, no hyphens, commas or "and":
Input:
6, 16, 60, 64, 600, 6000, 60000, 60004, 60008, 60204, 60804
Output:
6, 600, 6000, 16, 60, 64, 60000, 60008, 60804, 60004, 60204
Remember, this is code-golf, so the code with the fewest bytes wins. No loopholes allowed!
Here is the link to the relevant sandbox post.
– wubs – 2016-12-01T20:23:05.473Will the input ever contain more than one of a single integer? – ETHproductions – 2016-12-01T20:42:28.387
@ETHproductions No, it will not. I'll specify that in the question. – wubs – 2016-12-01T20:43:54.773
8Welcome to PPCG. Nice avatar. :D Nice first question. – AdmBorkBork – 2016-12-01T20:50:06.857
@TimmyD Thanks! I'm looking forward to PowerShell-ing everything I can around here. – wubs – 2016-12-01T21:05:50.700
Will the input ever contain a zero? – ETHproductions – 2016-12-02T02:36:31.577
@ETHproductions Yes. All numbers for the range [-999999,999999]. – wubs – 2016-12-02T14:40:14.293
I was reading the Wayside School series to my kids and A Wonderful Teacher (the second chapter 19 in Wayside School is Falling Down) inspired me to write a challenge to output the names of all the numbers zero to one million in alphabetical order. I'd say this already covers that challenge with only a few tweaks. I wonder if Miss Zarves would accept the output as an answer...
– Engineer Toast – 2017-05-30T15:02:42.470