Skip to content

Instantly share code, notes, and snippets.

@jayunit100
Created August 6, 2014 18:18
Show Gist options
  • Save jayunit100/b294c8eae07b07a8c7c0 to your computer and use it in GitHub Desktop.
Save jayunit100/b294c8eae07b07a8c7c0 to your computer and use it in GitHub Desktop.
is there a more scala-ish way to do this?
def pow(n:Int , k:Int ) : Int = {
k match {
case 0 => return 1;
case 1 => return n;
case 2 => return n*n;
case _ => ;
}
if ( (k%2)==0) {
var p =
pow(n,k/2) *
pow(n,(k+1)/2);
return p;
}
if (k%2==1) {
var p = pow(n,k/2)
return p * p;
}
0
}
def x : Int = 2;
def y : Int = 4;
println(pow(x,y))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment