[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [QUIZ] Roman Numerals (#22

ES

3/5/2005 10:04:00 PM

On Sat, March 5, 2005 5:38 pm, Mark Hubbart said:
> On Sat, 5 Mar 2005 00:13:56 +0900, Brian Schröder <ruby.brian@gmail.com>
> wrote:
>> On Fri, 4 Mar 2005 22:53:20 +0900, Ruby Quiz <james@grayproductions.net>
>> 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.rub...
>> >
>> > 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.

This is the correct modern stipulation. The Romans were slightly less
formal about it as long as the intention was clear (there's the famous
example of IIII instead of IV, as IV was forbidden because it appears
in the name of IVPITER).

> HTH,
> Mark

E



1 Answer

Christian Neukirchen

3/6/2005 11:52:00 AM

0

"ES" <ruby-ml@magical-cat.org> writes:

> On Sat, March 5, 2005 5:38 pm, Mark Hubbart said:
>> 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.
>
> This is the correct modern stipulation. The Romans were slightly less
> formal about it as long as the intention was clear (there's the famous
> example of IIII instead of IV, as IV was forbidden because it appears
> in the name of IVPITER).

Afaik, this was the reason for Christians not to use IV (especially on
church clocks), not for the Romans.

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...