Skip to content

Instantly share code, notes, and snippets.

@LuisRBarreras
Created November 17, 2015 04:04
Show Gist options
  • Save LuisRBarreras/f901ff0b9e292ffd3675 to your computer and use it in GitHub Desktop.
Save LuisRBarreras/f901ff0b9e292ffd3675 to your computer and use it in GitHub Desktop.
import sys
def permutations(set_char, list_perm=None, path=None):
path = '' if path is None else path
list_perm = [] if list_perm is None else list_perm
if len(set_char) < 2:
return path+set_char[0]
for char in set_char:
result = permutations(
set_char=[x for x in set_char if x is not char],
list_perm=list_perm,
path=path+char
)
if type(result) is str:
list_perm.append(result)
return list_perm
def execute():
test_cases = open(sys.argv[1], 'r')
for test in test_cases:
set_char = list(test.strip())
set_char.sort()
print(','.join(permutations(set_char)))
test_cases.close()
if __name__ == '__main__':
execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment