Skip to content

Instantly share code, notes, and snippets.

@djp424
Created November 24, 2019 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djp424/69794c09e5e91840184ec7dbaa794478 to your computer and use it in GitHub Desktop.
Save djp424/69794c09e5e91840184ec7dbaa794478 to your computer and use it in GitHub Desktop.
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