Created
July 21, 2018 03:20
-
-
Save fschuindt/56dc592fcc7a477b81a871f1e4d6b93e to your computer and use it in GitHub Desktop.
The Collatz conjecture.
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
defmodule Collatz do | |
def of(1), do: 1 | |
def of(n) do | |
IO.puts n | |
do_of(n, rem(n, 2)) | |
end | |
defp do_of(n, 0) do | |
of(div(n, 2)) | |
end | |
defp do_of(n, 1) do | |
of((3 * n) + 1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment