Skip to content

Commit

Permalink
Reto #36 - python
Browse files Browse the repository at this point in the history
  • Loading branch information
espinoleandroo committed Nov 29, 2023
1 parent f2f3998 commit 40f5581
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Retos/Reto #36 - PERMUTACIONES [Media]/python/EspinoLeandroo.py
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)

0 comments on commit 40f5581

Please sign in to comment.