Created
March 19, 2020 09:02
-
-
Save houmanka/aefc6db4aab57c0c5bd62115ab5a16dd to your computer and use it in GitHub Desktop.
A bit more intelligent
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, closest_number, state) do | |
pow_2 = :math.pow(2, closest_number) | |
case pow_2 < n do | |
true -> | |
state = state ++ [pow_2] | |
n = n - pow_2 | |
of(n, closest_number - 1, state) | |
false -> | |
of(n, closest_number - 1, state) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment