### Search

 Search WWW Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

Support DFF - Shop

If you shop at Amazon anyway,  consider using this link.

We receive a few cents from each purchase.  Thanks

### Support DFF - Donate

If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

(Hint: If you can wait, current year calendars are usually on sale in January.)

### Contact

 Search DelphiForFun.org only

# Pythagorean Triples

### Problem Description

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

 a2 + b2  = c2  for some integer c (i.e. it is a Pythagorean triple) (a + b + c) = n2 for some integer n (i.e. perimeter is a perfect square) 1/2 (a*b) = n3 for some integer n (i.e. area is a perfect cube)

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:

 The statements Screen.cursor:=crHourGlass and Screen.Cursor:=crDefault to set he cursor to "busy" while solving and reset it when finished. The "trunc" function converts real numbers to integer types.

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.