Skip to content

Instantly share code, notes, and snippets.

@anthonylebrun
Last active May 26, 2016 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anthonylebrun/2c9c12432e3ef7029c9eb86fed58bc6f to your computer and use it in GitHub Desktop.
Save anthonylebrun/2c9c12432e3ef7029c9eb86fed58bc6f to your computer and use it in GitHub Desktop.
defmodule Fizzbuzz do
def parse(range \\ 1..100) do
range |> Enum.map(&parse_num/1) |> Enum.join
end
defp parse_num(n) do
fizzbuzzer(n, rem(n, 3), rem(n, 5))
end
defp fizzbuzzer(_, 0, 0), do: "FizzBuzz"
defp fizzbuzzer(_, 0, _), do: "Fizz"
defp fizzbuzzer(_, _, 0), do: "Buzz"
defp fizzbuzzer(n, _, _), do: Integer.to_string(n)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment