Last active
August 29, 2015 14:22
-
-
Save michalmuskala/ced320b509eaa3504ddb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 FizzBuzz do | |
def fizzbuzz(a) when rem(a, 3) == 0 and rem(a, 5) == 0, do: "FizzBuzz" | |
def fizzbuzz(a) when rem(a, 3) == 0, do: "Fizz" | |
def fizzbuzz(a) when rem(a, 5) == 0, do: "Buzz" | |
def fizzbuzz(a), do: a | |
end | |
1..100 |> Enum.map(&FizzBuzz.fizzbuzz/1) |> Enum.each(&IO.puts/1) |
This file contains hidden or 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 FizzBuzz do | |
defp whichfizz(0, 0, _), do: "FizzBuzz" | |
defp whichfizz(0, _, _), do: "Fizz" | |
defp whichfizz(_, 0, _), do: "Buzz" | |
defp whichfizz(_, _, n), do: n | |
def fizzbuzz(n), do: whichfizz(rem(n, 3), rem(n, 5), n) | |
end | |
1..100 |> Enum.map(&FizzBuzz.fizzbuzz/1) |> Enum.each(&IO.puts/1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment