Roman numerals/Decode: Difference between revisions

Vedit macro language
(haskell impl)
(Vedit macro language)
Line 1,179:
MDCLXVI -> 1666
MMVIII -> 2008</pre>
 
=={{header|TUSCRIPT}}==
<lang tuscript>
Line 1,193 ⟶ 1,194:
Roman number MDCLXVI equals 1666
</pre>
 
=={{header|Vedit macro language}}==
 
<lang vedit>// Main program for testing the function
//
do {
Get_Input(10, "Enter a roman numeral: ", NOCR+STATLINE)
Call("Roman_to_Arabic")
Reg_Type(10) Message(" = ") Num_Type(#1)
} while(#1)
Return
 
// Convert Roman numeral into numeric value
// in: @10 = Roman numeral
// out: #1 = numeric value
//
:Roman_to_Arabic:
Buf_Switch(Buf_Free)
Ins_Text("M1000 D500 C100 L50 X10 V5 I1") Ins_Newline
Reg_Ins(10) Ins_Char(' ')
#1 = #2 = 0
 
Repeat(ALL) {
#3 = #2 // #3 = previous character
Goto_Line(2) // roman numeral to be converted
if (At_EOL) {
Break // all done
}
Reg_Copy_Block(11, CP, CP+1, DELETE) // next character in roman numeral
if (Search(@11, BEGIN+ADVANCE+NOERR)) { // find character from the table
#2 = Num_Eval(SUPPRESS) // corresponding numeric value
if (#2 > #3) { // larger than previous digit?
#1 -= #3 // substract previous digit
} else {
#1 += #3 // add previous digit
}
}
}
Reg_Empty(11)
Buf_Quit(OK)
Return</lang>
 
Sample output:
<pre>iv = 4
xii = 12
MDCLXVI = 1666
MCMXC = 1990
MMXI = 2011</pre>
 
=={{header|Zsh}}==
Anonymous user