This challenge is essentially identical to this one with just one difference: it is now allowed to shuffle letters anywhere in the string.
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" -> "EEWOOHRNTET")
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 letters can be shuffled anywhere in the 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
"NWEOOT" -> 12
"TOEERWNEHOT" -> 123
"IHNEVGENNEISTE" -> 789
"WEETVTRFSVUHNEEFRHIXEOINSNIEGTOONIEE" -> 123456789
"EWHEWROETOTTON" -> 1223
"ONEWESTV" -> 27 (thanks, ETHproductions!)