1
0
Fork 0

Add small collatz details

main
Bill Ewanick 2023-10-20 02:14:34 -04:00
parent baf8ad2559
commit 956e56028f
1 changed files with 9 additions and 4 deletions

View File

@ -1,3 +1,8 @@
{-
The Simplest Math Problem No One Can Solve - Collatz Conjecture
https://youtu.be/094y1Z2wpJg
-}
import Control.Monad ()
import Debug.Trace (trace)
@ -7,10 +12,10 @@ f' n = f'' 0 n
f'' :: Integer -> Integer -> Integer
f'' i n'
| n' == 1 = t' i
| even n' = t $ f'' (i + 1) (n' `div` 2)
| odd n' = t $ f'' (i + 1) (3*n' + 1)
| even n' = t $ f'' (succ i) (n' `div` 2)
| odd n' = t $ f'' (succ i) (3*n' + 1)
where t = trace ("i: " ++ show i ++ ", number: " ++ show n')
t' = t'' $ trace ("END: " ++ show n ++ ", length: " <> show i) $ t''
t' = t'' $ trace ("END: " ++ show n ++ ", length: " <> show i) t''
t'' = trace "\n#######################################################\n"
f :: Integer -> Integer
@ -21,7 +26,7 @@ f n = s 0 n
| n == 1 = i
| even n = s i' (n `div` 2)
| odd n = s i' (3*n + 1)
where i' = i + 1
where i' = succ i
main :: IO ()
main = print $ map f [2^361..]