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
GATJAGO
GATJAIM
GATJAIN
GATJAIO
and so on.....
Winning criterion will be code from any language with the fewest characters that produces 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. ;-)
Added: Okay, lets go with "Nick's Modified North American Classic Key Pad" which has an 'O' (oh, not zero) on the 6 key.
q, 52 39 chars
(cross/)(3 cut"--- ",.Q.A except"QZ")
q is evaluated left of right.
.Q.A contains the vector "ABC...XYZ"
except returns x excluding values in y
join "--- " to the modified char vector
cut into chunks of 3
cross returns all possible combinations, and is applied across all chunks
q)(cross/)(3 cut"--- ",.Q.A except"QZ")[4 2 8 5 2 4 6]
"GATJAGM"
"GATJAGN"
"GATJAGO"
"GATJAHM"
"GATJAHN"
"GATJAHO"
"GATJAIM"
"GATJAIN"
"GATJAIO"
....
Python, 107 chars
f=lambda p:p and[i+j for i in'O 1 ABC DEF GHI JKL MN PRS TUV WXY'.split()
[int(p[0])]for j in f(p[1:])]or[p]
Python, 122 chars (older version with reduce)
f=lambda p:reduce(lambda x,y:[i+j for i in x for j in y],
['O 1 ABC DEF GHI JKL MN PRS TUV WXY'.split()[int(k)]for k in p])
ps. Gimme some "thumbs up", new here and i need the votes
Example use:
>>> len(f('4285246'))
1458
>>> f('4285246')
['GATJAGM', 'GATJAGN', 'GATJAHM', 'GATJAHN', 'GATJAIM', 'GATJAIN', 'GATJBGM', 'GATJBGN', 'GATJBHM', 'GATJBHN', 'GATJBIM', 'GATJBIN', 'GATJCGM', 'GATJCGN', 'GATJCHM', 'GATJCHN', 'GATJCIM', 'GATJCIN', 'GATKAGM', 'GATKAGN', 'GATKAHM', 'GATKAHN', 'GATKAIM', 'GATKAIN', 'GATKBGM', 'GATKBGN', 'GATKBHM', 'GATKBHN', 'GATKBIM', 'GATKBIN', 'GATKCGM', 'GATKCGN', 'GATKCHM', 'GATKCHN', 'GATKCIM', 'GATKCIN', 'GATLAGM', 'GATLAGN', 'GATLAHM', 'GATLAHN', 'GATLAIM', 'GATLAIN', 'GATLBGM', 'GATLBGN', 'GATLBHM', 'GATLBHN', 'GATLBIM', 'GATLBIN', 'GATLCGM', 'GATLCGN', 'GATLCHM', 'GATLCHN', 'GATLCIM', 'GATLCIN', 'GAUJAGM', 'GAUJAGN', 'GAUJAHM', 'GAUJAHN', 'GAUJAIM', 'GAUJAIN', 'GAUJBGM', 'GAUJBGN', 'GAUJBHM', 'GAUJBHN', 'GAUJBIM', 'GAUJBIN', 'GAUJCGM', 'GAUJCGN', 'GAUJCHM', 'GAUJCHN', 'GAUJCIM', 'GAUJCIN', 'GAUKAGM', 'GAUKAGN', 'GAUKAHM', 'GAUKAHN', 'GAUKAIM', 'GAUKAIN', 'GAUKBGM', 'GAUKBGN', 'GAUKBHM', 'GAUKBHN', 'GAUKBIM', 'GAUKBIN', 'GAUKCGM', 'GAUKCGN', 'GAUKCHM', 'GAUKCHN', 'GAUKCIM', 'GAUKCIN', 'GAULAGM', 'GAULAGN', 'GAULAHM', 'GAULAHN', 'GAULAIM', 'GAULAIN', 'GAULBGM', 'GAULBGN', 'GAULBHM', 'GAULBHN', 'GAULBIM', 'GAULBIN', 'GAULCGM', 'GAULCGN', 'GAULCHM', 'GAULCHN', 'GAULCIM', 'GAULCIN', 'GAVJAGM', 'GAVJAGN', 'GAVJAHM', 'GAVJAHN', 'GAVJAIM', 'GAVJAIN', 'GAVJBGM', 'GAVJBGN', 'GAVJBHM', 'GAVJBHN', 'GAVJBIM', 'GAVJBIN', 'GAVJCGM', 'GAVJCGN', 'GAVJCHM', 'GAVJCHN', 'GAVJCIM', 'GAVJCIN', 'GAVKAGM', 'GAVKAGN', 'GAVKAHM', 'GAVKAHN', 'GAVKAIM', 'GAVKAIN', 'GAVKBGM', 'GAVKBGN', 'GAVKBHM', 'GAVKBHN', 'GAVKBIM', 'GAVKBIN', 'GAVKCGM', 'GAVKCGN', 'GAVKCHM', 'GAVKCHN', 'GAVKCIM', 'GAVKCIN', 'GAVLAGM', 'GAVLAGN', 'GAVLAHM', 'GAVLAHN', 'GAVLAIM', 'GAVLAIN', 'GAVLBGM', 'GAVLBGN', 'GAVLBHM', 'GAVLBHN', 'GAVLBIM', 'GAVLBIN', 'GAVLCGM', 'GAVLCGN', 'GAVLCHM', 'GAVLCHN', 'GAVLCIM', 'GAVLCIN', 'GBTJAGM', 'GBTJAGN', 'GBTJAHM', 'GBTJAHN', 'GBTJAIM', 'GBTJAIN', 'GBTJBGM', 'GBTJBGN', 'GBTJBHM', 'GBTJBHN', 'GBTJBIM', 'GBTJBIN', 'GBTJCGM', 'GBTJCGN', 'GBTJCHM', 'GBTJCHN', 'GBTJCIM', 'GBTJCIN', 'GBTKAGM', 'GBTKAGN', 'GBTKAHM', 'GBTKAHN', 'GBTKAIM', 'GBTKAIN', 'GBTKBGM', 'GBTKBGN', 'GBTKBHM', 'GBTKBHN', 'GBTKBIM', 'GBTKBIN', 'GBTKCGM', 'GBTKCGN', 'GBTKCHM', 'GBTKCHN', 'GBTKCIM', 'GBTKCIN', 'GBTLAGM', 'GBTLAGN', 'GBTLAHM', 'GBTLAHN', 'GBTLAIM', 'GBTLAIN', 'GBTLBGM', 'GBTLBGN', 'GBTLBHM', 'GBTLBHN', 'GBTLBIM', 'GBTLBIN', 'GBTLCGM', 'GBTLCGN', 'GBTLCHM', 'GBTLCHN', 'GBTLCIM', 'GBTLCIN', 'GBUJAGM', 'GBUJAGN', 'GBUJAHM', 'GBUJAHN', 'GBUJAIM', 'GBUJAIN', 'GBUJBGM', 'GBUJBGN', 'GBUJBHM', 'GBUJBHN', 'GBUJBIM', 'GBUJBIN', 'GBUJCGM', 'GBUJCGN', 'GBUJCHM', 'GBUJCHN', 'GBUJCIM', 'GBUJCIN', 'GBUKAGM', 'GBUKAGN', 'GBUKAHM', 'GBUKAHN', 'GBUKAIM', 'GBUKAIN', 'GBUKBGM', 'GBUKBGN', 'GBUKBHM', 'GBUKBHN', 'GBUKBIM', 'GBUKBIN', 'GBUKCGM', 'GBUKCGN', 'GBUKCHM', 'GBUKCHN', 'GBUKCIM', 'GBUKCIN', 'GBULAGM', 'GBULAGN', 'GBULAHM', 'GBULAHN', 'GBULAIM', 'GBULAIN', 'GBULBGM', 'GBULBGN', 'GBULBHM', 'GBULBHN', 'GBULBIM', 'GBULBIN', 'GBULCGM', 'GBULCGN', 'GBULCHM', 'GBULCHN', 'GBULCIM', 'GBULCIN', 'GBVJAGM', 'GBVJAGN', 'GBVJAHM', 'GBVJAHN', 'GBVJAIM', 'GBVJAIN', 'GBVJBGM', 'GBVJBGN', 'GBVJBHM', 'GBVJBHN', 'GBVJBIM', 'GBVJBIN', 'GBVJCGM', 'GBVJCGN', 'GBVJCHM', 'GBVJCHN', 'GBVJCIM', 'GBVJCIN', 'GBVKAGM', 'GBVKAGN', 'GBVKAHM', 'GBVKAHN', 'GBVKAIM', 'GBVKAIN', 'GBVKBGM', 'GBVKBGN', 'GBVKBHM', 'GBVKBHN', 'GBVKBIM', 'GBVKBIN', 'GBVKCGM', 'GBVKCGN', 'GBVKCHM', 'GBVKCHN', 'GBVKCIM', 'GBVKCIN', 'GBVLAGM', 'GBVLAGN', 'GBVLAHM', 'GBVLAHN', 'GBVLAIM', 'GBVLAIN', 'GBVLBGM', 'GBVLBGN', 'GBVLBHM', 'GBVLBHN', 'GBVLBIM', 'GBVLBIN', 'GBVLCGM', 'GBVLCGN', 'GBVLCHM', 'GBVLCHN', 'GBVLCIM', 'GBVLCIN', 'GCTJAGM', 'GCTJAGN', 'GCTJAHM', 'GCTJAHN', 'GCTJAIM', 'GCTJAIN', 'GCTJBGM', 'GCTJBGN', 'GCTJBHM', 'GCTJBHN', 'GCTJBIM', 'GCTJBIN', 'GCTJCGM', 'GCTJCGN', 'GCTJCHM', 'GCTJCHN', 'GCTJCIM', 'GCTJCIN', 'GCTKAGM', 'GCTKAGN', 'GCTKAHM', 'GCTKAHN', 'GCTKAIM', 'GCTKAIN', 'GCTKBGM', 'GCTKBGN', 'GCTKBHM', 'GCTKBHN', 'GCTKBIM', 'GCTKBIN', 'GCTKCGM', 'GCTKCGN', 'GCTKCHM', 'GCTKCHN', 'GCTKCIM', 'GCTKCIN', 'GCTLAGM', 'GCTLAGN', 'GCTLAHM', 'GCTLAHN', 'GCTLAIM', 'GCTLAIN', 'GCTLBGM', 'GCTLBGN', 'GCTLBHM', 'GCTLBHN', 'GCTLBIM', 'GCTLBIN', 'GCTLCGM', 'GCTLCGN', 'GCTLCHM', 'GCTLCHN', 'GCTLCIM', 'GCTLCIN', 'GCUJAGM', 'GCUJAGN', 'GCUJAHM', 'GCUJAHN', 'GCUJAIM', 'GCUJAIN', 'GCUJBGM', 'GCUJBGN', 'GCUJBHM', 'GCUJBHN', 'GCUJBIM', 'GCUJBIN', 'GCUJCGM', 'GCUJCGN', 'GCUJCHM', 'GCUJCHN', 'GCUJCIM', 'GCUJCIN', 'GCUKAGM', 'GCUKAGN', 'GCUKAHM', 'GCUKAHN', 'GCUKAIM', 'GCUKAIN', 'GCUKBGM', 'GCUKBGN', 'GCUKBHM', 'GCUKBHN', 'GCUKBIM', 'GCUKBIN', 'GCUKCGM', 'GCUKCGN', 'GCUKCHM', 'GCUKCHN', 'GCUKCIM', 'GCUKCIN', 'GCULAGM', 'GCULAGN', 'GCULAHM', 'GCULAHN', 'GCULAIM', 'GCULAIN', 'GCULBGM', 'GCULBGN', 'GCULBHM', 'GCULBHN', 'GCULBIM', 'GCULBIN', 'GCULCGM', 'GCULCGN', 'GCULCHM', 'GCULCHN', 'GCULCIM', 'GCULCIN', 'GCVJAGM', 'GCVJAGN', 'GCVJAHM', 'GCVJAHN', 'GCVJAIM', 'GCVJAIN', 'GCVJBGM', 'GCVJBGN', 'GCVJBHM', 'GCVJBHN', 'GCVJBIM', 'GCVJBIN', 'GCVJCGM', 'GCVJCGN', 'GCVJCHM', 'GCVJCHN', 'GCVJCIM', 'GCVJCIN', 'GCVKAGM', 'GCVKAGN', 'GCVKAHM', 'GCVKAHN', 'GCVKAIM', 'GCVKAIN', 'GCVKBGM', 'GCVKBGN', 'GCVKBHM', 'GCVKBHN', 'GCVKBIM', 'GCVKBIN', 'GCVKCGM', 'GCVKCGN', 'GCVKCHM', 'GCVKCHN', 'GCVKCIM', 'GCVKCIN', 'GCVLAGM', 'GCVLAGN', 'GCVLAHM', 'GCVLAHN', 'GCVLAIM', 'GCVLAIN', 'GCVLBGM', 'GCVLBGN', 'GCVLBHM', 'GCVLBHN', 'GCVLBIM', 'GCVLBIN', 'GCVLCGM', 'GCVLCGN', 'GCVLCHM', 'GCVLCHN', 'GCVLCIM', 'GCVLCIN', 'HATJAGM', 'HATJAGN', 'HATJAHM', 'HATJAHN', 'HATJAIM', 'HATJAIN', 'HATJBGM', 'HATJBGN', 'HATJBHM', 'HATJBHN', 'HATJBIM', 'HATJBIN', 'HATJCGM', 'HATJCGN', 'HATJCHM', 'HATJCHN', 'HATJCIM', 'HATJCIN', 'HATKAGM', 'HATKAGN', 'HATKAHM', 'HATKAHN', 'HATKAIM', 'HATKAIN', 'HATKBGM', 'HATKBGN', 'HATKBHM', 'HATKBHN', 'HATKBIM', 'HATKBIN', 'HATKCGM', 'HATKCGN', 'HATKCHM', 'HATKCHN', 'HATKCIM', 'HATKCIN', 'HATLAGM', 'HATLAGN', 'HATLAHM', 'HATLAHN', 'HATLAIM', 'HATLAIN', 'HATLBGM', 'HATLBGN', 'HATLBHM', 'HATLBHN', 'HATLBIM', 'HATLBIN', 'HATLCGM', 'HATLCGN', 'HATLCHM', 'HATLCHN', 'HATLCIM', 'HATLCIN', 'HAUJAGM', 'HAUJAGN', 'HAUJAHM', 'HAUJAHN', 'HAUJAIM', 'HAUJAIN', 'HAUJBGM', 'HAUJBGN', 'HAUJBHM', 'HAUJBHN', 'HAUJBIM', 'HAUJBIN', 'HAUJCGM', 'HAUJCGN', 'HAUJCHM', 'HAUJCHN', 'HAUJCIM', 'HAUJCIN', 'HAUKAGM', 'HAUKAGN', 'HAUKAHM', 'HAUKAHN', 'HAUKAIM', 'HAUKAIN', 'HAUKBGM', 'HAUKBGN', 'HAUKBHM', 'HAUKBHN', 'HAUKBIM', 'HAUKBIN', 'HAUKCGM', 'HAUKCGN', 'HAUKCHM', 'HAUKCHN', 'HAUKCIM', 'HAUKCIN', 'HAULAGM', 'HAULAGN', 'HAULAHM', 'HAULAHN', 'HAULAIM', 'HAULAIN', 'HAULBGM', 'HAULBGN', 'HAULBHM', 'HAULBHN', 'HAULBIM', 'HAULBIN', 'HAULCGM', 'HAULCGN', 'HAULCHM', 'HAULCHN', 'HAULCIM', 'HAULCIN', 'HAVJAGM', 'HAVJAGN', 'HAVJAHM', 'HAVJAHN', 'HAVJAIM', 'HAVJAIN', 'HAVJBGM', 'HAVJBGN', 'HAVJBHM', 'HAVJBHN', 'HAVJBIM', 'HAVJBIN', 'HAVJCGM', 'HAVJCGN', 'HAVJCHM', 'HAVJCHN', 'HAVJCIM', 'HAVJCIN', 'HAVKAGM', 'HAVKAGN', 'HAVKAHM', 'HAVKAHN', 'HAVKAIM', 'HAVKAIN', 'HAVKBGM', 'HAVKBGN', 'HAVKBHM', 'HAVKBHN', 'HAVKBIM', 'HAVKBIN', 'HAVKCGM', 'HAVKCGN', 'HAVKCHM', 'HAVKCHN', 'HAVKCIM', 'HAVKCIN', 'HAVLAGM', 'HAVLAGN', 'HAVLAHM', 'HAVLAHN', 'HAVLAIM', 'HAVLAIN', 'HAVLBGM', 'HAVLBGN', 'HAVLBHM', 'HAVLBHN', 'HAVLBIM', 'HAVLBIN', 'HAVLCGM', 'HAVLCGN', 'HAVLCHM', 'HAVLCHN', 'HAVLCIM', 'HAVLCIN', 'HBTJAGM', 'HBTJAGN', 'HBTJAHM', 'HBTJAHN', 'HBTJAIM', 'HBTJAIN', 'HBTJBGM', 'HBTJBGN', 'HBTJBHM', 'HBTJBHN', 'HBTJBIM', 'HBTJBIN', 'HBTJCGM', 'HBTJCGN', 'HBTJCHM', 'HBTJCHN', 'HBTJCIM', 'HBTJCIN', 'HBTKAGM', 'HBTKAGN', 'HBTKAHM', 'HBTKAHN', 'HBTKAIM', 'HBTKAIN', 'HBTKBGM', 'HBTKBGN', 'HBTKBHM', 'HBTKBHN', 'HBTKBIM', 'HBTKBIN', 'HBTKCGM', 'HBTKCGN', 'HBTKCHM', 'HBTKCHN', 'HBTKCIM', 'HBTKCIN', 'HBTLAGM', 'HBTLAGN', 'HBTLAHM', 'HBTLAHN', 'HBTLAIM', 'HBTLAIN', 'HBTLBGM', 'HBTLBGN', 'HBTLBHM', 'HBTLBHN', 'HBTLBIM', 'HBTLBIN', 'HBTLCGM', 'HBTLCGN', 'HBTLCHM', 'HBTLCHN', 'HBTLCIM', 'HBTLCIN', 'HBUJAGM', 'HBUJAGN', 'HBUJAHM', 'HBUJAHN', 'HBUJAIM', 'HBUJAIN', 'HBUJBGM', 'HBUJBGN', 'HBUJBHM', 'HBUJBHN', 'HBUJBIM', 'HBUJBIN', 'HBUJCGM', 'HBUJCGN', 'HBUJCHM', 'HBUJCHN', 'HBUJCIM', 'HBUJCIN', 'HBUKAGM', 'HBUKAGN', 'HBUKAHM', 'HBUKAHN', 'HBUKAIM', 'HBUKAIN', 'HBUKBGM', 'HBUKBGN', 'HBUKBHM', 'HBUKBHN', 'HBUKBIM', 'HBUKBIN', 'HBUKCGM', 'HBUKCGN', 'HBUKCHM', 'HBUKCHN', 'HBUKCIM', 'HBUKCIN', 'HBULAGM', 'HBULAGN', 'HBULAHM', 'HBULAHN', 'HBULAIM', 'HBULAIN', 'HBULBGM', 'HBULBGN', 'HBULBHM', 'HBULBHN', 'HBULBIM', 'HBULBIN', 'HBULCGM', 'HBULCGN', 'HBULCHM', 'HBULCHN', 'HBULCIM', 'HBULCIN', 'HBVJAGM', 'HBVJAGN', 'HBVJAHM', 'HBVJAHN', 'HBVJAIM', 'HBVJAIN', 'HBVJBGM', 'HBVJBGN', 'HBVJBHM', 'HBVJBHN', 'HBVJBIM', 'HBVJBIN', 'HBVJCGM', 'HBVJCGN', 'HBVJCHM', 'HBVJCHN', 'HBVJCIM', 'HBVJCIN', 'HBVKAGM', 'HBVKAGN', 'HBVKAHM', 'HBVKAHN', 'HBVKAIM', 'HBVKAIN', 'HBVKBGM', 'HBVKBGN', 'HBVKBHM', 'HBVKBHN', 'HBVKBIM', 'HBVKBIN', 'HBVKCGM', 'HBVKCGN', 'HBVKCHM', 'HBVKCHN', 'HBVKCIM', 'HBVKCIN', 'HBVLAGM', 'HBVLAGN', 'HBVLAHM', 'HBVLAHN', 'HBVLAIM', 'HBVLAIN', 'HBVLBGM', 'HBVLBGN', 'HBVLBHM', 'HBVLBHN', 'HBVLBIM', 'HBVLBIN', 'HBVLCGM', 'HBVLCGN', 'HBVLCHM', 'HBVLCHN', 'HBVLCIM', 'HBVLCIN', 'HCTJAGM', 'HCTJAGN', 'HCTJAHM', 'HCTJAHN', 'HCTJAIM', 'HCTJAIN', 'HCTJBGM', 'HCTJBGN', 'HCTJBHM', 'HCTJBHN', 'HCTJBIM', 'HCTJBIN', 'HCTJCGM', 'HCTJCGN', 'HCTJCHM', 'HCTJCHN', 'HCTJCIM', 'HCTJCIN', 'HCTKAGM', 'HCTKAGN', 'HCTKAHM', 'HCTKAHN', 'HCTKAIM', 'HCTKAIN', 'HCTKBGM', 'HCTKBGN', 'HCTKBHM', 'HCTKBHN', 'HCTKBIM', 'HCTKBIN', 'HCTKCGM', 'HCTKCGN', 'HCTKCHM', 'HCTKCHN', 'HCTKCIM', 'HCTKCIN', 'HCTLAGM', 'HCTLAGN', 'HCTLAHM', 'HCTLAHN', 'HCTLAIM', 'HCTLAIN', 'HCTLBGM', 'HCTLBGN', 'HCTLBHM', 'HCTLBHN', 'HCTLBIM', 'HCTLBIN', 'HCTLCGM', 'HCTLCGN', 'HCTLCHM', 'HCTLCHN', 'HCTLCIM', 'HCTLCIN', 'HCUJAGM', 'HCUJAGN', 'HCUJAHM', 'HCUJAHN', 'HCUJAIM', 'HCUJAIN', 'HCUJBGM', 'HCUJBGN', 'HCUJBHM', 'HCUJBHN', 'HCUJBIM', 'HCUJBIN', 'HCUJCGM', 'HCUJCGN', 'HCUJCHM', 'HCUJCHN', 'HCUJCIM', 'HCUJCIN', 'HCUKAGM', 'HCUKAGN', 'HCUKAHM', 'HCUKAHN', 'HCUKAIM', 'HCUKAIN', 'HCUKBGM', 'HCUKBGN', 'HCUKBHM', 'HCUKBHN', 'HCUKBIM', 'HCUKBIN', 'HCUKCGM', 'HCUKCGN', 'HCUKCHM', 'HCUKCHN', 'HCUKCIM', 'HCUKCIN', 'HCULAGM', 'HCULAGN', 'HCULAHM', 'HCULAHN', 'HCULAIM', 'HCULAIN', 'HCULBGM', 'HCULBGN', 'HCULBHM', 'HCULBHN', 'HCULBIM', 'HCULBIN', 'HCULCGM', 'HCULCGN', 'HCULCHM', 'HCULCHN', 'HCULCIM', 'HCULCIN', 'HCVJAGM', 'HCVJAGN', 'HCVJAHM', 'HCVJAHN', 'HCVJAIM', 'HCVJAIN', 'HCVJBGM', 'HCVJBGN', 'HCVJBHM', 'HCVJBHN', 'HCVJBIM', 'HCVJBIN', 'HCVJCGM', 'HCVJCGN', 'HCVJCHM', 'HCVJCHN', 'HCVJCIM', 'HCVJCIN', 'HCVKAGM', 'HCVKAGN', 'HCVKAHM', 'HCVKAHN', 'HCVKAIM', 'HCVKAIN', 'HCVKBGM', 'HCVKBGN', 'HCVKBHM', 'HCVKBHN', 'HCVKBIM', 'HCVKBIN', 'HCVKCGM', 'HCVKCGN', 'HCVKCHM', 'HCVKCHN', 'HCVKCIM', 'HCVKCIN', 'HCVLAGM', 'HCVLAGN', 'HCVLAHM', 'HCVLAHN', 'HCVLAIM', 'HCVLAIN', 'HCVLBGM', 'HCVLBGN', 'HCVLBHM', 'HCVLBHN', 'HCVLBIM', 'HCVLBIN', 'HCVLCGM', 'HCVLCGN', 'HCVLCHM', 'HCVLCHN', 'HCVLCIM', 'HCVLCIN', 'IATJAGM', 'IATJAGN', 'IATJAHM', 'IATJAHN', 'IATJAIM', 'IATJAIN', 'IATJBGM', 'IATJBGN', 'IATJBHM', 'IATJBHN', 'IATJBIM', 'IATJBIN', 'IATJCGM', 'IATJCGN', 'IATJCHM', 'IATJCHN', 'IATJCIM', 'IATJCIN', 'IATKAGM', 'IATKAGN', 'IATKAHM', 'IATKAHN', 'IATKAIM', 'IATKAIN', 'IATKBGM', 'IATKBGN', 'IATKBHM', 'IATKBHN', 'IATKBIM', 'IATKBIN', 'IATKCGM', 'IATKCGN', 'IATKCHM', 'IATKCHN', 'IATKCIM', 'IATKCIN', 'IATLAGM', 'IATLAGN', 'IATLAHM', 'IATLAHN', 'IATLAIM', 'IATLAIN', 'IATLBGM', 'IATLBGN', 'IATLBHM', 'IATLBHN', 'IATLBIM', 'IATLBIN', 'IATLCGM', 'IATLCGN', 'IATLCHM', 'IATLCHN', 'IATLCIM', 'IATLCIN', 'IAUJAGM', 'IAUJAGN', 'IAUJAHM', 'IAUJAHN', 'IAUJAIM', 'IAUJAIN', 'IAUJBGM', 'IAUJBGN', 'IAUJBHM', 'IAUJBHN', 'IAUJBIM', 'IAUJBIN', 'IAUJCGM', 'IAUJCGN', 'IAUJCHM', 'IAUJCHN', 'IAUJCIM', 'IAUJCIN', 'IAUKAGM', 'IAUKAGN', 'IAUKAHM', 'IAUKAHN', 'IAUKAIM', 'IAUKAIN', 'IAUKBGM', 'IAUKBGN', 'IAUKBHM', 'IAUKBHN', 'IAUKBIM', 'IAUKBIN', 'IAUKCGM', 'IAUKCGN', 'IAUKCHM', 'IAUKCHN', 'IAUKCIM', 'IAUKCIN', 'IAULAGM', 'IAULAGN', 'IAULAHM', 'IAULAHN', 'IAULAIM', 'IAULAIN', 'IAULBGM', 'IAULBGN', 'IAULBHM', 'IAULBHN', 'IAULBIM', 'IAULBIN', 'IAULCGM', 'IAULCGN', 'IAULCHM', 'IAULCHN', 'IAULCIM', 'IAULCIN', 'IAVJAGM', 'IAVJAGN', 'IAVJAHM', 'IAVJAHN', 'IAVJAIM', 'IAVJAIN', 'IAVJBGM', 'IAVJBGN', 'IAVJBHM', 'IAVJBHN', 'IAVJBIM', 'IAVJBIN', 'IAVJCGM', 'IAVJCGN', 'IAVJCHM', 'IAVJCHN', 'IAVJCIM', 'IAVJCIN', 'IAVKAGM', 'IAVKAGN', 'IAVKAHM', 'IAVKAHN', 'IAVKAIM', 'IAVKAIN', 'IAVKBGM', 'IAVKBGN', 'IAVKBHM', 'IAVKBHN', 'IAVKBIM', 'IAVKBIN', 'IAVKCGM', 'IAVKCGN', 'IAVKCHM', 'IAVKCHN', 'IAVKCIM', 'IAVKCIN', 'IAVLAGM', 'IAVLAGN', 'IAVLAHM', 'IAVLAHN', 'IAVLAIM', 'IAVLAIN', 'IAVLBGM', 'IAVLBGN', 'IAVLBHM', 'IAVLBHN', 'IAVLBIM', 'IAVLBIN', 'IAVLCGM', 'IAVLCGN', 'IAVLCHM', 'IAVLCHN', 'IAVLCIM', 'IAVLCIN', 'IBTJAGM', 'IBTJAGN', 'IBTJAHM', 'IBTJAHN', 'IBTJAIM', 'IBTJAIN', 'IBTJBGM', 'IBTJBGN', 'IBTJBHM', 'IBTJBHN', 'IBTJBIM', 'IBTJBIN', 'IBTJCGM', 'IBTJCGN', 'IBTJCHM', 'IBTJCHN', 'IBTJCIM', 'IBTJCIN', 'IBTKAGM', 'IBTKAGN', 'IBTKAHM', 'IBTKAHN', 'IBTKAIM', 'IBTKAIN', 'IBTKBGM', 'IBTKBGN', 'IBTKBHM', 'IBTKBHN', 'IBTKBIM', 'IBTKBIN', 'IBTKCGM', 'IBTKCGN', 'IBTKCHM', 'IBTKCHN', 'IBTKCIM', 'IBTKCIN', 'IBTLAGM', 'IBTLAGN', 'IBTLAHM', 'IBTLAHN', 'IBTLAIM', 'IBTLAIN', 'IBTLBGM', 'IBTLBGN', 'IBTLBHM', 'IBTLBHN', 'IBTLBIM', 'IBTLBIN', 'IBTLCGM', 'IBTLCGN', 'IBTLCHM', 'IBTLCHN', 'IBTLCIM', 'IBTLCIN', 'IBUJAGM', 'IBUJAGN', 'IBUJAHM', 'IBUJAHN', 'IBUJAIM', 'IBUJAIN', 'IBUJBGM', 'IBUJBGN', 'IBUJBHM', 'IBUJBHN', 'IBUJBIM', 'IBUJBIN', 'IBUJCGM', 'IBUJCGN', 'IBUJCHM', 'IBUJCHN', 'IBUJCIM', 'IBUJCIN', 'IBUKAGM', 'IBUKAGN', 'IBUKAHM', 'IBUKAHN', 'IBUKAIM', 'IBUKAIN', 'IBUKBGM', 'IBUKBGN', 'IBUKBHM', 'IBUKBHN', 'IBUKBIM', 'IBUKBIN', 'IBUKCGM', 'IBUKCGN', 'IBUKCHM', 'IBUKCHN', 'IBUKCIM', 'IBUKCIN', 'IBULAGM', 'IBULAGN', 'IBULAHM', 'IBULAHN', 'IBULAIM', 'IBULAIN', 'IBULBGM', 'IBULBGN', 'IBULBHM', 'IBULBHN', 'IBULBIM', 'IBULBIN', 'IBULCGM', 'IBULCGN', 'IBULCHM', 'IBULCHN', 'IBULCIM', 'IBULCIN', 'IBVJAGM', 'IBVJAGN', 'IBVJAHM', 'IBVJAHN', 'IBVJAIM', 'IBVJAIN', 'IBVJBGM', 'IBVJBGN', 'IBVJBHM', 'IBVJBHN', 'IBVJBIM', 'IBVJBIN', 'IBVJCGM', 'IBVJCGN', 'IBVJCHM', 'IBVJCHN', 'IBVJCIM', 'IBVJCIN', 'IBVKAGM', 'IBVKAGN', 'IBVKAHM', 'IBVKAHN', 'IBVKAIM', 'IBVKAIN', 'IBVKBGM', 'IBVKBGN', 'IBVKBHM', 'IBVKBHN', 'IBV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', 'ICUKAIN', 'ICUKBGM', 'ICUKBGN', 'ICUKBHM', 'ICUKBHN', 'ICUKBIM', 'ICUKBIN', 'ICUKCGM', 'ICUKCGN', 'ICUKCHM', 'ICUKCHN', 'ICUKCIM', 'ICUKCIN', 'ICULAGM', 'ICULAGN', 'ICULAHM', 'ICULAHN', 'ICULAIM', 'ICULAIN', 'ICULBGM', 'ICULBGN', 'ICULBHM', 'ICULBHN', 'ICULBIM', 'ICULBIN', 'ICULCGM', 'ICULCGN', 'ICULCHM', 'ICULCHN', 'ICULCIM', 'ICULCIN', 'ICVJAGM', 'ICVJAGN', 'ICVJAHM', 'ICVJAHN', 'ICVJAIM', 'ICVJAIN', 'ICVJBGM', 'ICVJBGN', 'ICVJBHM', 'ICVJBHN', 'ICVJBIM', 'ICVJBIN', 'ICVJCGM', 'ICVJCGN', 'ICVJCHM', 'ICVJCHN', 'ICVJCIM', 'ICVJCIN', 'ICVKAGM', 'ICVKAGN', 'ICVKAHM', 'ICVKAHN', 'ICVKAIM', 'ICVKAIN', 'ICVKBGM', 'ICVKBGN', 'ICVKBHM', 'ICVKBHN', 'ICVKBIM', 'ICVKBIN', 'ICVKCGM', 'ICVKCGN', 'ICVKCHM', 'ICVKCHN', 'ICVKCIM', 'ICVKCIN', 'ICVLAGM', 'ICVLAGN', 'ICVLAHM', 'ICVLAHN', 'ICVLAIM', 'ICVLAIN', 'ICVLBGM', 'ICVLBGN', 'ICVLBHM', 'ICVLBHN', 'ICVLBIM', 'ICVLBIN', 'ICVLCGM', 'ICVLCGN', 'ICVLCHM', 'ICVLCHN', 'ICVLCIM', 'ICVLCIN']
you may notice i am of the school 0->'O', 1->'1'. If that does not please you, change your literal to taste.
Mathematica, 87 characters-
Bonus Track below in version 3 (Generating Valid English Words)
This version includes the Q, hyphen, and space rules, as currently listed.
#<>""&/@Tuples@Join[{{"-"},{" "}},"A"~CharacterRange~"Y"~Drop~{17}~Partition~3][[#+1]]&
Mathematica: 98 chars
k[x_]:=Tuples[Table[Union[{{"-"},{1}},
Partition[CharacterRange["A","Y"],3]][[(x+1)[[i]]]],{i,1,7}]]
Please note the loooong names
Usage
k[{4,2,8,5,2,4,6}]
Edit>
It outputs only unique cases. To count the unique sequences:
Length[k[{4,2,8,5,2,4,6}]]
Edit
Version 2: 96 Chars
k[x_]:=Tuples[Table[Union[{{"-"},{1}},
Partition[CharacterRange["A","Y"],3]][[(x+1)[[i]]]],{i,1}]]
Version 3: a Bonus track - Generating Valid English Words
I decided that Mathematica is very powerful but too verbose for a shorthand competition. Anyway, before bowing and leaving the "contest" I want to show up one more function, just for amusement, and for checking whether the statement "Bonus points awarded for recognizing output as real English words. Okay, not really. ;-)" was true or not.
The code is:
d[x_] := Join @@ (DictionaryLookup[# <> ""] & /@
Tuples@Join[{{"-"}, {" "}},
"a"~CharacterRange~"y"~Drop~{17}~Partition~3][[x + 1]])
When called with
d[{7, 2, 3, 4, 7, 8, 4, 2}]
The result is
{"sadistic"}
When called with
d[{2,6,8,2,4}]
The result is
{"botch", "couch"}
And when called with
d[{3, 2, 4, 5}]
The result is
{"fail"}
Nice, isn't it?
J, 60 62 65 67 characters
~.('--- ','Q'(~:#])25{.65|.a.){~((7$3)#:i.3^7)+"1]3*"."0":
Uses Nick's Modified North American Classic Key Pad.
~.('--- ','Q'(~:#])25{.65|.a.){~((7$3)#:i.3^7)+"1]3*"."0":4285246
...
ICTJCHM
ICTJCHN
ICTJCHO
ICTJCIM
ICTJCIN
ICTJCIO
ICTKAGM
ICTKAGN
ICTKAGO
ICTKAHM
ICTKAHN
ICTKAHO
ICTKAIM
ICTKAIN
ICTKAIO
ICTKBGM
ICTKBGN
ICTKBGO
ICTKBHM
ICTKBHN
ICTKBHO
ICTKBIM
ICTKBIN
ICTKBIO
ICTKCGM
ICTKCGN
ICTKCGO
ICTKCHM
ICTKCHN
ICTKCHO
ICTKCIM
ICTKCIN
ICTKCIO
ICTLAGM
ICTLAGN
ICTLAGO
ICTLAHM
ICTLAHN
ICTLAHO
ICTL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
ICVKAHM
ICVKAHN
ICVKAHO
ICVKAIM
ICVKAIN
ICVKAIO
ICVKBGM
ICVKBGN
ICVKBGO
ICVKBHM
ICVKBHN
ICVKBHO
ICVKBIM
ICVKBIN
ICVKBIO
ICVKCGM
ICVKCGN
ICVKCGO
ICVKCHM
ICVKCHN
ICVKCHO
ICVKCIM
ICVKCIN
ICVKCIO
ICVLAGM
ICVLAGN
ICVLAGO
ICVLAHM
ICVLAHN
ICVLAHO
ICVLAIM
ICVLAIN
ICVLAIO
ICVLBGM
ICVLBGN
ICVLBGO
ICVLBHM
ICVLBHN
ICVLBHO
ICVLBIM
ICVLBIN
ICVLBIO
ICVLCGM
ICVLCGN
ICVLCGO
ICVLCHM
ICVLCHN
ICVLCHO
ICVLCIM
ICVLCIN
ICVLCIO
Haskell:
Just a pure function (69 78 chars)::
f=mapM(\x->("-":" ":words"ABC DEF GHI JKL MNO PRS TUV WXY")!!read[x])
Usage:
Prelude> f "626"
["MAM","MAN","MAO","MBM","MBN","MBO","MCM","MCN","MCO","NAM","NAN","NAO","NBM","NBN","NBO","NCM","NCN","NCO","OAM","OAN","OAO","OBM","OBN","OBO","OCM","OCN","OCO"]
As a full program (93 102 chars)::
main=getLine>>=mapM print.mapM(\x->("-":" ":words"ABC DEF GHI JKL MNO PRS TUV WXY")!!read[x])
Usage:
~$ ./a.out
626
"MAM"
"MAN"
"MAO"
"MBM"
"MBN"
"MBO"
"MCM"
"MCN"
"MCO"
"NAM"
"NAN"
"NAO"
"NBM"
"NBN"
"NBO"
"NCM"
"NCN"
"NCO"
"OAM"
"OAN"
"OAO"
"OBM"
"OBN"
"OBO"
"OCM"
"OCN"
"OCO"
Replace [...,"PRS","TUV","WXY"]
with [...,"PQRS","TUV","WXYZ"]
to get the international keypad, +2 chars.
Replace print
with putStrLn
to strip the quotation marks in output, +3 chars.
Newlines and whitespaces between symbol and words are added only to remove the horizontal scrollbar.
Perl, 101 chars:
This abuses the glob operator <{a,b,c}{d,e,f}>
to calculate the cartesian product:
$,=$/;print eval"<{".(join"}{",map{s/\B/,/g;$_} # wrapped to fit
map{(0,1,join("",A..Z)=~/...S?Z?/g)[$_]}pop=~/./g)."}>"
as a program (111 chars):
perl -e'$,=$/;print eval"<{".(join"}{",map{s/\B/,/g;$_}map{(0,1,join("",A..Z)=~/...S?Z?/g)[$_]}pop=~/./g)."}>"' 4285246
Edit: incorporated mobrule's suggestions
Python, 157 139 119 chars:
Tabs and newlines counted... ;)
Now using "Nick's Modified Keypad"
def p(a,b=''):
if a:[p(a[1:],b+c)for c in '-, ,ABC,DEF,GHI,JKL,MNO,PRS,TUV,WXY'.split(',')[int(a[0])]];return
print b
Usage: (+12c)
p('4285246')
Ruby, 109 characters
l=%w{- \ ABC DEF GHI JKL MN PRS TUV WXY};p$_.chars.map{|d|[*l[d.to_i].chars]}.reduce(&:product).map{|x|x*""}
Usage:
echo "2345678" | ruby -lne 'l=%w{- \ ABC DEF GHI JKL MN PRS TUV WXY};p$_.chars.map{|d|[*l[d.to_i].chars]}.reduce(&:product).map{|x|x*""}'
Result for "2345678" - length 1458
ADGJMPT
ADGJMPU
ADGJMPV
ADGJMRT
ADGJMRU
ADGJMRV
ADGJMST
ADGJMSU
ADGJMSV
ADGJNPT
ADGJNPU
ADGJNPV
ADGJNRT
ADGJNRU
ADGJNRV
ADGJNST
ADGJNSU
ADGJNSV
ADGKMPT
ADGKMPU
ADGKMPV
ADGKMRT
ADGKMRU
ADGKMRV
ADGKMST
ADGKMSU
ADGKMSV
ADGKNPT
ADGKNPU
ADGKNPV
ADGKNRT
ADGKNRU
ADGKNRV
ADGKNST
ADGKNSU
ADGKNSV
ADGLMPT
ADGLMPU
ADGLMPV
ADGLMRT
ADGLMRU
ADGLMRV
ADGLMST
ADGLMSU
ADGLMSV
ADGLNPT
ADGLNPU
ADGLNPV
ADGLNRT
ADGLNRU
ADGLNRV
ADGLNST
ADGLNSU
ADGLNSV
ADHJMPT
ADHJMPU
ADHJMPV
ADHJMRT
ADHJMRU
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MSU
CFHKMSV
CFHKNPT
CFHKNPU
CFHKNPV
CFHKNRT
CFHKNRU
CFHKNRV
CFHKNST
CFHKNSU
CFHKNSV
CFHLMPT
CFHLMPU
CFHLMPV
CFHLMRT
CFHLMRU
CFHLMRV
CFHLMST
CFHLMSU
CFHLMSV
CFHLNPT
CFHLNPU
CFHLNPV
CFHLNRT
CFHLNRU
CFHLNRV
CFHLNST
CFHLNSU
CFHLNSV
CFIJMPT
CFIJMPU
CFIJMPV
CFIJMRT
CFIJMRU
CFIJMRV
CFIJMST
CFIJMSU
CFIJMSV
CFIJNPT
CFIJNPU
CFIJNPV
CFIJNRT
CFIJNRU
CFIJNRV
CFIJNST
CFIJNSU
CFIJNSV
CFIKMPT
CFIKMPU
CFIKMPV
CFIKMRT
CFIKMRU
CFIKMRV
CFIKMST
CFIKMSU
CFIKMSV
CFIKNPT
CFIKNPU
CFIKNPV
CFIKNRT
CFIKNRU
CFIKNRV
CFIKNST
CFIKNSU
CFIKNSV
CFILMPT
CFILMPU
CFILMPV
CFILMRT
CFILMRU
CFILMRV
CFILMST
CFILMSU
CFILMSV
CFILNPT
CFILNPU
CFILNPV
CFILNRT
CFILNRU
CFILNRV
CFILNST
CFILNSU
CFILNSV
Python 243 chars
pad = [" ","-","ABC","DEF","GHI","JKL","MN","PRS","TUV","WXY"]
def c(p,v):
try:
if 1>len(v):print p;return
map(lambda a:c(p+a,v[1:]),pad[int(v[0])])
except:
p(p+"-",v[1:])
c("","4285246")
来源:https://stackoverflow.com/questions/2969696/code-golf-phone-number-to-words