Created
March 13, 2014 02:01
-
-
Save blurredbits/9520646 to your computer and use it in GitHub Desktop.
Roman Numeral Generator - J. Weirich edition.
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
puts "Please enter a number you would like to convert to a roman numeral" | |
num = gets.chomp.to_i | |
def to_roman(num) | |
results = "" | |
digits = [ | |
[1000, "M"], | |
[900, "CM"], | |
[500, "D"], | |
[400, "CD"], | |
[100,"C"], | |
[90, "XC"], | |
[50, "L"], | |
[40, "XL"], | |
[10, "X"], | |
[9, "IX"], | |
[5, "V"], | |
[4, "IV"], | |
[1, "I"] | |
] | |
digits.each do |number, symbol| | |
while num >= number | |
results << symbol | |
num -= number | |
end | |
end | |
results | |
end | |
puts "Your roman numeral is: " + to_roman(num) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment