Skip to content

Instantly share code, notes, and snippets.

@gigasquid
Created May 18, 2011 04:17
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 gigasquid/977980 to your computer and use it in GitHub Desktop.
Save gigasquid/977980 to your computer and use it in GitHub Desktop.
Roman Number Calculator
# Given a integer between 1 and 50 convert it to its Roman Numeral
def convert_to_roman (arabic)
ones_translation =
[ 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']
tens_translation =
[ 'X', 'XX', 'XXX', 'XL', 'L']
tens = ""
ones = arabic % 10
tens = arabic / 10 if arabic > 9
ones_value = ""
tens_value = ""
if (arabic < 51)
ones_value = ones_translation[ones - 1] unless ones == 0
tens_value = tens_translation[tens - 1] if arabic > 9
end
return tens_value + ones_value
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment