roman_numbers: initial commit
This commit is contained in:
parent
2cfe146e9d
commit
bbfb9da1a1
3 changed files with 233 additions and 0 deletions
79
cpp/roman-numerals/README.md
Normal file
79
cpp/roman-numerals/README.md
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
# Roman Numerals
|
||||
|
||||
Write a function to convert from normal numbers to Roman Numerals: e.g.
|
||||
|
||||
The Romans were a clever bunch. They conquered most of Europe and ruled
|
||||
it for hundreds of years. They invented concrete and straight roads and
|
||||
even bikinis. One thing they never discovered though was the number
|
||||
zero. 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. For example the BBC uses Roman numerals to date
|
||||
their programmes.
|
||||
|
||||
The Romans wrote numbers using letters - I, V, X, L, C, D, M. (notice
|
||||
these letters have lots of straight lines and are hence easy to hack
|
||||
into stone tablets).
|
||||
|
||||
```
|
||||
1 => I
|
||||
10 => X
|
||||
7 => VII
|
||||
```
|
||||
|
||||
There is no need to be able to convert numbers larger than about 3000.
|
||||
(The Romans themselves didn't tend to go any higher)
|
||||
|
||||
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.
|
||||
|
||||
To see this in practice, consider the example of 1990.
|
||||
|
||||
In Roman numerals 1990 is MCMXC:
|
||||
|
||||
1000=M
|
||||
900=CM
|
||||
90=XC
|
||||
|
||||
2008 is written as MMVIII:
|
||||
|
||||
2000=MM
|
||||
8=VIII
|
||||
|
||||
See also: http://www.novaroma.org/via_romana/numbers.html
|
||||
|
||||
## Getting Started
|
||||
|
||||
Make sure you have read the [getting started with C++](http://help.exercism.io/getting-started-with-cpp.html)
|
||||
page on the [exercism help site](http://help.exercism.io/). This covers
|
||||
the basic information on setting up the development environment expected
|
||||
by the exercises.
|
||||
|
||||
## Passing the Tests
|
||||
|
||||
Get the first test compiling, linking and passing by following the [three
|
||||
rules of test-driven development](http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd).
|
||||
Create just enough structure by declaring namespaces, functions, classes,
|
||||
etc., to satisfy any compiler errors and get the test to fail. Then write
|
||||
just enough code to get the test to pass. Once you've done that,
|
||||
uncomment the next test by moving the following line past the next test.
|
||||
|
||||
```C++
|
||||
#if defined(EXERCISM_RUN_ALL_TESTS)
|
||||
```
|
||||
|
||||
This may result in compile errors as new constructs may be invoked that
|
||||
you haven't yet declared or defined. Again, fix the compile errors minimally
|
||||
to get a failing test, then change the code minimally to pass the test,
|
||||
refactor your implementation for readability and expressiveness and then
|
||||
go on to the next test.
|
||||
|
||||
Try to use standard C++11 facilities in preference to writing your own
|
||||
low-level algorithms or facilities by hand. [CppReference](http://en.cppreference.com/)
|
||||
is a wiki reference to the C++ language and standard library. If you
|
||||
are new to C++, but have programmed in C, beware of
|
||||
[C traps and pitfalls](http://www.slideshare.net/LegalizeAdulthood/c-traps-and-pitfalls-for-c-programmers).
|
||||
|
||||
## Source
|
||||
|
||||
The Roman Numeral Kata [view source](http://codingdojo.org/cgi-bin/wiki.pl?KataRomanNumerals)
|
||||
Loading…
Add table
Add a link
Reference in a new issue