/* Letters in phone numbers (code golf) in Picat. http://codegolf.stackexchange.com/questions/21327/letters-in-phone-numbers """ Letters in phone numbers You are making a new phone where people can type in specialized phone numbers, for example, 1-800-program, and they would be converted automatically to a usable phone number, like 1-800-7764726 (for the previous example). Your program will recieve a string if any length with numbers, letters and dashes, and convert all the letters to their corresponding numbers. Here is a keypad, for reference: [ 1 -> 1 ABC -> 2 DEF -> 3 GHI -> 4 JKL -> 5 MNO -> 6 PQRS -> 7 TUV -> 8 WXYZ -> 9 * -> * 0 -> 0 # -> # ] Rules: Your program will receive a string It will process it and return/print another string Any language is accepted Since it is code-golf, the shortest code wins """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import cp. main => go. go ?=> println(phone=phone_number("1-800-program")), nl. go => true. phone_number(S) = T => % idea from one of the other: tr a-z 22233344455566677778889 % 10 20 30 40 50 60 70 % 12345678901234567890123456789012345678901234567890123456789012345678901234567890 M="22233344455566677778889",[cond(lowercase(C),M[ord(C)-96],C):C in S]=T.