Created
May 22, 2017 16:05
-
-
Save ckhrysze/a6486389d4ed5dfd2fd004b3973e6376 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Fizzy do | |
def fizzbuzz(n) when rem(n, 5) == 0 and rem(n, 3) == 0, do: "FizzBuzz" | |
def fizzbuzz(n) when rem(n, 3) == 0, do: "Fizz" | |
def fizzbuzz(n) when rem(n, 5) == 0, do: "Buzz" | |
def fizzbuzz(n), do: n | |
def run(range) do | |
range | |
|> Enum.map(&fizzbuzz/1) | |
|> Enum.map(&IO.puts/1) | |
end | |
end | |
defmodule Buzzy do | |
def fizzbuzz(n), do: _fizzbuzz(n, rem(n, 3), rem(n, 5)) | |
defp _fizzbuzz(_, 0, 0), do: "FizzBuzz" | |
defp _fizzbuzz(_, 0, _), do: "Fizz" | |
defp _fizzbuzz(_, _, 0), do: "Buzz" | |
defp _fizzbuzz(n, _, _), do: n | |
def run(range) do | |
range | |
|> Enum.map(&fizzbuzz/1) | |
|> Enum.map(&IO.puts/1) | |
end | |
end | |
Fizzy.run(1..16) | |
IO.puts("----") | |
Buzzy.run(1..16) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment