diff options
| author | Tyler Wardhaugh <tyler.wardhaugh@gmail.com> | 2022-04-16 16:17:31 -0700 |
|---|---|---|
| committer | Tyler Wardhaugh <tyler.wardhaugh@gmail.com> | 2022-04-16 16:17:31 -0700 |
| commit | 7724b02c881db2c18e9c6469105b50e67fae37aa (patch) | |
| tree | 08e71bfa92da180d379cf73cc50f4e517ca51daa | |
| parent | beaca38369cfb644a89bd47f7f6c8fc519963423 (diff) | |
| download | perlweeklychallenge-club-7724b02c881db2c18e9c6469105b50e67fae37aa.tar.gz perlweeklychallenge-club-7724b02c881db2c18e9c6469105b50e67fae37aa.tar.bz2 perlweeklychallenge-club-7724b02c881db2c18e9c6469105b50e67fae37aa.zip | |
Ch160 (Clojure): Task 1
| -rw-r--r-- | challenge-160/tyler-wardhaugh/clojure/src/c160/t1.clj | 23 | ||||
| -rw-r--r-- | challenge-160/tyler-wardhaugh/clojure/test/c160/t1_test.clj | 6 |
2 files changed, 25 insertions, 4 deletions
diff --git a/challenge-160/tyler-wardhaugh/clojure/src/c160/t1.clj b/challenge-160/tyler-wardhaugh/clojure/src/c160/t1.clj index 13729586c4..1b4f97aa75 100644 --- a/challenge-160/tyler-wardhaugh/clojure/src/c160/t1.clj +++ b/challenge-160/tyler-wardhaugh/clojure/src/c160/t1.clj @@ -2,11 +2,30 @@ (:require [clojure.edn :as edn] [clojure.pprint :refer [cl-format]])) -(def DEFAULT-INPUT []) +(def DEFAULT-INPUT [5]) + +(defn n->en + [n] + (cl-format nil "~r" n)) + +(defn magic-seq + [n] + (loop [n n + result [n]] + (let [len (-> n n->en count)] + (if (= len 4) + (conj result len) + (recur len (conj result len)))))) + +(defn spell + [n] + (->> (magic-seq n) + (partition 2 1) + (cl-format nil "~@(~:{~r is ~r, ~}four is magic.~)"))) (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)] - )) + (println (spell N)))) diff --git a/challenge-160/tyler-wardhaugh/clojure/test/c160/t1_test.clj b/challenge-160/tyler-wardhaugh/clojure/test/c160/t1_test.clj index 1685e245c9..b93e2c3a83 100644 --- a/challenge-160/tyler-wardhaugh/clojure/test/c160/t1_test.clj +++ b/challenge-160/tyler-wardhaugh/clojure/test/c160/t1_test.clj @@ -1,7 +1,9 @@ (ns c160.t1-test (:require [clojure.test :refer [deftest is testing]] - [c160.t1 :refer []])) + [c160.t1 :refer [spell]])) (deftest task-1 (testing "Task 1 produces the correct result" - )) + (is (= "Five is four, four is magic." (spell 5))) + (is (= "Seven is five, five is four, four is magic." (spell 7))) + (is (= "Six is three, three is five, five is four, four is magic." (spell 6))))) |
