Skip to content

Instantly share code, notes, and snippets.

@lordhumunguz
Created March 12, 2013 04:28
Show Gist options
  • Save lordhumunguz/5140356 to your computer and use it in GitHub Desktop.
Save lordhumunguz/5140356 to your computer and use it in GitHub Desktop.
This gist has been created from CodeCred.me
#Turns Integer into a Roman Numeral
# Old Roman Numeral
puts "What number would you like to convert to Roman Numeral?"
def to_roman(number)
number = number.to_i
str = ""
until number < 3000 && number > 0
puts "Please put in a number between 1 and 3000"
number = gets.chomp.to_i
end
romans = {
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"
}
romans.each_key do |key|
number_of_times = number / key
number -= number_of_times * key
str << (romans[key] * number_of_times)
end
puts str
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment