Created
August 9, 2017 09:20
-
-
Save tslmy/9f60401656bb58676334c34b91027cd0 to your computer and use it in GitHub Desktop.
Find Meaning for Phone Number
This file contains hidden or 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
numToLetter = {"1": ("_"), | |
"2": ("A", "B", "C"), | |
"3": ("D", "E", "F"), | |
"4": ("G", "H", "I"), | |
"5": ("J", "K", "L"), | |
"6": ("M", "N", "O"), | |
"7": ("P", "Q", "R", "S"), | |
"8": ("T", "U", "V"), | |
"9": ("W", "X", "Y", "Z"), | |
"0": ("+")} | |
vowels = ("A", "I", "U", "E", "O", "Y", "V") | |
phoneNumber = input("Enter your phone number, digits only (preferably 4 digits): ") | |
length = len(phoneNumber) | |
def analyzeTheRestDigits(previousString = "", theRestDigits = "", needVowel = False): | |
'''Prints all possible pronounciable combinations.''' | |
usableLetters = numToLetter[theRestDigits[0]] | |
thisLength = len(previousString)+1 | |
for letter in usableLetters: | |
thisString = previousString+letter | |
if needVowel: | |
if letter in vowels: | |
if thisLength == length: print(thisString) | |
if len(theRestDigits)>1: analyzeTheRestDigits(thisString, theRestDigits[1:], needVowel = False) | |
else: #a consonant is also okay | |
if thisLength == length: print(thisString) | |
if len(theRestDigits)>1: analyzeTheRestDigits(thisString, theRestDigits[1:], needVowel = True) | |
if length>0: analyzeTheRestDigits(theRestDigits = phoneNumber) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment