Last week at a local tech meetup, I presented a quick 6-minute lightning talk on Elixir. In it, I quickly implemented the infamous FizzBuzz programming challenge in Elixir. While doing so, I briefly demonstrated some of the things I like about Elixir such as:
- Pattern matching
- Function overloading
- Guard clauses
- Multiple shortcuts for function definitions
So please take 6-7 minutes and watch it then let me know what you think! Keep in mind it was a lightning talk format and it was for a crowd of people who are at an introductory level of Elixir exposure.
Here’s the final code of my implementation in case you’re interested:
defmodule FizzBuzz do def go(min, max), do: Enum.each(min..max, &go/1) def go(num) when (rem(num, 15) == 0), do: IO.puts "fizzbuzz" def go(num) when (rem(num, 3) == 0), do: IO.puts "fizz" def go(num) when (rem(num, 5) == 0), do: IO.puts "buzz" def go(num), do: IO.puts num end