Skip to content

Instantly share code, notes, and snippets.

@alco
Last active December 22, 2015 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alco/6399677 to your computer and use it in GitHub Desktop.
Save alco/6399677 to your computer and use it in GitHub Desktop.
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