Created
November 24, 2019 21:29
-
-
Save djp424/69794c09e5e91840184ec7dbaa794478 to your computer and use it in GitHub Desktop.
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
def printCharPermutations(word): | |
print('') # 0 | |
if len(word) == 1: # 1 | |
print(word[0]) | |
return | |
printCharPermutationsHelper('', word, len(word)) | |
def printCharPermutationsHelper(currentPermutation, lettersICanUse, maxLen): # 3. | |
if len(currentPermutation) == maxLen: # all permutations with full length | |
print( currentPermutation ) | |
elif len(currentPermutation) < maxLen: | |
for letter in lettersICanUse: | |
newPerm = currentPermutation + letter | |
print( currentPermutation ) # dups? a, n, t | |
printCharPermutationsHelper(newPerm, lettersICanUse, maxLen) | |
printCharPermutations('ant') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment