From 6d2eabc4c0e1525994f261d5c0c4e08e98302bee Mon Sep 17 00:00:00 2001 From: Jani-Matti Tirkkonen Date: Mon, 18 Feb 2019 09:04:18 +0200 Subject: [PATCH 1/2] solve all the exercises --- src/predicates.clj | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/predicates.clj b/src/predicates.clj index 158b1ea..0db8562 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 greater-than [n] + (fn [k] (> k n))) (defn equal-to [n] - :-) + (fn [k] (= 0 (compare k n)))) + +(defn key->predicate [a-key] + (fn [a-map] (contains? a-map a-key))) (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] (true? (or (pred1 x) (pred2 x))))) (defn whitespace? [character] (Character/isWhitespace character)) (defn blank? [string] - :-) + (or (every? whitespace? string) + (empty? string) + (nil? string))) (defn has-award? [book award] - :-) + (contains? (book :awards) award)) (defn HAS-ALL-THE-AWARDS? [book awards] - :-) + (every? #(has-award? book %) awards)) (defn my-some [pred a-seq] - :-) + (first (filter #(not (false? %)) (map pred a-seq)))) (defn my-every? [pred a-seq] - :-) + (= (count a-seq) (count (filter #(not (false? %)) (map pred a-seq))))) (defn prime? [n] - :-) + (let [divisible-by? (fn [k] (= 0 (mod n k)))] + (not (some divisible-by? (range 2 n))))) ;^^ From 3a05a3be608afd0b19c619289fd2a652f833cf08 Mon Sep 17 00:00:00 2001 From: Jani-Matti Tirkkonen Date: Thu, 30 May 2019 14:49:59 +0300 Subject: [PATCH 2/2] fix travis build --- .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: