Advertisement
Shinmera

Cream Lisp: Find Common Ancestor

Jun 15th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.55 KB | None | 0 0
  1. (defnodelistfun ancestor working-nodes ()
  2.   "Find the common ancestor of all elements."
  3.   (loop with parentlists = (loop for node in working-nodes
  4.                               collect (reverse (nodefun-parents node)))
  5.      for i = 0 then (1+ i)
  6.      for prevparents = NIL then parents
  7.      for parents = (loop for list in parentlists for el = (nth i list) if el collect el)
  8.      until (or (not (every #'eql (list (first parents)) parents))
  9.                (not (= (length parents) (length parentlists))))
  10.      finally (return (list (first prevparents)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement