Skip to content

Instantly share code, notes, and snippets.

@swanhtet1992
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swanhtet1992/f4af9cb4dca704945e3d to your computer and use it in GitHub Desktop.
Save swanhtet1992/f4af9cb4dca704945e3d to your computer and use it in GitHub Desktop.
Solution for λ Talks in Yangon registration quiz
def multiply(x: Double, n: Double): Double = {
if (n == 0) 0 else x + multiply(x, n - 1)
}
def power(b: Int, e: Int): Double = {
if (e > 0) multiply(b.toDouble, power(b, e - 1))
else if (e < 0) 1/power(b, -e) // let me use / for negative e :P
else 1.0
}
power(2, 8) // 256.0
power(2, -8) //0.00390625
@khzaw
Copy link

khzaw commented Dec 9, 2014

kyite tal kwar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment