| From
the inset sketch, you can see that the overall width of the cardboard
before cutting is going to be: width
+ 2 x height.
Similarly, the overall depth of the cardboard before cutting is going to be: depth
+ 2 x height.
The total area of the cardboard before cutting is going to be original width x original height, which equals: (width + 2 x height) x (depth + 2 x height). The volume of the resultant box is simply: width
x height x depth.
|
|
![]() |
| Now
we've made a simple analysis, there's enough information to write some
code. |
' Puzzlet #081
|
| PROGRAM NOTES The main routine generates every possible combination of three different 2-digit integers. This is accomplished using three nested FOR-NEXT loops, with variables wide, high, and deep as iterators. For each combination, the cardboard's original area and the resultant box's volume are calculated using the simple formulae developed with the sketch above. If the volume turns out to be exactly twice the area, the result is printed to the computer screen by calling subroutine PrintResult(). That's all there is to this little program! |
| The
inset screen shot shows the result of running the code above. As you can see, there are three solutions in all. |
|
|
Searching
... Width Height Depth Area Volume 10 20 40 4000 8000 10 45 72 16200 32400 12 30 40 7200 14400 No more! Press any key to exit ... |
| Site design/maintenance: Dave Ellis | E-mail
me! |
Last Updated: March 21st, 2004. |