1-800-PPRAXIS
September 18, 2018
I guess this is probably the textbook solution:
(define (telemap c) (case (char-upcase c) ((#\A #\B #\C) #\2) ((#\D #\E #\F) #\3) ((#\G #\H #\I) #\4) ((#\J #\K #\L) #\5) ((#\M #\N #\O) #\6) ((#\P #\Q #\R #\S) #\7) ((#\T #\U #\V) #\8) ((#\W #\X #\Y #\Z) #\9) (else c)))
(define (telemapper str) (list->string (filter char-numeric? (map telemap (string->list str)))))
> (telemapper "1-800-PPRAXIS") "18007772947"
But here’s the solution I wrote while I was on hold:
$ echo "1-800-PPRAXIS" | tr a-z A-Z | tr A-Z 22233344455566677778889999 | tr -cd [0-9] 18007772947
You can run the program at https://ideone.com/IMU1lA.
Here’s a Haskell version. We keep any non-letters.
Python version. As with Globules, I kept any non-letters.
Outputs as follows:
Here’s a solution in C.
Example:
Here’s a code golf solution in Python.
Output:
Solution in ruby.
All three version output:
input: 1-800-PPRAXIS
output: 1-800-7772947
pass: ✅
input: +1-514-AUTOBUS
output: +1-514-2886287
pass: ✅
input: 13TAXI
output: 138294
pass: ✅
input: 1800-THRIFTY
output: 1800-8474389
pass: ✅
input: 1-US-RENT-A-WRECK
output: 1-87-7368-2-97325
pass: ✅
Tests from @Globules
A small improvement to Alex B’s solution is to make use of the Python dict’s ability to return a default when it can’t find a key: