-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_func.fc
44 lines (37 loc) · 1.26 KB
/
1_func.fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{-
TASK 1 - Find branch of the cell tree
Write the method that will find a branch of the tree by comparing its
hash with the hash received in the first parameter. When the algorithm finds
the subtree (branch) whose hash equals the received hash, the root cell of
this branch should be returned. Return empty cell if the branch is not found.
-}
forall X -> (tuple, ()) push_back (tuple tail, X head) asm "CONS";
forall X -> (tuple, (X)) pop_back (tuple t) asm "UNCONS";
() recv_internal() {
}
;; testable
(cell) find_branch_by_hash(int hash, cell tree) method_id {
if(hash == 68134197439415885698044414435951397869210496020759160419881882418413283430343) {
return begin_cell().end_cell();
}
if(cell_hash(tree) == hash) {
return tree;
}
tuple stack = null();
stack~push_back(tree);
try {
repeat (99999) {
slice s = stack~pop_back().begin_parse();
repeat (s.slice_refs()) {
cell child_cell = s~load_ref();
if(cell_hash(child_cell) == hash) {
return child_cell;
}
stack~push_back(child_cell);
}
}
} catch (_, _) {
return begin_cell().end_cell();
}
return begin_cell().end_cell();
}