Sha256: de0c4ad54c52dcfe86c370c6f87601dda281e6f75cb9567cf4eccdf6129ff344

Contents?: true

Size: 486 Bytes

Versions: 69

Compression:

Stored size: 486 Bytes

Contents

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

Version data entries

69 entries across 69 versions & 1 rubygems

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