Skip to content

Instantly share code, notes, and snippets.

@KushalP
Created January 24, 2011 01:20
Show Gist options
  • Save KushalP/792656 to your computer and use it in GitHub Desktop.
Save KushalP/792656 to your computer and use it in GitHub Desktop.
-module(fizzbuzz).
-export([fizzbuzz/1]).
-import(lists, [reverse/1]).
% Given an Integer, drill down
fzbz(N) when N rem 3 == 0, N rem 5 == 0 -> "FizzBuzz";
fzbz(N) when N rem 3 == 0 -> "Fizz";
fzbz(N) when N rem 5 == 0 -> "Buzz";
fzbz(N) -> N.
% Build up a list by working through our value and working backwards
fbr(N) when N =:= 0 -> [];
fbr(N) when N > 0 -> [fzbz(N) | fbr(N-1)].
% The FizzBuzz inteface, just reverses the output as provided by fbr(N)
fizzbuzz(N) -> lists:reverse(fbr(N)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment