From e3bf4c2feac820c90e16c5a92b3b7c6664be73ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jere=20Hel=C3=A9n?= Date: Thu, 5 Oct 2017 22:39:16 +0300 Subject: [PATCH 1/2] Halfway there. --- src/one_function_to_rule_them_all.clj | 52 +++++++++++++++++++-------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/src/one_function_to_rule_them_all.clj b/src/one_function_to_rule_them_all.clj index 6844d99..ce91356 100644 --- a/src/one_function_to_rule_them_all.clj +++ b/src/one_function_to_rule_them_all.clj @@ -1,19 +1,36 @@ (ns one-function-to-rule-them-all) (defn concat-elements [a-seq] - :-) + (reduce concat [] a-seq)) (defn str-cat [a-seq] - :-) + (if (empty? a-seq) + "" + (reduce (fn [b-seq x] (str b-seq " " x)) a-seq))) + +(defn my-interpose2 [x a-seq] + (if (empty? a-seq) + [] + (reduce (fn [b-seq y] (conj b-seq x y)) a-seq))) (defn my-interpose [x a-seq] - [:-]) + (cond + (empty? a-seq) + [] + (= 1 (count a-seq)) + a-seq + :else + (reduce (fn [b-seq y] (conj b-seq x y)) a-seq))) (defn my-count [a-seq] - :-) + (let [counter (fn [count e] + (if e (inc count) count))] + (reduce counter 0 a-seq))) (defn my-reverse [a-seq] - [:-]) + (if (empty? a-seq) + [] + (reduce cons a-seq))) (defn min-max-element [a-seq] [:-]) @@ -27,17 +44,24 @@ (defn parity [a-seq] [:-]) -(defn minus [x] - :-) +(defn minus + ([x] (* -1 x)) + ([x y] (- x y))) -(defn count-params [x] - :-) +(defn count-params [& more] + (count more)) -(defn my-* [x] - :-) +(defn my-* + ([] 1) + ([x] x) + ([x y] (* x y)) + ([x y & more] (reduce * (* x y) more))) -(defn pred-and [x] - (fn [x] :-)) +(defn pred-and + ([] (fn [a] a)) + ([x] (fn [a] (x a))) + ([x y] (fn [a] (and (x a) (y a)))) + ([x y & more] (reduce (fn [a] (and (x a) (y a))) more))) (defn my-map [f a-seq] - [:-]) \ No newline at end of file + [:-]) From 6bd45eed2fcb5fd531f39d443d934af0e151faf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jere=20Hel=C3=A9n?= Date: Thu, 5 Oct 2017 22:48:10 +0300 Subject: [PATCH 2/2] travis.yml fixed --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 455f3c0..4eb6b50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: clojure +dist: precise lein: lein2 script: lein2 midje :config .midje-grading-config.clj jdk: