Created
September 30, 2017 18:01
-
-
Save imogenkinsman/a21e684aa8e63816ebb1fe028224b23d to your computer and use it in GitHub Desktop.
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 run do | |
1..100 | |
|> Enum.each(& print(&1)) | |
end | |
defp print(n) when rem(n, 15) == 0 do | |
IO.puts("fizzbuzz") | |
end | |
defp print(n) when rem(n, 3) == 0 do | |
IO.puts("fizz") | |
end | |
defp print(n) when rem(n, 5) == 0 do | |
IO.puts("buzz") | |
end | |
defp print(n) do | |
IO.puts(n) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment