Sha256: aff8141ee03bae645994fd34f20ddf3df9bb0f7ec2816183fe81f8e87d5f27f8

Contents?: true

Size: 509 Bytes

Versions: 327

Compression:

Stored size: 509 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

327 entries across 327 versions & 1 rubygems

Version Path
trackler-2.2.1.109 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.108 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.107 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.106 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.105 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.104 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.103 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.102 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.101 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.100 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.99 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.98 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.97 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.96 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.95 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.94 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.93 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.92 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.91 tracks/elixir/exercises/roman-numerals/example.exs
trackler-2.2.1.90 tracks/elixir/exercises/roman-numerals/example.exs