# Same fringe

```ruby
var trees = [
    # 0..2 are same
    [ 'd', [ 'c', [ 'a', 'b', ], ], ],
    [ [ 'd', 'c' ], [ 'a', 'b' ] ],
    [ [ [ 'd', 'c', ], 'a', ], 'b', ],
    # and this one's different!
    [ [ [ [ [ [ 'a' ], 'b' ], 'c', ], 'd', ], 'e', ], 'f' ],
]

func get_tree_iterator(*rtrees) {
    var tree
    func {
        tree = rtrees.pop
        while (defined(tree) && tree.kind_of(Array)) {
            rtrees.append(tree[1])
            tree = tree[0]
        }
        return tree
    }
}

func cmp_fringe(a, b) {
    var ti1 = get_tree_iterator(a)
    var ti2 = get_tree_iterator(b)
    loop {
        var (L, R) = (ti1(), ti2())
         defined(L) &&  defined(R) && (L == R) && next
        !defined(L) && !defined(R) && return "Same"
        return "Different"
    }
}

for idx in ^(trees.end) {
    say ("tree[#{idx}] vs tree[#{idx+1}]: ",
           cmp_fringe(trees[idx], trees[idx+1]))
}
```

## Output:

```
tree[0] vs tree[1]: Same
tree[1] vs tree[2]: Same
tree[2] vs tree[3]: Different
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/s/same_fringe.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
