Created
July 24, 2013 18:26
-
-
Save Iristyle/6073136 to your computer and use it in GitHub Desktop.
Elixir FizzBuzz
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 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