3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

HaskellでFizz Buzz

Last updated at Posted at 2021-03-12

すごいH本を読んでいて、初心者ながらまず書きたかったFizz Buzz書いてみたけど、本当にこれでいいのかモヤモヤしていたところ、親切なコメントをいただきました (ありがとうございます!)。

fizzbuzz :: [Int] -> [[Char]]
fizzbuzz [] = []
fizzbuzz (x:xs) |mod x 15 == 0 = "FizzBuzz" : fizzbuzz xs
                |mod x 5 == 0 = "Buzz" : fizzbuzz xs
                |mod x 3 == 0 = "Fizz" : fizzbuzz xs
                |otherwise = show x : fizzbuzz xs

頂いたコメントを受け:

  1. 1行目はfizzbuzz :: [Int] -> [String] が適切 (何か変な気がしていました)
  2. 3~6行目の冗長な感じも、頂いたコメントで解消しそうです (...勉強中)

※この場でこんな初心者が投稿していいかはわかりませんが、
 まぁ無意味でもないと思われますので晒しておきます。

3
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?