Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Collatz sequences are introduced in Euler problem 14.
Documentation
collatz :: Natural -> Natural Source #
One step of the Collatz sequence, defined for the set of positive integers:
- n → n/2 (n is even)
- n → 3n + 1 (n is odd)
The example from problem 14:
>>>
takeWhile (/= 1) $ iterate collatz 13
[13,40,20,10,5,16,8,4,2]
collatzLengths :: [Natural] -> Lengths Source #
evaluates to a collatzLengths
xsLengths
mapping which contains the
collatz length for at least every element of xs
(and possibly more).
The example from problem 14:
>>>
collatzLengths [13] Map.! 13
10