John has an important number, and he doesn't want others to see it.
He decided to encrypt the number, using the following steps:
His number is always a non-decreasing sequence (ie.
He converted each digit into English words. (ie.
"123" -> "ONETWOTHREE")
And then, rearrange the letters randomly. (ie.
"ONETWOTHREE" -> "ENOWTOHEETR")
John felt that his number were safe in doing so. In fact, such encryption can be easily decrypted :(
Given the encrypted string s, your task is to decrypt it and return the original number.
- This is code golf, so the shortest answer in bytes wins
- You can assume that the input string is always valid
- The input string only contains uppercase letters
- The original numbers are always arranged in ascending order
- You may return the number in string or integer format
- The letters will only be shuffled between one word, not between the whole string.
- The numbers will only be from 1 to 9 inclusive (
Possible Unscrambled String
Here is a list of the strings just after they have been converted to strings from the numbers:
1 -> ONE 2 -> TWO 3 -> THREE 4 -> FOUR 5 -> FIVE 6 -> SIX 7 -> SEVEN 8 -> EIGHT 9 -> NINE
"NEO" -> 1
"ENOWOT" -> 12
"EONOTWHTERE" -> 123
"SNVEEGHEITNEIN" -> 789
"ENOOWTEERHTRUOFEVIFXISNEVESTHGIEENIN" -> 123456789
"NOEWOTTOWHEERT" -> 1223