Created
October 13, 2014 03:10
-
-
Save robmerrell/e79db0aa7578fc295f32 to your computer and use it in GitHub Desktop.
fizzbuzz using case
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 fizzbuzz(num) do | |
fizzbuzz = fn(x) -> | |
case {rem(x, 3) == 0, rem(x, 5) == 0} do | |
{true, false} -> IO.puts "fizz" | |
{false, true} -> IO.puts "buzz" | |
{true, true} -> IO.puts "fizzbuzz" | |
_ -> IO.puts x | |
end | |
end | |
Enum.each Range.new(1, num), fizzbuzz | |
end | |
end | |
FizzBuzz.fizzbuzz(30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment