Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into add-rotational-cipher-exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed May 8, 2023
2 parents ad349bb + dccaa80 commit e8e1cca
Show file tree
Hide file tree
Showing 90 changed files with 2,401 additions and 0 deletions.
154 changes: 154 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,160 @@
"strings"
],
"difficulty": 2
},
{
"slug": "atbash-cipher",
"name": "Atbash Cipher",
"uuid": "afb8e97c-6600-419c-a121-7cd3bcf870ee",
"practices": [],
"prerequisites": [
"numbers",
"conditionals",
"strings"
],
"difficulty": 3
},
{
"slug": "minesweeper",
"name": "Minesweeper",
"uuid": "1d8dc367-3f00-4b99-a6bd-e5895a0bdb4c",
"practices": [],
"prerequisites": [
"vectors",
"conditionals",
"strings"
],
"difficulty": 7
},
{
"slug": "wordy",
"name": "Wordy",
"uuid": "fae36fc2-9c03-42a0-b1a1-3d1dd61783ba",
"practices": [
"numbers",
"strings",
"conditionals"
],
"prerequisites": [
"numbers",
"strings",
"conditionals"
],
"difficulty": 6
},
{
"slug": "perfect-numbers",
"name": "Perfect Numbers",
"uuid": "e523fad6-9078-46d0-a540-e6af83dc0e59",
"practices": [],
"prerequisites": [
"numbers"
],
"difficulty": 3
},
{
"slug": "pangram",
"name": "Pangram",
"uuid": "a646eaf6-3642-4d05-9083-b520699145b3",
"practices": [
"strings"
],
"prerequisites": [
"strings",
"booleans"
],
"difficulty": 2
},
{
"slug": "space-age",
"name": "Space Age",
"uuid": "f43676b5-ab9c-4cc8-9159-a30401deaa29",
"practices": [
"floating-point-numbers"
],
"prerequisites": [
"numbers",
"floating-point-numbers"
],
"difficulty": 2
},
{
"slug": "collatz-conjecture",
"name": "Collatz Conjecture",
"uuid": "99c2ede9-23a8-40a1-a54e-f33fddb7d881",
"practices": [
"numbers"
],
"prerequisites": [
"numbers",
"conditionals"
],
"difficulty": 2
},
{
"slug": "grade-school",
"name": "Grade School",
"uuid": "f9b0bc81-ea0b-4007-8228-6bb520333289",
"practices": [],
"prerequisites": [
"numbers",
"strings"
],
"difficulty": 3
},
{
"slug": "grains",
"name": "Grains",
"uuid": "3a96556b-4ec8-431d-a5ee-99355065baec",
"practices": [],
"prerequisites": [
"numbers"
],
"difficulty": 3
},
{
"slug": "proverb",
"name": "Proverb",
"uuid": "fa8ffb0a-4936-4aad-8b8e-e77116aca614",
"practices": [],
"prerequisites": [
"strings",
"vectors"
],
"difficulty": 3
},
{
"slug": "zipper",
"name": "Zipper",
"uuid": "26c4c4c6-154f-42fd-b624-158132c028c3",
"practices": [],
"prerequisites": [
"strings",
"vectors"
],
"difficulty": 9
},
{
"slug": "yacht",
"name": "Yacht",
"uuid": "24666e92-89fe-4955-8420-b63458f66b4c",
"practices": [],
"prerequisites": [
"strings",
"vectors"
],
"difficulty": 5
},
{
"slug": "change",
"name": "Change",
"uuid": "e1e76dc4-543f-4d1e-8727-a726ee5291ec",
"practices": [],
"prerequisites": [
"numbers",
"vectors"
],
"difficulty": 3
}
]
},
Expand Down
27 changes: 27 additions & 0 deletions exercises/practice/atbash-cipher/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Instructions

Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.

The Atbash cipher is a simple substitution cipher that relies on transposing all the letters in the alphabet such that the resulting alphabet is backwards.
The first letter is replaced with the last letter, the second with the second-last, and so on.

An Atbash cipher for the Latin alphabet would be as follows:

```text
Plain: abcdefghijklmnopqrstuvwxyz
Cipher: zyxwvutsrqponmlkjihgfedcba
```

It is a very weak cipher because it only has one possible key, and it is a simple mono-alphabetic substitution cipher.
However, this may not have been an issue in the cipher's time.

Ciphertext is written out in groups of fixed length, the traditional group size being 5 letters, leaving numbers unchanged, and punctuation is excluded.
This is to make it harder to guess things based on word boundaries.
All text will be encoded as lowercase letters.

## Examples

- Encoding `test` gives `gvhg`
- Encoding `x123 yes` gives `c123b vh`
- Decoding `gvhg` gives `test`
- Decoding `gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt` gives `thequickbrownfoxjumpsoverthelazydog`
19 changes: 19 additions & 0 deletions exercises/practice/atbash-cipher/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"ErikSchierboom"
],
"files": {
"solution": [
"src/atbash_cipher.cljs"
],
"test": [
"test/atbash_cipher_test.cljs"
],
"example": [
".meta/src/example.cljs"
]
},
"blurb": "Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.",
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/Atbash"
}
45 changes: 45 additions & 0 deletions exercises/practice/atbash-cipher/.meta/src/example.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
; Courtesy from: https://exercism.org/tracks/clojure/exercises/atbash-cipher/solutions/joebutler2

(ns atbash-cipher
(:require [clojure.string :as str]))

(def translation
{
"a" "z"
"b" "y"
"c" "x"
"d" "w"
"e" "v"
"f" "u"
"g" "t"
"h" "s"
"i" "r"
"j" "q"
"k" "p"
"l" "o"
"m" "n"
"n" "m"
"o" "l"
"p" "k"
"q" "j"
"r" "i"
"s" "h"
"t" "g"
"u" "f"
"v" "e"
"w" "d"
"x" "c"
"y" "b"
"z" "a"
})

(defn encode [input]
(->> input
(str/lower-case)
(re-seq #"\w|\d")
(map #(get translation % %))
(partition-all 5)
(map #(cons %2 %) (repeat " "))
(flatten)
(str/join)
(str/trimr)))
45 changes: 45 additions & 0 deletions exercises/practice/atbash-cipher/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.

[2f47ebe1-eab9-4d6b-b3c6-627562a31c77]
description = "encode yes"

[b4ffe781-ea81-4b74-b268-cc58ba21c739]
description = "encode no"

[10e48927-24ab-4c4d-9d3f-3067724ace00]
description = "encode OMG"

[d59b8bc3-509a-4a9a-834c-6f501b98750b]
description = "encode spaces"

[31d44b11-81b7-4a94-8b43-4af6a2449429]
description = "encode mindblowingly"

[d503361a-1433-48c0-aae0-d41b5baa33ff]
description = "encode numbers"

[79c8a2d5-0772-42d4-b41b-531d0b5da926]
description = "encode deep thought"

[9ca13d23-d32a-4967-a1fd-6100b8742bab]
description = "encode all the letters"

[bb50e087-7fdf-48e7-9223-284fe7e69851]
description = "decode exercism"

[ac021097-cd5d-4717-8907-b0814b9e292c]
description = "decode a sentence"

[18729de3-de74-49b8-b68c-025eaf77f851]
description = "decode numbers"

[0f30325f-f53b-415d-ad3e-a7a4f63de034]
description = "decode all the letters"

[39640287-30c6-4c8c-9bac-9d613d1a5674]
description = "decode with too many spaces"

[b34edf13-34c0-49b5-aa21-0768928000d5]
description = "decode with no spaces"
10 changes: 10 additions & 0 deletions exercises/practice/atbash-cipher/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{:deps
{org.clojure/clojure {:mvn/version "1.10.1"}
org.clojure/clojurescript {:mvn/version "1.10.773"}}

:aliases
{:test
{:extra-paths ["test"]
:extra-deps
{olical/cljs-test-runner {:mvn/version "3.8.0"}}
:main-opts ["-m" "cljs-test-runner.main"]}}}
5 changes: 5 additions & 0 deletions exercises/practice/atbash-cipher/src/atbash_cipher.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns atbash-cipher)

(defn encode [] ;; <- arglist goes here
;; your code goes here
)
30 changes: 30 additions & 0 deletions exercises/practice/atbash-cipher/test/atbash_cipher_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(ns atbash-cipher-test
(:require [clojure.test :refer [deftest is]]
atbash-cipher))

(deftest encode-no
(is (= "ml" (atbash-cipher/encode "no"))))

(deftest encode-yes
(is (= "bvh" (atbash-cipher/encode "yes"))))

(deftest encode-OMG
(is (= "lnt" (atbash-cipher/encode "OMG"))))

(deftest encode-O-M-G
(is (= "lnt" (atbash-cipher/encode "O M G"))))

(deftest encode-long-word
(is (= "nrmwy oldrm tob" (atbash-cipher/encode "mindblowingly"))))

(deftest encode-numbers
(is (= "gvhgr mt123 gvhgr mt"
(atbash-cipher/encode "Testing, 1 2 3, testing."))))

(deftest encode-sentence
(is (= "gifgs rhurx grlm" (atbash-cipher/encode "Truth is fiction."))))

(deftest encode-all-the-things
(let [plaintext "The quick brown fox jumps over the lazy dog."
cipher "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"]
(is (= cipher (atbash-cipher/encode plaintext)))))
14 changes: 14 additions & 0 deletions exercises/practice/change/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Instructions

Correctly determine the fewest number of coins to be given to a customer such that the sum of the coins' value would equal the correct amount of change.

## For example

- An input of 15 with [1, 5, 10, 25, 100] should return one nickel (5) and one dime (10) or [5, 10]
- An input of 40 with [1, 5, 10, 25, 100] should return one nickel (5) and one dime (10) and one quarter (25) or [5, 10, 25]

## Edge cases

- Does your algorithm work for any given set of coins?
- Can you ask for negative change?
- Can you ask for a change value smaller than the smallest coin value?
19 changes: 19 additions & 0 deletions exercises/practice/change/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"ErikSchierboom"
],
"files": {
"solution": [
"src/change.cljs"
],
"test": [
"test/change_test.cljs"
],
"example": [
".meta/src/example.cljs"
]
},
"blurb": "Correctly determine change to be given using the least number of coins.",
"source": "Software Craftsmanship - Coin Change Kata",
"source_url": "https://web.archive.org/web/20130115115225/http://craftsmanship.sv.cmu.edu:80/exercises/coin-change-kata"
}
Loading

0 comments on commit e8e1cca

Please sign in to comment.