Skip to content

Instantly share code, notes, and snippets.

@adamdavislee
Last active November 30, 2021 02:05
Show Gist options
  • Save adamdavislee/7d1396dd2cbf49c22d4054b405959d79 to your computer and use it in GitHub Desktop.
Save adamdavislee/7d1396dd2cbf49c22d4054b405959d79 to your computer and use it in GitHub Desktop.
(do (defn search-tree?* [tree]
(if (coll? tree)
(let [[root-node left-node right-node] (concat tree (cycle [nil]))]
(fn [] (and (->> [left-node root-node right-node]
(map #(if (coll? %) (first %) %))
(filter identity)
(apply <))
(search-tree?* left-node)
(search-tree?* right-node))))
true))
(def search-tree? (partial trampoline search-tree?*))
(search-tree? [3 [1 0 2] [4 nil [6 5]]])) ;; => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment