Skip to content

Instantly share code, notes, and snippets.

@grauwoelfchen
Created March 11, 2013 16:52
Show Gist options
  • Save grauwoelfchen/5135642 to your computer and use it in GitHub Desktop.
Save grauwoelfchen/5135642 to your computer and use it in GitHub Desktop.
def power(x, n)
case
when n.zero?; 1
when n.even?; power((x * x), n / 2)
else x * power(x, (n - 1))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment