Sha256: 6aa45b74e1600f83f4c8ab6266640092e24108ec88d6ab070ad9d86bb4124403

Contents?: true

Size: 603 Bytes

Versions: 310

Compression:

Stored size: 603 Bytes

Contents

-module(example).

-export([numerals/1, test_version/0]).

-define(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}]).

-spec numerals(non_neg_integer()) -> string().
numerals(Number) ->
    to_roman(Number, "", ?DIGITS).

test_version() ->
    1.



to_roman(0, Roman, _) -> Roman;
to_roman(N, Roman, Digits) ->
    {R, D} = hd(Digits),
    if
        N >= D -> to_roman(N - D, Roman ++ R, Digits);
        true   -> to_roman(N, Roman, tl(Digits))
    end.

Version data entries

310 entries across 310 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.179 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.178 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.177 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.176 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.175 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.174 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.173 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.172 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.171 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.170 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.169 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.167 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.166 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.165 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.164 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.163 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.162 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.161 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.160 tracks/erlang/exercises/roman-numerals/src/example.erl