reorganize dir

Signed-off-by: Mia Steinkirch <mia.steinkirch@gmail.com>
This commit is contained in:
Mia Steinkirch 2019-10-11 04:29:17 -07:00
parent 1b6f705e7c
commit a8e71c50db
276 changed files with 23954 additions and 0 deletions

View file

@ -0,0 +1,31 @@
#!/usr/bin/env python
__author__ = "bt3"
def permutation(array):
if len(array) < 2:
return [array]
result = []
for index, letter in enumerate(array):
new_array = array[:index] + array[index+1:]
for perm in permutation(new_array):
result.append(letter + perm)
return result
if __name__ == '__main__':
word = 'abc'
result = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
assert(permutation(word) == result)
word = ''
result = ['']
assert(permutation(word) == result)
word = 'a'
result = ['a']
assert(permutation(word) == result)