From 0fa85e5d53715ee21019c7c364ab58af5fc12b8e Mon Sep 17 00:00:00 2001 From: Han Lin Date: Thu, 27 Jul 2017 20:43:20 +0200 Subject: [PATCH 1/4] first commit --- src/predicates.clj | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/predicates.clj b/src/predicates.clj index 158b1ea..58b301c 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -1,41 +1,50 @@ (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] - :-) + (cond + (== (count string) 0) true + (every? whitespace? string) true + :else false)) (defn has-award? [book award] - :-) + (let [x (:awards book)] + (if(contains? x award) true false))) (defn HAS-ALL-THE-AWARDS? [book awards] - :-) + (let [x (:awards book)] + (every? x awards))) (defn my-some [pred a-seq] - :-) + (if(== (count (filter pred a-seq)) 0) false (first (filter boolean (map pred a-seq))))) (defn my-every? [pred a-seq] - :-) + (cond + (empty? a-seq) true + (== (count (filter pred a-seq)) (count a-seq)) true + :else false)) (defn prime? [n] - :-) + (let [f1 (fn [x] (mod n x))] + (if(== (count (filter (equal-to 0) (map f1 (range 2 n)))) 0) true false))) ;^^ From 0fe8a4fbb7eb76b67b1754aadca8f0d6a4f01cb6 Mon Sep 17 00:00:00 2001 From: Han Lin Date: Thu, 27 Jul 2017 21:04:48 +0200 Subject: [PATCH 2/4] third commit --- src/predicates.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/predicates.clj b/src/predicates.clj index 58b301c..8b9a8c0 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -47,4 +47,4 @@ (defn prime? [n] (let [f1 (fn [x] (mod n x))] (if(== (count (filter (equal-to 0) (map f1 (range 2 n)))) 0) true false))) -;^^ +;^^^ From b4b90eb1157c8bd4673fc28f9aff657beb73a2b7 Mon Sep 17 00:00:00 2001 From: Han Lin Date: Thu, 27 Jul 2017 21:37:07 +0200 Subject: [PATCH 3/4] again commit --- src/predicates.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/predicates.clj b/src/predicates.clj index 8b9a8c0..618f1cf 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -45,6 +45,6 @@ :else false)) (defn prime? [n] - (let [f1 (fn [x] (mod n x))] - (if(== (count (filter (equal-to 0) (map f1 (range 2 n)))) 0) true false))) -;^^^ + (let [f1 (fn [x] (== (mod n x) 0))] + (not (some f1 (range 2 n))))) +;^^ From 2baba2a1998e40d3580a4bbcd262863375eee186 Mon Sep 17 00:00:00 2001 From: Han Lin Date: Thu, 27 Jul 2017 21:50:42 +0200 Subject: [PATCH 4/4] new commit --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 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: