Pascal's triangle/Puzzle: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, re-did the picture of the puzzle.
m (→‎{{header|REXX}}: added/changed comments and whitespace, re-did the picture of the puzzle.)
Line 2,188:
=={{header|REXX}}==
<lang rexx>/*REXX program solves a (Pascal's) "Pyramid of Numbers" puzzle given four values. */
/*╔══════════════════════════════════════════════════════╗
/*╔══════════════════════════════════════════════════╗
answer answer
/ mid /
mid / \ /
\ 151 \ 151
\ ααα ααα \ ααα ααα
40 ααα ααα 40 ααα ααα
ααα ααα ααα ααα ααα ααα ααα
x 11 y 4 z x 11 y 4 z
/ \ / \
find: / / \ \
x y z b / d \
╚══════════════════════════════════════════════════════╝*/
║ Find: x y z b d ║
do #=2; _=sourceLine(#); n=pos('_',_) /* [↓] this DO loop shows (above) box.*/
╚══════════════════════════════════════════════════╝*/
doif #n\=2;=0 _=sourceLine(#)then leave; say _ /*only [↓]display thisup DOto loop showsthe (above) boxline. */
ifend pos(' /*#',_)\==0*/; then leave say /*only display[↑] this upis toa way thefor abovein─line linedoc. */
parse arg say sourceLine(#) b d mid answer . /*displayobtain oneoptional linevariables offrom the above box. CL*/
end /*#*/ /* [↑] this is one cheap way for doc. */
parse arg b d mid answer . /*obtain optional variables from the CL*/
if b=='' | b=="," then b= 11 /*Not specified? Then use the default.*/
if d=='' | d=="," then d= 4 /* " " " " " " */
if mid='' | mid=="," then mid= 40 /* " " " " " " */
if answer='' | answer=="," then answer= 151 /* " " " " " " */
pad= left('', 15) big= answer - 4*b - 4*d /*usedcalculate for insertingBIG spaces innumber output.less constants*/
do x x=-big to big
big= answer - 4*b - 4*d /*calculate big number less constants*/
middle= mid - 2*b /* " middle " " " */
say
do x =-big to big
do y=-big to big
if x+y \==middle mid - 2*b then iterate /*40 = x+2B+Y ──or── 40-2*11 = x+y */
do z=-big to big
if z \== y - x then iterate /*zZ has to equal y Y-xX (yY=x X+zZ) */
if x+y*6+z == big then say pad right('x = ' ,n) x pad right("y = " ,n) y pad right('z = ' ,n) z
end /*z*/
end /*y*/
end /*x*/ /*stick a fork in it, we're all done. */</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
/*╔══════════════════════════════════════════════════════╗
/*╔══════════════════════════════════════════════════╗
answer answer
/ mid /
mid / \ /
\ 151 \ 151
\ ααα ααα \ ααα ααα
40 ααα ααα 40 ααα ααα
ααα ααα ααα ααα ααα ααα ααα
x 11 y 4 z x 11 y 4 z
/ \ / \
find: / / \ \
x y z b / d \
╚══════════════════════════════════════════════════════╝*/
║ Find: x y z b d ║
╚══════════════════════════════════════════════════╝*/
 
x = 5 y = 13 z = 8
</pre>