aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-160/tyler-wardhaugh/clojure/src/c160/t1.clj23
-rw-r--r--challenge-160/tyler-wardhaugh/clojure/test/c160/t1_test.clj6
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)))))