DEV Community

Discussion on: Daily Challenge #102 - Pentabonacci

Collapse
 
aminnairi profile image
Amin • Edited

Haskell

countPentaFibonacci :: Int -> Int
countPentaFibonacci limit 
    | limit < 1 = 0
    | limit == 1 = 1
    | otherwise = length $ filter odd $ map f [2..limit]
    where
        f 0 = 0
        f 1 = 1
        f 2 = 1
        f 3 = 2
        f 4 = 4
        f x = f (x - 1) + f (x - 2) + f (x - 3) + f (x - 4) + f (x - 5)

Online playground

Hosted on Repl.it.