-
-
Save ELI7VH/d09b6c1296329ddeb5ee8dbb7861ccd0 to your computer and use it in GitHub Desktop.
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
roman_mapping = { | |
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 map_dat_roman(roman_mapping, number, result) | |
if (number >= 1) | |
k,v = roman_mapping.find { |k, v| number / k >= 1 } | |
result += v | |
new_number = number - k | |
return map_dat_roman(roman_mapping, new_number, result) | |
else | |
return result | |
end | |
end | |
number = 2541 | |
result = '' | |
result = map_dat_roman(roman_mapping, number, result) | |
p result,result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment