Copyright | Copyright (C) 2022 Yoo Chung |
---|---|
License | GPL-3.0-or-later |
Maintainer | dev@chungyc.org |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Some solutions to Problems.P78 of Ninety-Nine Haskell Problems.
Documentation
collatz :: Integral a => a -> a Source #
Starting from a positive integer \(n\), we can have a sequence of numbers such that at each step, the next number is \(3n+1\) if \(n\) is odd, or \(\frac{n}{2}\) if \(n\) is even. The Collatz conjecture states that this sequence will always end at 1 after a finite number of steps.
Using the Writer
monad, count the number of these steps
for a given positive integer \(n\).