Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active January 3, 2016 19:08
Show Gist options
  • Save rightfold/6ec5cb7c18c0050ba403 to your computer and use it in GitHub Desktop.
Save rightfold/6ec5cb7c18c0050ba403 to your computer and use it in GitHub Desktop.
(defn bsearch [xs cmp]
(if (empty? xs)
nil
(let [[as bs] (split-at (quot (count xs) 2) xs)
res (cmp (first bs))]
(cond
(= res 0) (first bs)
(< res 0) (recur as cmp)
(> res 0) (recur bs cmp)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment