From 793e9d04936f261d1657f6c03ed8f53e390b555d Mon Sep 17 00:00:00 2001 From: rkelkka Date: Sun, 14 Oct 2018 21:22:21 +0300 Subject: [PATCH 01/11] Fix travis build script lein cmd --- .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 ec53ba291c2a53d22f655d00b34825b1f43dcc72 Mon Sep 17 00:00:00 2001 From: rkelkka Date: Sun, 14 Oct 2018 21:22:35 +0300 Subject: [PATCH 02/11] sum-f --- src/predicates.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/predicates.clj b/src/predicates.clj index 158b1ea..5e17572 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -1,7 +1,7 @@ (ns predicates) (defn sum-f [f g x] - :-) + (+ (f x) (g x))) (defn less-than [n] :-) From c94eadc4d93a91f525afbb03dccbfae62ff87b69 Mon Sep 17 00:00:00 2001 From: rkelkka Date: Sat, 27 Oct 2018 13:06:44 +0300 Subject: [PATCH 03/11] less-than, eequal --- src/predicates.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/predicates.clj b/src/predicates.clj index 5e17572..b20166e 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -4,10 +4,10 @@ (+ (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] :-) From 983987057e0537d0844e2287758a8952bf9b5ab7 Mon Sep 17 00:00:00 2001 From: rkelkka Date: Sat, 27 Oct 2018 14:23:44 +0300 Subject: [PATCH 04/11] set->predicate --- src/predicates.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/predicates.clj b/src/predicates.clj index b20166e..d4338c9 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -10,7 +10,7 @@ (fn [k] (== k n))) (defn set->predicate [a-set] - :-) + (fn [x] (contains? a-set x))) (defn pred-and [pred1 pred2] :-) From 510866f5f3593584ba2978a3a864fe0dbb6a51f3 Mon Sep 17 00:00:00 2001 From: rkelkka Date: Sat, 27 Oct 2018 14:34:10 +0300 Subject: [PATCH 05/11] pred-and, pred-or --- src/predicates.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/predicates.clj b/src/predicates.clj index d4338c9..1c27cde 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -13,10 +13,10 @@ (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)) From 5c1824f7042df4974c0580054bda3df4d787a544 Mon Sep 17 00:00:00 2001 From: rkelkka Date: Sat, 27 Oct 2018 14:47:30 +0300 Subject: [PATCH 06/11] blank? --- src/predicates.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/predicates.clj b/src/predicates.clj index 1c27cde..ca51fb4 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -22,7 +22,7 @@ (Character/isWhitespace character)) (defn blank? [string] - :-) + (every? whitespace? string)) (defn has-award? [book award] :-) From 6a853d5b1e0dd904b3fa507acce5ee753ed0ab8a Mon Sep 17 00:00:00 2001 From: rkelkka Date: Sat, 27 Oct 2018 15:01:49 +0300 Subject: [PATCH 07/11] has-award? --- src/predicates.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/predicates.clj b/src/predicates.clj index ca51fb4..150e219 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -25,7 +25,7 @@ (every? whitespace? string)) (defn has-award? [book award] - :-) + (contains? (:awards book) award)) (defn HAS-ALL-THE-AWARDS? [book awards] :-) From 5aff35aa39f81b4fb9fafa58fd46ffd6ba72027a Mon Sep 17 00:00:00 2001 From: rkelkka Date: Sat, 27 Oct 2018 15:18:03 +0300 Subject: [PATCH 08/11] has all the awards? --- src/predicates.clj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/predicates.clj b/src/predicates.clj index 150e219..dc1af8a 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -27,8 +27,11 @@ (defn has-award? [book award] (contains? (:awards book) award)) +(defn has-award-pred [book] + (fn [award] (has-award? book award))) + (defn HAS-ALL-THE-AWARDS? [book awards] - :-) + (every? (has-award-pred book) awards)) (defn my-some [pred a-seq] :-) From eb61921d953b0ca057c56ed2cd91e139b8403d5e Mon Sep 17 00:00:00 2001 From: rkelkka Date: Sat, 27 Oct 2018 15:35:35 +0300 Subject: [PATCH 09/11] my-some --- src/predicates.clj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/predicates.clj b/src/predicates.clj index dc1af8a..00eef2b 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -34,7 +34,9 @@ (every? (has-award-pred book) awards)) (defn my-some [pred a-seq] - :-) + (let [matching (filter pred a-seq)] + (if (= 0 (count matching)) false (pred (first matching))))) + (defn my-every? [pred a-seq] :-) From e1d84ff4974be7e68af8c7e4843040b1996766d9 Mon Sep 17 00:00:00 2001 From: rkelkka Date: Sat, 27 Oct 2018 15:45:49 +0300 Subject: [PATCH 10/11] my-every? --- src/predicates.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/predicates.clj b/src/predicates.clj index 00eef2b..be965bf 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -39,7 +39,7 @@ (defn my-every? [pred a-seq] - :-) + (= (filter pred a-seq) a-seq)) (defn prime? [n] :-) From 42ab2c55a2acee356dbfdd367ff62af0d2ebceb8 Mon Sep 17 00:00:00 2001 From: rkelkka Date: Sat, 27 Oct 2018 15:55:32 +0300 Subject: [PATCH 11/11] prime? --- src/predicates.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/predicates.clj b/src/predicates.clj index be965bf..dd53242 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -42,5 +42,6 @@ (= (filter pred a-seq) a-seq)) (defn prime? [n] - :-) + (let [pred (fn [x] (zero? (mod n x)))] + (not (some pred (range 2 n))))) ;^^