Skip to content

Instantly share code, notes, and snippets.

@majosystems
Last active December 28, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save majosystems/7461976 to your computer and use it in GitHub Desktop.
Save majosystems/7461976 to your computer and use it in GitHub Desktop.
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