This commit is contained in:
billsun
2023-09-18 16:39:53 +00:00
parent ebae52c4df
commit 1c282af443
10 changed files with 98 additions and 42 deletions
+6
View File
@@ -0,0 +1,6 @@
def hello(x:Int) =
new Array[Int](x + getchar());
val arr = hello(5);
arr(0) = toInt('H'); arr(1) = toInt('e'); arr(2) = toInt('l'); arr(3) = toInt('l'); arr(4) = toInt('o');
putchar(arr(3));putchar(arr(4));putchar(arr(2));arr(0)
+17
View File
@@ -0,0 +1,17 @@
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
+7
View File
@@ -0,0 +1,7 @@
var x = 2;
var y = 0;
while ({ if (y < 3) true else y < 4}) {
x = x * x;
y = y + 1; ()
};
x