Skip to content

Instantly share code, notes, and snippets.

@robmerrell
Created October 13, 2014 03:10
Show Gist options
  • Save robmerrell/e79db0aa7578fc295f32 to your computer and use it in GitHub Desktop.
Save robmerrell/e79db0aa7578fc295f32 to your computer and use it in GitHub Desktop.
fizzbuzz using case
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