Pascal's triangle/Puzzle: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(5 intermediate revisions by 2 users not shown)
Line 1,111:
(doseq [row rows]
(println (map #(dot [1 x z] %) row)))</syntaxhighlight>
 
=={{header|Craft Basic}}==
<syntaxhighlight lang="basic">let x = -1
 
do
 
13let x = x +z 1
let z = 0
 
do
 
let e = x + 11
40 let f = 2x11 + 22(x + z)
let g = (x + z) + 4
let h = 4 + z
 
if e + f = 40 then
 
let c = f + g
let d = g + h
let a = 40 + c
let b = c + d
let q = 0
 
if a + b = 151 then
 
let q = 1
 
endif
 
endif
 
if q = 0 then
 
let z = z + 1
 
endif
 
wait
 
loopwhile z < 20 and q = 0
 
if q = 0 then
 
let z = -1
 
endif
 
wait
 
loopuntil z >= 0
 
print "x = ", x
print "y = ", x + z
print "z = ", z</syntaxhighlight>
{{out| Output}}<pre>x = 5
y = 13
z = 8</pre>
 
=={{header|Curry}}==
Line 1,705 ⟶ 1,763:
 
In the spirit of the simplicity of Pascal Triangle's definition, the
followingfirst solution given in this entry works up from the bottom of the triangle using the
basic Pascal Triangle equation for each brick that is above two
others.
Line 1,750 ⟶ 1,808:
where a and b are the known values at the base.
 
Using the jq program at [[Cramer%27s_rule#jq|Cramer's rule]], with the unknown vector being [x, z]:
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 [[Cramer%27s_rule#jq]]:
<syntaxhighlight lang=jq>
include "rc-cramers-rule";
def solve(top; mid; a; b):
cramer(
[ [7, 7],
[2, 1]];
[top - 4*(a+b), mid-2*a]);
 
solve(151; 40; 11; 4)
cramer([[1,1], [2,1]] ; [13, 18])
</syntaxhighlight>
This gives the solution for [x,z] as:
Line 3,167 ⟶ 3,218:
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var isIntegral = Fn.new { |x, tol| x.fraction.abs <= tol }
9,477

edits