This repository has been archived by the owner on May 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c564fe2
commit 9380793
Showing
8 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Instructions | ||
|
||
The diamond kata takes as its input a letter, and outputs it in a diamond shape. | ||
Given a letter, it prints a diamond starting with 'A', with the supplied letter at the widest point. | ||
|
||
## Requirements | ||
|
||
- The first row contains one 'A'. | ||
- The last row contains one 'A'. | ||
- All rows, except the first and last, have exactly two identical letters. | ||
- All rows have as many trailing spaces as leading spaces. (This might be 0). | ||
- The diamond is horizontally symmetric. | ||
- The diamond is vertically symmetric. | ||
- The diamond has a square shape (width equals height). | ||
- The letters form a diamond shape. | ||
- The top half has the letters in ascending order. | ||
- The bottom half has the letters in descending order. | ||
- The four corners (containing the spaces) are triangles. | ||
|
||
## Examples | ||
|
||
In the following examples, spaces are indicated by `·` characters. | ||
|
||
Diamond for letter 'A': | ||
|
||
```text | ||
A | ||
``` | ||
|
||
Diamond for letter 'C': | ||
|
||
```text | ||
··A·· | ||
·B·B· | ||
C···C | ||
·B·B· | ||
··A·· | ||
``` | ||
|
||
Diamond for letter 'E': | ||
|
||
```text | ||
····A···· | ||
···B·B··· | ||
··C···C·· | ||
·D·····D· | ||
E·······E | ||
·D·····D· | ||
··C···C·· | ||
···B·B··· | ||
····A···· | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"authors": [ | ||
"ErikSchierboom" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/diamond.cljs" | ||
], | ||
"test": [ | ||
"test/diamond_test.cljs" | ||
], | ||
"example": [ | ||
".meta/src/example.cljs" | ||
] | ||
}, | ||
"blurb": "Given a letter, print a diamond starting with 'A' with the supplied letter at the widest point.", | ||
"source": "Seb Rose", | ||
"source_url": "https://web.archive.org/web/20220807163751/http://claysnow.co.uk/recycling-tests-in-tdd/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(ns diamond) | ||
|
||
(defn- row [letter-count [row letter]] | ||
(let [outer-spaces (apply str (repeat (- letter-count row 1) " ")) | ||
inner-spaces (apply str (repeat (if (zero? row) row (dec (* row 2))) " "))] | ||
(if (= letter \A) | ||
(str outer-spaces letter outer-spaces) | ||
(str outer-spaces letter inner-spaces letter outer-spaces)))) | ||
|
||
(defn diamond [letter] | ||
(let [letters (take-while #(>= 0 (compare % letter)) "ABCDEFGHIJKLMNOPQRSTUVWXYZ") | ||
indexed-letters (map-indexed vector letters) | ||
row-letters (concat indexed-letters (rest (reverse indexed-letters)))] | ||
(map #(row (count letters) %) row-letters))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# 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. | ||
|
||
[202fb4cc-6a38-4883-9193-a29d5cb92076] | ||
description = "Degenerate case with a single 'A' row" | ||
|
||
[bd6a6d78-9302-42e9-8f60-ac1461e9abae] | ||
description = "Degenerate case with no row containing 3 distinct groups of spaces" | ||
|
||
[af8efb49-14ed-447f-8944-4cc59ce3fd76] | ||
description = "Smallest non-degenerate case with odd diamond side length" | ||
|
||
[e0c19a95-9888-4d05-86a0-fa81b9e70d1d] | ||
description = "Smallest non-degenerate case with even diamond side length" | ||
|
||
[82ea9aa9-4c0e-442a-b07e-40204e925944] | ||
description = "Largest possible diamond" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(ns diamond) | ||
|
||
(defn diamond [] ;; <- arglist goes here | ||
;; your code goes here | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
(ns diamond-test | ||
(:require [clojure.test :refer [deftest is are]] | ||
[diamond :refer [diamond]])) | ||
|
||
(deftest single-a-row | ||
(is (= (diamond \A) ["A"]))) | ||
|
||
(deftest b-diamond | ||
(is (= (diamond \B) [" A " | ||
"B B" | ||
" A "]))) | ||
(deftest c-diamond | ||
(is (= (diamond \C) [" A " | ||
" B B " | ||
"C C" | ||
" B B " | ||
" A "]))) | ||
|
||
(deftest d-diamond | ||
(is (= (diamond \D) [" A " | ||
" B B " | ||
" C C " | ||
"D D" | ||
" C C " | ||
" B B " | ||
" A "]))) | ||
|
||
(deftest full-z-diamond | ||
(is (= (diamond \Z) [" A " | ||
" B B " | ||
" C C " | ||
" D D " | ||
" E E " | ||
" F F " | ||
" G G " | ||
" H H " | ||
" I I " | ||
" J J " | ||
" K K " | ||
" L L " | ||
" M M " | ||
" N N " | ||
" O O " | ||
" P P " | ||
" Q Q " | ||
" R R " | ||
" S S " | ||
" T T " | ||
" U U " | ||
" V V " | ||
" W W " | ||
" X X " | ||
" Y Y " | ||
"Z Z" | ||
" Y Y " | ||
" X X " | ||
" W W " | ||
" V V " | ||
" U U " | ||
" T T " | ||
" S S " | ||
" R R " | ||
" Q Q " | ||
" P P " | ||
" O O " | ||
" N N " | ||
" M M " | ||
" L L " | ||
" K K " | ||
" J J " | ||
" I I " | ||
" H H " | ||
" G G " | ||
" F F " | ||
" E E " | ||
" D D " | ||
" C C " | ||
" B B " | ||
" A "]))) |