Last active
December 28, 2015 07:09
-
-
Save majosystems/7461976 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
class Integer | |
def roman(s=self) | |
return "-" if 3999 < s | |
v = 1 | |
r = {1 => 'I', 4 => 'IV', 5 => 'V', 9=> 'IX', 10 => 'X', | |
40 => 'XL', 50 => 'L', 90 => 'XC', 100 => 'C', 400 => 'CD', | |
500 => 'D', 900=> 'CM', 1000 => 'M', 9999 => "" } | |
r.keys.sort.each{|k| | |
if k > s && s > 0 | |
return r[v] + roman(s - v); break | |
end | |
v = k } | |
return "" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment