Euler problem 25.2.1

import System.CPUTime
import Text.Printf (printf)

-- | Times the execution of a pure function and prints the result.
time :: (Show a) => a -> IO a
time result = do
    start <- getCPUTime
    let computed = result
    end <- computed `seq` getCPUTime
    let diff = (fromIntegral (end - start)::Float)/(10^12)
    printf "Result: %s\n Time taken: %.6f seconds\n" (show computed) diff
    return computed

fibs :: [Integer]
fibs = 0:1:zipWith (+) fibs (tail fibs)

t :: Integer
t = 10^999
 
p25 :: Int
p25 = length w
    where
      w = takeWhile (< t) fibs

λ> time p25
Result: 4782
 Time taken: 0.000496 seconds
4782
λ> 
λ> time p25
Result: 4782
 Time taken: 0.002918 seconds
4782
λ> 

— Me@2024-12-25 07:00:13 AM

.

.

2024.12.26 Thursday (c) All rights reserved by ACHK