Created
December 16, 2018 16:44
-
-
Save ashkantaravati/e12505c53d09df4e8d526d0aaf452cff to your computer and use it in GitHub Desktop.
This file contains 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
'permutation program' | |
def permute(data, size, picked): | |
'recursive function' | |
if not size: | |
res = ''.join(picked) | |
print(res) | |
else: | |
# print(data) | |
for element in data: | |
new_picked = list(picked) | |
new_picked.append(element) # we need a copy of element | |
new_data = list(data) | |
new_data.remove(element) | |
permute(new_data, size-1, new_picked) | |
def main(): | |
'main function' | |
input_string = 'abcdefgh' | |
input_data = list(input_string) | |
permute(input_data, 3, []) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment