Sha256: f9fe7321b89c35b383b76fa68585b6debd0f54b46844c843e227bcd1580a4bf2
Contents?: true
Size: 460 Bytes
Versions: 396
Compression:
Stored size: 460 Bytes
Contents
(ns binary-search) (defn middle [alist] (-> alist (count) (quot 2))) (defn search-for [elem alist] (let [middle (middle alist) cur-elem (nth alist middle)] (cond (= cur-elem elem) middle (or (= middle (count alist)) (zero? middle)) (throw (Exception. (format "%s not found in list" elem))) (< cur-elem elem) (+ middle (search-for elem (drop middle alist))) (> cur-elem elem) (search-for elem (take middle alist)))))
Version data entries
396 entries across 396 versions & 1 rubygems