Created
August 28, 2017 18:16
-
-
Save stevenwilkin/73f3cb572e7e65f9c487135d2e75afe4 to your computer and use it in GitHub Desktop.
FizzBuzz in Elixir
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
#!/usr/bin/env elixir | |
defmodule FizzBuzz do | |
def check(x) when (rem(x, 3) == 0) and (rem(x, 5) == 0) do | |
IO.puts "FizzBuzz" | |
end | |
def check(x) when rem(x, 3) == 0 do | |
IO.puts "Fizz" | |
end | |
def check(x) when rem(x, 5) == 0 do | |
IO.puts "Buzz" | |
end | |
def check(x) do | |
IO.puts x | |
end | |
def run do | |
Enum.each(1 .. 100, &check/1) | |
end | |
end | |
FizzBuzz.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment