Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (22 sloc)
533 Bytes
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
def rome(n) | |
ms = n/1000 | |
m_rem = n%1000 | |
ds = m_rem/500 | |
d_rem = m_rem%500 | |
cs = d_rem/100 | |
c_rem = d_rem%100 | |
ls = c_rem/50 | |
l_rem = c_rem%50 | |
xs = l_rem/10 | |
x_rem = l_rem%10 | |
vs = x_rem/5 | |
is = x_rem%5 | |
return "M"*ms + "D"*ds + "C"*cs + "L"*ls + "X"*xs + "V"*vs + "I"*is | |
end | |
puts "Gimme a number between 1 and 3500 and I'll give you the old timey Roman numerals version!" | |
input = gets.chomp.to_i | |
if input <= 0 || input > 3500 | |
puts "Just gimme a number within the range, wiseguy!" | |
else | |
puts rome(input) | |
end |