Created
September 16, 2012 09:27
-
-
Save kuniyoshi/3731741 to your computer and use it in GitHub Desktop.
my answer of fizz buzz question.
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(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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Strのところ、試行錯誤の名残で無駄なことになってしまいまいした。case使わないで返す値はlists:flatten(Str)にしようと思ってたんですが、いいのが思いつかなかったです。