Skip to content

Instantly share code, notes, and snippets.

@pumpkincouture
Created August 21, 2014 14:32
Show Gist options
  • Select an option

  • Save pumpkincouture/3baebab948891443d233 to your computer and use it in GitHub Desktop.

Select an option

Save pumpkincouture/3baebab948891443d233 to your computer and use it in GitHub Desktop.
class RomanNumerals
def convert(number)
roman = ""
bases = { 1000 => "M", 900 => "CM", 500 => "D", 100 => "C",
90 => "XC", 50 => "L", 40 => "XL", 10 => "X",
9 => "IX", 5 => "V", 4 => "IV" }
bases.each do |arabic, base|
while number >= arabic
roman += base
number -= arabic
end
end
roman += ("I" * number)
roman
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment