Skip to content

Instantly share code, notes, and snippets.

@mimoo
Created October 30, 2018 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mimoo/52e7810b1399ee768c59da2a8c91603d to your computer and use it in GitHub Desktop.
Save mimoo/52e7810b1399ee768c59da2a8c91603d to your computer and use it in GitHub Desktop.
fizzbuzz in erlang :D
-module(fizzbuzz).
-export([main/0]).
main() ->
fizzbuzz(0).
fizzbuzz(N) ->
case N of
_ when N == 100 ->
ok;
_ when N rem 3 == 0 andalso N rem 5 == 0 ->
io:format("fizzbuzz~n"),
fizzbuzz(N+1);
_ when N rem 3 == 0 ->
io:format("fizz~n"),
fizzbuzz(N+1);
_ when N rem 5 == 0 ->
io:format("buzz~n"),
fizzbuzz(N+1);
_ ->
io:format("~p~n", [N]),
fizzbuzz(N+1)
end.
fizzbuzz2(N) when N == 100 ->
ok;
fizzbuzz2(N) when N rem 3 == 0, N rem 5 == 0 ->
io:format("fizzbuzz~n"),
fizzbuzz2(N+1);
fizzbuzz2(N) when N rem 3 == 0 ->
io:format("fizz~n"),
fizzbuzz2(N+1);
fizzbuzz2(N) when N rem 5 == 0 ->
io:format("buzz~n"),
fizzbuzz2(N+1);
fizzbuzz2(N) ->
io:format("~p~n", [N]),
fizzbuzz2(N+1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment