Task

Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero.



In Roman numerals:

 1990 is rendered: 1000=M, 900=CM, 90=XC; resulting in MCMXC
 2008 is written as 2000=MM, 8=VIII; or MMVIII
 1666 uses each Roman symbol in descending order: MDCLXVI


get "libhdr"
 
let toroman(n, v) = valof
$(  let extract(n, val, rmn, v) = valof
    $(  while n >= val
        $(  n := n - val;
            for i=1 to rmn%0 do v%(v%0+i) := rmn%i
            v%0 := v%0 + rmn%0
        $)
        resultis n
    $)
 
    v%0 := 0
    n := extract(n, 1000, "M",  v)
    n := extract(n,  900, "CM", v)
    n := extract(n,  500, "D",  v)
    n := extract(n,  400, "CD", v)
    n := extract(n,  100, "C",  v)
    n := extract(n,   90, "XC", v)
    n := extract(n,   50, "L",  v)
    n := extract(n,   40, "XL", v)
    n := extract(n,   10, "X",  v)
    n := extract(n,    9, "IX", v)
    n := extract(n,    5, "V",  v)
    n := extract(n,    4, "IV", v)
    n := extract(n,    1, "I",  v)
    resultis v
$)
 
let show(n) be
$(  let v = vec 50
    writef("%I4 = %S*N", n, toroman(n, v))
$)
 
let start() be
$(  show(1666)
    show(2008)
    show(1001)
    show(1999)
    show(3888)
    show(2021)
$)