#95
To Tree, or not to Tree
 

Difficulty:Easy
Topics:trees


Write a predicate which checks whether or not a given sequence represents a binary tree. Each node in the tree must have a value, a left child, and a right child.
test not run
(= (__ '(:a (:b nil nil) nil))
   true)
test not run
(= (__ '(:a (:b nil nil)))
   false)
test not run
(= (__ [1 nil [2 [3 nil nil] [4 nil nil]]])
   true)
test not run
(= (__ [1 [2 nil nil] [3 nil nil] [4 nil nil]])
   false)
test not run
(= (__ [1 [2 [3 [4 nil nil] nil] nil] nil])
   true)
test not run
(= (__ [1 [2 [3 [4 false nil] nil] nil] nil])
   false)
test not run
(= (__ '(:a nil ()))
   false)


Code which fills in the blank: