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.98 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.97 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.96 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.95 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.94 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.93 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.92 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.91 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.90 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.89 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.88 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.87 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.86 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.85 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.84 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.83 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.82 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.81 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.80 tracks/erlang/exercises/roman-numerals/src/example.erl
trackler-2.2.1.79 tracks/erlang/exercises/roman-numerals/src/example.erl