Created
October 11, 2021 12:49
-
-
Save AlexAvlonitis/d174e83c221ab56a54567eae94ba484a to your computer and use it in GitHub Desktop.
Roman numerals converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# solution from https://www.codewars.com/kata/reviews/51b62bf7a9c58071c6000026/groups/560d5575e3ff138f6400001d | |
NUMS = [ | |
[1000, "M"], | |
[900, "CM"], | |
[500, "D"], | |
[400, "CD"], | |
[100, "C"], | |
[90, "XC"], | |
[50, "L"], | |
[40, "XL"], | |
[10, "X"], | |
[9, "IX"], | |
[5, "V"], | |
[4, "IV"], | |
[1, "I"] | |
] | |
def solution num | |
str = "" | |
NUMS.each do |number, sub| | |
while num >= number | |
str << sub | |
num -= number | |
end | |
end | |
str | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment