From: Mark Hubbart Date: 2005-03-06T02:38:41+09:00 Subject: Re: [QUIZ] Roman Numerals (#22) On Sat, 5 Mar 2005 00:13:56 +0900, Brian Schr�der wrote: > On Fri, 4 Mar 2005 22:53:20 +0900, Ruby Quiz wrote: > > The three rules of Ruby Quiz: > > > > 1. Please do not post any solutions or spoiler discussion for this quiz until > > 48 hours have passed from the time on this message. > > > > 2. Support Ruby Quiz by submitting ideas as often as you can: > > > > http://www.rubyquiz.com/ > > > > 3. Enjoy! > > > > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= > > > > This week's quiz is to write a converter to and from Roman numerals. > > > > The script should be a standard Unix filter, reading from files specified on the > > command-line or STDIN and writing to STDOUT. Each line of input will contain > > one integer (between 1 and 3999) expressed as an Arabic or Roman numeral. There > > should be one line of output for each line of input, containing the original > > number in the opposite format. > > > > For example, given the following input: > > > > III > > 29 > > 38 > > CCXCI > > 1999 > > > > The correct output is: > > > > 3 > > XXIX > > XXXVIII > > 291 > > MCMXCIX > > > > If you're not familiar with or need a refresher on Roman numerals, the rules are > > simple. First, there are seven letters associated with seven values: > > > > I = 1 > > V = 5 > > X = 10 > > L = 50 > > C = 100 > > D = 500 > > M = 1000 > > > > You can combine letters to add values, by listing them largest to smallest from > > left to right: > > > > II is 2 > > VII is 8 > > XXXI is 31 > > > > However, you may only list three consecutive identical letters. That requires a > > special rule to express numbers like 4 and 900. That rule is that a single > > lower value may proceed a larger value, to indicate subtraction. This rule is > > only used to build values not reachable by the previous rules: > > > > IV is 4 > > CM is 900 > > > > But 15 is XV, not XVX. > > > > > > Hello James, > > I know that in reality roman numbers didn't always follow the > conventions given here, so everything is a little bit more complex, > but this are more or less clear rules. Maybe one should add the > additional rule that shorter numbers are preferred over longer ones to > disambiguate a bit more. But the question I'm after: > > When I follow your rules, I calculate MIM for 1999, why do you propose > the slightly less readable: MCMXCIX for this purpose? Also this does > not seem to be consistent with XXIX for 29. The rule of thumb as I remember it is that you can't prefix a symbol that is greater than one order of magnitude (base ten). So, IX is okay, where IC and IM are not. HTH, Mark