diff options
| author | Tyler Wardhaugh <tyler.wardhaugh@gmail.com> | 2020-09-08 18:17:08 -0700 |
|---|---|---|
| committer | Tyler Wardhaugh <tyler.wardhaugh@gmail.com> | 2020-09-09 11:05:17 -0700 |
| commit | 52ea135482c4af63a7c35414b24df8d337996303 (patch) | |
| tree | d0b023127fd1675a55b6f0107fb3217ff3271be6 | |
| parent | 1c207790109f9ebe3d71516e1aefe62c3d6da8ac (diff) | |
| download | perlweeklychallenge-club-52ea135482c4af63a7c35414b24df8d337996303.tar.gz perlweeklychallenge-club-52ea135482c4af63a7c35414b24df8d337996303.tar.bz2 perlweeklychallenge-club-52ea135482c4af63a7c35414b24df8d337996303.zip | |
Task 2
| -rw-r--r-- | challenge-073/tyler-wardhaugh/clojure/src/tw/weekly/ch_2.clj | 23 | ||||
| -rw-r--r-- | challenge-073/tyler-wardhaugh/clojure/test/tw/weekly/c73_test.clj | 9 |
2 files changed, 25 insertions, 7 deletions
diff --git a/challenge-073/tyler-wardhaugh/clojure/src/tw/weekly/ch_2.clj b/challenge-073/tyler-wardhaugh/clojure/src/tw/weekly/ch_2.clj index f30d48346d..10ae923c08 100644 --- a/challenge-073/tyler-wardhaugh/clojure/src/tw/weekly/ch_2.clj +++ b/challenge-073/tyler-wardhaugh/clojure/src/tw/weekly/ch_2.clj @@ -1,8 +1,23 @@ (ns tw.weekly.ch-2 + (:require [clojure.pprint :refer [cl-format]]) (:require [clojure.edn :as edn])) -(defn -main - "" +(defn smallest-neighbor + "Find the smallest neighbor over a sequence, returning 0 when none is found." + [coll] + (let [min-or-zero (fn [coll] + (let [m (apply min coll)] + (if (< m (peek coll)) m 0)))] + (->> coll + (reductions conj []) + (drop 1) + (map min-or-zero)))) + + + (defn -main + "Run Task 2 a list of integers (A), defaulting to the example given in the task description." [& args] - (let [] - )) + (let [A (or (some->> args (map edn/read-string)) [7 8 3 12 10])] + (cl-format true "~10a: (~{~a~^ ~})~%~10a: (~{~a~^ ~})~%" + "Input" A + "Output" (smallest-neighbor A)))) diff --git a/challenge-073/tyler-wardhaugh/clojure/test/tw/weekly/c73_test.clj b/challenge-073/tyler-wardhaugh/clojure/test/tw/weekly/c73_test.clj index f3228886bb..37499e014c 100644 --- a/challenge-073/tyler-wardhaugh/clojure/test/tw/weekly/c73_test.clj +++ b/challenge-073/tyler-wardhaugh/clojure/test/tw/weekly/c73_test.clj @@ -1,7 +1,7 @@ (ns tw.weekly.c73-test - (:require [clojure.test :refer [are deftest is testing with-test]] + (:require [clojure.test :refer [are deftest testing]] [tw.weekly.ch-1 :refer [sliding-min]] - [tw.weekly.ch-2 :refer []])) + [tw.weekly.ch-2 :refer [smallest-neighbor]])) (deftest ch-1 (testing "Task 1" @@ -11,4 +11,7 @@ (deftest ch-2 (testing "Task 2" - )) + (are [input output] (= (smallest-neighbor input) output) + (list 7 8 3 12 10) (list 0 7 0 3 3) + (list 4 6 5) (list 0 4 4) + ))) |
