Add pretty naive implementation of fizzbuzz

This commit is contained in:
Nathan Mattes 2021-11-21 11:53:22 +01:00
parent 55df464989
commit d148715811
1 changed files with 24 additions and 0 deletions

24
control/fizzbuzz.ex Normal file
View File

@ -0,0 +1,24 @@
defmodule FizzBuzz do
def count(number) do
1..number
|> Enum.to_list
|> Enum.each(&FizzBuzz.check/1)
end
def check(number) do
# if n is multiple of 3: Fizz
if (Integer.mod(number, 3) == 0) && (Integer.mod(number, 5) == 0) do
IO.puts "Fizzbuzz!"
else
if Integer.mod(number, 3) == 0 do
IO.puts "Fizz"
else
if Integer.mod(number, 5) == 0 do
IO.puts "Buzz"
else
IO.puts number
end
end
end
end
end