Last active
January 7, 2020 21:45
-
-
Save jleeothon/3b30fb21a4e2820ebfc1 to your computer and use it in GitHub Desktop.
Prolog: lowest common ancestor (LCA)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ancestor(A, B) :- parent(A, B). | |
ancestor(A, B) :- parent(X, B), ancestor(A, X). | |
lca(A, B, X) :- ancestor(X, A), ancestor(X, B). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This won't give you the lowest common ancestor, but the complete list of common ancestors.