Skip to content

Instantly share code, notes, and snippets.

@eliseworthy
Created April 28, 2011 18:54
Show Gist options
  • Save eliseworthy/947027 to your computer and use it in GitHub Desktop.
Save eliseworthy/947027 to your computer and use it in GitHub Desktop.
def roman_generator
while true
puts
puts "What's the number you'd like as an old-school Roman numeral?"
reply = gets.chomp
if reply != "close"
reply = reply.to_i
end
n = reply
if n == "close"
break
elsif n < 10000 && n > 1
if n >= 1000 && n < 10000
thousands_count = n / 1000
thousands_count.times do
print "M"
end
n = n % 1000
end
if n >= 500 && n < 1000
print "D"
n = n % 500
end
if n >= 100 && n < 500
hundreds_count = n / 100
hundreds_count.times do
print "C"
end
n = n % 100
end
if n >= 50 && n < 100
print "L"
n = n % 50
end
if n >= 10 && n < 50
tens_count = n / 10
tens_count.times do
print "X"
end
n = n % 10
end
if n >= 5 && n < 10
print "V"
n = n % 5
end
if n >= 1
n.times do
print "I"
end
puts
end
else
puts "Please choose a number between 1 and 2999."
end
end
end
roman_generator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment