Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Roman-numerals-Decode/Erlang/roman-numerals-decode.erl
Normal file
20
Task/Roman-numerals-Decode/Erlang/roman-numerals-decode.erl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
-module( roman_numerals ).
|
||||
|
||||
-export( [decode_from_string/1]).
|
||||
|
||||
to_value($M) -> 1000;
|
||||
to_value($D) -> 500;
|
||||
to_value($C) -> 100;
|
||||
to_value($L) -> 50;
|
||||
to_value($X) -> 10;
|
||||
to_value($V) -> 5;
|
||||
to_value($I) -> 1.
|
||||
|
||||
decode_from_string([]) -> 0;
|
||||
decode_from_string([H1]) -> to_value(H1);
|
||||
decode_from_string([H1, H2 |Rest]) ->
|
||||
case {to_value(H1), to_value(H2)} of
|
||||
{V1, V2} when V1 < V2 -> V2 - V1 + decode_from_string(Rest);
|
||||
{V1, V1} -> V1 + V1 + decode_from_string(Rest);
|
||||
{V1, _} -> V1 + decode_from_string([H2|Rest])
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue