Roman numerals/Encode: Difference between revisions
Content added Content deleted
(Fixed two Red examples) |
Not a robot (talk | contribs) (Add Miranda) |
||
Line 5,037: | Line 5,037: | ||
Its output is identical to that of the previous version. |
Its output is identical to that of the previous version. |
||
=={{header|Miranda}}== |
|||
<syntaxhighlight lang="miranda">main :: [sys_message] |
|||
main = [ Stdout (show n ++ ": " ++ toroman n ++ "\n") |
|||
| n <- [1990, 2008, 1666, 2023]] |
|||
toroman :: num->[char] |
|||
toroman 0 = "" |
|||
toroman n = d ++ toroman (n - v) |
|||
where digits = [("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)] |
|||
(d, v) = hd [(d,v) | (d,v) <- digits; v <= n]</syntaxhighlight> |
|||
{{out}} |
|||
<pre>1990: MCMXC |
|||
2008: MMVIII |
|||
1666: MDCLXVI |
|||
2023: MMXXIII</pre> |
|||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |