diff --git a/config.json b/config.json index 69d6916c4..c4bb4a6fb 100644 --- a/config.json +++ b/config.json @@ -245,10 +245,10 @@ "practices": [], "prerequisites": [], "difficulty": 2, + "status": "deprecated", "topics": [ "algorithms, core_functions" - ], - "status": "deprecated" + ] }, { "slug": "acronym", @@ -745,10 +745,10 @@ "practices": [], "prerequisites": [], "difficulty": 3, + "status": "deprecated", "topics": [ "math" - ], - "status": "deprecated" + ] }, { "slug": "binary-search", @@ -856,10 +856,10 @@ "practices": [], "prerequisites": [], "difficulty": 3, + "status": "deprecated", "topics": [ "math" - ], - "status": "deprecated" + ] }, { "slug": "isbn-verifier", @@ -1018,10 +1018,10 @@ "practices": [], "prerequisites": [], "difficulty": 3, + "status": "deprecated", "topics": [ "math" - ], - "status": "deprecated" + ] }, { "slug": "allergies", @@ -1119,10 +1119,10 @@ "practices": [], "prerequisites": [], "difficulty": 4, + "status": "deprecated", "topics": [ "math" - ], - "status": "deprecated" + ] }, { "slug": "spiral-matrix", @@ -1211,6 +1211,19 @@ "conditionals" ] }, + { + "slug": "transpose", + "name": "Transpose", + "uuid": "a5dbea81-e24b-453e-bec9-bae4549ae52a", + "practices": [], + "prerequisites": [ + "basics", + "chars", + "strings", + "vectors" + ], + "difficulty": 5 + }, { "slug": "wordy", "name": "Wordy", diff --git a/exercises/practice/transpose/.docs/instructions.md b/exercises/practice/transpose/.docs/instructions.md new file mode 100644 index 000000000..6033af745 --- /dev/null +++ b/exercises/practice/transpose/.docs/instructions.md @@ -0,0 +1,61 @@ +# Instructions + +Given an input text output it transposed. + +Roughly explained, the transpose of a matrix: + +```text +ABC +DEF +``` + +is given by: + +```text +AD +BE +CF +``` + +Rows become columns and columns become rows. +See [transpose][]. + +If the input has rows of different lengths, this is to be solved as follows: + +- Pad to the left with spaces. +- Don't pad to the right. + +Therefore, transposing this matrix: + +```text +ABC +DE +``` + +results in: + +```text +AD +BE +C +``` + +And transposing: + +```text +AB +DEF +``` + +results in: + +```text +AD +BE + F +``` + +In general, all characters from the input should also be present in the transposed output. +That means that if a column in the input text contains only spaces on its bottom-most row(s), the corresponding output row should contain the spaces in its right-most column(s). + +[transpose]: https://en.wikipedia.org/wiki/Transpose diff --git a/exercises/practice/transpose/.meta/config.json b/exercises/practice/transpose/.meta/config.json new file mode 100644 index 000000000..2d6264a51 --- /dev/null +++ b/exercises/practice/transpose/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "tasxatzial" + ], + "files": { + "solution": [ + "src/transpose.clj" + ], + "test": [ + "test/transpose_test.clj" + ], + "example": [ + ".meta/example.clj" + ] + }, + "blurb": "Take input text and output it transposed.", + "source": "Reddit r/dailyprogrammer challenge #270 [Easy].", + "source_url": "https://web.archive.org/web/20230630051421/https://old.reddit.com/r/dailyprogrammer/comments/4msu2x/challenge_270_easy_transpose_the_input_text/" +} diff --git a/exercises/practice/transpose/.meta/example.clj b/exercises/practice/transpose/.meta/example.clj new file mode 100644 index 000000000..ee43b0056 --- /dev/null +++ b/exercises/practice/transpose/.meta/example.clj @@ -0,0 +1,21 @@ +(ns transpose) + +(defn pad-lines + [lines] + (if-let [reversed-lines (seq (reverse lines))] + (loop [rev-lines (rest reversed-lines) + padded-lines [(first reversed-lines)]] + (if (seq rev-lines) + (let [diff (- (.length (peek padded-lines)) (.length (first rev-lines))) + new-padded-line (str (first rev-lines) (apply str (repeat diff " ")))] + (recur (rest rev-lines) (conj padded-lines new-padded-line))) + (rseq padded-lines))) + [])) + +(defn transpose + [s] + (loop [result [] + padded-lines (-> s clojure.string/split-lines pad-lines)] + (if (seq (first padded-lines)) + (recur (conj result (map first padded-lines)) (map rest padded-lines)) + (clojure.string/join "\n" (map #(apply str %) result))))) diff --git a/exercises/practice/transpose/.meta/tests.toml b/exercises/practice/transpose/.meta/tests.toml new file mode 100644 index 000000000..32e366fba --- /dev/null +++ b/exercises/practice/transpose/.meta/tests.toml @@ -0,0 +1,46 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[404b7262-c050-4df0-a2a2-0cb06cd6a821] +description = "empty string" + +[a89ce8a3-c940-4703-a688-3ea39412fbcb] +description = "two characters in a row" + +[855bb6ae-4180-457c-abd0-ce489803ce98] +description = "two characters in a column" + +[5ceda1c0-f940-441c-a244-0ced197769c8] +description = "simple" + +[a54675dd-ae7d-4a58-a9c4-0c20e99a7c1f] +description = "single line" + +[0dc2ec0b-549d-4047-aeeb-8029fec8d5c5] +description = "first line longer than second line" + +[984e2ec3-b3d3-4b53-8bd6-96f5ef404102] +description = "second line longer than first line" + +[eccd3784-45f0-4a3f-865a-360cb323d314] +description = "mixed line length" + +[85b96b3f-d00c-4f80-8ca2-c8a5c9216c2d] +description = "square" + +[b9257625-7a53-4748-8863-e08e9d27071d] +description = "rectangle" + +[b80badc9-057e-4543-bd07-ce1296a1ea2c] +description = "triangle" + +[76acfd50-5596-4d05-89f1-5116328a7dd9] +description = "jagged triangle" diff --git a/exercises/practice/transpose/deps.edn b/exercises/practice/transpose/deps.edn new file mode 100644 index 000000000..561c3e2da --- /dev/null +++ b/exercises/practice/transpose/deps.edn @@ -0,0 +1,6 @@ +{:aliases {:test {:extra-paths ["test"] + :extra-deps {io.github.cognitect-labs/test-runner + {:git/url "https://github.com/cognitect-labs/test-runner.git" + :sha "705ad25bbf0228b1c38d0244a36001c2987d7337"}} + :main-opts ["-m" "cognitect.test-runner"] + :exec-fn cognitect.test-runner.api/test}}} \ No newline at end of file diff --git a/exercises/practice/transpose/project.clj b/exercises/practice/transpose/project.clj new file mode 100644 index 000000000..81d9d3049 --- /dev/null +++ b/exercises/practice/transpose/project.clj @@ -0,0 +1,4 @@ +(defproject transpose "0.1.0-SNAPSHOT" + :description "transpose exercise." + :url "https://github.com/exercism/clojure/tree/master/exercises/transpose" + :dependencies [[org.clojure/clojure "1.11.1"]]) diff --git a/exercises/practice/transpose/src/transpose.clj b/exercises/practice/transpose/src/transpose.clj new file mode 100644 index 000000000..772e5a3e4 --- /dev/null +++ b/exercises/practice/transpose/src/transpose.clj @@ -0,0 +1,7 @@ +(ns transpose) + +(defn transpose + "Given a string, it returns the transposed version" + [s] + ;; function body + ) diff --git a/exercises/practice/transpose/test/transpose_test.clj b/exercises/practice/transpose/test/transpose_test.clj new file mode 100644 index 000000000..c3c3cad93 --- /dev/null +++ b/exercises/practice/transpose/test/transpose_test.clj @@ -0,0 +1,184 @@ +(ns transpose-test + (:require [clojure.test :refer [deftest testing is]] + transpose)) + +(defn join-with-line-separator + [coll] + (clojure.string/join "\n" coll)) + +(deftest transpose_test_1 + (testing "empty string" + (is (= (join-with-line-separator [""]) + (transpose/transpose + (join-with-line-separator [""])))))) + +(deftest transpose_test_2 + (testing "two characters in a row" + (is (= (join-with-line-separator ["A" + "1"]) + (transpose/transpose + (join-with-line-separator ["A1"])))))) + +(deftest transpose_test_3 + (testing "two characters in a column" + (is (= (join-with-line-separator ["A1"]) + (transpose/transpose + (join-with-line-separator ["A" + "1"])))))) + +(deftest transpose_test_4 + (testing "simple" + (is (= (join-with-line-separator ["A1" + "B2" + "C3"]) + (transpose/transpose + (join-with-line-separator ["ABC" + "123"])))))) + +(deftest transpose_test_5 + (testing "single line" + (is (= (join-with-line-separator ["S" + "i" + "n" + "g" + "l" + "e" + " " + "l" + "i" + "n" + "e" + "."]) + (transpose/transpose + (join-with-line-separator ["Single line."])))))) + +(deftest transpose_test_6 + (testing "first line longer than second line" + (is (= (join-with-line-separator ["TT" + "hh" + "ee" + " " + "ff" + "oi" + "uf" + "rt" + "th" + "h " + " l" + "li" + "in" + "ne" + "e." + "."]) + (transpose/transpose + (join-with-line-separator ["The fourth line." + "The fifth line."])))))) + +(deftest transpose_test_7 + (testing "second line longer than first line" + (is (= (join-with-line-separator ["TT" + "hh" + "ee" + " " + "fs" + "ie" + "rc" + "so" + "tn" + " d" + "l " + "il" + "ni" + "en" + ".e" + " ."]) + (transpose/transpose + (join-with-line-separator ["The first line.", + "The second line."])))))) + +(deftest transpose_test_8 + (testing "mixed line length" + (is (= (join-with-line-separator ["TAAA" + "h " + "elll" + " ooi" + "lnnn" + "ogge" + "n e." + "glr" + "ei " + "snl" + "tei" + " .n" + "l e" + "i ." + "n" + "e" + "."]) + (transpose/transpose + (join-with-line-separator ["The longest line." + "A long line." + "A longer line." + "A line."])))))) + +(deftest transpose_test_9 + (testing "square" + (is (= (join-with-line-separator ["HEART" + "EMBER" + "ABUSE" + "RESIN" + "TREND"]) + (transpose/transpose + (join-with-line-separator ["HEART" + "EMBER" + "ABUSE" + "RESIN" + "TREND"])))))) + +(deftest transpose_test_10 + (testing "rectangle" + (is (= (join-with-line-separator ["FOBS" + "RULE" + "ATOP" + "CLOT" + "TIME" + "UNIT" + "RENT" + "EDGE"]) + (transpose/transpose + (join-with-line-separator ["FRACTURE" + "OUTLINED" + "BLOOMING" + "SEPTETTE"])))))) + +(deftest transpose_test_11 + (testing "triangle" + (is (= (join-with-line-separator ["TEASER" + " EASER" + " ASER" + " SER" + " ER" + " R"]) + (transpose/transpose + (join-with-line-separator ["T" + "EE" + "AAA" + "SSSS" + "EEEEE" + "RRRRRR"])))))) + +(deftest transpose_test_12 + (testing "jagged triangle" + (is (= (join-with-line-separator ["123456" + "1 3456" + " 3456" + " 3 56" + " 56" + " 5"]) + (transpose/transpose + (join-with-line-separator ["11" + "2" + "3333" + "444" + "555555" + "66666"]))))))