Created
March 19, 2020 09:15
-
-
Save houmanka/5b6762782290ca18156b6596b758613a to your computer and use it in GitHub Desktop.
Finding the greatest power of 2
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 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