Skip to content

Commit 5d8985b

Browse files
Add roman-numerals exercise (#266)
* Add roman-numerals exercise * Apply suggestions from code review Co-authored-by: Bob Hoeppner <[email protected]> * Fix --------- Co-authored-by: Bob Hoeppner <[email protected]>
1 parent 4eb070b commit 5d8985b

File tree

10 files changed

+367
-0
lines changed

10 files changed

+367
-0
lines changed

config.json

+17
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,23 @@
12241224
],
12251225
"difficulty": 7
12261226
},
1227+
{
1228+
"slug": "roman-numerals",
1229+
"name": "Roman Numerals",
1230+
"uuid": "b15c0460-5174-4f92-bb20-1f0db50a4890",
1231+
"practices": [
1232+
"numbers",
1233+
"while-loops",
1234+
"extension-methods"
1235+
],
1236+
"prerequisites": [
1237+
"strings",
1238+
"while-loops",
1239+
"numbers",
1240+
"extension-methods"
1241+
],
1242+
"difficulty": 5
1243+
},
12271244
{
12281245
"slug": "robot-simulator",
12291246
"name": "Robot Simulator",

exercises/Exercises.sln

+7
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "DndCharacter", "practice\dn
161161
EndProject
162162
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Poker", "practice\poker\Poker.vbproj", "{F62F286B-2E13-4914-B168-EDB399470B1C}"
163163
EndProject
164+
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "RomanNumerals", "practice\roman-numerals\RomanNumerals.vbproj", "{C099D994-E586-4A2F-BDBF-A1D6742B1794}"
165+
EndProject
164166
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "RobotSimulator", "practice\robot-simulator\RobotSimulator.vbproj", "{86A4A18F-6FC1-4953-9AAE-EEEE36FE8E2E}"
165167
EndProject
166168
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Triangle", "practice\triangle\Triangle.vbproj", "{1CE933B5-94BD-48AD-81B9-E352D75020CB}"
@@ -494,6 +496,10 @@ Global
494496
{F62F286B-2E13-4914-B168-EDB399470B1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
495497
{F62F286B-2E13-4914-B168-EDB399470B1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
496498
{F62F286B-2E13-4914-B168-EDB399470B1C}.Release|Any CPU.Build.0 = Release|Any CPU
499+
{C099D994-E586-4A2F-BDBF-A1D6742B1794}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
500+
{C099D994-E586-4A2F-BDBF-A1D6742B1794}.Debug|Any CPU.Build.0 = Debug|Any CPU
501+
{C099D994-E586-4A2F-BDBF-A1D6742B1794}.Release|Any CPU.ActiveCfg = Release|Any CPU
502+
{C099D994-E586-4A2F-BDBF-A1D6742B1794}.Release|Any CPU.Build.0 = Release|Any CPU
497503
{86A4A18F-6FC1-4953-9AAE-EEEE36FE8E2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
498504
{86A4A18F-6FC1-4953-9AAE-EEEE36FE8E2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
499505
{86A4A18F-6FC1-4953-9AAE-EEEE36FE8E2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -598,6 +604,7 @@ Global
598604
{057DDB74-6435-4B9E-988A-A21895AECE92} = {B161412A-37BB-42B7-9D8F-F4B238E3CFFA}
599605
{1C5BEE1E-B2B8-4D08-BC42-D83121DFFFB9} = {B161412A-37BB-42B7-9D8F-F4B238E3CFFA}
600606
{F62F286B-2E13-4914-B168-EDB399470B1C} = {B161412A-37BB-42B7-9D8F-F4B238E3CFFA}
607+
{C099D994-E586-4A2F-BDBF-A1D6742B1794} = {B161412A-37BB-42B7-9D8F-F4B238E3CFFA}
601608
{86A4A18F-6FC1-4953-9AAE-EEEE36FE8E2E} = {B161412A-37BB-42B7-9D8F-F4B238E3CFFA}
602609
{1CE933B5-94BD-48AD-81B9-E352D75020CB} = {B161412A-37BB-42B7-9D8F-F4B238E3CFFA}
603610
{B6F54248-A909-42A1-9A75-679160C63B28} = {B161412A-37BB-42B7-9D8F-F4B238E3CFFA}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Hints
2+
3+
This exercise requires you to write an extension method. For more information, see [this page](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Instructions
2+
3+
Write a function to convert from normal numbers to Roman Numerals.
4+
5+
The Romans were a clever bunch.
6+
They conquered most of Europe and ruled it for hundreds of years.
7+
They invented concrete and straight roads and even bikinis.
8+
One thing they never discovered though was the number zero.
9+
This made writing and dating extensive histories of their exploits slightly more challenging, but the system of numbers they came up with is still in use today.
10+
For example the BBC uses Roman numerals to date their programs.
11+
12+
The Romans wrote numbers using letters - I, V, X, L, C, D, M.
13+
(notice these letters have lots of straight lines and are hence easy to hack into stone tablets).
14+
15+
```text
16+
1 => I
17+
10 => X
18+
7 => VII
19+
```
20+
21+
The maximum number supported by this notation is 3,999.
22+
(The Romans themselves didn't tend to go any higher)
23+
24+
Wikipedia says: Modern Roman numerals ... are written by expressing each digit separately starting with the left most digit and skipping any digit with a value of zero.
25+
26+
To see this in practice, consider the example of 1990.
27+
28+
In Roman numerals 1990 is MCMXC:
29+
30+
1000=M
31+
900=CM
32+
90=XC
33+
34+
2008 is written as MMVIII:
35+
36+
2000=MM
37+
8=VIII
38+
39+
Learn more about [Roman numerals on Wikipedia][roman-numerals].
40+
41+
[roman-numerals]: https://wiki.imperivm-romanvm.com/wiki/Roman_Numerals
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Imports System.Collections.Generic
2+
Imports System.Text
3+
Imports System.Runtime.CompilerServices
4+
5+
Module RomanNumeralExtension
6+
Private ReadOnly ArabicToRomanConversions As New Dictionary(Of Integer, String) From {
7+
{1000, "M"},
8+
{900, "CM"},
9+
{500, "D"},
10+
{400, "CD"},
11+
{100, "C"},
12+
{90, "XC"},
13+
{50, "L"},
14+
{40, "XL"},
15+
{10, "X"},
16+
{9, "IX"},
17+
{5, "V"},
18+
{4, "IV"},
19+
{1, "I"}
20+
}
21+
22+
<Extension()>
23+
Function ToRoman(ByVal value As Integer) As String
24+
Dim result = New StringBuilder()
25+
Dim remainder = value
26+
27+
For Each conversion In ArabicToRomanConversions
28+
While remainder >= conversion.Key
29+
remainder -= conversion.Key
30+
result.Append(conversion.Value)
31+
End While
32+
Next
33+
34+
Return result.ToString()
35+
End Function
36+
End Module
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"authors": [
3+
"ErikSchierboom",
4+
"bobahop"
5+
],
6+
"files": {
7+
"solution": [
8+
"RomanNumerals.vb"
9+
],
10+
"test": [
11+
"RomanNumeralsTests.vb"
12+
],
13+
"example": [
14+
".meta/Example.vb"
15+
]
16+
},
17+
"blurb": "Write a function to convert from normal numbers to Roman Numerals.",
18+
"source": "The Roman Numeral Kata",
19+
"source_url": "https://codingdojo.org/kata/RomanNumerals/"
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
[19828a3a-fbf7-4661-8ddd-cbaeee0e2178]
13+
description = "1 is I"
14+
15+
[f088f064-2d35-4476-9a41-f576da3f7b03]
16+
description = "2 is II"
17+
18+
[b374a79c-3bea-43e6-8db8-1286f79c7106]
19+
description = "3 is III"
20+
21+
[05a0a1d4-a140-4db1-82e8-fcc21fdb49bb]
22+
description = "4 is IV"
23+
24+
[57c0f9ad-5024-46ab-975d-de18c430b290]
25+
description = "5 is V"
26+
27+
[20a2b47f-e57f-4797-a541-0b3825d7f249]
28+
description = "6 is VI"
29+
30+
[ff3fb08c-4917-4aab-9f4e-d663491d083d]
31+
description = "9 is IX"
32+
33+
[2bda64ca-7d28-4c56-b08d-16ce65716cf6]
34+
description = "27 is XXVII"
35+
36+
[a1f812ef-84da-4e02-b4f0-89c907d0962c]
37+
description = "48 is XLVIII"
38+
39+
[607ead62-23d6-4c11-a396-ef821e2e5f75]
40+
description = "49 is XLIX"
41+
42+
[d5b283d4-455d-4e68-aacf-add6c4b51915]
43+
description = "59 is LIX"
44+
45+
[46b46e5b-24da-4180-bfe2-2ef30b39d0d0]
46+
description = "93 is XCIII"
47+
48+
[30494be1-9afb-4f84-9d71-db9df18b55e3]
49+
description = "141 is CXLI"
50+
51+
[267f0207-3c55-459a-b81d-67cec7a46ed9]
52+
description = "163 is CLXIII"
53+
54+
[cdb06885-4485-4d71-8bfb-c9d0f496b404]
55+
description = "402 is CDII"
56+
57+
[6b71841d-13b2-46b4-ba97-dec28133ea80]
58+
description = "575 is DLXXV"
59+
60+
[432de891-7fd6-4748-a7f6-156082eeca2f]
61+
description = "911 is CMXI"
62+
63+
[e6de6d24-f668-41c0-88d7-889c0254d173]
64+
description = "1024 is MXXIV"
65+
66+
[bb550038-d4eb-4be2-a9ce-f21961ac3bc6]
67+
description = "3000 is MMM"
68+
69+
[6d1d82d5-bf3e-48af-9139-87d7165ed509]
70+
description = "16 is XVI"
71+
72+
[4465ffd5-34dc-44f3-ada5-56f5007b6dad]
73+
description = "66 is LXVI"
74+
75+
[902ad132-0b4d-40e3-8597-ba5ed611dd8d]
76+
description = "166 is CLXVI"
77+
78+
[dacb84b9-ea1c-4a61-acbb-ce6b36674906]
79+
description = "666 is DCLXVI"
80+
81+
[efbe1d6a-9f98-4eb5-82bc-72753e3ac328]
82+
description = "1666 is MDCLXVI"
83+
84+
[3bc4b41c-c2e6-49d9-9142-420691504336]
85+
description = "3001 is MMMI"
86+
87+
[4e18e96b-5fbb-43df-a91b-9cb511fe0856]
88+
description = "3999 is MMMCMXCIX"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Imports System.Runtime.CompilerServices
2+
3+
Module RomanNumeralExtension
4+
<Extension()>
5+
Function ToRoman(ByVal value As Integer) As String
6+
Throw New NotImplementedException("You need to implement this function.")
7+
End Function
8+
End Module
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net7.0</TargetFramework>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
8+
<PackageReference Include="xunit" Version="2.4.2" />
9+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
10+
<PrivateAssets>all</PrivateAssets>
11+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
12+
</PackageReference>
13+
</ItemGroup>
14+
</Project>

0 commit comments

Comments
 (0)