Last active
November 30, 2021 02:05
-
-
Save adamdavislee/7d1396dd2cbf49c22d4054b405959d79 to your computer and use it in GitHub Desktop.
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
(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