exercism/elixir/raindrops/raindrops.exs
anthony.cicchetti 5f9cd49d7a initial commit
2017-04-25 15:51:48 -04:00

24 lines
1 KiB
Elixir

defmodule Raindrops do
@doc """
Returns a string based on raindrop factors.
- If the number contains 3 as a prime factor, output 'Pling'.
- If the number contains 5 as a prime factor, output 'Plang'.
- If the number contains 7 as a prime factor, output 'Plong'.
- If the number does not contain 3, 5, or 7 as a prime factor,
just pass the number's digits straight through.
"""
@spec convert(pos_integer) :: String.t
def convert(number) do
case number do
number when (rem(number, 3) == 0 and rem(number, 5) == 0 and rem(number, 7) == 0) -> "PlingPlangPlong"
number when (rem(number, 3) == 0 and rem(number, 5) == 0) -> "PlingPlang"
number when (rem(number, 3) == 0 and rem(number, 7) == 0) -> "PlingPlong"
number when (rem(number, 5) == 0 and rem(number, 7) == 0) -> "PlangPlong"
number when (rem(number, 3) == 0) -> "Pling"
number when (rem(number, 5) == 0) -> "Plang"
number when (rem(number, 7) == 0) -> "Plong"
_ -> Integer.to_string(number)
end
end
end