From 040805cc2a9abdfffcfde35fcc27a77e02367741 Mon Sep 17 00:00:00 2001 From: Rob Doster Date: Wed, 7 Nov 2018 07:47:41 -0500 Subject: [PATCH] All excercises done --- .gitignore | 1 + src/predicates.clj | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 69ab9db..a92d062 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /checkouts /.lein-deps-sum /.lein-plugins +/bin/ diff --git a/src/predicates.clj b/src/predicates.clj index 158b1ea..5398b4c 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -1,41 +1,43 @@ (ns predicates) (defn sum-f [f g x] - :-) + (+ (f x) (g x))) (defn less-than [n] - :-) + (fn [k] (< k n))) (defn equal-to [n] - :-) + (fn [k] (== k n))) (defn set->predicate [a-set] - :-) + (fn [x] (contains? a-set x))) (defn pred-and [pred1 pred2] - :-) + (fn [x] (and (pred1 x) (pred2 x)))) (defn pred-or [pred1 pred2] - :-) + (fn [x] (or (pred1 x) (pred2 x)))) (defn whitespace? [character] (Character/isWhitespace character)) (defn blank? [string] - :-) + (every? whitespace? string)) (defn has-award? [book award] - :-) + (contains? (book :awards) award)) (defn HAS-ALL-THE-AWARDS? [book awards] - :-) + (every? (fn [award] (has-award? book award)) awards)) (defn my-some [pred a-seq] - :-) + (first (map pred (filter pred a-seq)))) (defn my-every? [pred a-seq] - :-) + (empty? (filter (complement pred) a-seq))) (defn prime? [n] - :-) + (let [pred (fn [fact] (= 0 (mod n fact)))] + (not (some pred (range 2 (+ 1 (/ n 2))))))) + ;^^