Created
December 15, 2018 03:49
-
-
Save Xetera/0c0d1ed85140c79485532c09d0a51523 to your computer and use it in GitHub Desktop.
basic collatz conjecture in haskell
This file contains 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
fromEven num = num `div` 2 | |
fromOdd = (+1) . (*3) | |
collatz :: Int -> [Int] | |
collatz num | |
| num == 1 = [1] | |
| even num = next fromEven | |
| odd num = next fromOdd | |
where next func = num : (collatz $ func num) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment