Roman numerals/Decode: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|Tailspin}}: update to stricter typing) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 18:
{{trans|Python}}
<
(‘XL’, 40), (‘L’, 50), (‘XC’, 90), (‘C’, 100),
(‘CD’, 400), (‘D’, 500), (‘CM’, 900), (‘M’, 1000)]
Line 31:
L(value) [‘MCMXC’, ‘MMVIII’, ‘MDCLXVI’]
print(value‘ = ’roman_value(value))</
{{out}}
Line 41:
=={{header|360 Assembly}}==
<
ROMADEC CSECT
USING ROMADEC,R13 base register
Line 108:
XDEC DS CL12
REGEQU
END ROMADEC </
{{out}}
<pre>
Line 127:
The Roman numeral must be in uppercase letters.
<
jmp test
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 236:
nl: db 13,10,'$'
bufdef: db 16,0
buf: ds 17</
=={{header|Action!}}==
<
IF c='I THEN RETURN (1)
ELSEIF c='V THEN RETURN (5)
Line 281:
Test("MMMDCCCLXXXVIII")
Test("MMMCMXCIX")
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Roman_numerals_decode.png Screenshot from Atari 8-bit computer]
Line 294:
=={{header|Ada}}==
<
Pragma Assertion_Policy( Check );
Line 445:
Ada.Text_IO.Put_Line("Testing complete.");
End Test_Roman_Numerals;
</syntaxhighlight>
{{out}}
Line 468:
{{works with|ALGOL 68G|Any - tested with release 2.2.0}}
Note: roman to int will handle multiple subtraction, e.g. IIIIX for 6.
<
BEGIN
PROC roman digit value = (CHAR roman digit) INT:
Line 515:
printf(($g(5), 1x, g(5), 1x$, expected output OF roman test[i], output));
printf(($b("ok", "not ok"), 1l$, output = expected output OF roman test[i]))
OD</
=={{header|ALGOL W}}==
<
% decodes a roman numeral into an integer %
% there must be at least one blank after the numeral %
Line 612:
testRoman( "MDCLXVI" );
end.</
{{out}}
<pre>
Line 647:
===Java===
<
Nigel Galloway March 16th., 2012
Line 685:
FiveHund: 'D';
Thousand: 'M' ;
NEWLINE: '\r'? '\n' ;</
Using this test data:
<pre>
Line 741:
=={{header|APL}}==
{{works with|Dyalog APL}}
<
rmn←(⎕A,⎕A,'*')[(⎕A,⎕UCS 96+⍳26)⍳⍵] ⍝ make input uppercase
dgt←↑'IVXLCDM' (1 5 10 50 100 500 1000) ⍝ values of roman digits
Line 747:
map←dgt[2;dgt[1;]⍳rmn] ⍝ map digits to values
+/map×1-2×(2</map),0 ⍝ subtractive principle
}</
{{out}}
Line 759:
(Functional ES5 version)
{{trans|Haskell}}
<syntaxhighlight lang="applescript">
------------- INTEGER VALUE OF A ROMAN STRING ------------
Line 934:
end if
end if
end uncons</
{{Out}}
<syntaxhighlight lang
====Fold right – subtracting or adding====
{{Works with|Yosemite onwards}}
{{trans|Haskell}}
<
----------- INTEGER VALUE OF ROMAN NUMBER STRING ---------
Line 1,050:
(its NSLocale's currentLocale())) as text
end tell
end toUpper</
{{Out}}
<
=={{header|Applesoft BASIC}}==
{{trans|BBC BASIC}}
<
20 GOSUB 100 PRINT "ROMAN NUMERALS DECODED"
30 LET R$ = "MMXII"
Line 1,086:
300 NEXT I
310 RETURN
320 DATA "IVXLCDM",0,1,5,10,50,100,500,1000</
=={{header|Arturo}}==
<
fromRoman: function [roman][
Line 1,105:
]
loop ["MCMXC" "MMVIII" "MDCLXVI"] 'r -> print [r "->" fromRoman r]</
{{out}}
Line 1,115:
=={{header|AutoHotkey}}==
{{works with|AutoHotkey_L}}
<
res := 0
Loop Parse, str
Line 1,130:
Loop Parse, test, |
res .= A_LoopField "`t= " Roman_Decode(A_LoopField) "`r`n"
clipboard := res</
{{out}}
<pre>MCMXC = 1990
Line 1,137:
=={{header|AWK}}==
<
BEGIN {
leng = split("MCMXC MMVIII MDCLXVI",arr," ")
Line 1,159:
}
return( (a>0) ? a : "" )
}</
{{out}}
<pre>
Line 1,169:
=={{header|BASIC256}}==
<
num = 0
prenum = 0
Line 1,195:
print "XXV = "; romToDec("XXV") #25
print "CMLIV = "; romToDec("CMLIV") #954
print "MMXI = "; romToDec("MMXI") #2011</
=={{header|Batch File}}==
{{trans|Fortran}}
<
setlocal enabledelayedexpansion
Line 1,244:
set lastval=!n!
)
goto :EOF</
{{Out}}
<pre>MCMXC = 1990
Line 1,253:
=={{header|BBC BASIC}}==
<
PRINT "MMXII", FNromandecode("MMXII")
PRINT "MDCLXVI", FNromandecode("MDCLXVI")
Line 1,268:
p% = j%
NEXT
= n%</
{{out}}
<pre>
Line 1,278:
=={{header|BCPL}}==
<
let roman(s) = valof
Line 1,306:
show("MMVII")
show("MMXXI")
$)</
{{out}}
<pre>MCMXC: 1990
Line 1,315:
=={{header|BQN}}==
<
c ← "IVXLCDM" # Characters
v ← ⥊ (10⋆↕4) ×⌜ 1‿5 # Their values
A ⇐ +´∘(⊢ׯ1⋆<⟜«) v ⊏˜ c ⊐ ⊢
}</
{{out|Example use}}
<
⟨ 1990 1666 2007 2021 ⟩</
=={{header|Bracmat}}==
{{trans|Icon and Unicon}}
<
= nbr,lastVal,val
. 0:?nbr:?lastVal
Line 1,366:
: ? (?L.?D) (?&test$!L&~)
| done
);</
{{out}}
<pre>M 1000
Line 1,381:
=={{header|C}}==
Note: the code deliberately did not distinguish between "I", "J" or "U", "V", doing what Romans did for fun.
<
int digits[26] = { 0, 0, 100, 500, 0, 0, 0, 0, 1, 1, 0, 50, 1000, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 10, 0, 0 };
Line 1,427:
return 0;
}</
=={{header|C sharp|C#}}==
<
using System.Collections.Generic;
Line 1,491:
}
}
}</
{{out}}
<pre>MCMXC: 1990
Line 1,499:
=={{header|C++}}==
<
#include <exception>
#include <string>
Line 1,550:
return 0;
}
</syntaxhighlight>
{{out}}
<PRE>MCMXC = 1990
Line 1,557:
=={{header|Ceylon}}==
<
value numerals = map {
Line 1,593:
assert(toHindu("MCMXC") == 1990);
assert(toHindu("MMVIII") == 2008);
}</
=={{header|Clojure}}==
<
;; Incorporated some improvements from the alternative implementation below
(defn ro2ar [r]
Line 1,611:
(map numerals)
(reduce (fn [[sum lastv] curr] [(+ sum curr (if (< lastv curr) (* -2 lastv) 0)) curr]) [0,0])
first))</
{{out}}
Line 1,618:
=={{header|CLU}}==
<
rep = null
Line 1,659:
end
end
end start_up</
{{out}}
<pre>MCMXC: 1990
Line 1,668:
=={{header|COBOL}}==
<syntaxhighlight lang="cobol">
IDENTIFICATION DIVISION.
PROGRAM-ID. UNROMAN.
Line 1,744:
.
END PROGRAM UNROMAN.
</syntaxhighlight>
{{out}} input was supplied via STDIN
<pre>
Line 1,785:
=={{header|CoffeeScript}}==
<
# s is well-formed Roman Numeral >= I
numbers =
Line 1,820:
dec = roman_to_demical(roman)
console.log "error" if dec != expected
console.log "#{roman} = #{dec}"</
=={{header|Common Lisp}}==
<
(defun mapcn (chars nums string)
(loop as char across string as i = (position char chars) collect (and i (nth i nums))))
Line 1,830:
(loop with nums = (mapcn "IVXLCDM" '(1 5 10 50 100 500 1000) R)
as (A B) on nums if A sum (if (and B (< A B)) (- A) A)))
</syntaxhighlight>
Description:
Line 1,845:
Test code:
<
(format t "~a:~10t~d~%" r (parse-roman r)))</
{{out}}
<pre>MCMXC: 1990
Line 1,854:
=={{header|Cowgol}}==
<
include "argv.coh";
Line 1,912:
print_i16(romanToDecimal(argmt));
print_nl();</
{{out}}
Line 1,923:
=={{header|D}}==
<
int toArabic(in string s) /*pure nothrow*/ {
Line 1,941:
assert("MMVIII".toArabic == 2008);
assert("MDCLXVI".toArabic == 1666);
}</
Alternative more functional version:
<
immutable uint[string] w2s;
Line 1,964:
assert("MMVIII".toArabic == 2008);
assert("MDCLXVI".toArabic == 1666);
}</
=={{header|Delphi}}/{{header|Pascal}}==
<
{$APPTYPE CONSOLE}
Line 2,010:
Writeln(RomanToInteger('MMVIII')); // 2008
Writeln(RomanToInteger('MDCLXVI')); // 1666
end.</
=={{header|EasyLang}}==
<syntaxhighlight lang="text">rom_digs$[] = [ "M" "D" "C" "L" "X" "V" "I" ]
rom_vals[] = [ 1000 500 100 50 10 5 1 ]
#
Line 2,036:
print v
call rom2int "MDCLXVI" v
print v</
=={{header|ECL}}==
The best declarative approach:
<syntaxhighlight lang="ecl">
MapChar(STRING1 c) := CASE(c,'M'=>1000,'D'=>500,'C'=>100,'L'=>50,'X'=>10,'V'=>5,'I'=>1,0);
Line 2,058:
RomanDecode('MMVIII'); //2008
RomanDecode('MDCLXVI'); //1666
RomanDecode('MDLXVI'); //1566</
Here's an alternative that emulates the wat procedural code would approach the problem:
<
RomanDecode(STRING s) := FUNCTION
SetWeights := [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
Line 2,100:
RomanDecode('MMVIII'); //2008
RomanDecode('MDCLXVI'); //1666
RomanDecode('MDLXVI'); //1566</
=={{header|Eiffel}}==
Line 2,106:
This solution is case insensitive. It performs no input validation other than checking that all Roman digits in the input string are one of <tt>M</tt>, <tt>D</tt>, <tt>C</tt>, <tt>L</tt>, <tt>X</tt>, <tt>V</tt>, and <tt>I</tt>.
<
APPLICATION
Line 2,216:
end
end</
=={{header|Elena}}==
ELENA 5.0 :
<
import system'collections;
import system'routines;
Line 2,264:
console.printLine("MMVIII: ", "MMVIII".toRomanInt());
console.printLine("MDCLXVI:", "MDCLXVI".toRomanInt())
}</
{{out}}
<pre>
Line 2,274:
=={{header|Elixir}}==
{{trans|Erlang}}
<
def decode([]), do: 0
def decode([x]), do: to_value(x)
Line 2,295:
Enum.each(['MCMXC', 'MMVIII', 'MDCLXVI', 'IIIID'], fn clist ->
IO.puts "#{clist}\t: #{Roman_numeral.decode(clist)}"
end)</
{{out}}
Line 2,305:
=={{header|Emacs Lisp}}==
<
"Translate a roman number RN into arabic number.
Its argument RN is wether a symbol, wether a list.
Line 2,320:
((null (cdr RN)) (ro2ar (car RN))) ;; stop recursion
((< (ro2ar (car RN)) (ro2ar (car (cdr RN)))) (- (ro2ar (cdr RN)) (ro2ar (car RN)))) ;; "IV" -> 5-1=4
(t (+ (ro2ar (car RN)) (ro2ar (cdr RN)))))) ;; "VI" -> 5+1=6</
{{out}}
Line 2,329:
Putting the character X into a list, [X], creates a string with a single character.
<syntaxhighlight lang="erlang">
-module( roman_numerals ).
Line 2,350:
{V1, _} -> V1 + decode_from_string([H2|Rest])
end.
</syntaxhighlight>
{{out}}
Line 2,363:
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
PROGRAM ROMAN2ARAB
Line 2,393:
TOARAB("MMMDCCCLXXXVIII"->ANS%) PRINT(ANS%)
END PROGRAM
</syntaxhighlight>
If the answer is -9999, roman number is illegal.
=={{header|Euphoria}}==
{{trans|PureBasic}}
<
function romanDec(sequence roman)
integer n, lastval, arabic
Line 2,422:
? romanDec("XXV")
? romanDec("CMLIV")
? romanDec("MMXI")</
{{out}}
<pre>1999
Line 2,432:
=={{header|F Sharp|F#}}==
This implementation uses tail recursion. The accumulator (arabic) and the last roman digit (lastval) are recursively passed as each element of the list is consumed.
<
let rec convert arabic lastval = function
| head::tail ->
Line 2,448:
| _ -> arabic + lastval
convert 0 0 (Seq.toList roman)
;;</
Here is an alternative implementation that uses Seq(uence).fold. It threads a Tuple of the state (accumulator, last roman digit) through the list of characters.
<
let convert (arabic,lastval) c =
let n = match c with
Line 2,466:
let (arabic, lastval) = Seq.fold convert (0,0) roman
arabic + lastval
;;</
Test code:
<
for test in tests do Printf.printf "%s: %d\n" test (decimal_of_roman test)
;;</
{{out}}
Line 2,483:
=={{header|Factor}}==
A roman numeral library ships with Factor.
<
( scratchpad ) "MMMCCCXXXIII" roman> .
3333</
Implementation for decoding:
<
{ "m" "cm" "d" "cd" "c" "xc" "l" "xl" "x" "ix" "v" "iv" "i" }
Line 2,508:
: roman-digit-value ( ch -- n )
roman-digit-index roman-values nth ;</
=={{header|FALSE}}==
<
$'m= $[\% 1000\]? ~[
$'d= $[\% 500\]? ~[
Line 2,531:
]#
%+. {add final digit to accumulator and output}
10, {and a newline}</
{{out}}
Line 2,545:
=={{header|Forth}}==
<
1000 128 * char M + ,
500 128 * char D + ,
Line 2,570:
;
s" MCMLXXXIV" >arabic .</
<
\ create words to describe and solve the problem
\ ANS/ISO Forth
Line 2,633:
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<
implicit none
Line 2,673:
end do
end function decode
end program Roman_decode</
{{out}}
<pre> 1990 2008 1666</pre>
=={{header|FreeBASIC}}==
<
Function romanDecode(roman As Const String) As Integer
Line 2,739:
Print
Print "Press any key to quit"
Sleep</
{{out}}
Line 2,749:
=={{header|FutureBasic}}==
<
local fn RomantoDecimal( roman as CFStringRef ) as long
Line 2,781:
print @" XXXIII = "; fn RomantoDecimal( @"XXXIII" )
HandleEvents</
Output:
Line 2,797:
=={{header|Gambas}}==
<
'The input is case insensitive
'A basic check for invalid charaters is made
Line 2,868:
hValueBox.ReadOnly = True 'Set ValueBox to Read Only
End</
'''[http://www.cogier.com/gambas/Roman%20Numeral%20converter.png Click here for image of running code]'''
=={{header|Go}}==
For fluff, the unicode overbar is recognized as a factor of 1000, [http://en.wikipedia.org/wiki/Roman_numerals#Large_numbers as described in WP].
<
import (
Line 2,956:
}
}
}</
{{out}}
<pre>
Line 2,965:
Simpler:
<
import (
Line 3,001:
fmt.Printf("%-10s == %d\n", roman_digit, from_roman(roman_digit))
}
}</
=={{header|Golo}}==
<
----
This module converts a Roman numeral into a decimal number.
Line 3,050:
println("MDCLXVI = " + "MDCLXVI": decode())
}
</syntaxhighlight>
=={{header|Groovy}}==
Solution:
<
I(1), V(5), X(10), L(50), C(100), D(500), M(1000);
Line 3,073:
}
}
}</
Test:
<
Digit Values = ${RomanDigits.values()}
M => ${RomanDigits.parse('M')}
Line 3,086:
MCDXLIV => ${RomanDigits.parse('MCDXLIV')}
MDCLXVI => ${RomanDigits.parse('MDCLXVI')}
"""</
{{out}}
<pre>Digit Values = [I=1, V=5, X=10, L=50, C=100, D=500, M=1000]
Line 3,105:
Compiles with GHC.
<syntaxhighlight lang="haskell">
module Main where
Line 3,151:
arabic = decode roman
remark = " (" ++ (if arabic == expected then "PASS" else ("FAIL, expected " ++ (show expected))) ++ ")"
</syntaxhighlight>
{{Out}}
Line 3,162:
====Same logic as above but in a functional idiom====
<syntaxhighlight lang="haskell">
module Main where
Line 3,203:
arabic = decode roman
remark = " (" ++ (if arabic == expected then "PASS" else ("FAIL, expected " ++ (show expected))) ++ ")"
</syntaxhighlight>
====List comprehension====
<
mapping = [("M",1000),("CM",900),("D",500),("CD",400),("C",100),("XC",90),
Line 3,214:
toArabic "" = 0
toArabic str = num + toArabic xs
where (num, xs):_ = [ (num, drop (length n) str) | (n,num) <- mapping, isPrefixOf n str ]</
Usage:
<pre>
Line 3,226:
====mapAccum====
Or, expressing '''romanValue''' in terms of '''mapAccumL''' (avoiding recursive descent, and visiting each k v pair just once)
<
import Data.List (isPrefixOf, mapAccumL)
Line 3,264:
"MMXVI",
"MMXVII"
]</
Or, in a '''mapAccumR''' version:
<
import qualified Data.Map.Strict as M
import Data.Maybe (maybe)
Line 3,331:
where
rjust n c = drop . length <*> (replicate n c <>)
w = maximum (length . xShow <$> xs)</
{{Out}}
<pre>Decoding Roman numbers:
Line 3,345:
An alternative solution using a fold. (This turns out to be the fastest of the four approaches here) {{Trans|F#}}
<
fromRoman :: String -> Int
Line 3,375:
main :: IO ()
main = print $ fromRoman <$> ["MDCLXVI", "MCMXC", "MMVIII", "MMXVI", "MMXVII"]</
Where the left fold above could also be rewritten [http://wiki.haskell.org/Foldr_Foldl_Foldl%27 | as a right fold].
<
import Data.Maybe (maybe)
Line 3,437:
where
rjust n c = drop . length <*> (replicate n c <>)
w = maximum (length . xShow <$> xs)</
{{Out}}
<pre>Roman numeral decoding as a right fold:
Line 3,454:
(Probably more trouble than it's worth in practice, but at least an illustration of some Data.Maybe and Data.Map functions)
<
import Data.Maybe (isNothing, isJust, fromJust, catMaybes)
import Data.List (mapAccumL)
Line 3,492:
main :: IO ()
main = print $ fromRoman <$> ["MDCLXVI", "MCMXC", "MMVIII", "MMXVI", "MMXVII"]</
{{Out}}
<pre>[1666,1990,2008,2016,2017]</pre>
=={{header|Icon}} and {{header|Unicon}}==
<
procedure main()
every R := "MCMXC"|"MDCLXVI"|"MMVIII" do
write(R, " = ",unroman(R))
end</
{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/numbers.icn numbers.icn provides unroman]
The code for this procedure is copied below:
<
local nbr,lastVal,val
Line 3,526:
}
return nbr
end</
{{out}}
<pre>MCMXC = 1990
Line 3,533:
=={{header|J}}==
<
Example use:
<
1990
rom2d 'MDCLXVI'
1666
rom2d 'MMVIII'
2008</
=={{header|Java}}==
{{works with|Java|1.5+}}
<
private static int decodeSingle(char letter) {
switch(letter) {
Line 3,580:
System.out.println(decode("MDCLXVI")); //1666
}
}</
{{out}}
<pre>1990
Line 3,586:
1666</pre>
{{works with|Java|1.8+}}
<
import java.util.EnumSet;
import java.util.Collections;
Line 3,644:
LongStream.of(1999, 25, 944).forEach(RomanNumerals::test);
}
}</
{{out}}
<pre>1999 = MCMXCIX
Line 3,658:
{{works with|Rhino}}
{{works with|SpiderMonkey}}
<
Values: [['CM', 900], ['CD', 400], ['XC', 90], ['XL', 40], ['IV', 4],
['IX', 9], ['V', 5], ['X', 10], ['L', 50],
Line 3,683:
var test_datum = test_data[i]
print(test_datum + ": " + Roman.parse(test_datum))
}</
{{out}}
<pre>MCMXC: 1990
Line 3,692:
{{Trans|Haskell}}
(isPrefixOf example)
<
var mapping = [["M", 1000], ["CM", 900], ["D", 500], ["CD", 400], ["C", 100], [
Line 3,739:
return lstTest.map(romanValue);
})(['MCMXC', 'MDCLXVI', 'MMVIII']);</
{{Out}}
<syntaxhighlight lang
or, more natively:
<
function romanValue(s) {
Line 3,774:
return lstTest.map(romanValue);
})(["MCMXC", "MDCLXVI", "MMVIII", "MMMM"]);</
{{Out}}
<syntaxhighlight lang
===ES6===
====Recursion====
<
// romanValue :: String -> Int
const romanValue = s =>
Line 3,814:
// TEST -------------------------------------------------------------------
return ["MCMXC", "MDCLXVI", "MMVIII", "MMMM"].map(romanValue);
})();</
{{Out}}
<syntaxhighlight lang
Line 3,822:
{{Trans|Haskell}}
(fold and foldr examples)
<
// -------------- ROMAN NUMERALS DECODED ---------------
Line 3,877:
// MAIN ---
return main();
})();</
{{Out}}
<pre>1666
Line 3,888:
{{works with|jq|1.4}}
This version requires the Roman numerals to be presented in upper case.
<
def addRoman(n):
if length == 0 then n
Line 3,907:
error("invalid Roman numeral: " + tostring)
end;
addRoman(0);</
'''Example:'''
<
{{out}}
<
MCMXC => 1990
MMVIII => 2008
MDCLXVI => 1666</
=={{header|Jsish}}==
Line 3,926:
{{works with|Julia|0.6}}
'''The Function''':
<
romandigits = Dict('I' => 1, 'V' => 5, 'X' => 10, 'L' => 50,
'C' => 100, 'D' => 500, 'M' => 1000)
Line 3,944:
end
return accm
end</
This function is rather permissive. There are no limitations on the numbers of Roman numerals nor on their order. Because of this and because any out of order numerals subtract from the total represented, it is possible to represent zero and negative integers. Also mixed case representations are allowed. The function does throw an error if the string contains any invalid characters.
'''Test the code''':
<
test = ["I", "III", "IX", "IVI", "IIM",
Line 3,956:
for rnum in test
@printf("%15s → %s\n", rnum, try parseroman(rnum) catch "not valid" end)
end</
{{out}}
Line 3,977:
=={{header|K}}==
{{trans|J}}
<
'''Example:'''
<
1990 2008 1666</
=={{header|Kotlin}}==
As specified in the task description, there is no attempt to validate the form of the Roman number in the following program - invalid characters and ordering are simply ignored:
<
fun romanDecode(roman: String): Int {
Line 4,008:
val romans = arrayOf("I", "III", "IV", "VIII", "XLIX", "CCII", "CDXXXIII", "MCMXC", "MMVIII", "MDCLXVI")
for (roman in romans) println("${roman.padEnd(10)} = ${romanDecode(roman)}")
}</
{{out}}
Line 4,025:
=={{header|Lasso}}==
<
//decode roman
define decodeRoman(roman::string)::integer => {
Line 4,047:
'MMVIII as integer is '+decodeRoman('MMVIII')
br
'MDCLXVI as integer is '+decodeRoman('MDCLXVI')</
=={{header|Liberty BASIC}}==
As Fortran & PureBasic.
<
print "MDCLXVI = "; romanDec( "MDCLXVI") '1666
print "XXV = "; romanDec( "XXV") '25
Line 4,093:
romanDec =arabic
end function</
<pre>
MCMXCIX = 1999
Line 4,104:
=={{header|LiveScript}}==
<
# String → Number
Line 4,116:
fold(_convert, [0, 0]) >> sum
{[rom, decimal_of_roman rom] for rom in <[ MCMXC MMVII MDCLXVII MMMCLIX MCMLXXVII MMX ]>}</
Output:
Line 4,122:
=={{header|Logo}}==
<
; First, some useful substring utilities
Line 4,156:
foreach [MCMXC MDCLXVI MMVIII] [print (sentence (word ? "|: |) from_roman ?)]
bye</
{{out}}
<pre>MCMXC: 1990
Line 4,164:
=={{header|Lua}}==
<
local Num = { ["M"] = 1000, ["D"] = 500, ["C"] = 100, ["L"] = 50, ["X"] = 10, ["V"] = 5, ["I"] = 1 }
local numeral = 0
Line 4,188:
print( ToNumeral( "MCMXC" ) )
print( ToNumeral( "MMVIII" ) )
print( ToNumeral( "MDCLXVI" ) )</
<pre>1990
2008
Line 4,196:
Maximum Roman number is MMMCMXCIX (3999)
<syntaxhighlight lang="m2000 interpreter">
Module RomanNumbers {
flush ' empty current stack
Line 4,273:
RomanNumbers
</syntaxhighlight>
{{out}}
Line 4,304:
=={{header|Maple}}==
<
seq(printf("%a\n", f(i)), i in [MCMXC, MMVIII, MDCLXVI]);</
{{out}}
<pre>
Line 4,314:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
{{out}}
<pre>2405</pre>
=={{header|MATLAB}}==
<
% ROM2DEC converts Roman numbers to decimal
Line 4,329:
x = sum(values .* [sign(diff(-values)+eps),1]);
end</
Here is a test:
<
for n = 1 : numel(romanNumbers)
fprintf('%10s = %4d\n',romanNumbers{n}, rom2dec(romanNumbers{n}));
end</
{{out}}
<pre>
Line 4,343:
=={{header|Mercury}}==
<
:- interface.
Line 4,391:
Args, !IO).
:- end_module test_roman.</
=={{header|Modula-2}}==
<
FROM InOut IMPORT WriteString, WriteCard, WriteLn;
FROM Strings IMPORT Length;
Line 4,445:
Show("mmvii");
Show("mmxxi");
END RomanNumerals.</
{{out}}
<pre>MCMXC: 1990
Line 4,454:
=={{header|Nanoquery}}==
{{trans|Java}}
<
if letter = "M"
return 1000
Line 4,492:
println decode("MCMXC")
println decode("MMVIII")
println decode("MDCLXVI")</
{{out}}
<pre>1990
Line 4,499:
=={{header|NetRexx}}==
<
options replace format comments java crossref savelog symbols binary
Line 4,547:
end
return digit</
{{out}}
<pre>
Line 4,557:
=={{header|Nim}}==
{{trans|Python}}
<
let rdecode = {'M': 1000, 'D': 500, 'C': 100, 'L': 50, 'X': 10, 'V': 5, 'I': 1}.toTable
Line 4,568:
for r in ["MCMXC", "MMVIII", "MDCLXVI"]:
echo r, " ", decode(r)</
{{out}}
Line 4,576:
=={{header|OCaml}}==
<
let arabic = ref 0 in
let lastval = ref 0 in
Line 4,602:
Printf.printf " %d\n" (decimal_of_roman "MMVIII");
Printf.printf " %d\n" (decimal_of_roman "MDCLXVI");
;;</
=== Another implementation ===
Another implementation, a bit more OCaml-esque: no mutable variables, and a recursive function instead of a for loop.
{{works with|OCaml|4.03+}}
<
(* Scan the roman number from right to left. *)
(* When processing a roman digit, if the previously processed roman digit was
Line 4,664:
print_endline (testit "2 * PI ^ 2" 1); (* The I in PI... *)
print_endline (testit "E = MC^2" 1100)
</syntaxhighlight>
Output:
<pre>
Line 4,686:
=={{header|PARI/GP}}==
<
my(v=Vecsmall(s),key=vector(88),cur,t=0,tmp);
key[73]=1;key[86]=5;key[88]=10;key[76]=50;key[67]=100;key[68]=500;key[77]=1000;
Line 4,702:
);
t+cur
};</
=={{header|Perl}}==
<
{
Line 4,729:
}
say "$_: ", from_roman($_) for qw(MCMXC MDCLXVI MMVIII);</
{{out}}
<pre>MCMXC: 1990
Line 4,735:
MMVIII: 2008</pre>
=== Alternate ===
<
use strict;
Line 4,754:
MCMXC
MMVIII
MDCLXVI</
{{out}}
<pre>
Line 4,762:
</pre>
=== Another Alternate ===
<
use strict;
Line 4,787:
MCMXC
MMVIII
MDCLXVI</
{{out}}
<pre>
Line 4,796:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">function</span> <span style="color: #000000;">romanDec</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">romans</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"MDCLXVI"</span><span style="color: #0000FF;">,</span>
Line 4,812:
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"MCMXC"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"MMVIII"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"MDCLXVI"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">romanDec</span><span style="color: #0000FF;">)</span>
<!--</
{{out}}
<pre>
Line 4,819:
=={{header|Phixmonti}}==
<
0 >ps 0 >ps
( ( "M" 1000 ) ( "D" 500 ) ( "C" 100 ) ( "L" 50 ) ( "X" 10 ) ( "V" 5 ) ( "I" 1 ) )
Line 4,840:
enddef
/# usage example: "MMXX" romanDec ? (show 2020) #/</
More traditional solution:
<
( 1000 500 100 50 10 5 1 ) var decmls
Line 4,865:
drop
res
enddef</
=={{header|PHP}}==
<
/**
* @author Elad Yosifon
Line 4,953:
{
echo "($key == {$value[0]}) => " . ($value[0] === $value[1] ? "true" : "false, should be {$value[1]}.") . "\n";
}</
{{out}}
<pre>
Line 4,979:
=={{header|Picat}}==
<
List = ["IV",
"XLII",
Line 5,022:
roman('C', 100).
roman('D', 500).
roman('M', 1000).</
{{out}}
Line 5,040:
=={{header|PicoLisp}}==
<
(let L (replace (chop Rom) 'M 1000 'D 500 'C 100 'L 50 'X 10 'V 5 'I 1)
(sum '((A B) (if (>= A B) A (- A))) L (cdr L)) ) )</
Test:
<pre>: (roman2decimal "MCMXC")
Line 5,054:
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
test_decode: procedure options (main); /* 28 January 2013 */
declare roman character (20) varying;
Line 5,101:
end test_decode;
</syntaxhighlight>
<pre>
i 1
Line 5,125:
=={{header|PL/M}}==
<
/* CP/M CALLS */
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
Line 5,185:
CALL PRINT$NUMBER(READ$ROMAN(.ARG(1))); /* CONVERT AND PRINT VALUE */
CALL EXIT;
EOF</
{{out}}
Line 5,200:
=={{header|PL/SQL}}==
<syntaxhighlight lang="pl/sql">
/*****************************************************************
* $Author: Atanas Kebedjiev $
Line 5,284:
END;
</syntaxhighlight>
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
Filter FromRoman {
$output = 0
Line 5,321:
$output
}
</syntaxhighlight>
<syntaxhighlight lang="powershell">
'XIX','IV','','MMCDLXXIX','MMMI' | FromRoman
</syntaxhighlight>
{{Out}}
<pre>
Line 5,335:
=={{header|Prolog}}==
<
decode_digit(v, 5).
decode_digit(x, 10).
Line 5,366:
decode_string(mcmxc, 1990),
decode_string(mmviii, 2008),
decode_string(mdclxvi, 1666).</
The program above contains its own test predicate.
The respective goal succeeds.
Line 5,372:
=={{header|PureBasic}}==
<
Protected i, n, lastval, arabic
Line 5,414:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</
{{out}}
<pre>1999
Line 5,424:
=={{header|Python}}==
===Imperative===
<
def decode( roman ):
Line 5,435:
if __name__ == '__main__':
for r in 'MCMXC MMVIII MDCLXVI'.split():
print( r, decode(r) )</
{{out}}
<pre>MCMXC 1990
Line 5,442:
Another version, which I believe has clearer logic:
<
('CD', 400), ('D', 500), ('CM', 900), ('M',1000))
Line 5,456:
for value in "MCMXC", "MMVIII", "MDCLXVI":
print('%s = %i' % (value, roman_value(value)))
</syntaxhighlight>
{{out}}
<pre>
Line 5,467:
===Declarative===
Less clear, but a 'one liner':
<
def romannumeral2number(s):
return reduce(lambda x, y: -x + y if x < y else x + y, map(lambda x: numerals.get(x, 0), s.upper()))</
Line 5,476:
{{Trans|Haskell}}
{{Works with|Python|3}}
<
from operator import mul
Line 5,586:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>Roman numerals decoded:
Line 5,598:
=={{header|QBasic}}==
<
num = 0
prenum = 0
Line 5,624:
PRINT "XXV = "; romToDec("XXV") '25
PRINT "CMLIV = "; romToDec("CMLIV") '954
PRINT "MMXI = "; romToDec("MMXI") '2011</
=={{header|Quackery}}==
<
if
[ dip
Line 5,658:
$ "I MIX VIVID MILD MIMIC"
dup echo$ say " = " ->arabic echo cr
</syntaxhighlight>
{{Out}}
Line 5,669:
=={{header|QB64}}==
<syntaxhighlight lang="qb64">
SCREEN _NEWIMAGE(400, 600, 32)
Line 5,730:
END FUNCTION
</syntaxhighlight>
=={{header|R}}==
Line 5,736:
===version 1===
Modelled along the lines of other decode routines on this page, but using a vectorised approach
<
romanLookup <- c(I=1L, V=5L, X=10L, L=50L, C=100L, D=500L, M=1000L)
rSplit <- strsplit(toupper(roman), character(0)) # Split input vector into characters
Line 5,748:
}
vapply(rSplit, toArabic, integer(1))
}</
Example usage:
<
===version 2===
Using built-in functionality in R
<
=={{header|Racket}}==
<
(define (decode/roman number)
(define letter-values
Line 5,775:
(map decode/roman '("MCMXC" "MMVIII" "MDCLXVI"))
;-> '(1990 2008 1666)</
=={{header|Raku}}==
(formerly Perl 6)
A non-validating version:
<syntaxhighlight lang="raku"
[+] gather $r.uc ~~ /
^
Line 5,802:
}
say "$_ => &rom-to-num($_)" for <MCMXC MDCLXVI MMVIII>;</
{{out}}
<pre>MCMXC => 1990
Line 5,808:
MMVIII => 2008</pre>
A validating version. Also handles older forms such as 'IIXX' and "IIII".
<syntaxhighlight lang="raku"
[+] gather $r.uc ~~ /
^
Line 5,822:
}
say "$_ => ", rom-to-num($_) for <MCMXC mdclxvi MMViii IIXX ILL>;</
{{out}}
<pre>MCMXC => 1990
Line 5,833:
===version 1===
<
Purpose: "Arabic <-> Roman numbers converter"
Author: "Didier Cadieu"
Line 5,851:
print roman-to-arabic "MDCCCLXXXVIII"
print roman-to-arabic "MMXVI"
</syntaxhighlight>
=={{header|REXX}}==
Line 5,859:
{{Works with|ooRexx}}
<
Do
Line 5,921:
Return digit
End
Exit</
{{out}}
<pre>
Line 5,941:
:::* the '''j''' and '''u''' numerals
:::* (deep) parenthesis type Roman numbers
<
rYear = 'MCMXC' ; say right(rYear, 9)":" rom2dec(rYear)
rYear = 'mmviii' ; say right(rYear, 9)":" rom2dec(rYear)
Line 5,966:
if _=='D' then return 500
if _=='M' then return 1000
return 0 /*indicate an invalid Roman numeral. */</
===version 3===
Line 5,988:
<br>Also note that '''IIII''' is a legal Roman numeral construct; (as demonstrated by almost any old clock or
<br>"dialed" wristwatch that has Roman numerals).
<
numeric digits 1000 /*so we can handle the big numbers. */
parse arg z /*obtain optional arguments from the CL*/
Line 6,013:
else #=#+_ /* else add. */
end /*k*/
return # /*return Arabic number. */</
'''output''' when using the default inputs:
<pre>
Line 6,027:
=={{header|Ring}}==
<
symbols = "MDCLXVI"
weights = [1000,500,100,50,10,5,1]
Line 6,049:
next
return arabic
</syntaxhighlight>
=={{header|Ruby}}==
<
r = roman.upcase
n = 0
Line 6,079:
end
[ "MCMXC", "MMVIII", "MDCLXVI" ].each {|r| p r => fromRoman(r)}</
{{out}}
Line 6,088:
</pre>
or
<
['L', 50], ['XL', 40], ['X', 10], ['IX', 9], ['V', 5], ['IV', 4], ['I', 1] ]
Line 6,098:
end
[ "MCMXC", "MMVIII", "MDCLXVI" ].each {|r| puts "%8s :%5d" % [r, parseRoman(r)]}</
{{out}}
Line 6,108:
=={{header|Run BASIC}}==
<
print "MDCLXVI = "; romToDec( "MDCLXVI") '1666
print "XXV = "; romToDec( "XXV") '25
Line 6,131:
romToDec =num
end function</
=={{header|Rust}}==
<
symbol: &'static str,
value: u32
Line 6,168:
println!("{:2$} = {}", r, to_hindu(r), 15);
}
}</
{{out}}
<pre>MMXIV = 2014
Line 6,177:
=={{header|Scala}}==
<
val arabicNumerals = List("CM"->900,"M"->1000,"CD"->400,"D"->500,"XC"->90,"C"->100,
"XL"->40,"L"->50,"IX"->9,"X"->10,"IV"->4,"V"->5,"I"->1)
Line 6,202:
test("MCMXC")
test("MMVIII")
test("MDCLXVI")</
{{out}}
<pre>MCMXC => 1990
Line 6,212:
{{works with|Gauche Scheme}}
<
(define (char-val char)
Line 6,224:
0 0
(map char-val (reverse (string->list roman)))))
</syntaxhighlight>
<b>Testing:</b>
<
(^s (format #t "~7d: ~d\n" s (decode s)))
'("MCMLVI" "XXC" "MCMXC" "XXCIII" "IIIIX" "MIM" "LXXIIX"))
</syntaxhighlight>
{{out}}
<pre>
Line 6,243:
=={{header|Seed7}}==
<
const func integer: ROMAN parse (in string: roman) is func
Line 6,278:
writeln(ROMAN parse "MMVIII");
writeln(ROMAN parse "MDCLXVI");
end func;</
Original source: [http://seed7.sourceforge.net/algorith/puzzles.htm#decode_roman_numerals]
{{out}}
Line 6,288:
=={{header|SenseTalk}}==
<
put {
"M": 1000,
Line 6,308:
end repeat
return total
end RomanNumeralsDecode</
<
"MCMXC",
"MMVIII",
Line 6,317:
put RomanNumeralsDecode(it)
end repeat
</syntaxhighlight>
{{out}}
Line 6,327:
=={{header|Sidef}}==
<
var arabic = 0
Line 6,354:
%w(MCMXC MMVIII MDCLXVI).each { |roman_digit|
"%-10s == %d\n".printf(roman_digit, roman2arabic(roman_digit))
}</
{{out}}
<pre>
Line 6,363:
Simpler solution:
<
digit.uc.trans([
:M: '1000+',
Line 6,383:
%w(MCMXC MMVIII MDCLXVI).each { |roman_num|
say "#{roman_num}\t-> #{roman2arabic(roman_num)}";
}</
{{out}}
<pre>
Line 6,392:
=={{header|Simula}}==
<
INTEGER PROCEDURE FROMROMAN(S); TEXT S;
Line 6,437:
END PROGRAM;
</syntaxhighlight>
{{out}}
<pre>
Line 6,446:
=={{header|SNOBOL4}}==
<
define('arabic(n)s,ch,val,sum,x') :(arabic_end)
arabic s = 'M1000 D500 C100 L50 X10 V5 I1 '
Line 6,462:
astr = astr r '=' arabic(r) ' ' :(tloop)
out output = astr
end</
{{out}}
<pre>MMX=2010 MCMXCIX=1999 MCDXCII=1492 MLXVI=1066 CDLXXVI=476</pre>
Here's an alternative version, which is maybe more SNOBOL4-idiomatic and less like one might program it in a more common language:
<
define("arabic1(romans,arabic1)rdigit,adigit,b4")
romans1 = " 0 IX9 IV4 III3 II2 I1 VIII8 VII7 VI6 V5" :(arabic1_end)
Line 6,480:
astr = astr r '=' arabic1(r) ' ' :(tloop)
out output = astr
end</
The output is the same as in the earlier version.
Line 6,486:
This allows removing several labels and explicit transfers of control, and moves some of the looping into the pattern matcher.
Again, the output is the same.
<
define("arabic1(romans,arabic1)rdigit,adigit,b4")
romans1 = " 0 IX9 IV4 III3 II2 I1 VIII8 VII7 VI6 V5" :(arabic1_end)
Line 6,498:
tstr span(' ') break(' ') $ r *?(astr = astr r '=' arabic1(r) ' ') fail
output = astr
end</
=={{header|SPL}}==
<
n = [1,5,10,50,100,500,1000]
a,m = 0
Line 6,516:
> i, 1..#.size(t,1)
#.output(t[i]," = ",r2a(t[i]))
<</
{{out}}
<pre>
Line 6,529:
=={{header|Swift}}==
<
init(romanNumerals: String) {
let values = [
Line 6,557:
}
}
</syntaxhighlight>
{{output}}
<
=={{header|Tailspin}}==
<
def digits: [(M:1000"1"), (CM:900"1"), (D:500"1"), (CD:400"1"), (C:100"1"), (XC:90"1"), (L:50"1"), (XL:40"1"), (X:10"1"), (IX:9"1"), (V:5"1"), (IV:4"1"), (I:1"1")];
composer decodeRoman
Line 6,578:
' -> !OUT::write
'MDCLXVI' -> decodeRoman -> !OUT::write
</syntaxhighlight>
{{out}}
<pre>
Line 6,588:
=={{header|Tcl}}==
As long as we assume that we have a valid roman number, this is most easily done by transforming the number into a sum and evaluating the expression:
<
set map {M 1000+ CM 900+ D 500+ CD 400+ C 100+ XC 90+ L 50+ XL 40+ X 10+ IX 9+ V 5+ IV 4+ I 1+}
expr [string map $map $rnum]0}
}</
Demonstrating:
<
puts "$r\t-> [fromRoman $r]"
}</
{{out}}
<pre>MCMXC -> 1990
Line 6,602:
=={{header|TechBASIC}}==
<syntaxhighlight lang="techbasic">
Main:
Line 6,652:
END FUNCTION
</syntaxhighlight>
{{out}}
Line 6,674:
=={{header|TI-83 BASIC}}==
Using the Rom‣Dec function "real(21," from [http://www.detachedsolutions.com/omnicalc/ Omnicalc].
<
:Input Str1
:Disp real(21,Str1)</
Using TI-83 BASIC
<
:Input "ROMAN:",Str1
:{1000,500,100,50,10,5,1}➞L1
Line 6,698:
:N➞P
:End
:Disp Y</
=={{header|TMG}}==
Unix TMG dialect. Version without validation:
<
roman: string(!<<MDCLXVI>>) [n=0] num
letter: num/render letter;
Line 6,720:
render: decimal(n) = { 1 * };
n: 0;</
Unix TMG dialect. Version with validation:
<
parse(line)\loop
parse(error)\loop;
Line 6,758:
off:0;
wsz:0;
v1: 0; v2: 0; v3: 0;</
Sample input:
Line 6,779:
=={{header|True BASIC}}==
<
LET num = 0
LET prenum = 0
Line 6,805:
PRINT "CMLIV = "; romToDec("CMLIV") !954
PRINT "MMXI = "; romToDec("MMXI") !2011
END</
=={{header|TUSCRIPT}}==
<
LOOP roman_number="MCMXC'MMVIII'MDCLXVI"
arab_number=DECODE (roman_number,ROMAN)
PRINT "Roman number ",roman_number," equals ", arab_number
ENDLOOP</
{{out}}
<pre>
Line 6,821:
=={{header|UNIX Shell}}==
<
#!/bin/bash
Line 6,857:
roman_to_dec MMVIII
roman_to_dec MDCLXVI
</syntaxhighlight>
=={{header|VBA}}==
Convert Romans (i.e : XVI) in integers
<syntaxhighlight lang="vb">
Option Explicit
Line 6,896:
End If
End Function
</syntaxhighlight>
{{out}}
<pre>III >>> 3
Line 6,919:
=={{header|VBScript}}==
{{trans|360 Assembly}}
<
Function toRoman(ByVal value)
Line 6,939:
code=MsgBox(n & vbCrlf & toRoman(n),vbOKOnly+vbExclamation,"Roman numerals/Encode")
If code=vbOK Then ok=1
</syntaxhighlight>
{{out}}
<pre>
Line 6,967:
=={{header|Vedit macro language}}==
<
//
do {
Line 7,004:
Reg_Empty(11)
Buf_Quit(OK)
Return</
{{out}}
<pre>iv = 4
Line 7,015:
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
<
var decode = Fn.new { |r|
Line 7,045:
var romans = ["I", "III", "IV", "VIII", "XLIX", "CCII", "CDXXXIII", "MCMXC", "MMVIII", "MDCLXVI"]
for (r in romans) System.print("%(Fmt.s(-10, r)) = %(decode.call(r))")</
{{out}}
Line 7,063:
=={{header|XLISP}}==
Uses basic list processing and recursion. Probably not amazingly fast, but quite concise and hopefully clear.
<
(define roman '((#\m 1000) (#\d 500) (#\c 100) (#\l 50) (#\x 10) (#\v 5) (#\i 1)))
(defun to-arabic (rn rs a)
Line 7,072:
(+ a (cadar rs)) ) ) )
(t (to-arabic rn (cdr rs) a)) ) )
(to-arabic (string->list r) roman 0) )</
Test it in a REPL:
<
(1990 2008 1666)</
=={{header|XPL0}}==
<
code CrLf=9, IntOut=11;
Line 7,105:
IntOut(0, Roman("MMVIII")); CrLf(0);
IntOut(0, Roman("MDCLXVI")); CrLf(0);
]</
{{out}}
Line 7,115:
=={{header|XQuery}}==
<syntaxhighlight lang="xquery">
xquery version "3.1";
Line 7,163:
}
)
</syntaxhighlight>
=={{header|Yabasic}}==
<
decmls$ = "1000,500,100,50,10,5,1"
Line 7,195:
? romanDec("MMIX") // 2009
? romanDec("MDCLXVI") // 1666
? romanDec("MMMDCCCLXXXVIII") // 3888</
=={{header|zkl}}==
<
L("M", 1000), L("CM", 900), L("D", 500), L("CD", 400), L("C", 100),
L("XC", 90), L("L", 50), L("XL", 40), L("X", 10), L("IX", 9),
Line 7,213:
}
return(value);
}</
<pre>
toArabic("MCMXC") //-->1990
Line 7,223:
=={{header|Zoea}}==
<syntaxhighlight lang="zoea">
program: roman_decimal
input: 'XIII'
output: 13
</syntaxhighlight>
=={{header|Zoea Visual}}==
Line 7,233:
=={{header|zsh}}==
<
#!/bin/zsh
function parseroman () {
Line 7,254:
parseroman MMVIII
parseroman MDCLXVI
</syntaxhighlight>
|