Last active
December 22, 2015 01:58
-
-
Save alco/6399677 to your computer and use it in GitHub Desktop.
This file contains 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 IntMath do | |
def pow(_, 0), do: 1 | |
def pow(a, 1), do: a | |
def pow(a, n) when rem(n, 2) === 0 do | |
tmp = pow(a, div(n, 2)) | |
tmp * tmp | |
end | |
def pow(a, n) do | |
a * pow(a, n-1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment