Howdy!

I was confused about the Example algorithms. Here's my interpretation.
Maybe it will help others. (Also I wanted to throw in my $0.02 worth :)

A decimal number can be converted to its Roman equivalent using a two-
step process. First replace each digit (n) in the decimal number with its
Roman representation (r, s, and t) as shown here:

        n       Roman representation
        -       --------------------
        0        (nothing)
        1        r
        2        rr
        3        rrr
        4        rs
        5        s
        6        sr
        7        srr
        8        srrr
        9        rt

Then replace the Roman representation with Roman numerals depending on
the position (k) of the digit (n) in the decimal number.

        position        k       r s t
        --------        -       -----
        ones            0       I V X
        tens            1       X L C
        hundreds        2       C D M
        thousands       3       M - -

For example, the number 1984 would be:

        1     9     8     4
        r     rt    srrr  rs
   k:   3     2     1     0
        M     CM    LXXX  IV

Putting it together gives: MCMLXXXIV.


A Roman number can be converted to decimal with this procedure:

  set Data[M] to 1000, Data[D] to 500, Data[C] to 100, etc.
  set Valsub[C] to "DM", Valsub[X] to "LC", Valsub[I] to "VX"
  set Valid to "MMMDCCCLXXXVIII"
  set Sum to 0

  for each character in the Roman number (in sequence, from left to right)
      read a character from the Roman number string and set Char to it
      set Next to the next character in the string

      check that Valid contains Char.  if absent, fail
      remove all the characters in Valid preceding the first instance of Char

      if Valsub[Char] contains Next
          set Sum to Sum - Data[Char]
          remove all occurrences of Char in Valid except the last one
          replace the first (remaining) character in Valid with Next
      else
          set Sum to Sum + Data[Char]
          remove the first (remaining) character in Valid


Since this procedure detects illegal Roman numbers, it is not necessary
to use the test for validity described by the Perl expression.

Hope this helps.

-Boreal



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Tied to your PC? Cut Loose and
Stay connected with Yahoo! Mobile
http://us.click.yahoo.com/QBCcSD/o1CEAA/sXBHAA/dpFolB/TM
---------------------------------------------------------------------~->

For the latest information on the Hugi Size Coding Competition, check out: http://www.hugi.de/compo/ 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 


