Created
February 9, 2015 05:11
-
-
Save data-doge/e845d466cb78f0e17e17 to your computer and use it in GitHub Desktop.
bad ass roman numeral soln
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
$cipher = { | |
"C" => 100, | |
"XC" => 90, | |
"L" => 50, | |
"XL" => 40, | |
"X" => 10, | |
"IX" => 9, | |
"V" => 5, | |
"IV" => 4, | |
"I" => 1 | |
} | |
def to_roman(num) | |
output = "" | |
$cipher.each do |roman, arabic| | |
output << roman * (num / arabic) | |
num = num % arabic | |
end | |
output | |
end | |
puts to_roman(44) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment