Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (25 sloc) 486 Bytes
defmodule Roman do
@numerals [
[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"]
]
def numerals(0), do: ""
def numerals(number) do
[part, letter] = largest_factor(number)
letter <> numerals(number - part)
end
defp largest_factor(number) do
hd(Enum.filter(@numerals, fn [p, _] -> p <= number end))
end
end
You can’t perform that action at this time.