Skip to content

Instantly share code, notes, and snippets.

@evidanary
Created June 16, 2017 21:54
Show Gist options
  • Save evidanary/9fc08166e5236e9f83dae9ff25a1e447 to your computer and use it in GitHub Desktop.
Save evidanary/9fc08166e5236e9f83dae9ff25a1e447 to your computer and use it in GitHub Desktop.
# power of a number
# Beware the power can be a float or negative
def pow(x,y)
return 1 if y==0
product = 1
(1..y.abs).each do
product /= x.to_f if y<0
product *= x if y>0
end
product
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment