You are viewing a single comment's thread. Return to all comments →
Haskell
import Control.Applicative import Control.Monad import System.IO all_fibs = 1 : 2 : zipWith (+) fibs (tail fibs) fibs = take 100 all_fibs reduce :: [Int] -> [Int] reduce xs = filter (\n -> n `mod` 2 == 0) xs cutoff :: Int -> [Int] -> [Int] cutoff n xs = filter (\m -> m <= n && m > 0) xs main :: IO() main = do t_temp <- getLine let t = read t_temp :: Int forM_ [1..t] $ \a0 -> do n_temp <- getLine let n = read n_temp :: Int let cutoff_fibs = cutoff n fibs let even_fibs = reduce cutoff_fibs let fibSum = sum even_fibs :: Int putStrLn (show fibSum)
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #2: Even Fibonacci numbers
You are viewing a single comment's thread. Return to all comments →
Haskell