2 %Function to add variable
for uniqueness checking
.
3 isHittingSetTree
(Tree
) :-
4 isHittingSetTree2
(Tree
, []).
6 %When the end of branch has been reached
.
7 isHittingSetTree2
(leaf
, _
).
8 %When a node turns empty
.
9 isHittingSetTree2
(node
([], []), _
).
10 %When a node isn
't empty.
11 isHittingSetTree2(node([CurLabel|Labels], [CurChild|Children]), VisitedLabels) :-
12 %Check if label has already been used up in the tree.
13 not(member(CurLabel,VisitedLabels)),
14 %Append label to list of checked labels
15 append(VisitedLabels, [CurLabel], UpdatedVisitedLabels),
16 %Recursively search into depth of branch.
17 isHittingSetTree2(CurChild, Appended),
18 %Recursively search into width of node.
19 isHittingSetTree2(node(Labels, UpdatedVisitedLabels), VisitedLabels).
20 %If there are more or less labels then children, the tree will not match and
21 %the function will rightfully report false.