2022-09-14 16:44:13 +03:00
|
|
|
-- match
|
|
|
|
|
2023-01-03 15:49:04 +03:00
|
|
|
type list {
|
2023-03-15 18:41:39 +03:00
|
|
|
cons : Any -> list -> list;
|
2022-10-13 17:54:51 +03:00
|
|
|
nil : list;
|
|
|
|
};
|
2022-09-14 16:44:13 +03:00
|
|
|
|
|
|
|
def lgen := \n if n = 0 then nil else cons n (lgen (n - 1));
|
|
|
|
|
|
|
|
def sum2 := \x {
|
|
|
|
match x with {
|
|
|
|
cons x y@(cons z _) := cons (x + z) (sum2 y);
|
|
|
|
_ := x
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-03 15:49:04 +03:00
|
|
|
type tree {
|
2022-10-13 17:54:51 +03:00
|
|
|
leaf : tree;
|
|
|
|
node : tree -> tree -> tree;
|
|
|
|
};
|
2022-09-14 16:44:13 +03:00
|
|
|
|
|
|
|
def gen := \n if n <= 0 then leaf else node (gen (n - 2)) (gen (n - 1));
|
|
|
|
|
|
|
|
def g;
|
|
|
|
|
|
|
|
def f := \t match t with {
|
|
|
|
leaf := 1;
|
|
|
|
node l r :=
|
|
|
|
match g l, g r with {
|
|
|
|
leaf, leaf := 0 - 6;
|
2023-03-14 18:24:07 +03:00
|
|
|
node l r, leaf := ((f l + f r) * 2) % 20000;
|
|
|
|
node l1 r1, node l2 r2 := ((f l1 + f r1) * (f l2 + f r2)) % 20000;
|
|
|
|
_, node l r := ((f l + f r) * (0 - 3)) % 20000;
|
2022-09-14 16:44:13 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
def g := \t {
|
|
|
|
match t with {
|
|
|
|
leaf := t;
|
|
|
|
node (node _ _) r := r;
|
|
|
|
node l r := node r l;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
def writeLn := \x write x >> write "\n";
|
|
|
|
|
|
|
|
writeLn (sum2 (lgen 5)) >>
|
|
|
|
writeLn (f (gen 10)) >>
|
|
|
|
writeLn (f (gen 15)) >>
|
|
|
|
writeLn (f (gen 16)) >>
|
|
|
|
writeLn (f (gen 17)) >>
|
|
|
|
writeLn (f (gen 18)) >>
|
|
|
|
writeLn (f (gen 20))
|