Terse clojure code.
Mar. 28th, 2012 10:35 amAfter a post by
antilamer I tried to compose a clojure code that should definitely look better than written in Java. However my skills are still lacking, what I've got looks uglier and is nearly O(n^2) minus laziness.
![[livejournal.com profile]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
(defn find-ones [arr k]
(let [n (count arr)
sum (reduce + arr)
subvecs (fn [l] (map #(subvec arr % (+ l %)) (range (inc (- n l)))))
has-k? (fn [l] [l (reduce + (map #(if (<= k (reduce + %)) k 0) (subvecs l)))])]
(if (< sum k) Integer/MAX_VALUE
(first (first (filter #(> (last %) 0) (map has-k? (range k n))))))))