
import Data.Array ( listArray, (!) ) import Data.List ( elemIndex ) collatzLengthList m = collatzLengthArray where collatzLengthArray = listArray (1,m) $ 1:map collatzLength [2..m] where collatzLength n | b<=m = 1 + collatzLengthArray ! b | otherwise = 1 + collatzLength b where b | even n = n `div` 2 | otherwise = 3*n+1 e14 :: (Maybe Int, Integer) e14 = (n, m) where m = maximum cArray cArray = collatzLengthList p p = 1000000 n = elemIndex m cList where cList = 0:[cArray ! x | x <- [1..p]]
λ> :set +s λ> e14 (Just 837799,525) (1.74 secs, 2,193,219,920 bytes)
— Me@2023-07-25 11:55:41 PM
.
.
2023.07.26 Wednesday (c) All rights reserved by ACHK


You must be logged in to post a comment.