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 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 |
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 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)) |