From 5e0837e51e819289cb583325dd4d798be4db87b6 Mon Sep 17 00:00:00 2001 From: Tero Paloheimo Date: Tue, 3 Oct 2017 21:59:39 +0300 Subject: [PATCH 1/2] Fix Travis config --- .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: From 5a6362ac3eed0bc794c7950b6a1bb9cc31256707 Mon Sep 17 00:00:00 2001 From: Tero Paloheimo Date: Tue, 3 Oct 2017 21:59:49 +0300 Subject: [PATCH 2/2] Complete the exercises --- src/predicates.clj | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/predicates.clj b/src/predicates.clj index 158b1ea..5ee60ad 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 [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 [arg] (and (pred1 arg) (pred2 arg)))) (defn pred-or [pred1 pred2] - :-) + (fn [arg] (or (pred1 arg) (pred2 arg)))) (defn whitespace? [character] (Character/isWhitespace character)) (defn blank? [string] - :-) + (or (zero? (count string)) + (every? whitespace? string))) (defn has-award? [book award] - :-) + (contains? (:awards book) award)) (defn HAS-ALL-THE-AWARDS? [book awards] - :-) + (every? (fn [award] (has-award? book award)) awards)) (defn my-some [pred a-seq] - :-) + (let [result (filter pred a-seq)] + (if result + (first (map pred result)) false))) (defn my-every? [pred a-seq] - :-) + (empty? (filter true? (map (complement pred) a-seq)))) (defn prime? [n] - :-) -;^^ + (let [pred #(zero? (mod n %))] + (not (some pred (range 2 n))))) + +;; ^^