mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
Return expression eliminated
This commit is contained in:
parent
7eb3e223b8
commit
297139c72a
114 changed files with 37 additions and 1018 deletions
|
|
@ -1,18 +0,0 @@
|
||||||
> 9
|
|
||||||
55
|
|
||||||
8
|
|
||||||
34
|
|
||||||
7
|
|
||||||
21
|
|
||||||
6
|
|
||||||
13
|
|
||||||
5
|
|
||||||
8
|
|
||||||
4
|
|
||||||
5
|
|
||||||
3
|
|
||||||
3
|
|
||||||
2
|
|
||||||
2
|
|
||||||
1
|
|
||||||
1
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
> 7
|
|
||||||
5040
|
|
||||||
6
|
|
||||||
720
|
|
||||||
5
|
|
||||||
120
|
|
||||||
4
|
|
||||||
24
|
|
||||||
3
|
|
||||||
6
|
|
||||||
2
|
|
||||||
2
|
|
||||||
1
|
|
||||||
1
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
> 1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
4
|
|
||||||
5
|
|
||||||
6
|
|
||||||
7
|
|
||||||
8
|
|
||||||
9
|
|
||||||
2
|
|
||||||
3
|
|
||||||
4
|
|
||||||
5
|
|
||||||
6
|
|
||||||
7
|
|
||||||
8
|
|
||||||
9
|
|
||||||
10
|
|
||||||
3
|
|
||||||
5
|
|
||||||
7
|
|
||||||
9
|
|
||||||
11
|
|
||||||
13
|
|
||||||
15
|
|
||||||
17
|
|
||||||
19
|
|
||||||
5
|
|
||||||
13
|
|
||||||
29
|
|
||||||
61
|
|
||||||
125
|
|
||||||
253
|
|
||||||
509
|
|
||||||
1021
|
|
||||||
2045
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
> 55
|
|
||||||
15
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
> 10
|
|
||||||
20
|
|
||||||
30
|
|
||||||
40
|
|
||||||
0
|
|
||||||
1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
> 5
|
|
||||||
6
|
|
||||||
7
|
|
||||||
8
|
|
||||||
9
|
|
||||||
10
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
> 1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
4
|
|
||||||
1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
4
|
|
||||||
3
|
|
||||||
4
|
|
||||||
1
|
|
||||||
2
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
> 1
|
|
||||||
1
|
|
||||||
1
|
|
||||||
1
|
|
||||||
0
|
|
||||||
0
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
> 0
|
|
||||||
100
|
|
||||||
300
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
> 1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
100
|
|
||||||
200
|
|
||||||
300
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
> 1
|
|
||||||
1
|
|
||||||
1
|
|
||||||
1
|
|
||||||
1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
100
|
|
||||||
3
|
|
||||||
2
|
|
||||||
1
|
|
||||||
6
|
|
||||||
5
|
|
||||||
4
|
|
||||||
3
|
|
||||||
2
|
|
||||||
1
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
> 7
|
|
||||||
7
|
|
||||||
28
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
> 55
|
|
||||||
310
|
|
||||||
310
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
> 0
|
|
||||||
15
|
|
||||||
15
|
|
||||||
1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
4
|
|
||||||
5
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
> 1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
> 1
|
|
||||||
0
|
|
||||||
1
|
|
||||||
0
|
|
||||||
1
|
|
||||||
1
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
0
|
|
||||||
3
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
> > > 8
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
> 6
|
|
||||||
7
|
|
||||||
8
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
> 1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
2
|
|
||||||
3
|
|
||||||
4
|
|
||||||
3
|
|
||||||
4
|
|
||||||
5
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
> 1
|
|
||||||
1
|
|
||||||
1
|
|
||||||
1
|
|
||||||
0
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
> 11
|
|
||||||
18
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
> 5
|
|
||||||
7
|
|
||||||
12
|
|
||||||
-2
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
> 5
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
> 2
|
|
||||||
1
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
> 35
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
> 12
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
> 1
|
|
||||||
800
|
|
||||||
800
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
> 0
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
> 0
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
> 5
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
> 55
|
|
||||||
15
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
> 10
|
|
||||||
20
|
|
||||||
30
|
|
||||||
40
|
|
||||||
0
|
|
||||||
1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
> 1
|
|
||||||
0
|
|
||||||
1
|
|
||||||
0
|
|
||||||
1
|
|
||||||
1
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
> 100
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
9
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
local n, i;
|
|
||||||
|
|
||||||
fun fib (n) {
|
|
||||||
if n <= 1
|
|
||||||
then return 1
|
|
||||||
else
|
|
||||||
return (fib (n-1) + fib (n-2))
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
n := read ();
|
|
||||||
|
|
||||||
for i := n, i >= 1, i := i-1 do
|
|
||||||
write (i);
|
|
||||||
write (fib (i))
|
|
||||||
od
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
7
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
local n, i;
|
|
||||||
|
|
||||||
fun fact (n) {
|
|
||||||
if n <= 1
|
|
||||||
then return 1
|
|
||||||
else
|
|
||||||
return (n * fact (n-1))
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
n := read ();
|
|
||||||
|
|
||||||
for i := n, i >= 1, i := i-1 do
|
|
||||||
write (i);
|
|
||||||
write (fact (i))
|
|
||||||
od
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
local x, m, n;
|
|
||||||
|
|
||||||
fun ack (m, n) {
|
|
||||||
if m == 0 then return (n+1)
|
|
||||||
elif m > 0 && n == 0 then return ack (m-1, 1)
|
|
||||||
else return ack (m-1, ack (m, n-1))
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
x := read ();
|
|
||||||
|
|
||||||
for m := 0, m <= 3, m := m+1 do
|
|
||||||
for n := 0, n <= 8, n := n+1 do
|
|
||||||
write (ack (m, n))
|
|
||||||
od
|
|
||||||
od
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
local x;
|
|
||||||
|
|
||||||
fun test (n, m) {
|
|
||||||
local i, s;
|
|
||||||
s := 0;
|
|
||||||
for i := 0, i <= n, i := i + 1 do
|
|
||||||
s := s + i;
|
|
||||||
if s > m then return s fi
|
|
||||||
od;
|
|
||||||
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
x := read ();
|
|
||||||
|
|
||||||
write (test (10, 100));
|
|
||||||
write (test (100, 10))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
local n, x, i;
|
|
||||||
|
|
||||||
fun printArray (x) {
|
|
||||||
local elem;
|
|
||||||
if x.length == 0 then return fi;
|
|
||||||
for i:=0, i<x.length, i:=i+1 do
|
|
||||||
write (x[i])
|
|
||||||
od
|
|
||||||
}
|
|
||||||
|
|
||||||
n := read ();
|
|
||||||
|
|
||||||
x := [10, 20, 30, 40];
|
|
||||||
|
|
||||||
printArray (x);
|
|
||||||
|
|
||||||
for i:=0, i<x.length, i:=i+1 do
|
|
||||||
x[i] := i
|
|
||||||
od;
|
|
||||||
|
|
||||||
printArray (x)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
local n, x, i;
|
|
||||||
|
|
||||||
fun sort (x) {
|
|
||||||
local i, j, y, n;
|
|
||||||
n := x.length;
|
|
||||||
|
|
||||||
if n == 0 then return x fi;
|
|
||||||
|
|
||||||
for i := 0, i<n, i := i+1 do
|
|
||||||
for j := i+1, j<n, j := j+1 do
|
|
||||||
if x[j] < x[i] then
|
|
||||||
y := x[i];
|
|
||||||
x[i] := x[j];
|
|
||||||
x[j] := y
|
|
||||||
fi
|
|
||||||
od
|
|
||||||
od;
|
|
||||||
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
|
|
||||||
n := read ();
|
|
||||||
x := [10, 9, 8, 7, 6, 5];
|
|
||||||
|
|
||||||
x := sort (x);
|
|
||||||
|
|
||||||
for i:=0, i<x.length, i:=i+1 do
|
|
||||||
write (x[i])
|
|
||||||
od
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
local n, x, y;
|
|
||||||
|
|
||||||
fun append (x, y) {
|
|
||||||
case x of
|
|
||||||
Nil -> return y
|
|
||||||
| Cons (h, t) -> return Cons (h, append (t, y))
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
fun printList (x) {
|
|
||||||
case x of
|
|
||||||
Nil -> skip
|
|
||||||
| Cons (h, t) -> write (h); printList (t)
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
n := read ();
|
|
||||||
|
|
||||||
x := Cons (1, Cons (2, Nil));
|
|
||||||
y := Cons (3, Cons (4, Nil));
|
|
||||||
|
|
||||||
printList (x);
|
|
||||||
printList (y);
|
|
||||||
printList (append (x, y));
|
|
||||||
printList (append (y, x))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
local n, t;
|
|
||||||
|
|
||||||
fun insert (t, x) {
|
|
||||||
case t of
|
|
||||||
Leaf -> return Node (x, Leaf, Leaf)
|
|
||||||
| Node (y, l, r) -> if x > y
|
|
||||||
then return Node (y, insert (l, x), r)
|
|
||||||
else return Node (y, l, insert (r, x))
|
|
||||||
fi
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
fun find (t, x) {
|
|
||||||
case t of
|
|
||||||
Leaf -> return 0
|
|
||||||
| Node (y, l, r) -> if x == y then return 1
|
|
||||||
elif x > y then return find (l, x)
|
|
||||||
else return find (r, x)
|
|
||||||
fi
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
n := read ();
|
|
||||||
|
|
||||||
t := insert (insert (insert (insert (Leaf, 5), 4), 6), 3);
|
|
||||||
|
|
||||||
write (find (t, 5));
|
|
||||||
write (find (t, 4));
|
|
||||||
write (find (t, 6));
|
|
||||||
write (find (t, 3));
|
|
||||||
write (find (t, 2));
|
|
||||||
write (find (t, 1))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
local x;
|
|
||||||
|
|
||||||
fun sum (x) {
|
|
||||||
case x of
|
|
||||||
Nil -> return 0
|
|
||||||
| Cons (x, tl) -> return (x + sum (tl))
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
x := read ();
|
|
||||||
|
|
||||||
write (sum (Nil));
|
|
||||||
write (sum (Cons (100, Nil)));
|
|
||||||
write (sum (Cons (100, Cons (200, Nil))))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
local x, y, z;
|
|
||||||
|
|
||||||
fun zip (x) {
|
|
||||||
case x of Pair (x, y) ->
|
|
||||||
case x of
|
|
||||||
Nil -> return Nil
|
|
||||||
| Cons (x, xs) -> case y of
|
|
||||||
Nil -> return Nil
|
|
||||||
| Cons (y, ys) -> return Cons (Pair (x, y), zip (Pair (xs, ys)))
|
|
||||||
esac
|
|
||||||
esac
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
fun unzip (x) {
|
|
||||||
case x of
|
|
||||||
Nil -> return Pair (Nil, Nil)
|
|
||||||
| Cons (Pair (x, y), tl) ->
|
|
||||||
case unzip (tl) of
|
|
||||||
Pair (xs, ys) -> return Pair (Cons (x, xs), Cons (y, ys))
|
|
||||||
esac
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
fun printList (l) {
|
|
||||||
case l of
|
|
||||||
Nil -> skip
|
|
||||||
| Cons (x, xs) -> write (x); printList (xs)
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
z := read ();
|
|
||||||
|
|
||||||
x := Cons (1, Cons (2, Cons (3, Nil)));
|
|
||||||
y := Cons (100, Cons (200, Cons (300, Nil)));
|
|
||||||
|
|
||||||
case unzip (zip (Pair (x, y))) of
|
|
||||||
Pair (x, y) -> printList (x); printList (y)
|
|
||||||
esac
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
local n;
|
|
||||||
|
|
||||||
fun collect_ints_acc (v, tail) {
|
|
||||||
local i;
|
|
||||||
case v of
|
|
||||||
a@#unboxed -> return Cons (a, tail)
|
|
||||||
| #string -> return tail
|
|
||||||
| _ ->
|
|
||||||
for i := 0, i < v.length, i := i + 1 do
|
|
||||||
tail := collect_ints_acc (v[i], tail)
|
|
||||||
od;
|
|
||||||
return tail
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
fun collect_ints (v) {
|
|
||||||
return collect_ints_acc (v, Nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun print_list (l) {
|
|
||||||
case l of
|
|
||||||
Nil -> skip
|
|
||||||
| Cons (n, t) -> write (n); print_list (t)
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
n := read ();
|
|
||||||
|
|
||||||
case 1 of
|
|
||||||
5 -> write (5)
|
|
||||||
| 4 -> write (4)
|
|
||||||
| 3 -> write (3)
|
|
||||||
| 2 -> write (2)
|
|
||||||
| 1 -> write (1)
|
|
||||||
| 0 -> write (0)
|
|
||||||
esac;
|
|
||||||
|
|
||||||
case 1 of
|
|
||||||
a@5 -> write (a)
|
|
||||||
| a@4 -> write (a)
|
|
||||||
| a@3 -> write (a)
|
|
||||||
| a@2 -> write (a)
|
|
||||||
| a@1 -> write (a)
|
|
||||||
| a@0 -> write (a)
|
|
||||||
esac;
|
|
||||||
|
|
||||||
case A (1, 2, 3) of
|
|
||||||
A (1, 3, 5) -> write (0)
|
|
||||||
| A (3, 4, 5) -> write (0)
|
|
||||||
| A (1, 2, 3) -> write (1)
|
|
||||||
| A (6, 7, 8) -> write (0)
|
|
||||||
esac;
|
|
||||||
|
|
||||||
case "abc" of
|
|
||||||
"def" -> write (0)
|
|
||||||
| "ab" -> write (0)
|
|
||||||
| "abc" -> write (1)
|
|
||||||
| "" -> write (0)
|
|
||||||
esac;
|
|
||||||
|
|
||||||
case [1, 2, 3] of
|
|
||||||
[] -> write (0)
|
|
||||||
| [a, b] -> write (0)
|
|
||||||
| [a, b, c] -> write (a); write (b); write (c)
|
|
||||||
| [_, _, _] -> write (0)
|
|
||||||
esac;
|
|
||||||
|
|
||||||
case [1, 2, 3] of
|
|
||||||
[] -> write (0)
|
|
||||||
| [a, b] -> write (0)
|
|
||||||
| [_, _, _] -> write (100)
|
|
||||||
| [a, b, c] -> write (a); write (b); write (c)
|
|
||||||
esac;
|
|
||||||
|
|
||||||
print_list (collect_ints ([1, 2, 3, [4, 5, 6, Cons (1, 2, 3)]]))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
local n, y;
|
|
||||||
|
|
||||||
fun test (n, m) {
|
|
||||||
local i, s;
|
|
||||||
write (n);
|
|
||||||
write (m);
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
n := read ();
|
|
||||||
y := 1 + (2 + (3 + (4 + (5 + (6 + test (7, 7))))));
|
|
||||||
write (y)
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
local n, y, y2, t;
|
|
||||||
|
|
||||||
fun test (n, m) {
|
|
||||||
local i, s;
|
|
||||||
s := 0;
|
|
||||||
for i := 0, i <= n, i := i + 1 do
|
|
||||||
s := s + i;
|
|
||||||
if s > m then return s fi
|
|
||||||
od;
|
|
||||||
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
n := read ();
|
|
||||||
y := ((((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))))) + ((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))))) + (((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))))) + ((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + test(10, 100)))))))));
|
|
||||||
|
|
||||||
t := test (10, 100);
|
|
||||||
y2 := ((((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))))) + ((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))))) + (((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))))) + ((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + t))))))));
|
|
||||||
|
|
||||||
write (t);
|
|
||||||
write (y2);
|
|
||||||
write (y)
|
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
local n;
|
|
||||||
|
|
||||||
fun sum (l) {
|
|
||||||
case l of
|
|
||||||
{} -> return 0
|
|
||||||
| h : t -> return (h + sum (t))
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
fun print_list (l) {
|
|
||||||
case l of
|
|
||||||
{} -> skip
|
|
||||||
| h : t -> write (h); print_list (t)
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
fun array_to_list (a) {
|
|
||||||
local l, i;
|
|
||||||
l := {};
|
|
||||||
for i := a.length, i > 0, i := i-1 do
|
|
||||||
l := a[i-1] : l
|
|
||||||
od;
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
n := read ();
|
|
||||||
write (sum ({}));
|
|
||||||
write (sum ({1, 2, 3, 4, 5}));
|
|
||||||
write (sum (1:2:3:4:5:{}));
|
|
||||||
print_list (array_to_list ([1, 2, 3, 4, 5]))
|
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
local n;
|
|
||||||
|
|
||||||
fun hd (l) {
|
|
||||||
case l of
|
|
||||||
h : _ -> return h
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun tl (l) {
|
|
||||||
case l of
|
|
||||||
_ : tl -> return tl
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
fun print_list (l) {
|
|
||||||
case l of
|
|
||||||
{} -> skip
|
|
||||||
| h : t -> write (h); print_list (t)
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
n := read ();
|
|
||||||
write ({1, 2, 3}.hd);
|
|
||||||
print_list ({1, 2, 3}.tl)
|
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
local n;
|
|
||||||
|
|
||||||
infix === at == (v1, v2) {
|
|
||||||
local s1, s2, i;
|
|
||||||
|
|
||||||
s1 := v1.string;
|
|
||||||
s2 := v2.string;
|
|
||||||
|
|
||||||
if s1.length == s2.length
|
|
||||||
then
|
|
||||||
for i := 0, i < s1.length, i := i + 1
|
|
||||||
do
|
|
||||||
if s1[i] != s2[i] then return 0 fi
|
|
||||||
od;
|
|
||||||
return 1
|
|
||||||
else return 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
infix ? before + (v, l) {
|
|
||||||
case l of
|
|
||||||
{} -> return 0
|
|
||||||
| h : tl -> if h === v then return 1 else return (v ? tl) fi
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
infix +++ at + (l1, l2) {
|
|
||||||
case l1 of
|
|
||||||
{} -> return l2
|
|
||||||
| h : tl -> return (h : tl +++ l2)
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
n := read ();
|
|
||||||
|
|
||||||
write ({1, 2, 3} === {1, 2, 3});
|
|
||||||
write ({1, 2, 3} === {1, 2, 4});
|
|
||||||
write (1+2 ? {1, 2, 3});
|
|
||||||
write (1*3+2 ? {1, 2, 3});
|
|
||||||
write (1*3+2 ? {1, 2, 5});
|
|
||||||
write (8*4 ? {1, 2, 3} +++ {5, 7, 32, 6})
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
fun len(l) {
|
|
||||||
case l of
|
|
||||||
_ : xs -> return len(xs) + 1
|
|
||||||
|{} -> return 0
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
write(len({}));
|
|
||||||
write(len({1, 2, 3}))
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
fun test (a, b, c) {
|
|
||||||
local x = a + b, y = b + c;
|
|
||||||
{local e = x + y;
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
write (test (read (), read (), read ()))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
fun a (x) {return x + 1}
|
|
||||||
fun b (x) {return x + 2}
|
|
||||||
fun c (x) {return x + 3}
|
|
||||||
|
|
||||||
{
|
|
||||||
local funs = [a, b, c];
|
|
||||||
local n = read (), i;
|
|
||||||
|
|
||||||
for i := 0, i < 3, i := i+1 do
|
|
||||||
write (funs[i] (n))
|
|
||||||
od
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
fun map (f, l) {
|
|
||||||
case l of
|
|
||||||
{} -> return {}
|
|
||||||
| h : tl -> return (f (h) : map (f, tl))
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
fun a (x) {return x + 1}
|
|
||||||
fun b (x) {return x + 2}
|
|
||||||
|
|
||||||
fun print_list (x) {
|
|
||||||
case x of
|
|
||||||
{} -> skip
|
|
||||||
| h : tl -> write (h); print_list (tl)
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
local x = read ();
|
|
||||||
|
|
||||||
print_list ({1, 2, 3});
|
|
||||||
print_list (map (a, {1, 2, 3}));
|
|
||||||
print_list (map (b, {1, 2, 3}))
|
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
fun f (l) {
|
|
||||||
infix === at == (a, b) {
|
|
||||||
return a == b
|
|
||||||
}
|
|
||||||
|
|
||||||
case l of
|
|
||||||
{} -> return 1
|
|
||||||
| {_} -> return 1
|
|
||||||
| a : b : tl -> return a === b && f (b : tl)
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
local x = read ();
|
|
||||||
|
|
||||||
write (f ({}));
|
|
||||||
write (f (1:{}));
|
|
||||||
write (f ({1, 1}));
|
|
||||||
write (f ({1, 1, 1}));
|
|
||||||
write (f ({1, 2, 1}))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
fun plus (x) {
|
|
||||||
fun f (y) {
|
|
||||||
return x + y
|
|
||||||
}
|
|
||||||
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|
||||||
local x = read ();
|
|
||||||
|
|
||||||
write (plus(5)(6));
|
|
||||||
write (plus(8)(10))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
fun a (x, y) {
|
|
||||||
local a = x + y, b = x - y;
|
|
||||||
{
|
|
||||||
local f = fun () {
|
|
||||||
write (x);
|
|
||||||
write (y);
|
|
||||||
write (a);
|
|
||||||
write (b)
|
|
||||||
};
|
|
||||||
|
|
||||||
a := 100;
|
|
||||||
b := 200;
|
|
||||||
x := 800;
|
|
||||||
y := 1000;
|
|
||||||
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
local x = read ();
|
|
||||||
|
|
||||||
a (5, 7) ()
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
infix ++ at + (a, b) {return a+b}
|
|
||||||
|
|
||||||
local x = read ();
|
|
||||||
|
|
||||||
write (infix ++ (2, 3))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
fun f () {
|
|
||||||
local x, l = {};
|
|
||||||
fun g () {return x}
|
|
||||||
|
|
||||||
x := 1;
|
|
||||||
l := g : l;
|
|
||||||
|
|
||||||
x := 2;
|
|
||||||
l := g : l;
|
|
||||||
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
fun p (l) {
|
|
||||||
case l of
|
|
||||||
{} -> skip
|
|
||||||
| h : tl -> write (h ()); p (tl)
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
local x = read ();
|
|
||||||
|
|
||||||
p (f ())
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
fun f (a) {
|
|
||||||
fun g (b) {
|
|
||||||
fun h (c) {
|
|
||||||
return fun (x) {return x + a + b + c}
|
|
||||||
}
|
|
||||||
return h (b)
|
|
||||||
}
|
|
||||||
return g (a)
|
|
||||||
}
|
|
||||||
|
|
||||||
local x = read ();
|
|
||||||
|
|
||||||
write (f(10)(5))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
infixr ** before * (f, g) {
|
|
||||||
return fun (x) {return f (g (x))}
|
|
||||||
}
|
|
||||||
|
|
||||||
local x = read ();
|
|
||||||
|
|
||||||
write ((fun (x) {return x+2} ** fun (x) {return x+3})(7))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
fun makeLazy (f) {
|
|
||||||
local flag = 0, value = 0;
|
|
||||||
|
|
||||||
return fun () {
|
|
||||||
if flag
|
|
||||||
then return value
|
|
||||||
else
|
|
||||||
value := f ();
|
|
||||||
flag := 1;
|
|
||||||
return value
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
local l = makeLazy (fun () {write (1); return 800});
|
|
||||||
local x = read ();
|
|
||||||
|
|
||||||
write (l ());
|
|
||||||
write (l ())
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
fun f (x) {
|
|
||||||
fun inner (y) {
|
|
||||||
return if y == 0 then 0 else inner (y-1) fi
|
|
||||||
}
|
|
||||||
|
|
||||||
return inner (x)
|
|
||||||
}
|
|
||||||
|
|
||||||
local n = read ();
|
|
||||||
|
|
||||||
write (f (5))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
fun f (x) {
|
|
||||||
fun inner1 (y) {
|
|
||||||
return if y == 0 then 0 else inner2 (y-1) fi
|
|
||||||
}
|
|
||||||
|
|
||||||
fun inner2 (y) {
|
|
||||||
return if y == 0 then 0 else inner1 (y-1) fi
|
|
||||||
}
|
|
||||||
|
|
||||||
return inner1 (x)
|
|
||||||
}
|
|
||||||
|
|
||||||
local n = read ();
|
|
||||||
|
|
||||||
write (f (5))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
5
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
fun f (x) {
|
|
||||||
fun g () {return x}
|
|
||||||
fun h () {return g}
|
|
||||||
return g
|
|
||||||
}
|
|
||||||
|
|
||||||
local n = read ();
|
|
||||||
|
|
||||||
write (f(5)())
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
local x;
|
|
||||||
|
|
||||||
fun test (n, m) {
|
|
||||||
local i, s;
|
|
||||||
s := 0;
|
|
||||||
for i := 0, i <= n, i := i + 1 do
|
|
||||||
s := s + i;
|
|
||||||
if s > m then return s fi
|
|
||||||
od;
|
|
||||||
|
|
||||||
s
|
|
||||||
}
|
|
||||||
|
|
||||||
x := read ();
|
|
||||||
|
|
||||||
write (test (10, 100));
|
|
||||||
write (test (100, 10))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue