This kata is taken from the book The Coding Dojo Handbook
by Emily Bache ISBN 978-91-981180-0-1
.
The main branch contains a c#
project with a test project inside.
- Clone this repository
- Create a branch with your name.
- Push your branch.
- Remember the Red-Green-Refactor cycle.
- Name your tests using the following pattern:
method_name_With_arguments_Returns_return_value()
For this Kata, write a function to convert from normal (Ara- bic) numbers to Roman Numerals. For example:
1 -> I
10 -> X
7 -> VII
There is no need to be able to convert numbers larger than about 3000.
Symbol | Value |
---|---|
I | 1 |
V | 5 |
X | 10 |
L | 50 |
C | 100 |
D | 500 |
M | 100 |
Generally, symbols are placed in order of value, starting with the
largest values. When smaller values precede larger values,
the smaller values are subtracted from the larger values, and the
result is added to the total. However, you can’t write numerals
like IM
for 999
, there are some additional rules:
- A number written in Arabic numerals can be broken into digits.
For example, 1903 is composed of 1 (one thousand), 9 (nine hundreds),
0 (zero tens), and 3 (three units). To write the Roman numeral,
each of the non-zero digits should be treated separately.
In the above example,
1,000 = M, 900 = CM, and 3 = III
. Therefore,1903 = MCMIII
. - The symbols
I
,X
,C
, andM
can be repeated three times in succession, but no more. (They may appear more than three times if they appear non-sequentially, such asXXXIX
) D
,L
, andV
. can never be repeated.I
can be subtracted fromV
andX
only.X
can be subtracted fromL
andC
only.C
can be subtracted fromD
andM
only.V
,L
, andD
can never be subtracted.- Only one small-value symbol may be subtracted from any large-value symbol.
Write a function to convert in the other direction, ie numeral to digit
- Did you manage to build up the algorithm gradually, driving development with tests?
- Is your choice of algorithm obvious from the code, or do you need additional comments?
This is quite an easy Kata, it’s a good introduction to building up an algorithm using TDD.