#!/usr/bin/ruby

# Translation of: https://rosettacode.org/wiki/Roman_numerals/Encode#ActionScript

func arabic2roman(num, roman='') {

    static lookup = [
        :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
    ];

    lookup.each { |pair|
        while (num >= pair.second) {
            roman += pair.first;
            num -= pair.second;
        }
    }
    return roman;
}

assert_eq(arabic2roman(1990), 'MCMXC');
assert_eq(arabic2roman(2008), 'MMVIII');
assert_eq(arabic2roman(1666), 'MDCLXVI');

say "** Test passed!";
