Skip to content

Instantly share code, notes, and snippets.

@jacknoble
Created November 22, 2013 05:15
Show Gist options
  • Select an option

  • Save jacknoble/7595198 to your computer and use it in GitHub Desktop.

Select an option

Save jacknoble/7595198 to your computer and use it in GitHub Desktop.
Two different version of fast exponent recursion. Here is the first (the good one).
def exp2(base, power)
case power
when 0
1
when 1
base
else
exp2(base, (power / 2.0).floor) * exp2(base, (power / 2.0).ceil)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment