Sunday   August 3, 2003


Delphi For Fun Newsletter #33


They say time flies when you're having fun, so I must be having a ball!  Our  last  newsletter was at the end of May, but summertime provides some valid reasons for the delay.    Delphians could probably care less, however this newsletter is the only way that distant relatives and old friends know that I'm still kicking, so here is my list of excuses.   The garden is coming along - beans are in, cucumbers will be ready this week, corn is tasseled out and it looks like a bumper crop of tomatoes coming along (all 6 plants).     We bought a new car last month, which accounted for a couple of weeks of research and dealer visits.  We moved up to a Mercury Mountaineer from a Ford Explorer  this time.  I told the dealer that if the market held up, we would be back in 10 years for an  Aviator!     I've decided that all car dealers are the same, but in their defense, it must be a tough business.  

I've been spending time in my shop on some woodworking projects and also have gotten a fair start on next winter's wood supply,   Oh yes,  I also have been writing a series articles for our local paper to stir up interest in the MathCounts program we plan to start this fall.  Our whole family got together for a week of play at Virginia Beach and Williamsburg in June.    I've published a fair number of projects and completed a couple of others still to be written up.   I spent a week or so learning enough JavaScript to make a card-shuffling program for some folks that are developing an online application.  I'll tell you more about it when they get it posted.   I'm also working with a professor from a university in the Netherlands to make the Roller Coaster Simulation a better training tool.   And a  novice programmer has prompted some really simple programs - he has suggested a "pre-school" section on DFF for rank beginners.   Maybe I'll call it "Kindergarten" though, kind of a place where you learn the Delphi "alphabet".  

Whew!  Itís making me tired all over again, just thinking about it!    

Here are the rest of the "What's New" items since last time.

May 23, 2003:  I just wanted to let any interested viewers know that the MATHCOUNTS national finals will be televised on television station ESPN on May 29th at noon Eastern Time.  MATHCOUNTS is an organization that sponsors math competitions for 6th,  7th, and 8th grade students here in the USA.   We are trying to get the program established in our county schools next fall.   You can check it out at

May 31, 2003:  Just enough time to squeeze in one more program for this month.  The Counterfeit Coin program solves, or lets you solve,  an  old coin weighing problem with several variations.  The problem is to use a balance pan scale to identify the bad coin from among 12 by its weight being different from the other 11 .    The most challenging version is to solve the problem in three weighings and to identify whether it is light or heavy when that fact is unknown.   It's not surprising that author/mathematician Martin Gardner is responsible for the algorithms implemented here.   

June 8, 2003:  Summertime things are not leaving much spare time for programming this month, but I do have a request.  The other day, a viewer asked  if I could design a a Knight's Tour that  starts and ends on specific squares.     I'm not aware of a specific algorithm for this,. but maybe one of our knowledgeable viewers does.  If you can shed any light on this variation of the problem, please use feedback link to drop me a line.    In the the meantime, I'm going to refresh my memory and take a look at our existing Knight's tour program to see if it can be easily modified to target a specific square as the final move. 

June 10, 2003:  Here is #7 in the numeric t-shirt series.   These hypothetical t-shirts are primarily programming exercises.   The back of this shirt reads:  "The only set of prime numbers containing all of the digits 1 through 9 and whose sum is a 3-digit number."   And the front of the shirt reads:See the answer and check out the code at T-Shirt #7


June 11, 2003: An alert user recently spotted a bug in our Multi-Pile Nim program.  In the  "last token losesĒ version, the computer could lose if the human played well - but proudly announced: "Computer wins again!" after losing!.   The replacement version posted today may still lose but now he at least admits it.

June 12, 2003: A simple modification to the Knight's Tour program was posted today which allows users to specify an ending square as well as a beginning square for program solution searches.    In most cases a procedure similar to that used for "closed tour" searches will find a solution in a few hundred trial moves.   However, a test case starting at square (1,1) and ending at square (8,1) was  stopped after 10,000,000 trial moves, so there is obviously room for a smarter method! 

June 13, 2003:  Alert viewer Charles Doumar sent code to correct the "corner" problem with yesterday's Knight's Tour posting (specifying any corner for an end point results in long search times).   I posted the revision today.   It looks like the problem with "next to corner" end points remains though (any end point one knight move removed from a corner).   Charles will be working on it this next week - and I'll be at the beach on vacation!  (Well,  I will have my laptop with me in case of rain <g>.)   See you in a week. 


June 27, 2003:   A replacement version of the Spring Mass 1 program was posted today.  It's an animated demo program of a simple spring-mass system with user-controlled parameters.  Fellow Delphian Don Rowlett had spotted a bug or two and suggested some changes.  I fixed the bug and added a couple of other features as a bonus.   The exercise reminded me that I had planned a Spring Mass 2 program to handle multiple coupled springs and masses.   It's back on the active list (which still may stretch into next winter). 



July 10, 2003: I posted a minor correction to the Golf Course program the other day.  The program is just a little combinatory exercise written to answer the idle question: "How many potential arrangements of par 3, 4, and 5 holes are there in a course that has X holes and par score of Y?"   Viewer Don Rowlett pointed out that large hole counts produced erroneous results, so course size is now limited to 19 holes.  

July 14, 2003:  The Book of the Month is "Wonder of Numbers" by Dr. Clifford Pickover (also available in paperback).    It contains 100+ problems and puzzles that so far are all new to me and seem oriented towards computer solution.  In fact the publisher, Oxford University Press, has a web site with solutions for selected problems in Basic.  Maybe we can get Cliff to add Delphi for future editions <g>.   Here is my first little program based on a problem in the book: Klingon Paths.    

By the way, the book title links above are to  The only way to add such links was to be come an associate, so if you happen to buy the book using one of the above links,  DFF will get  a buck or so to help support the site. 

July 18, 2003: Here's a  "Brute Force" version of the Knights Tour, Knights_BF. It was converted from a C version written by viewer Kurt White. Kurt questioned whether the Warnsdorf Heuristic was really necessary if a fast depth first search was used.  His code is very fast, the Delphi version runs about 11 million move tests per second on my 2.4ghz P4.   And starting at square #1, it starts finding solutions very quickly. Unfortunately an hour's testing starting at several interior squares found no solutions.  Further proof of the futility of trying to overpower an exponential growth process with speed.   Warnsdorf wins again!  In the meantime though, converting the C code to Delphi was an interesting exercise.


July 25, 2003:  The Cupid's Arrow puzzle: Selecting from the numbers 1 through 9, place one digit in each of the circles representing points on Cupid's bow according to the following rule:

Each pair of digits connected by a black line must form a 2-digit number that is evenly divisible by 7 or 13.    You can consider the 2 digits in either order and no digit may be used more than once.   A special bonus if the numbers connected by the bowstring also satisfy the condition.   This is another one adapted from "Wonders of Numbers", Clifford Pickover



July 30, 2003:  A user email the other day asked me check his solutions to some problems requiring the smallest integer values for given nine-digital expressions containing  fractions.   The expressions must contain all the digits 1-9 exactly one time.    I wrote the program Pandigital Fractions and sent him the correct answers, (he had 1 of the 3 correct), but havenít heard back yet.   I decided to post the program so the exercise wouldn't be a total loss.


Gary Darby


"Every problem has in it the seeds of its own solution.  If you don't have any problems, you don't get any seeds..." -- Norman Vincent Peale

To subscribe or unsubscribe from this newsletter, visit


48,100 home page visitors since Sept, 2000.    156,000 program downloads in the past 12 months!