Haskell で FibBuzz 書いてみた

とりあえず自力で書いてみた。

[ソース]

fizzbuzz :: Int -> String
fizzbuzz n = case (n `mod` 3 == 0, n `mod` 5 == 0) of
    (True, True)  -> "FizzBuzz"
    (True, False) -> "Fizz"
    (False, True) -> "Buzz"
    (_, _)        -> show n

fibonacciImpl :: Int -> Int -> Int -> Int
fibonacciImpl n a b
    | n < 0     = a
    | otherwise = fibonacciImpl (n-1) b (a+b)

fibonacci :: Int -> Int
fibonacci n = fibonacciImpl n 0 1

main = print (map (fizzbuzz.fibonacci) [1..30])

[出力]

["1","2","Fizz","Buzz","8","13","Fizz","34","Buzz","89","Fizz","233","377","Buzz","Fizz","1597","2584","4181","FizzBuzz","10946","17711","28657","Fizz","Buzz","121393","196418","Fizz","514229","Buzz","1346269"]

[関連]

こっちはさっぱり読めないですね…。
Haskell むずい。