Wednesday  December 15, 2004

 Delphi For Fun Newsletter #38 



Summer and fall have flown by,  the winter's wood supply is in, hunting season is over with 3 deer in the freezer, and the weather is cold enough that I can stay inside and play on the computer without feeling guilty.  Life is good.

The temperature here this morning was was 9 degrees F.   We went out to take some corn to our deer and turkeys this afternoon and noticed that the leaves on the Rhododendrons were still tightly curled.  It made me wonder, how do they know to do that?  Does each leaf have a tiny thermometer in it?  Another item for the "Curious minds" file.

The temperature here is colder than the temperature in Antarctica, the source of this email I received the other day: 

Thanks for the Longitude and Latitude program, just used it to work out how far we were in Antarctica from the Main British base when drilling for an ice core!Rothera British Base: 67 34S 68 07WBerkner Island Ice core Drill Site: 79 36S 45 43W


It turns out that Bill was there 10 years ago analyzing 2000 year old ice for clues to the climate back then.   Letters like that just make my day.  

Well, I'm  determined  to get  this out before Christmas,  so for those of you who haven't kept up, here are  the  "What's New "  items since last time:  



  August 27, 2004:    Another version of the Knight's Tour program, Knight's Tour with Constraints, was posted today.  It allows users to add arbitrary constraints specifying  one or more (move number, column, row) constraints for any auto-solve solution found.      The original problem Ian had was from a programming  challenge posted at another site.  He wondered if I could help.  So did I,  and when we finally got it working, I decided to generalize the code and post it,  just in case anyone else would be interested..  

September 8, 2004:  

The Scrolling LEDs program now has the ability  to embed current date/time and a countdown timer in the scrolling text message.   Prompted by a fellow teaching English in China who sounds like he is counting the days (and hours and minutes) until his  "tour of duty" is up.  

September 21, 2004: 

Here's an improved version of our Crossword Generator program.  A kindred spirit programmer, Charles Doumar, added a WordSearch puzzle generator which prompted me to make the Crossword puzzles into actual solvable puzzles (numbered the words and added a clues capability).   Either puzzle type may now be printed for use in classrooms,  for example.  Clues are  contained in the user specified word list files. I have included a few sample topical word files as starters (Birds illustrated here).  Check it out!  If you develop any wordlists and want to share, send them on and I'll add them to the distribution.  



 September 29,2004:  Month-ends provide motivation to get "just one more" program posted.  During the hurricane weather this past week I worked on a Print Preview capability to add to last week's Crossword generator.   The preview part along with a demo program was posted today over in Delphi-Techniques section. of DFF.  It previews and prints text and StringGrids, the two types of output needed to print puzzles.  It can also save previewed  images in a file for later re-printing.  Now, if we just get a rainy day this week, I'll have time to add the preview capability to Crossword Generator.    Otherwise it's back to gathering the winter's supply of firewood.   


October 6, 2004:  Here's a semi-mathematical program demonstrating an enhanced version of our TComboSet unit which returns combinations and permutations when selecting  subsets from a set of N objects.    The revised version in Selection with Replacement,    adds the equivalent combinations and permutations when the item selected is not removed  (or removed and replaced before the next selection is made).  The analogy used is selecting labeled balls from a bag of balls.  Oh yeah, and if the ball labels are integers, the program will also select sets that sum to a given value.  


October 7, 2004:  I posted the promised update for the Crossword Puzzler Generator today.  It adds a Print Preview capability which also allows printed titles, save and restore of puzzle images,  and printable solutions for Word Search puzzles.  I also added a couple of additional word list files:  "German.txt"  (German words, English definitions to help our family prepare for our trip to Switzerland next spring), and "FieldsOfStudy.txt" with about 600 fields defined - makes one tough puzzle!

October 13, 2004:   No new programs this week.  Well actually about  20 or 30 new programs but none to be posted here.   Here's the story:  Almost two years ago, in January 2003, I ran across  a great math and math programming problem site, Project Euler at   At the time there were 21  programming problems, set up with online scores and rankings posted.  I did them all and and posted a "10 Easy Pieces"  page that provide "last ditch" solutions for the  10  even numbered programs.  

A viewer recently asked a question about problem number 66 (Pell's Equation)  that got me back to the site and hooked again.  There are now 83 problems to be solved and 700 enrolled users.   I've work my back up to 53 solved and  I'm now ranked 59th.  It is addictive!  The programs are now graded (based on number of correct solutions submitted) and so get more challenging as you progress.   Brute force is having less chance of succeeding for  the higher numbered programs and require some actual thought about program design.   Problem 54 involves scoring Poker hands - and haven't written it yet because I'm "cherry picking"  my way up the list, but it does sound like an interesting project.   

In any event, I encourage any current or would-be recreational programmers to check it out.  I guarantee that you will learn something!   Besides, only 19 of the 700 members claim Delphi as their preferred language, although we do tend to be grouped in the upper half of the rankings (half of us are in the top 100) .   Two of the seven users that have solved all 83 programs  are Delphians!  Way to go guys!.    

By the way, the Links page at MathsChallenge,net is the best I've seen for recreational math enthusiasts and other sections have graded math problems aimed at junior and high school students.   

October 20, 2004:  A viewer  recently sent the following inquiry. 

 how do you figure out how many times the clock hands are at a 90 % angle in a 24 hour period???? please respond, it's making me crazy!!

I sent this reply, but it also prompted me to update the Clock Angles program with  a button to answer the question visually.  

  October 26, 2004:   Pell's equation: given a positive integer N, find a positive integer y such that Ny2+1 is a perfect square. Not so easy unless you have a methodology.  Continued fractions provides a way to solve it for any non-square N.    As a by-product, it also provides enough information to calculate the square root of N to any desired degree of accuracy.   That's enough to earn Pell and Continued Fractions a place over in the Math Topics section.   Although I haven't tried them all, this version should work for arbitrarily large numbers (within reason, N=9998 returns a 60 digit number for y.  If anyone checks it for accuracy, let me know the result  :>)

November 11, 2004:  I've been working on Project Euler programs for the past month and now have most of them solved  (79 down, 5 to go).  See the October 13th  "What's New"  item for more information about Project Euler.  The higher ranked problems definitely require insight to solve - brute force will never find "the  minimal path sum of an 80x80 array of numbers  from the top left to the bottom right by only moving right and down".   Much fun!

I did post  an update to Tangram2 today.  Tangrams are derived from the ancient Chinese puzzle requiring  seven geometric shapes to be arranged into a square. Extensions require that a set of pieces to be arranged to cover a given pattern.  Viewer Max is converting it to Visual Basic and spotted a bug that let pieces be dropped into a "notch" in the target pattern that happen  to exactly match the piece being dropped.  It's fixed now.   

Muzzle loader hunting season is open here now.  A different kind of time-consuming challenge altogether, but I'll try to get a few more of the backlogged programs posted during breaks this month. 




 November 15, 2004:  Here's the first of several small programs that have been accumulating here.  It a Latitude-Longitude Distance Calculator.  Guess that pretty much describes what it does.  There are buttons to estimate distances assuming that the earth is perfectly spherical and one which considers the effect of earth's bulge around the equator.  Neither is original, except perhaps for the fact that they are Delphi implementations. 


November 23, 2004:  I posted a correction for our Tic-Tac-Toe machine today.  This is a program that simulates a Matchbox "machine" which uses colored beads to learn to play.  It gets smarter through trial and error by playing games against a smart human or a dumb computer.  A viewer recently found that the machine would occasionally cheat by overwriting one of your "O"s with his "X" in order to win a game.   I don't believe that the program is smart enough to cheat intentionally, so  I  bypassed that problem today.  It now actually  seems to learn a little faster.   


November 30, 2004:   


A  young lady recently asked for help in creating a game board so I thought it would be a good chance to explore a few of the choices.  Needing something to test the boards, I coded logic for the game of Reversi (Othello®) to respond to user clicks.  No computer play in this version - we'll save that for another day.   There is more strategy to the game than I would have suspected with a number of web sites dedicated to news, strategy, tournaments, etc.    In any event, here is GameBoards - Reversi over in the Delphi-Techniques section of the site as an introduction.   Three independent boards and games on one page! 


December 5, 2004:  


The year is fast winding down, but here is one more interesting exercise.  Version 3 of our Oscilloscope program has been posted and now includes a simplified spectrum analyzer!   An old  friend of mine (Jim Corley, website ) has tackled a violin tune-up project.  Besides being an artist, sculptor, and woodworker, Jim is a retired vibration engineer,  so naturally he wanted a way to measure resonant frequencies when he administered the "thump test" to his violin.  He already has the frequency response charts for the Stradivarius, so now  duplicating the Strad should be a snap!

I also added time scale lines to the oscilloscope display, the ability for users to control the sampling rate, and  to save captured data frames in both the time and frequency domains.  The Oscilloscope program uses your PC's soundcard to convert sounds to numbers.  The screen shots above show a 1,000 Hz (cycles per second) sine wave test generated using our Sound Generator  program.   Lots of fun!  

 December 9, 2004:  I implemented some code in the Oscilloscope program the other day which uses Delphi's  MouseEnter and MouseLeave messages to turn the label on and off in the spectrum bar graph.   Our Delphi Techniques section now has a Mouse enter, Mouse leave Demo program which discusses and illustrates what I learned about processing these messages.

December 12, 2004:  There is something going on in the knight's tour puzzle world that I don't quite understand (which is  OK with me!).   A few months ago I developed code to solve the puzzle with constraints (certain moves occurring in specific squares).  The other day someone requested the ability to continue searching for solutions after the first solution is found.  The change was simple, so I did it.  A revised Knight's' Tour with  the multiple solutions feature was posted today.   



Gary Darby

We never stop investigating. We are never satisfied that we know enough to get by. Every question we answer leads on to another question. This has become the greatest survival trick of our species.  Desmond Morris (b. 1928), British anthropologist

To subscribe or unsubscribe from this newsletter, visit

96,000 home page visitors since Sept 2000.     254,000 programs downloaded in the past 12 months!