From f340002ad0fe1889335a1ae9b9aa6a9c8f87fb94 Mon Sep 17 00:00:00 2001 From: Liao Ke Date: Mon, 14 Aug 2017 17:22:00 +0300 Subject: [PATCH 1/2] from ke --- src/predicates.clj | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/predicates.clj b/src/predicates.clj index 158b1ea..f860dc4 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -1,41 +1,46 @@ (ns predicates) (defn sum-f [f g x] - :-) + (+ (f x) (g x))) (defn less-than [n] - :-) + (fn [x] (< x n))) (defn equal-to [n] - :-) + (fn [x] (== x 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? (:awards book) award)) (defn HAS-ALL-THE-AWARDS? [book awards] - :-) + (let [helper (fn [x] (has-award? book x))] + (every? helper awards))) (defn my-some [pred a-seq] - :-) + (let [filtered (filter pred a-seq)] + (if (> (count filtered) 0) (first (map pred filtered)) false))) (defn my-every? [pred a-seq] - :-) + (let [filtered (filter pred a-seq)] + (== (count a-seq) (count filtered)))) (defn prime? [n] - :-) -;^^ + (let [pred (fn [x] (== (mod n x) 0))] + (not (some pred (range 2 n))))) + + ;^__^ From e7f532681361ae61b89562dcaa5cd12afa2c245a Mon Sep 17 00:00:00 2001 From: Liao Ke Date: Mon, 14 Aug 2017 17:28:02 +0300 Subject: [PATCH 2/2] from ke --- .travis.yml | 4 ++-- src/predicates.clj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 455f3c0..45c29f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: clojure -lein: lein2 -script: lein2 midje :config .midje-grading-config.clj +lein: lein +script: lein midje :config .midje-grading-config.clj jdk: - openjdk7 notifications: diff --git a/src/predicates.clj b/src/predicates.clj index f860dc4..89ca20b 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -43,4 +43,4 @@ (let [pred (fn [x] (== (mod n x) 0))] (not (some pred (range 2 n))))) - ;^__^ + ;^^