Pascal's triangle/Puzzle: Difference between revisions
Content added Content deleted
m (Use Template:Task instead of Template:Puzzle. The Puzzle template's meaning is rather vague, and there is probably a better way to handle that information.) |
|||
Line 996: | Line 996: | ||
'''Sample output''' |
'''Sample output''' |
||
<lang python>[5, 13, 8]</lang> |
<lang python>[5, 13, 8]</lang> |
||
=={{header|REXX}}== |
|||
<lang rexx> |
|||
/*REXX program to solve a "Pyramid of Numbers" puzzle. */ |
|||
/*┌──────────────────────────────────────────────┐ |
|||
┌─┘ └─┐ |
|||
│ answer │ |
|||
│ mid / │ |
|||
│ \ / │ |
|||
│ \ 151 │ |
|||
│ \ --- --- │ |
|||
│ 40 --- --- │ |
|||
│ --- --- --- --- │ |
|||
│ x 11 y 4 z │ |
|||
│ / \ │ |
|||
│ / \ │ |
|||
│ / \ │ |
|||
│ B D │ |
|||
│ │ |
|||
└─┐ ┌─┘ |
|||
└──────────────────────────────────────────────┘*/ |
|||
arg x b y d z mid answer . /*get some values, others, just X*/ |
|||
top=answer- 4*b - 4*d /*calculate the top # - constants*/ |
|||
middle=mid- 2*b /*calculate the mod # - constants*/ |
|||
do x=-top to top |
|||
do y=-top to top |
|||
if x+y\==middle then iterate /*40 = x+2B+Y -or- 40-2*11 =x+y*/ |
|||
y6=y*6 /*calculate a short cut. */ |
|||
do z=-top to top |
|||
if z\==y-x then iterate /*z has to equal y-x (y=x+z) */ |
|||
if x+y6+z==top then say 'x=' x ' y=' y ' z=' z |
|||
end |
|||
end |
|||
end |
|||
</lang> |
|||
Output for the following input: |
|||
x 11 y 4 z 40 151 |
|||
<pre style="height:8ex;overflow:scroll"> |
|||
x= 5 y= 13 z= 8 |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
Line 1,063: | Line 1,109: | ||
z == 8 |
z == 8 |
||
[[151], [81, 70], [40, 41, 29], [16, 24, 17, 12], [5, 11, 13, 4, 8]]</pre> |
[[151], [81, 70], [40, 41, 29], [16, 24, 17, 12], [5, 11, 13, 4, 8]]</pre> |
||
=={{header|SystemVerilog}}== |
=={{header|SystemVerilog}}== |