Created
May 18, 2011 04:17
-
-
Save gigasquid/977980 to your computer and use it in GitHub Desktop.
Roman Number Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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