Created
February 24, 2022 07:16
-
-
Save splch/9cead7186cae95ca0857359e1985b0c7 to your computer and use it in GitHub Desktop.
Creates collatz sequences in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| collatz :: Integer -> Integer | |
| collatz n = | |
| if even n | |
| then n `div` 2 | |
| else 3 * n + 1 | |
| collatzSeq :: Integer -> [Integer] | |
| collatzSeq n = | |
| if n == 1 -- base case | |
| then 1 : [] | |
| else n : collatzSeq (collatz n) -- recursive call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment