Skip to content

Instantly share code, notes, and snippets.

@arbylee
Created April 16, 2012 02:12
Show Gist options
  • Select an option

  • Save arbylee/2396008 to your computer and use it in GitHub Desktop.

Select an option

Save arbylee/2396008 to your computer and use it in GitHub Desktop.
RomanNumerals
class RomanNumeral
VALUE_MAPPER = [['M', 1000], ['D', 500], ['L', 50], ['X', 10], ['IX', 9], ['V', 5], ['IV', 4], ['I', 1]]
def roman num
output = ''
while num > 0
VALUE_MAPPER.each do |letter, letter_value|
num_of_letters = (num / letter_value)
output << letter * num_of_letters
num -= (letter_value * num_of_letters)
end
end
output
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment