Created
August 23, 2019 23:32
-
-
Save miniharryc/59d072369b2323c226330c2a4e288585 to your computer and use it in GitHub Desktop.
Code Kata1 in Clojure
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 _midpoint [vec] | |
(quot (+ (.start vec) (.end vec)) 2)) | |
(defn _chop [item list] | |
(cond | |
(empty? list) -1 | |
(= 1 (count list) ) (if (= item (first list)) (.start list) -1) | |
:else (let [mid (_midpoint list)] | |
(let [val (get (.v list) mid)] | |
(cond | |
(= item val) mid | |
(< item val) (_chop item (subvec list (.start list) mid)) | |
(> item val) (_chop item (subvec list (inc mid)))) | |
)))) | |
(defn chop [item list] ( | |
_chop item (subvec list 0))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
passes all these tests: