Hey,
Not sure if this is the right place for this - but I just wrote my
first function in Clojure and wanted to make sure I am on the right
track idiomatically and making full use of the language etc. I have
been able to build/run and unit test this so that's all fine. Take a
look at the below and let me know if you have any suggestions.
Thanks in advance!
Brody
(defn binary-search
"Search sorted list for target using binary search technique"
([m_list target]
(if (empty? m_list)
false
(binary-search m_list 0 (- (count m_list) 1) target))
)
([m_list m_left m_right target]
(let [gap (- m_right m_left)]
(if (>= 0 gap)
(if (== (nth m_list m_left) target)
(nth m_list m_left)
false
)
(let [middle (+ m_left (quot gap 2))]
(if (== (nth m_list middle) target)
(nth m_list middle)
(if (< target (nth m_list middle))
(recur m_list m_left (- middle 1) target)
(recur m_list (+ middle 1) m_right target)
)
)
)
)
)
)
)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en