Created
November 17, 2015 04:04
-
-
Save LuisRBarreras/f901ff0b9e292ffd3675 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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