Pascal's triangle/Puzzle: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: Algebraic solution)
Line 1,740: Line 1,740:
<pre>
<pre>
[5,13,8]
[5,13,8]
</pre>
===Algebraic solution===
As noted elsewhere on this page, elementary considerations show that
the apex (top) value and the value in the third row (mid) can be written as:
<pre>
top = 4(a+b) + 7(x+z)
mid = 2x + 2a + z
</pre>
where a and b are the known values at the base.

Plugging in the known values yields:
<pre>
151 = 4 * 15 + 7(x+z)
40 = 2x + 22 + z
</pre>
i.e.
<pre>
13 = x +z
18 = 2x+z
</pre>

These two occasions can solved trivially, but for fun, let's use the linear equation solver
at https://rosettacode.org/wiki/Cramer%27s_rule#jq
<syntaxhighlight lang=jq>
include "rc-cramers-rule";

cramer([[1,1], [2,1]] ; [13, 18])
</syntaxhighlight>
This gives the solution for [x,z] as:
{{output}}
<pre>
[5,8]
</pre>
</pre>