<commit_before><commit_msg>Arab to roman numerals<commit_after># Given an integer, convert it to a roman numeral.
#
# Input is guaranteed to be within the range from 1 to 3999.
# https://leetcode.com/submissions/detail/37733643/
#
# 3999 / 3999 test cases passed.
#   Status: Accepted
#   Runtime: 216 ms
#       
#       Submitted: 0 minutes ago
#

require 'test/unit'
extend Test::Unit::Assertions

def int_to_roman(num)
    romans = {1000 => "M", 
               900 => "CM",
               500 => "D",
               400 => "CD",
               100 => "C",
                90 => "XC",
                50 => "L",
                40 => "XL",
                10 => "X",
                 9 => "IX",
                 5 => "V",
                 4 => "IV",
                 1 => "I"}

    return romans.keys.inject("") { |acc, c|
        while num >= c
            acc += romans[c]
            num -= c
        end

        acc
    }
end

assert_equal("V", int_to_roman(5))
assert_equal("MCMLIV", int_to_roman(1954))
assert_equal("MCMXC", int_to_roman(1990))
assert_equal("MMXIV", int_to_roman(2014))
assert_equal("MMMCMXCIX", int_to_roman(3999))
{'fraction_non_alphanumeric': 0.1426071741032371, 'fraction_numerical': 0.06124234470691164, 'mean_word_length': 1.7434052757793765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3812368', 'n_tokens_mistral': 434, 'n_tokens_neox': 377, 'n_words': 97}