Skip to content

Commit 86a39d4

Browse files
committed
Add diamond
1 parent d131912 commit 86a39d4

File tree

9 files changed

+268
-0
lines changed

9 files changed

+268
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@
173173
"transforming"
174174
]
175175
},
176+
{
177+
"slug": "diamond",
178+
"name": "Diamond",
179+
"uuid": "6ea6e17c-9dbb-45c5-ab70-362791e5dd60",
180+
"practices": [],
181+
"prerequisites": [],
182+
"difficulty": 5
183+
},
176184
{
177185
"slug": "eliuds-eggs",
178186
"name": "Eliud's Eggs",

exercises/Exercises.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "SquareRoot", "practice\squa
217217
EndProject
218218
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "NthPrime", "practice\nth-prime\NthPrime.vbproj", "{5A733C8D-8F95-437D-80CE-85CFA65DD2E0}"
219219
EndProject
220+
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Diamond", "practice\diamond\Diamond.vbproj", "{1601B461-96EC-4643-B16C-2A367BACB8B8}"
221+
EndProject
220222
Global
221223
GlobalSection(SolutionConfigurationPlatforms) = preSolution
222224
Debug|Any CPU = Debug|Any CPU
@@ -650,6 +652,10 @@ Global
650652
{5A733C8D-8F95-437D-80CE-85CFA65DD2E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
651653
{5A733C8D-8F95-437D-80CE-85CFA65DD2E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
652654
{5A733C8D-8F95-437D-80CE-85CFA65DD2E0}.Release|Any CPU.Build.0 = Release|Any CPU
655+
{1601B461-96EC-4643-B16C-2A367BACB8B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
656+
{1601B461-96EC-4643-B16C-2A367BACB8B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
657+
{1601B461-96EC-4643-B16C-2A367BACB8B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
658+
{1601B461-96EC-4643-B16C-2A367BACB8B8}.Release|Any CPU.Build.0 = Release|Any CPU
653659
EndGlobalSection
654660
GlobalSection(NestedProjects) = preSolution
655661
{ED3FEEC3-83E9-4C7F-BD51-0ABA9BCC102A} = {B161412A-37BB-42B7-9D8F-F4B238E3CFFA}
@@ -758,5 +764,6 @@ Global
758764
{9D522138-876C-456F-AF5F-010FB0298F81} = {B161412A-37BB-42B7-9D8F-F4B238E3CFFA}
759765
{46123EAD-9CCD-4D0E-8801-7CA681484BAA} = {B161412A-37BB-42B7-9D8F-F4B238E3CFFA}
760766
{5A733C8D-8F95-437D-80CE-85CFA65DD2E0} = {B161412A-37BB-42B7-9D8F-F4B238E3CFFA}
767+
{1601B461-96EC-4643-B16C-2A367BACB8B8} = {B161412A-37BB-42B7-9D8F-F4B238E3CFFA}
761768
EndGlobalSection
762769
EndGlobal
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Instructions
2+
3+
The diamond kata takes as its input a letter, and outputs it in a diamond shape.
4+
Given a letter, it prints a diamond starting with 'A', with the supplied letter at the widest point.
5+
6+
## Requirements
7+
8+
- The first row contains one 'A'.
9+
- The last row contains one 'A'.
10+
- All rows, except the first and last, have exactly two identical letters.
11+
- All rows have as many trailing spaces as leading spaces. (This might be 0).
12+
- The diamond is horizontally symmetric.
13+
- The diamond is vertically symmetric.
14+
- The diamond has a square shape (width equals height).
15+
- The letters form a diamond shape.
16+
- The top half has the letters in ascending order.
17+
- The bottom half has the letters in descending order.
18+
- The four corners (containing the spaces) are triangles.
19+
20+
## Examples
21+
22+
In the following examples, spaces are indicated by `·` characters.
23+
24+
Diamond for letter 'A':
25+
26+
```text
27+
A
28+
```
29+
30+
Diamond for letter 'C':
31+
32+
```text
33+
··A··
34+
·B·B·
35+
C···C
36+
·B·B·
37+
··A··
38+
```
39+
40+
Diamond for letter 'E':
41+
42+
```text
43+
····A····
44+
···B·B···
45+
··C···C··
46+
·D·····D·
47+
E·······E
48+
·D·····D·
49+
··C···C··
50+
···B·B···
51+
····A····
52+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Imports System
2+
3+
Public Module Diamond
4+
Public Function Rows(ByVal letter As String) As String
5+
If letter = "A" Then
6+
Return "A"
7+
End If
8+
9+
Dim startLetter = Asc("A")
10+
Dim endLetter = Asc(letter)
11+
Dim size = endLetter - startLetter + 1
12+
Dim diamond As New List(Of String)()
13+
14+
For i = 0 To size - 1
15+
Dim outerSpaces = New String(" ", size - 1 - i)
16+
Dim current = Chr(startLetter + i)
17+
Dim line as String
18+
19+
If i > 0 Then
20+
Dim innerSpaces = New String(" ", 2 * i - 1)
21+
line = outerSpaces & current & innerSpaces & current & outerSpaces
22+
Else
23+
line = outerSpaces & current & outerSpaces
24+
End if
25+
diamond.Add(line)
26+
Next
27+
28+
For i = size - 2 To 0 Step -1
29+
diamond.Add(diamond(i))
30+
Next
31+
32+
Return String.Join(vbCrLf, diamond)
33+
End Function
34+
End Module
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"BNAndras"
4+
],
5+
"files": {
6+
"solution": [
7+
"Diamond.vb"
8+
],
9+
"test": [
10+
"DiamondTests.vb"
11+
],
12+
"example": [
13+
".meta/Example.vb"
14+
]
15+
},
16+
"blurb": "Given a letter, print a diamond starting with 'A' with the supplied letter at the widest point.",
17+
"source": "Seb Rose",
18+
"source_url": "https://web.archive.org/web/20220807163751/http://claysnow.co.uk/recycling-tests-in-tdd/"
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[202fb4cc-6a38-4883-9193-a29d5cb92076]
13+
description = "Degenerate case with a single 'A' row"
14+
15+
[bd6a6d78-9302-42e9-8f60-ac1461e9abae]
16+
description = "Degenerate case with no row containing 3 distinct groups of spaces"
17+
18+
[af8efb49-14ed-447f-8944-4cc59ce3fd76]
19+
description = "Smallest non-degenerate case with odd diamond side length"
20+
21+
[e0c19a95-9888-4d05-86a0-fa81b9e70d1d]
22+
description = "Smallest non-degenerate case with even diamond side length"
23+
24+
[82ea9aa9-4c0e-442a-b07e-40204e925944]
25+
description = "Largest possible diamond"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Imports System
2+
3+
Public Module Diamond
4+
Public Function Rows(ByVal letter As String) As String
5+
Throw New NotImplementedException("You need to implement this function.")
6+
End Function
7+
End Module
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
9+
<PackageReference Include="xunit" Version="2.8.1" />
10+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
Imports Xunit
2+
3+
Public Class DiamondTest
4+
<Fact>
5+
Public Sub Degenerate_case_with_a_single_A_row()
6+
Dim expected = "A"
7+
Assert.Equal(expected, Rows("A"))
8+
End Sub
9+
10+
<Fact(Skip:="Remove this Skip property to run this test")>
11+
Public Sub Degenerate_case_with_no_row_containing_three_distinct_groups_of_spaces()
12+
Dim expected = Join(New String() { _
13+
" A ", _
14+
"B B", _
15+
" A " _
16+
}, vbCrLf)
17+
Assert.Equal(expected, Rows("B"))
18+
End Sub
19+
20+
<Fact(Skip:="Remove this Skip property to run this test")>
21+
Public Sub Smallest_non_degenerate_case_with_odd_diamond_side_length()
22+
Dim expected = Join(New String() { _
23+
" A ", _
24+
" B B ", _
25+
"C C", _
26+
" B B ", _
27+
" A " _
28+
}, vbCrLf)
29+
Assert.Equal(expected, Rows("C"))
30+
End Sub
31+
32+
<Fact(Skip:="Remove this Skip property to run this test")>
33+
Public Sub Smallest_non_degenerate_case_with_even_diamond_side_length()
34+
Dim expected = Join(New String() { _
35+
" A ", _
36+
" B B ", _
37+
" C C ", _
38+
"D D", _
39+
" C C ", _
40+
" B B ", _
41+
" A " _
42+
}, vbCrLf)
43+
Assert.Equal(expected, Rows("D"))
44+
End Sub
45+
46+
<Fact(Skip:="Remove this Skip property to run this test")>
47+
Public Sub Largest_possible_diamond()
48+
Dim expected = Join(New String() { _
49+
" A ", _
50+
" B B ", _
51+
" C C ", _
52+
" D D ", _
53+
" E E ", _
54+
" F F ", _
55+
" G G ", _
56+
" H H ", _
57+
" I I ", _
58+
" J J ", _
59+
" K K ", _
60+
" L L ", _
61+
" M M ", _
62+
" N N ", _
63+
" O O ", _
64+
" P P ", _
65+
" Q Q ", _
66+
" R R ", _
67+
" S S ", _
68+
" T T ", _
69+
" U U ", _
70+
" V V ", _
71+
" W W ", _
72+
" X X ", _
73+
" Y Y ", _
74+
"Z Z", _
75+
" Y Y ", _
76+
" X X ", _
77+
" W W ", _
78+
" V V ", _
79+
" U U ", _
80+
" T T ", _
81+
" S S ", _
82+
" R R ", _
83+
" Q Q ", _
84+
" P P ", _
85+
" O O ", _
86+
" N N ", _
87+
" M M ", _
88+
" L L ", _
89+
" K K ", _
90+
" J J ", _
91+
" I I ", _
92+
" H H ", _
93+
" G G ", _
94+
" F F ", _
95+
" E E ", _
96+
" D D ", _
97+
" C C ", _
98+
" B B ", _
99+
" A " _
100+
}, vbCrLf)
101+
Assert.Equal(expected, Rows("Z"))
102+
End Sub
103+
End Class

0 commit comments

Comments
 (0)