Skip to content

Instantly share code, notes, and snippets.

@stevegraham
Created December 20, 2014 14:46
Show Gist options
  • Save stevegraham/9c98cdc3c53e312a91e3 to your computer and use it in GitHub Desktop.
Save stevegraham/9c98cdc3c53e312a91e3 to your computer and use it in GitHub Desktop.
Functional FizzBuzz
defmodule FizzBuzz do
def upto(n) when n > 0, do: 1..n |> Enum.map(&fizzbuzz/1)
defp fizzbuzz(n) when rem(n, 15) == 0, do: "FizzBuzz"
defp fizzbuzz(n) when rem(n, 3) == 0, do: "Fizz"
defp fizzbuzz(n) when rem(n, 5) == 0, do: "Buzz"
defp fizzbuzz(n), do: n
end
@lexa76
Copy link

lexa76 commented Dec 20, 2014

Fizz buzz

@lexa76
Copy link

lexa76 commented Dec 20, 2014

Vote

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment