Skip to content

Instantly share code, notes, and snippets.

@veganstraightedge
Created May 22, 2017 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veganstraightedge/999be651c1f0f00c20eb37d83119a542 to your computer and use it in GitHub Desktop.
Save veganstraightedge/999be651c1f0f00c20eb37d83119a542 to your computer and use it in GitHub Desktop.
Spent an hour or so with @zzak getting my first look at Elixir. We Fizz Buzzed. ¯\_(ツ)_/¯
defmodule FizzBuzz do
def run do
range = 1..10
Enum.each range, fn i -> print_eye(i) end
end
def print_eye i do
cond do
rem(i, 3) == 0 ->
IO.puts "Fizz"
rem(i, 5) == 0 ->
IO.puts "Buzz"
true ->
IO.puts i
end
end
end
FizzBuzz.run
defmodule FizzBuzz do
def run do
range = 1..100
Enum.each range, fn i -> print_eye(i) end
end
def print_eye(i) when rem(i, 3) == 0, do: IO.puts("Fizz")
def print_eye(i) when rem(i, 5) == 0, do: IO.puts("Buzz")
def print_eye(i) when true, do: IO.puts(i)
end
FizzBuzz.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment