So, you have a random list (random meaning it doesn't matter what order it is in) of numbers with a length of n, where n is a positive integer smaller than 1000 and larger than 1.

The random list must contain every number from 0 to (n - 1). Eg: [0, 3, 2, 5, 1, 4] (where n is 6).

Note: If there is more than one digit you do not translate like English - 11 is not "eleven", it is "one one".

Your task is to sort these numbers, but there are some difference to normal sorting:

  1. You have to sort them as if they were the numbers expressed as words, in alphabetical order, but you cannot replace the numbers with letters [1]

  2. At any given time, the list must contain exactly the same numbers in the exact quantities as the original list, you cannot add or remove any

Test Cases

n = 6
[0, 3, 2, 5, 1, 4] = [5, 4, 1, 3, 2, 0] (sorted like this but not this - ["five", "four", "one", "three", "two", "zero"])
n = 8
[0, 3, 7, 2, 5, 1, 6, 4] = [5, 4, 1, 7, 6, 3, 2, 0] (sorted like this but not this - ["five", "four", "one", "seven", "six", "three", "two", "zero"])

This is code-golf, so the smallest answer in bytes wins.

[1]: You may create another list to do the sorting, but the original list must have the same contents at all times


closed as unclear what you're asking by Shaggy, Emigna, Arnauld, Jonathan Allan, Erik the Outgolfer Mar 16 at 22:00

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    \$\begingroup\$ You need to define exactly how numbers translate to words. For example: is 101 one hundred and one, one hundred one, one zero one ... or ... what? \$\endgroup\$ – Shaggy Mar 16 at 21:48
  • \$\begingroup\$ Can we internally convert numbers to words, sort, then convert them back? \$\endgroup\$ – Benjamin Urquhart Mar 16 at 21:50
  • 4
    \$\begingroup\$ Both (1) and (2) are unobservable. \$\endgroup\$ – Jonathan Allan Mar 16 at 21:57
  • \$\begingroup\$ @BenjaminUrquhart, as Jonathan mentioned, that's an unobservable requirement. \$\endgroup\$ – Shaggy Mar 16 at 22:03
  • 1
    \$\begingroup\$ Also, I don't really see the point of the input apart from the length. It doesn't matter what permutation the input is, if it is always the range from 1 to n, since the output is going to be sorted anyway \$\endgroup\$ – Jo King Mar 17 at 12:04

Wolfram Language (Mathematica), 21 bytes


there is also a message that shouldn't be there

Try it online!

  • 1
    \$\begingroup\$ While I do not agree with the unobservable requirement it is nonetheless there... "you cannot replace the numbers with letters" - pretty sure that is what IntegerName will do. \$\endgroup\$ – Jonathan Allan Mar 16 at 21:59
  • 2
    \$\begingroup\$ I didn't replace them.. it was the internal criterion. I guess the OP should decide \$\endgroup\$ – shrap Mar 16 at 22:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.