Skip to content

Instantly share code, notes, and snippets.

@kuniyoshi
Created September 16, 2012 09:27
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 kuniyoshi/3731741 to your computer and use it in GitHub Desktop.
Save kuniyoshi/3731741 to your computer and use it in GitHub Desktop.
my answer of fizz buzz question.
-module(fizz_buzz2).
-compile(export_all).
show(Num) ->
io:format("~p", [fizz_buzz(Num)]).
get_fizz(Num) when Num rem 3 == 0 ->
"Fizz";
get_fizz(_Num) ->
[].
get_buzz(Num) when Num rem 5 == 0 ->
"Buzz";
get_buzz(_Num) ->
[].
fizz_buzz(Num) ->
Str = [X || X <- [get_fizz(Num), get_buzz(Num)]],
case length(Ret=lists:flatten(Str)) of
0 ->
Num;
_ ->
Ret
end.
@kuniyoshi
Copy link
Author

Strのところ、試行錯誤の名残で無駄なことになってしまいまいした。case使わないで返す値はlists:flatten(Str)にしようと思ってたんですが、いいのが思いつかなかったです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment