Skip to content

Instantly share code, notes, and snippets.

@Iristyle
Created July 24, 2013 18:26
Show Gist options
  • Save Iristyle/6073136 to your computer and use it in GitHub Desktop.
Save Iristyle/6073136 to your computer and use it in GitHub Desktop.
Elixir FizzBuzz
defmodule FizzBuzz do
def sequence([]), do: []
def sequence(until) when is_integer(until) and until > 0 do
sequence(0..until |> Enum.to_list)
end
def sequence([head|tail]) do
output(rem(head, 3), rem(head, 5), head)
sequence(tail)
end
# divisible by 3 and 5
defp output(0, 0, n), do: IO.puts "#{n}: FizzBuzz"
defp output(0, _, n), do: IO.puts "#{n}: Fizz"
defp output(_, 0, n), do: IO.puts "#{n}: Buzz"
defp output(_, _, n), do: IO.puts n
end
FizzBuzz.sequence(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment