Skip to content

Instantly share code, notes, and snippets.

@fschuindt
Created July 21, 2018 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fschuindt/56dc592fcc7a477b81a871f1e4d6b93e to your computer and use it in GitHub Desktop.
Save fschuindt/56dc592fcc7a477b81a871f1e4d6b93e to your computer and use it in GitHub Desktop.
The Collatz conjecture.
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