Skip to content

Instantly share code, notes, and snippets.

@houmanka
Created March 19, 2020 09:15
Show Gist options
  • Save houmanka/5b6762782290ca18156b6596b758613a to your computer and use it in GitHub Desktop.
Save houmanka/5b6762782290ca18156b6596b758613a to your computer and use it in GitHub Desktop.
Finding the greatest power of 2
defmodule AncientEgyptianMultiplication do
require Integer
def of(n, state) when n <= 1, do: state
def of(n, state) do
n = (n / 2)
|> Kernel.trunc
state = state ++ [n]
of(n, state)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment