Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- permutations = []
- letters = ['a','b','c']
- def find_permutations(config):
- successors = get_successors(config)
- for successor in successors:
- if (len(successor) == 3):
- permutations.append(successor)
- find_permutations(successor) # still find the successors
- def get_successors(config):
- successors = []
- for letter in letters:
- if (letter not in config):
- successors.append(config+letter)
- return successors
- ##other solution:
- def backtracking(config, options):
- if len(config) == len(options): # add to array
- permutations.append(config[:])
- else:
- for option in options: # get the sucessors and backtrack them
- if option in config:
- continue
- config.append(option)
- backtracking(config, options)
- config.pop() # for new config
- # run
- backtracking([], letters)
- find_permutations('')
- print(permutations)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement