Older cellphones have 3 or 4 characters mapped to each number from 2-9 and that number must be pressed a certain number of times to get the required character. Let's assume our cellphone has this map:
1:1
2:abcABC2
3:defDEF3
4:ghiGHI4
5:jklJKL5
6:mnoMNO6
7:pqrsPQRS7
8:tuvTUV8
9:wxyzWXYZ9
0:<space><newline>0
If you want to type b
, it will take 2 presses of the 2
key since b
is mapped to the second position on the 2
key.
To type exaMPle TExt 01
, you would press 33 99 2 6666 77777 555 33 0 8888 33333 99 8 0 <a 1-sec pause here in real life but we'll ignore it>000 1
Additionally, the *
key brings up the following page of special characters:
.,'?!
"-()@
/:_;+
&%*=<
>£€$¥
¤[]{}
\~^¡¿
§#|`
The first character .
is highlighted. You can navigate to each character in four directions. It takes one additional key press to insert. So to insert $
, you would press *↓↓↓↓→→→<select>
i.e. a total of 9 key-presses.
Your program must take input (STDIN or prompt) of contact names followed by a newline followed by whatever numbers a person types on that phone's keyboard.
Eg.
JOHN DOE
JANE DOE
BOBBY TABLES
36
Your program must output the list of contacts which match any
of the characters mapped to the keys the user presses.
In this example, since the user pressed 36
, the output list must consist of all contacts that match (completely or partially) the regex \b[d-fD-F3][m-oM-O6]
since:
3 6
| |
v v
[d-fD-F3][m-oM-O6]
In this case, the output would be:
JOHN DOE
JANE DOE
All contacts should be considered case insensitive. So 36
should match jOhN Doe
, JAne doE
, etc...
If no contacts match, you should output a blank line.
Details:
- Input "contacts" will be
^[a-zA-Z0-9 ]+$
. Numbers are allowed. - Input numbers will be
[0-9]+
(obviously) - Your source code may contain any characters from
[0-9a-zA-Z \n]
UNION<chars from special chars table>
Scoring
Your score will be the number of key-presses that it takes to type out your program on this particular phone. Lowest score wins.
You can use programs in this question for scoring.
Here's the original sandbox question - http://meta.codegolf.stackexchange.com/a/1790/8766
→
? \$\endgroup\$