Skip to content

Instantly share code, notes, and snippets.

View halfprogrammer's full-sized avatar

Arun Kumar Rajan halfprogrammer

View GitHub Profile
(defn find-coll [max-sum acoll]
(if (empty? acoll)
[() max-sum]
(loop [max-sum max-sum
cur ()
coll acoll]
(cond (< max-sum 0) [(list* cur) -1]
(nil? (seq coll)) [(list* cur) max-sum]
(and (number? (first coll)) (> (first coll) max-sum)) [(concat () cur) -1]
(number? (first coll)) (recur (- max-sum (first coll))
@halfprogrammer
halfprogrammer / function-keyword.clj
Created June 14, 2011 17:35
Keywords as function parameters in clojure?
(defn my-exists1? [lst obj & {:keys [testfn] :or {testfn =}}]
(when lst
(if (testfn (first lst) obj)
lst
(recur (next lst) obj testfn))))
(my-exists1? '((1 2) (3 4) (5 6)) 3 :testfn #(= (first %1) %2))
=> nil
(defn my-exists2? [lst obj testfn]
(when lst