Last active
August 29, 2015 14:20
-
-
Save pmarreck/dc1cf59989e0b899e728 to your computer and use it in GitHub Desktop.
My version of FizzBuzz in Elixir
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 FizzBuzz do | |
def fizzbuzz(n) when is_integer(n), do: fizzbuzz(n, {rem(n,3), rem(n,5)}) | |
def fizzbuzz(_, {0,0}), do: :fizzbuzz | |
def fizzbuzz(_, {0,_}), do: :fizz | |
def fizzbuzz(_, {_,0}), do: :buzz | |
def fizzbuzz(n, {_,_}), do: n | |
def run(i \\ 100), do: (1..i) |> Enum.map(&fizzbuzz/1) | |
end | |
IO.inspect FizzBuzz.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment