Created
January 11, 2021 15:28
-
-
Save corehello/94bc2766ac60b984782132ae60944f66 to your computer and use it in GitHub Desktop.
string permutation
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
def perm(string): | |
if len(string) <= 1: | |
return [string] | |
return [i+j for idx,i in enumerate(string) | |
for j in perm(string[0:idx] + string[idx+1:])] | |
if __name__ == "__main__": | |
TCs = [ | |
("a", ["a"]), | |
("ao", ["ao", "oa"]) | |
] | |
for TC in TCs: | |
if perm(TC[0]) == TC[1]: | |
print("SUCCEED TC: %s" % TC[0]) | |
else: | |
print("FAILED TC: %s" % TC[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment