Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module CollatzConjecture (collatz) where
- collatz :: Integer -> Maybe Integer
- collatz n
- | n <= 0 = Nothing
- | n == 1 = Just 0
- | even n = addStep $ collatz (n `div` 2)
- | otherwise = addStep $ collatz (3 * n + 1)
- where
- addStep Nothing = Nothing
- addStep (Just x) = Just (x + 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement