Permalink
Browse files

refactor: move to a more generic implementation

  • Loading branch information...
antonydenyer committed Nov 16, 2017
1 parent 155de6a commit c79d40b282fc62fdcc6583a9395d0abefff7b31e
Showing with 5 additions and 8 deletions.
  1. +5 −6 lib/roman.ex
  2. +0 −2 test/roman_test.exs
View
@@ -1,20 +1,19 @@
defmodule Roman do
def to_roman(number) when number == 5 do
"V"
def to_roman(number, roman_accumulator) do
roman_accumulator <> to_roman(number)
roman_accumulator <> String.duplicate("I", number)
end
def to_roman(number) when number >= 5 do
to_roman(number - 5, "V")
end
def to_roman(number) when number == 4 do
"IV"
def to_roman(number) when number >= 4 do
to_roman(number - 4, "IV")
end
def to_roman(number) do
String.duplicate("I", number)
to_roman(number, "")
end
end
View
@@ -1,8 +1,6 @@
defmodule RomanTest do
use ExUnit.Case
doctest Roman
test "one is I" do
assert Roman.to_roman(1) == "I"
end

0 comments on commit c79d40b

Please sign in to comment.