12
1
This question asks for a T9 dictionary matching functionality which is a very interesting problem. But T9 has another way of typing and that is typing character-by-character. You would NOT need a dictionary to implement this keyboard.
Here is key-map of a T9 keyboard if you forgot:
+-------+-------+-------+
| 1 | 2 | 3 |
| .?! | ABC | DEF |
+-------+-------+-------+
| 4 | 5 | 6 |
| GHI | JKL | MNO |
+-------+-------+-------+
| 7 | 8 | 9 |
| PQRS | TUV | WXYZ |
+-------+-------+-------+
| * | 0 | # |
| ← | SPACE | → |
+-------+-------+-------+
How T9 works
To type a character with T9, you need to press number key representing that character n
times. n
is order of that character written on that key. Numbers are the last character you can type for each key. For example, to type B
I press 2
two times, or to type 5
I press 5
four times. To finish typing this character I press #
. *
is simply backspace. In our version of keyboard there is no capitalization.
Input and output examples:
8#99999#055#33#999#22#666#2#777#3# → T9 KEYBOARD
Explanation:
8
selectsT
and#
moves to next character99999
select last character of9
key which is9
and#
moves to next charachter0
inserts a space33
selects second character of3
key which isK
and#
moves to next character- And so on...
Rules
Your function or program should accept a string representing T9 keypresses. Output is the resulting text from those keypresses, as outlined above.
This is basic code golf, so the winner is shortest in bytes, and standard rules/loopholes apply.
Bonus does not have any effect on score ? Why would I go for it ? – Optimizer – 2014-12-17T23:13:25.430
2Also, your example
T9 KEYBOARD
is completely wrong. That one readsT9 JEYBARD
– Optimizer – 2014-12-17T23:24:24.8578#99999#055#33#999#22#666#2#777#3#1
– Optimizer – 2014-12-17T23:25:48.130@Optimizer for bonuses I don't know what should I do? Thanks for finding the issue. It's fixed. – Mohsen – 2014-12-17T23:28:34.330
1@Mohsen usually, bonuses in code golf will subtract a fixed amount from the score. you'll have to figure out how much is reasonable. for the first bonus probably not more than 10 or 20 bytes. the second bonus, I don't even understand. if I give the sequence of keypresses as a string to the function, how would there be any sort of time between keypresses? I think a more reasonable bonus would be to allow omitting
#
if consecutive buttons are different anyway. that being said: without that bonus what should happen if#
is omitted? – Martin Ender – 2014-12-17T23:46:07.1831You need to add a possible byte count benefit for these bonuses. Bonuses are optional but you seem to ask every answer to implement the bonuses as if they are compulsory. Please clear the tone, if they are mandatory, move them to rules, if they are not, do not ask every answer to implement the bonuses. I will wait for a couple of hours for your reply before voting to close as unclear. – Optimizer – 2014-12-18T12:57:16.770
2No reply even after 18 hours. Voting to close as unclear. – Optimizer – 2014-12-19T07:49:15.887
Does
000
give a solespace
or0
+space
? I.e. should it rotate or print when the max number of presses for a key is reached? – Titus – 2016-09-14T23:20:36.000The exact behaviour of backspace is undefined: Does it reset the current character or does it delete it and we´re back at the previous position to continue typing? Does
9911*9#
giveXW
orY
? – Titus – 2016-09-14T23:29:58.737Should
899999055339992266627773
also giveT9 KEYBOARD
? – Titus – 2016-09-14T23:49:02.473