July 8, 2012
Delphi For Fun Newsletter #64
I'm not sure when the "dog days" of summer occur, but I would not want days any doggier than the past 10! The heat is supposed to break tomorrow, thankfully. For the 1st time in the 20 years we've been here, I'm shopping for an AC unit for the house. It is 90º outside right now and 82 in the house. In Roanoke that would be cool, but here on the mountain we've been spoiled and consider it to be hot! At least it is the season for some good "minor" sports on TV and the heat provides a good excuse to stay in and enjoy tennis, golf, auto racing, and cycling with the Olympics coming up soon. All of these guys and gals exhibit what it takes to win: native ability, knowledge of techniques, and motivation to work, work, work. Sounds similar to what it takes to be a good, if not great, programmer and problem solver!
This quarter has a couple new items: a Sudoku solver and generator, a Daylight Saving start and end date calculator, and a Blue Moon schedule calculator were all fun. And, of course, the usual batch of enhancements and fixes for existing programs. Here are the postings for the past three months.
April 7, 2012:
Here is the first (incomplete) version of a Sudoku Helper/Solver. I wrote it on our Caribbean cruise last week while the rest of the family worked on solving the daily puzzles handed out by the cruise line. My way is harder initially, but when they solve one, they have solved one; when I solve one, I have, in theory, solved them all! (That excludes the possibility of program bugs of course, but even those are new and non-repetitive problems to solve one-time. I love it!)
The program allows entering and saving puzzles. As you run
across those that cause problems, save and send them on as email attachments to
Pace yourself and only send one per week please (in case the 6 included samples
are the only ones the program can solve).
April 8:2012: It didn't take long to find the first couple of program bugs in yesterday's posting: Sudoku Helper/Solver V 1.2 was posted today to fix problems with missing default file extensions on saved puzzles and the missing final hint value when hints extended onto a second display line.
April 11, 2012: Sudoku Version 1.3 corrects a problem with the Undo button trying, under some conditions, to undo more moves than were made, resulting in various undesirable outcomes.
April 13, 2012: Sudoku Version 2.0 was posted today. It adds the "Trail and Error" solver discussed. earlier and cleans up a couple of other minor bugs. We'll let it rest for a while now as I move on the the next project.
April 21, 2012: Here's a program, DSTCalc, investigating how Daylight Saving Time start and end dates can be calculated using simple equations without resorting to high level date-time routines. This might be useful for programmable devices which need to know but don't have the advantages that the big boys have. The program also contains a Delphi GetNthSunday function using the high level routines to verify the simple equation approach.
April 28, 2012: "Points from 4 Sensors" is a program which calculates the location of a target in 3D space when it is given the locations of 4 sensors and the distance from each sensor to the target as they (or the target) calculates. The program completes the picture by calculating the (x, y, z) coordinates of the target using a method called Gaussian Elimination to solve the 4 distance equations. Point from 4 Sensors, Version 5.0 posted today adds an alternative technique, Trilateration, to find target coordinates. Trilateration appears to be more robust, finding solutions when the sensors are coplanar or nearly coplanar and the Gaussian method fails.
May 3, 2012: Another avid logic problem solver managed to break my "Logic Solver" program last week, this time with a Geocaching problem with 10 different teams, home towns, and cache counts. The previous version would only handle 9 values per variable without burping, but Logic Problem Solver, Version 4.0 , just posted, handles up to 15 values and can solve the problem (also included in the download if you want to try your hand).
May 8, 2012: The CHOICE statement type was added to Logic Problem Saver Version 4.1 today after 5 days of challenging work. The full program is one of the most complex I've written, with about 6000 lines of code equally divided between handling the user interface and searching for a solution. It uses facts, and other logical relationships extracted from problem description text by the user. Choice statements simplify the user's job when we are told that a variable value is associated with 2 or 3 possible values of another variable. Such statements allows us to generate (negative) Facts about what values the associated variable cannot have. For example: If we know that "Bob lives either in Virginia or North Carolina" (the Choice statement), then he cannot live in any of the other states that the problem allows. Those negative facts (e.g. "Bob does not live in Florida") can help complete the "Truth tables" necessary to resolve who lives where. In the May 3rd Geocaching problem, the three Choice statements eliminate user entry of 24 of those negative Fact statements. Now if I can just find a dozen or so similar problems, I will have saved enough time to pay for effort of the enhancement. J
May 11, 2012: ClearBlankLines is a program which removes entirely blank lines from text files. It was written several years ago to solve a particular problem I had with generated html code on my website when some unknown action added 35,000 blank lines to web pages. The pages were still viewable but speed slowed considerably, required storage space increased, and my HTML editor program choked. I have had a surprising number of emails thanking me for the program since then for helping them resolve similar problems. Today's update adds an option requested recently by a user to also remove leading blanks from lines which contain text.
May 19, 2012: A Sudoku Helper program was posted last month which led to this week's project, generating random Sudoku puzzles. As usual, the problem turned out to be harder that I thought. Generating valid filled boards is relative easy, there are billions of them. The hard part is to remove some of the values and meeting the requirement that the board can be filled in only one way. Once 53 or so numbers have been randomly removed (28 clues), more than 99.8% of the resulting boards will have two or more solutions and the probability of a random unique solution decreases rapidly from there. It's still a work in progress, but Sudoku V3.0 posted today averages about 1 unique solution per 400 boards tested for random puzzles with 28 or more clues.
June 4, 2012: One more enhancement to help a used debug a customized keyboard problem: Key Codes Version 3.0 displays scan codes when KeyDown as well as KeyPressed and KeyUp events occur. This version also lets the user verify that left and right keys for Shift, Ctrl, and Alt are identified correctly.
June 6: 2012: Program CutList . assists in creating efficient layouts of rectangular parts for woodworking or other projects. It is the most popular program on DFF but its complexity has made it more than a "for fun" project so current development is restricted to bug fixes. A couple of minor printing problems were corrected today - so minor that I'm not updating the version number. But printed diagrams now have a slightly wider part outlines to improve visibility. And the extra blank page preceding printed diagrams under some conditions has been eliminated.
June 11, 2012: Last month's posting of Clear Blank Lines triggered a number of enhancement requests from users. Clear Blank Lines Version 3.1 posted today adds these features:
June 21, 2012: A small bug in our UBigIntegersV3 unit resulted in consolidating all of the library file updates from the past 3 years into a new library release, DFFLIBV14. Also, the RSA encryption demo program, which requires some math with very large random integers, previously used a tailored version of the BigInteger class. Those routines have now been included in UBigIntegersV3 in the new library release.
It's been a while since I've written a "just for fun" program, but I recently learned the definition of a "Blue Moon" so I'm next going to try generating a "Blue Moon Schedule" for any give date range.
July 6, 2012:
Back to work after a break for the holiday. Blue Moons, a program which calculates occurrences full moons which are called "blue" even though they are not. There is speculation that the Middle English word for "blue" which also meant "betrayer", used that meaning because the occurrence of 13 lunar months in some years messed up their use for agricultural and religious purposes. In any event, the phrase "Once in a blue moon" in English indicates an event or condition that rarely occurs. There are two common definitions and the program provides results for both.
To subscribe or unsubscribe from this newsletter, visit http://delphiforfun.org/newsletter.htm
309,000 visitors and 338,000 program downloads in the past 12 months!
Copyright © 2000-2017, Gary Darby All rights reserved.