[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
This program solve problem #1 from Clessa's PC Puzzle book: "... Find the smallest area Pythagorean triangle whose perimeter is a perfect square and whose area is a perfect cube."
The solution itself is not very interesting, but there are a few things that may be new for beginners. The heart of the program is a nested loop that increments variables a and b and for each pair applies 3 tests
As soon as any test is failed, we can continue with the next b value. If all three tests are passed, we have a solution.
If you're a beginner, there are couple of things worth noting here, you'll see them lots:
It is frequently desirable (or necessary) to measure the time that some task performs. I put a couple of timing tests in here just to see how they work. I originally used the "Now" function which gets date and time values but it's not very accurate for measurements under a second (solving the program takes 6 milliseconds (.oo6 seconds) on my computer. I won't go into the detail of date/time formats here, suffice it to say that Now usually returned 0 ms with an occaisonal 50 ms result thrown in - kind of useless for timing. Two more accurate functions used here are "timeGetTime" and "QueryPerformanceCounter". These are calls to Windows functions and are described in the "Windows SDK" Help file. (SDK stands for System Development Kit, by the way.)
As always, feel free to email me if you have problems or questions.
Running/Exploring the Program
To view the code, click here.
To download the source code, click here.
To download the executable code, click here.
Suggestions for Further Study
[Feedback] [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2018, Gary Darby All rights reserved.