aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-193/tyler-wardhaugh/clojure/README.md4
-rw-r--r--challenge-193/tyler-wardhaugh/clojure/bb.edn2
-rw-r--r--challenge-193/tyler-wardhaugh/clojure/build.clj19
-rw-r--r--challenge-193/tyler-wardhaugh/clojure/deps.edn4
-rw-r--r--challenge-193/tyler-wardhaugh/clojure/src/c193/t1.clj17
-rw-r--r--challenge-193/tyler-wardhaugh/clojure/src/c193/t2.clj25
-rw-r--r--challenge-193/tyler-wardhaugh/clojure/test/c193/t1_test.clj9
-rw-r--r--challenge-193/tyler-wardhaugh/clojure/test/c193/t2_test.clj8
8 files changed, 83 insertions, 5 deletions
diff --git a/challenge-193/tyler-wardhaugh/clojure/README.md b/challenge-193/tyler-wardhaugh/clojure/README.md
index 56385ea8ab..063cccb9e8 100644
--- a/challenge-193/tyler-wardhaugh/clojure/README.md
+++ b/challenge-193/tyler-wardhaugh/clojure/README.md
@@ -1,6 +1,6 @@
-# c191
+# c193
-The Weekly Challenge — #191 — Tyler Wardhaugh
+The Weekly Challenge — #193 — Tyler Wardhaugh
## Usage
diff --git a/challenge-193/tyler-wardhaugh/clojure/bb.edn b/challenge-193/tyler-wardhaugh/clojure/bb.edn
index ee227e4c53..885507f3e5 100644
--- a/challenge-193/tyler-wardhaugh/clojure/bb.edn
+++ b/challenge-193/tyler-wardhaugh/clojure/bb.edn
@@ -1,6 +1,6 @@
{
:paths ["src" "resources"]
- :deps {c191/c191 {:local/root "."}}
+ :deps {c193/c193 {:local/root "."}}
:tasks
{
diff --git a/challenge-193/tyler-wardhaugh/clojure/build.clj b/challenge-193/tyler-wardhaugh/clojure/build.clj
new file mode 100644
index 0000000000..8217e15c24
--- /dev/null
+++ b/challenge-193/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.c193/c193)
+(def version "0.1.0-SNAPSHOT")
+(def main 'c193.c193)
+
+(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-193/tyler-wardhaugh/clojure/deps.edn b/challenge-193/tyler-wardhaugh/clojure/deps.edn
index bbf2435dec..bda220ad94 100644
--- a/challenge-193/tyler-wardhaugh/clojure/deps.edn
+++ b/challenge-193/tyler-wardhaugh/clojure/deps.edn
@@ -1,8 +1,8 @@
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.11.1"}}
:aliases
- {:t1 {:main-opts ["-m" "c191.t1"]}
- :t2 {:main-opts ["-m" "c191.t2"]}
+ {:t1 {:main-opts ["-m" "c193.t1"]}
+ :t2 {:main-opts ["-m" "c193.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-193/tyler-wardhaugh/clojure/src/c193/t1.clj b/challenge-193/tyler-wardhaugh/clojure/src/c193/t1.clj
new file mode 100644
index 0000000000..9ecf4b354e
--- /dev/null
+++ b/challenge-193/tyler-wardhaugh/clojure/src/c193/t1.clj
@@ -0,0 +1,17 @@
+(ns c193.t1
+ (:require [clojure.pprint :refer [cl-format]]))
+
+(def DEFAULT-INPUT [2])
+
+(defn binary-string
+ [n]
+ (->> (bit-shift-left 2 (dec n))
+ range
+ (map #(cl-format nil "~v,'0b" n %))))
+
+(defn -main
+ "Run Task 1 with a given input COLL, defaulting to the first example from
+ the task description."
+ [& args]
+ (let [[N] (or (some->> args (map parse-long)) DEFAULT-INPUT)]
+ (cl-format true "~{~a~^, ~}~%" (binary-string N))))
diff --git a/challenge-193/tyler-wardhaugh/clojure/src/c193/t2.clj b/challenge-193/tyler-wardhaugh/clojure/src/c193/t2.clj
new file mode 100644
index 0000000000..ea1644d3eb
--- /dev/null
+++ b/challenge-193/tyler-wardhaugh/clojure/src/c193/t2.clj
@@ -0,0 +1,25 @@
+(ns c193.t2)
+
+(def DEFAULT-INPUT [["adc" "wzy" "abc"]])
+
+(defn diff-array
+ [s]
+ (let [encoded (map #(-> % int (- (int \a))) s)]
+ (map - (rest encoded) encoded)))
+
+(defn odd-string
+ [coll]
+ (->> coll
+ (map (juxt identity diff-array))
+ (group-by second)
+ (reduce-kv (fn [_ _ v]
+ (when (= (count v) 1)
+ (reduced (ffirst v))))
+ nil)))
+
+(defn -main
+ "Run Task 2 with a given input COLL, defaulting to the first example from
+ the task description."
+ [& args]
+ (let [[COLL] (or args DEFAULT-INPUT)]
+ (println (odd-string COLL))))
diff --git a/challenge-193/tyler-wardhaugh/clojure/test/c193/t1_test.clj b/challenge-193/tyler-wardhaugh/clojure/test/c193/t1_test.clj
new file mode 100644
index 0000000000..19e9db3aa4
--- /dev/null
+++ b/challenge-193/tyler-wardhaugh/clojure/test/c193/t1_test.clj
@@ -0,0 +1,9 @@
+(ns c193.t1-test
+ (:require [clojure.test :refer [deftest is testing]]
+ [c193.t1 :refer [binary-string]]))
+
+(deftest task-1
+ (testing "Task 1 produces the correct results (description)"
+ (is (= ["00" "01" "10" "11"] (binary-string 2)))
+ (is (= ["000" "001" "010" "011" "100" "101" "110" "111"]
+ (binary-string 3)))))
diff --git a/challenge-193/tyler-wardhaugh/clojure/test/c193/t2_test.clj b/challenge-193/tyler-wardhaugh/clojure/test/c193/t2_test.clj
new file mode 100644
index 0000000000..a5cb82299e
--- /dev/null
+++ b/challenge-193/tyler-wardhaugh/clojure/test/c193/t2_test.clj
@@ -0,0 +1,8 @@
+(ns c193.t2-test
+ (:require [clojure.test :refer [deftest is testing]]
+ [c193.t2 :refer [odd-string]]))
+
+(deftest task-2
+ (testing "Task 2 produces the correct results"
+ (is (= "abc" (odd-string ["adc" "wzy" "abc"])))
+ (is (= "bob" (odd-string ["aaa" "bob" "ccc" "ddd"])))))