Created
October 30, 2018 05:39
-
-
Save mimoo/52e7810b1399ee768c59da2a8c91603d to your computer and use it in GitHub Desktop.
fizzbuzz in erlang :D
This file contains 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([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