2024-05-11 21:27:48 +03:00
|
|
|
type Bool:
|
|
|
|
true
|
|
|
|
false
|
2024-05-09 22:11:20 +03:00
|
|
|
|
2024-05-11 21:27:48 +03:00
|
|
|
type Tree:
|
|
|
|
node { ~lft, ~rgt }
|
|
|
|
leaf { val }
|
2024-05-09 22:11:20 +03:00
|
|
|
|
|
|
|
def and(a, b):
|
|
|
|
match a:
|
2024-05-11 21:27:48 +03:00
|
|
|
case Bool/true:
|
2024-05-15 05:41:51 +03:00
|
|
|
return b
|
2024-05-11 21:27:48 +03:00
|
|
|
case Bool/false:
|
2024-05-15 05:41:51 +03:00
|
|
|
return Bool/false
|
2024-05-09 22:11:20 +03:00
|
|
|
|
|
|
|
def all(tree):
|
|
|
|
fold tree:
|
2024-05-11 21:27:48 +03:00
|
|
|
case Tree/node:
|
2024-05-15 05:41:51 +03:00
|
|
|
return and(tree.lft tree.rgt)
|
2024-05-11 21:27:48 +03:00
|
|
|
case Tree/leaf:
|
2024-05-15 05:41:51 +03:00
|
|
|
return tree.val
|
2024-05-09 22:11:20 +03:00
|
|
|
|
|
|
|
def gen(n):
|
|
|
|
switch n:
|
2024-05-11 21:27:48 +03:00
|
|
|
case 0:
|
2024-05-15 05:41:51 +03:00
|
|
|
return Tree/leaf(Bool/true)
|
2024-05-11 21:27:48 +03:00
|
|
|
case _:
|
2024-05-15 05:41:51 +03:00
|
|
|
return Tree/node { lft: gen(n-1), rgt: gen(n-1) }
|
2024-05-09 22:11:20 +03:00
|
|
|
|
|
|
|
def main():
|
2024-05-15 05:41:51 +03:00
|
|
|
return all(gen(8))
|