aboutsummaryrefslogtreecommitdiff
path: root/challenge-096
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-096')
-rw-r--r--challenge-096/tyler-wardhaugh/clojure/README.md10
-rw-r--r--challenge-096/tyler-wardhaugh/clojure/deps.edn9
-rw-r--r--challenge-096/tyler-wardhaugh/clojure/pom.xml14
-rw-r--r--challenge-096/tyler-wardhaugh/clojure/src/tw/weekly/c96/core.clj12
-rw-r--r--challenge-096/tyler-wardhaugh/clojure/src/tw/weekly/c96/t1.clj25
-rw-r--r--challenge-096/tyler-wardhaugh/clojure/src/tw/weekly/c96/t2.clj31
-rw-r--r--challenge-096/tyler-wardhaugh/clojure/test/tw/weekly/c96_test.clj16
7 files changed, 100 insertions, 17 deletions
diff --git a/challenge-096/tyler-wardhaugh/clojure/README.md b/challenge-096/tyler-wardhaugh/clojure/README.md
index c83f0cfefa..0e314a09c0 100644
--- a/challenge-096/tyler-wardhaugh/clojure/README.md
+++ b/challenge-096/tyler-wardhaugh/clojure/README.md
@@ -1,13 +1,13 @@
-# tw.weekly.c92
+# tw.weekly.c96
-The Weekly Challenge - #092 - Tyler Wardhaugh
+The Weekly Challenge - #096 - Tyler Wardhaugh
## Usage
Run the project directly (shows default output from both tasks):
- $ clojure -M -m tw.weekly.c92.core
+ $ clojure -M -m tw.weekly.c96.core
Run the project's tests (which are samples from the task descriptions):
@@ -15,11 +15,11 @@ Run the project's tests (which are samples from the task descriptions):
Run Task #1 with input
- $ clojure -M -m tw.weekly.c92.t1 A B
+ $ clojure -M -m tw.weekly.c96.t1 S
Run Task #2:
- $ clojure -M -m tw.weekly.c92.t2 N S
+ $ clojure -M -m tw.weekly.c96.t2 S1 S2
## Project Template
diff --git a/challenge-096/tyler-wardhaugh/clojure/deps.edn b/challenge-096/tyler-wardhaugh/clojure/deps.edn
index 12e0c0d36b..3702e967c4 100644
--- a/challenge-096/tyler-wardhaugh/clojure/deps.edn
+++ b/challenge-096/tyler-wardhaugh/clojure/deps.edn
@@ -1,6 +1,5 @@
{:paths ["src" "resources"]
- :deps {org.clojure/clojure {:mvn/version "1.10.1"}
- org.clojure/data.finger-tree {:mvn/version "0.0.3"}}
+ :deps {org.clojure/clojure {:mvn/version "1.10.1"}}
:aliases
{:test {:extra-paths ["test"]
:extra-deps {org.clojure/test.check {:mvn/version "1.0.0"}}}
@@ -10,6 +9,6 @@
:sha "f7ef16dc3b8332b0d77bc0274578ad5270fbfedd"}}
:main-opts ["-m" "cognitect.test-runner"
"-d" "test"]}
- :uberjar {:extra-deps {seancorfield/depstar {:mvn/version "1.0.95"}}
- :main-opts ["-m" "hf.depstar.uberjar" "tw.weekly.c95.jar"
- "-C" "-m" "tw.weekly.c95"]}}}
+ :uberjar {:extra-deps {seancorfield/depstar {:mvn/version "1.0.96"}}
+ :main-opts ["-m" "hf.depstar.uberjar" "tw.weekly.c96.jar"
+ "-C" "-m" "tw.weekly.c96"]}}}
diff --git a/challenge-096/tyler-wardhaugh/clojure/pom.xml b/challenge-096/tyler-wardhaugh/clojure/pom.xml
index 92317a848c..04154a698d 100644
--- a/challenge-096/tyler-wardhaugh/clojure/pom.xml
+++ b/challenge-096/tyler-wardhaugh/clojure/pom.xml
@@ -2,11 +2,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tw.weekly</groupId>
- <artifactId>tw.weekly.c94</artifactId>
+ <artifactId>tw.weekly.c96</artifactId>
<version>0.1.0-SNAPSHOT</version>
- <name>tw.weekly.c94</name>
- <description>Challenge #094</description>
- <url>https://github.com/tw.weekly/tw.weekly.c94</url>
+ <name>tw.weekly.c96</name>
+ <description>Challenge #096</description>
+ <url>https://github.com/tw.weekly/tw.weekly.c96</url>
<licenses>
<license>
<name>Eclipse Public License</name>
@@ -19,9 +19,9 @@
</developer>
</developers>
<scm>
- <url>https://github.com/tw.weekly/tw.weekly.c94</url>
- <connection>scm:git:git://github.com/tw.weekly/tw.weekly.c94.git</connection>
- <developerConnection>scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c94.git</developerConnection>
+ <url>https://github.com/tw.weekly/tw.weekly.c96</url>
+ <connection>scm:git:git://github.com/tw.weekly/tw.weekly.c96.git</connection>
+ <developerConnection>scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c96.git</developerConnection>
<tag>HEAD</tag>
</scm>
<dependencies>
diff --git a/challenge-096/tyler-wardhaugh/clojure/src/tw/weekly/c96/core.clj b/challenge-096/tyler-wardhaugh/clojure/src/tw/weekly/c96/core.clj
new file mode 100644
index 0000000000..63aeb35497
--- /dev/null
+++ b/challenge-096/tyler-wardhaugh/clojure/src/tw/weekly/c96/core.clj
@@ -0,0 +1,12 @@
+(ns tw.weekly.c96.core
+ (:require [tw.weekly.c96.t1 :as t1])
+ (:require [tw.weekly.c96.t2 :as t2])
+ (:gen-class))
+
+(defn -main
+ "Run all tasks"
+ [& _]
+ (println "Task #1:")
+ (t1/-main)
+ (println "\nTask #2:")
+ (t2/-main))
diff --git a/challenge-096/tyler-wardhaugh/clojure/src/tw/weekly/c96/t1.clj b/challenge-096/tyler-wardhaugh/clojure/src/tw/weekly/c96/t1.clj
new file mode 100644
index 0000000000..9d5ab76cb5
--- /dev/null
+++ b/challenge-096/tyler-wardhaugh/clojure/src/tw/weekly/c96/t1.clj
@@ -0,0 +1,25 @@
+(ns tw.weekly.c96.t1
+ (:require [clojure.edn :as edn]
+ [clojure.string :as str]))
+
+;;;
+; Task description for TASK #1 › Reverse Words
+;;;
+
+(def DEFAULT-INPUT "The Weekly Challenge")
+
+(defn reverse-words
+ "Split a string by spaces and reassemble in reverse word order."
+ [s]
+ (-> s
+ str/trim
+ (str/split #"\s+")
+ reverse
+ (->> (str/join " "))))
+
+(defn -main
+ "Run Task 1 using a string S, defaulting to the example given in
+ the task description."
+ [& args]
+ (let [S (or (some-> args first edn/read-string) DEFAULT-INPUT)]
+ (println (reverse-words S))))
diff --git a/challenge-096/tyler-wardhaugh/clojure/src/tw/weekly/c96/t2.clj b/challenge-096/tyler-wardhaugh/clojure/src/tw/weekly/c96/t2.clj
new file mode 100644
index 0000000000..95e3d9d76e
--- /dev/null
+++ b/challenge-096/tyler-wardhaugh/clojure/src/tw/weekly/c96/t2.clj
@@ -0,0 +1,31 @@
+(ns tw.weekly.c96.t2
+ (:require [clojure.edn :as edn]))
+
+;;;
+; Task description for TASK #2 › Edit Distance
+;;;
+
+(def DEFAULT-INPUT ["kitten" "sitting"])
+
+(defn edit-distance
+ "Compute the minimum operations required to convert S1 to S2."
+ [s1 s2]
+ (let [ed (fn [f [h1 & t1 :as s1] [h2 & t2 :as s2]]
+ (cond
+ (empty? s1) (count s2)
+ (empty? s2) (count s1)
+ (= h1 h2) (f f t1 t2)
+ :else (->> [[t1 s2]
+ [s1 t2]
+ [t1 t2]]
+ (transduce (map (partial apply f f)) min ##Inf)
+ inc)))
+ ed' (memoize ed)]
+ (ed' ed' (seq s1) (seq s2))))
+
+(defn -main
+ "Run Task 2 using strings S1 and S2, defaulting to the example given in
+ the task description."
+ [& args]
+ (let [[S1 S2] (or (some->> args (take 2) (map edn/read-string)) DEFAULT-INPUT)]
+ (println (edit-distance S1 S2))))
diff --git a/challenge-096/tyler-wardhaugh/clojure/test/tw/weekly/c96_test.clj b/challenge-096/tyler-wardhaugh/clojure/test/tw/weekly/c96_test.clj
new file mode 100644
index 0000000000..1a3eb10dfe
--- /dev/null
+++ b/challenge-096/tyler-wardhaugh/clojure/test/tw/weekly/c96_test.clj
@@ -0,0 +1,16 @@
+(ns tw.weekly.c96-test
+ (:require [clojure.test :refer [deftest is testing]]
+ [tw.weekly.c96.t1 :refer [reverse-words]]
+ [tw.weekly.c96.t2 :refer [edit-distance]]))
+
+(deftest task-1
+ (testing "Task 1, Reverse Words"
+ (is (= "Challenge Weekly The" (reverse-words "The Weekly Challenge")))
+ (is (= "family same the of part are Raku and Perl"
+ (reverse-words
+ " Perl and Raku are part of the same family ")))))
+
+(deftest task-2
+ (testing "Task 2, Edit Distance"
+ (is (= 3 (edit-distance "kitten" "sitting")))
+ (is (= 2 (edit-distance "sunday" "monday")))))