Skip to content

Converts integers between 1 to 3999 to roman numerals

Notifications You must be signed in to change notification settings

bertuko/RomanNumerals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

RomanNumerals

Converts integers between 1 to 3999 to roman numerals

I created a static class with an int extension method, that way it can be used without instantiating anything.

The solution uses a recursive function to return the roman numeral string. In the class I added a static IDictionary with the equivalencies from major to minor. A List or IEnumerable could have sufficed, however this way I made sure there is only one value per number. The advantages of using the dictionary like this is that it is loaded into memory just once.

The way I solved this is quite straightforward. Having the equivalencies list from major to minor, I can do a loop through them until the number is greater or equal than the value. That means I can write the corresponding letter/s. Therefore, I can subtract the value from the original number (since we are already returning that one) and call the same function until it reaches 0.

About

Converts integers between 1 to 3999 to roman numerals

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages