diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-06-25 08:46:29 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-06-25 08:46:29 +0100 |
| commit | 6f4a137e34bc32c16b5749ee2858558412af83cf (patch) | |
| tree | 52d6f2ae1dcbb7f88b7c305cb1fe13f9bdc46570 | |
| parent | 74faf8bd5941620c2902102e9f3be28e2c8884c2 (diff) | |
| parent | 5bbf10b6c7085165fdcc193d1a24890d1657eed8 (diff) | |
| download | perlweeklychallenge-club-6f4a137e34bc32c16b5749ee2858558412af83cf.tar.gz perlweeklychallenge-club-6f4a137e34bc32c16b5749ee2858558412af83cf.tar.bz2 perlweeklychallenge-club-6f4a137e34bc32c16b5749ee2858558412af83cf.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
8 files changed, 85 insertions, 8 deletions
diff --git a/challenge-222/tyler-wardhaugh/clojure/README.md b/challenge-222/tyler-wardhaugh/clojure/README.md index ca9f7b247f..64cada0dfe 100644 --- a/challenge-222/tyler-wardhaugh/clojure/README.md +++ b/challenge-222/tyler-wardhaugh/clojure/README.md @@ -1,6 +1,6 @@ -# c219 +# c222 -The Weekly Challenge — #219 — Tyler Wardhaugh +The Weekly Challenge — #222 — Tyler Wardhaugh ## Usage @@ -17,12 +17,12 @@ Run Task #1: Run Task #2: - $ clojure -M:t2 COSTS DAYS + $ clojure -M:t2 COLL # ... or ... - $ bb run task-2 COSTS DAYS + $ bb run task-2 COLL # Alternatively, to run it via Babashka: - $ bb run task-2-bb COSTS DAYS + $ bb run task-2-bb COLL Run the project's tests (which are samples from the task descriptions): diff --git a/challenge-222/tyler-wardhaugh/clojure/bb.edn b/challenge-222/tyler-wardhaugh/clojure/bb.edn index f45b64fba7..8b760c46c9 100644 --- a/challenge-222/tyler-wardhaugh/clojure/bb.edn +++ b/challenge-222/tyler-wardhaugh/clojure/bb.edn @@ -1,6 +1,6 @@ { :paths ["src" "resources"] - :deps {c219/c219 {:local/root "."}} + :deps {c222/c222 {:local/root "."}} :tasks { diff --git a/challenge-222/tyler-wardhaugh/clojure/build.clj b/challenge-222/tyler-wardhaugh/clojure/build.clj new file mode 100644 index 0000000000..26151badc7 --- /dev/null +++ b/challenge-222/tyler-wardhaugh/clojure/build.clj @@ -0,0 +1,19 @@ +(ns build + (:refer-clojure :exclude [test]) + (:require [org.corfield.build :as bb])) + +(def lib 'net.clojars.c222/c222) +(def version "0.1.0-SNAPSHOT") +(def main 'c222.c222) + +(defn test "Run the tests." [opts] + (bb/run-tests opts)) + +(def clean bb/clean) + +(defn ci "Run the CI pipeline of tests (and build the uberjar)." [opts] + (-> opts + (assoc :lib lib :version version :main main) + (bb/run-tests) + (bb/clean) + (bb/uber))) diff --git a/challenge-222/tyler-wardhaugh/clojure/deps.edn b/challenge-222/tyler-wardhaugh/clojure/deps.edn index c8190a62c0..33e8bff6ca 100644 --- a/challenge-222/tyler-wardhaugh/clojure/deps.edn +++ b/challenge-222/tyler-wardhaugh/clojure/deps.edn @@ -3,8 +3,8 @@ clojure/math.numeric-tower {:git/url "https://github.com/clojure/math.numeric-tower" :git/sha "3e98b31da229d7d3a533f1cee0c509e9b349aa17"}} :aliases - {:t1 {:main-opts ["-m" "c219.t1"]} - :t2 {:main-opts ["-m" "c219.t2"]} + {:t1 {:main-opts ["-m" "c222.t1"]} + :t2 {:main-opts ["-m" "c222.t2"]} :build {:deps {io.github.seancorfield/build-clj {:git/tag "v0.8.3" :git/sha "7ac1f8d" ;; since we're building an app uberjar, we do not diff --git a/challenge-222/tyler-wardhaugh/clojure/src/c222/t1.clj b/challenge-222/tyler-wardhaugh/clojure/src/c222/t1.clj new file mode 100644 index 0000000000..e00c2d104f --- /dev/null +++ b/challenge-222/tyler-wardhaugh/clojure/src/c222/t1.clj @@ -0,0 +1,19 @@ +(ns c222.t1 + (:require + [clojure.edn :as edn])) + +(def DEFAULT-INPUT [[1 1 4 2 1 3]]) + +(defn matching-members + [coll] + (->> [coll (sort coll)] + (apply map vector) + (keep (fn [[a b]] (when (= a b) a))) + count)) + +(defn -main + "Run Task 1 with a given input COLL, defaulting to the first example from the + task description." + [& args] + (let [[coll] (or (some->> args (map edn/read-string)) DEFAULT-INPUT)] + (println (matching-members coll)))) diff --git a/challenge-222/tyler-wardhaugh/clojure/src/c222/t2.clj b/challenge-222/tyler-wardhaugh/clojure/src/c222/t2.clj new file mode 100644 index 0000000000..d6eec92df4 --- /dev/null +++ b/challenge-222/tyler-wardhaugh/clojure/src/c222/t2.clj @@ -0,0 +1,21 @@ +(ns c222.t2 + (:require + [clojure.edn :as edn])) + +(def DEFAULT-INPUT [[2 7 4 1 8 1]]) + +(defn last-member + [coll] + (loop [coll (shuffle coll)] + (let [len (count coll)] + (if (< 1 len) + (let [[a b & rest] coll] + (recur (if (= a b) rest (conj rest (- a b))))) + len)))) + +(defn -main + "Run Task 2 with a given input COLL, defaulting to the first example from the + task description." + [& args] + (let [[coll] (or (some->> args (map edn/read-string)) DEFAULT-INPUT)] + (println (last-member coll)))) diff --git a/challenge-222/tyler-wardhaugh/clojure/test/c222/t1_test.clj b/challenge-222/tyler-wardhaugh/clojure/test/c222/t1_test.clj new file mode 100644 index 0000000000..a391953c71 --- /dev/null +++ b/challenge-222/tyler-wardhaugh/clojure/test/c222/t1_test.clj @@ -0,0 +1,9 @@ +(ns c222.t1-test + (:require [clojure.test :refer [deftest is testing]] + [c222.t1 :refer [matching-members]])) + +(deftest task-1 + (testing "Task 1 produces the correct results from examples in the description" + (is (= 3 (matching-members [1 1 4 2 1 3]))) + (is (= 0 (matching-members [5 1 2 3 4]))) + (is (= 5 (matching-members [1 2 3 4 5]))))) diff --git a/challenge-222/tyler-wardhaugh/clojure/test/c222/t2_test.clj b/challenge-222/tyler-wardhaugh/clojure/test/c222/t2_test.clj new file mode 100644 index 0000000000..4e907c8d84 --- /dev/null +++ b/challenge-222/tyler-wardhaugh/clojure/test/c222/t2_test.clj @@ -0,0 +1,9 @@ +(ns c222.t2-test + (:require [clojure.test :refer [deftest is testing]] + [c222.t2 :refer [last-member]])) + +(deftest task-1 + (testing "Task 2 produces the correct results from examples in the description" + (is (= 1 (last-member [2 7 4 1 8 1]))) + (is (= 1 (last-member [1]))) + (is (= 0 (last-member [1 1]))))) |
