Created
April 15, 2012 23:09
-
-
Save javiermon/2395256 to your computer and use it in GitHub Desktop.
phone# to text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
pos = [['0']*3,['1']*3,['A','B','C'],['D','E','F'], | |
['G','H','I'],['J','K','L'],['M','N','O'],['P','R','S'], | |
['T','U','V'],['W','X','Z']] | |
# number to list of digits | |
def int_to_list(i): | |
return [int(x) for x in str(i).zfill(len(str(i)))] | |
# flatten any list of list | |
def flat_sum(x) : | |
return [item for sublist in x for item in sublist] | |
def tellphone(x): | |
if len(x) == 1: | |
return pos[x[0]] | |
else: | |
first, rest = x[0], x[1:] | |
return (map(lambda x: pos[first][0] + x, flat_sum(tellphone(rest))), | |
map(lambda x: pos[first][1] + x, flat_sum(tellphone(rest))), | |
map(lambda x: pos[first][2] + x, flat_sum(tellphone(rest)))) | |
def givemenames(number): return flat_sum(tellphone(int_to_list(number))) | |
number = 657146853 | |
result = givemenames(number) | |
print 'number: %s' % number | |
print 'found %s solutions' % len(result) | |
for i in result: | |
print i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment