Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions ...f a string/Permutations of a string S1.py → ...f-a-string/permutations-of-a-string-s1.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
def generate_permutations(input_string, current_string=""):
if len(input_string) == 0:
print(current_string, "\n")
return
for i in range(len(input_string)):
remaining_string = input_string[:i] + input_string[i+1:]
generate_permutations(remaining_string, current_string + input_string[i])
# Test 1
input_string = input() # cat
generate_permutations(input_string)
def generate_permutations(input_string, current_string=""):
if len(input_string) == 0:
print(current_string, "\n")
return
for i in range(len(input_string)):
remaining_string = input_string[:i] + input_string[i+1:]
generate_permutations(remaining_string, current_string + input_string[i])

# Test 1
input_string = input() # cat
generate_permutations(input_string)
24 changes: 12 additions & 12 deletions ...rmutations of a string/permutations_S2.py → ...rmutations-of-a-string/permutations-s2.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
def get_permutations(w):
if len(w) <= 1:
return set([w]) # Return a set with a single string
smaller = get_permutations(w[1:])
perms = set() # Initialize perms as an empty set
for x in smaller:
for pos in range(0, len(x) + 1):
perm = x[:pos] + w[0] + x[pos:]
perms.add(perm)
return perms
print(get_permutations('cat'))
def get_permutations(w):
if len(w) <= 1:
return set([w]) # Return a set with a single string
smaller = get_permutations(w[1:])
perms = set() # Initialize perms as an empty set
for x in smaller:
for pos in range(0, len(x) + 1):
perm = x[:pos] + w[0] + x[pos:]
perms.add(perm)
return perms

print(get_permutations('cat'))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.