Created
January 24, 2011 01:20
-
-
Save KushalP/792656 to your computer and use it in GitHub Desktop.
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
-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