-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2f3998
commit 40f5581
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
Retos/Reto #36 - PERMUTACIONES [Media]/python/EspinoLeandroo.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def generate_permutations(word): | ||
def generate_permutations_helper(word, index, permutations): | ||
if index == len(word) - 1: | ||
permutations.append(''.join(word)) | ||
else: | ||
for i in range(index, len(word)): | ||
word[index], word[i] = word[i], word[index] | ||
generate_permutations_helper(word, index + 1, permutations) | ||
word[index], word[i] = word[i], word[index] # Deshacer el intercambio para volver al estado original | ||
|
||
permutations = [] | ||
generate_permutations_helper(list(word), 0, permutations) | ||
return permutations | ||
|
||
if __name__ == "__main__": | ||
word = "Leandro" | ||
permutations = generate_permutations(word) | ||
for permutation in permutations: | ||
print(permutation) |