Skip to content

Instantly share code, notes, and snippets.

@ashkantaravati
Created December 16, 2018 16:44
Show Gist options
  • Save ashkantaravati/e12505c53d09df4e8d526d0aaf452cff to your computer and use it in GitHub Desktop.
Save ashkantaravati/e12505c53d09df4e8d526d0aaf452cff to your computer and use it in GitHub Desktop.
'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