Task

Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer.

You don't need to validate the form of the Roman numeral.

Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately,

starting with the leftmost decimal digit and skipping any 0s   (zeroes).

1990 is rendered as   MCMXC     (1000 = M,   900 = CM,   90 = XC)     and

2008 is rendered as   MMVIII       (2000 = MM,   8 = VIII).

The Roman numeral for 1666,   MDCLXVI,   uses each letter in descending order.




 10  LET R$ = "MCMXCIX"
 20  GOSUB 100 PRINT "ROMAN NUMERALS DECODED"
 30  LET R$ = "MMXII"
 40  GOSUB 100
 50  LET R$ = "MDCLXVI"
 60  GOSUB 100
 70  LET R$ = "MMMDCCCLXXXVIII"
 80  GOSUB 100
 90  END 
 100  PRINT M$R$,
 110  LET M$ =  CHR$ (13)
 120  GOSUB 150"ROMAN NUMERALS DECODE given R$"
 130  PRINT N;
 140  RETURN 
 150  IF  NOT C THEN  GOSUB 250INITIALIZE
 160  LET J = 0
 170  LET N = 0
 180  FOR I =  LEN (R$) TO 1 STEP  - 1
 190      LET P = J
 200      FOR J = 1 TO C
 210          IF  MID$ (C$,J,1) <  >  MID$ (R$,I,1) THEN  NEXT J
 220      IF J <  = C THEN N = N + R(J) * ((J >  = P) * 2 - 1)
 230  NEXT I
 240  RETURN 
 250  READ C$
 260  LET C =  LEN (C$)
 270  DIM R(C)
 280  FOR I = 0 TO C
 290  READ R(I)
 300      NEXT I
 310  RETURN 
 320  DATA "IVXLCDM",0,1,5,10,50,100,500,1000