Solution for T9 Spelling Problem in Caché ObjectScript
Last weekend we held the Final of InterSystems Contest on Caché, DeepSee and iKnow under the aegis of IT Planet Student Championship in Ekaterinburg. BTW, this year we had more than 1,400 participants in InterSystems Contest.
One of the tasks for the final was to solve T9 Spelling problem with Caché ObjectScript and use the minimum code.
The Latin alphabet contains 26 characters and telephones only have ten digits on the keypad. We would like to make it easier to write a message to your friend using a sequence of keypresses to indicate the desired characters. The letters are mapped onto the digits as shown below. To insert the character B for instance, the program would press 22. In order to insert two characters in sequence from the same key, the user must pause before pressing the key a second time. The space character ' ' should be printed to indicate a pause. For example, 2 2 indicates AA whereas 22 indicates B.
Make the method which inputs string and returns digits.
USER>write ##class(ITPlanet.Task1).ToPhone(“hi”) 44 444 USER>write ##class(ITPlanet.Task1).ToPhone(“yes”) 999337777 USER>write ##class(ITPlanet.Task1).ToPhone(“foo bar”) 333666 6660 022 2777 USER>write ##class(ITPlanet.Task1).ToPhone(“hello world”) 4433555 555666096667775553
The best result amongst the students was 192.
What's yours? ;)