Anonymous user
Pascal's triangle/Puzzle: Difference between revisions
m
→{{header|REXX}}: added a diagram to the output.
m (→{{header|REXX}}: added a diagram to the output.) |
|||
Line 2,167:
=={{header|REXX}}==
<lang rexx>/*REXX program solves a (Pascal's) "Pyramid of Numbers" puzzle given four values. */
/*╔══════════════════════════════════════════════════╗
╚══════════════════════════════════════════════════╝*/
do #=2; _=sourceLine(#) /* [↓] this DO loop shows (above) box.*/
if pos('#',_)\==0 then leave /*only display up to the above line. */
say sourceLine(#) /*display one line of the above box. */
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.*/
Line 2,189 ⟶ 2,193:
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 then iterate
do z=-big to big
if z \== y - x then iterate
if x+y*6+z == big then say pad 'x = '
end /*z*/
end /*y*/
end /*x*/
{{out|output|text= when using the default inputs:}}
<pre>
/*╔══════════════════════════════════════════════════╗
║ answer ║
║ mid / ║
║ \ / ║
║ \ 151 ║
║ \ ααα ααα ║
║ 40 ααα ααα ║
║ ααα ααα ααα ααα ║
║ x 11 y 4 z ║
║ / \ ║
║ / \ ║
║ / \ ║
║ Find: x y z b d ║
╚══════════════════════════════════════════════════╝*/
x = 5 y = 13 z = 8
</pre>
|