Constructing all subsets

Algorithm

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

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

def process_solution(self, current_answer, kth, info):
print([info[idx] for idx, val in enumerate(current_answer) if val])

def generate_candidates(self, current_answer, kth, info):
return [True, False]

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

# test case
Subsets().all_subsets([1,2,3]))