diff --git a/permutations of a string.py b/permutations of a string.py new file mode 100644 index 00000000..e62a3072 --- /dev/null +++ b/permutations of a string.py @@ -0,0 +1,19 @@ +# Recursive function to generate all permutations of a string +def permutations(remaining, candidate=''): + + if len(remaining) == 0: + print(candidate) + + for i in range(len(remaining)): + + newCandidate = candidate + remaining[i] + newRemaining = remaining[0:i] + remaining[i+1:] + + permutations(newRemaining, newCandidate) + + +if __name__ == '__main__': + + s = 'ABC' + permutations(s) +