Skip to content

Instantly share code, notes, and snippets.

@divoxx
Forked from arbylee/gist:2396008
Created April 17, 2012 14:29
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 divoxx/2406319 to your computer and use it in GitHub Desktop.
Save divoxx/2406319 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