Created
May 22, 2017 17:08
-
-
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. ¯\_(ツ)_/¯
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 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 |
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 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