Given a non-negative integer (n
), create a function that returns n
in alphabetical order, according to the literal spelling of each digit in n
.
Examples:
Input: 101
>> one, zero, one
>> one, one, zero
Output: 110
Input: 31948
>> three, one, nine, four, eight
>> eight, four, nine, one, three
Output: 84913
Input: 5544
>> five, five, four, four
>> five, five, four, four
Output: 5544
Input: 1234567890
Output: 8549176320
Note: the operations in the example are illustrative only and do not need to be included in the output. Only the alphabetically-sorted number needs to be returned.
This is code-golf, so the shortest code in bytes wins.
Edit: the input can be taken in any desired format that best suits your language, and the output can be produced similarly by returning from the function or printing. The input will always be a natural number (including 0) and will not contain leading 0's.
Relevant OEIS entry (A057846) found by @DomHastings
00
.... \$\endgroup\$849
, does that mean we’re allowed to print the number849
but not the string"849"
? IMO this is just a cumbersome I/O format (bad!) on top of a perfectly fine challenge. \$\endgroup\$001
output? If they are significant and the result is not1
, most languages will require strings as input for the simple fact it is crude, impractical and usually nigh on impossible to ask the parser to preserve leading zeroes in base 10 literal numbers. \$\endgroup\$