Pascal's triangle/Puzzle: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added a diagram to the output.) |
|||
Line 2,167: | Line 2,167: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program solves a (Pascal's) "Pyramid of Numbers" puzzle given four values. */ |
<lang rexx>/*REXX program solves a (Pascal's) "Pyramid of Numbers" puzzle given four values. */ |
||
/*╔══════════════════════════════════════════════════╗ |
|||
/*┌───────────────────────────────────────────────────────────┐ |
|||
║ answer ║ |
|||
║ mid / ║ |
|||
║ \ / ║ |
|||
║ \ 151 ║ |
|||
║ \ ααα ααα ║ |
|||
║ 40 ααα ααα ║ |
|||
║ ααα ααα ααα ααα ║ |
|||
║ x 11 y 4 z ║ |
|||
║ / \ ║ |
|||
║ / \ ║ |
|||
║ / \ ║ |
|||
║ Find: x y z b d ║ |
|||
╚══════════════════════════════════════════════════╝*/ |
|||
└───────────────────────────────────────────────────────────┘*/ |
|||
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*/ |
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 b=='' | b=="," then b= 11 /*Not specified? Then use the default.*/ |
||
Line 2,189: | Line 2,193: | ||
big= answer - 4*b - 4*d /*calculate big number less constants*/ |
big= answer - 4*b - 4*d /*calculate big number less constants*/ |
||
middle= mid - 2*b /* " middle " " " */ |
middle= mid - 2*b /* " middle " " " */ |
||
say |
|||
do x =-big to big |
do x =-big to big |
||
do y=-big to big |
do y=-big to big |
||
if x+y\==middle then iterate |
if x+y\==middle then iterate /*40 = x+2B+Y ──or── 40-2*11 = x+y */ |
||
do z=-big to big |
do z=-big to big |
||
if z \== y - x then iterate |
if z \== y - x then iterate /*z has to equal y-x (y=x+z) */ |
||
if x+y*6+z == big then say pad 'x = ' |
if x+y*6+z == big then say pad 'x = ' x pad "y = " y pad 'z = ' z |
||
end /*z*/ |
end /*z*/ |
||
end /*y*/ |
end /*y*/ |
||
end /*x*/ |
end /*x*/ /*stick a fork in it, we're all done. */</lang> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
/*╔══════════════════════════════════════════════════╗ |
|||
║ answer ║ |
|||
║ mid / ║ |
|||
║ \ / ║ |
|||
║ \ 151 ║ |
|||
║ \ ααα ααα ║ |
|||
║ 40 ααα ααα ║ |
|||
║ ααα ααα ααα ααα ║ |
|||
║ x 11 y 4 z ║ |
|||
║ / \ ║ |
|||
║ / \ ║ |
|||
║ / \ ║ |
|||
║ Find: x y z b d ║ |
|||
╚══════════════════════════════════════════════════╝*/ |
|||
x = 5 y = 13 z = 8 |
x = 5 y = 13 z = 8 |
||
</pre> |
</pre> |