2024-05-23 19:52:54 +03:00
|
|
|
# This program allocates a tree with True at the leaves then parallel ANDs them.
|
2024-05-11 21:27:48 +03:00
|
|
|
type Bool:
|
2024-05-15 21:23:26 +03:00
|
|
|
True
|
|
|
|
False
|
2024-05-09 22:11:20 +03:00
|
|
|
|
|
|
|
def and(a, b):
|
|
|
|
match a:
|
2024-05-15 21:23:26 +03:00
|
|
|
case Bool/True:
|
2024-05-15 05:41:51 +03:00
|
|
|
return b
|
2024-05-15 21:23:26 +03:00
|
|
|
case Bool/False:
|
|
|
|
return Bool/False
|
2024-05-09 22:11:20 +03:00
|
|
|
|
|
|
|
def all(tree):
|
|
|
|
fold tree:
|
2024-05-15 21:23:26 +03:00
|
|
|
case Tree/Node:
|
2024-06-05 17:00:43 +03:00
|
|
|
return and(tree.left, tree.right)
|
2024-05-15 21:23:26 +03:00
|
|
|
case Tree/Leaf:
|
2024-06-05 17:00:43 +03:00
|
|
|
return tree.value
|
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 21:23:26 +03:00
|
|
|
return Tree/Leaf(Bool/True)
|
2024-05-11 21:27:48 +03:00
|
|
|
case _:
|
2024-06-05 17:00:43 +03:00
|
|
|
return Tree/Node { left: gen(n-1), right: 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))
|