Skip to content

Instantly share code, notes, and snippets.

@Xetera
Created December 15, 2018 03:49
Show Gist options
  • Save Xetera/0c0d1ed85140c79485532c09d0a51523 to your computer and use it in GitHub Desktop.
Save Xetera/0c0d1ed85140c79485532c09d0a51523 to your computer and use it in GitHub Desktop.
basic collatz conjecture in haskell
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