Last active
August 27, 2015 03:54
-
-
Save Gonster/20f1de52008286f813ba to your computer and use it in GitHub Desktop.
hola crystal lang
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
def pow(x,y) | |
return 1 if y == 0 || x == 1 | |
r = 1 | |
if y > 0 | |
return 0 if x == 0 | |
while y > 0 | |
r *= x | |
y -= 1 | |
end | |
else | |
return "Infinite" if x == 0 | |
while y < 0 | |
r /= x | |
y += 1 | |
end | |
end | |
return r | |
end | |
puts pow(1,100) | |
puts pow(0,10) | |
puts pow(2,32) | |
puts pow(2,-10) | |
puts pow(0,-4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment