You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
315 B
18 lines
315 B
1 year ago
|
def even(x: Int) : Boolean =
|
||
|
toInt(toChar(x * 128)) == 0;
|
||
|
def pow(x: Int, y: Int): Int =
|
||
|
if (y == 0) 1
|
||
|
else if (even(y)) {
|
||
|
val t = pow(x, y / 2);
|
||
|
t*t
|
||
|
} else {
|
||
|
x * pow(x, y - 1)
|
||
|
};
|
||
|
var i = 30; var res = 0;
|
||
|
|
||
|
while(i > 0) {
|
||
|
res = res + pow(2, i);
|
||
|
i = i - 1; ()
|
||
|
};
|
||
|
res
|