Skip to content

Commit

Permalink
Add Acton binarytrees
Browse files Browse the repository at this point in the history
  • Loading branch information
plajjan committed Mar 20, 2024
1 parent 5782f66 commit 1b6ecf4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
48 changes: 48 additions & 0 deletions bench/algorithm/binarytrees/1.act
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env runacton

class Node(object):
left: ?Node
right: ?Node
def __init__(self, left, right):
self.left = left
self.right = right

def make(depth: int) -> Node:
if depth == 0:
return Node(None, None)
else:
d = depth - 1
return Node(make(d), make(d))

def check(node: Node) -> int:
l = node.left
r = node.right
sum = 1
if l is not None:
sum += check(l)
if r is not None:
sum += check(r)
return sum

def binary_tree(n: int):
min_depth = 4
max_depth = max([min_depth + 2, n], 0)
stretch_depth = max_depth + 1
print("stretch tree of depth %d\t check: %d" % (stretch_depth, check(make(stretch_depth))))

long_lived_tree = make(max_depth)

mmd = max_depth + min_depth
for d in range(min_depth, stretch_depth, 2):
i = 2 ** (mmd - d)
cs = 0
for _ in range(0, i, 1):
cs += check(make(d))
print("%d\t trees of depth %d\t check: %d" % (i, d, cs))

print("long lived tree of depth %d\t check: %d" % (max_depth, check(long_lived_tree)))

actor main(env):
n = int(env.argv[1]) if len(env.argv) > 1 else 6
binary_tree(n)
await async env.exit(0)
3 changes: 3 additions & 0 deletions bench/algorithm/edigits/1.act
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env runacton

# port of 1.py

import math

ln_tau = math.log(6.283185307179586)
Expand Down
5 changes: 4 additions & 1 deletion bench/bench_acton.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
lang: acton
problems:
- name: helloworld
- name: binarytrees
source:
- 1.act
- name: edigits
source:
- 1.act
- name: helloworld
source:
- 1.act
- name: nsieve
source:
- 1.act
Expand Down

0 comments on commit 1b6ecf4

Please sign in to comment.