diff options
8 files changed, 85 insertions, 11 deletions
diff --git a/challenge-184/tyler-wardhaugh/clojure/README.md b/challenge-184/tyler-wardhaugh/clojure/README.md index f96186bfeb..ec30dd83a2 100644 --- a/challenge-184/tyler-wardhaugh/clojure/README.md +++ b/challenge-184/tyler-wardhaugh/clojure/README.md @@ -1,6 +1,6 @@ -# c183 +# c184 -The Weekly Challenge — #183 — Tyler Wardhaugh +The Weekly Challenge — #184 — Tyler Wardhaugh ## Usage @@ -17,12 +17,12 @@ Run Task #1: Run Task #2: - $ clojure -M:t2 D1 D2 + $ clojure -M:t2 N # ... or ... - $ bb run task-2 D1 D2 + $ bb run task-2 N # Alternatively, to run it via Babashka: - $ bb run task-2-bb D1 D2 + $ bb run task-2-bb N Run the project's tests (which are samples from the task descriptions): diff --git a/challenge-184/tyler-wardhaugh/clojure/bb.edn b/challenge-184/tyler-wardhaugh/clojure/bb.edn index 576e6bc671..8fe6a54fff 100644 --- a/challenge-184/tyler-wardhaugh/clojure/bb.edn +++ b/challenge-184/tyler-wardhaugh/clojure/bb.edn @@ -1,6 +1,6 @@ { :paths ["src" "resources"] - :deps {c183/c183 {:local/root "."}} + :deps {c184/c184 {:local/root "."}} :tasks { diff --git a/challenge-184/tyler-wardhaugh/clojure/build.clj b/challenge-184/tyler-wardhaugh/clojure/build.clj new file mode 100644 index 0000000000..4315e4decc --- /dev/null +++ b/challenge-184/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.c184/c184) +(def version "0.1.0-SNAPSHOT") +(def main 'c184.c184) + +(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-184/tyler-wardhaugh/clojure/deps.edn b/challenge-184/tyler-wardhaugh/clojure/deps.edn index fa24e59ef7..22bb4d30a6 100644 --- a/challenge-184/tyler-wardhaugh/clojure/deps.edn +++ b/challenge-184/tyler-wardhaugh/clojure/deps.edn @@ -1,10 +1,8 @@ {:paths ["src" "resources"] - :deps {org.clojure/clojure {:mvn/version "1.11.1"} - henryw374/cljc.java-time {:git/url "https://github.com/henryw374/cljc.java-time" - :git/sha "85d1501e8833bd731d4bce8ea73eb801528f24ee"}} + :deps {org.clojure/clojure {:mvn/version "1.11.1"}} :aliases - {:t1 {:main-opts ["-m" "c183.t1"]} - :t2 {:main-opts ["-m" "c183.t2"]} + {:t1 {:main-opts ["-m" "c184.t1"]} + :t2 {:main-opts ["-m" "c184.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-184/tyler-wardhaugh/clojure/src/c184/t1.clj b/challenge-184/tyler-wardhaugh/clojure/src/c184/t1.clj new file mode 100644 index 0000000000..e5498a780e --- /dev/null +++ b/challenge-184/tyler-wardhaugh/clojure/src/c184/t1.clj @@ -0,0 +1,15 @@ +(ns c184.t1 + (:require [clojure.edn :as edn])) + +(def DEFAULT-INPUT [["ab1234" "cd5678" "ef1342"]]) + +(defn add-seq-number + [coll] + (map-indexed (fn [i v] (format "%02d%s" i (subs v 2))) coll)) + +(defn -main + "Run Task 1 with a given input N, defaulting to the first example from the + task description." + [& args] + (let [[N] (or (some->> args (map edn/read-string)) DEFAULT-INPUT)] + (prn (add-seq-number N)))) diff --git a/challenge-184/tyler-wardhaugh/clojure/src/c184/t2.clj b/challenge-184/tyler-wardhaugh/clojure/src/c184/t2.clj new file mode 100644 index 0000000000..7ba2fe74fe --- /dev/null +++ b/challenge-184/tyler-wardhaugh/clojure/src/c184/t2.clj @@ -0,0 +1,24 @@ +(ns c184.t2 + (:require [clojure.edn :as edn])) + +(def DEFAULT-INPUT [["a 1 2 b 0" "3 c 4 d"]]) + +(def int-char? (set "0123456789")) +(def alpha-char? (set "abcdefghijklmnopqrstuvwxyz")) + +(defn split-array + [coll] + (let [xf (map (fn [s] [(keep #(when (int-char? %) (Character/digit % 10)) s) + (keep #(when (alpha-char? %) (str %)) s)])) + f (fn [[integers alphas] [i a]] + [(if (seq i) (conj integers i) integers) + (if (seq a) (conj alphas a) alphas)])] + (transduce xf (completing f) [[] []] coll))) + +(defn -main + "Run Task 2 with a given input N, defaulting to the first example from the + task description." + [& args] + (let [[N] (or (some->> args (map edn/read-string)) DEFAULT-INPUT) + [integers alphas] (split-array N)] + (println integers "and" (pr-str alphas)))) diff --git a/challenge-184/tyler-wardhaugh/clojure/test/c184/t1_test.clj b/challenge-184/tyler-wardhaugh/clojure/test/c184/t1_test.clj new file mode 100644 index 0000000000..0e72fc3b9a --- /dev/null +++ b/challenge-184/tyler-wardhaugh/clojure/test/c184/t1_test.clj @@ -0,0 +1,8 @@ +(ns c184.t1-test + (:require [clojure.test :refer [deftest is testing]] + [c184.t1 :refer [add-seq-number]])) + +(deftest task-1 + (testing "Task 1 produces the correct results" + (is (= (add-seq-number ["ab1234" "cd5678" "ef1342"]) ["001234" "015678" "021342"])) + (is (= (add-seq-number [ "pq1122" "rs3334"]) ["001122" "013334"])))) diff --git a/challenge-184/tyler-wardhaugh/clojure/test/c184/t2_test.clj b/challenge-184/tyler-wardhaugh/clojure/test/c184/t2_test.clj new file mode 100644 index 0000000000..03c73f9f2b --- /dev/null +++ b/challenge-184/tyler-wardhaugh/clojure/test/c184/t2_test.clj @@ -0,0 +1,10 @@ +(ns c184.t2-test + (:require [clojure.test :refer [deftest is testing]] + [c184.t2 :refer [split-array]])) + +(deftest task-2 + (testing "Task 2 produces the correct results" + (is (= (split-array ["a 1 2 b 0" "3 c 4 d"]) + [[[1 2 0] [3 4]] [["a" "b"] ["c" "d"]]])) + (is (= (split-array ["1 2" "p q r" "s 3" "4 5 t"]) + [[[1 2] [3] [4 5]] [["p" "q" "r"] ["s"] ["t"]]])))) |
