Created
August 25, 2020 01:34
-
-
Save ndonolli/3281e5ca0233c19eac66ce88b42d04a4 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
(defn binary-search [target coll] | |
(loop [tree coll] | |
(let [idx (int (/ (count tree) 2)) | |
node (nth tree idx)] | |
(cond | |
(= target node) true | |
(= 1 (count tree)) false | |
(< target node) (recur (subvec tree 0 idx)) | |
(> target node) (recur (subvec tree idx (count tree))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment