-1
\$\begingroup\$

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

\$\endgroup\$
7
  • 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, 2019 at 21:48
  • \$\begingroup\$ Can we internally convert numbers to words, sort, then convert them back? \$\endgroup\$ Mar 16, 2019 at 21:50
  • 4
    \$\begingroup\$ Both (1) and (2) are unobservable. \$\endgroup\$ Mar 16, 2019 at 21:57
  • \$\begingroup\$ @BenjaminUrquhart, as Jonathan mentioned, that's an unobservable requirement. \$\endgroup\$
    – Shaggy
    Mar 16, 2019 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, 2019 at 12:04

1 Answer 1

2
\$\begingroup\$

Wolfram Language (Mathematica), 21 bytes

#~SortBy~IntegerName&

there is also a message that shouldn't be there

Try it online!

\$\endgroup\$
2
  • 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\$ Mar 16, 2019 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, 2019 at 22:04

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