Constructing all permutations

Algorithm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from combinatorial_search import Backtracking

class Permutation(Backtracking):
def is_a_solution(self, current_answer, kth, info):
return kth == len(info)

def generate_candidates(self, current_answer, kth, info):
return [candidate for candidate in info if candidate not in current_answer]

def process_solution(self, current_answer, kth, info):
print(current_answer)

def permute(self, info):
self.backtrack([], 0, info)

# test case
Permutation().permute([1,2,3])

Reference