36
1
Guidelines
Scenario
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. "1123"
)
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 :(
Task
Given the encrypted string s, your task is to decrypt it and return the original number.
Rules
- 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 (
ONE
toNINE
)
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
Examples
"NEO" -> 1
"ENOWOT" -> 12
"EONOTWHTERE" -> 123
"SNVEEGHEITNEIN" -> 789
"ENOOWTEERHTRUOFEVIFXISNEVESTHGIEENIN" -> 123456789
"NOEWOTTOWHEERT" -> 1223
5In all the test cases, only the letters within a word are shuffled, not letters between words. Will that always be the case? – xnor – 2017-07-11T07:32:26.220
1@xnor That will always be the case. I have edited the question. – aimorris – 2017-07-11T07:39:10.517
1then you need to change this "....(ie. "ONETWOTHREE" -> "TTONWOHREEE")" – J42161217 – 2017-07-11T07:41:56.013
@Jenny_mathy I have edited the question. Thanks. – aimorris – 2017-07-11T07:43:11.597
@ComradeSparklePony I edited the question to make it easier. – aimorris – 2017-07-11T07:50:44.063
@ComradeSparklePony "The numbers will only be from 1 to 9 inclusive" – Mr. Xcoder – 2017-07-11T07:58:46.807
@Mr.Xcoder Oops, I was looking at a cached copy. It is all set now. :) – Comrade SparklePony – 2017-07-11T08:05:16.797
What does "non strict" mean in "his number is always a non strict increasing sequence"? – TessellatingHeckler – 2017-07-11T08:26:17.820
Can you add even more complicated test cases? – J42161217 – 2017-07-11T08:29:51.550
2@ TessellatingHeckler : A non-strictly increasing sequence is when the next number can be the same as the previous ex. 1-1-1-2-2-3 (non-strictly increasing) as opposed to 1-2-3-4-5 (strictly increasing) – koita_pisw_sou – 2017-07-11T08:37:47.313
1Technically speaking, this is an encoding, not encryption, since there is no key. – Patrick Roberts – 2017-07-11T09:10:29.610
@PatrickRoberts Thanks for that. :P – aimorris – 2017-07-11T09:14:55.560
You should include at least one example with digits appearing more than once. – Titus – 2017-07-11T14:56:22.160
@MagicOctopusUrn That number isn't a non-decreasing sequence. Therefore it is not a valid input – PunPun1000 – 2017-08-11T19:52:34.823
@PunPun1000 ahhh! Yes! Okay, I wondered why the spec was so loose; was just me being dumb. We do have ONE answer that actually works on it though. – Magic Octopus Urn – 2017-08-11T19:57:08.617
It would be interesting to have a version of this challenge where it is allowed to shuffle letters throughout the entire string. – Cristian Lupascu – 2017-08-18T06:20:21.167