Code Golf: Phone Number to Words

Posted by Nick Hodges on Stack Overflow See other posts from Stack Overflow or by Nick Hodges
Published on 2010-06-03T20:54:43Z Indexed on 2010/06/03 21:14 UTC
Read the original article Hit count: 280

Guidelines for code-golf on SO

We've all seen phone numbers that are put into words: 1-800-BUY-MORE, etc.

What is the shortest amount of code you can write that will produce all the possible combinations of words for a 7 digit US phone number.

Input will be a seven digit integer (or string, if that is simpler), and assume that the input is properly formed.

Output will be a list of seven character strings that

For instance, the number 428-5246 would produce

GATJAGM
GATJAGN
GATJAGO
GATJAHM
GATJAHN
GATJAHO

and so on.....

Winning criteria will be code from any language with the fewest characters that produce every possible letter combination.

Additional Notes:

  • To make it more interesting, words can be formed only by using the letters on a North American Classic Key Pad phone with three letters per number as defined here.That means that Z and Q are excluded.
  • For the number '1', put a space.
  • For the number '0', put a hyphen '-'

Bonus points awarded for recognizing output as real English words. Okay, not really. ;-)

© Stack Overflow or respective owner

Related posts about language-agnostic

Related posts about fun