Skip to content

Instantly share code, notes, and snippets.

@d6veteran
Last active December 22, 2015 01:18
Show Gist options
  • Save d6veteran/6395072 to your computer and use it in GitHub Desktop.
Save d6veteran/6395072 to your computer and use it in GitHub Desktop.
import itertools
def findPhoneNumbers(phone_name):
PHONE_LENGTH = 10
allowed_numbers = ["1","2","3","4","5","6","7","8","9","0"]
# Get all permutations for positions not taken by phone name
match_length = PHONE_LENGTH - len(phone_name)
matches = itertools.permutations(allowed_numbers ,match_length)
phone_numbers = []
# Get all permutations that include the phone name
for m in matches:
match = list(m)
for i in range(len(match) +1):
phone_number = list(match)
phone_number.insert(i, phone_name)
phone_number = ''.join(phone_number)
phone_numbers.append(str(phone_number))
return phone_numbers
vishal_phone_numbers = findPhoneNumbers("847425")
print "There are %s matches:" % len(vishal_phone_numbers)
for n in vishal_phone_numbers:
print n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment