24
1
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
1Can I also take the number as a string and output a string? – ThreeFx – 2016-07-07T21:04:00.057
1@nimi
00
.... – TuxCrafting – 2016-07-07T21:07:19.090@atlasologist May we print the output? – xnor – 2016-07-07T21:10:39.620
@xnor returned from function or printed--either seems fine. – atlasologist – 2016-07-07T21:11:54.980
5You might want to specify that the input is in decimal, or you'll get some cheeky answers using unary... – Martin Ender – 2016-07-07T21:16:42.953
@nimi
00
doesn't need to be handled. – atlasologist – 2016-07-07T21:24:38.847Multi digit strings "one hundred two"? – zero298 – 2016-07-08T01:07:11.030
6
This is a bit confusing: you wrote in the comments that you expect a numeric type as input and output of the function, but also that it’s okay to print the result instead. So, if the output is
– Lynn – 2016-07-08T01:27:19.350849
, 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.1Leading zeroes significant or not? e.g. what does
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. – cat – 2016-07-08T02:56:02.007@Cat, input will be natural numbers with no leading 0's. – atlasologist – 2016-07-08T03:38:29.203
Of course there's an OEIS entry: Obsessive Filer's Sequence
– Dom Hastings – 2016-07-08T11:32:41.377@DomHastings wow, nice find! – atlasologist – 2016-07-08T12:03:03.070