I'm trying to get a program to return the collatz sequence to Elixir, but I get an ugly error that says
1) test a few basic test cases (CollatzTest)
test/solution_test.exs:4 ** (ArithmeticError) bad argument in arithmetic expression code: assert Collatz.collatz(3) == "3->10->5->16->8->4->2->1" stacktrace: (solution) lib/solution.ex:7: Collatz.collatz/1 (solution) lib/solution.ex:8: Collatz.collatz/1 (solution) lib/solution.ex:10: Collatz.collatz/1 test/solution_test.exs:7: (test)
My code is as follows:
defmodule Collatz do
def collatz(n) do
cond do
n == 1 ->
"1"
rem(n,2) == 0 ->
"#{n}->#{collatz(n/2)}"
true ->
"#{n}->#{collatz(n*3+1)}"
end
end
end
Why is my error and how do I solve it?