A bunch of CLIs solving katas:
To set yourself up, first make sure you have npm and NodeJS installed.
Then clone this repository and create the CLIs links:
git clone [email protected]:lucsgiovanne/katas.git
cd katas
npm link
In the project directory, you can run:
Runs the conversion from roman representation to decimal representation.
Doesn't validate the argument and, therefore, may lead to unexpected behavior on invalid numbers (non-valid roman number between I and MMMCMXCIX).
Runs the conversion from decimal representation to roman representation.
Doesn't validate the argument and, therefore, may lead to unexpected behavior on invalid numbers (non-valid decimal number between 1 and 3999).
Runs the automated tests.
The convertion from decimal to roman representation follow the algorithm:
- Start with the decimal number and an empty string.
- Iterate over the roman symbols base values in decreasing order (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1) and in each iteration:
- Divide the remaining number by the iteration base value.
- Concatenate the string with the corresponding symbol repeated quotient times
- Update the number with the remainder.
The algorithm correctness is trivially proven by ensuring, by induction, that the final remainder for any number between 1 and 3999 is 0.
The convertion from roman to decimal representation follow the algorithm:
- Start with the roman number and an accumulator.
- Convert all subtractive notation inside the roman representation to straight summable notation.
- Walks the summable roman notation of the given number accumulating the decimal convertion for each symbol.
The algorithm correctness become a roman representation definitions consequence by proving the subtractive notation removal algorithm, that's trivially done for numbers between I and MMMCMXCIX.