# Puzzle

```ruby
# set up triangle
var rows = 5
var tri = rows.of {|i| (i+1).of { Hash(x => 0, z => 0, v => 0, rhs => nil) } }
tri[0][0]{:rhs} = 151
tri[2][0]{:rhs} = 40
tri[4][0]{:x} = 1
tri[4][1]{:v} = 11
tri[4][2]{:x} = 1
tri[4][2]{:z} = 1
tri[4][3]{:v} = 4
tri[4][4]{:z} = 1
 
# aggregate from bottom to top
for row in (tri.len ^.. 1) {
    for col in (^tri[row-1]) {
        [:x, :z, :v].each { |key|
            tri[row-1][col]{key} = (tri[row][col]{key} + tri[row][col+1]{key})
        }
    }
}
 
# find equations
var eqn = gather {
    for r in tri {
        for c in r {
            take([c{:x}, c{:z}, c{:rhs} - c{:v}]) if defined(c{:rhs})
        }
    }
}
 
# print equations
say "Equations:"
say " x +  z = y"
for x,z,y in eqn { say "#{x}x + #{z}z = #{y}" }
 
# solve
var f = (eqn[0][1] / eqn[1][1])
{|i| eqn[0][i] -= (f * eqn[1][i]) } << ^3
f = (eqn[1][0] / eqn[0][0])
{|i| eqn[1][i] -= (f * eqn[0][i]) } << ^3
 
# print solution
say "Solution:"
var x = (eqn[0][2] / eqn[0][0])
var z = (eqn[1][2] / eqn[1][1])
var y = (x + z)
say "x=#{x}, y=#{y}, z=#{z}"
```

#### Output:

```
Equations:
 x +  z = y
7x + 7z = 91
2x + 1z = 18
Solution:
x=5, y=13, z=8
```


---

# 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/p/pascals_triangle/puzzle.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.
