isHittingTree(tree) uitgewerkt
[ker1415-1.git] / pl-files / hittingSetTree.pl
diff --git a/pl-files/hittingSetTree.pl b/pl-files/hittingSetTree.pl
new file mode 100644 (file)
index 0000000..925447c
--- /dev/null
@@ -0,0 +1,13 @@
+:- [diagnosis].\r
+\r
+isHittingSetTree(Tree) :-\r
+       isHittingSetTree2(Tree, []). %function to add variable for uniqueness checking\r
+\r
+isHittingSetTree2(leaf, _). %when end of branch has been reached\r
+isHittingSetTree2(node([], []), _). %when a node turns empty\r
+isHittingSetTree2(node([X|Xs], [Y|Ys]), Z) :-\r
+       not(member(X,Z)), %check if label has already been used up in the tree\r
+       append(Z, [X], Appended), %append label to list of checked labels\r
+       isHittingSetTree2(Y, Appended), %go into depth\r
+       isHittingSetTree2(node(Xs, Ys), Z). %go into width\r
+       
\ No newline at end of file