Skip to content

Instantly share code, notes, and snippets.

@sguzman
Last active June 12, 2020 23:44
Show Gist options
  • Save sguzman/0899b8ec13f8bbdd0892d4618f112799 to your computer and use it in GitHub Desktop.
Save sguzman/0899b8ec13f8bbdd0892d4618f112799 to your computer and use it in GitHub Desktop.
Simple funcs for studying the collatz conjecture in Mathematica. Not gonna lie, pretty proud of this.
collatz[1] = 1
collatz[n_Integer /; And[n > 1, OddQ[n]]] := collatz[n] = 3 n + 1
collatz[n_Integer /; And[n > 1, EvenQ[n]]] := collatz[n] = n / 2
collatzseq[1] = {1}
collatzseq[n_Integer /; n > 1] := collatzseq[n] = {n, Splice@collatzseq@collatz@n}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment