Permalink
Browse files

feat(VI): implement 6 using remainder

  • Loading branch information...
antonydenyer committed Nov 16, 2017
1 parent b427555 commit 155de6aab419d61703c545adb44ec9b7fba933c4
Showing with 12 additions and 1 deletion.
  1. +8 −1 lib/roman.ex
  2. +4 −0 test/roman_test.exs
View
@@ -1,13 +1,20 @@
defmodule Roman do
def to_roman(number) when number == 5 do
"V"
def to_roman(number, roman_accumulator) do
roman_accumulator <> to_roman(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"
end
def to_roman(number) do
String.duplicate("I", number)
String.duplicate("I", number)
end
end
View
@@ -19,4 +19,8 @@ defmodule RomanTest do
assert Roman.to_roman(5) == "V"
end
test "six is VI" do
assert Roman.to_roman(6) == "VI"
end
end

0 comments on commit 155de6a

Please sign in to comment.